diff ... libdrm-2.4.75/xf86drm.c --- libdrm-2.4.75-ref/xf86drm.c Fri Jan 27 20:15:16 2017 +++ libdrm-2.4.75/xf86drm.c Sat Apr 22 13:29:51 2017 @@ -98,6 +98,11 @@ #endif #endif /* __OpenBSD__ */ +#if defined(__sun) +/* Device majors are dynamic. */ +#define DRM_MAJOR (_sun_drm_get_major()) +#endif /* __sun */ + #ifndef DRM_MAJOR #define DRM_MAJOR 226 /* Linux */ #endif @@ -365,9 +370,14 @@ if (stat(DRM_DIR_NAME, &st)) { if (!isroot) return DRM_ERR_NOT_ROOT; +#if defined(__sun) + /* Let the system do this. */ + return DRM_ERR_NO_DEVICE; +#else mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE); chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */ chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE); +#endif } /* Check if the device node exists and create it if necessary. */ @@ -374,8 +384,13 @@ if (stat(buf, &st)) { if (!isroot) return DRM_ERR_NOT_ROOT; +#if defined(__sun) + /* Let the system do this. */ + return DRM_ERR_NO_DEVICE; +#else remove(buf); mknod(buf, S_IFCHR | devmode, dev); +#endif } if (drm_server_info && drm_server_info->get_perms) { @@ -421,6 +436,10 @@ if (st.st_rdev != dev) { if (!isroot) return DRM_ERR_NOT_ROOT; +#if defined(__sun) + /* Let the system do this. */ + return DRM_ERR_NO_DEVICE; +#else remove(buf); mknod(buf, S_IFCHR | devmode, dev); if (drm_server_info && drm_server_info->get_perms) { @@ -427,6 +446,7 @@ chown_check_return(buf, user, group); chmod(buf, devmode); } +#endif } fd = open(buf, O_RDWR, 0); drmMsg("drmOpenDevice: open result is %d, (%s)\n", @@ -548,6 +568,7 @@ } } +#ifndef __sun /* Avoid "static unused" warning */ static const char *drmGetMinorName(int type) { switch (type) { @@ -561,6 +582,7 @@ return NULL; } } +#endif /* __sun */ /** * Open the device by bus ID. @@ -1124,7 +1146,7 @@ drm_map_t map; memclear(map); - map.handle = (void *)(uintptr_t)handle; + map.handle = (drm_handle_t)(uintptr_t)handle; if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map)) return -errno; @@ -2712,6 +2734,15 @@ fstat(fd, &sbuf); d = sbuf.st_rdev; +#if defined(__sun) + /* + * Get rid of clone-open bits in the minor number. + * See: the drm driver drm_sun_open() + * Don't have DRM_CLONEID_NBITS here. + */ + d &= ~0x3fe00; +#endif + for (i = 0; i < DRM_MAX_MINOR; i++) { snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i); if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) @@ -2833,6 +2864,25 @@ out_close_dir: closedir(sysdir); +#elif defined(__sun) /* illumos, OSol */ + struct stat sbuf; + char *path = NULL; + int err, maj, min; + + if (fstat(fd, &sbuf)) + return (NULL); + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + return (NULL); + + /* Walk devices tree looking for this minor */ + err = _sun_drm_find_device(min, &path); + if (err == 0) + return (path); + /* else ... (ret NULL at endif) */ #else struct stat sbuf; char buf[PATH_MAX + 1]; @@ -2962,6 +3012,20 @@ return -EINVAL; #elif defined(__OpenBSD__) return DRM_BUS_PCI; +#elif defined(__sun) /* illumos, OSol */ + char *path = NULL; + int ret; + + if (maj != DRM_MAJOR) + return -EINVAL; + + ret = _sun_drm_find_device(min, &path); + if (ret != 0) + return (ret); + + ret = _sun_drm_get_subsystem(path); + free(path); + return (ret); #else #warning "Missing implementation of drmParseSubsystemType" return -EINVAL; @@ -3017,6 +3081,21 @@ info->func = pinfo.func; return 0; +#elif defined(__sun) /* illumos, OSol */ + char *path = NULL; + int err; + + if (maj != DRM_MAJOR) + return -EINVAL; + + err = _sun_drm_find_device(min, &path); + if (err != 0) + return (err); + + err = _sun_drm_get_pci_bus_info(path, info); + free(path); + + return err; #else #warning "Missing implementation of drmParsePciBusInfo" return -EINVAL; @@ -3182,6 +3261,21 @@ device->subdevice_id = pinfo.subdevice_id; return 0; +#elif defined(__sun) /* illumos, OSol */ + char *path = NULL; + int err; + + if (maj != DRM_MAJOR) + return -EINVAL; + + err = _sun_drm_find_device(min, &path); + if (err != 0) + return (err); + + err = _sun_drm_get_pci_dev_info(path, device); + free(path); + + return err; #else #warning "Missing implementation of drmParsePciDeviceInfo" return -EINVAL;