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 #include <asm/pgtable.h> 00024 #include <asm/io.h> 00025 #include <asm/rtai_vectors.h> 00026 00027 #undef __SHM_USE_VECTOR 00028 00029 #ifndef __KERNEL__ 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 /* convert virtual user memory address to physical address */ 00063 /* (virt_to_phys only works for kmalloced kernel memory) */ 00064 00065 static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) 00066 { 00067 unsigned long ret = 0UL; 00068 pmd_t *pmd; 00069 pte_t *ptep, pte; 00070 00071 if(!pgd_none(*pgd)) { 00072 pmd = pmd_offset(pgd, adr); 00073 if (!pmd_none(*pmd)) { 00074 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 00075 ptep = pte_offset(pmd, adr); 00076 #else /* >= 2.6.0 */ 00077 ptep = pte_offset_kernel(pmd, adr); 00078 #endif /* < 2.6.0 */ 00079 pte = *ptep; 00080 if(pte_present(pte)){ 00081 ret = (unsigned long) page_address(pte_page(pte)); 00082 ret |= (adr&(PAGE_SIZE-1)); 00083 } 00084 } 00085 } 00086 return ret; 00087 } 00088 00089 static inline unsigned long uvirt_to_bus(unsigned long adr) 00090 { 00091 unsigned long kva, ret; 00092 00093 kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr); 00094 ret = virt_to_bus((void *)kva); 00095 00096 return ret; 00097 } 00098 00099 #ifndef VMALLOC_VMADDR 00100 #define VMALLOC_VMADDR(x) ((unsigned long)(x)) 00101 #endif 00102 00103 static inline unsigned long kvirt_to_bus(unsigned long adr) 00104 { 00105 unsigned long va, kva, ret; 00106 00107 va = VMALLOC_VMADDR(adr); 00108 kva = uvirt_to_kva(pgd_offset_k(va), va); 00109 ret = virt_to_bus((void *)kva); 00110 00111 return ret; 00112 } 00113 00114 static inline unsigned long kvirt_to_pa(unsigned long adr) 00115 { 00116 unsigned long va, kva, ret; 00117 00118 va = VMALLOC_VMADDR(adr); 00119 kva = uvirt_to_kva(pgd_offset_k(va), va); 00120 ret = __pa(kva); 00121 00122 return ret; 00123 } 00124 00125 #endif /* !_RTAI_ASM_PPC_SHM_H */

Generated on Thu Nov 20 11:49:49 2008 for RTAI API by doxygen 1.3.8