rtai_shm.h

00001 /*
00002  * Copyright (C) 1999-2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program 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
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _RTAI_ASM_I386_SHM_H
00020 #define _RTAI_ASM_I386_SHM_H
00021 
00022 #include <asm/pgtable.h>
00023 #include <asm/io.h>
00024 #include <asm/rtai_vectors.h>
00025 #include <rtai_wrappers.h>
00026 
00027 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00028 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
00029 #endif /* >= 2.6.0 */
00030 
00031 #ifndef __KERNEL__
00032 
00033 static inline long long rtai_shmrq(int srq, unsigned long args)
00034 {
00035         long long retval;
00036         RTAI_DO_TRAP(RTAI_SYS_VECTOR, retval, srq, args);
00037         return retval;
00038 }
00039 
00040 #endif /* __KERNEL__ */
00041 
00042 /* convert virtual user memory address to physical address */
00043 /* (virt_to_phys only works for kmalloced kernel memory) */
00044 
00045 static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr)
00046 {
00047         unsigned long ret = 0UL;
00048         pmd_t *pmd;
00049         pte_t *ptep, pte;
00050 
00051         if(!pgd_none(*pgd)) {
00052                 pmd = pmd_offset(pgd, adr);
00053                 if (!pmd_none(*pmd)) {
00054 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00055                         ptep = pte_offset(pmd, adr);
00056 #else /* >= 2.6.0 */
00057                         ptep = pte_offset_kernel(pmd, adr);
00058 #endif /* < 2.6.0 */
00059                         pte = *ptep;
00060                         if(pte_present(pte)){
00061                                 ret = (unsigned long) page_address(pte_page(pte));
00062                                 ret |= (adr&(PAGE_SIZE-1));
00063                         }
00064                 }
00065         }
00066         return ret;
00067 }
00068 
00069 static inline unsigned long uvirt_to_bus(unsigned long adr)
00070 {
00071         unsigned long kva, ret;
00072 
00073         kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
00074         ret = virt_to_bus((void *)kva);
00075 
00076         return ret;
00077 }
00078 
00079 static inline unsigned long kvirt_to_bus(unsigned long adr)
00080 {
00081         unsigned long va, kva, ret;
00082 
00083         va = VMALLOC_VMADDR(adr);
00084         kva = uvirt_to_kva(pgd_offset_k(va), va);
00085         ret = virt_to_bus((void *)kva);
00086 
00087         return ret;
00088 }
00089 
00090 static inline unsigned long kvirt_to_pa(unsigned long adr)
00091 {
00092         unsigned long va, kva, ret;
00093 
00094         va = VMALLOC_VMADDR(adr);
00095         kva = uvirt_to_kva(pgd_offset_k(va), va);
00096         ret = __pa(kva);
00097 
00098         return ret;
00099 }
00100 
00101 #endif  /* !_RTAI_ASM_I386_SHM_H */

Generated on Tue Jan 18 22:53:52 2005 for RTAI API by  doxygen 1.3.9.1