/** * panthor_kernel_bo_destroy() - Destroy a kernel buffer object * @bo: Kernel buffer object to destroy. If NULL or an ERR_PTR(), the destruction * is skipped.
*/ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
{ struct panthor_vm *vm; int ret;
if (IS_ERR_OR_NULL(bo)) return;
vm = bo->vm;
panthor_kernel_bo_vunmap(bo);
if (drm_WARN_ON(bo->obj->dev,
to_panthor_bo(bo->obj)->exclusive_vm_root_gem != panthor_vm_root_gem(vm))) goto out_free_bo;
ret = panthor_vm_unmap_range(vm, bo->va_node.start, bo->va_node.size); if (ret) goto out_free_bo;
/** * panthor_kernel_bo_create() - Create and map a GEM object to a VM * @ptdev: Device. * @vm: VM to map the GEM to. If NULL, the kernel object is not GPU mapped. * @size: Size of the buffer object. * @bo_flags: Combination of drm_panthor_bo_flags flags. * @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those * that are related to map operations). * @gpu_va: GPU address assigned when mapping to the VM. * If gpu_va == PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be * automatically allocated. * @name: Descriptive label of the BO's contents * * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
*/ struct panthor_kernel_bo *
panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
size_t size, u32 bo_flags, u32 vm_map_flags,
u64 gpu_va, constchar *name)
{ struct drm_gem_shmem_object *obj; struct panthor_kernel_bo *kbo; struct panthor_gem_object *bo;
u32 debug_flags = PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL; int ret;
if (drm_WARN_ON(&ptdev->base, !vm)) return ERR_PTR(-EINVAL);
kbo = kzalloc(sizeof(*kbo), GFP_KERNEL); if (!kbo) return ERR_PTR(-ENOMEM);
obj = drm_gem_shmem_create(&ptdev->base, size); if (IS_ERR(obj)) {
ret = PTR_ERR(obj); goto err_free_bo;
}
bo = to_panthor_bo(&obj->base);
kbo->obj = &obj->base;
bo->flags = bo_flags;
if (vm == panthor_fw_vm(ptdev))
debug_flags |= PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED;
/* The system and GPU MMU page size might differ, which becomes a * problem for FW sections that need to be mapped at explicit address * since our PAGE_SIZE alignment might cover a VA range that's * expected to be used for another section. * Make sure we never map more than we need.
*/
size = ALIGN(size, panthor_vm_page_size(vm));
ret = panthor_vm_alloc_va(vm, gpu_va, size, &kbo->va_node); if (ret) goto err_put_obj;
ret = panthor_vm_map_bo_range(vm, bo, 0, size, kbo->va_node.start, vm_map_flags); if (ret) goto err_free_va;
staticstruct dma_buf *
panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
{ /* We can't export GEMs that have an exclusive VM. */ if (to_panthor_bo(obj)->exclusive_vm_root_gem) return ERR_PTR(-EINVAL);
/** * panthor_gem_create_with_handle() - Create a GEM object and attach it to a handle. * @file: DRM file. * @ddev: DRM device. * @exclusive_vm: Exclusive VM. Not NULL if the GEM object can't be shared. * @size: Size of the GEM object to allocate. * @flags: Combination of drm_panthor_bo_flags flags. * @handle: Pointer holding the handle pointing to the new GEM object. * * Return: Zero on success
*/ int
panthor_gem_create_with_handle(struct drm_file *file, struct drm_device *ddev, struct panthor_vm *exclusive_vm,
u64 *size, u32 flags, u32 *handle)
{ int ret; struct drm_gem_shmem_object *shmem; struct panthor_gem_object *bo;
shmem = drm_gem_shmem_create(ddev, *size); if (IS_ERR(shmem)) return PTR_ERR(shmem);
bo = to_panthor_bo(&shmem->base);
bo->flags = flags;
/* If this is a write-combine mapping, we query the sgt to force a CPU * cache flush (dma_map_sgtable() is called when the sgt is created). * This ensures the zero-ing is visible to any uncached mapping created * by vmap/mmap. * FIXME: Ideally this should be done when pages are allocated, not at * BO creation time.
*/ if (shmem->map_wc) { struct sg_table *sgt;
sgt = drm_gem_shmem_get_pages_sgt(shmem); if (IS_ERR(sgt)) {
ret = PTR_ERR(sgt); goto out_put_gem;
}
}
/* * Allocate an id of idr table where the obj is registered * and handle has the id what user can see.
*/
ret = drm_gem_handle_create(file, &shmem->base, handle); if (!ret)
*size = bo->base.base.size;
out_put_gem: /* drop reference from allocate - handle holds it now. */
drm_gem_object_put(&shmem->base);
/* We should never attempt labelling a UM-exposed GEM object */ if (drm_WARN_ON(bo->obj->dev, bo->obj->handle_count > 0)) return;
if (!label) return;
str = kstrdup_const(label, GFP_KERNEL); if (!str) { /* Failing to allocate memory for a label isn't a fatal condition */
drm_warn(bo->obj->dev, "Not enough memory to allocate BO label"); return;
}
seq_puts(m, "GEM state flags: "); for (i = 0, len = ARRAY_SIZE(gem_state_flags_names); i < len; i++) { if (!gem_state_flags_names[i]) continue;
seq_printf(m, "%s (0x%x)%s", gem_state_flags_names[i],
(u32)BIT(i), (i < len - 1) ? ", " : "\n");
}
seq_puts(m, "GEM usage flags: "); for (i = 0, len = ARRAY_SIZE(gem_usage_flags_names); i < len; i++) { if (!gem_usage_flags_names[i]) continue;
seq_printf(m, "%s (0x%x)%s", gem_usage_flags_names[i],
(u32)BIT(i), (i < len - 1) ? ", " : "\n\n");
}
}
if (bo->base.base.import_attach)
gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_IMPORTED; if (bo->base.base.dma_buf)
gem_state_flags |= PANTHOR_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.