From 33e77c904182668f36634a18ddf8f569dd2a4a7b Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Fri, 23 Feb 2024 13:24:58 +0100 Subject: [PATCH] v3d,v3d: use new simulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new simulator provides a new API, so we need to adapt the code. Reviewed-by: Alejandro PiƱeiro Signed-off-by: Juan A. Suarez Romero Part-of: --- src/broadcom/simulator/meson.build | 8 +- src/broadcom/simulator/v3d_simulator.c | 88 +++++++++---------- .../simulator/v3d_simulator_wrapper.cpp | 30 ++++--- .../simulator/v3d_simulator_wrapper.h | 7 +- src/broadcom/simulator/v3dx_simulator.c | 20 +++-- src/broadcom/vulkan/meson.build | 6 +- src/gallium/drivers/v3d/meson.build | 8 +- 7 files changed, 92 insertions(+), 75 deletions(-) diff --git a/src/broadcom/simulator/meson.build b/src/broadcom/simulator/meson.build index 49b15288698..0432fa0e52c 100644 --- a/src/broadcom/simulator/meson.build +++ b/src/broadcom/simulator/meson.build @@ -29,8 +29,8 @@ files_per_version = files( ) v3d_args = [] -dep_v3dv3 = dependency('v3dv3', required: false) -if dep_v3dv3.found() +dep_v3d_hw = dependency('v3d_hw', required: false) +if dep_v3d_hw.found() v3d_args += '-DUSE_V3D_SIMULATOR' endif @@ -44,7 +44,7 @@ foreach ver : v3d_versions ], c_args : [v3d_args, '-DV3D_VERSION=' + ver], gnu_symbol_visibility: 'hidden', - dependencies : [dep_v3dv3, dep_libdrm, dep_valgrind], + dependencies : [dep_v3d_hw, dep_libdrm, dep_valgrind], ) endforeach @@ -55,7 +55,7 @@ libbroadcom_simulator = static_library( c_args : [v3d_args, no_override_init_args], cpp_args : [v3d_args], gnu_symbol_visibility : 'hidden', - dependencies : [dep_v3dv3, dep_libdrm, dep_valgrind], + dependencies : [dep_v3d_hw, dep_libdrm, dep_valgrind], link_with : [per_version_libs], build_by_default : false, ) diff --git a/src/broadcom/simulator/v3d_simulator.c b/src/broadcom/simulator/v3d_simulator.c index ee062504fc1..7e5c97e33f4 100644 --- a/src/broadcom/simulator/v3d_simulator.c +++ b/src/broadcom/simulator/v3d_simulator.c @@ -78,12 +78,8 @@ static struct v3d_simulator_state { struct v3d_hw *v3d; int ver; - /* Base virtual address of the heap. */ - void *mem; - /* Base hardware address of the heap. */ - uint32_t mem_base; /* Size of the heap. */ - uint32_t mem_size; + uint64_t mem_size; struct mem_block *heap; struct mem_block *overflow; @@ -122,7 +118,7 @@ struct v3d_simulator_file { uint32_t active_perfid; struct mem_block *gmp; - void *gmp_vaddr; + uint64_t gmp_addr; /** For specific gpus, use their create ioctl. Otherwise use dumb bo. */ enum gem_type gem_type; @@ -136,7 +132,7 @@ struct v3d_simulator_bo { struct mem_block *block; uint32_t size; uint64_t mmap_offset; - void *sim_vaddr; + uint64_t sim_addr; void *gem_vaddr; int handle; @@ -197,7 +193,8 @@ set_gmp_flags(struct v3d_simulator_file *file, assert((offset & ((1 << GMP_ALIGN2) - 1)) == 0); int gmp_offset = offset >> GMP_ALIGN2; int gmp_count = align(size, 1 << GMP_ALIGN2) >> GMP_ALIGN2; - uint32_t *gmp = file->gmp_vaddr; + uint32_t *gmp = malloc((gmp_count + gmp_offset)*sizeof(uint32_t)); + v3d_hw_read_mem(sim_state.v3d, gmp, file->gmp_addr, (gmp_offset + gmp_count)*sizeof(uint32_t)); assert(flag <= 0x3); @@ -206,6 +203,9 @@ set_gmp_flags(struct v3d_simulator_file *file, gmp[i / 16] &= ~(0x3 << bitshift); gmp[i / 16] |= flag << bitshift; } + + v3d_hw_write_mem(sim_state.v3d, file->gmp_addr, gmp, (gmp_offset + gmp_count)*sizeof(uint32_t)); + free(gmp); } /** @@ -230,10 +230,11 @@ v3d_create_simulator_bo(int fd, unsigned size) sim_bo->size = size; /* Allocate space for the buffer in simulator memory. */ - sim_bo->sim_vaddr = sim_state.mem + sim_bo->block->ofs - sim_state.mem_base; - memset(sim_bo->sim_vaddr, 0xd0, size); + sim_bo->sim_addr = sim_bo->block->ofs; + v3d_hw_set_mem(sim_state.v3d, sim_bo->sim_addr, 0xd0, size); - *(uint32_t *)(sim_bo->sim_vaddr + sim_bo->size) = BO_SENTINEL; + uint32_t sentinel = BO_SENTINEL; + v3d_hw_write_mem(sim_state.v3d, sim_bo->sim_addr + sim_bo->size, &sentinel, sizeof(sentinel)); return sim_bo; } @@ -368,7 +369,7 @@ v3d_simulator_copy_in_handle(struct v3d_simulator_file *file, int handle) if (!sim_bo) return; - memcpy(sim_bo->sim_vaddr, sim_bo->gem_vaddr, sim_bo->size); + v3d_hw_write_mem(sim_state.v3d, sim_bo->sim_addr, sim_bo->gem_vaddr, sim_bo->size); } static void @@ -379,10 +380,11 @@ v3d_simulator_copy_out_handle(struct v3d_simulator_file *file, int handle) if (!sim_bo) return; - memcpy(sim_bo->gem_vaddr, sim_bo->sim_vaddr, sim_bo->size); + v3d_hw_read_mem(sim_state.v3d, sim_bo->gem_vaddr, sim_bo->sim_addr, sim_bo->size); - if (*(uint32_t *)(sim_bo->sim_vaddr + - sim_bo->size) != BO_SENTINEL) { + uint32_t sentinel; + v3d_hw_read_mem(sim_state.v3d, &sentinel, sim_bo->sim_addr + sim_bo->size, sizeof(sentinel)); + if (sentinel != BO_SENTINEL) { fprintf(stderr, "Buffer overflow in handle %d\n", handle); } @@ -733,14 +735,13 @@ v3d_timestamp_query(int fd, struct v3d_simulator_bo *bo = v3d_get_simulator_bo(file, bo_handles[0]); uint32_t *offsets = (void *)(uintptr_t) timestamp_query->offsets; uint32_t *syncs = (void *)(uintptr_t) timestamp_query->syncs; - uint8_t *value_addr; struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); for (uint32_t i = 0; i < timestamp_query->count; i++) { - value_addr = ((uint8_t *) bo->sim_vaddr) + offsets[i]; - *((uint64_t*)value_addr) = (i == 0) ? t.tv_sec * 1000000000ull + t.tv_nsec : 0ull; + uint64_t value = (i == 0) ? t.tv_sec * 1000000000ull + t.tv_nsec : 0ull; + v3d_hw_write_mem(sim_state.v3d, bo->sim_addr + offsets[i], &value, sizeof(value)); } drmSyncobjSignal(fd, syncs, timestamp_query->count); @@ -756,10 +757,8 @@ v3d_reset_timestamp_queries(int fd, uint32_t *bo_handles = (uint32_t *)(uintptr_t)args->bo_handles; struct v3d_simulator_bo *bo = v3d_get_simulator_bo(file, bo_handles[0]); uint32_t *syncs = (void *)(uintptr_t) reset->syncs; - uint8_t *base_addr; - base_addr = ((uint8_t *) bo->sim_vaddr) + reset->offset; - memset(base_addr, 0, 8 * reset->count); + v3d_hw_set_mem(sim_state.v3d, bo->sim_addr + reset->offset, 0, reset->count); drmSyncobjReset(fd, syncs, reset->count); } @@ -789,25 +788,27 @@ v3d_copy_query_results(int fd, uint32_t *offsets = (void *)(uintptr_t) copy->offsets; uint32_t *syncs = (void *)(uintptr_t) copy->syncs; bool available, write_result; - uint8_t *query_addr; - uint8_t *data; - - data = ((uint8_t *) bo->sim_vaddr) + copy->offset; + uint8_t *data = malloc(copy->count * copy->stride); + uint64_t query_val; + uint8_t *p = data; for (uint32_t i = 0; i < copy->count; i++) { available = (drmSyncobjWait(fd, &syncs[i], 1, 0, 0, NULL) == 0); write_result = available || copy->do_partial; if (write_result) { - query_addr = ((uint8_t *) timestamp->sim_vaddr) + offsets[i]; - write_to_buffer(data, 0, copy->do_64bit, *((uint64_t *) query_addr)); + v3d_hw_read_mem(sim_state.v3d, &query_val, timestamp->sim_addr + offsets[i], sizeof(uint64_t)); + write_to_buffer(p, 0, copy->do_64bit, query_val); } if (copy->availability_bit) - write_to_buffer(data, 1, copy->do_64bit, available ? 1u : 0u); + write_to_buffer(p, 1, copy->do_64bit, available ? 1u : 0u); - data += copy->stride; + p += copy->stride; } + + v3d_hw_write_mem(sim_state.v3d, bo->sim_addr + copy->offset, data, copy->count * copy->stride); + free(data); } static void @@ -889,10 +890,9 @@ v3d_copy_performance_query(int fd, uint64_t *kperfmon_ids = (void *)(uintptr_t) copy->kperfmon_ids; uint32_t *syncs = (void *)(uintptr_t) copy->syncs; bool available, write_result; - uint8_t *data; - - data = ((uint8_t *) bo->sim_vaddr) + copy->offset; + uint8_t *data = malloc(copy->count * copy->stride); + uint8_t *p = data; for (uint32_t i = 0; i < copy->count; i++) { /* Although we don't have in_syncs implemented in the simulator, * we don't need to wait for the availability of the syncobjs, @@ -905,16 +905,19 @@ v3d_copy_performance_query(int fd, if (write_result) { v3d_write_performance_query_result(fd, copy, (void *)(uintptr_t) kperfmon_ids[i], - data); + p); } if (copy->availability_bit) { - write_to_buffer(data, copy->ncounters, copy->do_64bit, + write_to_buffer(p, copy->ncounters, copy->do_64bit, available ? 1u : 0u); } - data += copy->stride; + p += copy->stride; } + + v3d_hw_write_mem(sim_state.v3d, bo->sim_addr + copy->offset, data, copy->count + copy->stride); + free(data); } static int @@ -1130,9 +1133,7 @@ v3d_simulator_init_global() sim_state.v3d = v3d_hw_auto_new(NULL); v3d_hw_alloc_mem(sim_state.v3d, 1024 * 1024 * 1024); - sim_state.mem_base = - v3d_hw_get_mem(sim_state.v3d, &sim_state.mem_size, - &sim_state.mem); + v3d_hw_get_mem(sim_state.v3d, &sim_state.mem_size); /* Allocate from anywhere from 4096 up. We don't allocate at 0, * because for OQs and some other addresses in the HW, 0 means @@ -1144,7 +1145,7 @@ v3d_simulator_init_global() * and land there. */ struct mem_block *b = u_mmAllocMem(sim_state.heap, 4096, GMP_ALIGN2, 0); - memset(sim_state.mem + b->ofs - sim_state.mem_base, 0xd0, 4096); + v3d_hw_set_mem(sim_state.v3d, b->ofs, 0xd0, 4096); sim_state.ver = v3d_hw_get_version(sim_state.v3d); @@ -1188,9 +1189,8 @@ v3d_simulator_init(int fd) simple_mtx_unlock(&sim_state.mutex); sim_file->gmp = u_mmAllocMem(sim_state.heap, 8096, GMP_ALIGN2, 0); - sim_file->gmp_vaddr = (sim_state.mem + sim_file->gmp->ofs - - sim_state.mem_base); - memset(sim_file->gmp_vaddr, 0, 8096); + sim_file->gmp_addr = sim_file->gmp->ofs; + v3d_hw_set_mem(sim_state.v3d, sim_file->gmp_addr, 0, 8096); return sim_file; } @@ -1203,8 +1203,8 @@ v3d_simulator_destroy(struct v3d_simulator_file *sim_file) _mesa_hash_table_destroy(sim_state.fd_map, NULL); util_dynarray_fini(&sim_state.bin_oom); u_mmDestroy(sim_state.heap); - /* No memsetting the struct, because it contains the mutex. */ - sim_state.mem = NULL; + /* No memsetting the sim_state struct, because it contains the + * mutex. */ } ralloc_free(sim_file); simple_mtx_unlock(&sim_state.mutex); diff --git a/src/broadcom/simulator/v3d_simulator_wrapper.cpp b/src/broadcom/simulator/v3d_simulator_wrapper.cpp index 88e439255d3..ef9bec492ee 100644 --- a/src/broadcom/simulator/v3d_simulator_wrapper.cpp +++ b/src/broadcom/simulator/v3d_simulator_wrapper.cpp @@ -30,12 +30,6 @@ #ifdef USE_V3D_SIMULATOR #include "v3d_simulator_wrapper.h" - -#define V3D_TECH_VERSION 3 -#define V3D_REVISION 3 -#define V3D_SUB_REV 0 -#define V3D_HIDDEN_REV 0 -#define V3D_COMPAT_REV 0 #include "v3d_hw_auto.h" extern "C" { @@ -45,13 +39,29 @@ struct v3d_hw *v3d_hw_auto_new(void *in_params) return v3d_hw_auto_make_unique().release(); } - -uint32_t v3d_hw_get_mem(const struct v3d_hw *hw, uint32_t *size, void **p) +uint64_t v3d_hw_get_mem(const struct v3d_hw *hw, uint64_t *size) { - return hw->get_mem(size, p); + uint64_t addr; + assert(hw->get_mem(&addr, size)); + return addr; } -bool v3d_hw_alloc_mem(struct v3d_hw *hw, size_t min_size) +void v3d_hw_set_mem(struct v3d_hw *hw, uint64_t addr, uint8_t value, uint64_t size) +{ + hw->set_mem(addr, value, size); +} + +void v3d_hw_write_mem(struct v3d_hw *hw, uint64_t addr, const void *p, uint64_t size) +{ + hw->write_mem(addr, p, size); +} + +void v3d_hw_read_mem(struct v3d_hw *hw, void *p, uint64_t addr, uint64_t size) +{ + hw->read_mem(p, addr, size); +} + +bool v3d_hw_alloc_mem(struct v3d_hw *hw, uint64_t min_size) { return hw->alloc_mem(min_size) == V3D_HW_ALLOC_SUCCESS; } diff --git a/src/broadcom/simulator/v3d_simulator_wrapper.h b/src/broadcom/simulator/v3d_simulator_wrapper.h index 05b2a3361ac..7f2be57a3be 100644 --- a/src/broadcom/simulator/v3d_simulator_wrapper.h +++ b/src/broadcom/simulator/v3d_simulator_wrapper.h @@ -31,8 +31,11 @@ extern "C" { #endif struct v3d_hw *v3d_hw_auto_new(void *params); -uint32_t v3d_hw_get_mem(const struct v3d_hw *hw, uint32_t *size, void **p); -bool v3d_hw_alloc_mem(struct v3d_hw *hw, size_t min_size); +uint64_t v3d_hw_get_mem(const struct v3d_hw *hw, uint64_t *size); +void v3d_hw_set_mem(struct v3d_hw *hw, uint64_t addr, uint8_t value, uint64_t size); +void v3d_hw_write_mem(struct v3d_hw *hw, uint64_t add, const void *p, uint64_t size); +void v3d_hw_read_mem(struct v3d_hw *hw, void *p, uint64_t addr, uint64_t size); +bool v3d_hw_alloc_mem(struct v3d_hw *hw, uint64_t min_size); uint32_t v3d_hw_read_reg(struct v3d_hw *hw, uint32_t reg); void v3d_hw_write_reg(struct v3d_hw *hw, uint32_t reg, uint32_t val); void v3d_hw_tick(struct v3d_hw *hw); diff --git a/src/broadcom/simulator/v3dx_simulator.c b/src/broadcom/simulator/v3dx_simulator.c index 0caca367025..ea682955dca 100644 --- a/src/broadcom/simulator/v3dx_simulator.c +++ b/src/broadcom/simulator/v3dx_simulator.c @@ -49,7 +49,7 @@ #define HW_REGISTER_RO(x) (x) #define HW_REGISTER_RW(x) (x) #if V3D_VERSION == 71 -#include "libs/core/v3d/registers/7.1.6.0/v3d.h" +#include "libs/core/v3d/registers/7.1.7.0/v3d.h" #else #if V3D_VERSION == 42 #include "libs/core/v3d/registers/4.2.14.0/v3d.h" @@ -181,7 +181,7 @@ int v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d, struct drm_v3d_submit_tfu *args) { - int last_vtct = V3D_READ(TFU_REG(CS)) & V3D_TFU_CS_CVTCT_SET; + int last_vtct = V3D_READ(TFU_REG(CS)) & TFU_REG(CS_CVTCT_SET); V3D_WRITE(TFU_REG(IIA), args->iia); V3D_WRITE(TFU_REG(IIS), args->iis); @@ -199,7 +199,7 @@ v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d, V3D_WRITE(TFU_REG(ICFG), args->icfg); - while ((V3D_READ(TFU_REG(CS)) & V3D_TFU_CS_CVTCT_SET) == last_vtct) { + while ((V3D_READ(TFU_REG(CS)) & TFU_REG(CS_CVTCT_SET)) == last_vtct) { v3d_hw_tick(v3d); } @@ -254,7 +254,11 @@ v3dX(simulator_get_param_ioctl)(struct v3d_hw *v3d, struct drm_v3d_get_param *args) { static const uint32_t reg_map[] = { +#if V3D_VERSION >= 71 + [DRM_V3D_PARAM_V3D_UIFCFG] = V3D_HUB_CTL_IDENT0, +#else [DRM_V3D_PARAM_V3D_UIFCFG] = V3D_HUB_CTL_UIFCFG, +#endif [DRM_V3D_PARAM_V3D_HUB_IDENT1] = V3D_HUB_CTL_IDENT1, [DRM_V3D_PARAM_V3D_HUB_IDENT2] = V3D_HUB_CTL_IDENT2, [DRM_V3D_PARAM_V3D_HUB_IDENT3] = V3D_HUB_CTL_IDENT3, @@ -345,7 +349,7 @@ handle_mmu_interruptions(struct v3d_hw *v3d, return; const char *client = "?"; - uint32_t axi_id = V3D_READ(V3D_MMU_VIO_ID); + uint32_t axi_id = V3D_READ(V3D_MMU0_VIO_ID); uint32_t va_width = 30; static const char *const v3d42_axi_ids[] = { @@ -363,15 +367,15 @@ handle_mmu_interruptions(struct v3d_hw *v3d, if (axi_id < ARRAY_SIZE(v3d42_axi_ids)) client = v3d42_axi_ids[axi_id]; - uint32_t mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO); + uint32_t mmu_debug = V3D_READ(V3D_MMU0_DEBUG_INFO); - va_width += ((mmu_debug & V3D_MMU_DEBUG_INFO_VA_WIDTH_SET) - >> V3D_MMU_DEBUG_INFO_VA_WIDTH_LSB); + va_width += ((mmu_debug & V3D_MMU0_DEBUG_INFO_VA_WIDTH_SET) + >> V3D_MMU0_DEBUG_INFO_VA_WIDTH_LSB); /* Only the top bits (final number depends on the gen) of the virtual * address are reported in the MMU VIO_ADDR register. */ - uint64_t vio_addr = ((uint64_t)V3D_READ(V3D_MMU_VIO_ADDR) << + uint64_t vio_addr = ((uint64_t)V3D_READ(V3D_MMU0_VIO_ADDR) << (va_width - 32)); /* Difference with the kernel: here were are going to abort after diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build index e758fba0cd8..4e6eb3990d5 100644 --- a/src/broadcom/vulkan/meson.build +++ b/src/broadcom/vulkan/meson.build @@ -73,8 +73,8 @@ v3d_versions = ['42', '71'] v3dv_flags = [] -dep_v3dv3 = dependency('v3dv3', required : false) -if dep_v3dv3.found() +dep_v3d_hw = dependency('v3d_hw', required : false) +if dep_v3d_hw.found() v3dv_flags += '-DUSE_V3D_SIMULATOR' endif @@ -82,7 +82,7 @@ v3dv_deps = [ dep_dl, dep_libdrm, dep_valgrind, - dep_v3dv3, + dep_v3d_hw, idep_nir, idep_nir_headers, idep_vulkan_util, diff --git a/src/gallium/drivers/v3d/meson.build b/src/gallium/drivers/v3d/meson.build index 1905ac393ae..d5f2a24b156 100644 --- a/src/gallium/drivers/v3d/meson.build +++ b/src/gallium/drivers/v3d/meson.build @@ -54,8 +54,8 @@ files_per_version = files( v3d_args = ['-DV3D_BUILD_NEON'] -dep_v3dv3 = dependency('v3dv3', required: false) -if dep_v3dv3.found() +dep_v3d_hw = dependency('v3d_hw', required: false) +if dep_v3d_hw.found() v3d_args += '-DUSE_V3D_SIMULATOR' endif @@ -72,7 +72,7 @@ foreach ver : v3d_versions ], c_args : [v3d_args, '-DV3D_VERSION=' + ver], gnu_symbol_visibility : 'hidden', - dependencies : [dep_v3dv3, dep_libdrm, dep_valgrind, idep_nir_headers], + dependencies : [dep_v3d_hw, dep_libdrm, dep_valgrind, idep_nir_headers], ) endforeach @@ -91,7 +91,7 @@ libv3d = static_library( cpp_args : [v3d_args], gnu_symbol_visibility : 'hidden', dependencies : [ - dep_v3dv3, dep_libdrm, dep_valgrind, + dep_v3d_hw, dep_libdrm, dep_valgrind, idep_nir_headers, idep_mesautil, ], link_with: [per_version_libs],