intel: provide pci bus and dev info in base device struct

Having PCI bus and dev info in the base struct
'intel_device_info' enables us to utilize the info across
multiple drivers for several purposes, such as computing
device uuids in a multi-gpu system.

Signed-off-by: Jianxun Zhang <jianxun.zhang@linux.intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Rohan Garg <rohan.garg@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13936>
This commit is contained in:
Jianxun Zhang 2022-01-05 16:48:28 -08:00 committed by Marge Bot
parent 17b753459e
commit db8405670a
3 changed files with 42 additions and 5 deletions

View file

@ -27,6 +27,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <xf86drm.h>
#include "intel_device_info.h"
#include "intel/common/intel_gem.h"
#include "util/bitscan.h"
@ -1658,7 +1661,6 @@ bool
intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo)
{
int devid = 0;
const char *devid_override = getenv("INTEL_DEVID_OVERRIDE");
if (devid_override && strlen(devid_override) > 0) {
if (geteuid() == getuid()) {
@ -1685,11 +1687,32 @@ intel_get_device_info_from_fd(int fd, struct intel_device_info *devinfo)
return false;
devinfo->no_hw = true;
} else {
/* query the device id */
if (!getparam(fd, I915_PARAM_CHIPSET_ID, &devid))
/* Get PCI info.
*
* Some callers may already have a valid drm device which holds
* values of PCI fields queried here prior to calling this function.
* But making this query optional leads to a more cumbersome
* implementation. These callers still need to initialize the fields
* somewhere out of this function and rely on an ioctl to get PCI
* device id for the next step when skipping this drm query.
*/
drmDevicePtr drmdev = NULL;
if (drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, &drmdev)) {
mesa_loge("Failed to query drm device.");
return false;
if (!intel_get_device_info_from_pci_id(devid, devinfo))
}
if (!intel_get_device_info_from_pci_id
(drmdev->deviceinfo.pci->device_id, devinfo)) {
drmFreeDevice(&drmdev);
return false;
}
devinfo->pci_domain = drmdev->businfo.pci->domain;
devinfo->pci_bus = drmdev->businfo.pci->bus;
devinfo->pci_dev = drmdev->businfo.pci->dev;
devinfo->pci_func = drmdev->businfo.pci->func;
devinfo->pci_device_id = drmdev->deviceinfo.pci->device_id;
devinfo->pci_revision_id = drmdev->deviceinfo.pci->revision_id;
drmFreeDevice(&drmdev);
devinfo->no_hw = env_var_as_boolean("INTEL_NO_HW", false);
}

View file

@ -93,9 +93,23 @@ struct intel_device_info
int ver;
int verx10;
int display_ver;
/**
* This revision is from ioctl (I915_PARAM_REVISION) unlike
* pci_revision_id from drm device. Its value is not always
* same as the pci_revision_id.
*/
int revision;
int gt;
/* PCI info */
uint16_t pci_domain;
uint8_t pci_bus;
uint8_t pci_dev;
uint8_t pci_func;
uint16_t pci_device_id;
uint8_t pci_revision_id;
enum intel_platform platform;
bool has_hiz_and_separate_stencil;

View file

@ -31,7 +31,7 @@ libintel_dev = static_library(
['intel_dev'],
[files_libintel_dev, sha1_h],
include_directories : [inc_include, inc_src, inc_intel],
dependencies : idep_mesautil,
dependencies : [dep_libdrm, idep_mesautil],
c_args : [no_override_init_args],
gnu_symbol_visibility : 'hidden',
)