# rtai_shm.h

    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                         ptep = pte_offset(pmd, adr);
    00075                         pte = *ptep;
    00076                         if(pte_present(pte)){
    00077                                 ret = (unsigned long) page_address(pte_page(pte));
    00078                                 ret |= (adr&(PAGE_SIZE-1));
    00079                         }
    00080                 }
    00081         }
    00082         return ret;
    00083 }
    00084
    00085 static inline unsigned long uvirt_to_bus(unsigned long adr)
    00086 {
    00087         unsigned long kva, ret;
    00088
    00089         kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
    00090         ret = virt_to_bus((void *)kva);
    00091
    00092         return ret;
    00093 }
    00094
    00095 static inline unsigned long kvirt_to_bus(unsigned long adr)
    00096 {
    00097         unsigned long va, kva, ret;
    00098
    00099         va = VMALLOC_VMADDR(adr);
    00100         kva = uvirt_to_kva(pgd_offset_k(va), va);
    00101         ret = virt_to_bus((void *)kva);
    00102
    00103         return ret;
    00104 }
    00105
    00106 static inline unsigned long kvirt_to_pa(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 = __pa(kva);
    00113
    00114         return ret;
    00115 }
    00116
    00117 #endif /* !_RTAI_ASM_PPC_SHM_H */