Hi,

this adds mmap(2) support for ssdfb(4), so we can map the framebuffer
from userland and have X11 or another graphical program write into it.

ok?

Patrick

diff --git a/sys/dev/fdt/ssdfb.c b/sys/dev/fdt/ssdfb.c
index e91762a0ad2..8f141608c91 100644
--- a/sys/dev/fdt/ssdfb.c
+++ b/sys/dev/fdt/ssdfb.c
@@ -24,6 +24,8 @@
 #include <sys/timeout.h>
 #include <sys/task.h>
 
+#include <uvm/uvm_extern.h>
+
 #include <dev/spi/spivar.h>
 
 #include <dev/ofw/openfirm.h>
@@ -190,7 +192,8 @@ ssdfb_attach(struct device *parent, struct device *self, 
void *aux)
        sc->sc_fb = malloc(sc->sc_fbsize, M_DEVBUF, M_WAITOK | M_ZERO);
 
        ri = &sc->sc_rinfo;
-       ri->ri_bits = malloc(sc->sc_fbsize, M_DEVBUF, M_WAITOK | M_ZERO);
+       ri->ri_bits = km_alloc(roundup(sc->sc_fbsize, PAGE_SIZE),
+           &kv_any, &kp_zero, &kd_waitok);
        ri->ri_bs = ssdfb_bs;
        ri->ri_flg = RI_CLEAR | RI_VCONS;
        ri->ri_depth = 1;
@@ -230,7 +233,8 @@ ssdfb_detach(struct device *self, int flags)
        struct rasops_info *ri = &sc->sc_rinfo;
        timeout_del(&sc->sc_to);
        task_del(systq, &sc->sc_task);
-       free(ri->ri_bits, M_DEVBUF, sc->sc_fbsize);
+       km_free(ri->ri_bits, roundup(sc->sc_fbsize, PAGE_SIZE),
+           &kv_any, &kp_zero);
        free(sc->sc_fb, M_DEVBUF, sc->sc_fbsize);
        free(sc->sc_gpio, M_DEVBUF, sc->sc_gpiolen);
        return 0;
@@ -392,7 +396,17 @@ ssdfb_ioctl(void *v, u_long cmd, caddr_t data, int flag, 
struct proc *p)
 paddr_t
 ssdfb_mmap(void *v, off_t off, int prot)
 {
-       return -1;
+       struct ssdfb_softc      *sc = v;
+       struct rasops_info      *ri = &sc->sc_rinfo;
+       paddr_t                  pa;
+
+       if (off >= sc->sc_fbsize || off < 0)
+               return (-1);
+
+       if (!pmap_extract(pmap_kernel(), (vaddr_t)ri->ri_bits, &pa))
+               return (-1);
+
+       return (pa + off);
 }
 
 int

Reply via email to