1 #ifdef HAVE_XORG_CONFIG_H
2 #include <xorg-config.h>
5 #ifdef XSERVER_PLATFORM_BUS
13 /* Linux platform device support */
14 #include "xf86_OSproc.h"
17 #include "xf86platformBus.h"
23 get_drm_info(struct OdevAttributes
*attribs
, char *path
, int delayed_index
)
30 fd
= open(path
, O_RDWR
, O_CLOEXEC
);
36 sv
.drm_dd_major
= -1; /* Don't care */
37 sv
.drm_dd_minor
= -1; /* Don't care */
39 err
= drmSetInterfaceVersion(fd
, &sv
);
41 ErrorF("setversion 1.4 failed: %s\n", strerror(-err
));
45 /* for a delayed probe we've already added the device */
46 if (delayed_index
== -1) {
47 xf86_add_platform_device(attribs
);
48 delayed_index
= xf86_num_platform_devices
- 1;
51 buf
= drmGetBusid(fd
);
52 xf86_add_platform_device_attrib(delayed_index
,
53 ODEV_ATTRIB_BUSID
, buf
);
61 xf86PlatformDeviceCheckBusID(struct xf86_platform_device
*device
, const char *busid
)
63 struct OdevAttribute
*attrib
;
64 const char *syspath
= NULL
;
67 xorg_list_for_each_entry(attrib
, &device
->attribs
->list
, member
) {
68 if (attrib
->attrib_id
== ODEV_ATTRIB_SYSPATH
) {
69 syspath
= attrib
->attrib_name
;
77 bustype
= StringToBusType(busid
, &id
);
78 if (bustype
== BUS_PCI
) {
79 struct pci_device
*pPci
= device
->pdev
;
80 if (xf86ComparePciBusString(busid
,
83 pPci
->dev
, pPci
->func
)) {
87 else if (bustype
== BUS_PLATFORM
) {
88 /* match on the minimum string */
91 if (strlen(syspath
) < strlen(id
))
92 len
= strlen(syspath
);
94 if (strncmp(id
, syspath
, len
))
102 xf86PlatformReprobeDevice(int index
, struct OdevAttributes
*attribs
)
106 dpath
= xf86_get_platform_attrib(index
, ODEV_ATTRIB_PATH
);
108 ret
= get_drm_info(attribs
, dpath
, index
);
110 xf86_remove_platform_device(index
);
113 ret
= xf86platformAddDevice(index
);
115 xf86_remove_platform_device(index
);
119 xf86PlatformDeviceProbe(struct OdevAttributes
*attribs
)
121 struct OdevAttribute
*attrib
;
126 xorg_list_for_each_entry(attrib
, &attribs
->list
, member
) {
127 if (attrib
->attrib_id
== ODEV_ATTRIB_PATH
) {
128 path
= attrib
->attrib_name
;
135 for (i
= 0; i
< xf86_num_platform_devices
; i
++) {
137 dpath
= xf86_get_platform_attrib(i
, ODEV_ATTRIB_PATH
);
139 if (!strcmp(path
, dpath
))
143 if (i
!= xf86_num_platform_devices
)
146 LogMessage(X_INFO
, "xfree86: Adding drm device (%s)\n", path
);
148 if (!xf86VTOwner()) {
149 /* if we don't currently own the VT then don't probe the device,
150 just mark it as unowned for later use */
151 attribs
->unowned
= TRUE
;
152 xf86_add_platform_device(attribs
);
156 ret
= get_drm_info(attribs
, path
, -1);
163 config_odev_free_attribute_list(attribs
);
166 void NewGPUDeviceRequest(struct OdevAttributes
*attribs
)
168 int old_num
= xf86_num_platform_devices
;
170 xf86PlatformDeviceProbe(attribs
);
172 if (old_num
== xf86_num_platform_devices
)
175 if (xf86_get_platform_device_unowned(xf86_num_platform_devices
- 1) == TRUE
)
178 ret
= xf86platformAddDevice(xf86_num_platform_devices
-1);
180 xf86_remove_platform_device(xf86_num_platform_devices
-1);
182 ErrorF("xf86: found device %d\n", xf86_num_platform_devices
);
186 void DeleteGPUDeviceRequest(struct OdevAttributes
*attribs
)
188 struct OdevAttribute
*attrib
;
190 char *syspath
= NULL
;
192 xorg_list_for_each_entry(attrib
, &attribs
->list
, member
) {
193 if (attrib
->attrib_id
== ODEV_ATTRIB_SYSPATH
) {
194 syspath
= attrib
->attrib_name
;
199 for (index
= 0; index
< xf86_num_platform_devices
; index
++) {
201 dspath
= xf86_get_platform_attrib(index
, ODEV_ATTRIB_SYSPATH
);
202 if (!strcmp(syspath
, dspath
))
206 if (index
== xf86_num_platform_devices
)
209 ErrorF("xf86: remove device %d %s\n", index
, syspath
);
211 if (xf86_get_platform_device_unowned(index
) == TRUE
)
212 xf86_remove_platform_device(index
);
214 xf86platformRemoveDevice(index
);
216 config_odev_free_attribute_list(attribs
);