ae115bc77f6fcde83175c75b4206dc2e50747966mrj * CDDL HEADER START
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The contents of this file are subject to the terms of the
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Common Development and Distribution License (the "License").
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * You may not use this file except in compliance with the License.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * See the License for the specific language governing permissions
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * and limitations under the License.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * When distributing Covered Code, include this CDDL HEADER in each
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * If applicable, add the following below this CDDL HEADER, with the
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * fields enclosed by brackets "[]" replaced with your own identifying
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * information: Portions Copyright [yyyy] [name of copyright owner]
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * CDDL HEADER END
613b28719c10e84c1202c1045df44d77767de21dRichard Bean * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Use is subject to license terms.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Joe's debug printing
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#define DBG(x) \
613b28719c10e84c1202c1045df44d77767de21dRichard Bean bop_printf(NULL, "kboot_mmu.c: %s is %" PRIx64 "\n", #x, (uint64_t)(x));
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Page table and memory stuff.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * this are needed by mmu_init()
ae115bc77f6fcde83175c75b4206dc2e50747966mrjint kbm_pae_support = 0; /* PAE is 64 bit Page table entries */
ae115bc77f6fcde83175c75b4206dc2e50747966mrjint kbm_pge_support = 0; /* PGE is Page table global bit enabled */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Initialize memory management parameters for boot time page table management
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * configure mmu information
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Change the addressible page table window to point at a given page
ae115bc77f6fcde83175c75b4206dc2e50747966mrj/*ARGSUSED*/
843e19887f64dde75055cf8842fc4db2171eff45johnlev x86pte_t pt_bits = PT_NOCONSIST | PT_VALID | PT_WRITABLE;
843e19887f64dde75055cf8842fc4db2171eff45johnlev pa_to_ma(physaddr) | pt_bits, UVMF_INVLPG | UVMF_LOCAL) < 0)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Add a mapping for the physical page at the given virtual address.
ae115bc77f6fcde83175c75b4206dc2e50747966mrjkbm_map(uintptr_t va, paddr_t pa, uint_t level, uint_t is_kernel)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj pteval = pa_to_ma(pa) | PT_NOCONSIST | PT_VALID | PT_WRITABLE;
843e19887f64dde75055cf8842fc4db2171eff45johnlev * try update_va_mapping first - fails if page table is missing.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Find the pte that will map this address. This creates any
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * missing intermediate level page tables.
843e19887f64dde75055cf8842fc4db2171eff45johnlev if (HYPERVISOR_update_va_mapping(va, pteval, UVMF_INVLPG | UVMF_LOCAL))
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Add a mapping for the machine page at the given virtual address.
843e19887f64dde75055cf8842fc4db2171eff45johnlev pteval = ma | PT_NOCONSIST | PT_VALID | PT_REF | PT_WRITABLE;
843e19887f64dde75055cf8842fc4db2171eff45johnlev * try update_va_mapping first - fails if page table is missing.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Find the pte that will map this address. This creates any
843e19887f64dde75055cf8842fc4db2171eff45johnlev * missing intermediate level page tables
843e19887f64dde75055cf8842fc4db2171eff45johnlev#endif /* __xpv */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Probe the boot time page tables to find the first mapping
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * including va (or higher) and return non-zero if one is found.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * va is updated to the starting address and len to the pagesize.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * pp will be set to point to the 1st page_t of the mapped page(s).
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Note that if va is in the middle of a large page, the returned va
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * will be less than what was asked for.
ae115bc77f6fcde83175c75b4206dc2e50747966mrjkbm_probe(uintptr_t *va, size_t *len, pfn_t *pfn, uint_t *prot)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj for (;;) {
ae115bc77f6fcde83175c75b4206dc2e50747966mrj return (0);
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * If we don't have a valid PTP/PTE at this level
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * then we can bump VA by this level's pagesize and try again.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * When the probe_va wraps around, we are done.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj return (0);
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * If this entry is a pointer to a lower level page table
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * go down to it.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * We found a boot level page table entry
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * pt_nx is cleared if processor doesn't support NX bit
ae115bc77f6fcde83175c75b4206dc2e50747966mrj return (1);
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Destroy a boot loader page table 4K mapping.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Change a boot loader page table 4K mapping.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Returns the pfn of the old mapping.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj x86pte_t pte_val = pa_to_ma(pfn_to_pa(pfn)) | PT_WRITABLE |
843e19887f64dde75055cf8842fc4db2171eff45johnlev if (HYPERVISOR_update_va_mapping(va, pte_val, UVMF_INVLPG | UVMF_LOCAL))
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Change a boot loader page table 4K mapping to read only.
843e19887f64dde75055cf8842fc4db2171eff45johnlev if (HYPERVISOR_update_va_mapping(va, pte_val, UVMF_INVLPG | UVMF_LOCAL))
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * interfaces for kernel debugger to access physical memory
843e19887f64dde75055cf8842fc4db2171eff45johnlev if (HYPERVISOR_update_va_mapping((uintptr_t)window, save_pte,
ae115bc77f6fcde83175c75b4206dc2e50747966mrjset_pteval(paddr_t table, uint_t index, uint_t level, x86pte_t pteval)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj new_table = do_bop_phys_alloc(MMU_PAGESIZE, MMU_PAGESIZE);
843e19887f64dde75055cf8842fc4db2171eff45johnlev /* Remove write permission to the new page table. */