base/include/asm-ppc/rtai_shm.h

Go to the documentation of this file.
00001 /*
00002 COPYRIGHT (C) 2000  Paolo Mantegazza (mantegazza@aero.polimi.it)
00003 
00004 This library is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU Lesser General Public
00006 License as published by the Free Software Foundation; either
00007 version 2 of the License, or (at your option) any later version.
00008 
00009 This library is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00017 */
00018 
00019 
00020 #ifndef _RTAI_ASM_PPC_SHM_H
00021 #define _RTAI_ASM_PPC_SHM_H
00022 
00023 #if 0
00024 
00025 #undef __SHM_USE_VECTOR
00026 
00027 #ifndef __KERNEL__
00028 
00029 #include <asm/rtai_vectors.h>
00030 
00031 #ifdef __SHM_USE_VECTOR
00032 // the following function is adapted from Linux PPC unistd.h 
00033 static inline long long rtai_shmrq(unsigned long srq, unsigned long whatever)
00034 {
00035     long long retval;
00036     register unsigned long __sc_0 __asm__ ("r0");
00037     register unsigned long __sc_3 __asm__ ("r3");
00038     register unsigned long __sc_4 __asm__ ("r4");
00039 
00040     __sc_0 = (__sc_3 = srq | (RTAI_SHM_VECTOR << 24)) + (__sc_4 = whatever);
00041     __asm__ __volatile__
00042         ("trap         \n\t"
00043         : "=&r" (__sc_3), "=&r" (__sc_4)
00044         : "0"   (__sc_3), "1"   (__sc_4),
00045               "r"   (__sc_0)
00046         : "r0", "r3", "r4" );
00047     ((unsigned long *)&retval)[0] = __sc_3;
00048     ((unsigned long *)&retval)[1] = __sc_4;
00049     return retval;
00050 }
00051 
00052 #else  /* __KERNEL__ */
00053 
00054 #define RTAI_SHM_HANDLER shm_handler
00055 
00056 #define DEFINE_SHM_HANDLER
00057 
00058 #endif /* __SHM_USE_VECTOR */
00059 
00060 #endif /* __KERNEL__ */
00061 
00062 #include <asm/pgtable.h>
00063 #include <asm/io.h>
00064 
00065 /* convert virtual user memory address to physical address */
00066 /* (virt_to_phys only works for kmalloced kernel memory) */
00067 
00068 static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr)
00069 {
00070     unsigned long ret = 0UL;
00071     pmd_t *pmd;
00072     pte_t *ptep, pte;
00073 
00074     if(!pgd_none(*pgd)) {
00075         pmd = pmd_offset(pgd, adr);
00076         if (!pmd_none(*pmd)) {
00077 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00078             ptep = pte_offset(pmd, adr);
00079 #else /* >= 2.6.0 */
00080             ptep = pte_offset_kernel(pmd, adr);
00081 #endif /* < 2.6.0 */
00082             pte = *ptep;
00083             if(pte_present(pte)){
00084                 ret = (unsigned long) page_address(pte_page(pte));
00085                 ret |= (adr&(PAGE_SIZE-1));
00086             }
00087         }
00088     }
00089     return ret;
00090 }
00091 
00092 static inline unsigned long uvirt_to_bus(unsigned long adr)
00093 {
00094     unsigned long kva, ret;
00095 
00096     kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
00097     ret = virt_to_bus((void *)kva);
00098 
00099     return ret;
00100 }
00101 
00102 #ifndef VMALLOC_VMADDR
00103 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
00104 #endif
00105 
00106 static inline unsigned long kvirt_to_bus(unsigned long adr)
00107 {
00108     unsigned long va, kva, ret;
00109 
00110     va = VMALLOC_VMADDR(adr);
00111     kva = uvirt_to_kva(pgd_offset_k(va), va);
00112     ret = virt_to_bus((void *)kva);
00113 
00114     return ret;
00115 }
00116 
00117 static inline unsigned long kvirt_to_pa(unsigned long adr)
00118 {
00119     unsigned long va, kva, ret;
00120 
00121     va = VMALLOC_VMADDR(adr);
00122     kva = uvirt_to_kva(pgd_offset_k(va), va);
00123     ret = __pa(kva);
00124 
00125     return ret;
00126 }
00127 
00128 #endif
00129 
00130 #endif /* !_RTAI_ASM_PPC_SHM_H */

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7