]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
parisc: Use lpa instruction to load physical addresses in driver code
authorJohn David Anglin <dave.anglin@bell.net>
Sun, 2 Jun 2019 23:12:40 +0000 (19:12 -0400)
committerHelge Deller <deller@gmx.de>
Thu, 6 Jun 2019 12:12:22 +0000 (14:12 +0200)
Most I/O in the kernel is done using the kernel offset mapping.
However, there is one API that uses aliased kernel address ranges:

> The final category of APIs is for I/O to deliberately aliased address
> ranges inside the kernel.  Such aliases are set up by use of the
> vmap/vmalloc API.  Since kernel I/O goes via physical pages, the I/O
> subsystem assumes that the user mapping and kernel offset mapping are
> the only aliases.  This isn't true for vmap aliases, so anything in
> the kernel trying to do I/O to vmap areas must manually manage
> coherency.  It must do this by flushing the vmap range before doing
> I/O and invalidating it after the I/O returns.

For this reason, we should use the hardware lpa instruction to load the
physical address of kernel virtual addresses in the driver code.

I believe we only use the vmap/vmalloc API with old PA 1.x processors
which don't have a sba, so we don't hit this problem.

Tested on c3750, c8000 and rp3440.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Signed-off-by: Helge Deller <deller@gmx.de>
arch/parisc/include/asm/special_insns.h
drivers/parisc/ccio-dma.c
drivers/parisc/sba_iommu.c

index 3d4dd68e181b44b2a8c2d089067bdca3ad0ab674..a303ae9a77f41fe8ceef5490ab2be5b394fc199d 100644 (file)
@@ -2,6 +2,30 @@
 #ifndef __PARISC_SPECIAL_INSNS_H
 #define __PARISC_SPECIAL_INSNS_H
 
+#define lpa(va)        ({                      \
+       unsigned long pa;               \
+       __asm__ __volatile__(           \
+               "copy %%r0,%0\n\t"      \
+               "lpa %%r0(%1),%0"       \
+               : "=r" (pa)             \
+               : "r" (va)              \
+               : "memory"              \
+       );                              \
+       pa;                             \
+})
+
+#define lpa_user(va)   ({              \
+       unsigned long pa;               \
+       __asm__ __volatile__(           \
+               "copy %%r0,%0\n\t"      \
+               "lpa %%r0(%%sr3,%1),%0" \
+               : "=r" (pa)             \
+               : "r" (va)              \
+               : "memory"              \
+       );                              \
+       pa;                             \
+})
+
 #define mfctl(reg)     ({              \
        unsigned long cr;               \
        __asm__ __volatile__(           \
index 9b434644524c20ca8c597cce0902a2138262ec63..8362517b98f94aa25d10de36657d7078c92ee591 100644 (file)
@@ -570,7 +570,7 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
        ** "hints" parm includes the VALID bit!
        ** "dep" clobbers the physical address offset bits as well.
        */
-       pa = virt_to_phys(vba);
+       pa = lpa(vba);
        asm volatile("depw  %1,31,12,%0" : "+r" (pa) : "r" (hints));
        ((u32 *)pdir_ptr)[1] = (u32) pa;
 
index 78df9260020386b4dd4627af6397e3a1a4078d78..aefb03ebeaf8c5c20eda2622e0a547dd51eee0df 100644 (file)
@@ -572,7 +572,7 @@ sba_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
        u64 pa; /* physical address */
        register unsigned ci; /* coherent index */
 
-       pa = virt_to_phys(vba);
+       pa = lpa(vba);
        pa &= IOVP_MASK;
 
        asm("lci 0(%1), %0" : "=r" (ci) : "r" (vba));