From 7999326f074dd2b9d4263bb39b74bacd32861a65 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Mon, 20 Mar 2023 16:48:51 +0100 Subject: [PATCH] broadcom/simulator: add per-hw version calls Add a wrapper to allow calling the right simulator function based on the hardware under simulation. Signed-off-by: Juan A. Suarez Romero Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/simulator/v3d_simulator.c | 95 +++++---------------------------- src/broadcom/simulator/v3d_simulator.h | 21 ++++++++ src/broadcom/simulator/v3dx_simulator.c | 16 ++++-- src/broadcom/simulator/v3dx_simulator.h | 1 + 4 files changed, 48 insertions(+), 85 deletions(-) diff --git a/src/broadcom/simulator/v3d_simulator.c b/src/broadcom/simulator/v3d_simulator.c index 36e7192..c3802dd 100644 --- a/src/broadcom/simulator/v3d_simulator.c +++ b/src/broadcom/simulator/v3d_simulator.c @@ -439,15 +439,15 @@ v3d_simulator_perfmon_switch(int fd, uint32_t perfid) perfmon = v3d_get_simulator_perfmon(fd, file->active_perfid); if (perfmon) - v3d41_simulator_perfmon_stop(sim_state.v3d, - perfmon->ncounters, - perfmon->values); + v3d_X_simulator(perfmon_stop)(sim_state.v3d, + perfmon->ncounters, + perfmon->values); perfmon = v3d_get_simulator_perfmon(fd, perfid); if (perfmon) - v3d41_simulator_perfmon_start(sim_state.v3d, - perfmon->ncounters, - perfmon->counters); + v3d_X_simulator(perfmon_start)(sim_state.v3d, + perfmon->ncounters, + perfmon->counters); file->active_perfid = perfid; } @@ -492,21 +492,7 @@ v3d_simulator_submit_cl_ioctl(int fd, struct drm_v3d_submit_cl *submit) bin_fd = fd; v3d_simulator_perfmon_switch(fd, submit->perfmon_id); - - switch(sim_state.ver) { - case 33: - v3d33_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs); - break; - case 41: - case 42: - v3d41_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs); - break; - case 71: - v3d71_simulator_submit_cl_ioctl(sim_state.v3d, submit, file->gmp->ofs); - break; - default: - unreachable("Unsupported V3D version\n"); - } + v3d_X_simulator(submit_cl_ioctl)(sim_state.v3d, submit, file->gmp->ofs); util_dynarray_foreach(&sim_state.bin_oom, struct v3d_simulator_bo *, sim_bo) { @@ -646,22 +632,6 @@ v3d_simulator_gem_close_ioctl(int fd, struct drm_gem_close *args) } static int -v3d_simulator_get_param_ioctl(int fd, struct drm_v3d_get_param *args) -{ - switch(sim_state.ver) { - case 33: - return v3d33_simulator_get_param_ioctl(sim_state.v3d, args); - case 41: - case 42: - return v3d41_simulator_get_param_ioctl(sim_state.v3d, args); - case 71: - return v3d71_simulator_get_param_ioctl(sim_state.v3d, args); - default: - unreachable("Unsupported V3D version\n"); - } -} - -static int v3d_simulator_submit_tfu_ioctl(int fd, struct drm_v3d_submit_tfu *args) { struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd); @@ -672,20 +642,7 @@ v3d_simulator_submit_tfu_ioctl(int fd, struct drm_v3d_submit_tfu *args) v3d_simulator_copy_in_handle(file, args->bo_handles[2]); v3d_simulator_copy_in_handle(file, args->bo_handles[3]); - switch(sim_state.ver) { - case 33: - ret = v3d33_simulator_submit_tfu_ioctl(sim_state.v3d, args); - break; - case 41: - case 42: - ret = v3d41_simulator_submit_tfu_ioctl(sim_state.v3d, args); - break; - case 71: - ret = v3d71_simulator_submit_tfu_ioctl(sim_state.v3d, args); - break; - default: - unreachable("Unsupported V3D version\n"); - } + ret = v3d_X_simulator(submit_tfu_ioctl)(sim_state.v3d, args); v3d_simulator_copy_out_handle(file, args->bo_handles[0]); @@ -712,19 +669,8 @@ v3d_simulator_submit_csd_ioctl(int fd, struct drm_v3d_submit_csd *args) v3d_simulator_perfmon_switch(fd, args->perfmon_id); - switch(sim_state.ver) { - case 41: - case 42: - ret = v3d41_simulator_submit_csd_ioctl(sim_state.v3d, args, - file->gmp->ofs); - break; - case 71: - ret = v3d71_simulator_submit_csd_ioctl(sim_state.v3d, args, - file->gmp->ofs); - break; - default: - ret = -1; - } + ret = v3d_X_simulator(submit_csd_ioctl)(sim_state.v3d, args, + file->gmp->ofs); for (int i = 0; i < args->bo_handle_count; i++) v3d_simulator_copy_out_handle(file, bo_handles[i]); @@ -835,7 +781,7 @@ v3d_simulator_ioctl(int fd, unsigned long request, void *args) return 0; case DRM_IOCTL_V3D_GET_PARAM: - return v3d_simulator_get_param_ioctl(fd, args); + return v3d_X_simulator(get_param_ioctl)(sim_state.v3d, args); case DRM_IOCTL_GEM_CLOSE: return v3d_simulator_gem_close_ioctl(fd, args); @@ -918,23 +864,8 @@ v3d_simulator_init_global() util_dynarray_init(&sim_state.bin_oom, NULL); - switch(sim_state.ver) { - case 33: - v3d33_simulator_init_regs(sim_state.v3d); - sim_state.perfcnt_total = 0; - break; - case 41: - case 42: - v3d41_simulator_init_regs(sim_state.v3d); - sim_state.perfcnt_total = 87; - break; - case 71: - v3d71_simulator_init_regs(sim_state.v3d); - sim_state.perfcnt_total = 93; - break; - default: - unreachable("Not supported V3D version\n"); - } + v3d_X_simulator(init_regs)(sim_state.v3d); + v3d_X_simulator(get_perfcnt_total)(&sim_state.perfcnt_total); } struct v3d_simulator_file * diff --git a/src/broadcom/simulator/v3d_simulator.h b/src/broadcom/simulator/v3d_simulator.h index 1472c31..9230563 100644 --- a/src/broadcom/simulator/v3d_simulator.h +++ b/src/broadcom/simulator/v3d_simulator.h @@ -59,4 +59,25 @@ uint32_t v3d_simulator_get_mem_free(void); #endif +/* Helper to call simulator ver specific functions */ +#define v3d_X_simulator(thing) ({ \ + __typeof(&v3d33_simulator_##thing) v3d_X_sim_thing;\ + switch (sim_state.ver) { \ + case 33: \ + case 40: \ + v3d_X_sim_thing = &v3d33_simulator_##thing; \ + break; \ + case 41: \ + case 42: \ + v3d_X_sim_thing = &v3d41_simulator_##thing; \ + break; \ + case 71: \ + v3d_X_sim_thing = &v3d71_simulator_##thing; \ + break; \ + default: \ + unreachable("Unsupported hardware generation"); \ + } \ + v3d_X_sim_thing; \ +}) + #endif diff --git a/src/broadcom/simulator/v3dx_simulator.c b/src/broadcom/simulator/v3dx_simulator.c index 618fd34..904cf2d 100644 --- a/src/broadcom/simulator/v3dx_simulator.c +++ b/src/broadcom/simulator/v3dx_simulator.c @@ -40,6 +40,8 @@ #include "v3d_simulator.h" #include "v3d_simulator_wrapper.h" +#include "common/v3d_performance_counters.h" + #include "util/macros.h" #include "util/bitscan.h" #include "drm-uapi/v3d_drm.h" @@ -218,12 +220,12 @@ v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d, return 0; } -#if V3D_VERSION >= 41 int v3dX(simulator_submit_csd_ioctl)(struct v3d_hw *v3d, struct drm_v3d_submit_csd *args, uint32_t gmp_ofs) { +#if V3D_VERSION >= 41 int last_completed_jobs = (V3D_READ(V3D_CSD_0_STATUS) & V3D_CSD_0_STATUS_NUM_COMPLETED_JOBS_SET); g_gmp_ofs = gmp_ofs; @@ -256,8 +258,10 @@ v3dX(simulator_submit_csd_ioctl)(struct v3d_hw *v3d, v3d_flush_caches(v3d); return 0; -} +#else + return -1; #endif +} int v3dX(simulator_get_param_ioctl)(struct v3d_hw *v3d, @@ -545,7 +549,8 @@ v3dX(simulator_submit_cl_ioctl)(struct v3d_hw *v3d, #define V3D_PCTR_0_SRC_N(x) (V3D_PCTR_0_SRC_0_3 + 4 * (x)) #define V3D_PCTR_0_SRC_N_SHIFT(x) ((x) * 8) #define V3D_PCTR_0_SRC_N_MASK(x) (BITFIELD_RANGE(V3D_PCTR_0_SRC_N_SHIFT(x), \ - V3D_PCTR_0_SRC_N_SHIFT(x) + 6)) + V3D_PCTR_0_SRC_N_SHIFT(x) + \ + V3D_PCTR_0_SRC_0_3_PCTRS0_MSB)) #endif void @@ -585,4 +590,9 @@ void v3dX(simulator_perfmon_stop)(struct v3d_hw *v3d, #endif } +void v3dX(simulator_get_perfcnt_total)(uint32_t *count) +{ + *count = ARRAY_SIZE(v3d_performance_counters); +} + #endif /* USE_V3D_SIMULATOR */ diff --git a/src/broadcom/simulator/v3dx_simulator.h b/src/broadcom/simulator/v3dx_simulator.h index f7d2cc6..51fc240 100644 --- a/src/broadcom/simulator/v3dx_simulator.h +++ b/src/broadcom/simulator/v3dx_simulator.h @@ -50,3 +50,4 @@ void v3dX(simulator_perfmon_start)(struct v3d_hw *v3d, void v3dX(simulator_perfmon_stop)(struct v3d_hw *v3d, uint32_t ncounters, uint64_t *values); +void v3dX(simulator_get_perfcnt_total)(uint32_t *count); -- 2.7.4