* Add a hardware memory region. */
| 311 | * Add a hardware memory region. |
| 312 | */ |
| 313 | void |
| 314 | physmem_hardware_region(uint64_t pa, uint64_t sz) |
| 315 | { |
| 316 | vm_offset_t adj; |
| 317 | |
| 318 | /* |
| 319 | * Filter out the page at PA 0x00000000. The VM can't handle it, as |
| 320 | * pmap_extract() == 0 means failure. |
| 321 | */ |
| 322 | if (pa == 0) { |
| 323 | if (sz <= PAGE_SIZE) |
| 324 | return; |
| 325 | pa = PAGE_SIZE; |
| 326 | sz -= PAGE_SIZE; |
| 327 | } else if (pa > MAX_PHYS_ADDR) { |
| 328 | /* This range is past usable memory, ignore it */ |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Also filter out the page at the end of the physical address space -- |
| 334 | * if addr is non-zero and addr+size is zero we wrapped to the next byte |
| 335 | * beyond what vm_paddr_t can express. That leads to a NULL pointer |
| 336 | * deref early in startup; work around it by leaving the last page out. |
| 337 | * |
| 338 | * XXX This just in: subtract out a whole megabyte, not just 1 page. |
| 339 | * Reducing the size by anything less than 1MB results in the NULL |
| 340 | * pointer deref in _vm_map_lock_read(). Better to give up a megabyte |
| 341 | * than leave some folks with an unusable system while we investigate. |
| 342 | */ |
| 343 | if ((pa + sz) > (MAX_PHYS_ADDR - 1024 * 1024)) { |
| 344 | sz = MAX_PHYS_ADDR - pa + 1; |
| 345 | if (sz <= 1024 * 1024) |
| 346 | return; |
| 347 | sz -= 1024 * 1024; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Round the starting address up to a page boundary, and truncate the |
| 352 | * ending page down to a page boundary. |
| 353 | */ |
| 354 | adj = round_page(pa) - pa; |
| 355 | pa = round_page(pa); |
| 356 | sz = trunc_page(sz - adj); |
| 357 | |
| 358 | if (sz > 0 && hwcnt < nitems(hwregions)) |
| 359 | hwcnt = insert_region(hwregions, hwcnt, pa, sz, 0); |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Add an exclusion region. |
no test coverage detected