diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2013-06-30 11:12:34 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2013-06-30 11:32:24 +0100 |
commit | 40301e6d03f6e8d2d2d01e6bb9f1754a7e543a08 (patch) | |
tree | 85752961213e347e5c3e75741dd49b98961a87ef | |
parent | 17da58f904e75d434aaf71e297e15d41153ba954 (diff) |
sna: Store the path used to open the device and pass to DRI
Avoid having to search the device tree once again in order to simply
recover the path we used to open the device.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/intel_device.c | 32 | ||||
-rw-r--r-- | src/intel_driver.h | 1 | ||||
-rw-r--r-- | src/sna/sna.h | 1 | ||||
-rw-r--r-- | src/sna/sna_dri.c | 4 |
4 files changed, 29 insertions, 9 deletions
diff --git a/src/intel_device.c b/src/intel_device.c index 5c49db03..5c369351 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -42,6 +42,7 @@ #include "intel_driver.h" struct intel_device { + char *path; int fd; int open_count; int master_count; @@ -80,11 +81,11 @@ static int fd_set_cloexec(int fd) return fd; } -static int __intel_open_device(const struct pci_device *pci, const char *path) +static int __intel_open_device(const struct pci_device *pci, char **path) { int fd; - if (path == NULL) { + if (*path == NULL) { char id[20]; int ret; @@ -103,14 +104,21 @@ static int __intel_open_device(const struct pci_device *pci, const char *path) } fd = drmOpen(NULL, id); + if (fd != -1) { + *path = drmGetDeviceNameFromFd(fd); + if (*path == NULL) { + close(fd); + fd = -1; + } + } } else { #ifdef O_CLOEXEC - fd = open(path, O_RDWR | O_CLOEXEC); + fd = open(*path, O_RDWR | O_CLOEXEC); #else fd = -1; #endif if (fd == -1) - fd = fd_set_cloexec(open(path, O_RDWR)); + fd = fd_set_cloexec(open(*path, O_RDWR)); } return fd; @@ -121,6 +129,7 @@ int intel_open_device(int entity_num, const char *path) { struct intel_device *dev; + char *local_path; int fd; if (intel_device_key == -1) @@ -132,16 +141,20 @@ int intel_open_device(int entity_num, if (dev) return dev->fd; - fd = __intel_open_device(pci, path); + local_path = path ? strdup(path) : NULL; + + fd = __intel_open_device(pci, &local_path); if (fd == -1) return -1; dev = malloc(sizeof(*dev)); if (dev == NULL) { + free(local_path); close(fd); return -1; } + dev->path = local_path; dev->fd = fd; dev->open_count = 0; dev->master_count = 0; @@ -190,6 +203,13 @@ int intel_get_device(ScrnInfoPtr scrn) return dev->fd; } +const char *intel_get_device_name(ScrnInfoPtr scrn) +{ + struct intel_device *dev = intel_device(scrn); + assert(dev && dev->path); + return dev->path; +} + int intel_get_master(ScrnInfoPtr scrn) { struct intel_device *dev = intel_device(scrn); @@ -236,6 +256,7 @@ void __intel_uxa_release_device(ScrnInfoPtr scrn) intel_set_device(scrn, NULL); drmClose(dev->fd); + free(dev->path); free(dev); } } @@ -253,5 +274,6 @@ void intel_put_device(ScrnInfoPtr scrn) intel_set_device(scrn, NULL); drmClose(dev->fd); + free(dev->path); free(dev); } diff --git a/src/intel_driver.h b/src/intel_driver.h index ed58444f..22b623ff 100644 --- a/src/intel_driver.h +++ b/src/intel_driver.h @@ -313,6 +313,7 @@ void intel_detect_chipset(ScrnInfoPtr scrn, int intel_open_device(int entity_num, const struct pci_device *pci, const char *path); int intel_get_device(ScrnInfoPtr scrn); +const char *intel_get_device_name(ScrnInfoPtr scrn); int intel_get_master(ScrnInfoPtr scrn); int intel_put_master(ScrnInfoPtr scrn); void intel_put_device(ScrnInfoPtr scrn); diff --git a/src/sna/sna.h b/src/sna/sna.h index f720c64f..7fe73597 100644 --- a/src/sna/sna.h +++ b/src/sna/sna.h @@ -293,7 +293,6 @@ struct sna { bool dri_available; bool dri_open; - char *deviceName; /* Broken-out options. */ OptionInfoPtr Options; diff --git a/src/sna/sna_dri.c b/src/sna/sna_dri.c index e610d521..ca5f0889 100644 --- a/src/sna/sna_dri.c +++ b/src/sna/sna_dri.c @@ -2445,11 +2445,10 @@ bool sna_dri_open(struct sna *sna, ScreenPtr screen) return false; } - sna->deviceName = drmGetDeviceNameFromFd(sna->kgem.fd); memset(&info, '\0', sizeof(info)); info.fd = sna->kgem.fd; info.driverName = dri_driver_name(sna); - info.deviceName = sna->deviceName; + info.deviceName = intel_get_device_name(sna->scrn); DBG(("%s: loading dri driver '%s' [gen=%d] for device '%s'\n", __FUNCTION__, info.driverName, sna->kgem.gen, info.deviceName)); @@ -2487,5 +2486,4 @@ void sna_dri_close(struct sna *sna, ScreenPtr screen) { DBG(("%s()\n", __FUNCTION__)); DRI2CloseScreen(screen); - drmFree(sna->deviceName); } |