1diff ... libdrm-2.4.75/xf86drm.c 2--- libdrm-2.4.75-ref/xf86drm.c Fri Jan 27 20:15:16 2017 3+++ libdrm-2.4.75/xf86drm.c Sat Apr 22 13:29:51 2017 4@@ -98,6 +98,11 @@ 5 #endif 6 #endif /* __OpenBSD__ */ 7 8+#if defined(__sun) 9+/* Device majors are dynamic. */ 10+#define DRM_MAJOR (_sun_drm_get_major()) 11+#endif /* __sun */ 12+ 13 #ifndef DRM_MAJOR 14 #define DRM_MAJOR 226 /* Linux */ 15 #endif 16@@ -365,9 +370,14 @@ 17 if (stat(DRM_DIR_NAME, &st)) { 18 if (!isroot) 19 return DRM_ERR_NOT_ROOT; 20+#if defined(__sun) 21+ /* Let the system do this. */ 22+ return DRM_ERR_NO_DEVICE; 23+#else 24 mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE); 25 chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */ 26 chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE); 27+#endif 28 } 29 30 /* Check if the device node exists and create it if necessary. */ 31@@ -374,8 +384,13 @@ 32 if (stat(buf, &st)) { 33 if (!isroot) 34 return DRM_ERR_NOT_ROOT; 35+#if defined(__sun) 36+ /* Let the system do this. */ 37+ return DRM_ERR_NO_DEVICE; 38+#else 39 remove(buf); 40 mknod(buf, S_IFCHR | devmode, dev); 41+#endif 42 } 43 44 if (drm_server_info && drm_server_info->get_perms) { 45@@ -421,6 +436,10 @@ 46 if (st.st_rdev != dev) { 47 if (!isroot) 48 return DRM_ERR_NOT_ROOT; 49+#if defined(__sun) 50+ /* Let the system do this. */ 51+ return DRM_ERR_NO_DEVICE; 52+#else 53 remove(buf); 54 mknod(buf, S_IFCHR | devmode, dev); 55 if (drm_server_info && drm_server_info->get_perms) { 56@@ -427,6 +446,7 @@ 57 chown_check_return(buf, user, group); 58 chmod(buf, devmode); 59 } 60+#endif 61 } 62 fd = open(buf, O_RDWR, 0); 63 drmMsg("drmOpenDevice: open result is %d, (%s)\n", 64@@ -548,6 +568,7 @@ 65 } 66 } 67 68+#ifndef __sun /* Avoid "static unused" warning */ 69 static const char *drmGetMinorName(int type) 70 { 71 switch (type) { 72@@ -561,6 +582,7 @@ 73 return NULL; 74 } 75 } 76+#endif /* __sun */ 77 78 /** 79 * Open the device by bus ID. 80@@ -1124,7 +1146,7 @@ 81 drm_map_t map; 82 83 memclear(map); 84- map.handle = (void *)(uintptr_t)handle; 85+ map.handle = (drm_handle_t)(uintptr_t)handle; 86 87 if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map)) 88 return -errno; 89@@ -2712,6 +2734,15 @@ 90 fstat(fd, &sbuf); 91 d = sbuf.st_rdev; 92 93+#if defined(__sun) 94+ /* 95+ * Get rid of clone-open bits in the minor number. 96+ * See: the drm driver drm_sun_open() 97+ * Don't have DRM_CLONEID_NBITS here. 98+ */ 99+ d &= ~0x3fe00; 100+#endif 101+ 102 for (i = 0; i < DRM_MAX_MINOR; i++) { 103 snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i); 104 if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) 105@@ -2833,6 +2864,25 @@ 106 107 out_close_dir: 108 closedir(sysdir); 109+#elif defined(__sun) /* illumos, OSol */ 110+ struct stat sbuf; 111+ char *path = NULL; 112+ int err, maj, min; 113+ 114+ if (fstat(fd, &sbuf)) 115+ return (NULL); 116+ 117+ maj = major(sbuf.st_rdev); 118+ min = minor(sbuf.st_rdev); 119+ 120+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) 121+ return (NULL); 122+ 123+ /* Walk devices tree looking for this minor */ 124+ err = _sun_drm_find_device(min, &path); 125+ if (err == 0) 126+ return (path); 127+ /* else ... (ret NULL at endif) */ 128 #else 129 struct stat sbuf; 130 char buf[PATH_MAX + 1]; 131@@ -2962,6 +3012,20 @@ 132 return -EINVAL; 133 #elif defined(__OpenBSD__) 134 return DRM_BUS_PCI; 135+#elif defined(__sun) /* illumos, OSol */ 136+ char *path = NULL; 137+ int ret; 138+ 139+ if (maj != DRM_MAJOR) 140+ return -EINVAL; 141+ 142+ ret = _sun_drm_find_device(min, &path); 143+ if (ret != 0) 144+ return (ret); 145+ 146+ ret = _sun_drm_get_subsystem(path); 147+ free(path); 148+ return (ret); 149 #else 150 #warning "Missing implementation of drmParseSubsystemType" 151 return -EINVAL; 152@@ -3017,6 +3081,21 @@ 153 info->func = pinfo.func; 154 155 return 0; 156+#elif defined(__sun) /* illumos, OSol */ 157+ char *path = NULL; 158+ int err; 159+ 160+ if (maj != DRM_MAJOR) 161+ return -EINVAL; 162+ 163+ err = _sun_drm_find_device(min, &path); 164+ if (err != 0) 165+ return (err); 166+ 167+ err = _sun_drm_get_pci_bus_info(path, info); 168+ free(path); 169+ 170+ return err; 171 #else 172 #warning "Missing implementation of drmParsePciBusInfo" 173 return -EINVAL; 174@@ -3182,6 +3261,21 @@ 175 device->subdevice_id = pinfo.subdevice_id; 176 177 return 0; 178+#elif defined(__sun) /* illumos, OSol */ 179+ char *path = NULL; 180+ int err; 181+ 182+ if (maj != DRM_MAJOR) 183+ return -EINVAL; 184+ 185+ err = _sun_drm_find_device(min, &path); 186+ if (err != 0) 187+ return (err); 188+ 189+ err = _sun_drm_get_pci_dev_info(path, device); 190+ free(path); 191+ 192+ return err; 193 #else 194 #warning "Missing implementation of drmParsePciDeviceInfo" 195 return -EINVAL; 196