From 132ba667f4a88bb182e2d2abc7c4e60699398380 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 28 Feb 2008 12:59:39 +1000 Subject: drm: add a check for if modesetting is supported. This is Linux only code, it just uses sysfs to see if a control device has been registered on the requested PCI ID --- libdrm/xf86drmMode.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 52fef81b..717e1fe2 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -41,6 +41,8 @@ #include "xf86drm.h" #include #include +#include +#include #define U642VOID(x) ((void *)(unsigned long)(x)) #define VOID2U64(x) ((uint64_t)(unsigned long)(x)) @@ -571,3 +573,49 @@ int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, return 0; } + +/* + * checks if a modesetting capable driver has attached to the pci id + * returns 0 if modesetting supported. + * -EINVAL or invalid bus id + * -ENOSYS if no modesetting support +*/ +int drmCheckModesettingSupported(const char *busid) +{ +#ifdef __linux__ + char pci_dev_dir[1024]; + char *bus_id_path; + char *bus_type; + int domain, bus, dev, func; + DIR *sysdir; + struct dirent *dent; + int found = 0, ret; + + ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func); + if (ret != 4) + return -EINVAL; + + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/", + domain, bus, dev, func); + + sysdir = opendir(pci_dev_dir); + if (!sysdir) + return -EINVAL; + + dent = readdir(sysdir); + while (dent) { + if (!strncmp(dent->d_name, "drm:controlD", 12)) { + found = 1; + break; + } + + dent = readdir(sysdir); + } + + closedir(sysdir); + if (found) + return 0; +#endif + return -ENOSYS; + +} -- cgit v1.2.3 From 0e72819629741339af46d0e303f33482acdf0972 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 29 Feb 2008 14:07:29 +1000 Subject: drm: change fb api to take a bo handle not the bo pointer. --- libdrm/xf86drmMode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 717e1fe2..dd1a6ca9 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -203,7 +203,8 @@ uint32_t drmModeGetHotplug(int fd) } int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, - uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id) + uint8_t bpp, uint32_t pitch, uint32_t bo_handle, + uint32_t *buf_id) { struct drm_mode_fb_cmd f; int ret; @@ -213,7 +214,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, f.pitch = pitch; f.bpp = bpp; f.depth = depth; - f.handle = bo->handle; + f.handle = bo_handle; if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) return ret; -- cgit v1.2.3 From 81db48536c9d7bb23c448af6a6f1de81df755585 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Mar 2008 10:31:43 +1000 Subject: remove unused functions + include header file --- libdrm/xf86drmMode.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index dd1a6ca9..30b434de 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -36,6 +36,7 @@ * platforms find which headers to include to get uint32_t */ #include +#include #include "xf86drmMode.h" #include "xf86drm.h" @@ -68,27 +69,6 @@ void* drmAllocCpy(void *array, int count, int entry_size) return r; } -/** - * Generate crtc and output ids. - * - * Will generate ids starting from 1 up to count if count is greater then 0. - */ -static uint32_t* drmAllocGenerate(int count) -{ - uint32_t *r; - int i; - - if(0 <= count) - return 0; - - if (!(r = drmMalloc(count*sizeof(*r)))) - return 0; - - for (i = 0; i < count; r[i] = ++i); - - return 0; -} - /* * A couple of free functions. */ -- cgit v1.2.3 From 4aa7efe398911bd58fb348703444a92114e45114 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 5 Mar 2008 10:41:54 +1000 Subject: libdrm: fix warnings in mode code --- libdrm/xf86drmMode.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 30b434de..07b14dbf 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -37,6 +37,7 @@ */ #include #include +#include #include "xf86drmMode.h" #include "xf86drm.h" @@ -125,7 +126,6 @@ void drmModeFreeOutput(drmModeOutputPtr ptr) drmModeResPtr drmModeGetResources(int fd) { struct drm_mode_card_res res; - int i; drmModeResPtr r = 0; memset(&res, 0, sizeof(struct drm_mode_card_res)); @@ -196,7 +196,7 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, f.depth = depth; f.handle = bo_handle; - if (ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f)) + if ((ret = ioctl(fd, DRM_IOCTL_MODE_ADDFB, &f))) return ret; *buf_id = f.buffer_id; @@ -243,7 +243,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) { struct drm_mode_crtc crtc; drmModeCrtcPtr r; - int i = 0; crtc.count_outputs = 0; crtc.outputs = 0; @@ -276,10 +275,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId) r->possibles = crtc.possibles; return r; - -err_allocs: - - return 0; } @@ -433,8 +428,7 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id) { struct drm_mode_get_property prop; drmModePropertyPtr r; - struct drm_mode_property_blob *blob_tmp; - int i; + prop.prop_id = property_id; prop.count_enum_blobs = 0; prop.count_values = 0; @@ -549,7 +543,7 @@ int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id, osp.prop_id = property_id; osp.value = value; - if (ret = ioctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp)) + if ((ret = ioctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp))) return ret; return 0; @@ -565,8 +559,6 @@ int drmCheckModesettingSupported(const char *busid) { #ifdef __linux__ char pci_dev_dir[1024]; - char *bus_id_path; - char *bus_type; int domain, bus, dev, func; DIR *sysdir; struct dirent *dent; -- cgit v1.2.3 From add7d21c79e2bd2012d92bb0043023230ec9aa74 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 7 Mar 2008 08:56:20 +1000 Subject: drm: fixup for new sysfs API --- libdrm/xf86drmMode.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libdrm/xf86drmMode.c') diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 07b14dbf..f86cc48f 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -568,6 +568,25 @@ int drmCheckModesettingSupported(const char *busid) if (ret != 4) return -EINVAL; + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm", + domain, bus, dev, func); + + sysdir = opendir(pci_dev_dir); + if (sysdir) { + dent = readdir(sysdir); + while (dent) { + if (!strncmp(dent->d_name, "controlD", 8)) { + found = 1; + break; + } + + dent = readdir(sysdir); + } + closedir(sysdir); + if (found) + return 0; + } + sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/", domain, bus, dev, func); -- cgit v1.2.3