Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

r600_drm.c 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * on the rights to use, copy, modify, merge, publish, distribute, sub
  8. * license, and/or sell copies of the Software, and to permit persons to whom
  9. * the Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Jerome Glisse
  25. * Corbin Simpson <MostAwesomeDude@gmail.com>
  26. * Joakim Sindholt <opensource@zhasha.com>
  27. */
  28. #include <stdio.h>
  29. #include <errno.h>
  30. #include <sys/ioctl.h>
  31. #include "util/u_inlines.h"
  32. #include "util/u_debug.h"
  33. #include <pipebuffer/pb_bufmgr.h>
  34. #include "r600.h"
  35. #include "r600_priv.h"
  36. #include "r600_drm_public.h"
  37. #include "xf86drm.h"
  38. #include "radeon_drm.h"
  39. static int radeon_get_device(struct radeon *radeon)
  40. {
  41. struct drm_radeon_info info;
  42. int r;
  43. radeon->device = 0;
  44. info.request = RADEON_INFO_DEVICE_ID;
  45. info.value = (uintptr_t)&radeon->device;
  46. r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
  47. sizeof(struct drm_radeon_info));
  48. return r;
  49. }
  50. struct radeon *radeon_new(int fd, unsigned device)
  51. {
  52. struct radeon *radeon;
  53. int r;
  54. radeon = calloc(1, sizeof(*radeon));
  55. if (radeon == NULL) {
  56. return NULL;
  57. }
  58. radeon->fd = fd;
  59. radeon->device = device;
  60. radeon->refcount = 1;
  61. if (fd >= 0) {
  62. r = radeon_get_device(radeon);
  63. if (r) {
  64. fprintf(stderr, "Failed to get device id\n");
  65. return radeon_decref(radeon);
  66. }
  67. }
  68. radeon->family = radeon_family_from_device(radeon->device);
  69. if (radeon->family == CHIP_UNKNOWN) {
  70. fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->device);
  71. return radeon_decref(radeon);
  72. }
  73. switch (radeon->family) {
  74. case CHIP_R600:
  75. case CHIP_RV610:
  76. case CHIP_RV630:
  77. case CHIP_RV670:
  78. case CHIP_RV620:
  79. case CHIP_RV635:
  80. case CHIP_RS780:
  81. case CHIP_RS880:
  82. case CHIP_RV770:
  83. case CHIP_RV730:
  84. case CHIP_RV710:
  85. case CHIP_RV740:
  86. case CHIP_CEDAR:
  87. case CHIP_REDWOOD:
  88. case CHIP_JUNIPER:
  89. case CHIP_CYPRESS:
  90. case CHIP_HEMLOCK:
  91. break;
  92. case CHIP_R100:
  93. case CHIP_RV100:
  94. case CHIP_RS100:
  95. case CHIP_RV200:
  96. case CHIP_RS200:
  97. case CHIP_R200:
  98. case CHIP_RV250:
  99. case CHIP_RS300:
  100. case CHIP_RV280:
  101. case CHIP_R300:
  102. case CHIP_R350:
  103. case CHIP_RV350:
  104. case CHIP_RV380:
  105. case CHIP_R420:
  106. case CHIP_R423:
  107. case CHIP_RV410:
  108. case CHIP_RS400:
  109. case CHIP_RS480:
  110. case CHIP_RS600:
  111. case CHIP_RS690:
  112. case CHIP_RS740:
  113. case CHIP_RV515:
  114. case CHIP_R520:
  115. case CHIP_RV530:
  116. case CHIP_RV560:
  117. case CHIP_RV570:
  118. case CHIP_R580:
  119. default:
  120. fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n",
  121. __func__, radeon->device);
  122. break;
  123. }
  124. /* setup class */
  125. switch (radeon->family) {
  126. case CHIP_R600:
  127. case CHIP_RV610:
  128. case CHIP_RV630:
  129. case CHIP_RV670:
  130. case CHIP_RV620:
  131. case CHIP_RV635:
  132. case CHIP_RS780:
  133. case CHIP_RS880:
  134. radeon->chip_class = R600;
  135. break;
  136. case CHIP_RV770:
  137. case CHIP_RV730:
  138. case CHIP_RV710:
  139. case CHIP_RV740:
  140. radeon->chip_class = R700;
  141. break;
  142. case CHIP_CEDAR:
  143. case CHIP_REDWOOD:
  144. case CHIP_JUNIPER:
  145. case CHIP_CYPRESS:
  146. case CHIP_HEMLOCK:
  147. radeon->chip_class = EVERGREEN;
  148. break;
  149. default:
  150. fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n",
  151. __func__, radeon->device);
  152. break;
  153. }
  154. radeon->mman = pb_malloc_bufmgr_create();
  155. if (!radeon->mman)
  156. return NULL;
  157. radeon->kman = radeon_bo_pbmgr_create(radeon);
  158. if (!radeon->kman)
  159. return NULL;
  160. radeon->cman = pb_cache_manager_create(radeon->kman, 100000);
  161. if (!radeon->cman)
  162. return NULL;
  163. return radeon;
  164. }
  165. struct radeon *r600_drm_winsys_create(int drmfd)
  166. {
  167. return radeon_new(drmfd, 0);
  168. }
  169. struct radeon *radeon_decref(struct radeon *radeon)
  170. {
  171. if (radeon == NULL)
  172. return NULL;
  173. if (--radeon->refcount > 0) {
  174. return NULL;
  175. }
  176. radeon->mman->destroy(radeon->mman);
  177. radeon->cman->destroy(radeon->cman);
  178. radeon->kman->destroy(radeon->kman);
  179. drmClose(radeon->fd);
  180. free(radeon);
  181. return NULL;
  182. }