diff options
Diffstat (limited to 'sys/powerpc/aim/copyinout.c')
-rw-r--r-- | sys/powerpc/aim/copyinout.c | 175 |
1 files changed, 153 insertions, 22 deletions
diff --git a/sys/powerpc/aim/copyinout.c b/sys/powerpc/aim/copyinout.c index e023b3f..35d0ee4 100644 --- a/sys/powerpc/aim/copyinout.c +++ b/sys/powerpc/aim/copyinout.c @@ -57,6 +57,8 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/lock.h> +#include <sys/mutex.h> #include <sys/systm.h> #include <sys/proc.h> @@ -66,20 +68,45 @@ __FBSDID("$FreeBSD$"); #include <machine/pcb.h> #include <machine/sr.h> +#include <machine/slb.h> int setfault(faultbuf); /* defined in locore.S */ /* * Makes sure that the right segment of userspace is mapped in. */ + +#ifdef __powerpc64__ +static __inline void +set_user_sr(pmap_t pm, const void *addr) +{ + register_t esid, vsid, slb1, slb2; + + esid = USER_ADDR >> ADDR_SR_SHFT; + PMAP_LOCK(pm); + vsid = va_to_vsid(pm, (vm_offset_t)addr); + PMAP_UNLOCK(pm); + + slb1 = vsid << SLBV_VSID_SHIFT; + slb2 = (esid << SLBE_ESID_SHIFT) | SLBE_VALID | USER_SR; + + __asm __volatile ("slbie %0; slbmte %1, %2" :: "r"(esid << 28), + "r"(slb1), "r"(slb2)); + isync(); +} +#else static __inline void -set_user_sr(register_t vsid) +set_user_sr(pmap_t pm, const void *addr) { + register_t vsid; + + vsid = va_to_vsid(pm, (vm_offset_t)addr); isync(); __asm __volatile ("mtsr %0,%1" :: "n"(USER_SR), "r"(vsid)); isync(); } +#endif int copyout(const void *kaddr, void *udaddr, size_t len) @@ -103,13 +130,13 @@ copyout(const void *kaddr, void *udaddr, size_t len) up = udaddr; while (len > 0) { - p = (char *)USER_ADDR + ((u_int)up & ~SEGMENT_MASK); + p = (char *)USER_ADDR + ((uintptr_t)up & ~SEGMENT_MASK); l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p; if (l > len) l = len; - set_user_sr(pm->pm_sr[(u_int)up >> ADDR_SR_SHFT]); + set_user_sr(pm,up); bcopy(kp, p, l); @@ -144,13 +171,13 @@ copyin(const void *udaddr, void *kaddr, size_t len) up = udaddr; while (len > 0) { - p = (char *)USER_ADDR + ((u_int)up & ~SEGMENT_MASK); + p = (char *)USER_ADDR + ((uintptr_t)up & ~SEGMENT_MASK); l = ((char *)USER_ADDR + SEGMENT_LENGTH) - p; if (l > len) l = len; - set_user_sr(pm->pm_sr[(u_int)up >> ADDR_SR_SHFT]); + set_user_sr(pm,up); bcopy(p, kp, l); @@ -218,14 +245,14 @@ subyte(void *addr, int byte) td = PCPU_GET(curthread); pm = &td->td_proc->p_vmspace->vm_pmap; - p = (char *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK)); + p = (char *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); if (setfault(env)) { td->td_pcb->pcb_onfault = NULL; return (-1); } - set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]); + set_user_sr(pm,addr); *p = (char)byte; @@ -233,6 +260,33 @@ subyte(void *addr, int byte) return (0); } +#ifdef __powerpc64__ +int +suword32(void *addr, int word) +{ + struct thread *td; + pmap_t pm; + faultbuf env; + int *p; + + td = PCPU_GET(curthread); + pm = &td->td_proc->p_vmspace->vm_pmap; + p = (int *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); + + if (setfault(env)) { + td->td_pcb->pcb_onfault = NULL; + return (-1); + } + + set_user_sr(pm,addr); + + *p = word; + + td->td_pcb->pcb_onfault = NULL; + return (0); +} +#endif + int suword(void *addr, long word) { @@ -243,14 +297,14 @@ suword(void *addr, long word) td = PCPU_GET(curthread); pm = &td->td_proc->p_vmspace->vm_pmap; - p = (long *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK)); + p = (long *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); if (setfault(env)) { td->td_pcb->pcb_onfault = NULL; return (-1); } - set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]); + set_user_sr(pm,addr); *p = word; @@ -258,12 +312,19 @@ suword(void *addr, long word) return (0); } +#ifdef __powerpc64__ +int +suword64(void *addr, int64_t word) +{ + return (suword(addr, (long)word)); +} +#else int suword32(void *addr, int32_t word) { return (suword(addr, (long)word)); } - +#endif int fubyte(const void *addr) @@ -276,20 +337,47 @@ fubyte(const void *addr) td = PCPU_GET(curthread); pm = &td->td_proc->p_vmspace->vm_pmap; - p = (u_char *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK)); + p = (u_char *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); + + if (setfault(env)) { + td->td_pcb->pcb_onfault = NULL; + return (-1); + } + + set_user_sr(pm,addr); + + val = *p; + + td->td_pcb->pcb_onfault = NULL; + return (val); +} + +#ifdef __powerpc64__ +int32_t +fuword32(const void *addr) +{ + struct thread *td; + pmap_t pm; + faultbuf env; + int32_t *p, val; + + td = PCPU_GET(curthread); + pm = &td->td_proc->p_vmspace->vm_pmap; + p = (int32_t *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); if (setfault(env)) { td->td_pcb->pcb_onfault = NULL; return (-1); } - set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]); + set_user_sr(pm,addr); val = *p; td->td_pcb->pcb_onfault = NULL; return (val); } +#endif long fuword(const void *addr) @@ -301,14 +389,14 @@ fuword(const void *addr) td = PCPU_GET(curthread); pm = &td->td_proc->p_vmspace->vm_pmap; - p = (long *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK)); + p = (long *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); if (setfault(env)) { td->td_pcb->pcb_onfault = NULL; return (-1); } - set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]); + set_user_sr(pm,addr); val = *p; @@ -316,18 +404,59 @@ fuword(const void *addr) return (val); } +#ifndef __powerpc64__ int32_t fuword32(const void *addr) { return ((int32_t)fuword(addr)); } +#endif uint32_t -casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval) +casuword32(volatile uint32_t *addr, uint32_t old, uint32_t new) { - return (casuword((volatile u_long *)base, oldval, newval)); + struct thread *td; + pmap_t pm; + faultbuf env; + uint32_t *p, val; + + td = PCPU_GET(curthread); + pm = &td->td_proc->p_vmspace->vm_pmap; + p = (uint32_t *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); + + set_user_sr(pm,(const void *)(vm_offset_t)addr); + + if (setfault(env)) { + td->td_pcb->pcb_onfault = NULL; + return (-1); + } + + __asm __volatile ( + "1:\tlwarx %0, 0, %2\n\t" /* load old value */ + "cmplw %3, %0\n\t" /* compare */ + "bne 2f\n\t" /* exit if not equal */ + "stwcx. %4, 0, %2\n\t" /* attempt to store */ + "bne- 1b\n\t" /* spin if failed */ + "b 3f\n\t" /* we've succeeded */ + "2:\n\t" + "stwcx. %0, 0, %2\n\t" /* clear reservation (74xx) */ + "3:\n\t" + : "=&r" (val), "=m" (*p) + : "r" (p), "r" (old), "r" (new), "m" (*p) + : "cc", "memory"); + + td->td_pcb->pcb_onfault = NULL; + + return (val); } +#ifndef __powerpc64__ +u_long +casuword(volatile u_long *addr, u_long old, u_long new) +{ + return (casuword32((volatile uint32_t *)addr, old, new)); +} +#else u_long casuword(volatile u_long *addr, u_long old, u_long new) { @@ -338,9 +467,9 @@ casuword(volatile u_long *addr, u_long old, u_long new) td = PCPU_GET(curthread); pm = &td->td_proc->p_vmspace->vm_pmap; - p = (u_long *)((u_int)USER_ADDR + ((u_int)addr & ~SEGMENT_MASK)); + p = (u_long *)(USER_ADDR + ((uintptr_t)addr & ~SEGMENT_MASK)); - set_user_sr(pm->pm_sr[(u_int)addr >> ADDR_SR_SHFT]); + set_user_sr(pm,(const void *)(vm_offset_t)addr); if (setfault(env)) { td->td_pcb->pcb_onfault = NULL; @@ -348,14 +477,14 @@ casuword(volatile u_long *addr, u_long old, u_long new) } __asm __volatile ( - "1:\tlwarx %0, 0, %2\n\t" /* load old value */ - "cmplw %3, %0\n\t" /* compare */ + "1:\tldarx %0, 0, %2\n\t" /* load old value */ + "cmpld %3, %0\n\t" /* compare */ "bne 2f\n\t" /* exit if not equal */ - "stwcx. %4, 0, %2\n\t" /* attempt to store */ + "stdcx. %4, 0, %2\n\t" /* attempt to store */ "bne- 1b\n\t" /* spin if failed */ "b 3f\n\t" /* we've succeeded */ "2:\n\t" - "stwcx. %0, 0, %2\n\t" /* clear reservation (74xx) */ + "stdcx. %0, 0, %2\n\t" /* clear reservation (74xx) */ "3:\n\t" : "=&r" (val), "=m" (*p) : "r" (p), "r" (old), "r" (new), "m" (*p) @@ -365,3 +494,5 @@ casuword(volatile u_long *addr, u_long old, u_long new) return (val); } +#endif + |