etnaviv_gpu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 2015 Etnaviv Project
  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. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * 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 NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Christian Gmeiner <christian.gmeiner@gmail.com>
  25. */
  26. #include "etnaviv_priv.h"
  27. #include "etnaviv_drmif.h"
  28. static uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)
  29. {
  30. struct drm_etnaviv_param req = {
  31. .pipe = core,
  32. .param = param,
  33. };
  34. int ret;
  35. ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));
  36. if (ret) {
  37. ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret, strerror(errno));
  38. return 0;
  39. }
  40. return req.value;
  41. }
  42. drm_public struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)
  43. {
  44. struct etna_gpu *gpu;
  45. gpu = calloc(1, sizeof(*gpu));
  46. if (!gpu) {
  47. ERROR_MSG("allocation failed");
  48. goto fail;
  49. }
  50. gpu->dev = dev;
  51. gpu->core = core;
  52. gpu->model = get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);
  53. gpu->revision = get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);
  54. if (!gpu->model)
  55. goto fail;
  56. INFO_MSG(" GPU model: 0x%x (rev %x)", gpu->model, gpu->revision);
  57. return gpu;
  58. fail:
  59. if (gpu)
  60. etna_gpu_del(gpu);
  61. return NULL;
  62. }
  63. drm_public void etna_gpu_del(struct etna_gpu *gpu)
  64. {
  65. free(gpu);
  66. }
  67. drm_public int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,
  68. uint64_t *value)
  69. {
  70. struct etna_device *dev = gpu->dev;
  71. unsigned int core = gpu->core;
  72. switch(param) {
  73. case ETNA_GPU_MODEL:
  74. *value = gpu->model;
  75. return 0;
  76. case ETNA_GPU_REVISION:
  77. *value = gpu->revision;
  78. return 0;
  79. case ETNA_GPU_FEATURES_0:
  80. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);
  81. return 0;
  82. case ETNA_GPU_FEATURES_1:
  83. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);
  84. return 0;
  85. case ETNA_GPU_FEATURES_2:
  86. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);
  87. return 0;
  88. case ETNA_GPU_FEATURES_3:
  89. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);
  90. return 0;
  91. case ETNA_GPU_FEATURES_4:
  92. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);
  93. return 0;
  94. case ETNA_GPU_FEATURES_5:
  95. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);
  96. return 0;
  97. case ETNA_GPU_FEATURES_6:
  98. *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);
  99. return 0;
  100. case ETNA_GPU_STREAM_COUNT:
  101. *value = get_param(dev, core, ETNA_GPU_STREAM_COUNT);
  102. return 0;
  103. case ETNA_GPU_REGISTER_MAX:
  104. *value = get_param(dev, core, ETNA_GPU_REGISTER_MAX);
  105. return 0;
  106. case ETNA_GPU_THREAD_COUNT:
  107. *value = get_param(dev, core, ETNA_GPU_THREAD_COUNT);
  108. return 0;
  109. case ETNA_GPU_VERTEX_CACHE_SIZE:
  110. *value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);
  111. return 0;
  112. case ETNA_GPU_SHADER_CORE_COUNT:
  113. *value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);
  114. return 0;
  115. case ETNA_GPU_PIXEL_PIPES:
  116. *value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);
  117. return 0;
  118. case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
  119. *value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);
  120. return 0;
  121. case ETNA_GPU_BUFFER_SIZE:
  122. *value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);
  123. return 0;
  124. case ETNA_GPU_INSTRUCTION_COUNT:
  125. *value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);
  126. return 0;
  127. case ETNA_GPU_NUM_CONSTANTS:
  128. *value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);
  129. return 0;
  130. case ETNA_GPU_NUM_VARYINGS:
  131. *value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);
  132. return 0;
  133. default:
  134. ERROR_MSG("invalid param id: %d", param);
  135. return -1;
  136. }
  137. return 0;
  138. }