Author: nwhitehorn
Date: Sat Jul 19 15:11:58 2014
New Revision: 268880
URL: http://svnweb.freebsd.org/changeset/base/268880

Log:
  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

Modified:
  head/sys/powerpc/aim/trap.c
  head/sys/powerpc/powerpc/mem.c

Modified: head/sys/powerpc/aim/trap.c
==============================================================================
--- head/sys/powerpc/aim/trap.c Sat Jul 19 15:09:53 2014        (r268879)
+++ head/sys/powerpc/aim/trap.c Sat Jul 19 15:11:58 2014        (r268880)
@@ -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);
                }

Modified: head/sys/powerpc/powerpc/mem.c
==============================================================================
--- head/sys/powerpc/powerpc/mem.c      Sat Jul 19 15:09:53 2014        
(r268879)
+++ head/sys/powerpc/powerpc/mem.c      Sat Jul 19 15:11:58 2014        
(r268880)
@@ -179,22 +179,13 @@ memmmap(struct cdev *dev, vm_ooffset_t o
 {
        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_lo
        }
        return (error);
 }
+
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to