Lines Matching +full:early +full:- +full:to +full:- +full:mid
1 // SPDX-License-Identifier: GPL-2.0
4 * Xen leaves the responsibility for maintaining p2m mappings to the
8 * The logical flat p2m table is mapped to a linear kernel memory area.
9 * For accesses by Xen a three-level tree linked via mfns only is set up to
10 * allow the address space to be sparse.
22 * The p2m_top_mfn level is limited to 1 page, so the maximum representable
23 * pseudo-physical address space is:
27 * unsigned long (8 bytes on 64-bit, 4 bytes on 32), leading to
40 * We also have the possibility of setting 1-1 mappings on certain regions, so
44 * The benefit of this is, that we can assume for non-RAM regions (think
46 * get the PFN value to match the MFN.
48 * For this to work efficiently we have one new page p2m_identity. All entries
49 * in p2m_identity are set to INVALID_P2M_ENTRY type (Xen toolstack only
52 * On lookup we spot that the entry points to p2m_identity and return the
54 * If the entry points to an allocated page, we just proceed as before and
60 * non-identity pfn. To protect ourselves against we elect to set (and get) the
84 #include <xen/hvc-console.h>
86 #include "xen-ops.h"
121 * Used to set HYPERVISOR_shared_info->arch.max_pfn so the toolstack
122 * can avoid scanning the whole P2M (which may be sized to account for
154 static void p2m_mid_mfn_init(unsigned long *mid, unsigned long *leaf) in p2m_mid_mfn_init() argument
159 mid[i] = virt_to_mfn(leaf); in p2m_mid_mfn_init()
201 * - At boot time we're called rather early, and must use alloc_bootmem*()
202 * to allocate memory.
204 * - After resume we're called from within stop_machine, but the mfn
214 if (xen_start_info->flags & SIF_VIRT_P2M_4TOOLS) in xen_build_mfn_list_list()
217 /* Pre-initialize p2m_top_mfn to be completely missing */ in xen_build_mfn_list_list()
242 ptep = (pte_t *)((unsigned long)ptep & ~(PAGE_SIZE - 1)); in xen_build_mfn_list_list()
244 /* Don't bother allocating any mfn mid levels if in xen_build_mfn_list_list()
252 pfn += (P2M_MID_PER_PAGE - 1) * P2M_PER_PAGE; in xen_build_mfn_list_list()
272 if (xen_start_info->flags & SIF_VIRT_P2M_4TOOLS) in xen_setup_mfn_list_list()
273 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL; in xen_setup_mfn_list_list()
275 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = in xen_setup_mfn_list_list()
277 HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; in xen_setup_mfn_list_list()
278 HYPERVISOR_shared_info->arch.p2m_generation = 0; in xen_setup_mfn_list_list()
279 HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long)xen_p2m_addr; in xen_setup_mfn_list_list()
280 HYPERVISOR_shared_info->arch.p2m_cr3 = in xen_setup_mfn_list_list()
284 /* Set up p2m_top to point to the domain-builder provided p2m pages */
289 xen_p2m_addr = (unsigned long *)xen_start_info->mfn_list; in xen_build_dynamic_phys_to_machine()
290 xen_p2m_size = ALIGN(xen_start_info->nr_pages, P2M_PER_PAGE); in xen_build_dynamic_phys_to_machine()
292 for (pfn = xen_start_info->nr_pages; pfn < xen_p2m_size; pfn++) in xen_build_dynamic_phys_to_machine()
348 * Try to map missing/identity PMDs or p2m-pages if possible. in xen_rebuild_p2m_list()
349 * We have to respect the structure of the mfn_list_list in xen_rebuild_p2m_list()
351 * Chunk size to test is one p2m page if we are in the middle in xen_rebuild_p2m_list()
352 * of a mfn_list_list mid page and the complete mid page area in xen_rebuild_p2m_list()
353 * if we are at index 0 of the mid page. Please note that a in xen_rebuild_p2m_list()
354 * mid page might cover more than one PMD, e.g. on 32 bit PAE in xen_rebuild_p2m_list()
357 chunk = (pfn & (P2M_PER_PAGE * P2M_MID_PER_PAGE - 1)) ? in xen_rebuild_p2m_list()
367 /* Reset to minimal chunk size. */ in xen_rebuild_p2m_list()
381 /* Map complete missing or identity p2m-page. */ in xen_rebuild_p2m_list()
455 * a new pmd is to replace p2m_missing_pte or p2m_identity_pte by a individual
468 /* Do all allocations first to bail out in error case. */ in alloc_p2m_pmd()
472 for (i--; i >= 0; i--) in alloc_p2m_pmd()
479 vaddr = addr & ~(PMD_SIZE * PMDS_PER_MID_PAGE - 1); in alloc_p2m_pmd()
492 HYPERVISOR_shared_info->arch.p2m_generation++; in alloc_p2m_pmd()
497 HYPERVISOR_shared_info->arch.p2m_generation++; in alloc_p2m_pmd()
515 * Fully allocate the p2m structure for a given pfn. We need to check
516 * that both the top and mid levels are allocated, and make sure the
533 pte_pg = (pte_t *)((unsigned long)ptep & ~(PAGE_SIZE - 1)); in xen_alloc_p2m_entry()
539 return -ENOMEM; in xen_alloc_p2m_entry()
550 /* Separately check the mid mfn level */ in xen_alloc_p2m_entry()
556 return -ENOMEM; in xen_alloc_p2m_entry()
582 return -ENOMEM; in xen_alloc_p2m_entry()
587 p2m_init_identity(p2m, pfn & ~(P2M_PER_PAGE - 1)); in xen_alloc_p2m_entry()
592 HYPERVISOR_shared_info->arch.p2m_generation++; in xen_alloc_p2m_entry()
597 HYPERVISOR_shared_info->arch.p2m_generation++; in xen_alloc_p2m_entry()
612 HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; in xen_alloc_p2m_entry()
636 return pfn - pfn_s; in set_phys_range_identity()
704 /* Do not add to override if the map failed. */ in set_foreign_p2m_mapping()
748 * Pre-populate both status fields, to be recognizable in in set_foreign_p2m_mapping()
782 ret = -EINVAL; in clear_foreign_p2m_mapping()
791 /* Remapped non-RAM areas */
801 * Do the real remapping of non-RAM regions as specified in the
813 end_pfn = PFN_UP(remap->paddr + remap->size); in xen_do_remap_nonram()
814 pfn = PFN_DOWN(remap->paddr); in xen_do_remap_nonram()
815 mfn = PFN_DOWN(remap->maddr); in xen_do_remap_nonram()
818 panic("Failed to set p2m mapping for pfn=%lx mfn=%lx\n", in xen_do_remap_nonram()
829 pr_info("Remapped %u non-RAM page(s)\n", remapped); in xen_do_remap_nonram()
834 * Xen variant of acpi_os_ioremap() taking potentially remapped non-RAM
836 * Any attempt to map an area crossing a remap boundary will produce a
838 * phys is related to remap->maddr on input and will be rebased to remap->paddr.
847 if (phys + size > remap->maddr && in xen_acpi_os_ioremap()
848 phys < remap->maddr + remap->size) { in xen_acpi_os_ioremap()
849 WARN_ON(phys < remap->maddr || in xen_acpi_os_ioremap()
850 phys + size > remap->maddr + remap->size); in xen_acpi_os_ioremap()
851 phys += remap->paddr - remap->maddr; in xen_acpi_os_ioremap()
861 * Add a new non-RAM remap entry.
875 /* Switch to the Xen acpi_os_ioremap() variant. */ in xen_add_remap_nonram()
905 seq_printf(m, " [0x%lx->0x%lx] %s\n", first_pfn, pfn, in p2m_dump_show()
911 seq_printf(m, " [0x%lx->0x%lx] %s\n", first_pfn, pfn, in p2m_dump_show()