aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie2008-01-08 23:44:31 -0600
committerDave Airlie2008-01-08 23:44:31 -0600
commit73bf5e867089b58b2c4baaa833d15a2b1fb268a4 (patch)
treed76cc72f9319403f914de40ea42c4ec2fb7ab261
parent8d6e3c208f8090ccc32ef3a38c58f2aca7f4be2a (diff)
downloadexternal-libdrm-73bf5e867089b58b2c4baaa833d15a2b1fb268a4.tar.gz
external-libdrm-73bf5e867089b58b2c4baaa833d15a2b1fb268a4.tar.xz
external-libdrm-73bf5e867089b58b2c4baaa833d15a2b1fb268a4.zip
add internals for opening a control node
-rw-r--r--libdrm/xf86drm.c21
-rw-r--r--libdrm/xf86drm.h1
-rw-r--r--tests/dristat.c2
3 files changed, 14 insertions, 10 deletions
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 4265c320..2d7d85c1 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -87,6 +87,9 @@
87 87
88#define DRM_MSG_VERBOSITY 3 88#define DRM_MSG_VERBOSITY 3
89 89
90#define DRM_NODE_CONTROL 0
91#define DRM_NODE_RENDER 1
92
90static drmServerInfoPtr drm_server_info; 93static drmServerInfoPtr drm_server_info;
91 94
92void drmSetServerInfo(drmServerInfoPtr info) 95void drmSetServerInfo(drmServerInfoPtr info)
@@ -264,7 +267,7 @@ static int drmMatchBusID(const char *id1, const char *id2)
264 * special file node with the major and minor numbers specified by \p dev and 267 * special file node with the major and minor numbers specified by \p dev and
265 * parent directory if necessary and was called by root. 268 * parent directory if necessary and was called by root.
266 */ 269 */
267static int drmOpenDevice(long dev, int minor) 270static int drmOpenDevice(long dev, int minor, int type)
268{ 271{
269 stat_t st; 272 stat_t st;
270 char buf[64]; 273 char buf[64];
@@ -274,7 +277,7 @@ static int drmOpenDevice(long dev, int minor)
274 uid_t user = DRM_DEV_UID; 277 uid_t user = DRM_DEV_UID;
275 gid_t group = DRM_DEV_GID, serv_group; 278 gid_t group = DRM_DEV_GID, serv_group;
276 279
277 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); 280 sprintf(buf, type ? DRM_DEV_NAME : DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, minor);
278 drmMsg("drmOpenDevice: node name is %s\n", buf); 281 drmMsg("drmOpenDevice: node name is %s\n", buf);
279 282
280 if (drm_server_info) { 283 if (drm_server_info) {
@@ -348,15 +351,15 @@ static int drmOpenDevice(long dev, int minor)
348 * Calls drmOpenDevice() if \p create is set, otherwise assembles the device 351 * Calls drmOpenDevice() if \p create is set, otherwise assembles the device
349 * name from \p minor and opens it. 352 * name from \p minor and opens it.
350 */ 353 */
351static int drmOpenMinor(int minor, int create) 354static int drmOpenMinor(int minor, int create, int type)
352{ 355{
353 int fd; 356 int fd;
354 char buf[64]; 357 char buf[64];
355 358
356 if (create) 359 if (create)
357 return drmOpenDevice(makedev(DRM_MAJOR, minor), minor); 360 return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type);
358 361
359 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor); 362 sprintf(buf, type ? DRM_DEV_NAME : DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, minor);
360 if ((fd = open(buf, O_RDWR, 0)) >= 0) 363 if ((fd = open(buf, O_RDWR, 0)) >= 0)
361 return fd; 364 return fd;
362 return -errno; 365 return -errno;
@@ -379,7 +382,7 @@ int drmAvailable(void)
379 int retval = 0; 382 int retval = 0;
380 int fd; 383 int fd;
381 384
382 if ((fd = drmOpenMinor(0, 1)) < 0) { 385 if ((fd = drmOpenMinor(0, 1, DRM_NODE_RENDER)) < 0) {
383#ifdef __linux__ 386#ifdef __linux__
384 /* Try proc for backward Linux compatibility */ 387 /* Try proc for backward Linux compatibility */
385 if (!access("/proc/dri/0", R_OK)) 388 if (!access("/proc/dri/0", R_OK))
@@ -420,7 +423,7 @@ static int drmOpenByBusid(const char *busid)
420 423
421 drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); 424 drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid);
422 for (i = 0; i < DRM_MAX_MINOR; i++) { 425 for (i = 0; i < DRM_MAX_MINOR; i++) {
423 fd = drmOpenMinor(i, 1); 426 fd = drmOpenMinor(i, 1, DRM_NODE_RENDER);
424 drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); 427 drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd);
425 if (fd >= 0) { 428 if (fd >= 0) {
426 sv.drm_di_major = 1; 429 sv.drm_di_major = 1;
@@ -482,7 +485,7 @@ static int drmOpenByName(const char *name)
482 * already in use. If it's in use it will have a busid assigned already. 485 * already in use. If it's in use it will have a busid assigned already.
483 */ 486 */
484 for (i = 0; i < DRM_MAX_MINOR; i++) { 487 for (i = 0; i < DRM_MAX_MINOR; i++) {
485 if ((fd = drmOpenMinor(i, 1)) >= 0) { 488 if ((fd = drmOpenMinor(i, 1, DRM_NODE_RENDER)) >= 0) {
486 if ((version = drmGetVersion(fd))) { 489 if ((version = drmGetVersion(fd))) {
487 if (!strcmp(version->name, name)) { 490 if (!strcmp(version->name, name)) {
488 drmFreeVersion(version); 491 drmFreeVersion(version);
@@ -526,7 +529,7 @@ static int drmOpenByName(const char *name)
526 if (*pt) { /* Found busid */ 529 if (*pt) { /* Found busid */
527 return drmOpenByBusid(++pt); 530 return drmOpenByBusid(++pt);
528 } else { /* No busid */ 531 } else { /* No busid */
529 return drmOpenDevice(strtol(devstring, NULL, 0),i); 532 return drmOpenDevice(strtol(devstring, NULL, 0),i, DRM_NODE_RENDER);
530 } 533 }
531 } 534 }
532 } 535 }
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 230f54ce..d6e98825 100644
--- a/libdrm/xf86drm.h
+++ b/libdrm/xf86drm.h
@@ -49,6 +49,7 @@
49 49
50#define DRM_DIR_NAME "/dev/dri" 50#define DRM_DIR_NAME "/dev/dri"
51#define DRM_DEV_NAME "%s/card%d" 51#define DRM_DEV_NAME "%s/card%d"
52#define DRM_CONTROL_DEV_NAME "%s/controlD%d"
52#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */ 53#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
53 54
54#define DRM_ERR_NO_DEVICE (-1001) 55#define DRM_ERR_NO_DEVICE (-1001)
diff --git a/tests/dristat.c b/tests/dristat.c
index 89853164..48c3b51b 100644
--- a/tests/dristat.c
+++ b/tests/dristat.c
@@ -263,7 +263,7 @@ int main(int argc, char **argv)
263 263
264 for (i = 0; i < 16; i++) if (!minor || i == minor) { 264 for (i = 0; i < 16; i++) if (!minor || i == minor) {
265 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i); 265 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
266 fd = drmOpenMinor(i, 1); 266 fd = drmOpenMinor(i, 1, DRM_NODE_RENDER);
267 if (fd >= 0) { 267 if (fd >= 0) {
268 printf("%s\n", buf); 268 printf("%s\n", buf);
269 if (mask & DRM_BUSID) getbusid(fd); 269 if (mask & DRM_BUSID) getbusid(fd);