summaryrefslogtreecommitdiff
path: root/usr/src/common/libdrm/patches/xf86drm-c.patch
blob: 87dffc99482a8c8d4a4ae90e67f0f0a28733d2c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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;