Add rsmi_dev_drm_render_minor_get()
Function to get the drm minor number associated with ROCm device Change-Id: I9356b9ca75151882acbb075076bc072f08b73aae Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
This commit is contained in:
@@ -1425,6 +1425,19 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
|
||||
|
||||
return RSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static rsmi_status_t
|
||||
get_dev_drm_render_minor(uint32_t dv_ind, uint32_t *minor) {
|
||||
|
||||
GET_DEV_FROM_INDX
|
||||
|
||||
*minor = dev->drm_render_minor();
|
||||
if (*minor)
|
||||
return RSMI_STATUS_SUCCESS;
|
||||
|
||||
return RSMI_STATUS_INIT_ERROR;
|
||||
}
|
||||
|
||||
rsmi_status_t
|
||||
rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) {
|
||||
rsmi_status_t ret;
|
||||
@@ -1458,6 +1471,20 @@ rsmi_dev_subsystem_name_get(uint32_t dv_ind, char *name, size_t len) {
|
||||
CATCH
|
||||
}
|
||||
|
||||
rsmi_status_t
|
||||
rsmi_dev_drm_render_minor_get(uint32_t dv_ind, uint32_t *minor) {
|
||||
rsmi_status_t ret;
|
||||
|
||||
TRY
|
||||
if (minor == nullptr)
|
||||
return RSMI_STATUS_INVALID_ARGS;
|
||||
|
||||
DEVICE_MUTEX
|
||||
ret = get_dev_drm_render_minor(dv_ind, minor);
|
||||
return ret;
|
||||
CATCH
|
||||
}
|
||||
|
||||
rsmi_status_t
|
||||
rsmi_dev_vendor_name_get(uint32_t dv_ind, char *name, size_t len) {
|
||||
rsmi_status_t ret;
|
||||
|
||||
@@ -82,6 +82,39 @@ static uint32_t GetDeviceIndex(const std::string s) {
|
||||
return stoi(t);
|
||||
}
|
||||
|
||||
// Find the drm minor from from sysfs path "/sys/class/drm/cardX/device/drm".
|
||||
// From the directory renderDN in that sysfs path, the drm minor can be
|
||||
// computed for cardX.
|
||||
// On success, return drm_minor which is >= 128 otherwise return 0
|
||||
static uint32_t GetDrmRenderMinor(const std::string s) {
|
||||
std::string drm_path = s;
|
||||
int drm_minor = 0;
|
||||
const std::string render_file_prefix = "renderD";
|
||||
const uint32_t prefix_size = render_file_prefix.size();
|
||||
drm_path += "/device/drm";
|
||||
|
||||
auto drm_dir = opendir(drm_path.c_str());
|
||||
if (drm_dir == nullptr)
|
||||
return 0;
|
||||
|
||||
auto dentry = readdir(drm_dir);
|
||||
|
||||
while (dentry != nullptr) {
|
||||
std::string render_file = dentry->d_name;
|
||||
if (!render_file.compare(0, prefix_size, render_file_prefix)) {
|
||||
drm_minor = stoi(render_file.substr(prefix_size));
|
||||
if (drm_minor)
|
||||
break;
|
||||
}
|
||||
dentry = readdir(drm_dir);
|
||||
}
|
||||
|
||||
if (closedir(drm_dir))
|
||||
return 0;
|
||||
|
||||
return drm_minor;
|
||||
}
|
||||
|
||||
static int SameDevice(const std::string fileA, const std::string fileB) {
|
||||
return SameFile(fileA + "/device", fileB + "/device");
|
||||
}
|
||||
@@ -300,6 +333,7 @@ RocmSMI::AddToDeviceList(std::string dev_name) {
|
||||
|
||||
std::string d_name = dev_name;
|
||||
uint32_t d_index = GetDeviceIndex(d_name);
|
||||
dev->set_drm_render_minor(GetDrmRenderMinor(dev_path));
|
||||
dev->set_index(d_index);
|
||||
|
||||
GetSupportedEventGroups(d_index, dev->supported_event_groups());
|
||||
|
||||
Reference in New Issue
Block a user