struct radeon_drm_winsys *rws = bo->rws;
struct drm_gem_close args;
+ assert(bo->handle && "must not be called for slab entries");
+
memset(&args, 0, sizeof(args));
pipe_mutex_lock(rws->bo_handles_mutex);
}
pipe_mutex_unlock(rws->bo_handles_mutex);
- if (bo->ptr)
- os_munmap(bo->ptr, bo->base.size);
+ if (bo->u.real.ptr)
+ os_munmap(bo->u.real.ptr, bo->base.size);
if (rws->info.has_virtual_memory) {
if (rws->va_unmap_working) {
args.handle = bo->handle;
drmIoctl(rws->fd, DRM_IOCTL_GEM_CLOSE, &args);
- pipe_mutex_destroy(bo->map_mutex);
+ pipe_mutex_destroy(bo->u.real.map_mutex);
if (bo->initial_domain & RADEON_DOMAIN_VRAM)
rws->allocated_vram -= align(bo->base.size, rws->info.gart_page_size);
else if (bo->initial_domain & RADEON_DOMAIN_GTT)
rws->allocated_gtt -= align(bo->base.size, rws->info.gart_page_size);
- if (bo->map_count >= 1) {
+ if (bo->u.real.map_count >= 1) {
if (bo->initial_domain & RADEON_DOMAIN_VRAM)
bo->rws->mapped_vram -= bo->base.size;
else
{
struct radeon_bo *bo = radeon_bo(_buf);
- if (bo->use_reusable_pool)
- pb_cache_add_buffer(&bo->cache_entry);
+ assert(bo->handle && "must not be called for slab entries");
+
+ if (bo->u.real.use_reusable_pool)
+ pb_cache_add_buffer(&bo->u.real.cache_entry);
else
radeon_bo_destroy(_buf);
}
{
struct drm_radeon_gem_mmap args = {0};
void *ptr;
+ unsigned offset;
/* If the buffer is created from user memory, return the user pointer. */
if (bo->user_ptr)
return bo->user_ptr;
+ if (bo->handle) {
+ offset = 0;
+ } else {
+ offset = bo->va - bo->u.slab.real->va;
+ bo = bo->u.slab.real;
+ }
+
/* Map the buffer. */
- pipe_mutex_lock(bo->map_mutex);
+ pipe_mutex_lock(bo->u.real.map_mutex);
/* Return the pointer if it's already mapped. */
- if (bo->ptr) {
- bo->map_count++;
- pipe_mutex_unlock(bo->map_mutex);
- return bo->ptr;
+ if (bo->u.real.ptr) {
+ bo->u.real.map_count++;
+ pipe_mutex_unlock(bo->u.real.map_mutex);
+ return (uint8_t*)bo->u.real.ptr + offset;
}
args.handle = bo->handle;
args.offset = 0;
DRM_RADEON_GEM_MMAP,
&args,
sizeof(args))) {
- pipe_mutex_unlock(bo->map_mutex);
+ pipe_mutex_unlock(bo->u.real.map_mutex);
fprintf(stderr, "radeon: gem_mmap failed: %p 0x%08X\n",
bo, bo->handle);
return NULL;
ptr = os_mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED,
bo->rws->fd, args.addr_ptr);
if (ptr == MAP_FAILED) {
- pipe_mutex_unlock(bo->map_mutex);
+ pipe_mutex_unlock(bo->u.real.map_mutex);
fprintf(stderr, "radeon: mmap failed, errno: %i\n", errno);
return NULL;
}
}
- bo->ptr = ptr;
- bo->map_count = 1;
+ bo->u.real.ptr = ptr;
+ bo->u.real.map_count = 1;
if (bo->initial_domain & RADEON_DOMAIN_VRAM)
bo->rws->mapped_vram += bo->base.size;
else
bo->rws->mapped_gtt += bo->base.size;
- pipe_mutex_unlock(bo->map_mutex);
- return bo->ptr;
+ pipe_mutex_unlock(bo->u.real.map_mutex);
+ return (uint8_t*)bo->u.real.ptr + offset;
}
static void *radeon_bo_map(struct pb_buffer *buf,
if (bo->user_ptr)
return;
- pipe_mutex_lock(bo->map_mutex);
- if (!bo->ptr) {
- pipe_mutex_unlock(bo->map_mutex);
+ if (!bo->handle)
+ bo = bo->u.slab.real;
+
+ pipe_mutex_lock(bo->u.real.map_mutex);
+ if (!bo->u.real.ptr) {
+ pipe_mutex_unlock(bo->u.real.map_mutex);
return; /* it's not been mapped */
}
- assert(bo->map_count);
- if (--bo->map_count) {
- pipe_mutex_unlock(bo->map_mutex);
+ assert(bo->u.real.map_count);
+ if (--bo->u.real.map_count) {
+ pipe_mutex_unlock(bo->u.real.map_mutex);
return; /* it's been mapped multiple times */
}
- os_munmap(bo->ptr, bo->base.size);
- bo->ptr = NULL;
+ os_munmap(bo->u.real.ptr, bo->base.size);
+ bo->u.real.ptr = NULL;
if (bo->initial_domain & RADEON_DOMAIN_VRAM)
bo->rws->mapped_vram -= bo->base.size;
else
bo->rws->mapped_gtt -= bo->base.size;
- pipe_mutex_unlock(bo->map_mutex);
+ pipe_mutex_unlock(bo->u.real.map_mutex);
}
static const struct pb_vtbl radeon_bo_vtbl = {
return NULL;
}
+ assert(args.handle != 0);
+
bo = CALLOC_STRUCT(radeon_bo);
if (!bo)
return NULL;
bo->handle = args.handle;
bo->va = 0;
bo->initial_domain = initial_domains;
- pipe_mutex_init(bo->map_mutex);
- pb_cache_init_entry(&rws->bo_cache, &bo->cache_entry, &bo->base,
+ pipe_mutex_init(bo->u.real.map_mutex);
+ pb_cache_init_entry(&rws->bo_cache, &bo->u.real.cache_entry, &bo->base,
pb_cache_bucket);
if (rws->info.has_virtual_memory) {
struct radeon_bo *bo = radeon_bo(_buf);
struct drm_radeon_gem_set_tiling args;
+ assert(bo->handle && "must not be called for slab entries");
+
memset(&args, 0, sizeof(args));
args.handle = bo->handle;
struct radeon_bo *bo = radeon_bo(_buf);
struct drm_radeon_gem_set_tiling args;
+ assert(bo->handle && "must not be called for slab entries");
+
memset(&args, 0, sizeof(args));
os_wait_until_zero(&bo->num_active_ioctls, PIPE_TIMEOUT_INFINITE);
return NULL;
}
- bo->use_reusable_pool = true;
+ bo->u.real.use_reusable_pool = true;
pipe_mutex_lock(ws->bo_handles_mutex);
util_hash_table_set(ws->bo_handles, (void*)(uintptr_t)bo->handle, bo);
return NULL;
}
+ assert(args.handle != 0);
+
pipe_mutex_lock(ws->bo_handles_mutex);
/* Initialize it. */
bo->user_ptr = pointer;
bo->va = 0;
bo->initial_domain = RADEON_DOMAIN_GTT;
- pipe_mutex_init(bo->map_mutex);
+ pipe_mutex_init(bo->u.real.map_mutex);
util_hash_table_set(ws->bo_handles, (void*)(uintptr_t)bo->handle, bo);
lseek(whandle->handle, 0, SEEK_SET);
}
+ assert(handle != 0);
+
bo->handle = handle;
/* Initialize it. */
bo->base.vtbl = &radeon_bo_vtbl;
bo->rws = ws;
bo->va = 0;
- pipe_mutex_init(bo->map_mutex);
+ pipe_mutex_init(bo->u.real.map_mutex);
if (bo->flink_name)
util_hash_table_set(ws->bo_names, (void*)(uintptr_t)bo->flink_name, bo);
struct radeon_bo *bo = radeon_bo(buffer);
struct radeon_drm_winsys *ws = bo->rws;
+ if (!bo->handle) {
+ offset += bo->va - bo->u.slab.real->va;
+ bo = bo->u.slab.real;
+ }
+
memset(&flink, 0, sizeof(flink));
- bo->use_reusable_pool = false;
+ bo->u.real.use_reusable_pool = false;
if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
if (!bo->flink_name) {