xref: /linux/drivers/gpu/drm/imagination/pvr_vm.h (revision 79d2e1919a2728ef49d938eb20ebd5903c14dfb0)
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 /* Copyright (c) 2023 Imagination Technologies Ltd. */
3 
4 #ifndef PVR_VM_H
5 #define PVR_VM_H
6 
7 #include "pvr_rogue_mmu_defs.h"
8 
9 #include <uapi/drm/pvr_drm.h>
10 
11 #include <linux/types.h>
12 
13 /* Forward declaration from "pvr_device.h" */
14 struct pvr_device;
15 struct pvr_file;
16 
17 /* Forward declaration from "pvr_gem.h" */
18 struct pvr_gem_object;
19 
20 /* Forward declaration from "pvr_vm.c" */
21 struct pvr_vm_context;
22 
23 /* Forward declaration from <uapi/drm/pvr_drm.h> */
24 struct drm_pvr_ioctl_get_heap_info_args;
25 
26 /* Forward declaration from <drm/drm_exec.h> */
27 struct drm_exec;
28 
29 /* Functions defined in pvr_vm.c */
30 
31 bool pvr_device_addr_is_valid(u64 device_addr);
32 bool pvr_device_addr_and_size_are_valid(struct pvr_vm_context *vm_ctx,
33 					u64 device_addr, u64 size);
34 
35 struct pvr_vm_context *pvr_vm_create_context(struct pvr_device *pvr_dev,
36 					     bool is_userspace_context);
37 
38 int pvr_vm_map(struct pvr_vm_context *vm_ctx,
39 	       struct pvr_gem_object *pvr_obj, u64 pvr_obj_offset,
40 	       u64 device_addr, u64 size);
41 int pvr_vm_unmap(struct pvr_vm_context *vm_ctx, u64 device_addr, u64 size);
42 void pvr_vm_unmap_all(struct pvr_vm_context *vm_ctx);
43 
44 dma_addr_t pvr_vm_get_page_table_root_addr(struct pvr_vm_context *vm_ctx);
45 struct dma_resv *pvr_vm_get_dma_resv(struct pvr_vm_context *vm_ctx);
46 
47 int pvr_static_data_areas_get(const struct pvr_device *pvr_dev,
48 			      struct drm_pvr_ioctl_dev_query_args *args);
49 int pvr_heap_info_get(const struct pvr_device *pvr_dev,
50 		      struct drm_pvr_ioctl_dev_query_args *args);
51 const struct drm_pvr_heap *pvr_find_heap_containing(struct pvr_device *pvr_dev,
52 						    u64 addr, u64 size);
53 
54 struct pvr_gem_object *pvr_vm_find_gem_object(struct pvr_vm_context *vm_ctx,
55 					      u64 device_addr,
56 					      u64 *mapped_offset_out,
57 					      u64 *mapped_size_out);
58 
59 struct pvr_fw_object *
60 pvr_vm_get_fw_mem_context(struct pvr_vm_context *vm_ctx);
61 
62 struct pvr_vm_context *pvr_vm_context_lookup(struct pvr_file *pvr_file, u32 handle);
63 struct pvr_vm_context *pvr_vm_context_get(struct pvr_vm_context *vm_ctx);
64 bool pvr_vm_context_put(struct pvr_vm_context *vm_ctx);
65 void pvr_destroy_vm_contexts_for_file(struct pvr_file *pvr_file);
66 
67 #endif /* PVR_VM_H */
68