1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 /* Copyright (c) 2023 Imagination Technologies Ltd. */
7 #include <linux/memory.h>
8 #include <linux/types.h>
10 /* Forward declaration from "pvr_device.h" */
13 /* Forward declaration from "pvr_mmu.c" */
14 struct pvr_mmu_context;
15 struct pvr_mmu_op_context;
17 /* Forward declaration from "pvr_vm.c" */
18 struct pvr_vm_context;
20 /* Forward declaration from <linux/scatterlist.h> */
24 * DOC: Public API (constants)
26 * .. c:macro:: PVR_DEVICE_PAGE_SIZE
28 * Fixed page size referenced by leaf nodes in the page table tree
29 * structure. In the current implementation, this value is pegged to the
30 * CPU page size (%PAGE_SIZE). It is therefore an error to specify a CPU
31 * page size which is not also a supported device page size. The supported
32 * device page sizes are: 4KiB, 16KiB, 64KiB, 256KiB, 1MiB and 2MiB.
34 * .. c:macro:: PVR_DEVICE_PAGE_SHIFT
36 * Shift value used to efficiently multiply or divide by
37 * %PVR_DEVICE_PAGE_SIZE.
39 * This value is derived from %PVR_DEVICE_PAGE_SIZE.
41 * .. c:macro:: PVR_DEVICE_PAGE_MASK
43 * Mask used to round a value down to the nearest multiple of
44 * %PVR_DEVICE_PAGE_SIZE. When bitwise negated, it will indicate whether a
45 * value is already a multiple of %PVR_DEVICE_PAGE_SIZE.
47 * This value is derived from %PVR_DEVICE_PAGE_SIZE.
50 /* PVR_DEVICE_PAGE_SIZE determines the page size */
51 #define PVR_DEVICE_PAGE_SIZE (PAGE_SIZE)
52 #define PVR_DEVICE_PAGE_SHIFT (PAGE_SHIFT)
53 #define PVR_DEVICE_PAGE_MASK (PAGE_MASK)
56 * DOC: Page table index utilities (constants)
58 * .. c:macro:: PVR_PAGE_TABLE_ADDR_SPACE_SIZE
60 * Size of device-virtual address space which can be represented in the page
63 * This value is checked at runtime against
64 * &pvr_device_features.virtual_address_space_bits by
65 * pvr_vm_create_context(), which will return an error if the feature value
66 * does not match this constant.
68 * .. admonition:: Future work
70 * It should be possible to support other values of
71 * &pvr_device_features.virtual_address_space_bits, but so far no
72 * hardware has been created which advertises an unsupported value.
74 * .. c:macro:: PVR_PAGE_TABLE_ADDR_BITS
76 * Number of bits needed to represent any value less than
77 * %PVR_PAGE_TABLE_ADDR_SPACE_SIZE exactly.
79 * .. c:macro:: PVR_PAGE_TABLE_ADDR_MASK
81 * Bitmask of device-virtual addresses which are valid in the page table
84 * This value is derived from %PVR_PAGE_TABLE_ADDR_SPACE_SIZE, so the same
85 * notes on that constant apply here.
87 #define PVR_PAGE_TABLE_ADDR_SPACE_SIZE SZ_1T
88 #define PVR_PAGE_TABLE_ADDR_BITS __ffs(PVR_PAGE_TABLE_ADDR_SPACE_SIZE)
89 #define PVR_PAGE_TABLE_ADDR_MASK (PVR_PAGE_TABLE_ADDR_SPACE_SIZE - 1)
91 void pvr_mmu_flush_request_all(struct pvr_device *pvr_dev);
92 int pvr_mmu_flush_exec(struct pvr_device *pvr_dev, bool wait);
94 struct pvr_mmu_context *pvr_mmu_context_create(struct pvr_device *pvr_dev);
95 void pvr_mmu_context_destroy(struct pvr_mmu_context *ctx);
97 dma_addr_t pvr_mmu_get_root_table_dma_addr(struct pvr_mmu_context *ctx);
99 void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx);
100 struct pvr_mmu_op_context *
101 pvr_mmu_op_context_create(struct pvr_mmu_context *ctx,
102 struct sg_table *sgt, u64 sgt_offset, u64 size);
104 int pvr_mmu_map(struct pvr_mmu_op_context *op_ctx, u64 size, u64 flags,
106 int pvr_mmu_unmap(struct pvr_mmu_op_context *op_ctx, u64 device_addr, u64 size);
108 #endif /* PVR_MMU_H */