| 4581 | } |
| 4582 | |
| 4583 | static vm_page_t |
| 4584 | pmap_allocpte(pmap_t pmap, vm_offset_t va, struct rwlock **lockp) |
| 4585 | { |
| 4586 | vm_pindex_t ptepindex; |
| 4587 | pd_entry_t *pd, PG_V; |
| 4588 | vm_page_t m; |
| 4589 | |
| 4590 | PG_V = pmap_valid_bit(pmap); |
| 4591 | |
| 4592 | /* |
| 4593 | * Calculate pagetable page index |
| 4594 | */ |
| 4595 | ptepindex = pmap_pde_pindex(va); |
| 4596 | retry: |
| 4597 | /* |
| 4598 | * Get the page directory entry |
| 4599 | */ |
| 4600 | pd = pmap_pde(pmap, va); |
| 4601 | |
| 4602 | /* |
| 4603 | * This supports switching from a 2MB page to a |
| 4604 | * normal 4K page. |
| 4605 | */ |
| 4606 | if (pd != NULL && (*pd & (PG_PS | PG_V)) == (PG_PS | PG_V)) { |
| 4607 | if (!pmap_demote_pde_locked(pmap, pd, va, lockp)) { |
| 4608 | /* |
| 4609 | * Invalidation of the 2MB page mapping may have caused |
| 4610 | * the deallocation of the underlying PD page. |
| 4611 | */ |
| 4612 | pd = NULL; |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | /* |
| 4617 | * If the page table page is mapped, we just increment the |
| 4618 | * hold count, and activate it. |
| 4619 | */ |
| 4620 | if (pd != NULL && (*pd & PG_V) != 0) { |
| 4621 | m = PHYS_TO_VM_PAGE(*pd & PG_FRAME); |
| 4622 | m->ref_count++; |
| 4623 | } else { |
| 4624 | /* |
| 4625 | * Here if the pte page isn't mapped, or if it has been |
| 4626 | * deallocated. |
| 4627 | */ |
| 4628 | m = pmap_allocpte_alloc(pmap, ptepindex, lockp, va); |
| 4629 | if (m == NULL && lockp != NULL) |
| 4630 | goto retry; |
| 4631 | } |
| 4632 | return (m); |
| 4633 | } |
| 4634 | |
| 4635 | /*************************************************** |
| 4636 | * Pmap allocation/deallocation routines. |
no test coverage detected