mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 02:38:04 +02:00
panfrost: Add support for Panthor in drm-shim
Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com> Reviewed-by: Brezillon Boris <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28241>
This commit is contained in:
parent
9c92d92ab9
commit
76397f76c9
1 changed files with 173 additions and 25 deletions
|
|
@ -28,7 +28,9 @@
|
|||
#include <stdlib.h>
|
||||
#include "drm-shim/drm_shim.h"
|
||||
#include "drm-uapi/panfrost_drm.h"
|
||||
#include "drm-uapi/panthor_drm.h"
|
||||
|
||||
#include "util/os_mman.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
/* Default GPU ID if PAN_GPU_ID is not set. This defaults to Mali-G52. */
|
||||
|
|
@ -36,6 +38,17 @@
|
|||
|
||||
bool drm_shim_driver_prefers_first_render_node = true;
|
||||
|
||||
static uint64_t
|
||||
pan_get_gpu_id(void)
|
||||
{
|
||||
char *override_version = getenv("PAN_GPU_ID");
|
||||
|
||||
if (override_version)
|
||||
return strtol(override_version, NULL, 16);
|
||||
|
||||
return PAN_GPU_ID_DEFAULT;
|
||||
}
|
||||
|
||||
static int
|
||||
pan_ioctl_noop(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
|
|
@ -43,19 +56,13 @@ pan_ioctl_noop(int fd, unsigned long request, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
pan_ioctl_get_param(int fd, unsigned long request, void *arg)
|
||||
panfrost_ioctl_get_param(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panfrost_get_param *gp = arg;
|
||||
|
||||
switch (gp->param) {
|
||||
case DRM_PANFROST_PARAM_GPU_PROD_ID: {
|
||||
char *override_version = getenv("PAN_GPU_ID");
|
||||
|
||||
if (override_version)
|
||||
gp->value = strtol(override_version, NULL, 16);
|
||||
else
|
||||
gp->value = PAN_GPU_ID_DEFAULT;
|
||||
|
||||
gp->value = pan_get_gpu_id();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +105,7 @@ pan_ioctl_get_param(int fd, unsigned long request, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
pan_ioctl_create_bo(int fd, unsigned long request, void *arg)
|
||||
panfrost_ioctl_create_bo(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panfrost_create_bo *create = arg;
|
||||
|
||||
|
|
@ -117,7 +124,7 @@ pan_ioctl_create_bo(int fd, unsigned long request, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
pan_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
|
||||
panfrost_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panfrost_mmap_bo *mmap_bo = arg;
|
||||
|
||||
|
|
@ -130,7 +137,7 @@ pan_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
pan_ioctl_madvise(int fd, unsigned long request, void *arg)
|
||||
panfrost_ioctl_madvise(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panfrost_madvise *madvise = arg;
|
||||
|
||||
|
|
@ -139,35 +146,176 @@ pan_ioctl_madvise(int fd, unsigned long request, void *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ioctl_fn_t driver_ioctls[] = {
|
||||
static ioctl_fn_t panfrost_driver_ioctls[] = {
|
||||
[DRM_PANFROST_SUBMIT] = pan_ioctl_noop,
|
||||
[DRM_PANFROST_WAIT_BO] = pan_ioctl_noop,
|
||||
[DRM_PANFROST_CREATE_BO] = pan_ioctl_create_bo,
|
||||
[DRM_PANFROST_MMAP_BO] = pan_ioctl_mmap_bo,
|
||||
[DRM_PANFROST_GET_PARAM] = pan_ioctl_get_param,
|
||||
[DRM_PANFROST_CREATE_BO] = panfrost_ioctl_create_bo,
|
||||
[DRM_PANFROST_MMAP_BO] = panfrost_ioctl_mmap_bo,
|
||||
[DRM_PANFROST_GET_PARAM] = panfrost_ioctl_get_param,
|
||||
[DRM_PANFROST_GET_BO_OFFSET] = pan_ioctl_noop,
|
||||
[DRM_PANFROST_PERFCNT_ENABLE] = pan_ioctl_noop,
|
||||
[DRM_PANFROST_PERFCNT_DUMP] = pan_ioctl_noop,
|
||||
[DRM_PANFROST_MADVISE] = pan_ioctl_madvise,
|
||||
[DRM_PANFROST_MADVISE] = panfrost_ioctl_madvise,
|
||||
};
|
||||
|
||||
static int
|
||||
panthor_ioctl_dev_query(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panthor_dev_query *dev_query = arg;
|
||||
|
||||
switch (dev_query->type) {
|
||||
case DRM_PANTHOR_DEV_QUERY_GPU_INFO: {
|
||||
struct drm_panthor_gpu_info *gpu_info =
|
||||
(struct drm_panthor_gpu_info *)dev_query->pointer;
|
||||
|
||||
gpu_info->gpu_id = pan_get_gpu_id() << 16;
|
||||
gpu_info->gpu_rev = 0;
|
||||
|
||||
/* Dumped from a G610 */
|
||||
gpu_info->csf_id = 0x40a0412;
|
||||
gpu_info->l2_features = 0x7120306;
|
||||
gpu_info->tiler_features = 0x809;
|
||||
gpu_info->mem_features = 0x301;
|
||||
gpu_info->mmu_features = 0x2830;
|
||||
gpu_info->thread_features = 0x4010000;
|
||||
gpu_info->max_threads = 2048;
|
||||
gpu_info->thread_max_workgroup_size = 1024;
|
||||
gpu_info->thread_max_barrier_size = 1024;
|
||||
gpu_info->coherency_features = 0;
|
||||
gpu_info->texture_features[0] = 0xc1ffff9e;
|
||||
gpu_info->as_present = 0xff;
|
||||
gpu_info->shader_present = 0x50005;
|
||||
gpu_info->l2_present = 1;
|
||||
gpu_info->tiler_present = 1;
|
||||
return 0;
|
||||
}
|
||||
case DRM_PANTHOR_DEV_QUERY_CSIF_INFO: {
|
||||
struct drm_panthor_csif_info *csif_info =
|
||||
(struct drm_panthor_csif_info *)dev_query->pointer;
|
||||
|
||||
/* Dumped from a G610 */
|
||||
csif_info->csg_slot_count = 8;
|
||||
csif_info->cs_slot_count = 8;
|
||||
csif_info->cs_reg_count = 96;
|
||||
csif_info->scoreboard_slot_count = 8;
|
||||
csif_info->unpreserved_cs_reg_count = 4;
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "Unknown DRM_IOCTL_PANTHOR_DEV_QUERY %d\n",
|
||||
dev_query->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
panthor_ioctl_bo_create(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panthor_bo_create *bo_create = arg;
|
||||
|
||||
struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
|
||||
struct shim_bo *bo = calloc(1, sizeof(*bo));
|
||||
size_t size = ALIGN(bo_create->size, 4096);
|
||||
|
||||
drm_shim_bo_init(bo, size);
|
||||
|
||||
bo_create->handle = drm_shim_bo_get_handle(shim_fd, bo);
|
||||
|
||||
drm_shim_bo_put(bo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
panthor_ioctl_bo_mmap_offset(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
struct drm_panthor_bo_mmap_offset *mmap_offset = arg;
|
||||
|
||||
struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
|
||||
struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, mmap_offset->handle);
|
||||
|
||||
mmap_offset->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ioctl_fn_t panthor_driver_ioctls[] = {
|
||||
[DRM_PANTHOR_DEV_QUERY] = panthor_ioctl_dev_query,
|
||||
[DRM_PANTHOR_VM_CREATE] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_VM_DESTROY] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_VM_BIND] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_VM_GET_STATE] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_BO_CREATE] = panthor_ioctl_bo_create,
|
||||
[DRM_PANTHOR_BO_MMAP_OFFSET] = panthor_ioctl_bo_mmap_offset,
|
||||
[DRM_PANTHOR_GROUP_CREATE] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_GROUP_DESTROY] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_GROUP_SUBMIT] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_GROUP_GET_STATE] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_TILER_HEAP_CREATE] = pan_ioctl_noop,
|
||||
[DRM_PANTHOR_TILER_HEAP_DESTROY] = pan_ioctl_noop,
|
||||
};
|
||||
|
||||
static void *flush_id_mmap;
|
||||
|
||||
static void *
|
||||
panthor_iomem_mmap(size_t size, int prot, int flags, off64_t offset)
|
||||
{
|
||||
switch (offset) {
|
||||
case DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET:
|
||||
if (prot != PROT_READ || flags != MAP_SHARED || size != getpagesize())
|
||||
return MAP_FAILED;
|
||||
|
||||
return flush_id_mmap;
|
||||
|
||||
default:
|
||||
return MAP_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drm_shim_driver_init(void)
|
||||
{
|
||||
uint64_t gpu_id = pan_get_gpu_id();
|
||||
bool is_csf_based = (gpu_id >> 12) > 9;
|
||||
|
||||
shim_device.bus_type = DRM_BUS_PLATFORM;
|
||||
shim_device.driver_name = "panfrost";
|
||||
shim_device.driver_ioctls = driver_ioctls;
|
||||
shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
|
||||
|
||||
/* panfrost uses the DRM version to expose features, instead of getparam. */
|
||||
shim_device.version_major = 1;
|
||||
shim_device.version_minor = 1;
|
||||
shim_device.version_patchlevel = 0;
|
||||
|
||||
drm_shim_override_file("DRIVER=panfrost\n"
|
||||
"OF_FULLNAME=/soc/mali\n"
|
||||
"OF_COMPATIBLE_0=arm,mali-t860\n"
|
||||
"OF_COMPATIBLE_N=1\n",
|
||||
"/sys/dev/char/%d:%d/device/uevent", DRM_MAJOR,
|
||||
render_node_minor);
|
||||
if (is_csf_based) {
|
||||
shim_device.driver_name = "panthor";
|
||||
shim_device.driver_ioctls = panthor_driver_ioctls;
|
||||
shim_device.driver_ioctl_count = ARRAY_SIZE(panthor_driver_ioctls);
|
||||
|
||||
flush_id_mmap = os_mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
|
||||
assert(flush_id_mmap != MAP_FAILED);
|
||||
memset(flush_id_mmap, 0, getpagesize());
|
||||
|
||||
drm_shim_init_iomem_region(DRM_PANTHOR_USER_MMIO_OFFSET, getpagesize(),
|
||||
panthor_iomem_mmap);
|
||||
|
||||
drm_shim_override_file("DRIVER=panthor\n"
|
||||
"OF_FULLNAME=/soc/mali\n"
|
||||
"OF_COMPATIBLE_0=arm,mali-valhall-csf\n"
|
||||
"OF_COMPATIBLE_N=1\n",
|
||||
"/sys/dev/char/%d:%d/device/uevent", DRM_MAJOR,
|
||||
render_node_minor);
|
||||
} else {
|
||||
shim_device.driver_name = "panfrost";
|
||||
shim_device.driver_ioctls = panfrost_driver_ioctls;
|
||||
shim_device.driver_ioctl_count = ARRAY_SIZE(panfrost_driver_ioctls);
|
||||
|
||||
drm_shim_override_file("DRIVER=panfrost\n"
|
||||
"OF_FULLNAME=/soc/mali\n"
|
||||
"OF_COMPATIBLE_0=arm,mali-t860\n"
|
||||
"OF_COMPATIBLE_N=1\n",
|
||||
"/sys/dev/char/%d:%d/device/uevent", DRM_MAJOR,
|
||||
render_node_minor);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue