[Mesa-dev] loader: Add amdgpu code to loader.c

Submitted by Albert Freeman on Nov. 24, 2016, 5:25 a.m.

Details

Message ID CAHD8uZM-+dnY_EtrUyE4hUr_d_77nGbWFjnk0O-wNkxd8g_NEQ@mail.gmail.com
State New
Headers show
Series "loader: Add amdgpu code to loader.c" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Albert Freeman Nov. 24, 2016, 5:25 a.m.
I wrote this code in response to a issue someone on mesa-users had
(https://lists.freedesktop.org/archives/mesa-users/2016-October/001231.html).
They didn't reply so I don't know if the patch resolved the issue. Can
someone please determine its usefulness. Also please check if
drmCommandWrite() is the correct function to use. I can't test the
code, I don't have amdgpu.

Patch hide | download patch | download mbox

diff --git a/mesa/src/loader/loader.c b/mesa2/src/loader/loader.c
index 3e60e4c..4a89ba4 100644
--- a/mesa/src/loader/loader.c
+++ b/mesa2/src/loader/loader.c
@@ -515,6 +515,8 @@  sysfs_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 #include <i915_drm.h>
 /* for radeon */
 #include <radeon_drm.h>
+/* for amdgpu */
+#include <amdgpu_drm.h>
 
 static int
 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
@@ -564,6 +566,26 @@  drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 	 *chip_id = -1;
       }
    }
+   else if (strcmp(version->name, "amdgpu") == 0) {
+      struct drm_amdgpu_info info;
+      struct drm_amdgpu_info_device info_device;
+      int ret;
+
+      *vendor_id = 0x1002;
+
+      memset(&info, 0, sizeof(info));
+      memset(&info_device, 0, sizeof(info_device));
+      info.query = AMDGPU_INFO_DEV_INFO;
+      info.return_pointer = (uint64_t) &info_device;
+      info.return_size = sizeof(struct drm_amdgpu_info_device);
+      ret = drmCommandWrite(fd, DRM_AMDGPU_INFO, &info, sizeof(info));
+      if (ret) {
+         log_(_LOADER_WARNING, "MESA-LOADER: failed to get info for amdgpu\n");
+         *chip_id = -1;
+      } else {
+         *chip_id = info_device.device_id;
+      }
+   }
    else if (strcmp(version->name, "nouveau") == 0) {
       *vendor_id = 0x10de;
       /* not used */

Comments

A different patch to that code has been applied that does the same
thing in a different (better) way.

On 24 November 2016 at 05:25, Albert Freeman <albertwdfreeman@gmail.com> wrote:
> I wrote this code in response to a issue someone on mesa-users had
> (https://lists.freedesktop.org/archives/mesa-users/2016-October/001231.html).
> They didn't reply so I don't know if the patch resolved the issue. Can
> someone please determine its usefulness. Also please check if
> drmCommandWrite() is the correct function to use. I can't test the
> code, I don't have amdgpu.
On 24 November 2016 at 05:50, Albert Freeman <albertwdfreeman@gmail.com> wrote:
> A different patch to that code has been applied that does the same
> thing in a different (better) way.
>
FWIW I would strongly suggest using radeonsi with 13.0 considering the
amazing work that Marek, Nicolai and others have put.

If one insists on using 12.0 their would need either a) libudev at
build and runtime or b) pass the following to their configure
--enable-sysfs

With 13.0 (as you noticed) there is just a single codepath (as opposed
to three beforehand) and things should work as expected. Barring the
odd libdrm bug of course ;-)
Emil