turnip: Implement pipe-less param query.
authorBas Nieuwenhuizen <basni@chromium.org>
Fri, 21 Dec 2018 13:49:30 +0000 (14:49 +0100)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_drm.c
src/freedreno/vulkan/tu_private.h

index e595152d4657649dcba7f9e43c80d3eb15fb365f..b42bb4cb03b9bc2189ac82e409d806f97271a8b7 100644 (file)
@@ -149,7 +149,6 @@ tu_physical_device_init(struct tu_physical_device *device,
    drmVersionPtr version;
    int fd;
    int master_fd = -1;
-   struct fd_pipe *tmp_pipe = NULL;
    uint64_t val;
 
    fd = open(path, O_RDWR | O_CLOEXEC);
@@ -214,35 +213,31 @@ tu_physical_device_init(struct tu_physical_device *device,
 
    device->drm_device = fd_device_new_dup(fd);
    if (!device->drm_device) {
+      if (instance->debug_flags & TU_DEBUG_STARTUP)
+         tu_logi("Could not create the libdrm device");
       result = vk_errorf(
         instance, VK_ERROR_INITIALIZATION_FAILED, "could not create the libdrm device");
        goto fail;
    }
 
-   tmp_pipe = fd_pipe_new(device->drm_device, FD_PIPE_3D);
-   if (!tmp_pipe) {
-      result = vk_errorf(
-        instance, VK_ERROR_INITIALIZATION_FAILED, "could not open the 3D pipe");
-      goto fail;
-   }
-
-   if (fd_pipe_get_param(tmp_pipe, FD_GPU_ID, &val)) {
+   if (tu_drm_query_param(device, MSM_PARAM_GPU_ID, &val)) {
+      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 (fd_pipe_get_param(tmp_pipe, FD_GMEM_SIZE, &val)) {
+   if (tu_drm_query_param(device, MSM_PARAM_GMEM_SIZE, &val)) {
+      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;
 
-   fd_pipe_del(tmp_pipe);
-   tmp_pipe = NULL;
-
    memset(device->name, 0, sizeof(device->name));
    sprintf(device->name, "FD%d", device->gpu_id);
 
@@ -285,8 +280,6 @@ tu_physical_device_init(struct tu_physical_device *device,
    return VK_SUCCESS;
 
 fail:
-   if (tmp_pipe)
-      fd_pipe_del(tmp_pipe);
    if (device->drm_device)
       fd_device_del(device->drm_device);
    close(fd);
index b8a4c6f8a98a13e1a6289ebf1b00267f1f1f1d5f..11c3b008155ead32859dbd92d5d9574898295f2a 100644 (file)
@@ -92,3 +92,24 @@ tu_gem_info_iova(struct tu_device *dev, uint32_t gem_handle)
 {
    return tu_gem_info(dev, gem_handle, MSM_INFO_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 5b5315ed15ea0aa02ea8715806d7abad7efd9662..454a051336e5a1f11d6266b4cc1d72ccb04d83cf 100644 (file)
@@ -1203,6 +1203,8 @@ 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)                          \
                                                                                \