From 4e28dfe58e83141d8bea1942f42227545e8ed492 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 1 Aug 2021 10:37:06 -0700 Subject: [PATCH] freedreno: Device matching based on chip_id Add support for device matching based on chip_id instead of gpu_id, to handle newer GPUs Signed-off-by: Rob Clark Part-of: --- src/freedreno/common/freedreno_dev_info.c | 15 ++++++++++++++- src/freedreno/common/freedreno_dev_info.h | 15 +++++++++++++++ src/freedreno/common/freedreno_devices.py | 19 ++++++++++++++++--- src/freedreno/drm/freedreno_pipe.c | 3 +++ src/freedreno/drm/msm_pipe.c | 2 +- src/freedreno/vulkan/tu_drm.c | 6 ++++++ src/freedreno/vulkan/tu_kgsl.c | 1 + 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/freedreno/common/freedreno_dev_info.c b/src/freedreno/common/freedreno_dev_info.c index dc2d01f8d11..8b217b3186a 100644 --- a/src/freedreno/common/freedreno_dev_info.c +++ b/src/freedreno/common/freedreno_dev_info.c @@ -39,7 +39,20 @@ struct fd_dev_rec { static bool dev_id_compare(const struct fd_dev_id *a, const struct fd_dev_id *b) { - return a->gpu_id == b->gpu_id; + if (a->gpu_id && b->gpu_id) { + return a->gpu_id == b->gpu_id; + } else { + assert(a->chip_id && b->chip_id); + /* Match on either: + * (a) exact match + * (b) device table entry has 0xff wildcard patch_id and core/ + * major/minor match + */ + return (a->chip_id == b->chip_id) || + (((a->chip_id & 0xff) == 0xff) && + ((a->chip_id & UINT64_C(0xffffff00)) == + (b->chip_id & UINT64_C(0xffffff00)))); + } } const struct fd_dev_info * diff --git a/src/freedreno/common/freedreno_dev_info.h b/src/freedreno/common/freedreno_dev_info.h index 7d7ed47ca09..b0f109470dd 100644 --- a/src/freedreno/common/freedreno_dev_info.h +++ b/src/freedreno/common/freedreno_dev_info.h @@ -25,6 +25,7 @@ #ifndef FREEDRENO_DEVICE_INFO_H #define FREEDRENO_DEVICE_INFO_H +#include #include #include @@ -107,11 +108,25 @@ struct fd_dev_info { struct fd_dev_id { uint32_t gpu_id; + uint64_t chip_id; }; +/** + * Note that gpu-id should be considered deprecated. For newer a6xx, if + * there is no gpu-id, this attempts to generate one from the chip-id. + * But that may not work forever, so avoid depending on this for newer + * gens + */ static inline uint32_t fd_dev_gpu_id(const struct fd_dev_id *id) { + assert(id->gpu_id || id->chip_id); + if (!id->gpu_id) { + return ((id->chip_id >> 24) & 0xff) * 100 + + ((id->chip_id >> 16) & 0xff) * 10 + + ((id->chip_id >> 8) & 0xff); + + } return id->gpu_id; } diff --git a/src/freedreno/common/freedreno_devices.py b/src/freedreno/common/freedreno_devices.py index c0df32e881e..f5bb756a3d3 100644 --- a/src/freedreno/common/freedreno_devices.py +++ b/src/freedreno/common/freedreno_devices.py @@ -52,9 +52,22 @@ def add_gpus(ids, info): s.gpus[id] = info class GPUId(object): - def __init__(self, gpu_id, name=None): + def __init__(self, gpu_id = None, chip_id = None, name=None): + if chip_id == None: + assert(gpu_id != None) + val = gpu_id + core = int(val / 100) + val -= (core * 100); + major = int(val / 10); + val -= (major * 10) + minor = val + chip_id = (core << 24) | (major << 16) | (minor << 8) | 0xff + self.chip_id = chip_id + if gpu_id == None: + gpu_id = 0 self.gpu_id = gpu_id if name == None: + assert(gpu_id != 0) name = "FD%d" % gpu_id self.name = name @@ -272,7 +285,7 @@ add_gpus([ )) add_gpus([ - GPUId(635, "Adreno 7c Gen 3"), + GPUId(chip_id=0x06030500, name="Adreno 7c Gen 3"), ], A6xxGPUInfo( a6xx_gen4, num_sp_cores = 2, @@ -328,7 +341,7 @@ static const struct fd_dev_info __info${s.info_index(info)} = ${str(info)}; static const struct fd_dev_rec fd_dev_recs[] = { %for id, info in s.gpus.items(): - { {${id.gpu_id}}, "${id.name}", &__info${s.info_index(info)} }, + { {${id.gpu_id}, ${hex(id.chip_id)}}, "${id.name}", &__info${s.info_index(info)} }, %endfor }; """ diff --git a/src/freedreno/drm/freedreno_pipe.c b/src/freedreno/drm/freedreno_pipe.c index 0a5cea9e2dd..53fd808821e 100644 --- a/src/freedreno/drm/freedreno_pipe.c +++ b/src/freedreno/drm/freedreno_pipe.c @@ -60,6 +60,9 @@ fd_pipe_new2(struct fd_device *dev, enum fd_pipe_id id, uint32_t prio) fd_pipe_get_param(pipe, FD_GPU_ID, &val); pipe->dev_id.gpu_id = val; + fd_pipe_get_param(pipe, FD_CHIP_ID, &val); + pipe->dev_id.chip_id = val; + pipe->control_mem = fd_bo_new(dev, sizeof(*pipe->control), 0, "pipe-control"); pipe->control = fd_bo_map(pipe->control_mem); diff --git a/src/freedreno/drm/msm_pipe.c b/src/freedreno/drm/msm_pipe.c index 4fcd4c9d77d..0c35063c35f 100644 --- a/src/freedreno/drm/msm_pipe.c +++ b/src/freedreno/drm/msm_pipe.c @@ -245,7 +245,7 @@ msm_pipe_new(struct fd_device *dev, enum fd_pipe_id id, uint32_t prio) if (fd_device_version(pipe->dev) >= FD_VERSION_GMEM_BASE) msm_pipe->gmem_base = get_param(pipe, MSM_PARAM_GMEM_BASE); - if (!msm_pipe->gpu_id) + if (!(msm_pipe->gpu_id || msm_pipe->chip_id)) goto fail; INFO_MSG("Pipe Info:"); diff --git a/src/freedreno/vulkan/tu_drm.c b/src/freedreno/vulkan/tu_drm.c index 36d8fd34a33..5ddf290eea8 100644 --- a/src/freedreno/vulkan/tu_drm.c +++ b/src/freedreno/vulkan/tu_drm.c @@ -451,6 +451,12 @@ tu_drm_device_init(struct tu_physical_device *device, goto fail; } + if (tu_drm_get_param(device, MSM_PARAM_CHIP_ID, &device->dev_id.chip_id)) { + result = vk_startup_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, + "could not get CHIP ID"); + goto fail; + } + if (tu_drm_get_gmem_size(device, &device->gmem_size)) { result = vk_startup_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, "could not get GMEM size"); diff --git a/src/freedreno/vulkan/tu_kgsl.c b/src/freedreno/vulkan/tu_kgsl.c index 49651cdec9f..8249b55540b 100644 --- a/src/freedreno/vulkan/tu_kgsl.c +++ b/src/freedreno/vulkan/tu_kgsl.c @@ -243,6 +243,7 @@ tu_enumerate_devices(struct tu_instance *instance) ((info.chip_id >> 24) & 0xff) * 100 + ((info.chip_id >> 16) & 0xff) * 10 + ((info.chip_id >> 8) & 0xff); + device->dev_id.chip_id = info.chip_id; device->gmem_size = info.gmem_sizebytes; device->gmem_base = gmem_iova;