Allow mappings of memory not previously direct-mapped by the kernel when

calling mmap on /dev/mem and add a handler for the possible userland
machine checks that may result. Remove some pointless and wrong copy/paste
that has been in here for a decade as well.

This results in a /dev/mem with identical semantics to the x86 version.

MFC after:	1 week
This commit is contained in:
nwhitehorn 2014-07-19 15:11:58 +00:00
parent ed03f0e596
commit afb6ef5a71
2 changed files with 16 additions and 17 deletions

View File

@ -264,6 +264,15 @@ trap(struct trapframe *frame)
}
break;
case EXC_MCHK:
/*
* Note that this may not be recoverable for the user
* process, depending on the type of machine check,
* but it at least prevents the kernel from dying.
*/
sig = SIGBUS;
break;
default:
trap_fatal(frame);
}

View File

@ -179,22 +179,13 @@ memmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
{
int i;
/*
* /dev/mem is the only one that makes sense through this
* interface. For /dev/kmem any physaddr we return here
* could be transient and hence incorrect or invalid at
* a later time.
*/
if (dev2unit(dev) != CDEV_MINOR_MEM)
return (-1);
/* Only direct-mapped addresses. */
if (mem_valid(offset, 0)
&& pmap_dev_direct_mapped(offset, 0))
if (dev2unit(dev) == CDEV_MINOR_MEM)
*paddr = offset;
else if (dev2unit(dev) == CDEV_MINOR_KMEM)
*paddr = vtophys(offset);
else
return (EFAULT);
*paddr = offset;
for (i = 0; i < mem_range_softc.mr_ndesc; i++) {
if (!(mem_range_softc.mr_desc[i].mr_flags & MDF_ACTIVE))
continue;
@ -231,9 +222,7 @@ ppc_mrinit(struct mem_range_softc *sc)
sc->mr_cap = 0;
sc->mr_ndesc = 8; /* XXX: Should be dynamically expandable */
sc->mr_desc = malloc(sc->mr_ndesc * sizeof(struct mem_range_desc),
M_MEMDESC, M_NOWAIT | M_ZERO);
if (sc->mr_desc == NULL)
panic("%s: malloc returns NULL", __func__);
M_MEMDESC, M_WAITOK | M_ZERO);
}
static int
@ -328,3 +317,4 @@ memioctl(struct cdev *dev __unused, u_long cmd, caddr_t data, int flags,
}
return (error);
}