rtai-core/include/asm-i386/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 #define __SHM_USE_VECTOR 1
00032 
00033 #ifndef __KERNEL__
00034 
00035 #ifdef __SHM_USE_VECTOR
00036 static inline long long rtai_shmrq(int srq, unsigned int whatever)
00037 {
00038         long long retval;
00039         RTAI_DO_TRAP(RTAI_SHM_VECTOR,retval,srq,whatever);
00040         return retval;
00041 }
00042 #endif /* __SHM_USE_VECTOR */
00043 
00044 #else /* __KERNEL__ */
00045 
00046 #define RTAI_SHM_HANDLER rtai_shm_handler
00047 
00048 #define __STR(x) #x
00049 #define STR(x) __STR(x)
00050 
00051 #define DEFINE_SHM_HANDLER \
00052 static void rtai_shm_handler(void) \
00053 { \
00054         __asm__ __volatile__ (" \
00055         cld; pushl %es; pushl %ds; pushl %ebp;\n\t \
00056         pushl %edi; pushl %esi; pushl %ecx;\n\t \
00057         pushl %ebx; pushl %edx; pushl %eax;\n\t \
00058         movl $" STR(__KERNEL_DS) ",%ebx; mov %bx,%ds; mov %bx,%es"); \
00059         __asm__ __volatile__ ("call "SYMBOL_NAME_STR(shm_handler)); \
00060         __asm__ __volatile__ (" \
00061         addl $8,%esp; popl %ebx; popl %ecx; popl %esi;\n\t \
00062         popl %edi; popl %ebp; popl %ds; popl %es; iret"); \
00063 }
00064 
00065 #endif /* __KERNEL__ */
00066 
00067 /* convert virtual user memory address to physical address */
00068 /* (virt_to_phys only works for kmalloced kernel memory) */
00069 
00070 static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr)
00071 {
00072         unsigned long ret = 0UL;
00073         pmd_t *pmd;
00074         pte_t *ptep, pte;
00075 
00076         if(!pgd_none(*pgd)) {
00077                 pmd = pmd_offset(pgd, adr);
00078                 if (!pmd_none(*pmd)) {
00079 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
00080                         ptep = pte_offset(pmd, adr);
00081 #else /* >= 2.6.0 */
00082                         ptep = pte_offset_kernel(pmd, adr);
00083 #endif /* < 2.6.0 */
00084                         pte = *ptep;
00085                         if(pte_present(pte)){
00086                                 ret = (unsigned long) page_address(pte_page(pte));
00087                                 ret |= (adr&(PAGE_SIZE-1));
00088                         }
00089                 }
00090         }
00091         return ret;
00092 }
00093 
00094 static inline unsigned long uvirt_to_bus(unsigned long adr)
00095 {
00096         unsigned long kva, ret;
00097 
00098         kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
00099         ret = virt_to_bus((void *)kva);
00100 
00101         return ret;
00102 }
00103 
00104 static inline unsigned long kvirt_to_bus(unsigned long adr)
00105 {
00106         unsigned long va, kva, ret;
00107 
00108         va = VMALLOC_VMADDR(adr);
00109         kva = uvirt_to_kva(pgd_offset_k(va), va);
00110         ret = virt_to_bus((void *)kva);
00111 
00112         return ret;
00113 }
00114 
00115 static inline unsigned long kvirt_to_pa(unsigned long adr)
00116 {
00117         unsigned long va, kva, ret;
00118 
00119         va = VMALLOC_VMADDR(adr);
00120         kva = uvirt_to_kva(pgd_offset_k(va), va);
00121         ret = __pa(kva);
00122 
00123         return ret;
00124 }
00125 
00126 #endif  /* !_RTAI_ASM_I386_SHM_H */

Generated on Sat Jul 24 19:36:02 2004 for RTAI API by doxygen 1.3.4