|
80 | 80 | #include <asm/xen/hypervisor.h>
|
81 | 81 | #include <xen/balloon.h>
|
82 | 82 | #include <xen/grant_table.h>
|
| 83 | +#include <xen/hvc-console.h> |
83 | 84 |
|
84 | 85 | #include "xen-ops.h"
|
85 | 86 |
|
@@ -792,6 +793,68 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
|
792 | 793 | return ret;
|
793 | 794 | }
|
794 | 795 |
|
| 796 | +/* Remapped non-RAM areas */ |
| 797 | +#define NR_NONRAM_REMAP 4 |
| 798 | +static struct nonram_remap { |
| 799 | + phys_addr_t maddr; |
| 800 | + phys_addr_t paddr; |
| 801 | + size_t size; |
| 802 | +} xen_nonram_remap[NR_NONRAM_REMAP] __ro_after_init; |
| 803 | +static unsigned int nr_nonram_remap __ro_after_init; |
| 804 | + |
| 805 | +/* |
| 806 | + * Do the real remapping of non-RAM regions as specified in the |
| 807 | + * xen_nonram_remap[] array. |
| 808 | + * In case of an error just crash the system. |
| 809 | + */ |
| 810 | +void __init xen_do_remap_nonram(void) |
| 811 | +{ |
| 812 | + unsigned int i; |
| 813 | + unsigned int remapped = 0; |
| 814 | + const struct nonram_remap *remap = xen_nonram_remap; |
| 815 | + unsigned long pfn, mfn, end_pfn; |
| 816 | + |
| 817 | + for (i = 0; i < nr_nonram_remap; i++) { |
| 818 | + end_pfn = PFN_UP(remap->paddr + remap->size); |
| 819 | + pfn = PFN_DOWN(remap->paddr); |
| 820 | + mfn = PFN_DOWN(remap->maddr); |
| 821 | + while (pfn < end_pfn) { |
| 822 | + if (!set_phys_to_machine(pfn, mfn)) |
| 823 | + panic("Failed to set p2m mapping for pfn=%lx mfn=%lx\n", |
| 824 | + pfn, mfn); |
| 825 | + |
| 826 | + pfn++; |
| 827 | + mfn++; |
| 828 | + remapped++; |
| 829 | + } |
| 830 | + |
| 831 | + remap++; |
| 832 | + } |
| 833 | + |
| 834 | + pr_info("Remapped %u non-RAM page(s)\n", remapped); |
| 835 | +} |
| 836 | + |
| 837 | +/* |
| 838 | + * Add a new non-RAM remap entry. |
| 839 | + * In case of no free entry found, just crash the system. |
| 840 | + */ |
| 841 | +void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr, |
| 842 | + unsigned long size) |
| 843 | +{ |
| 844 | + BUG_ON((maddr & ~PAGE_MASK) != (paddr & ~PAGE_MASK)); |
| 845 | + |
| 846 | + if (nr_nonram_remap == NR_NONRAM_REMAP) { |
| 847 | + xen_raw_console_write("Number of required E820 entry remapping actions exceed maximum value\n"); |
| 848 | + BUG(); |
| 849 | + } |
| 850 | + |
| 851 | + xen_nonram_remap[nr_nonram_remap].maddr = maddr; |
| 852 | + xen_nonram_remap[nr_nonram_remap].paddr = paddr; |
| 853 | + xen_nonram_remap[nr_nonram_remap].size = size; |
| 854 | + |
| 855 | + nr_nonram_remap++; |
| 856 | +} |
| 857 | + |
795 | 858 | #ifdef CONFIG_XEN_DEBUG_FS
|
796 | 859 | #include <linux/debugfs.h>
|
797 | 860 | static int p2m_dump_show(struct seq_file *m, void *v)
|
|
0 commit comments