diff options
-rw-r--r-- | xf86drm.c | 1444 |
1 files changed, 721 insertions, 723 deletions
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * \file xf86drm.c | 2 | * \file xf86drm.c |
3 | * User-level interface to DRM device | 3 | * User-level interface to DRM device |
4 | * | 4 | * |
5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> | 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
@@ -70,13 +70,13 @@ | |||
70 | #include "util_math.h" | 70 | #include "util_math.h" |
71 | 71 | ||
72 | #ifdef __OpenBSD__ | 72 | #ifdef __OpenBSD__ |
73 | #define DRM_PRIMARY_MINOR_NAME "drm" | 73 | #define DRM_PRIMARY_MINOR_NAME "drm" |
74 | #define DRM_CONTROL_MINOR_NAME "drmC" | 74 | #define DRM_CONTROL_MINOR_NAME "drmC" |
75 | #define DRM_RENDER_MINOR_NAME "drmR" | 75 | #define DRM_RENDER_MINOR_NAME "drmR" |
76 | #else | 76 | #else |
77 | #define DRM_PRIMARY_MINOR_NAME "card" | 77 | #define DRM_PRIMARY_MINOR_NAME "card" |
78 | #define DRM_CONTROL_MINOR_NAME "controlD" | 78 | #define DRM_CONTROL_MINOR_NAME "controlD" |
79 | #define DRM_RENDER_MINOR_NAME "renderD" | 79 | #define DRM_RENDER_MINOR_NAME "renderD" |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) | 82 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
@@ -96,7 +96,7 @@ | |||
96 | #endif /* __OpenBSD__ */ | 96 | #endif /* __OpenBSD__ */ |
97 | 97 | ||
98 | #ifndef DRM_MAJOR | 98 | #ifndef DRM_MAJOR |
99 | #define DRM_MAJOR 226 /* Linux */ | 99 | #define DRM_MAJOR 226 /* Linux */ |
100 | #endif | 100 | #endif |
101 | 101 | ||
102 | #define DRM_MSG_VERBOSITY 3 | 102 | #define DRM_MSG_VERBOSITY 3 |
@@ -128,18 +128,18 @@ drmDebugPrint(const char *format, va_list ap) | |||
128 | void | 128 | void |
129 | drmMsg(const char *format, ...) | 129 | drmMsg(const char *format, ...) |
130 | { | 130 | { |
131 | va_list ap; | 131 | va_list ap; |
132 | const char *env; | 132 | const char *env; |
133 | if (((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) || | 133 | if (((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) || |
134 | (drm_server_info && drm_server_info->debug_print)) | 134 | (drm_server_info && drm_server_info->debug_print)) |
135 | { | 135 | { |
136 | va_start(ap, format); | 136 | va_start(ap, format); |
137 | if (drm_server_info) { | 137 | if (drm_server_info) { |
138 | drm_server_info->debug_print(format,ap); | 138 | drm_server_info->debug_print(format,ap); |
139 | } else { | 139 | } else { |
140 | drmDebugPrint(format, ap); | 140 | drmDebugPrint(format, ap); |
141 | } | 141 | } |
142 | va_end(ap); | 142 | va_end(ap); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
@@ -166,10 +166,10 @@ void drmFree(void *pt) | |||
166 | int | 166 | int |
167 | drmIoctl(int fd, unsigned long request, void *arg) | 167 | drmIoctl(int fd, unsigned long request, void *arg) |
168 | { | 168 | { |
169 | int ret; | 169 | int ret; |
170 | 170 | ||
171 | do { | 171 | do { |
172 | ret = ioctl(fd, request, arg); | 172 | ret = ioctl(fd, request, arg); |
173 | } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); | 173 | } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); |
174 | return ret; | 174 | return ret; |
175 | } | 175 | } |
@@ -190,16 +190,16 @@ drmHashEntry *drmGetEntry(int fd) | |||
190 | drmHashEntry *entry; | 190 | drmHashEntry *entry; |
191 | 191 | ||
192 | if (!drmHashTable) | 192 | if (!drmHashTable) |
193 | drmHashTable = drmHashCreate(); | 193 | drmHashTable = drmHashCreate(); |
194 | 194 | ||
195 | if (drmHashLookup(drmHashTable, key, &value)) { | 195 | if (drmHashLookup(drmHashTable, key, &value)) { |
196 | entry = drmMalloc(sizeof(*entry)); | 196 | entry = drmMalloc(sizeof(*entry)); |
197 | entry->fd = fd; | 197 | entry->fd = fd; |
198 | entry->f = NULL; | 198 | entry->f = NULL; |
199 | entry->tagTable = drmHashCreate(); | 199 | entry->tagTable = drmHashCreate(); |
200 | drmHashInsert(drmHashTable, key, entry); | 200 | drmHashInsert(drmHashTable, key, entry); |
201 | } else { | 201 | } else { |
202 | entry = value; | 202 | entry = value; |
203 | } | 203 | } |
204 | return entry; | 204 | return entry; |
205 | } | 205 | } |
@@ -221,41 +221,41 @@ static int drmMatchBusID(const char *id1, const char *id2, int pci_domain_ok) | |||
221 | { | 221 | { |
222 | /* First, check if the IDs are exactly the same */ | 222 | /* First, check if the IDs are exactly the same */ |
223 | if (strcasecmp(id1, id2) == 0) | 223 | if (strcasecmp(id1, id2) == 0) |
224 | return 1; | 224 | return 1; |
225 | 225 | ||
226 | /* Try to match old/new-style PCI bus IDs. */ | 226 | /* Try to match old/new-style PCI bus IDs. */ |
227 | if (strncasecmp(id1, "pci", 3) == 0) { | 227 | if (strncasecmp(id1, "pci", 3) == 0) { |
228 | unsigned int o1, b1, d1, f1; | 228 | unsigned int o1, b1, d1, f1; |
229 | unsigned int o2, b2, d2, f2; | 229 | unsigned int o2, b2, d2, f2; |
230 | int ret; | 230 | int ret; |
231 | 231 | ||
232 | ret = sscanf(id1, "pci:%04x:%02x:%02x.%u", &o1, &b1, &d1, &f1); | 232 | ret = sscanf(id1, "pci:%04x:%02x:%02x.%u", &o1, &b1, &d1, &f1); |
233 | if (ret != 4) { | 233 | if (ret != 4) { |
234 | o1 = 0; | 234 | o1 = 0; |
235 | ret = sscanf(id1, "PCI:%u:%u:%u", &b1, &d1, &f1); | 235 | ret = sscanf(id1, "PCI:%u:%u:%u", &b1, &d1, &f1); |
236 | if (ret != 3) | 236 | if (ret != 3) |
237 | return 0; | 237 | return 0; |
238 | } | 238 | } |
239 | 239 | ||
240 | ret = sscanf(id2, "pci:%04x:%02x:%02x.%u", &o2, &b2, &d2, &f2); | 240 | ret = sscanf(id2, "pci:%04x:%02x:%02x.%u", &o2, &b2, &d2, &f2); |
241 | if (ret != 4) { | 241 | if (ret != 4) { |
242 | o2 = 0; | 242 | o2 = 0; |
243 | ret = sscanf(id2, "PCI:%u:%u:%u", &b2, &d2, &f2); | 243 | ret = sscanf(id2, "PCI:%u:%u:%u", &b2, &d2, &f2); |
244 | if (ret != 3) | 244 | if (ret != 3) |
245 | return 0; | 245 | return 0; |
246 | } | 246 | } |
247 | 247 | ||
248 | /* If domains aren't properly supported by the kernel interface, | 248 | /* If domains aren't properly supported by the kernel interface, |
249 | * just ignore them, which sucks less than picking a totally random | 249 | * just ignore them, which sucks less than picking a totally random |
250 | * card with "open by name" | 250 | * card with "open by name" |
251 | */ | 251 | */ |
252 | if (!pci_domain_ok) | 252 | if (!pci_domain_ok) |
253 | o1 = o2 = 0; | 253 | o1 = o2 = 0; |
254 | 254 | ||
255 | if ((o1 != o2) || (b1 != b2) || (d1 != d2) || (f1 != f2)) | 255 | if ((o1 != o2) || (b1 != b2) || (d1 != d2) || (f1 != f2)) |
256 | return 0; | 256 | return 0; |
257 | else | 257 | else |
258 | return 1; | 258 | return 1; |
259 | } | 259 | } |
260 | return 0; | 260 | return 0; |
261 | } | 261 | } |
@@ -277,18 +277,18 @@ static int drmMatchBusID(const char *id1, const char *id2, int pci_domain_ok) | |||
277 | #if !defined(UDEV) | 277 | #if !defined(UDEV) |
278 | static int chown_check_return(const char *path, uid_t owner, gid_t group) | 278 | static int chown_check_return(const char *path, uid_t owner, gid_t group) |
279 | { | 279 | { |
280 | int rv; | 280 | int rv; |
281 | 281 | ||
282 | do { | 282 | do { |
283 | rv = chown(path, owner, group); | 283 | rv = chown(path, owner, group); |
284 | } while (rv != 0 && errno == EINTR); | 284 | } while (rv != 0 && errno == EINTR); |
285 | 285 | ||
286 | if (rv == 0) | 286 | if (rv == 0) |
287 | return 0; | 287 | return 0; |
288 | 288 | ||
289 | drmMsg("Failed to change owner or group for file %s! %d: %s\n", | 289 | drmMsg("Failed to change owner or group for file %s! %d: %s\n", |
290 | path, errno, strerror(errno)); | 290 | path, errno, strerror(errno)); |
291 | return -1; | 291 | return -1; |
292 | } | 292 | } |
293 | #endif | 293 | #endif |
294 | 294 | ||
@@ -297,7 +297,7 @@ static int chown_check_return(const char *path, uid_t owner, gid_t group) | |||
297 | * | 297 | * |
298 | * \param dev major and minor numbers of the device. | 298 | * \param dev major and minor numbers of the device. |
299 | * \param minor minor number of the device. | 299 | * \param minor minor number of the device. |
300 | * | 300 | * |
301 | * \return a file descriptor on success, or a negative value on error. | 301 | * \return a file descriptor on success, or a negative value on error. |
302 | * | 302 | * |
303 | * \internal | 303 | * \internal |
@@ -321,99 +321,99 @@ static int drmOpenDevice(dev_t dev, int minor, int type) | |||
321 | 321 | ||
322 | switch (type) { | 322 | switch (type) { |
323 | case DRM_NODE_PRIMARY: | 323 | case DRM_NODE_PRIMARY: |
324 | dev_name = DRM_DEV_NAME; | 324 | dev_name = DRM_DEV_NAME; |
325 | break; | 325 | break; |
326 | case DRM_NODE_CONTROL: | 326 | case DRM_NODE_CONTROL: |
327 | dev_name = DRM_CONTROL_DEV_NAME; | 327 | dev_name = DRM_CONTROL_DEV_NAME; |
328 | break; | 328 | break; |
329 | case DRM_NODE_RENDER: | 329 | case DRM_NODE_RENDER: |
330 | dev_name = DRM_RENDER_DEV_NAME; | 330 | dev_name = DRM_RENDER_DEV_NAME; |
331 | break; | 331 | break; |
332 | default: | 332 | default: |
333 | return -EINVAL; | 333 | return -EINVAL; |
334 | }; | 334 | }; |
335 | 335 | ||
336 | sprintf(buf, dev_name, DRM_DIR_NAME, minor); | 336 | sprintf(buf, dev_name, DRM_DIR_NAME, minor); |
337 | drmMsg("drmOpenDevice: node name is %s\n", buf); | 337 | drmMsg("drmOpenDevice: node name is %s\n", buf); |
338 | 338 | ||
339 | if (drm_server_info && drm_server_info->get_perms) { | 339 | if (drm_server_info && drm_server_info->get_perms) { |
340 | drm_server_info->get_perms(&serv_group, &serv_mode); | 340 | drm_server_info->get_perms(&serv_group, &serv_mode); |
341 | devmode = serv_mode ? serv_mode : DRM_DEV_MODE; | 341 | devmode = serv_mode ? serv_mode : DRM_DEV_MODE; |
342 | devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH); | 342 | devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH); |
343 | } | 343 | } |
344 | 344 | ||
345 | #if !defined(UDEV) | 345 | #if !defined(UDEV) |
346 | if (stat(DRM_DIR_NAME, &st)) { | 346 | if (stat(DRM_DIR_NAME, &st)) { |
347 | if (!isroot) | 347 | if (!isroot) |
348 | return DRM_ERR_NOT_ROOT; | 348 | return DRM_ERR_NOT_ROOT; |
349 | mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE); | 349 | mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE); |
350 | chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */ | 350 | chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */ |
351 | chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE); | 351 | chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE); |
352 | } | 352 | } |
353 | 353 | ||
354 | /* Check if the device node exists and create it if necessary. */ | 354 | /* Check if the device node exists and create it if necessary. */ |
355 | if (stat(buf, &st)) { | 355 | if (stat(buf, &st)) { |
356 | if (!isroot) | 356 | if (!isroot) |
357 | return DRM_ERR_NOT_ROOT; | 357 | return DRM_ERR_NOT_ROOT; |
358 | remove(buf); | 358 | remove(buf); |
359 | mknod(buf, S_IFCHR | devmode, dev); | 359 | mknod(buf, S_IFCHR | devmode, dev); |
360 | } | 360 | } |
361 | 361 | ||
362 | if (drm_server_info && drm_server_info->get_perms) { | 362 | if (drm_server_info && drm_server_info->get_perms) { |
363 | group = ((int)serv_group >= 0) ? serv_group : DRM_DEV_GID; | 363 | group = ((int)serv_group >= 0) ? serv_group : DRM_DEV_GID; |
364 | chown_check_return(buf, user, group); | 364 | chown_check_return(buf, user, group); |
365 | chmod(buf, devmode); | 365 | chmod(buf, devmode); |
366 | } | 366 | } |
367 | #else | 367 | #else |
368 | /* if we modprobed then wait for udev */ | 368 | /* if we modprobed then wait for udev */ |
369 | { | 369 | { |
370 | int udev_count = 0; | 370 | int udev_count = 0; |
371 | wait_for_udev: | 371 | wait_for_udev: |
372 | if (stat(DRM_DIR_NAME, &st)) { | 372 | if (stat(DRM_DIR_NAME, &st)) { |
373 | usleep(20); | 373 | usleep(20); |
374 | udev_count++; | 374 | udev_count++; |
375 | 375 | ||
376 | if (udev_count == 50) | 376 | if (udev_count == 50) |
377 | return -1; | 377 | return -1; |
378 | goto wait_for_udev; | 378 | goto wait_for_udev; |
379 | } | 379 | } |
380 | 380 | ||
381 | if (stat(buf, &st)) { | 381 | if (stat(buf, &st)) { |
382 | usleep(20); | 382 | usleep(20); |
383 | udev_count++; | 383 | udev_count++; |
384 | 384 | ||
385 | if (udev_count == 50) | 385 | if (udev_count == 50) |
386 | return -1; | 386 | return -1; |
387 | goto wait_for_udev; | 387 | goto wait_for_udev; |
388 | } | 388 | } |
389 | } | 389 | } |
390 | #endif | 390 | #endif |
391 | 391 | ||
392 | fd = open(buf, O_RDWR, 0); | 392 | fd = open(buf, O_RDWR, 0); |
393 | drmMsg("drmOpenDevice: open result is %d, (%s)\n", | 393 | drmMsg("drmOpenDevice: open result is %d, (%s)\n", |
394 | fd, fd < 0 ? strerror(errno) : "OK"); | 394 | fd, fd < 0 ? strerror(errno) : "OK"); |
395 | if (fd >= 0) | 395 | if (fd >= 0) |
396 | return fd; | 396 | return fd; |
397 | 397 | ||
398 | #if !defined(UDEV) | 398 | #if !defined(UDEV) |
399 | /* Check if the device node is not what we expect it to be, and recreate it | 399 | /* Check if the device node is not what we expect it to be, and recreate it |
400 | * and try again if so. | 400 | * and try again if so. |
401 | */ | 401 | */ |
402 | if (st.st_rdev != dev) { | 402 | if (st.st_rdev != dev) { |
403 | if (!isroot) | 403 | if (!isroot) |
404 | return DRM_ERR_NOT_ROOT; | 404 | return DRM_ERR_NOT_ROOT; |
405 | remove(buf); | 405 | remove(buf); |
406 | mknod(buf, S_IFCHR | devmode, dev); | 406 | mknod(buf, S_IFCHR | devmode, dev); |
407 | if (drm_server_info && drm_server_info->get_perms) { | 407 | if (drm_server_info && drm_server_info->get_perms) { |
408 | chown_check_return(buf, user, group); | 408 | chown_check_return(buf, user, group); |
409 | chmod(buf, devmode); | 409 | chmod(buf, devmode); |
410 | } | 410 | } |
411 | } | 411 | } |
412 | fd = open(buf, O_RDWR, 0); | 412 | fd = open(buf, O_RDWR, 0); |
413 | drmMsg("drmOpenDevice: open result is %d, (%s)\n", | 413 | drmMsg("drmOpenDevice: open result is %d, (%s)\n", |
414 | fd, fd < 0 ? strerror(errno) : "OK"); | 414 | fd, fd < 0 ? strerror(errno) : "OK"); |
415 | if (fd >= 0) | 415 | if (fd >= 0) |
416 | return fd; | 416 | return fd; |
417 | 417 | ||
418 | drmMsg("drmOpenDevice: Open failed\n"); | 418 | drmMsg("drmOpenDevice: Open failed\n"); |
419 | remove(buf); | 419 | remove(buf); |
@@ -429,7 +429,7 @@ wait_for_udev: | |||
429 | * \param create allow to create the device if set. | 429 | * \param create allow to create the device if set. |
430 | * | 430 | * |
431 | * \return a file descriptor on success, or a negative value on error. | 431 | * \return a file descriptor on success, or a negative value on error. |
432 | * | 432 | * |
433 | * \internal | 433 | * \internal |
434 | * Calls drmOpenDevice() if \p create is set, otherwise assembles the device | 434 | * Calls drmOpenDevice() if \p create is set, otherwise assembles the device |
435 | * name from \p minor and opens it. | 435 | * name from \p minor and opens it. |
@@ -439,37 +439,37 @@ static int drmOpenMinor(int minor, int create, int type) | |||
439 | int fd; | 439 | int fd; |
440 | char buf[64]; | 440 | char buf[64]; |
441 | const char *dev_name; | 441 | const char *dev_name; |
442 | 442 | ||
443 | if (create) | 443 | if (create) |
444 | return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); | 444 | return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); |
445 | 445 | ||
446 | switch (type) { | 446 | switch (type) { |
447 | case DRM_NODE_PRIMARY: | 447 | case DRM_NODE_PRIMARY: |
448 | dev_name = DRM_DEV_NAME; | 448 | dev_name = DRM_DEV_NAME; |
449 | break; | 449 | break; |
450 | case DRM_NODE_CONTROL: | 450 | case DRM_NODE_CONTROL: |
451 | dev_name = DRM_CONTROL_DEV_NAME; | 451 | dev_name = DRM_CONTROL_DEV_NAME; |
452 | break; | 452 | break; |
453 | case DRM_NODE_RENDER: | 453 | case DRM_NODE_RENDER: |
454 | dev_name = DRM_RENDER_DEV_NAME; | 454 | dev_name = DRM_RENDER_DEV_NAME; |
455 | break; | 455 | break; |
456 | default: | 456 | default: |
457 | return -EINVAL; | 457 | return -EINVAL; |
458 | }; | 458 | }; |
459 | 459 | ||
460 | sprintf(buf, dev_name, DRM_DIR_NAME, minor); | 460 | sprintf(buf, dev_name, DRM_DIR_NAME, minor); |
461 | if ((fd = open(buf, O_RDWR, 0)) >= 0) | 461 | if ((fd = open(buf, O_RDWR, 0)) >= 0) |
462 | return fd; | 462 | return fd; |
463 | return -errno; | 463 | return -errno; |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | /** | 467 | /** |
468 | * Determine whether the DRM kernel driver has been loaded. | 468 | * Determine whether the DRM kernel driver has been loaded. |
469 | * | 469 | * |
470 | * \return 1 if the DRM driver is loaded, 0 otherwise. | 470 | * \return 1 if the DRM driver is loaded, 0 otherwise. |
471 | * | 471 | * |
472 | * \internal | 472 | * \internal |
473 | * Determine the presence of the kernel driver by attempting to open the 0 | 473 | * Determine the presence of the kernel driver by attempting to open the 0 |
474 | * minor and get version information. For backward compatibility with older | 474 | * minor and get version information. For backward compatibility with older |
475 | * Linux implementations, /proc/dri is also checked. | 475 | * Linux implementations, /proc/dri is also checked. |
@@ -482,16 +482,16 @@ int drmAvailable(void) | |||
482 | 482 | ||
483 | if ((fd = drmOpenMinor(0, 1, DRM_NODE_PRIMARY)) < 0) { | 483 | if ((fd = drmOpenMinor(0, 1, DRM_NODE_PRIMARY)) < 0) { |
484 | #ifdef __linux__ | 484 | #ifdef __linux__ |
485 | /* Try proc for backward Linux compatibility */ | 485 | /* Try proc for backward Linux compatibility */ |
486 | if (!access("/proc/dri/0", R_OK)) | 486 | if (!access("/proc/dri/0", R_OK)) |
487 | return 1; | 487 | return 1; |
488 | #endif | 488 | #endif |
489 | return 0; | 489 | return 0; |
490 | } | 490 | } |
491 | 491 | ||
492 | if ((version = drmGetVersion(fd))) { | 492 | if ((version = drmGetVersion(fd))) { |
493 | retval = 1; | 493 | retval = 1; |
494 | drmFreeVersion(version); | 494 | drmFreeVersion(version); |
495 | } | 495 | } |
496 | close(fd); | 496 | close(fd); |
497 | 497 | ||
@@ -570,37 +570,37 @@ static int drmOpenByBusid(const char *busid, int type) | |||
570 | 570 | ||
571 | drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); | 571 | drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid); |
572 | for (i = base; i < base + DRM_MAX_MINOR; i++) { | 572 | for (i = base; i < base + DRM_MAX_MINOR; i++) { |
573 | fd = drmOpenMinor(i, 1, type); | 573 | fd = drmOpenMinor(i, 1, type); |
574 | drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); | 574 | drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); |
575 | if (fd >= 0) { | 575 | if (fd >= 0) { |
576 | /* We need to try for 1.4 first for proper PCI domain support | 576 | /* We need to try for 1.4 first for proper PCI domain support |
577 | * and if that fails, we know the kernel is busted | 577 | * and if that fails, we know the kernel is busted |
578 | */ | 578 | */ |
579 | sv.drm_di_major = 1; | 579 | sv.drm_di_major = 1; |
580 | sv.drm_di_minor = 4; | 580 | sv.drm_di_minor = 4; |
581 | sv.drm_dd_major = -1; /* Don't care */ | 581 | sv.drm_dd_major = -1; /* Don't care */ |
582 | sv.drm_dd_minor = -1; /* Don't care */ | 582 | sv.drm_dd_minor = -1; /* Don't care */ |
583 | if (drmSetInterfaceVersion(fd, &sv)) { | 583 | if (drmSetInterfaceVersion(fd, &sv)) { |
584 | #ifndef __alpha__ | 584 | #ifndef __alpha__ |
585 | pci_domain_ok = 0; | 585 | pci_domain_ok = 0; |
586 | #endif | 586 | #endif |
587 | sv.drm_di_major = 1; | 587 | sv.drm_di_major = 1; |
588 | sv.drm_di_minor = 1; | 588 | sv.drm_di_minor = 1; |
589 | sv.drm_dd_major = -1; /* Don't care */ | 589 | sv.drm_dd_major = -1; /* Don't care */ |
590 | sv.drm_dd_minor = -1; /* Don't care */ | 590 | sv.drm_dd_minor = -1; /* Don't care */ |
591 | drmMsg("drmOpenByBusid: Interface 1.4 failed, trying 1.1\n"); | 591 | drmMsg("drmOpenByBusid: Interface 1.4 failed, trying 1.1\n"); |
592 | drmSetInterfaceVersion(fd, &sv); | 592 | drmSetInterfaceVersion(fd, &sv); |
593 | } | 593 | } |
594 | buf = drmGetBusid(fd); | 594 | buf = drmGetBusid(fd); |
595 | drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf); | 595 | drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf); |
596 | if (buf && drmMatchBusID(buf, busid, pci_domain_ok)) { | 596 | if (buf && drmMatchBusID(buf, busid, pci_domain_ok)) { |
597 | drmFreeBusid(buf); | 597 | drmFreeBusid(buf); |
598 | return fd; | 598 | return fd; |
599 | } | 599 | } |
600 | if (buf) | 600 | if (buf) |
601 | drmFreeBusid(buf); | 601 | drmFreeBusid(buf); |
602 | close(fd); | 602 | close(fd); |
603 | } | 603 | } |
604 | } | 604 | } |
605 | return -1; | 605 | return -1; |
606 | } | 606 | } |
@@ -611,14 +611,14 @@ static int drmOpenByBusid(const char *busid, int type) | |||
611 | * | 611 | * |
612 | * \param name driver name. | 612 | * \param name driver name. |
613 | * \param type the device node type. | 613 | * \param type the device node type. |
614 | * | 614 | * |
615 | * \return a file descriptor on success, or a negative value on error. | 615 | * \return a file descriptor on success, or a negative value on error. |
616 | * | 616 | * |
617 | * \internal | 617 | * \internal |
618 | * This function opens the first minor number that matches the driver name and | 618 | * This function opens the first minor number that matches the driver name and |
619 | * isn't already in use. If it's in use it then it will already have a bus ID | 619 | * isn't already in use. If it's in use it then it will already have a bus ID |
620 | * assigned. | 620 | * assigned. |
621 | * | 621 | * |
622 | * \sa drmOpenMinor(), drmGetVersion() and drmGetBusid(). | 622 | * \sa drmOpenMinor(), drmGetVersion() and drmGetBusid(). |
623 | */ | 623 | */ |
624 | static int drmOpenByName(const char *name, int type) | 624 | static int drmOpenByName(const char *name, int type) |
@@ -637,56 +637,56 @@ static int drmOpenByName(const char *name, int type) | |||
637 | * already in use. If it's in use it will have a busid assigned already. | 637 | * already in use. If it's in use it will have a busid assigned already. |
638 | */ | 638 | */ |
639 | for (i = base; i < base + DRM_MAX_MINOR; i++) { | 639 | for (i = base; i < base + DRM_MAX_MINOR; i++) { |
640 | if ((fd = drmOpenMinor(i, 1, type)) >= 0) { | 640 | if ((fd = drmOpenMinor(i, 1, type)) >= 0) { |
641 | if ((version = drmGetVersion(fd))) { | 641 | if ((version = drmGetVersion(fd))) { |
642 | if (!strcmp(version->name, name)) { | 642 | if (!strcmp(version->name, name)) { |
643 | drmFreeVersion(version); | 643 | drmFreeVersion(version); |
644 | id = drmGetBusid(fd); | 644 | id = drmGetBusid(fd); |
645 | drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL"); | 645 | drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL"); |
646 | if (!id || !*id) { | 646 | if (!id || !*id) { |
647 | if (id) | 647 | if (id) |
648 | drmFreeBusid(id); | 648 | drmFreeBusid(id); |
649 | return fd; | 649 | return fd; |
650 | } else { | 650 | } else { |
651 | drmFreeBusid(id); | 651 | drmFreeBusid(id); |
652 | } | 652 | } |
653 | } else { | 653 | } else { |
654 | drmFreeVersion(version); | 654 | drmFreeVersion(version); |
655 | } | 655 | } |
656 | } | 656 | } |
657 | close(fd); | 657 | close(fd); |
658 | } | 658 | } |
659 | } | 659 | } |
660 | 660 | ||
661 | #ifdef __linux__ | 661 | #ifdef __linux__ |
662 | /* Backward-compatibility /proc support */ | 662 | /* Backward-compatibility /proc support */ |
663 | for (i = 0; i < 8; i++) { | 663 | for (i = 0; i < 8; i++) { |
664 | char proc_name[64], buf[512]; | 664 | char proc_name[64], buf[512]; |
665 | char *driver, *pt, *devstring; | 665 | char *driver, *pt, *devstring; |
666 | int retcode; | 666 | int retcode; |
667 | 667 | ||
668 | sprintf(proc_name, "/proc/dri/%d/name", i); | 668 | sprintf(proc_name, "/proc/dri/%d/name", i); |
669 | if ((fd = open(proc_name, 0, 0)) >= 0) { | 669 | if ((fd = open(proc_name, 0, 0)) >= 0) { |
670 | retcode = read(fd, buf, sizeof(buf)-1); | 670 | retcode = read(fd, buf, sizeof(buf)-1); |
671 | close(fd); | 671 | close(fd); |
672 | if (retcode) { | 672 | if (retcode) { |
673 | buf[retcode-1] = '\0'; | 673 | buf[retcode-1] = '\0'; |
674 | for (driver = pt = buf; *pt && *pt != ' '; ++pt) | 674 | for (driver = pt = buf; *pt && *pt != ' '; ++pt) |
675 | ; | 675 | ; |
676 | if (*pt) { /* Device is next */ | 676 | if (*pt) { /* Device is next */ |
677 | *pt = '\0'; | 677 | *pt = '\0'; |
678 | if (!strcmp(driver, name)) { /* Match */ | 678 | if (!strcmp(driver, name)) { /* Match */ |
679 | for (devstring = ++pt; *pt && *pt != ' '; ++pt) | 679 | for (devstring = ++pt; *pt && *pt != ' '; ++pt) |
680 | ; | 680 | ; |
681 | if (*pt) { /* Found busid */ | 681 | if (*pt) { /* Found busid */ |
682 | return drmOpenByBusid(++pt, type); | 682 | return drmOpenByBusid(++pt, type); |
683 | } else { /* No busid */ | 683 | } else { /* No busid */ |
684 | return drmOpenDevice(strtol(devstring, NULL, 0),i, type); | 684 | return drmOpenDevice(strtol(devstring, NULL, 0),i, type); |
685 | } | 685 | } |
686 | } | 686 | } |
687 | } | 687 | } |
688 | } | 688 | } |
689 | } | 689 | } |
690 | } | 690 | } |
691 | #endif | 691 | #endif |
692 | 692 | ||
@@ -702,9 +702,9 @@ static int drmOpenByName(const char *name, int type) | |||
702 | * | 702 | * |
703 | * \param name driver name. Not referenced if bus ID is supplied. | 703 | * \param name driver name. Not referenced if bus ID is supplied. |
704 | * \param busid bus ID. Zero if not known. | 704 | * \param busid bus ID. Zero if not known. |
705 | * | 705 | * |
706 | * \return a file descriptor on success, or a negative value on error. | 706 | * \return a file descriptor on success, or a negative value on error. |
707 | * | 707 | * |
708 | * \internal | 708 | * \internal |
709 | * It calls drmOpenByBusid() if \p busid is specified or drmOpenByName() | 709 | * It calls drmOpenByBusid() if \p busid is specified or drmOpenByName() |
710 | * otherwise. | 710 | * otherwise. |
@@ -734,21 +734,21 @@ int drmOpenWithType(const char *name, const char *busid, int type) | |||
734 | { | 734 | { |
735 | if (!drmAvailable() && name != NULL && drm_server_info && | 735 | if (!drmAvailable() && name != NULL && drm_server_info && |
736 | drm_server_info->load_module) { | 736 | drm_server_info->load_module) { |
737 | /* try to load the kernel module */ | 737 | /* try to load the kernel module */ |
738 | if (!drm_server_info->load_module(name)) { | 738 | if (!drm_server_info->load_module(name)) { |
739 | drmMsg("[drm] failed to load kernel module \"%s\"\n", name); | 739 | drmMsg("[drm] failed to load kernel module \"%s\"\n", name); |
740 | return -1; | 740 | return -1; |
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | if (busid) { | 744 | if (busid) { |
745 | int fd = drmOpenByBusid(busid, type); | 745 | int fd = drmOpenByBusid(busid, type); |
746 | if (fd >= 0) | 746 | if (fd >= 0) |
747 | return fd; | 747 | return fd; |
748 | } | 748 | } |
749 | 749 | ||
750 | if (name) | 750 | if (name) |
751 | return drmOpenByName(name, type); | 751 | return drmOpenByName(name, type); |
752 | 752 | ||
753 | return -1; | 753 | return -1; |
754 | } | 754 | } |
@@ -775,7 +775,7 @@ int drmOpenRender(int minor) | |||
775 | void drmFreeVersion(drmVersionPtr v) | 775 | void drmFreeVersion(drmVersionPtr v) |
776 | { | 776 | { |
777 | if (!v) | 777 | if (!v) |
778 | return; | 778 | return; |
779 | drmFree(v->name); | 779 | drmFree(v->name); |
780 | drmFree(v->date); | 780 | drmFree(v->date); |
781 | drmFree(v->desc); | 781 | drmFree(v->desc); |
@@ -795,7 +795,7 @@ void drmFreeVersion(drmVersionPtr v) | |||
795 | static void drmFreeKernelVersion(drm_version_t *v) | 795 | static void drmFreeKernelVersion(drm_version_t *v) |
796 | { | 796 | { |
797 | if (!v) | 797 | if (!v) |
798 | return; | 798 | return; |
799 | drmFree(v->name); | 799 | drmFree(v->name); |
800 | drmFree(v->date); | 800 | drmFree(v->date); |
801 | drmFree(v->desc); | 801 | drmFree(v->desc); |
@@ -805,10 +805,10 @@ static void drmFreeKernelVersion(drm_version_t *v) | |||
805 | 805 | ||
806 | /** | 806 | /** |
807 | * Copy version information. | 807 | * Copy version information. |
808 | * | 808 | * |
809 | * \param d destination pointer. | 809 | * \param d destination pointer. |
810 | * \param s source pointer. | 810 | * \param s source pointer. |
811 | * | 811 | * |
812 | * \internal | 812 | * \internal |
813 | * Used by drmGetVersion() to translate the information returned by the ioctl | 813 | * Used by drmGetVersion() to translate the information returned by the ioctl |
814 | * interface in a private structure into the public structure counterpart. | 814 | * interface in a private structure into the public structure counterpart. |
@@ -831,12 +831,12 @@ static void drmCopyVersion(drmVersionPtr d, const drm_version_t *s) | |||
831 | * Query the driver version information. | 831 | * Query the driver version information. |
832 | * | 832 | * |
833 | * \param fd file descriptor. | 833 | * \param fd file descriptor. |
834 | * | 834 | * |
835 | * \return pointer to a drmVersion structure which should be freed with | 835 | * \return pointer to a drmVersion structure which should be freed with |
836 | * drmFreeVersion(). | 836 | * drmFreeVersion(). |
837 | * | 837 | * |
838 | * \note Similar information is available via /proc/dri. | 838 | * \note Similar information is available via /proc/dri. |
839 | * | 839 | * |
840 | * \internal | 840 | * \internal |
841 | * It gets the version information via successive DRM_IOCTL_VERSION ioctls, | 841 | * It gets the version information via successive DRM_IOCTL_VERSION ioctls, |
842 | * first with zeros to get the string lengths, and then the actually strings. | 842 | * first with zeros to get the string lengths, and then the actually strings. |
@@ -850,21 +850,21 @@ drmVersionPtr drmGetVersion(int fd) | |||
850 | memclear(*version); | 850 | memclear(*version); |
851 | 851 | ||
852 | if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) { | 852 | if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) { |
853 | drmFreeKernelVersion(version); | 853 | drmFreeKernelVersion(version); |
854 | return NULL; | 854 | return NULL; |
855 | } | 855 | } |
856 | 856 | ||
857 | if (version->name_len) | 857 | if (version->name_len) |
858 | version->name = drmMalloc(version->name_len + 1); | 858 | version->name = drmMalloc(version->name_len + 1); |
859 | if (version->date_len) | 859 | if (version->date_len) |
860 | version->date = drmMalloc(version->date_len + 1); | 860 | version->date = drmMalloc(version->date_len + 1); |
861 | if (version->desc_len) | 861 | if (version->desc_len) |
862 | version->desc = drmMalloc(version->desc_len + 1); | 862 | version->desc = drmMalloc(version->desc_len + 1); |
863 | 863 | ||
864 | if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) { | 864 | if (drmIoctl(fd, DRM_IOCTL_VERSION, version)) { |
865 | drmMsg("DRM_IOCTL_VERSION: %s\n", strerror(errno)); | 865 | drmMsg("DRM_IOCTL_VERSION: %s\n", strerror(errno)); |
866 | drmFreeKernelVersion(version); | 866 | drmFreeKernelVersion(version); |
867 | return NULL; | 867 | return NULL; |
868 | } | 868 | } |
869 | 869 | ||
870 | /* The results might not be null-terminated strings, so terminate them. */ | 870 | /* The results might not be null-terminated strings, so terminate them. */ |
@@ -881,13 +881,13 @@ drmVersionPtr drmGetVersion(int fd) | |||
881 | 881 | ||
882 | /** | 882 | /** |
883 | * Get version information for the DRM user space library. | 883 | * Get version information for the DRM user space library. |
884 | * | 884 | * |
885 | * This version number is driver independent. | 885 | * This version number is driver independent. |
886 | * | 886 | * |
887 | * \param fd file descriptor. | 887 | * \param fd file descriptor. |
888 | * | 888 | * |
889 | * \return version information. | 889 | * \return version information. |
890 | * | 890 | * |
891 | * \internal | 891 | * \internal |
892 | * This function allocates and fills a drm_version structure with a hard coded | 892 | * This function allocates and fills a drm_version structure with a hard coded |
893 | * version number. | 893 | * version number. |
@@ -915,29 +915,29 @@ drmVersionPtr drmGetLibVersion(int fd) | |||
915 | 915 | ||
916 | int drmGetCap(int fd, uint64_t capability, uint64_t *value) | 916 | int drmGetCap(int fd, uint64_t capability, uint64_t *value) |
917 | { | 917 | { |
918 | struct drm_get_cap cap; | 918 | struct drm_get_cap cap; |
919 | int ret; | 919 | int ret; |
920 | 920 | ||
921 | memclear(cap); | 921 | memclear(cap); |
922 | cap.capability = capability; | 922 | cap.capability = capability; |
923 | 923 | ||
924 | ret = drmIoctl(fd, DRM_IOCTL_GET_CAP, &cap); | 924 | ret = drmIoctl(fd, DRM_IOCTL_GET_CAP, &cap); |
925 | if (ret) | 925 | if (ret) |
926 | return ret; | 926 | return ret; |
927 | 927 | ||
928 | *value = cap.value; | 928 | *value = cap.value; |
929 | return 0; | 929 | return 0; |
930 | } | 930 | } |
931 | 931 | ||
932 | int drmSetClientCap(int fd, uint64_t capability, uint64_t value) | 932 | int drmSetClientCap(int fd, uint64_t capability, uint64_t value) |
933 | { | 933 | { |
934 | struct drm_set_client_cap cap; | 934 | struct drm_set_client_cap cap; |
935 | 935 | ||
936 | memclear(cap); | 936 | memclear(cap); |
937 | cap.capability = capability; | 937 | cap.capability = capability; |
938 | cap.value = value; | 938 | cap.value = value; |
939 | 939 | ||
940 | return drmIoctl(fd, DRM_IOCTL_SET_CLIENT_CAP, &cap); | 940 | return drmIoctl(fd, DRM_IOCTL_SET_CLIENT_CAP, &cap); |
941 | } | 941 | } |
942 | 942 | ||
943 | /** | 943 | /** |
@@ -973,10 +973,10 @@ char *drmGetBusid(int fd) | |||
973 | memclear(u); | 973 | memclear(u); |
974 | 974 | ||
975 | if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) | 975 | if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) |
976 | return NULL; | 976 | return NULL; |
977 | u.unique = drmMalloc(u.unique_len + 1); | 977 | u.unique = drmMalloc(u.unique_len + 1); |
978 | if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) | 978 | if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) |
979 | return NULL; | 979 | return NULL; |
980 | u.unique[u.unique_len] = '\0'; | 980 | u.unique[u.unique_len] = '\0'; |
981 | 981 | ||
982 | return u.unique; | 982 | return u.unique; |
@@ -1004,7 +1004,7 @@ int drmSetBusid(int fd, const char *busid) | |||
1004 | u.unique_len = strlen(busid); | 1004 | u.unique_len = strlen(busid); |
1005 | 1005 | ||
1006 | if (drmIoctl(fd, DRM_IOCTL_SET_UNIQUE, &u)) { | 1006 | if (drmIoctl(fd, DRM_IOCTL_SET_UNIQUE, &u)) { |
1007 | return -errno; | 1007 | return -errno; |
1008 | } | 1008 | } |
1009 | return 0; | 1009 | return 0; |
1010 | } | 1010 | } |
@@ -1017,7 +1017,7 @@ int drmGetMagic(int fd, drm_magic_t * magic) | |||
1017 | 1017 | ||
1018 | *magic = 0; | 1018 | *magic = 0; |
1019 | if (drmIoctl(fd, DRM_IOCTL_GET_MAGIC, &auth)) | 1019 | if (drmIoctl(fd, DRM_IOCTL_GET_MAGIC, &auth)) |
1020 | return -errno; | 1020 | return -errno; |
1021 | *magic = auth.magic; | 1021 | *magic = auth.magic; |
1022 | return 0; | 1022 | return 0; |
1023 | } | 1023 | } |
@@ -1029,7 +1029,7 @@ int drmAuthMagic(int fd, drm_magic_t magic) | |||
1029 | memclear(auth); | 1029 | memclear(auth); |
1030 | auth.magic = magic; | 1030 | auth.magic = magic; |
1031 | if (drmIoctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth)) | 1031 | if (drmIoctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth)) |
1032 | return -errno; | 1032 | return -errno; |
1033 | return 0; | 1033 | return 0; |
1034 | } | 1034 | } |
1035 | 1035 | ||
@@ -1045,7 +1045,7 @@ int drmAuthMagic(int fd, drm_magic_t magic) | |||
1045 | * \param flags combination of several flags to modify the function actions. | 1045 | * \param flags combination of several flags to modify the function actions. |
1046 | * \param handle will be set to a value that may be used as the offset | 1046 | * \param handle will be set to a value that may be used as the offset |
1047 | * parameter for mmap(). | 1047 | * parameter for mmap(). |
1048 | * | 1048 | * |
1049 | * \return zero on success or a negative value on error. | 1049 | * \return zero on success or a negative value on error. |
1050 | * | 1050 | * |
1051 | * \par Mapping the frame buffer | 1051 | * \par Mapping the frame buffer |
@@ -1056,7 +1056,7 @@ int drmAuthMagic(int fd, drm_magic_t magic) | |||
1056 | * | 1056 | * |
1057 | * \par | 1057 | * \par |
1058 | * The area mapped will be uncached. If MTRR support is available in the | 1058 | * The area mapped will be uncached. If MTRR support is available in the |
1059 | * kernel, the frame buffer area will be set to write combining. | 1059 | * kernel, the frame buffer area will be set to write combining. |
1060 | * | 1060 | * |
1061 | * \par Mapping the MMIO register area | 1061 | * \par Mapping the MMIO register area |
1062 | * For the MMIO register area, | 1062 | * For the MMIO register area, |
@@ -1064,19 +1064,19 @@ int drmAuthMagic(int fd, drm_magic_t magic) | |||
1064 | * - \p size will be the size of the register area bytes, and | 1064 | * - \p size will be the size of the register area bytes, and |
1065 | * - \p type will be DRM_REGISTERS. | 1065 | * - \p type will be DRM_REGISTERS. |
1066 | * \par | 1066 | * \par |
1067 | * The area mapped will be uncached. | 1067 | * The area mapped will be uncached. |
1068 | * | 1068 | * |
1069 | * \par Mapping the SAREA | 1069 | * \par Mapping the SAREA |
1070 | * For the SAREA, | 1070 | * For the SAREA, |
1071 | * - \p offset will be ignored and should be set to zero, | 1071 | * - \p offset will be ignored and should be set to zero, |
1072 | * - \p size will be the desired size of the SAREA in bytes, | 1072 | * - \p size will be the desired size of the SAREA in bytes, |
1073 | * - \p type will be DRM_SHM. | 1073 | * - \p type will be DRM_SHM. |
1074 | * | 1074 | * |
1075 | * \par | 1075 | * \par |
1076 | * A shared memory area of the requested size will be created and locked in | 1076 | * A shared memory area of the requested size will be created and locked in |
1077 | * kernel memory. This area may be mapped into client-space by using the handle | 1077 | * kernel memory. This area may be mapped into client-space by using the handle |
1078 | * returned. | 1078 | * returned. |
1079 | * | 1079 | * |
1080 | * \note May only be called by root. | 1080 | * \note May only be called by root. |
1081 | * | 1081 | * |
1082 | * \internal | 1082 | * \internal |
@@ -1084,7 +1084,7 @@ int drmAuthMagic(int fd, drm_magic_t magic) | |||
1084 | * the arguments in a drm_map structure. | 1084 | * the arguments in a drm_map structure. |
1085 | */ | 1085 | */ |
1086 | int drmAddMap(int fd, drm_handle_t offset, drmSize size, drmMapType type, | 1086 | int drmAddMap(int fd, drm_handle_t offset, drmSize size, drmMapType type, |
1087 | drmMapFlags flags, drm_handle_t *handle) | 1087 | drmMapFlags flags, drm_handle_t *handle) |
1088 | { | 1088 | { |
1089 | drm_map_t map; | 1089 | drm_map_t map; |
1090 | 1090 | ||
@@ -1094,9 +1094,9 @@ int drmAddMap(int fd, drm_handle_t offset, drmSize size, drmMapType type, | |||
1094 | map.type = type; | 1094 | map.type = type; |
1095 | map.flags = flags; | 1095 | map.flags = flags; |
1096 | if (drmIoctl(fd, DRM_IOCTL_ADD_MAP, &map)) | 1096 | if (drmIoctl(fd, DRM_IOCTL_ADD_MAP, &map)) |
1097 | return -errno; | 1097 | return -errno; |
1098 | if (handle) | 1098 | if (handle) |
1099 | *handle = (drm_handle_t)(uintptr_t)map.handle; | 1099 | *handle = (drm_handle_t)(uintptr_t)map.handle; |
1100 | return 0; | 1100 | return 0; |
1101 | } | 1101 | } |
1102 | 1102 | ||
@@ -1108,18 +1108,18 @@ int drmRmMap(int fd, drm_handle_t handle) | |||
1108 | map.handle = (void *)(uintptr_t)handle; | 1108 | map.handle = (void *)(uintptr_t)handle; |
1109 | 1109 | ||
1110 | if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map)) | 1110 | if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map)) |
1111 | return -errno; | 1111 | return -errno; |
1112 | return 0; | 1112 | return 0; |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | /** | 1115 | /** |
1116 | * Make buffers available for DMA transfers. | 1116 | * Make buffers available for DMA transfers. |
1117 | * | 1117 | * |
1118 | * \param fd file descriptor. | 1118 | * \param fd file descriptor. |
1119 | * \param count number of buffers. | 1119 | * \param count number of buffers. |
1120 | * \param size size of each buffer. | 1120 | * \param size size of each buffer. |
1121 | * \param flags buffer allocation flags. | 1121 | * \param flags buffer allocation flags. |
1122 | * \param agp_offset offset in the AGP aperture | 1122 | * \param agp_offset offset in the AGP aperture |
1123 | * | 1123 | * |
1124 | * \return number of buffers allocated, negative on error. | 1124 | * \return number of buffers allocated, negative on error. |
1125 | * | 1125 | * |
@@ -1129,7 +1129,7 @@ int drmRmMap(int fd, drm_handle_t handle) | |||
1129 | * \sa drm_buf_desc. | 1129 | * \sa drm_buf_desc. |
1130 | */ | 1130 | */ |
1131 | int drmAddBufs(int fd, int count, int size, drmBufDescFlags flags, | 1131 | int drmAddBufs(int fd, int count, int size, drmBufDescFlags flags, |
1132 | int agp_offset) | 1132 | int agp_offset) |
1133 | { | 1133 | { |
1134 | drm_buf_desc_t request; | 1134 | drm_buf_desc_t request; |
1135 | 1135 | ||
@@ -1140,7 +1140,7 @@ int drmAddBufs(int fd, int count, int size, drmBufDescFlags flags, | |||
1140 | request.agp_start = agp_offset; | 1140 | request.agp_start = agp_offset; |
1141 | 1141 | ||
1142 | if (drmIoctl(fd, DRM_IOCTL_ADD_BUFS, &request)) | 1142 | if (drmIoctl(fd, DRM_IOCTL_ADD_BUFS, &request)) |
1143 | return -errno; | 1143 | return -errno; |
1144 | return request.count; | 1144 | return request.count; |
1145 | } | 1145 | } |
1146 | 1146 | ||
@@ -1152,28 +1152,28 @@ int drmMarkBufs(int fd, double low, double high) | |||
1152 | memclear(info); | 1152 | memclear(info); |
1153 | 1153 | ||
1154 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) | 1154 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) |
1155 | return -EINVAL; | 1155 | return -EINVAL; |
1156 | 1156 | ||
1157 | if (!info.count) | 1157 | if (!info.count) |
1158 | return -EINVAL; | 1158 | return -EINVAL; |
1159 | 1159 | ||
1160 | if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) | 1160 | if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) |
1161 | return -ENOMEM; | 1161 | return -ENOMEM; |
1162 | 1162 | ||
1163 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { | 1163 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { |
1164 | int retval = -errno; | 1164 | int retval = -errno; |
1165 | drmFree(info.list); | 1165 | drmFree(info.list); |
1166 | return retval; | 1166 | return retval; |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | for (i = 0; i < info.count; i++) { | 1169 | for (i = 0; i < info.count; i++) { |
1170 | info.list[i].low_mark = low * info.list[i].count; | 1170 | info.list[i].low_mark = low * info.list[i].count; |
1171 | info.list[i].high_mark = high * info.list[i].count; | 1171 | info.list[i].high_mark = high * info.list[i].count; |
1172 | if (drmIoctl(fd, DRM_IOCTL_MARK_BUFS, &info.list[i])) { | 1172 | if (drmIoctl(fd, DRM_IOCTL_MARK_BUFS, &info.list[i])) { |
1173 | int retval = -errno; | 1173 | int retval = -errno; |
1174 | drmFree(info.list); | 1174 | drmFree(info.list); |
1175 | return retval; | 1175 | return retval; |
1176 | } | 1176 | } |
1177 | } | 1177 | } |
1178 | drmFree(info.list); | 1178 | drmFree(info.list); |
1179 | 1179 | ||
@@ -1188,9 +1188,9 @@ int drmMarkBufs(int fd, double low, double high) | |||
1188 | * \param list list of buffers to be freed. | 1188 | * \param list list of buffers to be freed. |
1189 | * | 1189 | * |
1190 | * \return zero on success, or a negative value on failure. | 1190 | * \return zero on success, or a negative value on failure. |
1191 | * | 1191 | * |
1192 | * \note This function is primarily used for debugging. | 1192 | * \note This function is primarily used for debugging. |
1193 | * | 1193 | * |
1194 | * \internal | 1194 | * \internal |
1195 | * This function is a wrapper around the DRM_IOCTL_FREE_BUFS ioctl, passing | 1195 | * This function is a wrapper around the DRM_IOCTL_FREE_BUFS ioctl, passing |
1196 | * the arguments in a drm_buf_free structure. | 1196 | * the arguments in a drm_buf_free structure. |
@@ -1203,7 +1203,7 @@ int drmFreeBufs(int fd, int count, int *list) | |||
1203 | request.count = count; | 1203 | request.count = count; |
1204 | request.list = list; | 1204 | request.list = list; |
1205 | if (drmIoctl(fd, DRM_IOCTL_FREE_BUFS, &request)) | 1205 | if (drmIoctl(fd, DRM_IOCTL_FREE_BUFS, &request)) |
1206 | return -errno; | 1206 | return -errno; |
1207 | return 0; | 1207 | return 0; |
1208 | } | 1208 | } |
1209 | 1209 | ||
@@ -1243,7 +1243,7 @@ int drmClose(int fd) | |||
1243 | * begins. | 1243 | * begins. |
1244 | * | 1244 | * |
1245 | * \return zero on success, or a negative value on failure. | 1245 | * \return zero on success, or a negative value on failure. |
1246 | * | 1246 | * |
1247 | * \internal | 1247 | * \internal |
1248 | * This function is a wrapper for mmap(). | 1248 | * This function is a wrapper for mmap(). |
1249 | */ | 1249 | */ |
@@ -1252,16 +1252,16 @@ int drmMap(int fd, drm_handle_t handle, drmSize size, drmAddressPtr address) | |||
1252 | static unsigned long pagesize_mask = 0; | 1252 | static unsigned long pagesize_mask = 0; |
1253 | 1253 | ||
1254 | if (fd < 0) | 1254 | if (fd < 0) |
1255 | return -EINVAL; | 1255 | return -EINVAL; |
1256 | 1256 | ||
1257 | if (!pagesize_mask) | 1257 | if (!pagesize_mask) |
1258 | pagesize_mask = getpagesize() - 1; | 1258 | pagesize_mask = getpagesize() - 1; |
1259 | 1259 | ||
1260 | size = (size + pagesize_mask) & ~pagesize_mask; | 1260 | size = (size + pagesize_mask) & ~pagesize_mask; |
1261 | 1261 | ||
1262 | *address = drm_mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle); | 1262 | *address = drm_mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle); |
1263 | if (*address == MAP_FAILED) | 1263 | if (*address == MAP_FAILED) |
1264 | return -errno; | 1264 | return -errno; |
1265 | return 0; | 1265 | return 0; |
1266 | } | 1266 | } |
1267 | 1267 | ||
@@ -1271,7 +1271,7 @@ int drmMap(int fd, drm_handle_t handle, drmSize size, drmAddressPtr address) | |||
1271 | * | 1271 | * |
1272 | * \param address address as given by drmMap(). | 1272 | * \param address address as given by drmMap(). |
1273 | * \param size size in bytes. Must match the size used by drmMap(). | 1273 | * \param size size in bytes. Must match the size used by drmMap(). |
1274 | * | 1274 | * |
1275 | * \return zero on success, or a negative value on failure. | 1275 | * \return zero on success, or a negative value on failure. |
1276 | * | 1276 | * |
1277 | * \internal | 1277 | * \internal |
@@ -1291,28 +1291,28 @@ drmBufInfoPtr drmGetBufInfo(int fd) | |||
1291 | memclear(info); | 1291 | memclear(info); |
1292 | 1292 | ||
1293 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) | 1293 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) |
1294 | return NULL; | 1294 | return NULL; |
1295 | 1295 | ||
1296 | if (info.count) { | 1296 | if (info.count) { |
1297 | if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) | 1297 | if (!(info.list = drmMalloc(info.count * sizeof(*info.list)))) |
1298 | return NULL; | 1298 | return NULL; |
1299 | 1299 | ||
1300 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { | 1300 | if (drmIoctl(fd, DRM_IOCTL_INFO_BUFS, &info)) { |
1301 | drmFree(info.list); | 1301 | drmFree(info.list); |
1302 | return NULL; | 1302 | return NULL; |
1303 | } | 1303 | } |
1304 | 1304 | ||
1305 | retval = drmMalloc(sizeof(*retval)); | 1305 | retval = drmMalloc(sizeof(*retval)); |
1306 | retval->count = info.count; | 1306 | retval->count = info.count; |
1307 | retval->list = drmMalloc(info.count * sizeof(*retval->list)); | 1307 | retval->list = drmMalloc(info.count * sizeof(*retval->list)); |
1308 | for (i = 0; i < info.count; i++) { | 1308 | for (i = 0; i < info.count; i++) { |
1309 | retval->list[i].count = info.list[i].count; | 1309 | retval->list[i].count = info.list[i].count; |
1310 | retval->list[i].size = info.list[i].size; | 1310 | retval->list[i].size = info.list[i].size; |
1311 | retval->list[i].low_mark = info.list[i].low_mark; | 1311 | retval->list[i].low_mark = info.list[i].low_mark; |
1312 | retval->list[i].high_mark = info.list[i].high_mark; | 1312 | retval->list[i].high_mark = info.list[i].high_mark; |
1313 | } | 1313 | } |
1314 | drmFree(info.list); | 1314 | drmFree(info.list); |
1315 | return retval; | 1315 | return retval; |
1316 | } | 1316 | } |
1317 | return NULL; | 1317 | return NULL; |
1318 | } | 1318 | } |
@@ -1326,12 +1326,12 @@ drmBufInfoPtr drmGetBufInfo(int fd) | |||
1326 | * | 1326 | * |
1327 | * \note The client may not use these buffers until obtaining buffer indices | 1327 | * \note The client may not use these buffers until obtaining buffer indices |
1328 | * with drmDMA(). | 1328 | * with drmDMA(). |
1329 | * | 1329 | * |
1330 | * \internal | 1330 | * \internal |
1331 | * This function calls the DRM_IOCTL_MAP_BUFS ioctl and copies the returned | 1331 | * This function calls the DRM_IOCTL_MAP_BUFS ioctl and copies the returned |
1332 | * information about the buffers in a drm_buf_map structure into the | 1332 | * information about the buffers in a drm_buf_map structure into the |
1333 | * client-visible data structures. | 1333 | * client-visible data structures. |
1334 | */ | 1334 | */ |
1335 | drmBufMapPtr drmMapBufs(int fd) | 1335 | drmBufMapPtr drmMapBufs(int fd) |
1336 | { | 1336 | { |
1337 | drm_buf_map_t bufs; | 1337 | drm_buf_map_t bufs; |
@@ -1340,32 +1340,31 @@ drmBufMapPtr drmMapBufs(int fd) | |||
1340 | 1340 | ||
1341 | memclear(bufs); | 1341 | memclear(bufs); |
1342 | if (drmIoctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) | 1342 | if (drmIoctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) |
1343 | return NULL; | 1343 | return NULL; |
1344 | 1344 | ||
1345 | if (!bufs.count) | 1345 | if (!bufs.count) |
1346 | return NULL; | 1346 | return NULL; |
1347 | 1347 | ||
1348 | if (!(bufs.list = drmMalloc(bufs.count * sizeof(*bufs.list)))) | 1348 | if (!(bufs.list = drmMalloc(bufs.count * sizeof(*bufs.list)))) |
1349 | return NULL; | 1349 | return NULL; |
1350 | 1350 | ||
1351 | if (drmIoctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) { | 1351 | if (drmIoctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) { |
1352 | drmFree(bufs.list); | 1352 | drmFree(bufs.list); |
1353 | return NULL; | 1353 | return NULL; |
1354 | } | 1354 | } |
1355 | 1355 | ||
1356 | retval = drmMalloc(sizeof(*retval)); | 1356 | retval = drmMalloc(sizeof(*retval)); |
1357 | retval->count = bufs.count; | 1357 | retval->count = bufs.count; |
1358 | retval->list = drmMalloc(bufs.count * sizeof(*retval->list)); | 1358 | retval->list = drmMalloc(bufs.count * sizeof(*retval->list)); |
1359 | for (i = 0; i < bufs.count; i++) { | 1359 | for (i = 0; i < bufs.count; i++) { |
1360 | retval->list[i].idx = bufs.list[i].idx; | 1360 | retval->list[i].idx = bufs.list[i].idx; |
1361 | retval->list[i].total = bufs.list[i].total; | 1361 | retval->list[i].total = bufs.list[i].total; |
1362 | retval->list[i].used = 0; | 1362 | retval->list[i].used = 0; |
1363 | retval->list[i].address = bufs.list[i].address; | 1363 | retval->list[i].address = bufs.list[i].address; |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | drmFree(bufs.list); | 1366 | drmFree(bufs.list); |
1367 | 1367 | return retval; | |
1368 | return retval; | ||
1369 | } | 1368 | } |
1370 | 1369 | ||
1371 | 1370 | ||
@@ -1383,24 +1382,23 @@ int drmUnmapBufs(drmBufMapPtr bufs) | |||
1383 | int i; | 1382 | int i; |
1384 | 1383 | ||
1385 | for (i = 0; i < bufs->count; i++) { | 1384 | for (i = 0; i < bufs->count; i++) { |
1386 | drm_munmap(bufs->list[i].address, bufs->list[i].total); | 1385 | drm_munmap(bufs->list[i].address, bufs->list[i].total); |
1387 | } | 1386 | } |
1388 | 1387 | ||
1389 | drmFree(bufs->list); | 1388 | drmFree(bufs->list); |
1390 | drmFree(bufs); | 1389 | drmFree(bufs); |
1391 | |||
1392 | return 0; | 1390 | return 0; |
1393 | } | 1391 | } |
1394 | 1392 | ||
1395 | 1393 | ||
1396 | #define DRM_DMA_RETRY 16 | 1394 | #define DRM_DMA_RETRY 16 |
1397 | 1395 | ||
1398 | /** | 1396 | /** |
1399 | * Reserve DMA buffers. | 1397 | * Reserve DMA buffers. |
1400 | * | 1398 | * |
1401 | * \param fd file descriptor. | 1399 | * \param fd file descriptor. |
1402 | * \param request | 1400 | * \param request |
1403 | * | 1401 | * |
1404 | * \return zero on success, or a negative value on failure. | 1402 | * \return zero on success, or a negative value on failure. |
1405 | * | 1403 | * |
1406 | * \internal | 1404 | * \internal |
@@ -1424,14 +1422,14 @@ int drmDMA(int fd, drmDMAReqPtr request) | |||
1424 | dma.granted_count = 0; | 1422 | dma.granted_count = 0; |
1425 | 1423 | ||
1426 | do { | 1424 | do { |
1427 | ret = ioctl( fd, DRM_IOCTL_DMA, &dma ); | 1425 | ret = ioctl( fd, DRM_IOCTL_DMA, &dma ); |
1428 | } while ( ret && errno == EAGAIN && i++ < DRM_DMA_RETRY ); | 1426 | } while ( ret && errno == EAGAIN && i++ < DRM_DMA_RETRY ); |
1429 | 1427 | ||
1430 | if ( ret == 0 ) { | 1428 | if ( ret == 0 ) { |
1431 | request->granted_count = dma.granted_count; | 1429 | request->granted_count = dma.granted_count; |
1432 | return 0; | 1430 | return 0; |
1433 | } else { | 1431 | } else { |
1434 | return -errno; | 1432 | return -errno; |
1435 | } | 1433 | } |
1436 | } | 1434 | } |
1437 | 1435 | ||
@@ -1443,9 +1441,9 @@ int drmDMA(int fd, drmDMAReqPtr request) | |||
1443 | * \param context context. | 1441 | * \param context context. |
1444 | * \param flags flags that determine the sate of the hardware when the function | 1442 | * \param flags flags that determine the sate of the hardware when the function |
1445 | * returns. | 1443 | * returns. |
1446 | * | 1444 | * |
1447 | * \return always zero. | 1445 | * \return always zero. |
1448 | * | 1446 | * |
1449 | * \internal | 1447 | * \internal |
1450 | * This function translates the arguments into a drm_lock structure and issue | 1448 | * This function translates the arguments into a drm_lock structure and issue |
1451 | * the DRM_IOCTL_LOCK ioctl until the lock is successfully acquired. | 1449 | * the DRM_IOCTL_LOCK ioctl until the lock is successfully acquired. |
@@ -1465,7 +1463,7 @@ int drmGetLock(int fd, drm_context_t context, drmLockFlags flags) | |||
1465 | if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; | 1463 | if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; |
1466 | 1464 | ||
1467 | while (drmIoctl(fd, DRM_IOCTL_LOCK, &lock)) | 1465 | while (drmIoctl(fd, DRM_IOCTL_LOCK, &lock)) |
1468 | ; | 1466 | ; |
1469 | return 0; | 1467 | return 0; |
1470 | } | 1468 | } |
1471 | 1469 | ||
@@ -1474,9 +1472,9 @@ int drmGetLock(int fd, drm_context_t context, drmLockFlags flags) | |||
1474 | * | 1472 | * |
1475 | * \param fd file descriptor. | 1473 | * \param fd file descriptor. |
1476 | * \param context context. | 1474 | * \param context context. |
1477 | * | 1475 | * |
1478 | * \return zero on success, or a negative value on failure. | 1476 | * \return zero on success, or a negative value on failure. |
1479 | * | 1477 | * |
1480 | * \internal | 1478 | * \internal |
1481 | * This function is a wrapper around the DRM_IOCTL_UNLOCK ioctl, passing the | 1479 | * This function is a wrapper around the DRM_IOCTL_UNLOCK ioctl, passing the |
1482 | * argument in a drm_lock structure. | 1480 | * argument in a drm_lock structure. |
@@ -1499,24 +1497,24 @@ drm_context_t *drmGetReservedContextList(int fd, int *count) | |||
1499 | 1497 | ||
1500 | memclear(res); | 1498 | memclear(res); |
1501 | if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) | 1499 | if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) |
1502 | return NULL; | 1500 | return NULL; |
1503 | 1501 | ||
1504 | if (!res.count) | 1502 | if (!res.count) |
1505 | return NULL; | 1503 | return NULL; |
1506 | 1504 | ||
1507 | if (!(list = drmMalloc(res.count * sizeof(*list)))) | 1505 | if (!(list = drmMalloc(res.count * sizeof(*list)))) |
1508 | return NULL; | 1506 | return NULL; |
1509 | if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { | 1507 | if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { |
1510 | drmFree(list); | 1508 | drmFree(list); |
1511 | return NULL; | 1509 | return NULL; |
1512 | } | 1510 | } |
1513 | 1511 | ||
1514 | res.contexts = list; | 1512 | res.contexts = list; |
1515 | if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) | 1513 | if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) |
1516 | return NULL; | 1514 | return NULL; |
1517 | 1515 | ||
1518 | for (i = 0; i < res.count; i++) | 1516 | for (i = 0; i < res.count; i++) |
1519 | retval[i] = list[i].handle; | 1517 | retval[i] = list[i].handle; |
1520 | drmFree(list); | 1518 | drmFree(list); |
1521 | 1519 | ||
1522 | *count = res.count; | 1520 | *count = res.count; |
@@ -1537,11 +1535,11 @@ void drmFreeReservedContextList(drm_context_t *pt) | |||
1537 | * \param fd file descriptor. | 1535 | * \param fd file descriptor. |
1538 | * \param handle is set on success. To be used by the client when requesting DMA | 1536 | * \param handle is set on success. To be used by the client when requesting DMA |
1539 | * dispatch with drmDMA(). | 1537 | * dispatch with drmDMA(). |
1540 | * | 1538 | * |
1541 | * \return zero on success, or a negative value on failure. | 1539 | * \return zero on success, or a negative value on failure. |
1542 | * | 1540 | * |
1543 | * \note May only be called by root. | 1541 | * \note May only be called by root. |
1544 | * | 1542 | * |
1545 | * \internal | 1543 | * \internal |
1546 | * This function is a wrapper around the DRM_IOCTL_ADD_CTX ioctl, passing the | 1544 | * This function is a wrapper around the DRM_IOCTL_ADD_CTX ioctl, passing the |
1547 | * argument in a drm_ctx structure. | 1545 | * argument in a drm_ctx structure. |
@@ -1552,7 +1550,7 @@ int drmCreateContext(int fd, drm_context_t *handle) | |||
1552 | 1550 | ||
1553 | memclear(ctx); | 1551 | memclear(ctx); |
1554 | if (drmIoctl(fd, DRM_IOCTL_ADD_CTX, &ctx)) | 1552 | if (drmIoctl(fd, DRM_IOCTL_ADD_CTX, &ctx)) |
1555 | return -errno; | 1553 | return -errno; |
1556 | *handle = ctx.handle; | 1554 | *handle = ctx.handle; |
1557 | return 0; | 1555 | return 0; |
1558 | } | 1556 | } |
@@ -1564,7 +1562,7 @@ int drmSwitchToContext(int fd, drm_context_t context) | |||
1564 | memclear(ctx); | 1562 | memclear(ctx); |
1565 | ctx.handle = context; | 1563 | ctx.handle = context; |
1566 | if (drmIoctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx)) | 1564 | if (drmIoctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx)) |
1567 | return -errno; | 1565 | return -errno; |
1568 | return 0; | 1566 | return 0; |
1569 | } | 1567 | } |
1570 | 1568 | ||
@@ -1581,11 +1579,11 @@ int drmSetContextFlags(int fd, drm_context_t context, drm_context_tFlags flags) | |||
1581 | memclear(ctx); | 1579 | memclear(ctx); |
1582 | ctx.handle = context; | 1580 | ctx.handle = context; |
1583 | if (flags & DRM_CONTEXT_PRESERVED) | 1581 | if (flags & DRM_CONTEXT_PRESERVED) |
1584 | ctx.flags |= _DRM_CONTEXT_PRESERVED; | 1582 | ctx.flags |= _DRM_CONTEXT_PRESERVED; |
1585 | if (flags & DRM_CONTEXT_2DONLY) | 1583 | if (flags & DRM_CONTEXT_2DONLY) |
1586 | ctx.flags |= _DRM_CONTEXT_2DONLY; | 1584 | ctx.flags |= _DRM_CONTEXT_2DONLY; |
1587 | if (drmIoctl(fd, DRM_IOCTL_MOD_CTX, &ctx)) | 1585 | if (drmIoctl(fd, DRM_IOCTL_MOD_CTX, &ctx)) |
1588 | return -errno; | 1586 | return -errno; |
1589 | return 0; | 1587 | return 0; |
1590 | } | 1588 | } |
1591 | 1589 | ||
@@ -1597,12 +1595,12 @@ int drmGetContextFlags(int fd, drm_context_t context, | |||
1597 | memclear(ctx); | 1595 | memclear(ctx); |
1598 | ctx.handle = context; | 1596 | ctx.handle = context; |
1599 | if (drmIoctl(fd, DRM_IOCTL_GET_CTX, &ctx)) | 1597 | if (drmIoctl(fd, DRM_IOCTL_GET_CTX, &ctx)) |
1600 | return -errno; | 1598 | return -errno; |
1601 | *flags = 0; | 1599 | *flags = 0; |
1602 | if (ctx.flags & _DRM_CONTEXT_PRESERVED) | 1600 | if (ctx.flags & _DRM_CONTEXT_PRESERVED) |
1603 | *flags |= DRM_CONTEXT_PRESERVED; | 1601 | *flags |= DRM_CONTEXT_PRESERVED; |
1604 | if (ctx.flags & _DRM_CONTEXT_2DONLY) | 1602 | if (ctx.flags & _DRM_CONTEXT_2DONLY) |
1605 | *flags |= DRM_CONTEXT_2DONLY; | 1603 | *flags |= DRM_CONTEXT_2DONLY; |
1606 | return 0; | 1604 | return 0; |
1607 | } | 1605 | } |
1608 | 1606 | ||
@@ -1611,14 +1609,14 @@ int drmGetContextFlags(int fd, drm_context_t context, | |||
1611 | * | 1609 | * |
1612 | * Free any kernel-level resources allocated with drmCreateContext() associated | 1610 | * Free any kernel-level resources allocated with drmCreateContext() associated |
1613 | * with the context. | 1611 | * with the context. |
1614 | * | 1612 | * |
1615 | * \param fd file descriptor. | 1613 | * \param fd file descriptor. |
1616 | * \param handle handle given by drmCreateContext(). | 1614 | * \param handle handle given by drmCreateContext(). |
1617 | * | 1615 | * |
1618 | * \return zero on success, or a negative value on failure. | 1616 | * \return zero on success, or a negative value on failure. |
1619 | * | 1617 | * |
1620 | * \note May only be called by root. | 1618 | * \note May only be called by root. |
1621 | * | 1619 | * |
1622 | * \internal | 1620 | * \internal |
1623 | * This function is a wrapper around the DRM_IOCTL_RM_CTX ioctl, passing the | 1621 | * This function is a wrapper around the DRM_IOCTL_RM_CTX ioctl, passing the |
1624 | * argument in a drm_ctx structure. | 1622 | * argument in a drm_ctx structure. |
@@ -1630,7 +1628,7 @@ int drmDestroyContext(int fd, drm_context_t handle) | |||
1630 | memclear(ctx); | 1628 | memclear(ctx); |
1631 | ctx.handle = handle; | 1629 | ctx.handle = handle; |
1632 | if (drmIoctl(fd, DRM_IOCTL_RM_CTX, &ctx)) | 1630 | if (drmIoctl(fd, DRM_IOCTL_RM_CTX, &ctx)) |
1633 | return -errno; | 1631 | return -errno; |
1634 | return 0; | 1632 | return 0; |
1635 | } | 1633 | } |
1636 | 1634 | ||
@@ -1640,7 +1638,7 @@ int drmCreateDrawable(int fd, drm_drawable_t *handle) | |||
1640 | 1638 | ||
1641 | memclear(draw); | 1639 | memclear(draw); |
1642 | if (drmIoctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) | 1640 | if (drmIoctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) |
1643 | return -errno; | 1641 | return -errno; |
1644 | *handle = draw.handle; | 1642 | *handle = draw.handle; |
1645 | return 0; | 1643 | return 0; |
1646 | } | 1644 | } |
@@ -1652,13 +1650,13 @@ int drmDestroyDrawable(int fd, drm_drawable_t handle) | |||
1652 | memclear(draw); | 1650 | memclear(draw); |
1653 | draw.handle = handle; | 1651 | draw.handle = handle; |
1654 | if (drmIoctl(fd, DRM_IOCTL_RM_DRAW, &draw)) | 1652 | if (drmIoctl(fd, DRM_IOCTL_RM_DRAW, &draw)) |
1655 | return -errno; | 1653 | return -errno; |
1656 | return 0; | 1654 | return 0; |
1657 | } | 1655 | } |
1658 | 1656 | ||
1659 | int drmUpdateDrawableInfo(int fd, drm_drawable_t handle, | 1657 | int drmUpdateDrawableInfo(int fd, drm_drawable_t handle, |
1660 | drm_drawable_info_type_t type, unsigned int num, | 1658 | drm_drawable_info_type_t type, unsigned int num, |
1661 | void *data) | 1659 | void *data) |
1662 | { | 1660 | { |
1663 | drm_update_draw_t update; | 1661 | drm_update_draw_t update; |
1664 | 1662 | ||
@@ -1669,7 +1667,7 @@ int drmUpdateDrawableInfo(int fd, drm_drawable_t handle, | |||
1669 | update.data = (unsigned long long)(unsigned long)data; | 1667 | update.data = (unsigned long long)(unsigned long)data; |
1670 | 1668 | ||
1671 | if (drmIoctl(fd, DRM_IOCTL_UPDATE_DRAW, &update)) | 1669 | if (drmIoctl(fd, DRM_IOCTL_UPDATE_DRAW, &update)) |
1672 | return -errno; | 1670 | return -errno; |
1673 | 1671 | ||
1674 | return 0; | 1672 | return 0; |
1675 | } | 1673 | } |
@@ -1680,16 +1678,16 @@ int drmUpdateDrawableInfo(int fd, drm_drawable_t handle, | |||
1680 | * Must be called before any of the other AGP related calls. | 1678 | * Must be called before any of the other AGP related calls. |
1681 | * | 1679 | * |
1682 | * \param fd file descriptor. | 1680 | * \param fd file descriptor. |
1683 | * | 1681 | * |
1684 | * \return zero on success, or a negative value on failure. | 1682 | * \return zero on success, or a negative value on failure. |
1685 | * | 1683 | * |
1686 | * \internal | 1684 | * \internal |
1687 | * This function is a wrapper around the DRM_IOCTL_AGP_ACQUIRE ioctl. | 1685 | * This function is a wrapper around the DRM_IOCTL_AGP_ACQUIRE ioctl. |
1688 | */ | 1686 | */ |
1689 | int drmAgpAcquire(int fd) | 1687 | int drmAgpAcquire(int fd) |
1690 | { | 1688 | { |
1691 | if (drmIoctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL)) | 1689 | if (drmIoctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL)) |
1692 | return -errno; | 1690 | return -errno; |
1693 | return 0; | 1691 | return 0; |
1694 | } | 1692 | } |
1695 | 1693 | ||
@@ -1698,16 +1696,16 @@ int drmAgpAcquire(int fd) | |||
1698 | * Release the AGP device. | 1696 | * Release the AGP device. |
1699 | * | 1697 | * |
1700 | * \param fd file descriptor. | 1698 | * \param fd file descriptor. |
1701 | * | 1699 | * |
1702 | * \return zero on success, or a negative value on failure. | 1700 | * \return zero on success, or a negative value on failure. |
1703 | * | 1701 | * |
1704 | * \internal | 1702 | * \internal |
1705 | * This function is a wrapper around the DRM_IOCTL_AGP_RELEASE ioctl. | 1703 | * This function is a wrapper around the DRM_IOCTL_AGP_RELEASE ioctl. |
1706 | */ | 1704 | */ |
1707 | int drmAgpRelease(int fd) | 1705 | int drmAgpRelease(int fd) |
1708 | { | 1706 | { |
1709 | if (drmIoctl(fd, DRM_IOCTL_AGP_RELEASE, NULL)) | 1707 | if (drmIoctl(fd, DRM_IOCTL_AGP_RELEASE, NULL)) |
1710 | return -errno; | 1708 | return -errno; |
1711 | return 0; | 1709 | return 0; |
1712 | } | 1710 | } |
1713 | 1711 | ||
@@ -1717,9 +1715,9 @@ int drmAgpRelease(int fd) | |||
1717 | * | 1715 | * |
1718 | * \param fd file descriptor. | 1716 | * \param fd file descriptor. |
1719 | * \param mode AGP mode. | 1717 | * \param mode AGP mode. |
1720 | * | 1718 | * |
1721 | * \return zero on success, or a negative value on failure. | 1719 | * \return zero on success, or a negative value on failure. |
1722 | * | 1720 | * |
1723 | * \internal | 1721 | * \internal |
1724 | * This function is a wrapper around the DRM_IOCTL_AGP_ENABLE ioctl, passing the | 1722 | * This function is a wrapper around the DRM_IOCTL_AGP_ENABLE ioctl, passing the |
1725 | * argument in a drm_agp_mode structure. | 1723 | * argument in a drm_agp_mode structure. |
@@ -1731,7 +1729,7 @@ int drmAgpEnable(int fd, unsigned long mode) | |||
1731 | memclear(m); | 1729 | memclear(m); |
1732 | m.mode = mode; | 1730 | m.mode = mode; |
1733 | if (drmIoctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) | 1731 | if (drmIoctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) |
1734 | return -errno; | 1732 | return -errno; |
1735 | return 0; | 1733 | return 0; |
1736 | } | 1734 | } |
1737 | 1735 | ||
@@ -1745,15 +1743,15 @@ int drmAgpEnable(int fd, unsigned long mode) | |||
1745 | * \param address if not zero, will be set to the physical address of the | 1743 | * \param address if not zero, will be set to the physical address of the |
1746 | * allocated memory. | 1744 | * allocated memory. |
1747 | * \param handle on success will be set to a handle of the allocated memory. | 1745 | * \param handle on success will be set to a handle of the allocated memory. |
1748 | * | 1746 | * |
1749 | * \return zero on success, or a negative value on failure. | 1747 | * \return zero on success, or a negative value on failure. |
1750 | * | 1748 | * |
1751 | * \internal | 1749 | * \internal |
1752 | * This function is a wrapper around the DRM_IOCTL_AGP_ALLOC ioctl, passing the | 1750 | * This function is a wrapper around the DRM_IOCTL_AGP_ALLOC ioctl, passing the |
1753 | * arguments in a drm_agp_buffer structure. | 1751 | * arguments in a drm_agp_buffer structure. |
1754 | */ | 1752 | */ |
1755 | int drmAgpAlloc(int fd, unsigned long size, unsigned long type, | 1753 | int drmAgpAlloc(int fd, unsigned long size, unsigned long type, |
1756 | unsigned long *address, drm_handle_t *handle) | 1754 | unsigned long *address, drm_handle_t *handle) |
1757 | { | 1755 | { |
1758 | drm_agp_buffer_t b; | 1756 | drm_agp_buffer_t b; |
1759 | 1757 | ||
@@ -1762,9 +1760,9 @@ int drmAgpAlloc(int fd, unsigned long size, unsigned long type, | |||
1762 | b.size = size; | 1760 | b.size = size; |
1763 | b.type = type; | 1761 | b.type = type; |
1764 | if (drmIoctl(fd, DRM_IOCTL_AGP_ALLOC, &b)) | 1762 | if (drmIoctl(fd, DRM_IOCTL_AGP_ALLOC, &b)) |
1765 | return -errno; | 1763 | return -errno; |
1766 | if (address != 0UL) | 1764 | if (address != 0UL) |
1767 | *address = b.physical; | 1765 | *address = b.physical; |
1768 | *handle = b.handle; | 1766 | *handle = b.handle; |
1769 | return 0; | 1767 | return 0; |
1770 | } | 1768 | } |
@@ -1775,9 +1773,9 @@ int drmAgpAlloc(int fd, unsigned long size, unsigned long type, | |||
1775 | * | 1773 | * |
1776 | * \param fd file descriptor. | 1774 | * \param fd file descriptor. |
1777 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). | 1775 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). |
1778 | * | 1776 | * |
1779 | * \return zero on success, or a negative value on failure. | 1777 | * \return zero on success, or a negative value on failure. |
1780 | * | 1778 | * |
1781 | * \internal | 1779 | * \internal |
1782 | * This function is a wrapper around the DRM_IOCTL_AGP_FREE ioctl, passing the | 1780 | * This function is a wrapper around the DRM_IOCTL_AGP_FREE ioctl, passing the |
1783 | * argument in a drm_agp_buffer structure. | 1781 | * argument in a drm_agp_buffer structure. |
@@ -1789,7 +1787,7 @@ int drmAgpFree(int fd, drm_handle_t handle) | |||
1789 | memclear(b); | 1787 | memclear(b); |
1790 | b.handle = handle; | 1788 | b.handle = handle; |
1791 | if (drmIoctl(fd, DRM_IOCTL_AGP_FREE, &b)) | 1789 | if (drmIoctl(fd, DRM_IOCTL_AGP_FREE, &b)) |
1792 | return -errno; | 1790 | return -errno; |
1793 | return 0; | 1791 | return 0; |
1794 | } | 1792 | } |
1795 | 1793 | ||
@@ -1800,9 +1798,9 @@ int drmAgpFree(int fd, drm_handle_t handle) | |||
1800 | * \param fd file descriptor. | 1798 | * \param fd file descriptor. |
1801 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). | 1799 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). |
1802 | * \param offset offset in bytes. It will round to page boundary. | 1800 | * \param offset offset in bytes. It will round to page boundary. |
1803 | * | 1801 | * |
1804 | * \return zero on success, or a negative value on failure. | 1802 | * \return zero on success, or a negative value on failure. |
1805 | * | 1803 | * |
1806 | * \internal | 1804 | * \internal |
1807 | * This function is a wrapper around the DRM_IOCTL_AGP_BIND ioctl, passing the | 1805 | * This function is a wrapper around the DRM_IOCTL_AGP_BIND ioctl, passing the |
1808 | * argument in a drm_agp_binding structure. | 1806 | * argument in a drm_agp_binding structure. |
@@ -1815,7 +1813,7 @@ int drmAgpBind(int fd, drm_handle_t handle, unsigned long offset) | |||
1815 | b.handle = handle; | 1813 | b.handle = handle; |
1816 | b.offset = offset; | 1814 | b.offset = offset; |
1817 | if (drmIoctl(fd, DRM_IOCTL_AGP_BIND, &b)) | 1815 | if (drmIoctl(fd, DRM_IOCTL_AGP_BIND, &b)) |
1818 | return -errno; | 1816 | return -errno; |
1819 | return 0; | 1817 | return 0; |
1820 | } | 1818 | } |
1821 | 1819 | ||
@@ -1825,9 +1823,9 @@ int drmAgpBind(int fd, drm_handle_t handle, unsigned long offset) | |||
1825 | * | 1823 | * |
1826 | * \param fd file descriptor. | 1824 | * \param fd file descriptor. |
1827 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). | 1825 | * \param handle handle to the allocated memory, as given by drmAgpAllocate(). |
1828 | * | 1826 | * |
1829 | * \return zero on success, or a negative value on failure. | 1827 | * \return zero on success, or a negative value on failure. |
1830 | * | 1828 | * |
1831 | * \internal | 1829 | * \internal |
1832 | * This function is a wrapper around the DRM_IOCTL_AGP_UNBIND ioctl, passing | 1830 | * This function is a wrapper around the DRM_IOCTL_AGP_UNBIND ioctl, passing |
1833 | * the argument in a drm_agp_binding structure. | 1831 | * the argument in a drm_agp_binding structure. |
@@ -1839,7 +1837,7 @@ int drmAgpUnbind(int fd, drm_handle_t handle) | |||
1839 | memclear(b); | 1837 | memclear(b); |
1840 | b.handle = handle; | 1838 | b.handle = handle; |
1841 | if (drmIoctl(fd, DRM_IOCTL_AGP_UNBIND, &b)) | 1839 | if (drmIoctl(fd, DRM_IOCTL_AGP_UNBIND, &b)) |
1842 | return -errno; | 1840 | return -errno; |
1843 | return 0; | 1841 | return 0; |
1844 | } | 1842 | } |
1845 | 1843 | ||
@@ -1848,9 +1846,9 @@ int drmAgpUnbind(int fd, drm_handle_t handle) | |||
1848 | * Get AGP driver major version number. | 1846 | * Get AGP driver major version number. |
1849 | * | 1847 | * |
1850 | * \param fd file descriptor. | 1848 | * \param fd file descriptor. |
1851 | * | 1849 | * |
1852 | * \return major version number on success, or a negative value on failure.. | 1850 | * \return major version number on success, or a negative value on failure.. |
1853 | * | 1851 | * |
1854 | * \internal | 1852 | * \internal |
1855 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1853 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1856 | * necessary information in a drm_agp_info structure. | 1854 | * necessary information in a drm_agp_info structure. |
@@ -1862,7 +1860,7 @@ int drmAgpVersionMajor(int fd) | |||
1862 | memclear(i); | 1860 | memclear(i); |
1863 | 1861 | ||
1864 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1862 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1865 | return -errno; | 1863 | return -errno; |
1866 | return i.agp_version_major; | 1864 | return i.agp_version_major; |
1867 | } | 1865 | } |
1868 | 1866 | ||
@@ -1871,9 +1869,9 @@ int drmAgpVersionMajor(int fd) | |||
1871 | * Get AGP driver minor version number. | 1869 | * Get AGP driver minor version number. |
1872 | * | 1870 | * |
1873 | * \param fd file descriptor. | 1871 | * \param fd file descriptor. |
1874 | * | 1872 | * |
1875 | * \return minor version number on success, or a negative value on failure. | 1873 | * \return minor version number on success, or a negative value on failure. |
1876 | * | 1874 | * |
1877 | * \internal | 1875 | * \internal |
1878 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1876 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1879 | * necessary information in a drm_agp_info structure. | 1877 | * necessary information in a drm_agp_info structure. |
@@ -1885,7 +1883,7 @@ int drmAgpVersionMinor(int fd) | |||
1885 | memclear(i); | 1883 | memclear(i); |
1886 | 1884 | ||
1887 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1885 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1888 | return -errno; | 1886 | return -errno; |
1889 | return i.agp_version_minor; | 1887 | return i.agp_version_minor; |
1890 | } | 1888 | } |
1891 | 1889 | ||
@@ -1894,9 +1892,9 @@ int drmAgpVersionMinor(int fd) | |||
1894 | * Get AGP mode. | 1892 | * Get AGP mode. |
1895 | * | 1893 | * |
1896 | * \param fd file descriptor. | 1894 | * \param fd file descriptor. |
1897 | * | 1895 | * |
1898 | * \return mode on success, or zero on failure. | 1896 | * \return mode on success, or zero on failure. |
1899 | * | 1897 | * |
1900 | * \internal | 1898 | * \internal |
1901 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1899 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1902 | * necessary information in a drm_agp_info structure. | 1900 | * necessary information in a drm_agp_info structure. |
@@ -1908,7 +1906,7 @@ unsigned long drmAgpGetMode(int fd) | |||
1908 | memclear(i); | 1906 | memclear(i); |
1909 | 1907 | ||
1910 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1908 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1911 | return 0; | 1909 | return 0; |
1912 | return i.mode; | 1910 | return i.mode; |
1913 | } | 1911 | } |
1914 | 1912 | ||
@@ -1917,9 +1915,9 @@ unsigned long drmAgpGetMode(int fd) | |||
1917 | * Get AGP aperture base. | 1915 | * Get AGP aperture base. |
1918 | * | 1916 | * |
1919 | * \param fd file descriptor. | 1917 | * \param fd file descriptor. |
1920 | * | 1918 | * |
1921 | * \return aperture base on success, zero on failure. | 1919 | * \return aperture base on success, zero on failure. |
1922 | * | 1920 | * |
1923 | * \internal | 1921 | * \internal |
1924 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1922 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1925 | * necessary information in a drm_agp_info structure. | 1923 | * necessary information in a drm_agp_info structure. |
@@ -1931,7 +1929,7 @@ unsigned long drmAgpBase(int fd) | |||
1931 | memclear(i); | 1929 | memclear(i); |
1932 | 1930 | ||
1933 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1931 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1934 | return 0; | 1932 | return 0; |
1935 | return i.aperture_base; | 1933 | return i.aperture_base; |
1936 | } | 1934 | } |
1937 | 1935 | ||
@@ -1940,9 +1938,9 @@ unsigned long drmAgpBase(int fd) | |||
1940 | * Get AGP aperture size. | 1938 | * Get AGP aperture size. |
1941 | * | 1939 | * |
1942 | * \param fd file descriptor. | 1940 | * \param fd file descriptor. |
1943 | * | 1941 | * |
1944 | * \return aperture size on success, zero on failure. | 1942 | * \return aperture size on success, zero on failure. |
1945 | * | 1943 | * |
1946 | * \internal | 1944 | * \internal |
1947 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1945 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1948 | * necessary information in a drm_agp_info structure. | 1946 | * necessary information in a drm_agp_info structure. |
@@ -1954,7 +1952,7 @@ unsigned long drmAgpSize(int fd) | |||
1954 | memclear(i); | 1952 | memclear(i); |
1955 | 1953 | ||
1956 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1954 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1957 | return 0; | 1955 | return 0; |
1958 | return i.aperture_size; | 1956 | return i.aperture_size; |
1959 | } | 1957 | } |
1960 | 1958 | ||
@@ -1963,9 +1961,9 @@ unsigned long drmAgpSize(int fd) | |||
1963 | * Get used AGP memory. | 1961 | * Get used AGP memory. |
1964 | * | 1962 | * |
1965 | * \param fd file descriptor. | 1963 | * \param fd file descriptor. |
1966 | * | 1964 | * |
1967 | * \return memory used on success, or zero on failure. | 1965 | * \return memory used on success, or zero on failure. |
1968 | * | 1966 | * |
1969 | * \internal | 1967 | * \internal |
1970 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1968 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1971 | * necessary information in a drm_agp_info structure. | 1969 | * necessary information in a drm_agp_info structure. |
@@ -1977,7 +1975,7 @@ unsigned long drmAgpMemoryUsed(int fd) | |||
1977 | memclear(i); | 1975 | memclear(i); |
1978 | 1976 | ||
1979 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 1977 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
1980 | return 0; | 1978 | return 0; |
1981 | return i.memory_used; | 1979 | return i.memory_used; |
1982 | } | 1980 | } |
1983 | 1981 | ||
@@ -1986,9 +1984,9 @@ unsigned long drmAgpMemoryUsed(int fd) | |||
1986 | * Get available AGP memory. | 1984 | * Get available AGP memory. |
1987 | * | 1985 | * |
1988 | * \param fd file descriptor. | 1986 | * \param fd file descriptor. |
1989 | * | 1987 | * |
1990 | * \return memory available on success, or zero on failure. | 1988 | * \return memory available on success, or zero on failure. |
1991 | * | 1989 | * |
1992 | * \internal | 1990 | * \internal |
1993 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 1991 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
1994 | * necessary information in a drm_agp_info structure. | 1992 | * necessary information in a drm_agp_info structure. |
@@ -2000,7 +1998,7 @@ unsigned long drmAgpMemoryAvail(int fd) | |||
2000 | memclear(i); | 1998 | memclear(i); |
2001 | 1999 | ||
2002 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 2000 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
2003 | return 0; | 2001 | return 0; |
2004 | return i.memory_allowed; | 2002 | return i.memory_allowed; |
2005 | } | 2003 | } |
2006 | 2004 | ||
@@ -2009,9 +2007,9 @@ unsigned long drmAgpMemoryAvail(int fd) | |||
2009 | * Get hardware vendor ID. | 2007 | * Get hardware vendor ID. |
2010 | * | 2008 | * |
2011 | * \param fd file descriptor. | 2009 | * \param fd file descriptor. |
2012 | * | 2010 | * |
2013 | * \return vendor ID on success, or zero on failure. | 2011 | * \return vendor ID on success, or zero on failure. |
2014 | * | 2012 | * |
2015 | * \internal | 2013 | * \internal |
2016 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 2014 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
2017 | * necessary information in a drm_agp_info structure. | 2015 | * necessary information in a drm_agp_info structure. |
@@ -2023,7 +2021,7 @@ unsigned int drmAgpVendorId(int fd) | |||
2023 | memclear(i); | 2021 | memclear(i); |
2024 | 2022 | ||
2025 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 2023 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
2026 | return 0; | 2024 | return 0; |
2027 | return i.id_vendor; | 2025 | return i.id_vendor; |
2028 | } | 2026 | } |
2029 | 2027 | ||
@@ -2032,9 +2030,9 @@ unsigned int drmAgpVendorId(int fd) | |||
2032 | * Get hardware device ID. | 2030 | * Get hardware device ID. |
2033 | * | 2031 | * |
2034 | * \param fd file descriptor. | 2032 | * \param fd file descriptor. |
2035 | * | 2033 | * |
2036 | * \return zero on success, or zero on failure. | 2034 | * \return zero on success, or zero on failure. |
2037 | * | 2035 | * |
2038 | * \internal | 2036 | * \internal |
2039 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the | 2037 | * This function is a wrapper around the DRM_IOCTL_AGP_INFO ioctl, getting the |
2040 | * necessary information in a drm_agp_info structure. | 2038 | * necessary information in a drm_agp_info structure. |
@@ -2046,7 +2044,7 @@ unsigned int drmAgpDeviceId(int fd) | |||
2046 | memclear(i); | 2044 | memclear(i); |
2047 | 2045 | ||
2048 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) | 2046 | if (drmIoctl(fd, DRM_IOCTL_AGP_INFO, &i)) |
2049 | return 0; | 2047 | return 0; |
2050 | return i.id_device; | 2048 | return i.id_device; |
2051 | } | 2049 | } |
2052 | 2050 | ||
@@ -2059,7 +2057,7 @@ int drmScatterGatherAlloc(int fd, unsigned long size, drm_handle_t *handle) | |||
2059 | *handle = 0; | 2057 | *handle = 0; |
2060 | sg.size = size; | 2058 | sg.size = size; |
2061 | if (drmIoctl(fd, DRM_IOCTL_SG_ALLOC, &sg)) | 2059 | if (drmIoctl(fd, DRM_IOCTL_SG_ALLOC, &sg)) |
2062 | return -errno; | 2060 | return -errno; |
2063 | *handle = sg.handle; | 2061 | *handle = sg.handle; |
2064 | return 0; | 2062 | return 0; |
2065 | } | 2063 | } |
@@ -2071,7 +2069,7 @@ int drmScatterGatherFree(int fd, drm_handle_t handle) | |||
2071 | memclear(sg); | 2069 | memclear(sg); |
2072 | sg.handle = handle; | 2070 | sg.handle = handle; |
2073 | if (drmIoctl(fd, DRM_IOCTL_SG_FREE, &sg)) | 2071 | if (drmIoctl(fd, DRM_IOCTL_SG_FREE, &sg)) |
2074 | return -errno; | 2072 | return -errno; |
2075 | return 0; | 2073 | return 0; |
2076 | } | 2074 | } |
2077 | 2075 | ||
@@ -2080,9 +2078,9 @@ int drmScatterGatherFree(int fd, drm_handle_t handle) | |||
2080 | * | 2078 | * |
2081 | * \param fd file descriptor. | 2079 | * \param fd file descriptor. |
2082 | * \param vbl pointer to a drmVBlank structure. | 2080 | * \param vbl pointer to a drmVBlank structure. |
2083 | * | 2081 | * |
2084 | * \return zero on success, or a negative value on failure. | 2082 | * \return zero on success, or a negative value on failure. |
2085 | * | 2083 | * |
2086 | * \internal | 2084 | * \internal |
2087 | * This function is a wrapper around the DRM_IOCTL_WAIT_VBLANK ioctl. | 2085 | * This function is a wrapper around the DRM_IOCTL_WAIT_VBLANK ioctl. |
2088 | */ | 2086 | */ |
@@ -2093,8 +2091,8 @@ int drmWaitVBlank(int fd, drmVBlankPtr vbl) | |||
2093 | 2091 | ||
2094 | ret = clock_gettime(CLOCK_MONOTONIC, &timeout); | 2092 | ret = clock_gettime(CLOCK_MONOTONIC, &timeout); |
2095 | if (ret < 0) { | 2093 | if (ret < 0) { |
2096 | fprintf(stderr, "clock_gettime failed: %s\n", strerror(errno)); | 2094 | fprintf(stderr, "clock_gettime failed: %s\n", strerror(errno)); |
2097 | goto out; | 2095 | goto out; |
2098 | } | 2096 | } |
2099 | timeout.tv_sec++; | 2097 | timeout.tv_sec++; |
2100 | 2098 | ||
@@ -2102,15 +2100,15 @@ int drmWaitVBlank(int fd, drmVBlankPtr vbl) | |||
2102 | ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl); | 2100 | ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl); |
2103 | vbl->request.type &= ~DRM_VBLANK_RELATIVE; | 2101 | vbl->request.type &= ~DRM_VBLANK_RELATIVE; |
2104 | if (ret && errno == EINTR) { | 2102 | if (ret && errno == EINTR) { |
2105 | clock_gettime(CLOCK_MONOTONIC, &cur); | 2103 | clock_gettime(CLOCK_MONOTONIC, &cur); |
2106 | /* Timeout after 1s */ | 2104 | /* Timeout after 1s */ |
2107 | if (cur.tv_sec > timeout.tv_sec + 1 || | 2105 | if (cur.tv_sec > timeout.tv_sec + 1 || |
2108 | (cur.tv_sec == timeout.tv_sec && cur.tv_nsec >= | 2106 | (cur.tv_sec == timeout.tv_sec && cur.tv_nsec >= |
2109 | timeout.tv_nsec)) { | 2107 | timeout.tv_nsec)) { |
2110 | errno = EBUSY; | 2108 | errno = EBUSY; |
2111 | ret = -1; | 2109 | ret = -1; |
2112 | break; | 2110 | break; |
2113 | } | 2111 | } |
2114 | } | 2112 | } |
2115 | } while (ret && errno == EINTR); | 2113 | } while (ret && errno == EINTR); |
2116 | 2114 | ||
@@ -2122,22 +2120,22 @@ int drmError(int err, const char *label) | |||
2122 | { | 2120 | { |
2123 | switch (err) { | 2121 | switch (err) { |
2124 | case DRM_ERR_NO_DEVICE: | 2122 | case DRM_ERR_NO_DEVICE: |
2125 | fprintf(stderr, "%s: no device\n", label); | 2123 | fprintf(stderr, "%s: no device\n", label); |
2126 | break; | 2124 | break; |
2127 | case DRM_ERR_NO_ACCESS: | 2125 | case DRM_ERR_NO_ACCESS: |
2128 | fprintf(stderr, "%s: no access\n", label); | 2126 | fprintf(stderr, "%s: no access\n", label); |
2129 | break; | 2127 | break; |
2130 | case DRM_ERR_NOT_ROOT: | 2128 | case DRM_ERR_NOT_ROOT: |
2131 | fprintf(stderr, "%s: not root\n", label); | 2129 | fprintf(stderr, "%s: not root\n", label); |
2132 | break; | 2130 | break; |
2133 | case DRM_ERR_INVALID: | 2131 | case DRM_ERR_INVALID: |
2134 | fprintf(stderr, "%s: invalid args\n", label); | 2132 | fprintf(stderr, "%s: invalid args\n", label); |
2135 | break; | 2133 | break; |
2136 | default: | 2134 | default: |
2137 | if (err < 0) | 2135 | if (err < 0) |
2138 | err = -err; | 2136 | err = -err; |
2139 | fprintf( stderr, "%s: error %d (%s)\n", label, err, strerror(err) ); | 2137 | fprintf( stderr, "%s: error %d (%s)\n", label, err, strerror(err) ); |
2140 | break; | 2138 | break; |
2141 | } | 2139 | } |
2142 | 2140 | ||
2143 | return 1; | 2141 | return 1; |
@@ -2148,9 +2146,9 @@ int drmError(int err, const char *label) | |||
2148 | * | 2146 | * |
2149 | * \param fd file descriptor. | 2147 | * \param fd file descriptor. |
2150 | * \param irq IRQ number. | 2148 | * \param irq IRQ number. |
2151 | * | 2149 | * |
2152 | * \return zero on success, or a negative value on failure. | 2150 | * \return zero on success, or a negative value on failure. |
2153 | * | 2151 | * |
2154 | * \internal | 2152 | * \internal |
2155 | * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the | 2153 | * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the |
2156 | * argument in a drm_control structure. | 2154 | * argument in a drm_control structure. |
@@ -2163,7 +2161,7 @@ int drmCtlInstHandler(int fd, int irq) | |||
2163 | ctl.func = DRM_INST_HANDLER; | 2161 | ctl.func = DRM_INST_HANDLER; |
2164 | ctl.irq = irq; | 2162 | ctl.irq = irq; |
2165 | if (drmIoctl(fd, DRM_IOCTL_CONTROL, &ctl)) | 2163 | if (drmIoctl(fd, DRM_IOCTL_CONTROL, &ctl)) |
2166 | return -errno; | 2164 | return -errno; |
2167 | return 0; | 2165 | return 0; |
2168 | } | 2166 | } |
2169 | 2167 | ||
@@ -2172,9 +2170,9 @@ int drmCtlInstHandler(int fd, int irq) | |||
2172 | * Uninstall IRQ handler. | 2170 | * Uninstall IRQ handler. |
2173 | * | 2171 | * |
2174 | * \param fd file descriptor. | 2172 | * \param fd file descriptor. |
2175 | * | 2173 | * |
2176 | * \return zero on success, or a negative value on failure. | 2174 | * \return zero on success, or a negative value on failure. |
2177 | * | 2175 | * |
2178 | * \internal | 2176 | * \internal |
2179 | * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the | 2177 | * This function is a wrapper around the DRM_IOCTL_CONTROL ioctl, passing the |
2180 | * argument in a drm_control structure. | 2178 | * argument in a drm_control structure. |
@@ -2187,7 +2185,7 @@ int drmCtlUninstHandler(int fd) | |||
2187 | ctl.func = DRM_UNINST_HANDLER; | 2185 | ctl.func = DRM_UNINST_HANDLER; |
2188 | ctl.irq = 0; | 2186 | ctl.irq = 0; |
2189 | if (drmIoctl(fd, DRM_IOCTL_CONTROL, &ctl)) | 2187 | if (drmIoctl(fd, DRM_IOCTL_CONTROL, &ctl)) |
2190 | return -errno; | 2188 | return -errno; |
2191 | return 0; | 2189 | return 0; |
2192 | } | 2190 | } |
2193 | 2191 | ||
@@ -2204,7 +2202,7 @@ int drmFinish(int fd, int context, drmLockFlags flags) | |||
2204 | if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES; | 2202 | if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES; |
2205 | if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; | 2203 | if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES; |
2206 | if (drmIoctl(fd, DRM_IOCTL_FINISH, &lock)) | 2204 | if (drmIoctl(fd, DRM_IOCTL_FINISH, &lock)) |
2207 | return -errno; | 2205 | return -errno; |
2208 | return 0; | 2206 | return 0; |
2209 | } | 2207 | } |
2210 | 2208 | ||
@@ -2215,9 +2213,9 @@ int drmFinish(int fd, int context, drmLockFlags flags) | |||
2215 | * \param busnum bus number. | 2213 | * \param busnum bus number. |
2216 | * \param devnum device number. | 2214 | * \param devnum device number. |
2217 | * \param funcnum function number. | 2215 | * \param funcnum function number. |
2218 | * | 2216 | * |
2219 | * \return IRQ number on success, or a negative value on failure. | 2217 | * \return IRQ number on success, or a negative value on failure. |
2220 | * | 2218 | * |
2221 | * \internal | 2219 | * \internal |
2222 | * This function is a wrapper around the DRM_IOCTL_IRQ_BUSID ioctl, passing the | 2220 | * This function is a wrapper around the DRM_IOCTL_IRQ_BUSID ioctl, passing the |
2223 | * arguments in a drm_irq_busid structure. | 2221 | * arguments in a drm_irq_busid structure. |
@@ -2231,7 +2229,7 @@ int drmGetInterruptFromBusID(int fd, int busnum, int devnum, int funcnum) | |||
2231 | p.devnum = devnum; | 2229 | p.devnum = devnum; |
2232 | p.funcnum = funcnum; | 2230 | p.funcnum = funcnum; |
2233 | if (drmIoctl(fd, DRM_IOCTL_IRQ_BUSID, &p)) | 2231 | if (drmIoctl(fd, DRM_IOCTL_IRQ_BUSID, &p)) |
2234 | return -errno; | 2232 | return -errno; |
2235 | return p.irq; | 2233 | return p.irq; |
2236 | } | 2234 | } |
2237 | 2235 | ||
@@ -2240,8 +2238,8 @@ int drmAddContextTag(int fd, drm_context_t context, void *tag) | |||
2240 | drmHashEntry *entry = drmGetEntry(fd); | 2238 | drmHashEntry *entry = drmGetEntry(fd); |
2241 | 2239 | ||
2242 | if (drmHashInsert(entry->tagTable, context, tag)) { | 2240 | if (drmHashInsert(entry->tagTable, context, tag)) { |
2243 | drmHashDelete(entry->tagTable, context); | 2241 | drmHashDelete(entry->tagTable, context); |
2244 | drmHashInsert(entry->tagTable, context, tag); | 2242 | drmHashInsert(entry->tagTable, context, tag); |
2245 | } | 2243 | } |
2246 | return 0; | 2244 | return 0; |
2247 | } | 2245 | } |
@@ -2259,7 +2257,7 @@ void *drmGetContextTag(int fd, drm_context_t context) | |||
2259 | void *value; | 2257 | void *value; |
2260 | 2258 | ||
2261 | if (drmHashLookup(entry->tagTable, context, &value)) | 2259 | if (drmHashLookup(entry->tagTable, context, &value)) |
2262 | return NULL; | 2260 | return NULL; |
2263 | 2261 | ||
2264 | return value; | 2262 | return value; |
2265 | } | 2263 | } |
@@ -2274,7 +2272,7 @@ int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, | |||
2274 | map.handle = (void *)(uintptr_t)handle; | 2272 | map.handle = (void *)(uintptr_t)handle; |
2275 | 2273 | ||
2276 | if (drmIoctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map)) | 2274 | if (drmIoctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map)) |
2277 | return -errno; | 2275 | return -errno; |
2278 | return 0; | 2276 | return 0; |
2279 | } | 2277 | } |
2280 | 2278 | ||
@@ -2287,23 +2285,23 @@ int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, | |||
2287 | map.ctx_id = ctx_id; | 2285 | map.ctx_id = ctx_id; |
2288 | 2286 | ||
2289 | if (drmIoctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map)) | 2287 | if (drmIoctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map)) |
2290 | return -errno; | 2288 | return -errno; |
2291 | if (handle) | 2289 | if (handle) |
2292 | *handle = (drm_handle_t)(uintptr_t)map.handle; | 2290 | *handle = (drm_handle_t)(uintptr_t)map.handle; |
2293 | 2291 | ||
2294 | return 0; | 2292 | return 0; |
2295 | } | 2293 | } |
2296 | 2294 | ||
2297 | int drmGetMap(int fd, int idx, drm_handle_t *offset, drmSize *size, | 2295 | int drmGetMap(int fd, int idx, drm_handle_t *offset, drmSize *size, |
2298 | drmMapType *type, drmMapFlags *flags, drm_handle_t *handle, | 2296 | drmMapType *type, drmMapFlags *flags, drm_handle_t *handle, |
2299 | int *mtrr) | 2297 | int *mtrr) |
2300 | { | 2298 | { |
2301 | drm_map_t map; | 2299 | drm_map_t map; |
2302 | 2300 | ||
2303 | memclear(map); | 2301 | memclear(map); |
2304 | map.offset = idx; | 2302 | map.offset = idx; |
2305 | if (drmIoctl(fd, DRM_IOCTL_GET_MAP, &map)) | 2303 | if (drmIoctl(fd, DRM_IOCTL_GET_MAP, &map)) |
2306 | return -errno; | 2304 | return -errno; |
2307 | *offset = map.offset; | 2305 | *offset = map.offset; |
2308 | *size = map.size; | 2306 | *size = map.size; |
2309 | *type = map.type; | 2307 | *type = map.type; |
@@ -2314,14 +2312,14 @@ int drmGetMap(int fd, int idx, drm_handle_t *offset, drmSize *size, | |||
2314 | } | 2312 | } |
2315 | 2313 | ||
2316 | int drmGetClient(int fd, int idx, int *auth, int *pid, int *uid, | 2314 | int drmGetClient(int fd, int idx, int *auth, int *pid, int *uid, |
2317 | unsigned long *magic, unsigned long *iocs) | 2315 | unsigned long *magic, unsigned long *iocs) |
2318 | { | 2316 | { |
2319 | drm_client_t client; | 2317 | drm_client_t client; |
2320 | 2318 | ||
2321 | memclear(client); | 2319 | memclear(client); |
2322 | client.idx = idx; | 2320 | client.idx = idx; |
2323 | if (drmIoctl(fd, DRM_IOCTL_GET_CLIENT, &client)) | 2321 | if (drmIoctl(fd, DRM_IOCTL_GET_CLIENT, &client)) |
2324 | return -errno; | 2322 | return -errno; |
2325 | *auth = client.auth; | 2323 | *auth = client.auth; |
2326 | *pid = client.pid; | 2324 | *pid = client.pid; |
2327 | *uid = client.uid; | 2325 | *uid = client.uid; |
@@ -2337,12 +2335,12 @@ int drmGetStats(int fd, drmStatsT *stats) | |||
2337 | 2335 | ||
2338 | memclear(s); | 2336 | memclear(s); |
2339 | if (drmIoctl(fd, DRM_IOCTL_GET_STATS, &s)) | 2337 | if (drmIoctl(fd, DRM_IOCTL_GET_STATS, &s)) |
2340 | return -errno; | 2338 | return -errno; |
2341 | 2339 | ||
2342 | stats->count = 0; | 2340 | stats->count = 0; |
2343 | memset(stats, 0, sizeof(*stats)); | 2341 | memset(stats, 0, sizeof(*stats)); |
2344 | if (s.count > sizeof(stats->data)/sizeof(stats->data[0])) | 2342 | if (s.count > sizeof(stats->data)/sizeof(stats->data[0])) |
2345 | return -1; | 2343 | return -1; |
2346 | 2344 | ||
2347 | #define SET_VALUE \ | 2345 | #define SET_VALUE \ |
2348 | stats->data[i].long_format = "%-20.20s"; \ | 2346 | stats->data[i].long_format = "%-20.20s"; \ |
@@ -2369,87 +2367,87 @@ int drmGetStats(int fd, drmStatsT *stats) | |||
2369 | 2367 | ||
2370 | stats->count = s.count; | 2368 | stats->count = s.count; |
2371 | for (i = 0; i < s.count; i++) { | 2369 | for (i = 0; i < s.count; i++) { |
2372 | stats->data[i].value = s.data[i].value; | 2370 | stats->data[i].value = s.data[i].value; |
2373 | switch (s.data[i].type) { | 2371 | switch (s.data[i].type) { |
2374 | case _DRM_STAT_LOCK: | 2372 | case _DRM_STAT_LOCK: |
2375 | stats->data[i].long_name = "Lock"; | 2373 | stats->data[i].long_name = "Lock"; |
2376 | stats->data[i].rate_name = "Lock"; | 2374 | stats->data[i].rate_name = "Lock"; |
2377 | SET_VALUE; | 2375 | SET_VALUE; |
2378 | break; | 2376 | break; |
2379 | case _DRM_STAT_OPENS: | 2377 | case _DRM_STAT_OPENS: |
2380 | stats->data[i].long_name = "Opens"; | 2378 | stats->data[i].long_name = "Opens"; |
2381 | stats->data[i].rate_name = "O"; | 2379 | stats->data[i].rate_name = "O"; |
2382 | SET_COUNT; | 2380 | SET_COUNT; |
2383 | stats->data[i].verbose = 1; | 2381 | stats->data[i].verbose = 1; |
2384 | break; | 2382 | break; |
2385 | case _DRM_STAT_CLOSES: | 2383 | case _DRM_STAT_CLOSES: |
2386 | stats->data[i].long_name = "Closes"; | 2384 | stats->data[i].long_name = "Closes"; |
2387 | stats->data[i].rate_name = "Lock"; | 2385 | stats->data[i].rate_name = "Lock"; |
2388 | SET_COUNT; | 2386 | SET_COUNT; |
2389 | stats->data[i].verbose = 1; | 2387 | stats->data[i].verbose = 1; |
2390 | break; | 2388 | break; |
2391 | case _DRM_STAT_IOCTLS: | 2389 | case _DRM_STAT_IOCTLS: |
2392 | stats->data[i].long_name = "Ioctls"; | 2390 | stats->data[i].long_name = "Ioctls"; |
2393 | stats->data[i].rate_name = "Ioc/s"; | 2391 | stats->data[i].rate_name = "Ioc/s"; |
2394 | SET_COUNT; | 2392 | SET_COUNT; |
2395 | break; | 2393 | break; |
2396 | case _DRM_STAT_LOCKS: | 2394 | case _DRM_STAT_LOCKS: |
2397 | stats->data[i].long_name = "Locks"; | 2395 | stats->data[i].long_name = "Locks"; |
2398 | stats->data[i].rate_name = "Lck/s"; | 2396 | stats->data[i].rate_name = "Lck/s"; |
2399 | SET_COUNT; | 2397 | SET_COUNT; |
2400 | break; | 2398 | break; |
2401 | case _DRM_STAT_UNLOCKS: | 2399 | case _DRM_STAT_UNLOCKS: |
2402 | stats->data[i].long_name = "Unlocks"; | 2400 | stats->data[i].long_name = "Unlocks"; |
2403 | stats->data[i].rate_name = "Unl/s"; | 2401 | stats->data[i].rate_name = "Unl/s"; |
2404 | SET_COUNT; | 2402 | SET_COUNT; |
2405 | break; | 2403 | break; |
2406 | case _DRM_STAT_IRQ: | 2404 | case _DRM_STAT_IRQ: |
2407 | stats->data[i].long_name = "IRQs"; | 2405 | stats->data[i].long_name = "IRQs"; |
2408 | stats->data[i].rate_name = "IRQ/s"; | 2406 | stats->data[i].rate_name = "IRQ/s"; |
2409 | SET_COUNT; | 2407 | SET_COUNT; |
2410 | break; | 2408 | break; |
2411 | case _DRM_STAT_PRIMARY: | 2409 | case _DRM_STAT_PRIMARY: |
2412 | stats->data[i].long_name = "Primary Bytes"; | 2410 | stats->data[i].long_name = "Primary Bytes"; |
2413 | stats->data[i].rate_name = "PB/s"; | 2411 | stats->data[i].rate_name = "PB/s"; |
2414 | SET_BYTE; | 2412 | SET_BYTE; |
2415 | break; | 2413 | break; |
2416 | case _DRM_STAT_SECONDARY: | 2414 | case _DRM_STAT_SECONDARY: |
2417 | stats->data[i].long_name = "Secondary Bytes"; | 2415 | stats->data[i].long_name = "Secondary Bytes"; |
2418 | stats->data[i].rate_name = "SB/s"; | 2416 | stats->data[i].rate_name = "SB/s"; |
2419 | SET_BYTE; | 2417 | SET_BYTE; |
2420 | break; | 2418 | break; |
2421 | case _DRM_STAT_DMA: | 2419 | case _DRM_STAT_DMA: |
2422 | stats->data[i].long_name = "DMA"; | 2420 | stats->data[i].long_name = "DMA"; |
2423 | stats->data[i].rate_name = "DMA/s"; | 2421 | stats->data[i].rate_name = "DMA/s"; |
2424 | SET_COUNT; | 2422 | SET_COUNT; |
2425 | break; | 2423 | break; |
2426 | case _DRM_STAT_SPECIAL: | 2424 | case _DRM_STAT_SPECIAL: |
2427 | stats->data[i].long_name = "Special DMA"; | 2425 | stats->data[i].long_name = "Special DMA"; |
2428 | stats->data[i].rate_name = "dma/s"; | 2426 | stats->data[i].rate_name = "dma/s"; |
2429 | SET_COUNT; | 2427 | SET_COUNT; |
2430 | break; | 2428 | break; |
2431 | case _DRM_STAT_MISSED: | 2429 | case _DRM_STAT_MISSED: |
2432 | stats->data[i].long_name = "Miss"; | 2430 | stats->data[i].long_name = "Miss"; |
2433 | stats->data[i].rate_name = "Ms/s"; | 2431 | stats->data[i].rate_name = "Ms/s"; |
2434 | SET_COUNT; | 2432 | SET_COUNT; |
2435 | break; | 2433 | break; |
2436 | case _DRM_STAT_VALUE: | 2434 | case _DRM_STAT_VALUE: |
2437 | stats->data[i].long_name = "Value"; | 2435 | stats->data[i].long_name = "Value"; |
2438 | stats->data[i].rate_name = "Value"; | 2436 | stats->data[i].rate_name = "Value"; |
2439 | SET_VALUE; | 2437 | SET_VALUE; |
2440 | break; | 2438 | break; |
2441 | case _DRM_STAT_BYTE: | 2439 | case _DRM_STAT_BYTE: |
2442 | stats->data[i].long_name = "Bytes"; | 2440 | stats->data[i].long_name = "Bytes"; |
2443 | stats->data[i].rate_name = "B/s"; | 2441 | stats->data[i].rate_name = "B/s"; |
2444 | SET_BYTE; | 2442 | SET_BYTE; |
2445 | break; | 2443 | break; |
2446 | case _DRM_STAT_COUNT: | 2444 | case _DRM_STAT_COUNT: |
2447 | default: | 2445 | default: |
2448 | stats->data[i].long_name = "Count"; | 2446 | stats->data[i].long_name = "Count"; |
2449 | stats->data[i].rate_name = "Cnt/s"; | 2447 | stats->data[i].rate_name = "Cnt/s"; |
2450 | SET_COUNT; | 2448 | SET_COUNT; |
2451 | break; | 2449 | break; |
2452 | } | 2450 | } |
2453 | } | 2451 | } |
2454 | return 0; | 2452 | return 0; |
2455 | } | 2453 | } |
@@ -2458,14 +2456,14 @@ int drmGetStats(int fd, drmStatsT *stats) | |||
2458 | * Issue a set-version ioctl. | 2456 | * Issue a set-version ioctl. |
2459 | * | 2457 | * |
2460 | * \param fd file descriptor. | 2458 | * \param fd file descriptor. |
2461 | * \param drmCommandIndex command index | 2459 | * \param drmCommandIndex command index |
2462 | * \param data source pointer of the data to be read and written. | 2460 | * \param data source pointer of the data to be read and written. |
2463 | * \param size size of the data to be read and written. | 2461 | * \param size size of the data to be read and written. |
2464 | * | 2462 | * |
2465 | * \return zero on success, or a negative value on failure. | 2463 | * \return zero on success, or a negative value on failure. |
2466 | * | 2464 | * |
2467 | * \internal | 2465 | * \internal |
2468 | * It issues a read-write ioctl given by | 2466 | * It issues a read-write ioctl given by |
2469 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. | 2467 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. |
2470 | */ | 2468 | */ |
2471 | int drmSetInterfaceVersion(int fd, drmSetVersion *version) | 2469 | int drmSetInterfaceVersion(int fd, drmSetVersion *version) |
@@ -2480,7 +2478,7 @@ int drmSetInterfaceVersion(int fd, drmSetVersion *version) | |||
2480 | sv.drm_dd_minor = version->drm_dd_minor; | 2478 | sv.drm_dd_minor = version->drm_dd_minor; |
2481 | 2479 | ||
2482 | if (drmIoctl(fd, DRM_IOCTL_SET_VERSION, &sv)) { | 2480 | if (drmIoctl(fd, DRM_IOCTL_SET_VERSION, &sv)) { |
2483 | retcode = -errno; | 2481 | retcode = -errno; |
2484 | } | 2482 | } |
2485 | 2483 | ||
2486 | version->drm_di_major = sv.drm_di_major; | 2484 | version->drm_di_major = sv.drm_di_major; |
@@ -2495,12 +2493,12 @@ int drmSetInterfaceVersion(int fd, drmSetVersion *version) | |||
2495 | * Send a device-specific command. | 2493 | * Send a device-specific command. |
2496 | * | 2494 | * |
2497 | * \param fd file descriptor. | 2495 | * \param fd file descriptor. |
2498 | * \param drmCommandIndex command index | 2496 | * \param drmCommandIndex command index |
2499 | * | 2497 | * |
2500 | * \return zero on success, or a negative value on failure. | 2498 | * \return zero on success, or a negative value on failure. |
2501 | * | 2499 | * |
2502 | * \internal | 2500 | * \internal |
2503 | * It issues a ioctl given by | 2501 | * It issues a ioctl given by |
2504 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. | 2502 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. |
2505 | */ | 2503 | */ |
2506 | int drmCommandNone(int fd, unsigned long drmCommandIndex) | 2504 | int drmCommandNone(int fd, unsigned long drmCommandIndex) |
@@ -2510,7 +2508,7 @@ int drmCommandNone(int fd, unsigned long drmCommandIndex) | |||
2510 | request = DRM_IO( DRM_COMMAND_BASE + drmCommandIndex); | 2508 | request = DRM_IO( DRM_COMMAND_BASE + drmCommandIndex); |
2511 | 2509 | ||
2512 | if (drmIoctl(fd, request, NULL)) { | 2510 | if (drmIoctl(fd, request, NULL)) { |
2513 | return -errno; | 2511 | return -errno; |
2514 | } | 2512 | } |
2515 | return 0; | 2513 | return 0; |
2516 | } | 2514 | } |
@@ -2520,14 +2518,14 @@ int drmCommandNone(int fd, unsigned long drmCommandIndex) | |||
2520 | * Send a device-specific read command. | 2518 | * Send a device-specific read command. |
2521 | * | 2519 | * |
2522 | * \param fd file descriptor. | 2520 | * \param fd file descriptor. |
2523 | * \param drmCommandIndex command index | 2521 | * \param drmCommandIndex command index |
2524 | * \param data destination pointer of the data to be read. | 2522 | * \param data destination pointer of the data to be read. |
2525 | * \param size size of the data to be read. | 2523 | * \param size size of the data to be read. |
2526 | * | 2524 | * |
2527 | * \return zero on success, or a negative value on failure. | 2525 | * \return zero on success, or a negative value on failure. |
2528 | * | 2526 | * |
2529 | * \internal | 2527 | * \internal |
2530 | * It issues a read ioctl given by | 2528 | * It issues a read ioctl given by |
2531 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. | 2529 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. |
2532 | */ | 2530 | */ |
2533 | int drmCommandRead(int fd, unsigned long drmCommandIndex, void *data, | 2531 | int drmCommandRead(int fd, unsigned long drmCommandIndex, void *data, |
@@ -2535,11 +2533,11 @@ int drmCommandRead(int fd, unsigned long drmCommandIndex, void *data, | |||
2535 | { | 2533 | { |
2536 | unsigned long request; | 2534 | unsigned long request; |
2537 | 2535 | ||
2538 | request = DRM_IOC( DRM_IOC_READ, DRM_IOCTL_BASE, | 2536 | request = DRM_IOC( DRM_IOC_READ, DRM_IOCTL_BASE, |
2539 | DRM_COMMAND_BASE + drmCommandIndex, size); | 2537 | DRM_COMMAND_BASE + drmCommandIndex, size); |
2540 | 2538 | ||
2541 | if (drmIoctl(fd, request, data)) { | 2539 | if (drmIoctl(fd, request, data)) { |
2542 | return -errno; | 2540 | return -errno; |
2543 | } | 2541 | } |
2544 | return 0; | 2542 | return 0; |
2545 | } | 2543 | } |
@@ -2549,14 +2547,14 @@ int drmCommandRead(int fd, unsigned long drmCommandIndex, void *data, | |||
2549 | * Send a device-specific write command. | 2547 | * Send a device-specific write command. |
2550 | * | 2548 | * |
2551 | * \param fd file descriptor. | 2549 | * \param fd file descriptor. |
2552 | * \param drmCommandIndex command index | 2550 | * \param drmCommandIndex command index |
2553 | * \param data source pointer of the data to be written. | 2551 | * \param data source pointer of the data to be written. |
2554 | * \param size size of the data to be written. | 2552 | * \param size size of the data to be written. |
2555 | * | 2553 | * |
2556 | * \return zero on success, or a negative value on failure. | 2554 | * \return zero on success, or a negative value on failure. |
2557 | * | 2555 | * |
2558 | * \internal | 2556 | * \internal |
2559 | * It issues a write ioctl given by | 2557 | * It issues a write ioctl given by |
2560 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. | 2558 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. |
2561 | */ | 2559 | */ |
2562 | int drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data, | 2560 | int drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data, |
@@ -2564,11 +2562,11 @@ int drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data, | |||
2564 | { | 2562 | { |
2565 | unsigned long request; | 2563 | unsigned long request; |
2566 | 2564 | ||
2567 | request = DRM_IOC( DRM_IOC_WRITE, DRM_IOCTL_BASE, | 2565 | request = DRM_IOC( DRM_IOC_WRITE, DRM_IOCTL_BASE, |
2568 | DRM_COMMAND_BASE + drmCommandIndex, size); | 2566 | DRM_COMMAND_BASE + drmCommandIndex, size); |
2569 | 2567 | ||
2570 | if (drmIoctl(fd, request, data)) { | 2568 | if (drmIoctl(fd, request, data)) { |
2571 | return -errno; | 2569 | return -errno; |
2572 | } | 2570 | } |
2573 | return 0; | 2571 | return 0; |
2574 | } | 2572 | } |
@@ -2578,14 +2576,14 @@ int drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data, | |||
2578 | * Send a device-specific read-write command. | 2576 | * Send a device-specific read-write command. |
2579 | * | 2577 | * |
2580 | * \param fd file descriptor. | 2578 | * \param fd file descriptor. |
2581 | * \param drmCommandIndex command index | 2579 | * \param drmCommandIndex command index |
2582 | * \param data source pointer of the data to be read and written. | 2580 | * \param data source pointer of the data to be read and written. |
2583 | * \param size size of the data to be read and written. | 2581 | * \param size size of the data to be read and written. |
2584 | * | 2582 | * |
2585 | * \return zero on success, or a negative value on failure. | 2583 | * \return zero on success, or a negative value on failure. |
2586 | * | 2584 | * |
2587 | * \internal | 2585 | * \internal |
2588 | * It issues a read-write ioctl given by | 2586 | * It issues a read-write ioctl given by |
2589 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. | 2587 | * \code DRM_COMMAND_BASE + drmCommandIndex \endcode. |
2590 | */ | 2588 | */ |
2591 | int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, | 2589 | int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, |
@@ -2593,11 +2591,11 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, | |||
2593 | { | 2591 | { |
2594 | unsigned long request; | 2592 | unsigned long request; |
2595 | 2593 | ||
2596 | request = DRM_IOC( DRM_IOC_READ|DRM_IOC_WRITE, DRM_IOCTL_BASE, | 2594 | request = DRM_IOC( DRM_IOC_READ|DRM_IOC_WRITE, DRM_IOCTL_BASE, |
2597 | DRM_COMMAND_BASE + drmCommandIndex, size); | 2595 | DRM_COMMAND_BASE + drmCommandIndex, size); |
2598 | 2596 | ||
2599 | if (drmIoctl(fd, request, data)) | 2597 | if (drmIoctl(fd, request, data)) |
2600 | return -errno; | 2598 | return -errno; |
2601 | return 0; | 2599 | return 0; |
2602 | } | 2600 | } |
2603 | 2601 | ||
@@ -2611,9 +2609,9 @@ static struct { | |||
2611 | 2609 | ||
2612 | static int nr_fds = 0; | 2610 | static int nr_fds = 0; |
2613 | 2611 | ||
2614 | int drmOpenOnce(void *unused, | 2612 | int drmOpenOnce(void *unused, |
2615 | const char *BusID, | 2613 | const char *BusID, |
2616 | int *newlyopened) | 2614 | int *newlyopened) |
2617 | { | 2615 | { |
2618 | return drmOpenOnceWithType(BusID, newlyopened, DRM_NODE_PRIMARY); | 2616 | return drmOpenOnceWithType(BusID, newlyopened, DRM_NODE_PRIMARY); |
2619 | } | 2617 | } |
@@ -2622,19 +2620,19 @@ int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type) | |||
2622 | { | 2620 | { |
2623 | int i; | 2621 | int i; |
2624 | int fd; | 2622 | int fd; |
2625 | 2623 | ||
2626 | for (i = 0; i < nr_fds; i++) | 2624 | for (i = 0; i < nr_fds; i++) |
2627 | if ((strcmp(BusID, connection[i].BusID) == 0) && | 2625 | if ((strcmp(BusID, connection[i].BusID) == 0) && |
2628 | (connection[i].type == type)) { | 2626 | (connection[i].type == type)) { |
2629 | connection[i].refcount++; | 2627 | connection[i].refcount++; |
2630 | *newlyopened = 0; | 2628 | *newlyopened = 0; |
2631 | return connection[i].fd; | 2629 | return connection[i].fd; |
2632 | } | 2630 | } |
2633 | 2631 | ||
2634 | fd = drmOpenWithType(NULL, BusID, type); | 2632 | fd = drmOpenWithType(NULL, BusID, type); |
2635 | if (fd < 0 || nr_fds == DRM_MAX_FDS) | 2633 | if (fd < 0 || nr_fds == DRM_MAX_FDS) |
2636 | return fd; | 2634 | return fd; |
2637 | 2635 | ||
2638 | connection[nr_fds].BusID = strdup(BusID); | 2636 | connection[nr_fds].BusID = strdup(BusID); |
2639 | connection[nr_fds].fd = fd; | 2637 | connection[nr_fds].fd = fd; |
2640 | connection[nr_fds].refcount = 1; | 2638 | connection[nr_fds].refcount = 1; |
@@ -2642,9 +2640,9 @@ int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type) | |||
2642 | *newlyopened = 1; | 2640 | *newlyopened = 1; |
2643 | 2641 | ||
2644 | if (0) | 2642 | if (0) |
2645 | fprintf(stderr, "saved connection %d for %s %d\n", | 2643 | fprintf(stderr, "saved connection %d for %s %d\n", |
2646 | nr_fds, connection[nr_fds].BusID, | 2644 | nr_fds, connection[nr_fds].BusID, |
2647 | strcmp(BusID, connection[nr_fds].BusID)); | 2645 | strcmp(BusID, connection[nr_fds].BusID)); |
2648 | 2646 | ||
2649 | nr_fds++; | 2647 | nr_fds++; |
2650 | 2648 | ||
@@ -2656,180 +2654,180 @@ void drmCloseOnce(int fd) | |||
2656 | int i; | 2654 | int i; |
2657 | 2655 | ||
2658 | for (i = 0; i < nr_fds; i++) { | 2656 | for (i = 0; i < nr_fds; i++) { |
2659 | if (fd == connection[i].fd) { | 2657 | if (fd == connection[i].fd) { |
2660 | if (--connection[i].refcount == 0) { | 2658 | if (--connection[i].refcount == 0) { |
2661 | drmClose(connection[i].fd); | 2659 | drmClose(connection[i].fd); |
2662 | free(connection[i].BusID); | 2660 | free(connection[i].BusID); |
2663 | 2661 | ||
2664 | if (i < --nr_fds) | 2662 | if (i < --nr_fds) |
2665 | connection[i] = connection[nr_fds]; | 2663 | connection[i] = connection[nr_fds]; |
2666 | 2664 | ||
2667 | return; | 2665 | return; |
2668 | } | 2666 | } |
2669 | } | 2667 | } |
2670 | } | 2668 | } |
2671 | } | 2669 | } |
2672 | 2670 | ||
2673 | int drmSetMaster(int fd) | 2671 | int drmSetMaster(int fd) |
2674 | { | 2672 | { |
2675 | return drmIoctl(fd, DRM_IOCTL_SET_MASTER, NULL); | 2673 | return drmIoctl(fd, DRM_IOCTL_SET_MASTER, NULL); |
2676 | } | 2674 | } |
2677 | 2675 | ||
2678 | int drmDropMaster(int fd) | 2676 | int drmDropMaster(int fd) |
2679 | { | 2677 | { |
2680 | return drmIoctl(fd, DRM_IOCTL_DROP_MASTER, NULL); | 2678 | return drmIoctl(fd, DRM_IOCTL_DROP_MASTER, NULL); |
2681 | } | 2679 | } |
2682 | 2680 | ||
2683 | char *drmGetDeviceNameFromFd(int fd) | 2681 | char *drmGetDeviceNameFromFd(int fd) |
2684 | { | 2682 | { |
2685 | char name[128]; | 2683 | char name[128]; |
2686 | struct stat sbuf; | 2684 | struct stat sbuf; |
2687 | dev_t d; | 2685 | dev_t d; |
2688 | int i; | 2686 | int i; |
2689 | 2687 | ||
2690 | /* The whole drmOpen thing is a fiasco and we need to find a way | 2688 | /* The whole drmOpen thing is a fiasco and we need to find a way |
2691 | * back to just using open(2). For now, however, lets just make | 2689 | * back to just using open(2). For now, however, lets just make |
2692 | * things worse with even more ad hoc directory walking code to | 2690 | * things worse with even more ad hoc directory walking code to |
2693 | * discover the device file name. */ | 2691 | * discover the device file name. */ |
2694 | 2692 | ||
2695 | fstat(fd, &sbuf); | 2693 | fstat(fd, &sbuf); |
2696 | d = sbuf.st_rdev; | 2694 | d = sbuf.st_rdev; |
2697 | 2695 | ||
2698 | for (i = 0; i < DRM_MAX_MINOR; i++) { | 2696 | for (i = 0; i < DRM_MAX_MINOR; i++) { |
2699 | snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i); | 2697 | snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i); |
2700 | if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) | 2698 | if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) |
2701 | break; | 2699 | break; |
2702 | } | 2700 | } |
2703 | if (i == DRM_MAX_MINOR) | 2701 | if (i == DRM_MAX_MINOR) |
2704 | return NULL; | 2702 | return NULL; |
2705 | 2703 | ||
2706 | return strdup(name); | 2704 | return strdup(name); |
2707 | } | 2705 | } |
2708 | 2706 | ||
2709 | int drmGetNodeTypeFromFd(int fd) | 2707 | int drmGetNodeTypeFromFd(int fd) |
2710 | { | 2708 | { |
2711 | struct stat sbuf; | 2709 | struct stat sbuf; |
2712 | int maj, min, type; | 2710 | int maj, min, type; |
2713 | 2711 | ||
2714 | if (fstat(fd, &sbuf)) | 2712 | if (fstat(fd, &sbuf)) |
2715 | return -1; | 2713 | return -1; |
2716 | 2714 | ||
2717 | maj = major(sbuf.st_rdev); | 2715 | maj = major(sbuf.st_rdev); |
2718 | min = minor(sbuf.st_rdev); | 2716 | min = minor(sbuf.st_rdev); |
2719 | 2717 | ||
2720 | if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) { | 2718 | if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) { |
2721 | errno = EINVAL; | 2719 | errno = EINVAL; |
2722 | return -1; | 2720 | return -1; |
2723 | } | 2721 | } |
2724 | 2722 | ||
2725 | type = drmGetMinorType(min); | 2723 | type = drmGetMinorType(min); |
2726 | if (type == -1) | 2724 | if (type == -1) |
2727 | errno = ENODEV; | 2725 | errno = ENODEV; |
2728 | return type; | 2726 | return type; |
2729 | } | 2727 | } |
2730 | 2728 | ||
2731 | int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) | 2729 | int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) |
2732 | { | 2730 | { |
2733 | struct drm_prime_handle args; | 2731 | struct drm_prime_handle args; |
2734 | int ret; | 2732 | int ret; |
2735 | 2733 | ||
2736 | memclear(args); | 2734 | memclear(args); |
2737 | args.fd = -1; | 2735 | args.fd = -1; |
2738 | args.handle = handle; | 2736 | args.handle = handle; |
2739 | args.flags = flags; | 2737 | args.flags = flags; |
2740 | ret = drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); | 2738 | ret = drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); |
2741 | if (ret) | 2739 | if (ret) |
2742 | return ret; | 2740 | return ret; |
2743 | 2741 | ||
2744 | *prime_fd = args.fd; | 2742 | *prime_fd = args.fd; |
2745 | return 0; | 2743 | return 0; |
2746 | } | 2744 | } |
2747 | 2745 | ||
2748 | int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) | 2746 | int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) |
2749 | { | 2747 | { |
2750 | struct drm_prime_handle args; | 2748 | struct drm_prime_handle args; |
2751 | int ret; | 2749 | int ret; |
2752 | 2750 | ||
2753 | memclear(args); | 2751 | memclear(args); |
2754 | args.fd = prime_fd; | 2752 | args.fd = prime_fd; |
2755 | ret = drmIoctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args); | 2753 | ret = drmIoctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args); |
2756 | if (ret) | 2754 | if (ret) |
2757 | return ret; | 2755 | return ret; |
2758 | 2756 | ||
2759 | *handle = args.handle; | 2757 | *handle = args.handle; |
2760 | return 0; | 2758 | return 0; |
2761 | } | 2759 | } |
2762 | 2760 | ||
2763 | static char *drmGetMinorNameForFD(int fd, int type) | 2761 | static char *drmGetMinorNameForFD(int fd, int type) |
2764 | { | 2762 | { |
2765 | #ifdef __linux__ | 2763 | #ifdef __linux__ |
2766 | DIR *sysdir; | 2764 | DIR *sysdir; |
2767 | struct dirent *pent, *ent; | 2765 | struct dirent *pent, *ent; |
2768 | struct stat sbuf; | 2766 | struct stat sbuf; |
2769 | const char *name = drmGetMinorName(type); | 2767 | const char *name = drmGetMinorName(type); |
2770 | int len; | 2768 | int len; |
2771 | char dev_name[64], buf[64]; | 2769 | char dev_name[64], buf[64]; |
2772 | long name_max; | 2770 | long name_max; |
2773 | int maj, min; | 2771 | int maj, min; |
2774 | 2772 | ||
2775 | if (!name) | 2773 | if (!name) |
2776 | return NULL; | 2774 | return NULL; |
2777 | 2775 | ||
2778 | len = strlen(name); | 2776 | len = strlen(name); |
2779 | 2777 | ||
2780 | if (fstat(fd, &sbuf)) | 2778 | if (fstat(fd, &sbuf)) |
2781 | return NULL; | 2779 | return NULL; |
2782 | 2780 | ||
2783 | maj = major(sbuf.st_rdev); | 2781 | maj = major(sbuf.st_rdev); |
2784 | min = minor(sbuf.st_rdev); | 2782 | min = minor(sbuf.st_rdev); |
2785 | 2783 | ||
2786 | if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) | 2784 | if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) |
2787 | return NULL; | 2785 | return NULL; |
2788 | 2786 | ||
2789 | snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); | 2787 | snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); |
2790 | 2788 | ||
2791 | sysdir = opendir(buf); | 2789 | sysdir = opendir(buf); |
2792 | if (!sysdir) | 2790 | if (!sysdir) |
2793 | return NULL; | 2791 | return NULL; |
2794 | 2792 | ||
2795 | name_max = fpathconf(dirfd(sysdir), _PC_NAME_MAX); | 2793 | name_max = fpathconf(dirfd(sysdir), _PC_NAME_MAX); |
2796 | if (name_max == -1) | 2794 | if (name_max == -1) |
2797 | goto out_close_dir; | 2795 | goto out_close_dir; |
2798 | 2796 | ||
2799 | pent = malloc(offsetof(struct dirent, d_name) + name_max + 1); | 2797 | pent = malloc(offsetof(struct dirent, d_name) + name_max + 1); |
2800 | if (pent == NULL) | 2798 | if (pent == NULL) |
2801 | goto out_close_dir; | 2799 | goto out_close_dir; |
2802 | 2800 | ||
2803 | while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) { | 2801 | while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) { |
2804 | if (strncmp(ent->d_name, name, len) == 0) { | 2802 | if (strncmp(ent->d_name, name, len) == 0) { |
2805 | snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s", | 2803 | snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s", |
2806 | ent->d_name); | 2804 | ent->d_name); |
2807 | 2805 | ||
2808 | free(pent); | 2806 | free(pent); |
2809 | closedir(sysdir); | 2807 | closedir(sysdir); |
2810 | 2808 | ||
2811 | return strdup(dev_name); | 2809 | return strdup(dev_name); |
2812 | } | 2810 | } |
2813 | } | 2811 | } |
2814 | 2812 | ||
2815 | free(pent); | 2813 | free(pent); |
2816 | 2814 | ||
2817 | out_close_dir: | 2815 | out_close_dir: |
2818 | closedir(sysdir); | 2816 | closedir(sysdir); |
2819 | #else | 2817 | #else |
2820 | #warning "Missing implementation of drmGetMinorNameForFD" | 2818 | #warning "Missing implementation of drmGetMinorNameForFD" |
2821 | #endif | 2819 | #endif |
2822 | return NULL; | 2820 | return NULL; |
2823 | } | 2821 | } |
2824 | 2822 | ||
2825 | char *drmGetPrimaryDeviceNameFromFd(int fd) | 2823 | char *drmGetPrimaryDeviceNameFromFd(int fd) |
2826 | { | 2824 | { |
2827 | return drmGetMinorNameForFD(fd, DRM_NODE_PRIMARY); | 2825 | return drmGetMinorNameForFD(fd, DRM_NODE_PRIMARY); |
2828 | } | 2826 | } |
2829 | 2827 | ||
2830 | char *drmGetRenderDeviceNameFromFd(int fd) | 2828 | char *drmGetRenderDeviceNameFromFd(int fd) |
2831 | { | 2829 | { |
2832 | return drmGetMinorNameForFD(fd, DRM_NODE_RENDER); | 2830 | return drmGetMinorNameForFD(fd, DRM_NODE_RENDER); |
2833 | } | 2831 | } |
2834 | 2832 | ||
2835 | static int drmParseSubsystemType(int maj, int min) | 2833 | static int drmParseSubsystemType(int maj, int min) |
@@ -3005,14 +3003,14 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name, | |||
3005 | char *addr; | 3003 | char *addr; |
3006 | 3004 | ||
3007 | *device = calloc(1, sizeof(drmDevice) + | 3005 | *device = calloc(1, sizeof(drmDevice) + |
3008 | (DRM_NODE_MAX * (sizeof(void *) + max_node_str)) + | 3006 | (DRM_NODE_MAX * (sizeof(void *) + max_node_str)) + |
3009 | sizeof(drmPciBusInfo) + | 3007 | sizeof(drmPciBusInfo) + |
3010 | sizeof(drmPciDeviceInfo)); | 3008 | sizeof(drmPciDeviceInfo)); |
3011 | if (!*device) | 3009 | if (!*device) |
3012 | return -ENOMEM; | 3010 | return -ENOMEM; |
3013 | 3011 | ||
3014 | addr = (char*)*device; | 3012 | addr = (char*)*device; |
3015 | 3013 | ||
3016 | (*device)->bustype = DRM_BUS_PCI; | 3014 | (*device)->bustype = DRM_BUS_PCI; |
3017 | (*device)->available_nodes = 1 << node_type; | 3015 | (*device)->available_nodes = 1 << node_type; |
3018 | 3016 | ||
@@ -3268,8 +3266,8 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) | |||
3268 | 3266 | ||
3269 | device_count = 0; | 3267 | device_count = 0; |
3270 | for (i = 0; i < node_count; i++) { | 3268 | for (i = 0; i < node_count; i++) { |
3271 | if (!local_devices[i]) | 3269 | if (!local_devices[i]) |
3272 | continue; | 3270 | continue; |
3273 | 3271 | ||
3274 | if ((devices != NULL) && (device_count < max_devices)) | 3272 | if ((devices != NULL) && (device_count < max_devices)) |
3275 | devices[device_count] = local_devices[i]; | 3273 | devices[device_count] = local_devices[i]; |