ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MADVISE, &madv);
if (!ret && !madv.retained) {
- panfrost_bo_release(screen, entry, false);
+ panfrost_bo_release(entry, false);
continue;
}
/* Let's go! */
* successful */
static bool
-panfrost_bo_cache_put(
- struct panfrost_screen *screen,
- struct panfrost_bo *bo)
+panfrost_bo_cache_put(struct panfrost_bo *bo)
{
+ struct panfrost_screen *screen = bo->screen;
+
pthread_mutex_lock(&screen->bo_cache_lock);
struct list_head *bucket = pan_bucket(screen, bo->size);
struct drm_panfrost_madvise madv;
list_for_each_entry_safe(struct panfrost_bo, entry, bucket, link) {
list_del(&entry->link);
- panfrost_bo_release(screen, entry, false);
+ panfrost_bo_release(entry, false);
}
}
pthread_mutex_unlock(&screen->bo_cache_lock);
}
void
-panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
+panfrost_bo_mmap(struct panfrost_bo *bo)
{
struct drm_panfrost_mmap_bo mmap_bo = { .handle = bo->gem_handle };
int ret;
if (bo->cpu)
return;
- ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
+ ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
if (ret) {
fprintf(stderr, "DRM_IOCTL_PANFROST_MMAP_BO failed: %m\n");
assert(0);
}
bo->cpu = os_mmap(NULL, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
- screen->fd, mmap_bo.offset);
+ bo->screen->fd, mmap_bo.offset);
if (bo->cpu == MAP_FAILED) {
fprintf(stderr, "mmap failed: %p %m\n", bo->cpu);
assert(0);
}
static void
-panfrost_bo_munmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
+panfrost_bo_munmap(struct panfrost_bo *bo)
{
if (!bo->cpu)
return;
* for GPU-internal use. But we do trace them anyway. */
if (!(flags & (PAN_BO_INVISIBLE | PAN_BO_DELAY_MMAP)))
- panfrost_bo_mmap(screen, bo);
+ panfrost_bo_mmap(bo);
else if (flags & PAN_BO_INVISIBLE) {
if (pan_debug & PAN_DBG_TRACE)
pandecode_inject_mmap(bo->gpu, NULL, bo->size, NULL);
}
void
-panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
- bool cacheable)
+panfrost_bo_release(struct panfrost_bo *bo, bool cacheable)
{
if (!bo)
return;
/* Rather than freeing the BO now, we'll cache the BO for later
* allocations if we're allowed to */
- panfrost_bo_munmap(screen, bo);
+ panfrost_bo_munmap(bo);
if (cacheable) {
- bool cached = panfrost_bo_cache_put(screen, bo);
+ bool cached = panfrost_bo_cache_put(bo);
if (cached)
return;
/* Otherwise, if the BO wasn't cached, we'll legitimately free the BO */
- ret = drmIoctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
+ ret = drmIoctl(bo->screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
if (ret) {
fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %m\n");
assert(0);
}
void
-panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
+panfrost_bo_unreference(struct panfrost_bo *bo)
{
if (!bo)
return;
/* When the reference count goes to zero, we need to cleanup */
if (pipe_reference(&bo->reference, NULL))
- panfrost_bo_release(pan_screen(screen), bo, true);
+ panfrost_bo_release(bo, true);
}
struct panfrost_bo *
ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_GET_BO_OFFSET, &get_bo_offset);
assert(!ret);
+ bo->screen = screen;
bo->gem_handle = gem_handle;
bo->gpu = (mali_ptr) get_bo_offset.offset;
bo->size = lseek(fd, 0, SEEK_END);
pipe_reference_init(&bo->reference, 1);
// TODO map and unmap on demand?
- panfrost_bo_mmap(screen, bo);
+ panfrost_bo_mmap(bo);
return bo;
}
int
-panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo)
+panfrost_bo_export(struct panfrost_bo *bo)
{
struct drm_prime_handle args = {
.handle = bo->gem_handle,
.flags = DRM_CLOEXEC,
};
- int ret = drmIoctl(screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
+ int ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
if (ret == -1)
return -1;
struct pipe_reference reference;
+ struct panfrost_screen *screen;
+
/* Mapping for the entire object (all levels) */
uint8_t *cpu;
void
panfrost_bo_reference(struct panfrost_bo *bo);
void
-panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo);
+panfrost_bo_unreference(struct panfrost_bo *bo);
struct panfrost_bo *
panfrost_bo_create(struct panfrost_screen *screen, size_t size,
uint32_t flags);
void
-panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo);
+panfrost_bo_mmap(struct panfrost_bo *bo);
void
-panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
- bool cacheable);
+panfrost_bo_release(struct panfrost_bo *bo, bool cacheable);
struct panfrost_bo *
panfrost_bo_import(struct panfrost_screen *screen, int fd);
int
-panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo);
+panfrost_bo_export(struct panfrost_bo *bo);
void
panfrost_bo_cache_evict_all(struct panfrost_screen *screen);
for (unsigned i = 0; i < cso->variant_count; ++i) {
struct panfrost_shader_state *shader_state = &cso->variants[i];
- panfrost_bo_unreference(pctx->screen, shader_state->bo);
+ panfrost_bo_unreference(shader_state->bo);
shader_state->bo = NULL;
}
panfrost_destroy(struct pipe_context *pipe)
{
struct panfrost_context *panfrost = pan_context(pipe);
- struct panfrost_screen *screen = pan_screen(pipe->screen);
if (panfrost->blitter)
util_blitter_destroy(panfrost->blitter);
if (panfrost->blitter_wallpaper)
util_blitter_destroy(panfrost->blitter_wallpaper);
- panfrost_bo_release(screen, panfrost->scratchpad, false);
- panfrost_bo_release(screen, panfrost->tiler_heap, false);
- panfrost_bo_release(screen, panfrost->tiler_dummy, false);
+ panfrost_bo_release(panfrost->scratchpad, false);
+ panfrost_bo_release(panfrost->tiler_heap, false);
+ panfrost_bo_release(panfrost->tiler_dummy, false);
ralloc_free(pipe);
}
return true;
} else {
- int fd = panfrost_bo_export(screen, rsrc->bo);
+ int fd = panfrost_bo_export(rsrc->bo);
if (fd < 0)
return false;
renderonly_scanout_destroy(rsrc->scanout, pscreen->ro);
if (rsrc->bo)
- panfrost_bo_unreference(screen, rsrc->bo);
+ panfrost_bo_unreference(rsrc->bo);
util_range_destroy(&rsrc->valid_buffer_range);
ralloc_free(rsrc);
*out_transfer = &transfer->base;
/* If we haven't already mmaped, now's the time */
- panfrost_bo_mmap(pan_screen(pctx->screen), bo);
+ panfrost_bo_mmap(bo);
/* Check if we're bound for rendering and this is a read pixels. If so,
* we need to flush */
/* If we grew in size, reallocate the BO */
if (new_size > rsrc->bo->size) {
- panfrost_bo_release(screen, rsrc->bo, true);
+ panfrost_bo_release(rsrc->bo, true);
rsrc->bo = panfrost_bo_create(screen, new_size, PAN_BO_DELAY_MMAP);
}
}