ia64/xen-unstable

view xen/arch/ia64/xen/dom_fw.c @ 13684:f4395e945393

[IA64] Include dummy EFI memory descriptors for unmapped ranges

This eliminates a lot of warnings about dom0 trying to do UC
mappings to WB ranges. Linux doesn't deal well with holes within
a granule.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author awilliam@xenbuild2.aw
date Tue Jan 30 23:35:32 2007 -0700 (2007-01-30)
parents 90db0f68b121
children 6d38ae7927cf
line source
1 /*
2 * Xen domain firmware emulation support
3 * Copyright (C) 2004 Hewlett-Packard Co.
4 * Dan Magenheimer (dan.magenheimer@hp.com)
5 *
6 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
7 * VA Linux Systems Japan K.K.
8 * dom0 vp model support
9 */
11 #include <xen/config.h>
12 #include <asm/system.h>
13 #include <asm/pgalloc.h>
15 #include <linux/efi.h>
16 #include <linux/sort.h>
17 #include <asm/io.h>
18 #include <asm/pal.h>
19 #include <asm/sal.h>
20 #include <asm/meminit.h>
21 #include <asm/fpswa.h>
22 #include <xen/version.h>
23 #include <xen/acpi.h>
24 #include <xen/errno.h>
26 #include <asm/dom_fw.h>
27 #include <asm/bundle.h>
29 #define ONE_MB (1UL << 20)
31 extern unsigned long running_on_sim;
33 #define FW_VENDOR "X\0e\0n\0/\0i\0a\0\066\0\064\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
35 #define MAKE_MD(typ, attr, start, end) \
36 do { \
37 md = tables->efi_memmap + i++; \
38 md->type = typ; \
39 md->pad = 0; \
40 md->phys_addr = start; \
41 md->virt_addr = 0; \
42 md->num_pages = (end - start) >> EFI_PAGE_SHIFT; \
43 md->attribute = attr; \
44 } while (0)
46 #define EFI_HYPERCALL_PATCH(tgt, call) \
47 do { \
48 dom_efi_hypercall_patch(d, FW_HYPERCALL_##call##_PADDR, \
49 FW_HYPERCALL_##call, hypercalls_imva); \
50 /* Descriptor address. */ \
51 tables->efi_runtime.tgt = \
52 FW_FIELD_MPA(func_ptrs) + 8 * pfn; \
53 /* Descriptor. */ \
54 tables->func_ptrs[pfn++] = FW_HYPERCALL_##call##_PADDR; \
55 tables->func_ptrs[pfn++] = 0; \
56 } while (0)
58 /* allocate a page for fw
59 * guest_setup() @ libxc/xc_linux_build.c does for domU
60 */
61 static inline void
62 assign_new_domain_page_if_dom0(struct domain *d, unsigned long mpaddr)
63 {
64 if (d == dom0)
65 assign_new_domain0_page(d, mpaddr);
66 }
68 /**************************************************************************
69 Hypercall bundle creation
70 **************************************************************************/
72 static void
73 build_hypercall_bundle(u64 *imva, u64 brkimm, u64 hypnum, u64 ret)
74 {
75 INST64_A5 slot0;
76 INST64_I19 slot1;
77 INST64_B4 slot2;
78 IA64_BUNDLE bundle;
80 // slot1: mov r2 = hypnum (low 20 bits)
81 slot0.inst = 0;
82 slot0.qp = 0; slot0.r1 = 2; slot0.r3 = 0; slot0.major = 0x9;
83 slot0.imm7b = hypnum; slot0.imm9d = hypnum >> 7;
84 slot0.imm5c = hypnum >> 16; slot0.s = 0;
85 // slot1: break brkimm
86 slot1.inst = 0;
87 slot1.qp = 0; slot1.x6 = 0; slot1.x3 = 0; slot1.major = 0x0;
88 slot1.imm20 = brkimm; slot1.i = brkimm >> 20;
89 // if ret slot2: br.ret.sptk.many rp
90 // else slot2: br.cond.sptk.many rp
91 slot2.inst = 0; slot2.qp = 0; slot2.p = 1; slot2.b2 = 0;
92 slot2.wh = 0; slot2.d = 0; slot2.major = 0x0;
93 if (ret) {
94 slot2.btype = 4; slot2.x6 = 0x21;
95 }
96 else {
97 slot2.btype = 0; slot2.x6 = 0x20;
98 }
100 bundle.i64[0] = 0; bundle.i64[1] = 0;
101 bundle.template = 0x11;
102 bundle.slot0 = slot0.inst; bundle.slot2 = slot2.inst;
103 bundle.slot1a = slot1.inst; bundle.slot1b = slot1.inst >> 18;
105 imva[0] = bundle.i64[0]; imva[1] = bundle.i64[1];
106 ia64_fc(imva);
107 ia64_fc(imva + 1);
108 }
110 static void
111 build_pal_hypercall_bundles(u64 *imva, u64 brkimm, u64 hypnum)
112 {
113 extern unsigned long pal_call_stub[];
114 IA64_BUNDLE bundle;
115 INST64_A5 slot_a5;
116 INST64_M37 slot_m37;
118 /* The source of the hypercall stub is the pal_call_stub function
119 defined in xenasm.S. */
121 /* Copy the first bundle and patch the hypercall number. */
122 bundle.i64[0] = pal_call_stub[0];
123 bundle.i64[1] = pal_call_stub[1];
124 slot_a5.inst = bundle.slot0;
125 slot_a5.imm7b = hypnum;
126 slot_a5.imm9d = hypnum >> 7;
127 slot_a5.imm5c = hypnum >> 16;
128 bundle.slot0 = slot_a5.inst;
129 imva[0] = bundle.i64[0];
130 imva[1] = bundle.i64[1];
131 ia64_fc(imva);
132 ia64_fc(imva + 1);
134 /* Copy the second bundle and patch the hypercall vector. */
135 bundle.i64[0] = pal_call_stub[2];
136 bundle.i64[1] = pal_call_stub[3];
137 slot_m37.inst = bundle.slot0;
138 slot_m37.imm20a = brkimm;
139 slot_m37.i = brkimm >> 20;
140 bundle.slot0 = slot_m37.inst;
141 imva[2] = bundle.i64[0];
142 imva[3] = bundle.i64[1];
143 ia64_fc(imva + 2);
144 ia64_fc(imva + 3);
145 }
147 // builds a hypercall bundle at domain physical address
148 static void
149 dom_fpswa_hypercall_patch(struct domain *d, unsigned long imva)
150 {
151 unsigned long *entry_imva, *patch_imva;
152 const unsigned long entry_paddr = FW_HYPERCALL_FPSWA_ENTRY_PADDR;
153 const unsigned long patch_paddr = FW_HYPERCALL_FPSWA_PATCH_PADDR;
155 entry_imva = (unsigned long *)(imva + entry_paddr -
156 FW_HYPERCALL_BASE_PADDR);
157 patch_imva = (unsigned long *)(imva + patch_paddr -
158 FW_HYPERCALL_BASE_PADDR);
160 /* Descriptor. */
161 *entry_imva++ = patch_paddr;
162 *entry_imva = 0;
164 build_hypercall_bundle(patch_imva, d->arch.breakimm,
165 FW_HYPERCALL_FPSWA, 1);
166 }
168 // builds a hypercall bundle at domain physical address
169 static void
170 dom_efi_hypercall_patch(struct domain *d, unsigned long paddr,
171 unsigned long hypercall, unsigned long imva)
172 {
173 build_hypercall_bundle((u64 *)(imva + paddr - FW_HYPERCALL_BASE_PADDR),
174 d->arch.breakimm, hypercall, 1);
175 }
177 // builds a hypercall bundle at domain physical address
178 static void
179 dom_fw_hypercall_patch(struct domain *d, unsigned long paddr,
180 unsigned long hypercall,unsigned long ret,
181 unsigned long imva)
182 {
183 build_hypercall_bundle((u64 *)(imva + paddr - FW_HYPERCALL_BASE_PADDR),
184 d->arch.breakimm, hypercall, ret);
185 }
187 static void
188 dom_fw_pal_hypercall_patch(struct domain *d, unsigned long paddr,
189 unsigned long imva)
190 {
191 build_pal_hypercall_bundles((u64*)(imva + paddr -
192 FW_HYPERCALL_BASE_PADDR),
193 d->arch.breakimm, FW_HYPERCALL_PAL_CALL);
194 }
196 static inline void
197 print_md(efi_memory_desc_t *md)
198 {
199 u64 size;
201 printk("dom mem: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) ",
202 md->type, md->attribute, md->phys_addr,
203 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT));
205 size = md->num_pages << EFI_PAGE_SHIFT;
206 if (size > ONE_MB)
207 printk ("(%luMB)\n", size >> 20);
208 else
209 printk ("(%luKB)\n", size >> 10);
210 }
212 static u32 lsapic_nbr;
214 /* Modify lsapic table. Provides LPs. */
215 static int
216 acpi_update_lsapic (acpi_table_entry_header *header, const unsigned long end)
217 {
218 struct acpi_table_lsapic *lsapic;
219 int enable;
221 lsapic = (struct acpi_table_lsapic *) header;
222 if (!lsapic)
223 return -EINVAL;
225 if (lsapic_nbr < MAX_VIRT_CPUS && dom0->vcpu[lsapic_nbr] != NULL)
226 enable = 1;
227 else
228 enable = 0;
229 if (lsapic->flags.enabled && enable) {
230 printk("enable lsapic entry: 0x%lx\n", (u64)lsapic);
231 lsapic->id = lsapic_nbr;
232 lsapic->eid = 0;
233 lsapic_nbr++;
234 } else if (lsapic->flags.enabled) {
235 printk("DISABLE lsapic entry: 0x%lx\n", (u64)lsapic);
236 lsapic->flags.enabled = 0;
237 lsapic->id = 0;
238 lsapic->eid = 0;
239 }
240 return 0;
241 }
243 static int __init
244 acpi_patch_plat_int_src (
245 acpi_table_entry_header *header, const unsigned long end)
246 {
247 struct acpi_table_plat_int_src *plintsrc;
249 plintsrc = (struct acpi_table_plat_int_src *)header;
250 if (!plintsrc)
251 return -EINVAL;
253 if (plintsrc->type == ACPI_INTERRUPT_CPEI) {
254 printk("ACPI_INTERRUPT_CPEI disabled for Domain0\n");
255 plintsrc->type = -1;
256 }
257 return 0;
258 }
260 static u8
261 generate_acpi_checksum(void *tbl, unsigned long len)
262 {
263 u8 *ptr, sum = 0;
265 for (ptr = tbl; len > 0 ; len--, ptr++)
266 sum += *ptr;
268 return 0 - sum;
269 }
271 static int
272 acpi_update_madt_checksum (unsigned long phys_addr, unsigned long size)
273 {
274 struct acpi_table_madt* acpi_madt;
276 if (!phys_addr || !size)
277 return -EINVAL;
279 acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
280 acpi_madt->header.checksum = 0;
281 acpi_madt->header.checksum = generate_acpi_checksum(acpi_madt, size);
283 return 0;
284 }
286 /* base is physical address of acpi table */
287 static void touch_acpi_table(void)
288 {
289 lsapic_nbr = 0;
290 if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_update_lsapic, 0) < 0)
291 printk("Error parsing MADT - no LAPIC entries\n");
292 if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC,
293 acpi_patch_plat_int_src, 0) < 0)
294 printk("Error parsing MADT - no PLAT_INT_SRC entries\n");
296 acpi_table_parse(ACPI_APIC, acpi_update_madt_checksum);
298 return;
299 }
301 struct fake_acpi_tables {
302 struct acpi20_table_rsdp rsdp;
303 struct xsdt_descriptor_rev2 xsdt;
304 u64 madt_ptr;
305 struct fadt_descriptor_rev2 fadt;
306 struct facs_descriptor_rev2 facs;
307 struct acpi_table_header dsdt;
308 u8 aml[8 + 11 * MAX_VIRT_CPUS];
309 struct acpi_table_madt madt;
310 struct acpi_table_lsapic lsapic[MAX_VIRT_CPUS];
311 u8 pm1a_evt_blk[4];
312 u8 pm1a_cnt_blk[1];
313 u8 pm_tmr_blk[4];
314 };
315 #define ACPI_TABLE_MPA(field) \
316 FW_ACPI_BASE_PADDR + offsetof(struct fake_acpi_tables, field);
318 /* Create enough of an ACPI structure to make the guest OS ACPI happy. */
319 static void
320 dom_fw_fake_acpi(struct domain *d, struct fake_acpi_tables *tables)
321 {
322 struct acpi20_table_rsdp *rsdp = &tables->rsdp;
323 struct xsdt_descriptor_rev2 *xsdt = &tables->xsdt;
324 struct fadt_descriptor_rev2 *fadt = &tables->fadt;
325 struct facs_descriptor_rev2 *facs = &tables->facs;
326 struct acpi_table_header *dsdt = &tables->dsdt;
327 struct acpi_table_madt *madt = &tables->madt;
328 struct acpi_table_lsapic *lsapic = tables->lsapic;
329 int i;
330 int aml_len;
331 int nbr_cpus;
333 memset(tables, 0, sizeof(struct fake_acpi_tables));
335 /* setup XSDT (64bit version of RSDT) */
336 strncpy(xsdt->signature, XSDT_SIG, 4);
337 /* XSDT points to both the FADT and the MADT, so add one entry */
338 xsdt->length = sizeof(struct xsdt_descriptor_rev2) + sizeof(u64);
339 xsdt->revision = 1;
340 strcpy(xsdt->oem_id, "XEN");
341 strcpy(xsdt->oem_table_id, "Xen/ia64");
342 strcpy(xsdt->asl_compiler_id, "XEN");
343 xsdt->asl_compiler_revision = (xen_major_version() << 16) |
344 xen_minor_version();
346 xsdt->table_offset_entry[0] = ACPI_TABLE_MPA(fadt);
347 tables->madt_ptr = ACPI_TABLE_MPA(madt);
349 xsdt->checksum = generate_acpi_checksum(xsdt, xsdt->length);
351 /* setup FADT */
352 strncpy(fadt->signature, FADT_SIG, 4);
353 fadt->length = sizeof(struct fadt_descriptor_rev2);
354 fadt->revision = FADT2_REVISION_ID;
355 strcpy(fadt->oem_id, "XEN");
356 strcpy(fadt->oem_table_id, "Xen/ia64");
357 strcpy(fadt->asl_compiler_id, "XEN");
358 fadt->asl_compiler_revision = (xen_major_version() << 16) |
359 xen_minor_version();
361 strncpy(facs->signature, FACS_SIG, 4);
362 facs->version = 1;
363 facs->length = sizeof(struct facs_descriptor_rev2);
365 fadt->xfirmware_ctrl = ACPI_TABLE_MPA(facs);
366 fadt->Xdsdt = ACPI_TABLE_MPA(dsdt);
368 /*
369 * All of the below FADT entries are filled it to prevent warnings
370 * from sanity checks in the ACPI CA. Emulate required ACPI hardware
371 * registers in system memory.
372 */
373 fadt->pm1_evt_len = 4;
374 fadt->xpm1a_evt_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
375 fadt->xpm1a_evt_blk.register_bit_width = 8;
376 fadt->xpm1a_evt_blk.address = ACPI_TABLE_MPA(pm1a_evt_blk);
377 fadt->pm1_cnt_len = 1;
378 fadt->xpm1a_cnt_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
379 fadt->xpm1a_cnt_blk.register_bit_width = 8;
380 fadt->xpm1a_cnt_blk.address = ACPI_TABLE_MPA(pm1a_cnt_blk);
381 fadt->pm_tm_len = 4;
382 fadt->xpm_tmr_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
383 fadt->xpm_tmr_blk.register_bit_width = 8;
384 fadt->xpm_tmr_blk.address = ACPI_TABLE_MPA(pm_tmr_blk);
386 fadt->checksum = generate_acpi_checksum(fadt, fadt->length);
388 /* setup RSDP */
389 strncpy(rsdp->signature, RSDP_SIG, 8);
390 strcpy(rsdp->oem_id, "XEN");
391 rsdp->revision = 2; /* ACPI 2.0 includes XSDT */
392 rsdp->length = sizeof(struct acpi20_table_rsdp);
393 rsdp->xsdt_address = ACPI_TABLE_MPA(xsdt);
395 rsdp->checksum = generate_acpi_checksum(rsdp,
396 ACPI_RSDP_CHECKSUM_LENGTH);
397 rsdp->ext_checksum = generate_acpi_checksum(rsdp, rsdp->length);
399 /* setup DSDT with trivial namespace. */
400 strncpy(dsdt->signature, DSDT_SIG, 4);
401 dsdt->revision = 1;
402 strcpy(dsdt->oem_id, "XEN");
403 strcpy(dsdt->oem_table_id, "Xen/ia64");
404 strcpy(dsdt->asl_compiler_id, "XEN");
405 dsdt->asl_compiler_revision = (xen_major_version() << 16) |
406 xen_minor_version();
408 /* Trivial namespace, avoids ACPI CA complaints */
409 tables->aml[0] = 0x10; /* Scope */
410 tables->aml[1] = 0x40; /* length/offset to next object (patched) */
411 tables->aml[2] = 0x00;
412 strncpy((char *)&tables->aml[3], "_SB_", 4);
414 /* The processor object isn't absolutely necessary, revist for SMP */
415 aml_len = 7;
416 for (i = 0; i < 3; i++) {
417 unsigned char *p = tables->aml + aml_len;
418 p[0] = 0x5b; /* processor object */
419 p[1] = 0x83;
420 p[2] = 0x0b; /* next */
421 p[3] = 'C';
422 p[4] = 'P';
423 snprintf ((char *)p + 5, 3, "%02x", i);
424 if (i < 16)
425 p[5] = 'U';
426 p[7] = i; /* acpi_id */
427 p[8] = 0; /* pblk_addr */
428 p[9] = 0;
429 p[10] = 0;
430 p[11] = 0;
431 p[12] = 0; /* pblk_len */
432 aml_len += 13;
433 }
434 tables->aml[1] = 0x40 + ((aml_len - 1) & 0x0f);
435 tables->aml[2] = (aml_len - 1) >> 4;
436 dsdt->length = sizeof(struct acpi_table_header) + aml_len;
437 dsdt->checksum = generate_acpi_checksum(dsdt, dsdt->length);
439 /* setup MADT */
440 strncpy(madt->header.signature, APIC_SIG, 4);
441 madt->header.revision = 2;
442 strcpy(madt->header.oem_id, "XEN");
443 strcpy(madt->header.oem_table_id, "Xen/ia64");
444 strcpy(madt->header.asl_compiler_id, "XEN");
445 madt->header.asl_compiler_revision = (xen_major_version() << 16) |
446 xen_minor_version();
448 /* An LSAPIC entry describes a CPU. */
449 nbr_cpus = 0;
450 for (i = 0; i < MAX_VIRT_CPUS; i++) {
451 lsapic[i].header.type = ACPI_MADT_LSAPIC;
452 lsapic[i].header.length = sizeof(struct acpi_table_lsapic);
453 lsapic[i].acpi_id = i;
454 lsapic[i].id = i;
455 lsapic[i].eid = 0;
456 if (d->vcpu[i] != NULL) {
457 lsapic[i].flags.enabled = 1;
458 nbr_cpus++;
459 }
460 }
461 madt->header.length = sizeof(struct acpi_table_madt) +
462 nbr_cpus * sizeof(struct acpi_table_lsapic);
463 madt->header.checksum = generate_acpi_checksum(madt,
464 madt->header.length);
465 return;
466 }
468 static int
469 efi_mdt_cmp(const void *a, const void *b)
470 {
471 const efi_memory_desc_t *x = a, *y = b;
473 if (x->phys_addr > y->phys_addr)
474 return 1;
475 if (x->phys_addr < y->phys_addr)
476 return -1;
478 // num_pages == 0 is allowed.
479 if (x->num_pages > y->num_pages)
480 return 1;
481 if (x->num_pages < y->num_pages)
482 return -1;
484 return 0;
485 }
487 #define NFUNCPTRS 16
488 #define NUM_EFI_SYS_TABLES 6
489 #define NUM_MEM_DESCS 64 //large enough
491 struct fw_tables {
492 efi_system_table_t efi_systab;
493 efi_runtime_services_t efi_runtime;
494 efi_config_table_t efi_tables[NUM_EFI_SYS_TABLES];
496 struct ia64_sal_systab sal_systab;
497 struct ia64_sal_desc_entry_point sal_ed;
498 struct ia64_sal_desc_ap_wakeup sal_wakeup;
499 /* End of SAL descriptors. Do not forget to update checkum bound. */
501 fpswa_interface_t fpswa_inf;
502 efi_memory_desc_t efi_memmap[NUM_MEM_DESCS];
503 unsigned long func_ptrs[2*NFUNCPTRS];
504 struct xen_sal_data sal_data;
505 unsigned char fw_vendor[sizeof(FW_VENDOR)];
506 };
507 #define FW_FIELD_MPA(field) \
508 FW_TABLES_BASE_PADDR + offsetof(struct fw_tables, field)
510 /* Complete the dom0 memmap. */
511 static int
512 complete_dom0_memmap(struct domain *d,
513 struct fw_tables *tables,
514 unsigned long maxmem,
515 int num_mds)
516 {
517 efi_memory_desc_t *md;
518 u64 addr;
519 void *efi_map_start, *efi_map_end, *p;
520 u64 efi_desc_size;
521 int i;
522 unsigned long dom_mem = maxmem - (d->tot_pages << PAGE_SHIFT);
524 /* Walk through all MDT entries.
525 Copy all interesting entries. */
526 efi_map_start = __va(ia64_boot_param->efi_memmap);
527 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
528 efi_desc_size = ia64_boot_param->efi_memdesc_size;
530 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
531 const efi_memory_desc_t *md = p;
532 efi_memory_desc_t *dom_md = &tables->efi_memmap[num_mds];
533 u64 start = md->phys_addr;
534 u64 size = md->num_pages << EFI_PAGE_SHIFT;
535 u64 end = start + size;
536 unsigned long flags;
538 switch (md->type) {
539 case EFI_RUNTIME_SERVICES_CODE:
540 case EFI_RUNTIME_SERVICES_DATA:
541 case EFI_ACPI_RECLAIM_MEMORY:
542 case EFI_ACPI_MEMORY_NVS:
543 case EFI_RESERVED_TYPE:
544 /*
545 * Map into dom0 - We must respect protection
546 * and cache attributes. Not all of these pages
547 * are writable!!!
548 */
549 flags = ASSIGN_writable; /* dummy - zero */
550 if (md->attribute & EFI_MEMORY_WP)
551 flags |= ASSIGN_readonly;
552 if ((md->attribute & EFI_MEMORY_UC) &&
553 !(md->attribute & EFI_MEMORY_WB))
554 flags |= ASSIGN_nocache;
556 assign_domain_mach_page(d, start, size, flags);
558 /* Fall-through. */
559 case EFI_MEMORY_MAPPED_IO:
560 /* Will be mapped with ioremap. */
561 /* Copy descriptor. */
562 *dom_md = *md;
563 dom_md->virt_addr = 0;
564 num_mds++;
565 break;
567 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
568 /* Map into dom0. */
569 assign_domain_mmio_page(d, start, size);
570 /* Copy descriptor. */
571 *dom_md = *md;
572 dom_md->virt_addr = 0;
573 num_mds++;
574 break;
576 case EFI_CONVENTIONAL_MEMORY:
577 case EFI_LOADER_CODE:
578 case EFI_LOADER_DATA:
579 case EFI_BOOT_SERVICES_CODE:
580 case EFI_BOOT_SERVICES_DATA:
581 if (!(md->attribute & EFI_MEMORY_WB))
582 break;
584 start = max(FW_END_PADDR, start);
585 end = min(start + dom_mem, end);
586 if (end <= start)
587 break;
589 dom_md->type = EFI_CONVENTIONAL_MEMORY;
590 dom_md->phys_addr = start;
591 dom_md->virt_addr = 0;
592 dom_md->num_pages = (end - start) >> EFI_PAGE_SHIFT;
593 dom_md->attribute = EFI_MEMORY_WB;
594 num_mds++;
596 dom_mem -= dom_md->num_pages << EFI_PAGE_SHIFT;
597 d->arch.convmem_end = end;
598 break;
600 case EFI_UNUSABLE_MEMORY:
601 case EFI_PAL_CODE:
602 /*
603 * We don't really need these, but holes in the
604 * memory map may cause Linux to assume there are
605 * uncacheable ranges within a granule.
606 */
607 dom_md->type = EFI_UNUSABLE_MEMORY;
608 dom_md->phys_addr = start;
609 dom_md->virt_addr = 0;
610 dom_md->num_pages = (end - start) >> EFI_PAGE_SHIFT;
611 dom_md->attribute = EFI_MEMORY_WB;
612 num_mds++;
613 break;
615 default:
616 /* Print a warning but continue. */
617 printk("complete_dom0_memmap: warning: "
618 "unhandled MDT entry type %u\n", md->type);
619 }
620 }
621 BUG_ON(num_mds > NUM_MEM_DESCS);
623 sort(tables->efi_memmap, num_mds, sizeof(efi_memory_desc_t),
624 efi_mdt_cmp, NULL);
626 /* setup_guest() @ libxc/xc_linux_build() arranges memory for domU.
627 * however no one arranges memory for dom0,
628 * instead we allocate pages manually.
629 */
630 for (i = 0; i < num_mds; i++) {
631 md = &tables->efi_memmap[i];
633 if (md->type == EFI_LOADER_DATA ||
634 md->type == EFI_PAL_CODE ||
635 md->type == EFI_CONVENTIONAL_MEMORY) {
636 unsigned long start = md->phys_addr & PAGE_MASK;
637 unsigned long end = md->phys_addr +
638 (md->num_pages << EFI_PAGE_SHIFT);
640 if (end == start) {
641 /* md->num_pages = 0 is allowed. */
642 continue;
643 }
645 for (addr = start; addr < end; addr += PAGE_SIZE)
646 assign_new_domain0_page(d, addr);
647 }
648 }
649 // Map low-memory holes & unmapped MMIO for legacy drivers
650 for (addr = 0; addr < ONE_MB; addr += PAGE_SIZE) {
651 if (domain_page_mapped(d, addr))
652 continue;
654 if (efi_mmio(addr, PAGE_SIZE))
655 assign_domain_mmio_page(d, addr, PAGE_SIZE);
656 }
657 return num_mds;
658 }
660 static void
661 dom_fw_init(struct domain *d,
662 struct ia64_boot_param *bp,
663 struct fw_tables *tables,
664 unsigned long hypercalls_imva,
665 unsigned long maxmem)
666 {
667 efi_memory_desc_t *md;
668 unsigned long pfn;
669 unsigned char checksum;
670 char *cp;
671 int num_mds, i;
673 memset(tables, 0, sizeof(struct fw_tables));
675 /* Initialise for EFI_SET_VIRTUAL_ADDRESS_MAP emulation */
676 d->arch.efi_runtime = &tables->efi_runtime;
677 d->arch.fpswa_inf = &tables->fpswa_inf;
678 d->arch.sal_data = &tables->sal_data;
680 /* EFI systab. */
681 tables->efi_systab.hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE;
682 tables->efi_systab.hdr.revision = EFI_SYSTEM_TABLE_REVISION;
683 tables->efi_systab.hdr.headersize = sizeof(tables->efi_systab.hdr);
685 memcpy(tables->fw_vendor,FW_VENDOR,sizeof(FW_VENDOR));
686 tables->efi_systab.fw_vendor = FW_FIELD_MPA(fw_vendor);
687 tables->efi_systab.fw_revision = 1;
688 tables->efi_systab.runtime = (void *)FW_FIELD_MPA(efi_runtime);
689 tables->efi_systab.nr_tables = NUM_EFI_SYS_TABLES;
690 tables->efi_systab.tables = FW_FIELD_MPA(efi_tables);
692 /* EFI runtime. */
693 tables->efi_runtime.hdr.signature = EFI_RUNTIME_SERVICES_SIGNATURE;
694 tables->efi_runtime.hdr.revision = EFI_RUNTIME_SERVICES_REVISION;
695 tables->efi_runtime.hdr.headersize = sizeof(tables->efi_runtime.hdr);
697 pfn = 0;
698 EFI_HYPERCALL_PATCH(get_time,EFI_GET_TIME);
699 EFI_HYPERCALL_PATCH(set_time,EFI_SET_TIME);
700 EFI_HYPERCALL_PATCH(get_wakeup_time,EFI_GET_WAKEUP_TIME);
701 EFI_HYPERCALL_PATCH(set_wakeup_time,EFI_SET_WAKEUP_TIME);
702 EFI_HYPERCALL_PATCH(set_virtual_address_map,
703 EFI_SET_VIRTUAL_ADDRESS_MAP);
704 EFI_HYPERCALL_PATCH(get_variable,EFI_GET_VARIABLE);
705 EFI_HYPERCALL_PATCH(get_next_variable,EFI_GET_NEXT_VARIABLE);
706 EFI_HYPERCALL_PATCH(set_variable,EFI_SET_VARIABLE);
707 EFI_HYPERCALL_PATCH(get_next_high_mono_count,
708 EFI_GET_NEXT_HIGH_MONO_COUNT);
709 EFI_HYPERCALL_PATCH(reset_system,EFI_RESET_SYSTEM);
711 /* System tables. */
712 tables->efi_tables[0].guid = SAL_SYSTEM_TABLE_GUID;
713 tables->efi_tables[0].table = FW_FIELD_MPA(sal_systab);
714 for (i = 1; i < NUM_EFI_SYS_TABLES; i++) {
715 tables->efi_tables[i].guid = NULL_GUID;
716 tables->efi_tables[i].table = 0;
717 }
718 i = 1;
719 if (d == dom0) {
720 /* Write messages to the console. */
721 touch_acpi_table();
723 printk("Domain0 EFI passthrough:");
724 if (efi.mps) {
725 tables->efi_tables[i].guid = MPS_TABLE_GUID;
726 tables->efi_tables[i].table = __pa(efi.mps);
727 printk(" MPS=0x%lx",tables->efi_tables[i].table);
728 i++;
729 }
731 if (efi.acpi20) {
732 tables->efi_tables[i].guid = ACPI_20_TABLE_GUID;
733 tables->efi_tables[i].table = __pa(efi.acpi20);
734 printk(" ACPI 2.0=0x%lx",tables->efi_tables[i].table);
735 i++;
736 }
737 if (efi.acpi) {
738 tables->efi_tables[i].guid = ACPI_TABLE_GUID;
739 tables->efi_tables[i].table = __pa(efi.acpi);
740 printk(" ACPI=0x%lx",tables->efi_tables[i].table);
741 i++;
742 }
743 if (efi.smbios) {
744 tables->efi_tables[i].guid = SMBIOS_TABLE_GUID;
745 tables->efi_tables[i].table = __pa(efi.smbios);
746 printk(" SMBIOS=0x%lx",tables->efi_tables[i].table);
747 i++;
748 }
749 if (efi.hcdp) {
750 tables->efi_tables[i].guid = HCDP_TABLE_GUID;
751 tables->efi_tables[i].table = __pa(efi.hcdp);
752 printk(" HCDP=0x%lx",tables->efi_tables[i].table);
753 i++;
754 }
755 printk("\n");
756 } else {
757 printk("DomainU EFI build up:");
759 tables->efi_tables[i].guid = ACPI_20_TABLE_GUID;
760 tables->efi_tables[i].table = FW_ACPI_BASE_PADDR;
761 printk(" ACPI 2.0=0x%lx",tables->efi_tables[i].table);
762 i++;
763 printk("\n");
764 }
766 /* fill in the SAL system table: */
767 memcpy(tables->sal_systab.signature, "SST_", 4);
768 tables->sal_systab.size = sizeof(tables->sal_systab);
769 tables->sal_systab.sal_rev_minor = 1;
770 tables->sal_systab.sal_rev_major = 0;
771 tables->sal_systab.entry_count = 2;
773 strcpy((char *)tables->sal_systab.oem_id, "Xen/ia64");
774 strcpy((char *)tables->sal_systab.product_id, "Xen/ia64");
776 /* PAL entry point: */
777 tables->sal_ed.type = SAL_DESC_ENTRY_POINT;
778 tables->sal_ed.pal_proc = FW_HYPERCALL_PAL_CALL_PADDR;
779 dom_fw_pal_hypercall_patch(d, tables->sal_ed.pal_proc,
780 hypercalls_imva);
781 /* SAL entry point. */
782 tables->sal_ed.sal_proc = FW_HYPERCALL_SAL_CALL_PADDR;
783 dom_fw_hypercall_patch(d, tables->sal_ed.sal_proc,
784 FW_HYPERCALL_SAL_CALL, 1, hypercalls_imva);
785 tables->sal_ed.gp = 0; /* will be ignored */
787 /* Fill an AP wakeup descriptor. */
788 tables->sal_wakeup.type = SAL_DESC_AP_WAKEUP;
789 tables->sal_wakeup.mechanism = IA64_SAL_AP_EXTERNAL_INT;
790 tables->sal_wakeup.vector = XEN_SAL_BOOT_RENDEZ_VEC;
792 /* Compute checksum. */
793 checksum = 0;
794 for (cp = (char *)&tables->sal_systab;
795 cp < (char *)&tables->fpswa_inf;
796 ++cp)
797 checksum += *cp;
798 tables->sal_systab.checksum = -checksum;
800 /* SAL return point. */
801 dom_fw_hypercall_patch(d, FW_HYPERCALL_SAL_RETURN_PADDR,
802 FW_HYPERCALL_SAL_RETURN, 0, hypercalls_imva);
804 /* Fill in the FPSWA interface: */
805 if (fpswa_interface) {
806 tables->fpswa_inf.revision = fpswa_interface->revision;
807 dom_fpswa_hypercall_patch(d, hypercalls_imva);
808 tables->fpswa_inf.fpswa =
809 (void *)FW_HYPERCALL_FPSWA_ENTRY_PADDR;
810 }
812 i = 0; /* Used by MAKE_MD */
814 /* hypercall patches live here, masquerade as reserved PAL memory */
815 MAKE_MD(EFI_PAL_CODE,EFI_MEMORY_WB|EFI_MEMORY_RUNTIME,
816 FW_HYPERCALL_BASE_PADDR, FW_HYPERCALL_END_PADDR);
818 /* Create dom0/domu md entry for fw and cpi tables area. */
819 MAKE_MD(EFI_ACPI_MEMORY_NVS, EFI_MEMORY_WB | EFI_MEMORY_RUNTIME,
820 FW_ACPI_BASE_PADDR, FW_ACPI_END_PADDR);
821 MAKE_MD(EFI_RUNTIME_SERVICES_DATA, EFI_MEMORY_WB | EFI_MEMORY_RUNTIME,
822 FW_TABLES_BASE_PADDR, FW_TABLES_END_PADDR);
824 if (d != dom0 || running_on_sim) {
825 /* DomU (or hp-ski).
826 Create a continuous memory area. */
827 /* Memory. */
828 MAKE_MD(EFI_CONVENTIONAL_MEMORY, EFI_MEMORY_WB,
829 FW_END_PADDR, maxmem);
830 d->arch.convmem_end = maxmem;
832 /* Create an entry for IO ports. */
833 MAKE_MD(EFI_MEMORY_MAPPED_IO_PORT_SPACE, EFI_MEMORY_UC,
834 IO_PORTS_PADDR, IO_PORTS_PADDR + IO_PORTS_SIZE);
836 num_mds = i;
837 }
838 else {
839 /* Dom0.
840 We must preserve ACPI data from real machine,
841 as well as IO areas. */
842 num_mds = complete_dom0_memmap(d, tables, maxmem, i);
843 }
845 /* Display memmap. */
846 for (i = 0 ; i < num_mds; i++)
847 print_md(&tables->efi_memmap[i]);
849 /* Fill boot_param */
850 bp->efi_systab = FW_FIELD_MPA(efi_systab);
851 bp->efi_memmap = FW_FIELD_MPA(efi_memmap);
852 bp->efi_memmap_size = num_mds * sizeof(efi_memory_desc_t);
853 bp->efi_memdesc_size = sizeof(efi_memory_desc_t);
854 bp->efi_memdesc_version = EFI_MEMDESC_VERSION;
855 bp->command_line = 0;
856 bp->console_info.num_cols = 80;
857 bp->console_info.num_rows = 25;
858 bp->console_info.orig_x = 0;
859 bp->console_info.orig_y = 24;
860 if (fpswa_interface)
861 bp->fpswa = FW_FIELD_MPA(fpswa_inf);
862 }
864 void dom_fw_setup(struct domain *d, unsigned long bp_mpa, unsigned long maxmem)
865 {
866 struct ia64_boot_param *bp;
867 unsigned long imva_tables_base;
868 unsigned long imva_hypercall_base;
870 BUILD_BUG_ON(sizeof(struct fw_tables) >
871 (FW_TABLES_END_PADDR - FW_TABLES_BASE_PADDR));
873 BUILD_BUG_ON(sizeof(struct fake_acpi_tables) >
874 (FW_ACPI_END_PADDR - FW_ACPI_BASE_PADDR));
876 /* Create page for hypercalls. */
877 assign_new_domain_page_if_dom0(d, FW_HYPERCALL_BASE_PADDR);
878 imva_hypercall_base = (unsigned long)domain_mpa_to_imva
879 (d, FW_HYPERCALL_BASE_PADDR);
881 /* Create page for acpi tables. */
882 if (d != dom0) {
883 void *imva;
885 assign_new_domain_page_if_dom0(d, FW_ACPI_BASE_PADDR);
886 imva = domain_mpa_to_imva (d, FW_ACPI_BASE_PADDR);
887 dom_fw_fake_acpi(d, (struct fake_acpi_tables *)imva);
888 }
890 /* Create page for FW tables. */
891 assign_new_domain_page_if_dom0(d, FW_TABLES_BASE_PADDR);
892 imva_tables_base = (unsigned long)domain_mpa_to_imva
893 (d, FW_TABLES_BASE_PADDR);
895 /* Create page for boot_param. */
896 assign_new_domain_page_if_dom0(d, bp_mpa);
897 bp = domain_mpa_to_imva(d, bp_mpa);
899 dom_fw_init(d, bp, (struct fw_tables *)imva_tables_base,
900 imva_hypercall_base, maxmem);
901 }