pvr_mmu.h 3.6 KB

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