* Find a best fit mgaw for the given maxaddr: * - if allow_less is false, must find sagaw which maps all requested * addresses (used by identity mappings); * - if allow_less is true, and no supported sagaw can map all requested * address space, accept the biggest sagaw, whatever is it. */
| 148 | * address space, accept the biggest sagaw, whatever is it. |
| 149 | */ |
| 150 | int |
| 151 | dmar_maxaddr2mgaw(struct dmar_unit *unit, iommu_gaddr_t maxaddr, bool allow_less) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | for (i = 0; i < nitems(sagaw_bits); i++) { |
| 156 | if ((1ULL << sagaw_bits[i].agaw) >= maxaddr && |
| 157 | (DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) != 0) |
| 158 | break; |
| 159 | } |
| 160 | if (allow_less && i == nitems(sagaw_bits)) { |
| 161 | do { |
| 162 | i--; |
| 163 | } while ((DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) |
| 164 | == 0); |
| 165 | } |
| 166 | if (i < nitems(sagaw_bits)) |
| 167 | return (sagaw_bits[i].agaw); |
| 168 | KASSERT(0, ("no mgaw for maxaddr %jx allow_less %d", |
| 169 | (uintmax_t) maxaddr, allow_less)); |
| 170 | return (-1); |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Calculate the total amount of page table pages needed to map the |