Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Machine specific setup for xen |
| 3 | * |
| 4 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/pm.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 11 | #include <linux/memblock.h> |
Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 12 | #include <linux/cpuidle.h> |
Konrad Rzeszutek Wilk | 48cdd82 | 2012-03-13 20:06:57 -0400 | [diff] [blame] | 13 | #include <linux/cpufreq.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/elf.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 16 | #include <asm/vdso.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 17 | #include <asm/e820.h> |
| 18 | #include <asm/setup.h> |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 19 | #include <asm/acpi.h> |
Konrad Rzeszutek Wilk | 8d54db79 | 2012-08-17 10:22:37 -0400 | [diff] [blame] | 20 | #include <asm/numa.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 21 | #include <asm/xen/hypervisor.h> |
| 22 | #include <asm/xen/hypercall.h> |
| 23 | |
Ian Campbell | 45263cb | 2010-10-25 16:32:29 -0700 | [diff] [blame] | 24 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 25 | #include <xen/page.h> |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 26 | #include <xen/interface/callback.h> |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 27 | #include <xen/interface/memory.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 28 | #include <xen/interface/physdev.h> |
| 29 | #include <xen/features.h> |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 30 | #include "mmu.h" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 31 | #include "xen-ops.h" |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 32 | #include "vdso.h" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 33 | |
| 34 | /* These are code, but not functions. Defined in entry.S */ |
| 35 | extern const char xen_hypervisor_callback[]; |
| 36 | extern const char xen_failsafe_callback[]; |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 37 | #ifdef CONFIG_X86_64 |
Andi Kleen | 07ba06d | 2013-10-22 09:07:59 -0700 | [diff] [blame] | 38 | extern asmlinkage void nmi(void); |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 39 | #endif |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame] | 40 | extern void xen_sysenter_target(void); |
| 41 | extern void xen_syscall_target(void); |
| 42 | extern void xen_syscall32_target(void); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 43 | |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 44 | /* Amount of extra memory space we add to the e820 ranges */ |
David Vrabel | 8b5d44a | 2011-09-28 17:46:34 +0100 | [diff] [blame] | 45 | struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 46 | |
David Vrabel | aa24411 | 2011-09-28 17:46:32 +0100 | [diff] [blame] | 47 | /* Number of pages released from the initial allocation. */ |
| 48 | unsigned long xen_released_pages; |
| 49 | |
Jeremy Fitzhardinge | 698bb8d | 2010-09-14 10:19:14 -0700 | [diff] [blame] | 50 | /* |
| 51 | * The maximum amount of extra memory compared to the base size. The |
| 52 | * main scaling factor is the size of struct page. At extreme ratios |
| 53 | * of base:extra, all the base memory can be filled with page |
| 54 | * structures for the extra memory, leaving no space for anything |
| 55 | * else. |
| 56 | * |
| 57 | * 10x seems like a reasonable balance between scaling flexibility and |
| 58 | * leaving a practically usable system. |
| 59 | */ |
| 60 | #define EXTRA_MEM_RATIO (10) |
| 61 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 62 | static void __init xen_add_extra_mem(u64 start, u64 size) |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 63 | { |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 64 | unsigned long pfn; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 65 | int i; |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 66 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 67 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
| 68 | /* Add new region. */ |
| 69 | if (xen_extra_mem[i].size == 0) { |
| 70 | xen_extra_mem[i].start = start; |
| 71 | xen_extra_mem[i].size = size; |
| 72 | break; |
| 73 | } |
| 74 | /* Append to existing region. */ |
| 75 | if (xen_extra_mem[i].start + xen_extra_mem[i].size == start) { |
| 76 | xen_extra_mem[i].size += size; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | if (i == XEN_EXTRA_MEM_MAX_REGIONS) |
| 81 | printk(KERN_WARNING "Warning: not enough extra memory regions\n"); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 82 | |
Tejun Heo | d4bbf7e | 2011-11-28 09:46:22 -0800 | [diff] [blame] | 83 | memblock_reserve(start, size); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 84 | |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 85 | if (xen_feature(XENFEAT_auto_translated_physmap)) |
| 86 | return; |
| 87 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 88 | xen_max_p2m_pfn = PFN_DOWN(start + size); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 89 | for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) { |
| 90 | unsigned long mfn = pfn_to_mfn(pfn); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 91 | |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 92 | if (WARN(mfn == pfn, "Trying to over-write 1-1 mapping (pfn: %lx)\n", pfn)) |
| 93 | continue; |
| 94 | WARN(mfn != INVALID_P2M_ENTRY, "Trying to remove %lx which has %lx mfn!\n", |
| 95 | pfn, mfn); |
| 96 | |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 97 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 98 | } |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 101 | static unsigned long __init xen_do_chunk(unsigned long start, |
| 102 | unsigned long end, bool release) |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 103 | { |
| 104 | struct xen_memory_reservation reservation = { |
| 105 | .address_bits = 0, |
| 106 | .extent_order = 0, |
| 107 | .domid = DOMID_SELF |
| 108 | }; |
Jeremy Fitzhardinge | f89e048 | 2009-09-16 12:38:33 -0700 | [diff] [blame] | 109 | unsigned long len = 0; |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 110 | int xlated_phys = xen_feature(XENFEAT_auto_translated_physmap); |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 111 | unsigned long pfn; |
| 112 | int ret; |
| 113 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 114 | for (pfn = start; pfn < end; pfn++) { |
| 115 | unsigned long frame; |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 116 | unsigned long mfn = pfn_to_mfn(pfn); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 117 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 118 | if (release) { |
| 119 | /* Make sure pfn exists to start with */ |
| 120 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) |
| 121 | continue; |
| 122 | frame = mfn; |
| 123 | } else { |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 124 | if (!xlated_phys && mfn != INVALID_P2M_ENTRY) |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 125 | continue; |
| 126 | frame = pfn; |
| 127 | } |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 128 | set_xen_guest_handle(reservation.extent_start, &frame); |
| 129 | reservation.nr_extents = 1; |
| 130 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 131 | ret = HYPERVISOR_memory_op(release ? XENMEM_decrease_reservation : XENMEM_populate_physmap, |
| 132 | &reservation); |
| 133 | WARN(ret != 1, "Failed to %s pfn %lx err=%d\n", |
| 134 | release ? "release" : "populate", pfn, ret); |
| 135 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 136 | if (ret == 1) { |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 137 | if (!early_set_phys_to_machine(pfn, release ? INVALID_P2M_ENTRY : frame)) { |
| 138 | if (release) |
| 139 | break; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 140 | set_xen_guest_handle(reservation.extent_start, &frame); |
| 141 | reservation.nr_extents = 1; |
| 142 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 143 | &reservation); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 144 | break; |
| 145 | } |
| 146 | len++; |
| 147 | } else |
| 148 | break; |
| 149 | } |
| 150 | if (len) |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 151 | printk(KERN_INFO "%s %lx-%lx pfn range: %lu pages %s\n", |
| 152 | release ? "Freeing" : "Populating", |
| 153 | start, end, len, |
| 154 | release ? "freed" : "added"); |
| 155 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 156 | return len; |
| 157 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 158 | |
| 159 | static unsigned long __init xen_release_chunk(unsigned long start, |
| 160 | unsigned long end) |
| 161 | { |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 162 | /* |
| 163 | * Xen already ballooned out the E820 non RAM regions for us |
| 164 | * and set them up properly in EPT. |
| 165 | */ |
| 166 | if (xen_feature(XENFEAT_auto_translated_physmap)) |
| 167 | return end - start; |
| 168 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 169 | return xen_do_chunk(start, end, true); |
| 170 | } |
| 171 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 172 | static unsigned long __init xen_populate_chunk( |
| 173 | const struct e820entry *list, size_t map_size, |
| 174 | unsigned long max_pfn, unsigned long *last_pfn, |
| 175 | unsigned long credits_left) |
| 176 | { |
| 177 | const struct e820entry *entry; |
| 178 | unsigned int i; |
| 179 | unsigned long done = 0; |
| 180 | unsigned long dest_pfn; |
| 181 | |
| 182 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 183 | unsigned long s_pfn; |
| 184 | unsigned long e_pfn; |
| 185 | unsigned long pfns; |
| 186 | long capacity; |
| 187 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 188 | if (credits_left <= 0) |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 189 | break; |
| 190 | |
| 191 | if (entry->type != E820_RAM) |
| 192 | continue; |
| 193 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 194 | e_pfn = PFN_DOWN(entry->addr + entry->size); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 195 | |
| 196 | /* We only care about E820 after the xen_start_info->nr_pages */ |
| 197 | if (e_pfn <= max_pfn) |
| 198 | continue; |
| 199 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 200 | s_pfn = PFN_UP(entry->addr); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 201 | /* If the E820 falls within the nr_pages, we want to start |
| 202 | * at the nr_pages PFN. |
| 203 | * If that would mean going past the E820 entry, skip it |
| 204 | */ |
| 205 | if (s_pfn <= max_pfn) { |
| 206 | capacity = e_pfn - max_pfn; |
| 207 | dest_pfn = max_pfn; |
| 208 | } else { |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 209 | capacity = e_pfn - s_pfn; |
| 210 | dest_pfn = s_pfn; |
| 211 | } |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 212 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 213 | if (credits_left < capacity) |
| 214 | capacity = credits_left; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 215 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 216 | pfns = xen_do_chunk(dest_pfn, dest_pfn + capacity, false); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 217 | done += pfns; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 218 | *last_pfn = (dest_pfn + pfns); |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 219 | if (pfns < capacity) |
| 220 | break; |
| 221 | credits_left -= pfns; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 222 | } |
| 223 | return done; |
| 224 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 225 | |
| 226 | static void __init xen_set_identity_and_release_chunk( |
| 227 | unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, |
| 228 | unsigned long *released, unsigned long *identity) |
| 229 | { |
| 230 | unsigned long pfn; |
| 231 | |
| 232 | /* |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 233 | * If the PFNs are currently mapped, clear the mappings |
| 234 | * (except for the ISA region which must be 1:1 mapped) to |
| 235 | * release the refcounts (in Xen) on the original frames. |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 236 | */ |
Mukesh Rathor | 9103bb0 | 2013-12-13 13:02:58 -0500 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * PVH E820 matches the hypervisor's P2M which means we need to |
| 240 | * account for the proper values of *release and *identity. |
| 241 | */ |
| 242 | for (pfn = start_pfn; !xen_feature(XENFEAT_auto_translated_physmap) && |
| 243 | pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) { |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 244 | pte_t pte = __pte_ma(0); |
| 245 | |
| 246 | if (pfn < PFN_UP(ISA_END_ADDRESS)) |
| 247 | pte = mfn_pte(pfn, PAGE_KERNEL_IO); |
| 248 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 249 | (void)HYPERVISOR_update_va_mapping( |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 250 | (unsigned long)__va(pfn << PAGE_SHIFT), pte, 0); |
| 251 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 252 | |
| 253 | if (start_pfn < nr_pages) |
| 254 | *released += xen_release_chunk( |
| 255 | start_pfn, min(end_pfn, nr_pages)); |
| 256 | |
| 257 | *identity += set_phys_range_identity(start_pfn, end_pfn); |
| 258 | } |
| 259 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 260 | static unsigned long __init xen_set_identity_and_release( |
| 261 | const struct e820entry *list, size_t map_size, unsigned long nr_pages) |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 262 | { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 263 | phys_addr_t start = 0; |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 264 | unsigned long released = 0; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 265 | unsigned long identity = 0; |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 266 | const struct e820entry *entry; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 267 | int i; |
| 268 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 269 | /* |
| 270 | * Combine non-RAM regions and gaps until a RAM region (or the |
| 271 | * end of the map) is reached, then set the 1:1 map and |
| 272 | * release the pages (if available) in those non-RAM regions. |
| 273 | * |
| 274 | * The combined non-RAM regions are rounded to a whole number |
| 275 | * of pages so any partial pages are accessible via the 1:1 |
| 276 | * mapping. This is needed for some BIOSes that put (for |
| 277 | * example) the DMI tables in a reserved region that begins on |
| 278 | * a non-page boundary. |
| 279 | */ |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 280 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 281 | phys_addr_t end = entry->addr + entry->size; |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 282 | if (entry->type == E820_RAM || i == map_size - 1) { |
| 283 | unsigned long start_pfn = PFN_DOWN(start); |
| 284 | unsigned long end_pfn = PFN_UP(end); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 285 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 286 | if (entry->type == E820_RAM) |
| 287 | end_pfn = PFN_UP(entry->addr); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 288 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 289 | if (start_pfn < end_pfn) |
| 290 | xen_set_identity_and_release_chunk( |
| 291 | start_pfn, end_pfn, nr_pages, |
| 292 | &released, &identity); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 293 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 294 | start = end; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 295 | } |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 296 | } |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 297 | |
Konrad Rzeszutek Wilk | ca11823 | 2012-03-30 15:37:07 -0400 | [diff] [blame] | 298 | if (released) |
| 299 | printk(KERN_INFO "Released %lu pages of unused memory\n", released); |
| 300 | if (identity) |
| 301 | printk(KERN_INFO "Set %ld page(s) to 1-1 mapping\n", identity); |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 302 | |
| 303 | return released; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 304 | } |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 305 | |
| 306 | static unsigned long __init xen_get_max_pages(void) |
| 307 | { |
| 308 | unsigned long max_pages = MAX_DOMAIN_PAGES; |
| 309 | domid_t domid = DOMID_SELF; |
| 310 | int ret; |
| 311 | |
Ian Campbell | d3db728 | 2011-12-14 12:16:08 +0000 | [diff] [blame] | 312 | /* |
| 313 | * For the initial domain we use the maximum reservation as |
| 314 | * the maximum page. |
| 315 | * |
| 316 | * For guest domains the current maximum reservation reflects |
| 317 | * the current maximum rather than the static maximum. In this |
| 318 | * case the e820 map provided to us will cover the static |
| 319 | * maximum region. |
| 320 | */ |
| 321 | if (xen_initial_domain()) { |
| 322 | ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); |
| 323 | if (ret > 0) |
| 324 | max_pages = ret; |
| 325 | } |
| 326 | |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 327 | return min(max_pages, MAX_DOMAIN_PAGES); |
| 328 | } |
| 329 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 330 | static void xen_align_and_add_e820_region(u64 start, u64 size, int type) |
| 331 | { |
| 332 | u64 end = start + size; |
| 333 | |
| 334 | /* Align RAM regions to page boundaries. */ |
| 335 | if (type == E820_RAM) { |
| 336 | start = PAGE_ALIGN(start); |
| 337 | end &= ~((u64)PAGE_SIZE - 1); |
| 338 | } |
| 339 | |
| 340 | e820_add_region(start, end - start, type); |
| 341 | } |
| 342 | |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 343 | void xen_ignore_unusable(struct e820entry *list, size_t map_size) |
| 344 | { |
| 345 | struct e820entry *entry; |
| 346 | unsigned int i; |
| 347 | |
| 348 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
| 349 | if (entry->type == E820_UNUSABLE) |
| 350 | entry->type = E820_RAM; |
| 351 | } |
| 352 | } |
| 353 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 354 | /** |
| 355 | * machine_specific_memory_setup - Hook for machine specific memory setup. |
| 356 | **/ |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 357 | char * __init xen_memory_setup(void) |
| 358 | { |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 359 | static struct e820entry map[E820MAX] __initdata; |
| 360 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 361 | unsigned long max_pfn = xen_start_info->nr_pages; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 362 | unsigned long long mem_end; |
| 363 | int rc; |
| 364 | struct xen_memory_map memmap; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 365 | unsigned long max_pages; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 366 | unsigned long last_pfn = 0; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 367 | unsigned long extra_pages = 0; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 368 | unsigned long populated; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 369 | int i; |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 370 | int op; |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 371 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 372 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 373 | mem_end = PFN_PHYS(max_pfn); |
| 374 | |
| 375 | memmap.nr_entries = E820MAX; |
| 376 | set_xen_guest_handle(memmap.buffer, map); |
| 377 | |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 378 | op = xen_initial_domain() ? |
| 379 | XENMEM_machine_memory_map : |
| 380 | XENMEM_memory_map; |
| 381 | rc = HYPERVISOR_memory_op(op, &memmap); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 382 | if (rc == -ENOSYS) { |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 383 | BUG_ON(xen_initial_domain()); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 384 | memmap.nr_entries = 1; |
| 385 | map[0].addr = 0ULL; |
| 386 | map[0].size = mem_end; |
| 387 | /* 8MB slack (to balance backend allocations). */ |
| 388 | map[0].size += 8ULL << 20; |
| 389 | map[0].type = E820_RAM; |
| 390 | rc = 0; |
| 391 | } |
| 392 | BUG_ON(rc); |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 393 | |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 394 | /* |
| 395 | * Xen won't allow a 1:1 mapping to be created to UNUSABLE |
| 396 | * regions, so if we're using the machine memory map leave the |
| 397 | * region as RAM as it is in the pseudo-physical map. |
| 398 | * |
| 399 | * UNUSABLE regions in domUs are not handled and will need |
| 400 | * a patch in the future. |
| 401 | */ |
| 402 | if (xen_initial_domain()) |
| 403 | xen_ignore_unusable(map, memmap.nr_entries); |
| 404 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 405 | /* Make sure the Xen-supplied memory map is well-ordered. */ |
| 406 | sanitize_e820_map(map, memmap.nr_entries, &memmap.nr_entries); |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 407 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 408 | max_pages = xen_get_max_pages(); |
| 409 | if (max_pages > max_pfn) |
| 410 | extra_pages += max_pages - max_pfn; |
Stefano Stabellini | 7cb31b7 | 2011-01-27 10:13:25 -0500 | [diff] [blame] | 411 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 412 | /* |
| 413 | * Set P2M for all non-RAM pages and E820 gaps to be identity |
| 414 | * type PFNs. Any RAM pages that would be made inaccesible by |
| 415 | * this are first released. |
| 416 | */ |
| 417 | xen_released_pages = xen_set_identity_and_release( |
| 418 | map, memmap.nr_entries, max_pfn); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 419 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 420 | /* |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 421 | * Populate back the non-RAM pages and E820 gaps that had been |
| 422 | * released. */ |
| 423 | populated = xen_populate_chunk(map, memmap.nr_entries, |
| 424 | max_pfn, &last_pfn, xen_released_pages); |
| 425 | |
Konrad Rzeszutek Wilk | 58b7b53 | 2012-05-29 12:36:43 -0400 | [diff] [blame] | 426 | xen_released_pages -= populated; |
| 427 | extra_pages += xen_released_pages; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 428 | |
| 429 | if (last_pfn > max_pfn) { |
| 430 | max_pfn = min(MAX_DOMAIN_PAGES, last_pfn); |
| 431 | mem_end = PFN_PHYS(max_pfn); |
| 432 | } |
| 433 | /* |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 434 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO |
| 435 | * factor the base size. On non-highmem systems, the base |
| 436 | * size is the full initial memory allocation; on highmem it |
| 437 | * is limited to the max size of lowmem, so that it doesn't |
| 438 | * get completely filled. |
| 439 | * |
| 440 | * In principle there could be a problem in lowmem systems if |
| 441 | * the initial memory is also very large with respect to |
| 442 | * lowmem, but we won't try to deal with that here. |
| 443 | */ |
| 444 | extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), |
| 445 | extra_pages); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 446 | i = 0; |
| 447 | while (i < memmap.nr_entries) { |
| 448 | u64 addr = map[i].addr; |
| 449 | u64 size = map[i].size; |
| 450 | u32 type = map[i].type; |
| 451 | |
| 452 | if (type == E820_RAM) { |
| 453 | if (addr < mem_end) { |
| 454 | size = min(size, mem_end - addr); |
| 455 | } else if (extra_pages) { |
| 456 | size = min(size, (u64)extra_pages * PAGE_SIZE); |
| 457 | extra_pages -= size / PAGE_SIZE; |
| 458 | xen_add_extra_mem(addr, size); |
| 459 | } else |
| 460 | type = E820_UNUSABLE; |
Jeremy Fitzhardinge | 3654581 | 2010-09-29 16:54:33 -0700 | [diff] [blame] | 461 | } |
| 462 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 463 | xen_align_and_add_e820_region(addr, size, type); |
Jeremy Fitzhardinge | b5b43ce | 2010-09-02 17:10:12 -0700 | [diff] [blame] | 464 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 465 | map[i].addr += size; |
| 466 | map[i].size -= size; |
| 467 | if (map[i].size == 0) |
| 468 | i++; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 469 | } |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 470 | |
| 471 | /* |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 472 | * In domU, the ISA region is normal, usable memory, but we |
| 473 | * reserve ISA memory anyway because too many things poke |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 474 | * about in there. |
| 475 | */ |
| 476 | e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, |
| 477 | E820_RESERVED); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 478 | |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Reserve Xen bits: |
| 481 | * - mfn_list |
| 482 | * - xen_start_info |
| 483 | * See comment above "struct start_info" in <xen/interface/xen.h> |
Konrad Rzeszutek Wilk | 51faaf2 | 2012-08-22 13:00:10 -0400 | [diff] [blame] | 484 | * We tried to make the the memblock_reserve more selective so |
| 485 | * that it would be clear what region is reserved. Sadly we ran |
| 486 | * in the problem wherein on a 64-bit hypervisor with a 32-bit |
| 487 | * initial domain, the pt_base has the cr3 value which is not |
| 488 | * neccessarily where the pagetable starts! As Jan put it: " |
| 489 | * Actually, the adjustment turns out to be correct: The page |
| 490 | * tables for a 32-on-64 dom0 get allocated in the order "first L1", |
| 491 | * "first L2", "first L3", so the offset to the page table base is |
| 492 | * indeed 2. When reading xen/include/public/xen.h's comment |
| 493 | * very strictly, this is not a violation (since there nothing is said |
| 494 | * that the first thing in the page table space is pointed to by |
| 495 | * pt_base; I admit that this seems to be implied though, namely |
| 496 | * do I think that it is implied that the page table space is the |
| 497 | * range [pt_base, pt_base + nt_pt_frames), whereas that |
| 498 | * range here indeed is [pt_base - 2, pt_base - 2 + nt_pt_frames), |
| 499 | * which - without a priori knowledge - the kernel would have |
| 500 | * difficulty to figure out)." - so lets just fall back to the |
| 501 | * easy way and reserve the whole region. |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 502 | */ |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 503 | memblock_reserve(__pa(xen_start_info->mfn_list), |
| 504 | xen_start_info->pt_base - xen_start_info->mfn_list); |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 505 | |
| 506 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); |
| 507 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 508 | return "Xen"; |
| 509 | } |
| 510 | |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 511 | /* |
| 512 | * Set the bit indicating "nosegneg" library variants should be used. |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 513 | * We only need to bother in pure 32-bit mode; compat 32-bit processes |
| 514 | * can have un-truncated segments, so wrapping around is allowed. |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 515 | */ |
Sam Ravnborg | 08b6d29 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 516 | static void __init fiddle_vdso(void) |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 517 | { |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 518 | #ifdef CONFIG_X86_32 |
| 519 | u32 *mask; |
| 520 | mask = VDSO32_SYMBOL(&vdso32_int80_start, NOTE_MASK); |
| 521 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
| 522 | mask = VDSO32_SYMBOL(&vdso32_sysenter_start, NOTE_MASK); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 523 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 524 | #endif |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 527 | static int register_callback(unsigned type, const void *func) |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 528 | { |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 529 | struct callback_register callback = { |
| 530 | .type = type, |
| 531 | .address = XEN_CALLBACK(__KERNEL_CS, func), |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 532 | .flags = CALLBACKF_mask_events, |
| 533 | }; |
| 534 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 535 | return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); |
| 536 | } |
| 537 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 538 | void xen_enable_sysenter(void) |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 539 | { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 540 | int ret; |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 541 | unsigned sysenter_feature; |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 542 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 543 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 544 | sysenter_feature = X86_FEATURE_SEP; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 545 | #else |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 546 | sysenter_feature = X86_FEATURE_SYSENTER32; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 547 | #endif |
| 548 | |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 549 | if (!boot_cpu_has(sysenter_feature)) |
| 550 | return; |
| 551 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 552 | ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 553 | if(ret != 0) |
| 554 | setup_clear_cpu_cap(sysenter_feature); |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 557 | void xen_enable_syscall(void) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 558 | { |
| 559 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 560 | int ret; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 561 | |
| 562 | ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target); |
| 563 | if (ret != 0) { |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 564 | printk(KERN_ERR "Failed to set syscall callback: %d\n", ret); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 565 | /* Pretty fatal; 64-bit userspace has no other |
| 566 | mechanism for syscalls. */ |
| 567 | } |
| 568 | |
| 569 | if (boot_cpu_has(X86_FEATURE_SYSCALL32)) { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 570 | ret = register_callback(CALLBACKTYPE_syscall32, |
| 571 | xen_syscall32_target); |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 572 | if (ret != 0) |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 573 | setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 574 | } |
| 575 | #endif /* CONFIG_X86_64 */ |
| 576 | } |
Paul Gortmaker | 3b284bd | 2013-11-08 11:21:51 -0500 | [diff] [blame] | 577 | void xen_enable_nmi(void) |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 578 | { |
| 579 | #ifdef CONFIG_X86_64 |
Andi Kleen | 07ba06d | 2013-10-22 09:07:59 -0700 | [diff] [blame] | 580 | if (register_callback(CALLBACKTYPE_nmi, (char *)nmi)) |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 581 | BUG(); |
| 582 | #endif |
| 583 | } |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 584 | void __init xen_pvmmu_arch_setup(void) |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 585 | { |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 586 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); |
| 587 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); |
| 588 | |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 589 | HYPERVISOR_vm_assist(VMASST_CMD_enable, |
| 590 | VMASST_TYPE_pae_extended_cr3); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 591 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 592 | if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) || |
| 593 | register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) |
| 594 | BUG(); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 595 | |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 596 | xen_enable_sysenter(); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 597 | xen_enable_syscall(); |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 598 | xen_enable_nmi(); |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* This function is not called for HVM domains */ |
| 602 | void __init xen_arch_setup(void) |
| 603 | { |
| 604 | xen_panic_handler_init(); |
| 605 | if (!xen_feature(XENFEAT_auto_translated_physmap)) |
| 606 | xen_pvmmu_arch_setup(); |
| 607 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 608 | #ifdef CONFIG_ACPI |
| 609 | if (!(xen_start_info->flags & SIF_INITDOMAIN)) { |
| 610 | printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); |
| 611 | disable_acpi(); |
| 612 | } |
| 613 | #endif |
| 614 | |
| 615 | memcpy(boot_command_line, xen_start_info->cmd_line, |
| 616 | MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? |
| 617 | COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); |
| 618 | |
Jeremy Fitzhardinge | bc15fde | 2010-11-22 17:17:50 -0800 | [diff] [blame] | 619 | /* Set up idle, making sure it calls safe_halt() pvop */ |
Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 620 | disable_cpuidle(); |
Konrad Rzeszutek Wilk | 48cdd82 | 2012-03-13 20:06:57 -0400 | [diff] [blame] | 621 | disable_cpufreq(); |
Len Brown | 6a377dd | 2013-02-09 23:08:07 -0500 | [diff] [blame] | 622 | WARN_ON(xen_set_default_idle()); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 623 | fiddle_vdso(); |
Konrad Rzeszutek Wilk | 8d54db79 | 2012-08-17 10:22:37 -0400 | [diff] [blame] | 624 | #ifdef CONFIG_NUMA |
| 625 | numa_off = 1; |
| 626 | #endif |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 627 | } |