Lines Matching refs:lvl

51 #define _ARM_V7S_LVL_BITS(lvl, cfg)	((lvl) == 1 ? ((cfg)->ias - 20) : 8)
52 #define ARM_V7S_LVL_SHIFT(lvl) ((lvl) == 1 ? 20 : 12)
55 #define ARM_V7S_PTES_PER_LVL(lvl, cfg) (1 << _ARM_V7S_LVL_BITS(lvl, cfg))
56 #define ARM_V7S_TABLE_SIZE(lvl, cfg) \
57 (ARM_V7S_PTES_PER_LVL(lvl, cfg) * sizeof(arm_v7s_iopte))
59 #define ARM_V7S_BLOCK_SIZE(lvl) (1UL << ARM_V7S_LVL_SHIFT(lvl))
60 #define ARM_V7S_LVL_MASK(lvl) ((u32)(~0U << ARM_V7S_LVL_SHIFT(lvl)))
62 #define _ARM_V7S_IDX_MASK(lvl, cfg) (ARM_V7S_PTES_PER_LVL(lvl, cfg) - 1)
63 #define ARM_V7S_LVL_IDX(addr, lvl, cfg) ({ \
64 int _l = lvl; \
84 #define ARM_V7S_PTE_IS_TABLE(pte, lvl) \
85 ((lvl) == 1 && (((pte) & 0x3) == ARM_V7S_PTE_TYPE_TABLE))
88 #define ARM_V7S_ATTR_XN(lvl) BIT(4 * (2 - (lvl)))
102 #define ARM_V7S_ATTR_SHIFT(lvl) (16 - (lvl) * 6)
172 static bool arm_v7s_pte_is_cont(arm_v7s_iopte pte, int lvl);
196 static arm_v7s_iopte paddr_to_iopte(phys_addr_t paddr, int lvl,
199 arm_v7s_iopte pte = paddr & ARM_V7S_LVL_MASK(lvl);
207 static phys_addr_t iopte_to_paddr(arm_v7s_iopte pte, int lvl,
213 if (ARM_V7S_PTE_IS_TABLE(pte, lvl))
215 else if (arm_v7s_pte_is_cont(pte, lvl))
216 mask = ARM_V7S_LVL_MASK(lvl) * ARM_V7S_CONT_PAGES;
218 mask = ARM_V7S_LVL_MASK(lvl);
233 static arm_v7s_iopte *iopte_deref(arm_v7s_iopte pte, int lvl,
236 return phys_to_virt(iopte_to_paddr(pte, lvl, &data->iop.cfg));
239 static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
246 size_t size = ARM_V7S_TABLE_SIZE(lvl, cfg);
257 if (lvl == 1)
259 else if (lvl == 2)
284 if (lvl == 2)
292 if (lvl == 1)
299 static void __arm_v7s_free_table(void *table, int lvl,
304 size_t size = ARM_V7S_TABLE_SIZE(lvl, cfg);
309 if (lvl == 1)
335 static arm_v7s_iopte arm_v7s_prot_to_pte(int prot, int lvl,
350 pte <<= ARM_V7S_ATTR_SHIFT(lvl);
353 pte |= ARM_V7S_ATTR_XN(lvl);
360 if (lvl == 1 && (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS))
366 static int arm_v7s_pte_to_prot(arm_v7s_iopte pte, int lvl)
369 arm_v7s_iopte attr = pte >> ARM_V7S_ATTR_SHIFT(lvl);
379 if (pte & ARM_V7S_ATTR_XN(lvl))
385 static arm_v7s_iopte arm_v7s_pte_to_cont(arm_v7s_iopte pte, int lvl)
387 if (lvl == 1) {
389 } else if (lvl == 2) {
390 arm_v7s_iopte xn = pte & ARM_V7S_ATTR_XN(lvl);
401 static arm_v7s_iopte arm_v7s_cont_to_pte(arm_v7s_iopte pte, int lvl)
403 if (lvl == 1) {
405 } else if (lvl == 2) {
418 static bool arm_v7s_pte_is_cont(arm_v7s_iopte pte, int lvl)
420 if (lvl == 1 && !ARM_V7S_PTE_IS_TABLE(pte, lvl))
422 else if (lvl == 2)
433 int lvl, int num_entries, arm_v7s_iopte *ptep)
440 if (ARM_V7S_PTE_IS_TABLE(ptep[i], lvl)) {
446 size_t sz = ARM_V7S_BLOCK_SIZE(lvl);
448 tblp = ptep - ARM_V7S_LVL_IDX(iova, lvl, cfg);
450 sz, lvl, tblp) != sz))
458 pte = arm_v7s_prot_to_pte(prot, lvl, cfg);
460 pte = arm_v7s_pte_to_cont(pte, lvl);
462 pte |= paddr_to_iopte(paddr, lvl, cfg);
499 int lvl, arm_v7s_iopte *ptep, gfp_t gfp)
503 int num_entries = size >> ARM_V7S_LVL_SHIFT(lvl);
506 ptep += ARM_V7S_LVL_IDX(iova, lvl, cfg);
511 lvl, num_entries, ptep);
514 if (WARN_ON(lvl == 2))
520 cptep = __arm_v7s_alloc_table(lvl + 1, gfp, data);
526 __arm_v7s_free_table(cptep, lvl + 1, data);
532 if (ARM_V7S_PTE_IS_TABLE(pte, lvl)) {
533 cptep = iopte_deref(pte, lvl, data);
541 return __arm_v7s_map(data, iova, paddr, size, prot, lvl + 1, cptep, gfp);
596 unsigned long iova, int idx, int lvl,
601 size_t size = ARM_V7S_BLOCK_SIZE(lvl);
606 if (!arm_v7s_pte_is_cont(pte, lvl))
610 pte = arm_v7s_cont_to_pte(pte, lvl);
668 unsigned long iova, size_t size, int lvl,
673 int idx, i = 0, num_entries = size >> ARM_V7S_LVL_SHIFT(lvl);
676 if (WARN_ON(lvl > 2))
679 idx = ARM_V7S_LVL_IDX(iova, lvl, &iop->cfg);
697 if (num_entries <= 1 && arm_v7s_pte_is_cont(pte[0], lvl)) {
701 pte[0] = arm_v7s_split_cont(data, iova, idx, lvl, ptep);
707 size_t blk_size = ARM_V7S_BLOCK_SIZE(lvl);
712 if (ARM_V7S_PTE_IS_TABLE(pte[i], lvl)) {
715 ARM_V7S_BLOCK_SIZE(lvl + 1));
716 ptep = iopte_deref(pte[i], lvl, data);
717 __arm_v7s_free_table(ptep, lvl + 1, data);
724 } else if (lvl == 1 && !ARM_V7S_PTE_IS_TABLE(pte[0], lvl)) {
734 ptep = iopte_deref(pte[0], lvl, data);
735 return __arm_v7s_unmap(data, gather, iova, size, lvl + 1, ptep);
765 int lvl = 0;
769 ptep += ARM_V7S_LVL_IDX(iova, ++lvl, &data->iop.cfg);
771 ptep = iopte_deref(pte, lvl, data);
772 } while (ARM_V7S_PTE_IS_TABLE(pte, lvl));
777 mask = ARM_V7S_LVL_MASK(lvl);
778 if (arm_v7s_pte_is_cont(pte, lvl))
780 return iopte_to_paddr(pte, lvl, &data->iop.cfg) | (iova & ~mask);