turnip: add wrappers around DRM_MSM_GET_PARAM
authorChia-I Wu <olvaffe@gmail.com>
Thu, 10 Jan 2019 23:27:28 +0000 (15:27 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
Add tu_drm_get_gpu_id and tu_drm_get_gmem_size.

src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_drm.c
src/freedreno/vulkan/tu_private.h

index 65a0e40545280bfd7d6f5e5639bf863a587563e1..e321f4ad39f1ede6e45c6afab6d6759de7ccafd1 100644 (file)
@@ -152,7 +152,6 @@ tu_physical_device_init(struct tu_physical_device *device,
    drmVersionPtr version;
    int fd;
    int master_fd = -1;
-   uint64_t val;
 
    fd = open(path, O_RDWR | O_CLOEXEC);
    if (fd < 0) {
@@ -214,23 +213,21 @@ tu_physical_device_init(struct tu_physical_device *device,
    device->master_fd = master_fd;
    device->local_fd = fd;
 
-   if (tu_drm_query_param(device, MSM_PARAM_GPU_ID, &val)) {
+   if (tu_drm_get_gpu_id(device, &device->gpu_id)) {
       if (instance->debug_flags & TU_DEBUG_STARTUP)
          tu_logi("Could not query the GPU ID");
       result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
                          "could not get GPU ID");
       goto fail;
    }
-   device->gpu_id = val;
 
-   if (tu_drm_query_param(device, MSM_PARAM_GMEM_SIZE, &val)) {
+   if (tu_drm_get_gmem_size(device, &device->gmem_size)) {
       if (instance->debug_flags & TU_DEBUG_STARTUP)
          tu_logi("Could not query the GMEM size");
       result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
                          "could not get GMEM size");
       goto fail;
    }
-   device->gmem_size = val;
 
    memset(device->name, 0, sizeof(device->name));
    sprintf(device->name, "FD%d", device->gpu_id);
index d0d1cd8d4f64104f27cddcf40f345ee5692e6efe..b28de8f2c0660068ddc8a50475196c60809743c7 100644 (file)
 
 #include "drm/msm_drm.h"
 
+static int
+tu_drm_get_param(const struct tu_physical_device *dev,
+                 uint32_t param,
+                 uint64_t *value)
+{
+   /* Technically this requires a pipe, but the kernel only supports one pipe
+    * anyway at the time of writing and most of these are clearly pipe
+    * independent. */
+   struct drm_msm_param req = {
+      .pipe = MSM_PIPE_3D0,
+      .param = param,
+   };
+
+   int ret = drmCommandWriteRead(dev->local_fd, DRM_MSM_GET_PARAM, &req,
+                                 sizeof(req));
+   if (ret)
+      return ret;
+
+   *value = req.value;
+
+   return 0;
+}
+
+int
+tu_drm_get_gpu_id(const struct tu_physical_device *dev, uint32_t *id)
+{
+   uint64_t value;
+   int ret = tu_drm_get_param(dev, MSM_PARAM_GPU_ID, &value);
+   if (ret)
+      return ret;
+
+   *id = value;
+   return 0;
+}
+
+int
+tu_drm_get_gmem_size(const struct tu_physical_device *dev, uint32_t *size)
+{
+   uint64_t value;
+   int ret = tu_drm_get_param(dev, MSM_PARAM_GMEM_SIZE, &value);
+   if (ret)
+      return ret;
+
+   *size = value;
+   return 0;
+}
+
 /**
  * Return gem handle on success. Return 0 on failure.
  */
@@ -90,26 +137,3 @@ tu_gem_info_iova(struct tu_device *dev, uint32_t gem_handle)
 {
    return tu_gem_info(dev, gem_handle, MSM_INFO_GET_IOVA);
 }
-
-int
-tu_drm_query_param(struct tu_physical_device *dev,
-                   uint32_t param,
-                   uint64_t *value)
-{
-   /* Technically this requires a pipe, but the kernel only supports one pipe
-    * anyway at the time of writing and most of these are clearly pipe
-    * independent. */
-   struct drm_msm_param req = {
-      .pipe = MSM_PIPE_3D0,
-      .param = param,
-   };
-
-   int ret = drmCommandWriteRead(dev->local_fd, DRM_MSM_GET_PARAM, &req,
-                                 sizeof(req));
-   if (ret)
-      return ret;
-
-   *value = req.value;
-
-   return 0;
-}
index 7209785840ea5596fa7e07bb4a4e677c0e749dba..a2deb98abf8185908ebb6d3c14285d64cba906dc 100644 (file)
@@ -1189,6 +1189,12 @@ struct tu_fence
    uint32_t temp_syncobj;
 };
 
+int
+tu_drm_get_gpu_id(const struct tu_physical_device *dev, uint32_t *id);
+
+int
+tu_drm_get_gmem_size(const struct tu_physical_device *dev, uint32_t *size);
+
 uint32_t
 tu_gem_new(struct tu_device *dev, uint64_t size, uint32_t flags);
 void
@@ -1197,10 +1203,6 @@ uint64_t
 tu_gem_info_offset(struct tu_device *dev, uint32_t gem_handle);
 uint64_t
 tu_gem_info_iova(struct tu_device *dev, uint32_t gem_handle);
-int
-tu_drm_query_param(struct tu_physical_device *dev,
-                   uint32_t param,
-                   uint64_t *value);
 
 #define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType)                          \
                                                                              \