base/include/asm-x86_64/rtai_shm.h

Go to the documentation of this file.
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_X8664_SHM_H
00020 #define _RTAI_ASM_X8664_SHM_H
00021 
00022 #if 0
00023 
00024 #ifndef __KERNEL__
00025 
00026 #include <asm/rtai_vectors.h>
00027 
00028 static inline long long rtai_shmrq(int srq, unsigned long args)
00029 {
00030     long long retval;
00031     RTAI_DO_TRAP(RTAI_SYS_VECTOR, retval, srq, args);
00032     return retval;
00033 }
00034 
00035 #endif /* __KERNEL__ */
00036 
00037 #include <asm/pgtable.h>
00038 #include <asm/io.h>
00039 #include <rtai_wrappers.h>
00040 
00041 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
00042 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
00043 #endif /* >= 2.6.0 */
00044 
00045 /* convert virtual user memory address to physical address */
00046 /* (virt_to_phys only works for kmalloced kernel memory) */
00047 
00048 static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr)
00049 {
00050     unsigned long ret = 0UL;
00051     pmd_t *pmd;
00052     pte_t *ptep, pte;
00053 
00054     if(!pgd_none(*pgd)) {
00055 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
00056                 pmd = pmd_offset(pgd, adr);
00057 #else /* >= 2.6.11 */
00058                 pmd = pmd_offset(pud_offset(pgd, adr), adr);
00059 #endif /* < 2.6.11 */
00060         if (!pmd_none(*pmd)) {
00061 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00062             ptep = pte_offset(pmd, adr);
00063 #else /* >= 2.6.0 */
00064             ptep = pte_offset_kernel(pmd, adr);
00065 #endif /* < 2.6.0 */
00066             pte = *ptep;
00067             if(pte_present(pte)){
00068                 ret = (unsigned long) page_address(pte_page(pte));
00069                 ret |= (adr&(PAGE_SIZE-1));
00070             }
00071         }
00072     }
00073     return ret;
00074 }
00075 
00076 static inline unsigned long uvirt_to_bus(unsigned long adr)
00077 {
00078     unsigned long kva, ret;
00079 
00080     kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
00081     ret = virt_to_bus((void *)kva);
00082 
00083     return ret;
00084 }
00085 
00086 static inline unsigned long kvirt_to_bus(unsigned long adr)
00087 {
00088     unsigned long va, kva, ret;
00089 
00090     va = VMALLOC_VMADDR(adr);
00091     kva = uvirt_to_kva(pgd_offset_k(va), va);
00092     ret = virt_to_bus((void *)kva);
00093 
00094     return ret;
00095 }
00096 
00097 static inline unsigned long kvirt_to_pa(unsigned long adr)
00098 {
00099     unsigned long va, kva, ret;
00100 
00101     va = VMALLOC_VMADDR(adr);
00102     kva = uvirt_to_kva(pgd_offset_k(va), va);
00103     ret = __pa(kva);
00104 
00105     return ret;
00106 }
00107 
00108 #endif
00109 
00110 #endif  /* !_RTAI_ASM_X8664_SHM_H */

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