MCPcopy Create free account
hub / github.com/F-Stack/f-stack / smmu_init_strtab_2lvl

Function smmu_init_strtab_2lvl

freebsd/arm64/iommu/smmu.c:897–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

895}
896
897static int
898smmu_init_strtab_2lvl(struct smmu_softc *sc)
899{
900 struct smmu_strtab *strtab;
901 vm_paddr_t base;
902 uint64_t reg_base;
903 uint32_t l1size;
904 uint32_t size;
905 uint32_t reg;
906 int sz;
907
908 strtab = &sc->strtab;
909
910 size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3);
911 size = min(size, sc->sid_bits - STRTAB_SPLIT);
912 strtab->num_l1_entries = (1 << size);
913 size += STRTAB_SPLIT;
914
915 l1size = strtab->num_l1_entries * (STRTAB_L1_DESC_DWORDS << 3);
916
917 if (bootverbose)
918 device_printf(sc->dev,
919 "%s: size %d, l1 entries %d, l1size %d\n",
920 __func__, size, strtab->num_l1_entries, l1size);
921
922 strtab->vaddr = contigmalloc(l1size, M_SMMU,
923 M_WAITOK | M_ZERO, /* flags */
924 0, /* low */
925 (1ul << 48) - 1, /* high */
926 l1size, /* alignment */
927 0); /* boundary */
928 if (strtab->vaddr == NULL) {
929 device_printf(sc->dev, "Failed to allocate 2lvl strtab.\n");
930 return (ENOMEM);
931 }
932
933 sz = strtab->num_l1_entries * sizeof(struct l1_desc);
934
935 strtab->l1 = malloc(sz, M_SMMU, M_WAITOK | M_ZERO);
936 if (strtab->l1 == NULL) {
937 contigfree(strtab->vaddr, l1size, M_SMMU);
938 return (ENOMEM);
939 }
940
941 reg = STRTAB_BASE_CFG_FMT_2LVL;
942 reg |= size << STRTAB_BASE_CFG_LOG2SIZE_S;
943 reg |= STRTAB_SPLIT << STRTAB_BASE_CFG_SPLIT_S;
944 strtab->base_cfg = (uint32_t)reg;
945
946 base = vtophys(strtab->vaddr);
947
948 reg_base = base & STRTAB_BASE_ADDR_M;
949 KASSERT(reg_base == base, ("bad allocation 3"));
950 reg_base |= STRTAB_BASE_RA;
951 strtab->base = reg_base;
952
953 return (0);
954}

Callers 1

smmu_init_strtabFunction · 0.85

Calls 6

minFunction · 0.85
device_printfFunction · 0.85
contigmallocFunction · 0.85
mallocFunction · 0.85
contigfreeFunction · 0.85
ilog2Function · 0.70

Tested by

no test coverage detected