| 148 | } |
| 149 | |
| 150 | void |
| 151 | vm_ksubmap_init(struct kva_md_info *kmi) |
| 152 | { |
| 153 | vm_offset_t firstaddr; |
| 154 | caddr_t v; |
| 155 | vm_size_t size = 0; |
| 156 | long physmem_est; |
| 157 | vm_offset_t minaddr; |
| 158 | vm_offset_t maxaddr; |
| 159 | |
| 160 | /* |
| 161 | * Allocate space for system data structures. |
| 162 | * The first available kernel virtual address is in "v". |
| 163 | * As pages of kernel virtual memory are allocated, "v" is incremented. |
| 164 | * As pages of memory are allocated and cleared, |
| 165 | * "firstaddr" is incremented. |
| 166 | */ |
| 167 | |
| 168 | /* |
| 169 | * Make two passes. The first pass calculates how much memory is |
| 170 | * needed and allocates it. The second pass assigns virtual |
| 171 | * addresses to the various data structures. |
| 172 | */ |
| 173 | firstaddr = 0; |
| 174 | again: |
| 175 | v = (caddr_t)firstaddr; |
| 176 | |
| 177 | /* |
| 178 | * Discount the physical memory larger than the size of kernel_map |
| 179 | * to avoid eating up all of KVA space. |
| 180 | */ |
| 181 | physmem_est = lmin(physmem, btoc(vm_map_max(kernel_map) - |
| 182 | vm_map_min(kernel_map))); |
| 183 | |
| 184 | v = kern_vfs_bio_buffer_alloc(v, physmem_est); |
| 185 | |
| 186 | /* |
| 187 | * End of first pass, size has been calculated so allocate memory |
| 188 | */ |
| 189 | if (firstaddr == 0) { |
| 190 | size = (vm_size_t)v; |
| 191 | #ifdef VM_FREELIST_DMA32 |
| 192 | /* |
| 193 | * Try to protect 32-bit DMAable memory from the largest |
| 194 | * early alloc of wired mem. |
| 195 | */ |
| 196 | firstaddr = kmem_alloc_attr(size, M_ZERO | M_NOWAIT, |
| 197 | (vm_paddr_t)1 << 32, ~(vm_paddr_t)0, VM_MEMATTR_DEFAULT); |
| 198 | if (firstaddr == 0) |
| 199 | #endif |
| 200 | firstaddr = kmem_malloc(size, M_ZERO | M_WAITOK); |
| 201 | if (firstaddr == 0) |
| 202 | panic("startup: no room for tables"); |
| 203 | goto again; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * End of second pass, addresses have been assigned |
no test coverage detected