turnip: add wrappers around DRM_MSM_GET_PARAM
Add tu_drm_get_gpu_id and tu_drm_get_gmem_size.
This commit is contained in:
@@ -152,7 +152,6 @@ tu_physical_device_init(struct tu_physical_device *device,
|
||||
drmVersionPtr version;
|
||||
int fd;
|
||||
int master_fd = -1;
|
||||
uint64_t val;
|
||||
|
||||
fd = open(path, O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
@@ -214,23 +213,21 @@ tu_physical_device_init(struct tu_physical_device *device,
|
||||
device->master_fd = master_fd;
|
||||
device->local_fd = fd;
|
||||
|
||||
if (tu_drm_query_param(device, MSM_PARAM_GPU_ID, &val)) {
|
||||
if (tu_drm_get_gpu_id(device, &device->gpu_id)) {
|
||||
if (instance->debug_flags & TU_DEBUG_STARTUP)
|
||||
tu_logi("Could not query the GPU ID");
|
||||
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
|
||||
"could not get GPU ID");
|
||||
goto fail;
|
||||
}
|
||||
device->gpu_id = val;
|
||||
|
||||
if (tu_drm_query_param(device, MSM_PARAM_GMEM_SIZE, &val)) {
|
||||
if (tu_drm_get_gmem_size(device, &device->gmem_size)) {
|
||||
if (instance->debug_flags & TU_DEBUG_STARTUP)
|
||||
tu_logi("Could not query the GMEM size");
|
||||
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
|
||||
"could not get GMEM size");
|
||||
goto fail;
|
||||
}
|
||||
device->gmem_size = val;
|
||||
|
||||
memset(device->name, 0, sizeof(device->name));
|
||||
sprintf(device->name, "FD%d", device->gpu_id);
|
||||
|
||||
@@ -31,6 +31,53 @@
|
||||
|
||||
#include "drm/msm_drm.h"
|
||||
|
||||
static int
|
||||
tu_drm_get_param(const struct tu_physical_device *dev,
|
||||
uint32_t param,
|
||||
uint64_t *value)
|
||||
{
|
||||
/* Technically this requires a pipe, but the kernel only supports one pipe
|
||||
* anyway at the time of writing and most of these are clearly pipe
|
||||
* independent. */
|
||||
struct drm_msm_param req = {
|
||||
.pipe = MSM_PIPE_3D0,
|
||||
.param = param,
|
||||
};
|
||||
|
||||
int ret = drmCommandWriteRead(dev->local_fd, DRM_MSM_GET_PARAM, &req,
|
||||
sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*value = req.value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
tu_drm_get_gpu_id(const struct tu_physical_device *dev, uint32_t *id)
|
||||
{
|
||||
uint64_t value;
|
||||
int ret = tu_drm_get_param(dev, MSM_PARAM_GPU_ID, &value);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*id = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
tu_drm_get_gmem_size(const struct tu_physical_device *dev, uint32_t *size)
|
||||
{
|
||||
uint64_t value;
|
||||
int ret = tu_drm_get_param(dev, MSM_PARAM_GMEM_SIZE, &value);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*size = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return gem handle on success. Return 0 on failure.
|
||||
*/
|
||||
@@ -90,26 +137,3 @@ tu_gem_info_iova(struct tu_device *dev, uint32_t gem_handle)
|
||||
{
|
||||
return tu_gem_info(dev, gem_handle, MSM_INFO_GET_IOVA);
|
||||
}
|
||||
|
||||
int
|
||||
tu_drm_query_param(struct tu_physical_device *dev,
|
||||
uint32_t param,
|
||||
uint64_t *value)
|
||||
{
|
||||
/* Technically this requires a pipe, but the kernel only supports one pipe
|
||||
* anyway at the time of writing and most of these are clearly pipe
|
||||
* independent. */
|
||||
struct drm_msm_param req = {
|
||||
.pipe = MSM_PIPE_3D0,
|
||||
.param = param,
|
||||
};
|
||||
|
||||
int ret = drmCommandWriteRead(dev->local_fd, DRM_MSM_GET_PARAM, &req,
|
||||
sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*value = req.value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1189,6 +1189,12 @@ struct tu_fence
|
||||
uint32_t temp_syncobj;
|
||||
};
|
||||
|
||||
int
|
||||
tu_drm_get_gpu_id(const struct tu_physical_device *dev, uint32_t *id);
|
||||
|
||||
int
|
||||
tu_drm_get_gmem_size(const struct tu_physical_device *dev, uint32_t *size);
|
||||
|
||||
uint32_t
|
||||
tu_gem_new(struct tu_device *dev, uint64_t size, uint32_t flags);
|
||||
void
|
||||
@@ -1197,10 +1203,6 @@ uint64_t
|
||||
tu_gem_info_offset(struct tu_device *dev, uint32_t gem_handle);
|
||||
uint64_t
|
||||
tu_gem_info_iova(struct tu_device *dev, uint32_t gem_handle);
|
||||
int
|
||||
tu_drm_query_param(struct tu_physical_device *dev,
|
||||
uint32_t param,
|
||||
uint64_t *value);
|
||||
|
||||
#define TU_DEFINE_HANDLE_CASTS(__tu_type, __VkType) \
|
||||
\
|
||||
|
||||
Reference in New Issue
Block a user