Read PCIe slot type from sysfs

Read the PCIe slot type from sysfs instead of libdrm.

Change-Id: I9392b9e18a209ac7332f6902bcafb3b6062c86c1


[ROCm/amdsmi commit: 656f12e0f3]
This commit is contained in:
Bill(Shuzhou) Liu
2023-10-03 11:11:56 -05:00
committed by Shuzhou Liu
parent 1b4acb28f8
commit 528161560d
7 changed files with 107 additions and 24 deletions
@@ -625,6 +625,19 @@ typedef enum {
typedef rsmi_freq_ind_t rsmi_freq_ind;
/// \endcond
/**
* @brief The values of this enum are used as PCIe slot type.
*/
typedef enum {
RSMI_PCIE_SLOT_PCIE = 0,
RSMI_PCIE_SLOT_CEM = 1,
RSMI_PCIE_SLOT_OAM = 2,
RSMI_PCIE_SLOT_UNKNOWN = 3 //!< An unknown
} rsmi_pcie_slot_type_t;
/// \cond Ignore in docs.
typedef rsmi_pcie_slot_type_t rsmi_pcie_slot_type;
/// \endcond
/**
* @brief The values of this enum are used to identify the various firmware
@@ -1391,6 +1404,26 @@ rsmi_status_t rsmi_dev_vendor_name_get(uint32_t dv_ind, char *name,
rsmi_status_t rsmi_dev_vram_vendor_get(uint32_t dv_ind, char *brand,
uint32_t len);
/**
* @brief Get the PCIe slot type of a gpu device.
*
* @details Given a device index @p dv_ind, a pointer to a caller provided
* char buffer @p type, this function will write the PCIe slot type of the
* device to @p type.
*
*
* @param[in] dv_ind a device index
*
* @param[inout] type a pointer to a caller provided buffer to which the
* type info will be written
*
* @retval ::RSMI_STATUS_SUCCESS is returned upon successful call.
*
*/
rsmi_status_t rsmi_dev_pcie_slot_type_get(uint32_t dv_ind,
rsmi_pcie_slot_type_t* type);
/**
* @brief Get the serial number string for a device
*
@@ -105,6 +105,7 @@ enum DevInfoTypes {
kDevDevRevID,
kDevDevProdName,
kDevDevProdNum,
kDevBoardInfo,
kDevVendorID,
kDevSubSysDevID,
kDevSubSysVendorID,
@@ -200,6 +201,9 @@ class Device {
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
int readDevInfo(DevInfoTypes type, std::size_t b_size,
void *p_binary_data);
// Get the property from a file which may contain multiple properties.
int readDevInfo(DevInfoTypes type, const std::string& property,
std::string& value);
int writeDevInfo(DevInfoTypes type, uint64_t val);
int writeDevInfo(DevInfoTypes type, std::string val);
@@ -269,6 +269,9 @@ class ScopedAcquire {
// In VM environment, the /proc/cpuinfo set hypervisor flag by default
bool is_vm_guest();
// trim a string
std::string trim(const std::string &s);
} // namespace smi
} // namespace amd
+23
View File
@@ -910,6 +910,29 @@ rsmi_dev_vendor_id_get(uint32_t dv_ind, uint16_t *id) {
return get_id(dv_ind, amd::smi::kDevVendorID, id);
}
rsmi_status_t
rsmi_dev_pcie_slot_type_get(uint32_t dv_ind, rsmi_pcie_slot_type_t* type) {
TRY
std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start =======";
LOG_TRACE(ss);
CHK_SUPPORT_NAME_ONLY(type)
DEVICE_MUTEX
std::string value;
int ret = dev->readDevInfo(amd::smi::kDevBoardInfo, "type", value);
if (ret != 0) return RSMI_STATUS_NOT_SUPPORTED;
*type = RSMI_PCIE_SLOT_PCIE;
if (value.compare("oam") == 0) *type=RSMI_PCIE_SLOT_OAM;
else if (value.compare("cem") == 0 ) *type=RSMI_PCIE_SLOT_CEM;
else if (value.compare("unknown") == 0 ) *type=RSMI_PCIE_SLOT_UNKNOWN;
return RSMI_STATUS_SUCCESS;
CATCH
}
rsmi_status_t
rsmi_dev_subsystem_vendor_id_get(uint32_t dv_ind, uint16_t *id) {
std::ostringstream ss;
@@ -87,6 +87,7 @@ static const char *kDevDevProdNumFName = "product_number";
static const char *kDevDevIDFName = "device";
static const char *kDevDevRevIDFName = "revision";
static const char *kDevVendorIDFName = "vendor";
static const char *kDevBoardInfoFName = "board_info";
static const char *kDevSubSysDevIDFName = "subsystem_device";
static const char *kDevSubSysVendorIDFName = "subsystem_vendor";
static const char *kDevOverDriveLevelFName = "pp_sclk_od";
@@ -238,6 +239,7 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevPerfLevel, kDevPerfLevelFName},
{kDevOverDriveLevel, kDevOverDriveLevelFName},
{kDevMemOverDriveLevel, kDevMemOverDriveLevelFName},
{kDevBoardInfo, kDevBoardInfoFName},
{kDevDevProdName, kDevDevProdNameFName},
{kDevDevProdNum, kDevDevProdNumFName},
{kDevDevID, kDevDevIDFName},
@@ -388,6 +390,7 @@ static const std::map<const char *, dev_depends_t> kDevFuncDependsMap = {
{"rsmi_dev_name_get", {{kDevVendorIDFName,
kDevDevIDFName}, {}}},
{"rsmi_dev_sku_get", {{kDevDevProdNumFName}, {}}},
{"rsmi_dev_pcie_slot_type_get", {{kDevBoardInfoFName}, {}}},
{"rsmi_dev_brand_get", {{kDevVendorIDFName,
kDevVBiosVerFName}, {}}},
{"rsmi_dev_vendor_name_get", {{kDevVendorIDFName}, {}}},
@@ -1003,6 +1006,34 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) {
return 0;
}
// Read a property from a file which may contain multiple properties
int Device::readDevInfo(DevInfoTypes type, const std::string& property,
std::string& value) {
std::vector<std::string> val;
int ret = 0;
switch (type) {
case kDevBoardInfo:
ret = readDevInfoMultiLineStr(type, &val);
break;
default:
return EINVAL;
}
if (ret != 0) return ret;
// Find the property from the file
for (unsigned int i = 0; i < val.size(); i++) {
auto pos = val[i].find(":"); // delimiter
if (pos == std::string::npos) continue;
auto name = trim(val[i].substr(0, pos));
if (name != property) continue;
value = trim(val[i].substr(pos+1));
return 0;
}
return EINVAL;
}
int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
assert(val != nullptr);
@@ -86,6 +86,7 @@ amd::smi::RocmSMI::devInfoTypesStrings = {
{amd::smi::kDevDevID, amdSMI + "kDevDevID"},
{amd::smi::kDevDevRevID, amdSMI + "kDevDevRevID"},
{amd::smi::kDevDevProdName, amdSMI + "kDevDevProdName"},
{amd::smi::kDevBoardInfo, amdSMI + "kDevBoardInfo"},
{amd::smi::kDevDevProdNum, amdSMI + "kDevDevProdNum"},
{amd::smi::kDevVendorID, amdSMI + "kDevVendorID"},
{amd::smi::kDevSubSysDevID, amdSMI + "kDevSubSysDevID"},
+12 -24
View File
@@ -1830,22 +1830,14 @@ amdsmi_get_pcie_link_status(amdsmi_processor_handle processor_handle, amdsmi_pci
// default to PCIe
info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE;
amd::smi::AMDSmiGPUDevice* gpu_device = nullptr;
status = get_gpu_device_from_handle(
processor_handle, &gpu_device);
if (status == AMDSMI_STATUS_SUCCESS
&& gpu_device->check_if_drm_is_supported()) {
struct drm_amdgpu_info_device dev_info = {};
status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO,
sizeof(struct drm_amdgpu_memory_info), &dev_info);
// bits [16:17] in ids_flags field as slot type
if (status == AMDSMI_STATUS_SUCCESS) {
// two bits starts with index 16
info->pcie_slot_type = static_cast<amdsmi_pcie_slot_type_t>((dev_info.ids_flags >> 16) & 0x03);
}
rsmi_pcie_slot_type_t slot_type;
status = rsmi_wrapper(rsmi_dev_pcie_slot_type_get,
processor_handle, &slot_type);
if (status == AMDSMI_STATUS_SUCCESS) {
info->pcie_slot_type = static_cast<amdsmi_pcie_slot_type_t>(slot_type);
}
return status;
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_handle, amdsmi_pcie_info_t *info) {
@@ -1921,18 +1913,14 @@ amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_hand
// default to PCIe
info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE;
if (gpu_device->check_if_drm_is_supported()) {
struct drm_amdgpu_info_device dev_info = {};
status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO,
sizeof(struct drm_amdgpu_memory_info), &dev_info);
// bits [16:17] in ids_flags field as slot type
if (status == AMDSMI_STATUS_SUCCESS) {
// two bits starts with index 16
info->pcie_slot_type = static_cast<amdsmi_pcie_slot_type_t>((dev_info.ids_flags >> 16) & 0x03);
}
rsmi_pcie_slot_type_t slot_type;
status = rsmi_wrapper(rsmi_dev_pcie_slot_type_get,
processor_handle, &slot_type);
if (status == AMDSMI_STATUS_SUCCESS) {
info->pcie_slot_type = static_cast<amdsmi_pcie_slot_type_t>(slot_type);
}
return status;
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t amdsmi_get_processor_handle_from_bdf(amdsmi_bdf_t bdf,