123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #ifndef __IO_PGTABLE_H
- #define __IO_PGTABLE_H
- #include <linux/bitops.h>
- enum io_pgtable_fmt {
- ARM_32_LPAE_S1,
- ARM_32_LPAE_S2,
- ARM_64_LPAE_S1,
- ARM_64_LPAE_S2,
- ARM_V7S,
- IO_PGTABLE_NUM_FMTS,
- };
- struct iommu_gather_ops {
- void (*tlb_flush_all)(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 {
-
- #define IO_PGTABLE_QUIRK_ARM_NS BIT(0)
- #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1)
- #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2)
- #define IO_PGTABLE_QUIRK_ARM_MTK_4GB BIT(3)
- unsigned long quirks;
- unsigned long pgsize_bitmap;
- unsigned int ias;
- unsigned int oas;
- const struct iommu_gather_ops *tlb;
- struct device *iommu_dev;
-
- union {
- struct {
- u64 ttbr[2];
- u64 tcr;
- u64 mair[2];
- } arm_lpae_s1_cfg;
- struct {
- u64 vttbr;
- u64 vtcr;
- } arm_lpae_s2_cfg;
- struct {
- u32 ttbr[2];
- u32 tcr;
- u32 nmrr;
- u32 prrr;
- } arm_v7s_cfg;
- };
- };
- 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,
- size_t size);
- phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
- unsigned long iova);
- };
- struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
- struct io_pgtable_cfg *cfg,
- void *cookie);
- void free_io_pgtable_ops(struct io_pgtable_ops *ops);
- struct io_pgtable {
- enum io_pgtable_fmt fmt;
- void *cookie;
- bool tlb_sync_pending;
- struct io_pgtable_cfg cfg;
- struct io_pgtable_ops ops;
- };
- #define io_pgtable_ops_to_pgtable(x) container_of((x), struct io_pgtable, ops)
- static inline void io_pgtable_tlb_flush_all(struct io_pgtable *iop)
- {
- iop->cfg.tlb->tlb_flush_all(iop->cookie);
- iop->tlb_sync_pending = true;
- }
- static inline void io_pgtable_tlb_add_flush(struct io_pgtable *iop,
- unsigned long iova, size_t size, size_t granule, bool leaf)
- {
- iop->cfg.tlb->tlb_add_flush(iova, size, granule, leaf, iop->cookie);
- iop->tlb_sync_pending = true;
- }
- static inline void io_pgtable_tlb_sync(struct io_pgtable *iop)
- {
- if (iop->tlb_sync_pending) {
- iop->cfg.tlb->tlb_sync(iop->cookie);
- iop->tlb_sync_pending = false;
- }
- }
- struct io_pgtable_init_fns {
- struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
- void (*free)(struct io_pgtable *iop);
- };
- extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s1_init_fns;
- 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;
- #endif
|