intel/dump_gpu: Add an ensure_device_info helper
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 19 Mar 2020 21:44:56 +0000 (16:44 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Mar 2020 06:28:29 +0000 (06:28 +0000)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4250>

src/intel/tools/intel_dump_gpu.c

index 551477db23bc15b43973e8c825bb97dc7c3fe6c2..fabbf4f73d8f82e863d782c2ef79b55d88c093f8 100644 (file)
@@ -116,6 +116,20 @@ static struct gen_device_info devinfo = {0};
 static int device = 0;
 static struct aub_file aub_file;
 
+static void
+ensure_device_info(int fd)
+{
+   /* We can't do this at open time as we're not yet authenticated. */
+   if (device == 0) {
+      fail_if(!gen_get_device_info_from_fd(fd, &devinfo),
+              "failed to identify chipset.\n");
+      device = devinfo.chipset_id;
+   } else if (devinfo.gen == 0) {
+      fail_if(!gen_get_device_info_from_pci_id(device, &devinfo),
+              "failed to identify chipset.\n");
+   }
+}
+
 static void *
 relocate_bo(int fd, struct bo *bo, const struct drm_i915_gem_execbuffer2 *execbuffer2,
             const struct drm_i915_gem_exec_object2 *obj)
@@ -202,15 +216,7 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
    int batch_index;
    void *data;
 
-   /* We can't do this at open time as we're not yet authenticated. */
-   if (device == 0) {
-      fail_if(!gen_get_device_info_from_fd(fd, &devinfo),
-              "failed to identify chipset.\n");
-      device = devinfo.chipset_id;
-   } else if (devinfo.gen == 0) {
-      fail_if(!gen_get_device_info_from_pci_id(device, &devinfo),
-              "failed to identify chipset.\n");
-   }
+   ensure_device_info(fd);
 
    if (!aub_file.file) {
       aub_file_init(&aub_file, output_file,
@@ -470,6 +476,8 @@ ioctl(int fd, unsigned long request, ...)
       case DRM_IOCTL_I915_GETPARAM: {
          struct drm_i915_getparam *getparam = argp;
 
+         ensure_device_info(fd);
+
          if (getparam->param == I915_PARAM_CHIPSET_ID)
             return get_pci_id(fd, getparam->value);