tech-x11 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

DRM/KMS for Intel graphics



Hi folks!  Sorry for the long delay in updates about DRM/KMS, but it's
time to report that it roughly works, if a little flakily, with a
slightly tweaked but current libdrm, xorg-server, xf86-video-intel,
&c.

If you want to build it and try it out, check out the riastradh-drm2
branch as of now and build the amd64/DRMKMS kernel.  (No other
platforms yet, although i386 might work too.)  You will probably want
a serial console when you test it.  Textual wscons should work.  If
you have some spare time, you could also try a building a current X
server and libraries with the attached patches.  twm seems to work
fine for me; x11perf fairly quickly wedges the GPU and/or driver, but
the X server can be restarted without trouble after that.

The next steps will be:

1. Update all the userland components in xsrc and pkgsrc.
2. Update kernel drm again -- which should be much less painful now.
3. Port the non-Intel drivers, particularly radeon and nouveau.

Let me know if you have any questions!
--- xorg-server-1.14.5/glx/indirect_size_get.c.~1~      2013-07-26 
05:14:32.000000000 +0000
+++ xorg-server-1.14.5/glx/indirect_size_get.c  2014-01-16 15:29:57.000000000 
+0000
@@ -599,7 +599,9 @@ __glGetBooleanv_size(GLenum e)
     case GL_OCCLUSION_TEST_HP:
     case GL_OCCLUSION_TEST_RESULT_HP:
     case GL_LIGHT_MODEL_COLOR_CONTROL:
+#if 0                          /* XXX newer GL */
     case GL_RESET_NOTIFICATION_STRATEGY_ARB:
+#endif
     case GL_CURRENT_FOG_COORD:
     case GL_FOG_COORDINATE_ARRAY_TYPE:
     case GL_FOG_COORDINATE_ARRAY_STRIDE:
--- libdrm-2.4.49/include/drm/drm.h.~1~ 2013-11-22 15:25:06.000000000 +0000
+++ libdrm-2.4.49/include/drm/drm.h     2014-01-18 01:15:56.000000000 +0000
@@ -751,6 +751,20 @@ struct drm_prime_handle {
 #define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct 
drm_mode_obj_set_property)
 #define DRM_IOCTL_MODE_CURSOR2         DRM_IOWR(0xBB, struct drm_mode_cursor2)
 
+#ifdef __NetBSD__
+/*
+ * Instrumenting mmap is trickier than just making an ioctl to do it.
+ */
+struct drm_mmap {
+       void            *dnm_addr;  /* in/out */
+       size_t          dnm_size;   /* in */
+       int             dnm_prot;   /* in */
+       int             dnm_flags;  /* in */
+       off_t           dnm_offset; /* in */
+};
+#define        DRM_IOCTL_MMAP  DRM_IOWR(0xff, struct drm_mmap)
+#endif
+
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x99.
--- libdrm-2.4.49/intel/intel_bufmgr_gem.c.~1~  2013-11-22 15:25:06.000000000 
+0000
+++ libdrm-2.4.49/intel/intel_bufmgr_gem.c      2014-01-17 21:29:03.000000000 
+0000
@@ -1237,12 +1237,10 @@ map_gtt(drm_intel_bo *bo)
                }
 
                /* and mmap it */
-               bo_gem->gtt_virtual = mmap(0, bo->size, PROT_READ | PROT_WRITE,
-                                          MAP_SHARED, bufmgr_gem->fd,
-                                          mmap_arg.offset);
-               if (bo_gem->gtt_virtual == MAP_FAILED) {
+               ret = drmMap(bufmgr_gem->fd, mmap_arg.offset, bo->size,
+                   &bo_gem->gtt_virtual);
+               if (ret) {
                        bo_gem->gtt_virtual = NULL;
-                       ret = -errno;
                        DBG("%s:%d: Error mapping buffer %d (%s): %s .\n",
                            __FILE__, __LINE__,
                            bo_gem->gem_handle, bo_gem->name,
@@ -3286,7 +3284,7 @@ drm_intel_bufmgr_gem_init(int fd, int ba
        bufmgr_gem->bufmgr.bo_busy = drm_intel_gem_bo_busy;
        bufmgr_gem->bufmgr.bo_madvise = drm_intel_gem_bo_madvise;
        bufmgr_gem->bufmgr.destroy = drm_intel_bufmgr_gem_destroy;
-       bufmgr_gem->bufmgr.debug = 0;
+       bufmgr_gem->bufmgr.debug = 1;
        bufmgr_gem->bufmgr.check_aperture_space =
            drm_intel_gem_check_aperture_space;
        bufmgr_gem->bufmgr.bo_disable_reuse = drm_intel_gem_bo_disable_reuse;
--- libdrm-2.4.49/tests/modetest/modetest.c.~1~ 2013-09-17 13:02:43.000000000 
+0000
+++ libdrm-2.4.49/tests/modetest/modetest.c     2014-01-15 21:51:57.000000000 
+0000
@@ -1185,6 +1185,17 @@ static void test_page_flip(struct device
 
 #define min(a, b)      ((a) < (b) ? (a) : (b))
 
+/* XXX local definition of GNUism for expedience */
+static char *
+strchrnul(const char *s, int c)
+{
+
+       while ((*s != c) && (*s != '\0'))
+               s++;
+
+       return __UNCONST(s);
+}
+
 static int parse_connector(struct pipe_arg *pipe, const char *arg)
 {
        unsigned int len;
--- libdrm-2.4.49/xf86drmMode.c.~1~     2013-08-12 18:01:48.000000000 +0000
+++ libdrm-2.4.49/xf86drmMode.c 2014-01-21 18:13:41.000000000 +0000
@@ -755,6 +755,22 @@ int drmCheckModesettingSupported(const c
        if (found)
                return 0;
 #endif
+#ifdef __NetBSD__
+       int fd;
+       static const struct drm_mode_card_res zero_res;
+       struct drm_mode_card_res res = zero_res;
+       int ret;
+
+       fd = drmOpen(NULL, busid);
+       if (fd == -1)
+               return -EINVAL;
+       if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
+               ret = -errno;
+       else
+               ret = 0;
+       drmClose(fd);
+       return ret;
+#endif
        return -ENOSYS;
 
 }
--- libdrm-2.4.49/xf86drm.c.~1~ 2013-11-22 15:25:06.000000000 +0000
+++ libdrm-2.4.49/xf86drm.c     2014-01-18 01:16:58.000000000 +0000
@@ -505,9 +505,13 @@ static int drmOpenByBusid(const char *bu
            buf = drmGetBusid(fd);
            drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf);
            if (buf && drmMatchBusID(buf, busid, pci_domain_ok)) {
+               drmMsg("drmOpenByBusid: drmMatchBusID returned OK for %d\n",
+                   fd);
                drmFreeBusid(buf);
                return fd;
            }
+           drmMsg("drmOpenByBusid: drmMatchBusID returned mismatch for %d\n",
+               fd);
            if (buf)
                drmFreeBusid(buf);
            close(fd);
@@ -1137,6 +1141,10 @@ int drmClose(int fd)
 int drmMap(int fd, drm_handle_t handle, drmSize size, drmAddressPtr address)
 {
     static unsigned long pagesize_mask = 0;
+#ifdef __NetBSD__              /* XXX */
+    static const struct drm_mmap zero_mmap_req;
+    struct drm_mmap mmap_req = zero_mmap_req;
+#endif
 
     if (fd < 0)
        return -EINVAL;
@@ -1146,9 +1154,20 @@ int drmMap(int fd, drm_handle_t handle, 
 
     size = (size + pagesize_mask) & ~pagesize_mask;
 
+#ifdef __NetBSD__
+    mmap_req.dnm_addr = NULL;
+    mmap_req.dnm_size = size;
+    mmap_req.dnm_prot = (PROT_READ | PROT_WRITE);
+    mmap_req.dnm_flags = MAP_SHARED;
+    mmap_req.dnm_offset = handle;
+    if (drmIoctl(fd, DRM_IOCTL_MMAP, &mmap_req) == -1)
+       return -errno;
+    *address = mmap_req.dnm_addr;
+#else
     *address = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle);
     if (*address == MAP_FAILED)
        return -errno;
+#endif
     return 0;
 }
 
--- xf86-video-intel-2.99.906/src/sna/kgem.c.~1~        2013-11-13 
09:54:29.000000000 +0000
+++ xf86-video-intel-2.99.906/src/sna/kgem.c    2014-01-17 21:21:40.000000000 
+0000
@@ -325,6 +325,7 @@ static void *__kgem_bo_map__gtt(struct k
 {
        struct drm_i915_gem_mmap_gtt mmap_arg;
        void *ptr;
+       int err;
 
        DBG(("%s(handle=%d, size=%d)\n", __FUNCTION__,
             bo->handle, bytes(bo)));
@@ -336,7 +337,7 @@ retry_gtt:
        VG_CLEAR(mmap_arg);
        mmap_arg.handle = bo->handle;
        if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
-               int err = errno;
+               err = errno;
 
                assert(err != EINVAL);
 
@@ -353,11 +354,8 @@ retry_gtt:
        }
 
 retry_mmap:
-       ptr = mmap(0, bytes(bo), PROT_READ | PROT_WRITE, MAP_SHARED,
-                  kgem->fd, mmap_arg.offset);
-       if (ptr == MAP_FAILED) {
-               int err = errno;
-
+       err = -drmMap(kgem->fd, mmap_arg.offset, bytes(bo), &ptr);
+       if (err) {
                assert(err != EINVAL);
 
                if (__kgem_throttle_retire(kgem, 0))


Home | Main Index | Thread Index | Old Index