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:
@@ -830,6 +830,25 @@ rsmi_status_t rsmi_dev_subsystem_id_get(uint32_t dv_ind, uint16_t *id);
|
||||
rsmi_status_t
|
||||
rsmi_dev_subsystem_name_get(uint32_t dv_ind, char *name, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Get the drm minor number associated with this device
|
||||
*
|
||||
* @details Given a device index @p dv_ind, find its render device file
|
||||
* /dev/dri/renderDN where N corresponds to its minor number.
|
||||
*
|
||||
* @param[in] dv_ind a device index
|
||||
*
|
||||
* @param[inout] minor a pointer to a uint32_t into which minor number will
|
||||
* be copied
|
||||
*
|
||||
* @retval :: RSMI_STATUS_SUCCESS is returned upon successful call.
|
||||
* @retval :: RSMI_STATUS_INIT_ERROR if failed to get minor number during
|
||||
* initialization.
|
||||
*
|
||||
*/
|
||||
rsmi_status_t
|
||||
rsmi_dev_drm_render_minor_get(uint32_t dv_ind, uint32_t *minor);
|
||||
|
||||
/**
|
||||
* @brief Get the device subsystem vendor id associated with the device with
|
||||
* provided device index.
|
||||
|
||||
@@ -139,6 +139,8 @@ class Device {
|
||||
int writeDevInfo(DevInfoTypes type, std::string val);
|
||||
uint32_t index(void) const {return index_;}
|
||||
void set_index(uint32_t index) {index_ = index;}
|
||||
uint32_t drm_render_minor(void) const {return drm_render_minor_;}
|
||||
void set_drm_render_minor(uint32_t minor) {drm_render_minor_ = minor;}
|
||||
static rsmi_dev_perf_level perfLvlStrToEnum(std::string s);
|
||||
uint64_t bdfid(void) const {return bdfid_;}
|
||||
void set_bdfid(uint64_t val) {bdfid_ = val;}
|
||||
@@ -153,6 +155,7 @@ class Device {
|
||||
std::string path_;
|
||||
shared_mutex_t mutex_;
|
||||
uint32_t index_;
|
||||
uint32_t drm_render_minor_;
|
||||
const RocmSMI_env_vars *env_;
|
||||
template <typename T> int openSysfsFileStream(DevInfoTypes type, T *fs,
|
||||
const char *str = nullptr);
|
||||
|
||||
@@ -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());
|
||||
|
||||
Verwijs in nieuw issue
Block a user