--- zzzz-none-000/linux-4.4.271/drivers/iommu/io-pgtable.h 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/drivers/iommu/io-pgtable.h 2023-04-19 10:22:28.000000000 +0000 @@ -1,5 +1,8 @@ #ifndef __IO_PGTABLE_H #define __IO_PGTABLE_H +#include + +#include /* * Public API for use by IOMMU drivers @@ -9,6 +12,8 @@ ARM_32_LPAE_S2, ARM_64_LPAE_S1, ARM_64_LPAE_S2, + ARM_V7S, + ARM_V8L_FAST, IO_PGTABLE_NUM_FMTS, }; @@ -18,34 +23,36 @@ * @tlb_flush_all: Synchronously invalidate the entire TLB context. * @tlb_add_flush: Queue up a TLB invalidation for a virtual address range. * @tlb_sync: Ensure any queued TLB invalidation has taken effect, and - * any corresponding page table updates are visible to the - * IOMMU. + * any corresponding page table updates are visible to the + * IOMMU. * * Note that these can all be called in atomic context and must therefore * not block. */ struct iommu_gather_ops { void (*tlb_flush_all)(void *cookie); - void (*tlb_add_flush)(unsigned long iova, size_t size, bool leaf, - void *cookie); + void (*tlb_add_flush)(unsigned long iova, size_t size, size_t granule, + bool leaf, void *cookie); void (*tlb_sync)(void *cookie); }; /** * struct io_pgtable_cfg - Configuration data for a set of page tables. * - * @quirks: A bitmap of hardware quirks that require some special - * action by the low-level page table allocator. + * @quirks: A bitmap of hardware quirks that require some special + * action by the low-level page table allocator. * @pgsize_bitmap: A bitmap of page sizes supported by this set of page - * tables. - * @ias: Input address (iova) size, in bits. - * @oas: Output address (paddr) size, in bits. - * @tlb: TLB management callbacks for this set of tables. + * tables. + * @ias: Input address (iova) size, in bits. + * @oas: Output address (paddr) size, in bits. + * @tlb: TLB management callbacks for this set of tables. * @iommu_dev: The device representing the DMA configuration for the - * page table walker. + * page table walker. */ struct io_pgtable_cfg { - #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */ + #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) /* Set NS bit in PTEs */ + #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) /* No AP/XN bits */ + #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2) /* TLB Inv. on map */ int quirks; unsigned long pgsize_bitmap; unsigned int ias; @@ -65,6 +72,19 @@ u64 vttbr; u64 vtcr; } arm_lpae_s2_cfg; + + struct { + u32 ttbr[2]; + u32 tcr; + u32 nmrr; + u32 prrr; + } arm_v7s_cfg; + struct { + u64 ttbr[2]; + u64 tcr; + u64 mair[2]; + void *pmds; + } av8l_fast_cfg; }; }; @@ -72,6 +92,9 @@ * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers. * * @map: Map a physically contiguous memory region. + * @map_sg: Map a scatterlist. Returns the number of bytes mapped, + * or 0 on failure. The size parameter contains the size + * of the partial mapping in case of failure. * @unmap: Unmap a physically contiguous memory region. * @iova_to_phys: Translate iova to physical address. * @@ -81,7 +104,10 @@ struct io_pgtable_ops { int (*map)(struct io_pgtable_ops *ops, unsigned long iova, phys_addr_t paddr, size_t size, int prot); - int (*unmap)(struct io_pgtable_ops *ops, unsigned long iova, + int (*map_sg)(struct io_pgtable_ops *ops, unsigned long iova, + struct scatterlist *sg, unsigned int nents, + int prot, size_t *size); + size_t (*unmap)(struct io_pgtable_ops *ops, unsigned long iova, size_t size); phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops, unsigned long iova); @@ -92,10 +118,10 @@ * * @fmt: The page table format. * @cfg: The page table configuration. This will be modified to represent - * the configuration actually provided by the allocator (e.g. the - * pgsize_bitmap may be restricted). + * the configuration actually provided by the allocator (e.g. the + * pgsize_bitmap may be restricted). * @cookie: An opaque token provided by the IOMMU driver and passed back to - * the callback routines in cfg->tlb. + * the callback routines in cfg->tlb. */ struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt, struct io_pgtable_cfg *cfg, @@ -103,8 +129,8 @@ /** * free_io_pgtable_ops() - Free an io_pgtable_ops structure. The caller - * *must* ensure that the page table is no longer - * live, but the TLB can be dirty. + * *must* ensure that the page table is no longer + * live, but the TLB can be dirty. * * @ops: The ops returned from alloc_io_pgtable_ops. */ @@ -120,7 +146,7 @@ * * @fmt: The page table format. * @cookie: An opaque token provided by the IOMMU driver and passed back to - * any callback routines. + * any callback routines. * @cfg: A copy of the page table configuration. * @ops: The page table operations in use for this set of page tables. */ @@ -133,7 +159,7 @@ /** * struct io_pgtable_init_fns - Alloc/free a set of page tables for a - * particular format. + * particular format. * * @alloc: Allocate a set of page tables described by cfg. * @free: Free the page tables associated with iop. @@ -147,5 +173,7 @@ extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s2_init_fns; extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns; extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns; +extern struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns; +extern struct io_pgtable_init_fns io_pgtable_av8l_fast_init_fns; #endif /* __IO_PGTABLE_H */