diff options
author | Eric Anholt <[email protected]> | 2016-10-11 17:44:43 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2016-10-21 14:12:22 -0700 |
commit | 9f755223821eaa0a889f8a10cccc66e15bf0abb4 (patch) | |
tree | e7040d4ef7f085c3683f0e3d4a46bcfe1aa7c26c /src/gallium | |
parent | 78087676c98aa8884ba92e75a0a5306a8f78ad43 (diff) |
vc4: Move simulator globals into a struct.
I would like to put a couple more things in here, so it's time to package
it up.
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/vc4/vc4_screen.h | 3 | ||||
-rw-r--r-- | src/gallium/drivers/vc4/vc4_simulator.c | 60 |
2 files changed, 29 insertions, 34 deletions
diff --git a/src/gallium/drivers/vc4/vc4_screen.h b/src/gallium/drivers/vc4/vc4_screen.h index 16003cfccf0..9fbe48c9a51 100644 --- a/src/gallium/drivers/vc4/vc4_screen.h +++ b/src/gallium/drivers/vc4/vc4_screen.h @@ -55,9 +55,6 @@ struct vc4_screen { const char *name; - void *simulator_mem_base; - uint32_t simulator_mem_size; - /** The last seqno we've completed a wait for. * * This lets us slightly optimize our waits by skipping wait syscalls diff --git a/src/gallium/drivers/vc4/vc4_simulator.c b/src/gallium/drivers/vc4/vc4_simulator.c index 76896c06e73..e77819d9045 100644 --- a/src/gallium/drivers/vc4/vc4_simulator.c +++ b/src/gallium/drivers/vc4/vc4_simulator.c @@ -34,7 +34,17 @@ #include "vc4_simulator_validate.h" #include "simpenrose/simpenrose.h" -static mtx_t exec_mutex = _MTX_INITIALIZER_NP; +/** Global (across GEM fds) state for the simulator */ +static struct vc4_simulator_state { + mtx_t mutex; + + void *mem; + ssize_t mem_size; + + int refcount; +} sim_state = { + .mutex = _MTX_INITIALIZER_NP, +}; /* A marker placed just after each BO, then checked after rendering to make * sure it's still there. @@ -46,8 +56,6 @@ static mtx_t exec_mutex = _MTX_INITIALIZER_NP; static struct drm_gem_cma_object * vc4_wrap_bo_with_cma(struct drm_device *dev, struct vc4_bo *bo) { - struct vc4_context *vc4 = dev->vc4; - struct vc4_screen *screen = vc4->screen; struct drm_vc4_bo *drm_bo = CALLOC_STRUCT(drm_vc4_bo); struct drm_gem_cma_object *obj = &drm_bo->base; uint32_t size = align(bo->size, 4096); @@ -55,12 +63,12 @@ vc4_wrap_bo_with_cma(struct drm_device *dev, struct vc4_bo *bo) drm_bo->bo = bo; obj->base.size = size; obj->base.dev = dev; - obj->vaddr = screen->simulator_mem_base + dev->simulator_mem_next; + obj->vaddr = sim_state.mem + dev->simulator_mem_next; obj->paddr = simpenrose_hw_addr(obj->vaddr); dev->simulator_mem_next += size + sizeof(uint32_t); dev->simulator_mem_next = align(dev->simulator_mem_next, 4096); - assert(dev->simulator_mem_next <= screen->simulator_mem_size); + assert(dev->simulator_mem_next <= sim_state.mem_size); *(uint32_t *)(obj->vaddr + bo->size) = BO_SENTINEL; @@ -226,7 +234,6 @@ int vc4_simulator_flush(struct vc4_context *vc4, struct drm_vc4_submit_cl *args, struct vc4_job *job) { - struct vc4_screen *screen = vc4->screen; struct vc4_surface *csurf = vc4_surface(vc4->framebuffer.cbufs[0]); struct vc4_resource *ctex = csurf ? vc4_resource(csurf->base.texture) : NULL; uint32_t winsys_stride = ctex ? ctex->bo->simulator_winsys_stride : 0; @@ -271,7 +278,7 @@ vc4_simulator_flush(struct vc4_context *vc4, if (vc4_debug & VC4_DEBUG_CL) { fprintf(stderr, "RCL:\n"); - vc4_dump_cl(screen->simulator_mem_base + exec.ct1ca, + vc4_dump_cl(sim_state.mem + exec.ct1ca, exec.ct1ea - exec.ct1ca, true); } @@ -283,7 +290,7 @@ vc4_simulator_flush(struct vc4_context *vc4, fprintf(stderr, "Binning returned %d flushes, should be 1.\n", bfc); fprintf(stderr, "Relocated binning command list:\n"); - vc4_dump_cl(screen->simulator_mem_base + exec.ct0ca, + vc4_dump_cl(sim_state.mem + exec.ct0ca, exec.ct0ea - exec.ct0ca, false); abort(); } @@ -293,7 +300,7 @@ vc4_simulator_flush(struct vc4_context *vc4, fprintf(stderr, "Rendering returned %d frames, should be 1.\n", rfc); fprintf(stderr, "Relocated render command list:\n"); - vc4_dump_cl(screen->simulator_mem_base + exec.ct1ca, + vc4_dump_cl(sim_state.mem + exec.ct1ca, exec.ct1ea - exec.ct1ca, true); abort(); } @@ -459,33 +466,24 @@ vc4_simulator_ioctl(int fd, unsigned long request, void *args) } } -static void *sim_mem_base = NULL; -static int sim_mem_refcount = 0; -static ssize_t sim_mem_size = 256 * 1024 * 1024; - void vc4_simulator_init(struct vc4_screen *screen) { - mtx_lock(&exec_mutex); - if (sim_mem_refcount++) { - screen->simulator_mem_size = sim_mem_size; - screen->simulator_mem_base = sim_mem_base; - mtx_unlock(&exec_mutex); + mtx_lock(&sim_state.mutex); + if (sim_state.refcount++) { + mtx_unlock(&sim_state.mutex); return; } - sim_mem_base = calloc(sim_mem_size, 1); - if (!sim_mem_base) + sim_state.mem_size = 256 * 1024 * 1024; + sim_state.mem = calloc(sim_state.mem_size, 1); + if (!sim_state.mem) abort(); - screen->simulator_mem_size = sim_mem_size; - screen->simulator_mem_base = sim_mem_base; - /* We supply our own memory so that we can have more aperture * available (256MB instead of simpenrose's default 64MB). */ - simpenrose_init_hardware_supply_mem(screen->simulator_mem_base, - screen->simulator_mem_size); + simpenrose_init_hardware_supply_mem(sim_state.mem, sim_state.mem_size); /* Carve out low memory for tile allocation overflow. The kernel * should be automatically handling overflow memory setup on real @@ -496,18 +494,18 @@ vc4_simulator_init(struct vc4_screen *screen) */ simpenrose_supply_overflow_mem(0, OVERFLOW_SIZE); - mtx_unlock(&exec_mutex); + mtx_unlock(&sim_state.mutex); } void vc4_simulator_destroy(struct vc4_screen *screen) { - mtx_lock(&exec_mutex); - if (!--sim_mem_refcount) { - free(sim_mem_base); - sim_mem_base = NULL; + mtx_lock(&sim_state.mutex); + if (!--sim_state.refcount) { + free(sim_state.mem); + /* No memsetting it, because it contains the mutex. */ } - mtx_unlock(&exec_mutex); + mtx_unlock(&sim_state.mutex); } #endif /* USE_VC4_SIMULATOR */ |