diff --git a/include/xhyve/acpi.h b/include/xhyve/acpi.h index 11969af..12019f5 100644 --- a/include/xhyve/acpi.h +++ b/include/xhyve/acpi.h @@ -30,9 +30,6 @@ #include -/* if set, create AML instead of ASL and calling out to iasl */ -#define ACPITBL_AML 1 - #define SCI_INT 9 #define SMI_CMD 0xb2 @@ -45,13 +42,32 @@ #define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ -int acpi_build(int ncpu); -void dsdt_line(const char *fmt, ...); -void dsdt_fixed_ioport(uint16_t iobase, uint16_t length); -void dsdt_fixed_irq(uint8_t irq); -void dsdt_fixed_mem32(uint32_t base, uint32_t length); -void dsdt_indent(int levels); -void dsdt_unindent(int levels); -void dsdt_fixup(int bus, uint16_t iobase, uint16_t iolimit, uint32_t membase32, - uint32_t memlimit32, uint64_t membase64, uint64_t memlimit64); +extern char* asl_compiler_path; + +typedef int (*acpi_build_func_t)(int ncpu); +typedef void (*dsdt_line_func_t)(const char *fmt, ...); +typedef void (*dsdt_fixed_ioport_func_t)(uint16_t iobase, uint16_t length); +typedef void (*dsdt_fixed_irq_func_t)(uint8_t irq); +typedef void (*dsdt_fixed_mem32_func_t)(uint32_t base, uint32_t length); +typedef void (*dsdt_indent_func_t)(int levels); +typedef void (*dsdt_unindent_func_t)(int levels); +typedef void (*dsdt_fixup_func_t)(int bus, uint16_t iobase, uint16_t iolimit, uint32_t membase32, uint32_t memlimit32, + uint64_t membase64, uint64_t memlimit64); + +struct acpi_ops_t { + acpi_build_func_t acpi_build; + dsdt_line_func_t dsdt_line; + dsdt_fixed_ioport_func_t dsdt_fixed_ioport; + dsdt_fixed_irq_func_t dsdt_fixed_irq; + dsdt_fixed_mem32_func_t dsdt_fixed_mem32; + dsdt_indent_func_t dsdt_indent; + dsdt_unindent_func_t dsdt_unindent; + dsdt_fixup_func_t dsdt_fixup; +}; + +extern struct acpi_ops_t acpi_ops; +extern struct acpi_ops_t acpi_ops_compile; +extern struct acpi_ops_t acpi_ops_prebuilt_aml; + +void acpi_init(void); void sci_init(void); diff --git a/src/acpi.c b/src/acpi.c index 3d6a773..e2280d7 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -38,7 +38,9 @@ * The tables are placed in the guest's ROM area just below 1MB physical, * above the MPTable. * - * Layout + * Layout (No longer correct at FADT and beyond due to properly + * calculating the size of the MADT to allow for changes to + * VM_MAXCPU above 21 which overflows this layout.) * ------ * RSDP -> 0xf2400 (36 bytes fixed) * RSDT -> 0xf2440 (36 bytes + 4*7 table addrs, 4 used) @@ -67,22 +69,34 @@ #include /* - * Define the base address of the ACPI tables, and the offsets to - * the individual tables + * Define the base address of the ACPI tables, the sizes of some tables, + * and the offsets to the individual tables, */ #define BHYVE_ACPI_BASE 0xf2400 #define RSDT_OFFSET 0x040 #define XSDT_OFFSET 0x080 #define MADT_OFFSET 0x100 -#define FADT_OFFSET 0x200 -#define HPET_OFFSET 0x340 -#define MCFG_OFFSET 0x380 -#define FACS_OFFSET 0x3C0 -#define DSDT_OFFSET 0x400 +/* + * The MADT consists of: + * 44 Fixed Header + * 8 * maxcpu Processor Local APIC entries + * 12 I/O APIC entry + * 2 * 10 Interrupt Source Override entires + * 6 Local APIC NMI entry + */ +#define MADT_SIZE (44 + VM_MAXCPU*8 + 12 + 2*10 + 6) +#define FADT_OFFSET (MADT_OFFSET + MADT_SIZE) +#define FADT_SIZE 0x140 +#define HPET_OFFSET (FADT_OFFSET + FADT_SIZE) +#define HPET_SIZE 0x40 +#define MCFG_OFFSET (HPET_OFFSET + HPET_SIZE) +#define MCFG_SIZE 0x40 +#define FACS_OFFSET (MCFG_OFFSET + MCFG_SIZE) +#define FACS_SIZE 0x40 +#define DSDT_OFFSET (FACS_OFFSET + FACS_SIZE) #define BHYVE_ASL_TEMPLATE "bhyve.XXXXXXX" #define BHYVE_ASL_SUFFIX ".aml" -#define BHYVE_ASL_COMPILER "/usr/sbin/iasl" static int basl_keep_temps; static int basl_verbose_iasl; @@ -267,6 +281,7 @@ basl_fwrite_madt(FILE *fp) EFPRINTF(fp, "[0001]\t\tLocal Apic ID : %02x\n", i); EFPRINTF(fp, "[0004]\t\tFlags (decoded below) : 00000001\n"); EFPRINTF(fp, "\t\t\tProcessor Enabled : 1\n"); + EFPRINTF(fp, "\t\t\tRuntime Online Capable : 0\n"); EFPRINTF(fp, "\n"); } @@ -304,11 +319,11 @@ basl_fwrite_madt(FILE *fp) /* Local APIC NMI is connected to LINT 1 on all CPUs */ EFPRINTF(fp, "[0001]\t\tSubtable Type : 04\n"); EFPRINTF(fp, "[0001]\t\tLength : 06\n"); - EFPRINTF(fp, "[0001]\t\tProcessorId : FF\n"); + EFPRINTF(fp, "[0001]\t\tProcessor ID : FF\n"); EFPRINTF(fp, "[0002]\t\tFlags (decoded below) : 0005\n"); EFPRINTF(fp, "\t\t\tPolarity : 1\n"); EFPRINTF(fp, "\t\t\tTrigger Mode : 1\n"); - EFPRINTF(fp, "[0001]\t\tInterrupt : 01\n"); + EFPRINTF(fp, "[0001]\t\tInterrupt Input LINT : 01\n"); EFPRINTF(fp, "\n"); EFFLUSH(fp); @@ -563,7 +578,7 @@ basl_fwrite_hpet(FILE *fp) EFPRINTF(fp, "[0004]\t\tAsl Compiler Revision : 00000000\n"); EFPRINTF(fp, "\n"); - EFPRINTF(fp, "[0004]\t\tTimer Block ID : %08X\n", hpet_capabilities); + EFPRINTF(fp, "[0004]\t\tHardware Block ID : %08X\n", hpet_capabilities); EFPRINTF(fp, "[0012]\t\tTimer Block Register : [Generic Address Structure]\n"); EFPRINTF(fp, "[0001]\t\tSpace ID : 00 [SystemMemory]\n"); @@ -574,7 +589,7 @@ basl_fwrite_hpet(FILE *fp) EFPRINTF(fp, "[0008]\t\tAddress : 00000000FED00000\n"); EFPRINTF(fp, "\n"); - EFPRINTF(fp, "[0001]\t\tHPET Number : 00\n"); + EFPRINTF(fp, "[0001]\t\tSequence Number : 00\n"); EFPRINTF(fp, "[0002]\t\tMinimum Clock Ticks : 0000\n"); EFPRINTF(fp, "[0004]\t\tFlags (decoded below) : 00000001\n"); EFPRINTF(fp, "\t\t\t4K Page Protect : 1\n"); @@ -611,10 +626,10 @@ basl_fwrite_mcfg(FILE *fp) EFPRINTF(fp, "[0008]\t\tReserved : 0\n"); EFPRINTF(fp, "\n"); - EFPRINTF(fp, "[0008]\t\tBase Address : %016llx\n", pci_ecfg_base()); - EFPRINTF(fp, "[0002]\t\tSegment Group: 0000\n"); - EFPRINTF(fp, "[0001]\t\tStart Bus: 00\n"); - EFPRINTF(fp, "[0001]\t\tEnd Bus: FF\n"); + EFPRINTF(fp, "[0008]\t\tBase Address : %016llX\n", pci_ecfg_base()); + EFPRINTF(fp, "[0002]\t\tSegment Group Number : 0000\n"); + EFPRINTF(fp, "[0001]\t\tStart Bus Number : 00\n"); + EFPRINTF(fp, "[0001]\t\tEnd Bus Number : FF\n"); EFPRINTF(fp, "[0004]\t\tReserved : 0\n"); EFFLUSH(fp); return (0); @@ -660,7 +675,7 @@ basl_fwrite_facs(FILE *fp) /* * Helper routines for writing to the DSDT from other modules. */ -void +static void dsdt_line(const char *fmt, ...) { va_list ap; @@ -675,8 +690,10 @@ dsdt_line(const char *fmt, ...) if (dsdt_indent_level != 0) EFPRINTF(dsdt_fp, "%*c", dsdt_indent_level * 2, ' '); va_start(ap, fmt); - if (vfprintf(dsdt_fp, fmt, ap) < 0) + if (vfprintf(dsdt_fp, fmt, ap) < 0) { + va_end(ap); goto err_exit; + } va_end(ap); } EFPRINTF(dsdt_fp, "\n"); @@ -687,7 +704,7 @@ dsdt_line(const char *fmt, ...) } #pragma clang diagnostic pop -void +static void dsdt_indent(int levels) { @@ -695,7 +712,7 @@ dsdt_indent(int levels) assert(dsdt_indent_level >= 0); } -void +static void dsdt_unindent(int levels) { @@ -703,7 +720,7 @@ dsdt_unindent(int levels) dsdt_indent_level -= levels; } -void +static void dsdt_fixed_ioport(uint16_t iobase, uint16_t length) { @@ -715,7 +732,7 @@ dsdt_fixed_ioport(uint16_t iobase, uint16_t length) dsdt_line(" )"); } -void +static void dsdt_fixed_irq(uint8_t irq) { @@ -723,7 +740,7 @@ dsdt_fixed_irq(uint8_t irq) dsdt_line(" {%d}", irq); } -void +static void dsdt_fixed_mem32(uint32_t base, uint32_t length) { @@ -892,7 +909,7 @@ basl_compile(int (*fwrite_section)(FILE *), uint64_t offset) snprintf(iaslbuf, sizeof(iaslbuf), fmt, - BHYVE_ASL_COMPILER, + asl_compiler_path, io[1].f_name, io[0].f_name); err = system(iaslbuf); @@ -911,6 +928,11 @@ basl_compile(int (*fwrite_section)(FILE *), uint64_t offset) } #pragma clang diagnostic pop +static void dsdt_fixup(UNUSED int bus, UNUSED uint16_t iobase, UNUSED uint16_t iolimit, UNUSED uint32_t membase32, + UNUSED uint32_t memlimit32, UNUSED uint64_t membase64, UNUSED uint64_t memlimit64) { + +} + static int basl_make_templates(void) { @@ -974,7 +996,7 @@ static struct { { NULL , 0} }; -int +static int acpi_build(int ncpu) { int err; @@ -1015,3 +1037,25 @@ acpi_build(int ncpu) return (err); } + +struct acpi_ops_t acpi_ops; + +struct acpi_ops_t acpi_ops_compile = { + acpi_build, + dsdt_line, + dsdt_fixed_ioport, + dsdt_fixed_irq, + dsdt_fixed_mem32, + dsdt_indent, + dsdt_unindent, + dsdt_fixup +}; + +void acpi_init(void) +{ + if (asl_compiler_path != NULL) { + acpi_ops = acpi_ops_compile; + } else { + acpi_ops = acpi_ops_prebuilt_aml; + } +} diff --git a/src/acpitbl.c b/src/acpitbl.c index 48bfd74..b3ae6a0 100644 --- a/src/acpitbl.c +++ b/src/acpitbl.c @@ -65,14 +65,14 @@ #define XHYVE_ACPI_BASE 0xf2400 #define XHYVE_ACPI_SIZE 0xdc00 -#define RSDT_OFFSET 0x040 -#define XSDT_OFFSET 0x080 -#define MADT_OFFSET 0x100 -#define FADT_OFFSET 0x200 -#define HPET_OFFSET 0x340 -#define MCFG_OFFSET 0x380 -#define FACS_OFFSET 0x3C0 -#define DSDT_OFFSET 0x400 +#define XHYVE_AML_RSDT_OFFSET 0x040 +#define XHYVE_AML_XSDT_OFFSET 0x080 +#define XHYVE_AML_MADT_OFFSET 0x100 +#define XHYVE_AML_FADT_OFFSET 0x200 +#define XHYVE_AML_HPET_OFFSET 0x340 +#define XHYVE_AML_MCFG_OFFSET 0x380 +#define XHYVE_AML_FACS_OFFSET 0x3C0 +#define XHYVE_AML_DSDT_OFFSET 0x400 /* ACPI table base in guest memory */ static void *tb; @@ -80,32 +80,32 @@ static int acpi_ncpu; static uint32_t hpet_capabilities; static void *dsdt; -void +static void dsdt_line(UNUSED const char *fmt, ...) { } -void +static void dsdt_fixed_ioport(UNUSED uint16_t iobase, UNUSED uint16_t length) { } -void +static void dsdt_fixed_irq(UNUSED uint8_t irq) { } -void +static void dsdt_fixed_mem32(UNUSED uint32_t base, UNUSED uint32_t length) { } -void +static void dsdt_indent(UNUSED int levels) { } -void dsdt_unindent(UNUSED int levels) +static void dsdt_unindent(UNUSED int levels) { } @@ -167,8 +167,8 @@ acpitbl_build_rdsp(void) { /* copy RDSP template to guest memory */ memcpy(rdsp, rdsp_tmpl, 36); /* fixup table */ - acpitbl_write32(rdsp, 0x10, ((uint32_t) (XHYVE_ACPI_BASE + RSDT_OFFSET))); - acpitbl_write64(rdsp, 0x18, ((uint64_t) (XHYVE_ACPI_BASE + XSDT_OFFSET))); + acpitbl_write32(rdsp, 0x10, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_RSDT_OFFSET))); + acpitbl_write64(rdsp, 0x18, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_XSDT_OFFSET))); /* write checksum */ acpitbl_write8(rdsp, 0x8, acpitbl_checksum(rdsp, 20)); /* write extended checksum */ @@ -203,14 +203,14 @@ acpitbl_build_rsdt(void) { 0x00, 0x00, 0x00, 0x00 }; - rsdt = (void *) (((uintptr_t) tb) + RSDT_OFFSET); + rsdt = (void *) (((uintptr_t) tb) + XHYVE_AML_RSDT_OFFSET); /* copy RSDT template to guest memory */ memcpy(rsdt, rsdt_tmpl, 52); /* fixup table */ - acpitbl_write32(rsdt, 0x24, ((uint32_t) (XHYVE_ACPI_BASE + MADT_OFFSET))); - acpitbl_write32(rsdt, 0x28, ((uint32_t) (XHYVE_ACPI_BASE + FADT_OFFSET))); - acpitbl_write32(rsdt, 0x2c, ((uint32_t) (XHYVE_ACPI_BASE + HPET_OFFSET))); - acpitbl_write32(rsdt, 0x30, ((uint32_t) (XHYVE_ACPI_BASE + MCFG_OFFSET))); + acpitbl_write32(rsdt, 0x24, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_MADT_OFFSET))); + acpitbl_write32(rsdt, 0x28, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_FADT_OFFSET))); + acpitbl_write32(rsdt, 0x2c, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_HPET_OFFSET))); + acpitbl_write32(rsdt, 0x30, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_MCFG_OFFSET))); /* write checksum */ acpitbl_write8(rsdt, 0x9, acpitbl_checksum(rsdt, 52)); } @@ -245,14 +245,14 @@ acpitbl_build_xsdt(void) { 0x00, 0x00, 0x00, 0x00 }; - xsdt = (void *) (((uintptr_t) tb) + XSDT_OFFSET); + xsdt = (void *) (((uintptr_t) tb) + XHYVE_AML_XSDT_OFFSET); /* copy XSDT template to guest memory */ memcpy(xsdt, xsdt_tmpl, 68); /* fixup table */ - acpitbl_write64(xsdt, 0x24, ((uint64_t) (XHYVE_ACPI_BASE + MADT_OFFSET))); - acpitbl_write64(xsdt, 0x2c, ((uint64_t) (XHYVE_ACPI_BASE + FADT_OFFSET))); - acpitbl_write64(xsdt, 0x34, ((uint64_t) (XHYVE_ACPI_BASE + HPET_OFFSET))); - acpitbl_write64(xsdt, 0x3c, ((uint64_t) (XHYVE_ACPI_BASE + MCFG_OFFSET))); + acpitbl_write64(xsdt, 0x24, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_MADT_OFFSET))); + acpitbl_write64(xsdt, 0x2c, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_FADT_OFFSET))); + acpitbl_write64(xsdt, 0x34, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_HPET_OFFSET))); + acpitbl_write64(xsdt, 0x3c, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_MCFG_OFFSET))); /* write checksum */ acpitbl_write8(xsdt, 0x9, acpitbl_checksum(xsdt, 68)); } @@ -333,13 +333,13 @@ acpitbl_build_madt(void) { 0x04, 0x06, 0xFF, 0x05, 0x00, 0x01 }; - madt_head = (void *) (((uintptr_t) tb) + MADT_OFFSET); + madt_head = (void *) (((uintptr_t) tb) + XHYVE_AML_MADT_OFFSET); /* copy MADT head template to guest memory */ memcpy(madt_head, madt_head_tmpl, 44); for (i = 0; i < acpi_ncpu; i++) { madt_apic = (void *) (((uintptr_t) tb) - + ((size_t) ((MADT_OFFSET + 44) + (8 * i)))); + + ((size_t) ((XHYVE_AML_MADT_OFFSET + 44) + (8 * i)))); /* copy MADT APIC template to guest memory */ memcpy(madt_apic, madt_apic_tmpl, 8); /* fixup table */ @@ -348,7 +348,7 @@ acpitbl_build_madt(void) { } madt_tail = (void *) (((uintptr_t) tb) - + ((size_t) ((MADT_OFFSET + 44) + (8 * acpi_ncpu)))); + + ((size_t) ((XHYVE_AML_MADT_OFFSET + 44) + (8 * acpi_ncpu)))); /* copy MADT tail template to guest memory */ memcpy(madt_tail, madt_tail_tmpl, 38); /* fixup table */ @@ -545,12 +545,12 @@ acpitbl_build_fadt(void) { 0x00, 0x00, 0x00, 0x00 }; - fadt = (void *) (((uintptr_t) tb) + FADT_OFFSET); + fadt = (void *) (((uintptr_t) tb) + XHYVE_AML_FADT_OFFSET); /* copy FADT template to guest memory */ memcpy(fadt, fadt_tmpl, 268); /* fixup table */ - acpitbl_write32(fadt, 0x24, ((uint32_t) (XHYVE_ACPI_BASE + FACS_OFFSET))); - acpitbl_write32(fadt, 0x28, ((uint32_t) (XHYVE_ACPI_BASE + DSDT_OFFSET))); + acpitbl_write32(fadt, 0x24, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_FACS_OFFSET))); + acpitbl_write32(fadt, 0x28, ((uint32_t) (XHYVE_ACPI_BASE + XHYVE_AML_DSDT_OFFSET))); acpitbl_write16(fadt, 0x2e, SCI_INT); acpitbl_write32(fadt, 0x30, SMI_CMD); acpitbl_write8(fadt, 0x34, BHYVE_ACPI_ENABLE); @@ -558,8 +558,8 @@ acpitbl_build_fadt(void) { acpitbl_write32(fadt, 0x38, PM1A_EVT_ADDR); acpitbl_write32(fadt, 0x40, PM1A_CNT_ADDR); acpitbl_write32(fadt, 0x4c, IO_PMTMR); - acpitbl_write64(fadt, 0x84, ((uint64_t) (XHYVE_ACPI_BASE + FACS_OFFSET))); - acpitbl_write64(fadt, 0x8c, ((uint64_t) (XHYVE_ACPI_BASE + DSDT_OFFSET))); + acpitbl_write64(fadt, 0x84, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_FACS_OFFSET))); + acpitbl_write64(fadt, 0x8c, ((uint64_t) (XHYVE_ACPI_BASE + XHYVE_AML_DSDT_OFFSET))); acpitbl_write64(fadt, 0x98, ((uint64_t) PM1A_EVT_ADDR)); acpitbl_write64(fadt, 0xb0, ((uint64_t) PM1A_CNT_ADDR)); acpitbl_write64(fadt, 0xd4, ((uint64_t) IO_PMTMR)); @@ -603,7 +603,7 @@ acpitbl_build_hpet(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; - hpet = (void *) (((uintptr_t) tb) + HPET_OFFSET); + hpet = (void *) (((uintptr_t) tb) + XHYVE_AML_HPET_OFFSET); /* copy HPET template to guest memory */ memcpy(hpet, hpet_tmpl, 56); /* fixup table */ @@ -643,7 +643,7 @@ acpitbl_build_mcfg(void) { 0x00, 0x00, 0x00, 0x00 }; - mcfg = (void *) (((uintptr_t) tb) + MCFG_OFFSET); + mcfg = (void *) (((uintptr_t) tb) + XHYVE_AML_MCFG_OFFSET); /* copy MCFG template to guest memory */ memcpy(mcfg, mcfg_tmpl, 60); /* fixup table */ @@ -681,12 +681,12 @@ acpitbl_build_facs(void) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - facs = (void *) (((uintptr_t) tb) + FACS_OFFSET); + facs = (void *) (((uintptr_t) tb) + XHYVE_AML_FACS_OFFSET); /* copy MCFG template to guest memory */ memcpy(facs, facs_tmpl, 64); } -void dsdt_fixup(int bus, uint16_t iobase, uint16_t iolimit, uint32_t membase32, +static void dsdt_fixup(int bus, uint16_t iobase, uint16_t iolimit, uint32_t membase32, uint32_t memlimit32, uint64_t membase64, uint64_t memlimit64) { if (bus != 0) { @@ -1036,7 +1036,7 @@ acpitbl_build_dsdt(void) { 0x04, 0x00, 0x00, 0x79 }; - dsdt = (void *) (((uintptr_t) tb) + DSDT_OFFSET); + dsdt = (void *) (((uintptr_t) tb) + XHYVE_AML_DSDT_OFFSET); /* copy DSDT template to guest memory */ memcpy(dsdt, dsdt_tmpl, 2604); @@ -1046,7 +1046,7 @@ acpitbl_build_dsdt(void) { acpitbl_write8(dsdt, 0x9, acpitbl_checksum(dsdt, 2604)); } -int +static int acpi_build(int ncpu) { int err; @@ -1074,3 +1074,14 @@ acpi_build(int ncpu) return 0; } + +struct acpi_ops_t acpi_ops_prebuilt_aml = { + acpi_build, + dsdt_line, + dsdt_fixed_ioport, + dsdt_fixed_irq, + dsdt_fixed_mem32, + dsdt_indent, + dsdt_unindent, + dsdt_fixup +}; diff --git a/src/atkbdc.c b/src/atkbdc.c index a3faaf8..b56e300 100644 --- a/src/atkbdc.c +++ b/src/atkbdc.c @@ -550,33 +550,33 @@ static void atkbdc_dsdt(void) { - dsdt_line(""); - dsdt_line("Device (KBD)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0303\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(KBD_DATA_PORT, 1); - dsdt_fixed_ioport(KBD_STS_CTL_PORT, 1); - dsdt_fixed_irq(1); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); - - dsdt_line(""); - dsdt_line("Device (MOU)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0F13\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(KBD_DATA_PORT, 1); - dsdt_fixed_ioport(KBD_STS_CTL_PORT, 1); - dsdt_fixed_irq(12); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (KBD)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0303\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(KBD_DATA_PORT, 1); + acpi_ops.dsdt_fixed_ioport(KBD_STS_CTL_PORT, 1); + acpi_ops.dsdt_fixed_irq(1); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); + + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (MOU)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0F13\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(KBD_DATA_PORT, 1); + acpi_ops.dsdt_fixed_ioport(KBD_STS_CTL_PORT, 1); + acpi_ops.dsdt_fixed_irq(12); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); } LPC_DSDT(atkbdc_dsdt); diff --git a/src/pci_emul.c b/src/pci_emul.c index bf7d028..e874cf9 100644 --- a/src/pci_emul.c +++ b/src/pci_emul.c @@ -1185,13 +1185,13 @@ pci_apic_prt_entry(UNUSED int bus, int slot, int pin, UNUSED int pirq_pin, int ioapic_irq, UNUSED void *arg) { - dsdt_line(" Package ()"); - dsdt_line(" {"); - dsdt_line(" 0x%X,", slot << 16 | 0xffff); - dsdt_line(" 0x%02X,", pin - 1); - dsdt_line(" Zero,"); - dsdt_line(" 0x%X", ioapic_irq); - dsdt_line(" },"); + acpi_ops.dsdt_line(" Package ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" 0x%X,", slot << 16 | 0xffff); + acpi_ops.dsdt_line(" 0x%02X,", pin - 1); + acpi_ops.dsdt_line(" Zero,"); + acpi_ops.dsdt_line(" 0x%X", ioapic_irq); + acpi_ops.dsdt_line(" },"); } static void @@ -1203,25 +1203,19 @@ pci_pirq_prt_entry(UNUSED int bus, int slot, int pin, int pirq_pin, name = lpc_pirq_name(pirq_pin); if (name == NULL) return; - dsdt_line(" Package ()"); - dsdt_line(" {"); - dsdt_line(" 0x%X,", slot << 16 | 0xffff); - dsdt_line(" 0x%02X,", pin - 1); - dsdt_line(" %s,", name); - dsdt_line(" 0x00"); - dsdt_line(" },"); + acpi_ops.dsdt_line(" Package ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" 0x%X,", slot << 16 | 0xffff); + acpi_ops.dsdt_line(" 0x%02X,", pin - 1); + acpi_ops.dsdt_line(" %s,", name); + acpi_ops.dsdt_line(" 0x00"); + acpi_ops.dsdt_line(" },"); free(name); } -/* - * A bhyve virtual machine has a flat PCI hierarchy with a root port - * corresponding to each PCI bus. - */ -#if ACPITBL_AML static void -pci_bus_write_dsdt(int bus) -{ - struct businfo *bi; +pci_bus_write_dsdt_precompiled(int bus) { + struct businfo *bi; /* * If there are no devices on this 'bus' then just return. @@ -1236,15 +1230,16 @@ pci_bus_write_dsdt(int bus) return; } - dsdt_fixup(bus, bi->iobase, bi->iolimit, bi->membase32, bi->memlimit32, + acpi_ops.dsdt_fixup(bus, bi->iobase, bi->iolimit, bi->membase32, bi->memlimit32, bi->membase64, bi->memlimit64); (void) pci_pirq_prt_entry; (void) pci_apic_prt_entry; } -#else + + static void -pci_bus_write_dsdt(int bus) +pci_bus_write_dsdt_compile(int bus) { struct businfo *bi; struct slotinfo *si; @@ -1264,121 +1259,121 @@ pci_bus_write_dsdt(int bus) return; } - dsdt_line(" Device (PC%02X)", bus); - dsdt_line(" {"); - dsdt_line(" Name (_HID, EisaId (\"PNP0A03\"))"); - dsdt_line(" Name (_ADR, Zero)"); - - dsdt_line(" Method (_BBN, 0, NotSerialized)"); - dsdt_line(" {"); - dsdt_line(" Return (0x%08X)", bus); - dsdt_line(" }"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_line(" WordBusNumber (ResourceProducer, MinFixed, " + acpi_ops.dsdt_line(" Device (PC%02X)", bus); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0A03\"))"); + acpi_ops.dsdt_line(" Name (_ADR, Zero)"); + + acpi_ops.dsdt_line(" Method (_BBN, 0, NotSerialized)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x%08X)", bus); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" WordBusNumber (ResourceProducer, MinFixed, " "MaxFixed, PosDecode,"); - dsdt_line(" 0x0000, // Granularity"); - dsdt_line(" 0x%04X, // Range Minimum", bus); - dsdt_line(" 0x%04X, // Range Maximum", bus); - dsdt_line(" 0x0000, // Translation Offset"); - dsdt_line(" 0x0001, // Length"); - dsdt_line(" ,, )"); + acpi_ops.dsdt_line(" 0x0000, // Granularity"); + acpi_ops.dsdt_line(" 0x%04X, // Range Minimum", bus); + acpi_ops.dsdt_line(" 0x%04X, // Range Maximum", bus); + acpi_ops.dsdt_line(" 0x0000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x0001, // Length"); + acpi_ops.dsdt_line(" ,, )"); if (bus == 0) { - dsdt_indent(3); - dsdt_fixed_ioport(0xCF8, 8); - dsdt_unindent(3); + acpi_ops.dsdt_indent(3); + acpi_ops.dsdt_fixed_ioport(0xCF8, 8); + acpi_ops.dsdt_unindent(3); - dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " + acpi_ops.dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " "PosDecode, EntireRange,"); - dsdt_line(" 0x0000, // Granularity"); - dsdt_line(" 0x0000, // Range Minimum"); - dsdt_line(" 0x0CF7, // Range Maximum"); - dsdt_line(" 0x0000, // Translation Offset"); - dsdt_line(" 0x0CF8, // Length"); - dsdt_line(" ,, , TypeStatic)"); - - dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " + acpi_ops.dsdt_line(" 0x0000, // Granularity"); + acpi_ops.dsdt_line(" 0x0000, // Range Minimum"); + acpi_ops.dsdt_line(" 0x0CF7, // Range Maximum"); + acpi_ops.dsdt_line(" 0x0000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x0CF8, // Length"); + acpi_ops.dsdt_line(" ,, , TypeStatic)"); + + acpi_ops.dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " "PosDecode, EntireRange,"); - dsdt_line(" 0x0000, // Granularity"); - dsdt_line(" 0x0D00, // Range Minimum"); - dsdt_line(" 0x%04X, // Range Maximum", + acpi_ops.dsdt_line(" 0x0000, // Granularity"); + acpi_ops.dsdt_line(" 0x0D00, // Range Minimum"); + acpi_ops.dsdt_line(" 0x%04X, // Range Maximum", PCI_EMUL_IOBASE - 1); - dsdt_line(" 0x0000, // Translation Offset"); - dsdt_line(" 0x%04X, // Length", + acpi_ops.dsdt_line(" 0x0000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x%04X, // Length", PCI_EMUL_IOBASE - 0x0D00); - dsdt_line(" ,, , TypeStatic)"); + acpi_ops.dsdt_line(" ,, , TypeStatic)"); if (bi == NULL) { - dsdt_line(" })"); + acpi_ops.dsdt_line(" })"); goto done; } } assert(bi != NULL); /* i/o window */ - dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " + acpi_ops.dsdt_line(" WordIO (ResourceProducer, MinFixed, MaxFixed, " "PosDecode, EntireRange,"); - dsdt_line(" 0x0000, // Granularity"); - dsdt_line(" 0x%04X, // Range Minimum", bi->iobase); - dsdt_line(" 0x%04X, // Range Maximum", + acpi_ops.dsdt_line(" 0x0000, // Granularity"); + acpi_ops.dsdt_line(" 0x%04X, // Range Minimum", bi->iobase); + acpi_ops.dsdt_line(" 0x%04X, // Range Maximum", bi->iolimit - 1); - dsdt_line(" 0x0000, // Translation Offset"); - dsdt_line(" 0x%04X, // Length", + acpi_ops.dsdt_line(" 0x0000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x%04X, // Length", bi->iolimit - bi->iobase); - dsdt_line(" ,, , TypeStatic)"); + acpi_ops.dsdt_line(" ,, , TypeStatic)"); /* mmio window (32-bit) */ - dsdt_line(" DWordMemory (ResourceProducer, PosDecode, " + acpi_ops.dsdt_line(" DWordMemory (ResourceProducer, PosDecode, " "MinFixed, MaxFixed, NonCacheable, ReadWrite,"); - dsdt_line(" 0x00000000, // Granularity"); - dsdt_line(" 0x%08X, // Range Minimum\n", bi->membase32); - dsdt_line(" 0x%08X, // Range Maximum\n", + acpi_ops.dsdt_line(" 0x00000000, // Granularity"); + acpi_ops.dsdt_line(" 0x%08X, // Range Minimum\n", bi->membase32); + acpi_ops.dsdt_line(" 0x%08X, // Range Maximum\n", bi->memlimit32 - 1); - dsdt_line(" 0x00000000, // Translation Offset"); - dsdt_line(" 0x%08X, // Length\n", + acpi_ops.dsdt_line(" 0x00000000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x%08X, // Length\n", bi->memlimit32 - bi->membase32); - dsdt_line(" ,, , AddressRangeMemory, TypeStatic)"); + acpi_ops.dsdt_line(" ,, , AddressRangeMemory, TypeStatic)"); /* mmio window (64-bit) */ - dsdt_line(" QWordMemory (ResourceProducer, PosDecode, " + acpi_ops.dsdt_line(" QWordMemory (ResourceProducer, PosDecode, " "MinFixed, MaxFixed, NonCacheable, ReadWrite,"); - dsdt_line(" 0x0000000000000000, // Granularity"); - dsdt_line(" 0x%016lX, // Range Minimum\n", bi->membase64); - dsdt_line(" 0x%016lX, // Range Maximum\n", + acpi_ops.dsdt_line(" 0x0000000000000000, // Granularity"); + acpi_ops.dsdt_line(" 0x%016lX, // Range Minimum\n", bi->membase64); + acpi_ops.dsdt_line(" 0x%016lX, // Range Maximum\n", bi->memlimit64 - 1); - dsdt_line(" 0x0000000000000000, // Translation Offset"); - dsdt_line(" 0x%016lX, // Length\n", + acpi_ops.dsdt_line(" 0x0000000000000000, // Translation Offset"); + acpi_ops.dsdt_line(" 0x%016lX, // Length\n", bi->memlimit64 - bi->membase64); - dsdt_line(" ,, , AddressRangeMemory, TypeStatic)"); - dsdt_line(" })"); + acpi_ops.dsdt_line(" ,, , AddressRangeMemory, TypeStatic)"); + acpi_ops.dsdt_line(" })"); count = pci_count_lintr(bus); if (count != 0) { - dsdt_indent(2); - dsdt_line("Name (PPRT, Package ()"); - dsdt_line("{"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_line("Name (PPRT, Package ()"); + acpi_ops.dsdt_line("{"); pci_walk_lintr(bus, pci_pirq_prt_entry, NULL); - dsdt_line("})"); - dsdt_line("Name (APRT, Package ()"); - dsdt_line("{"); + acpi_ops.dsdt_line("})"); + acpi_ops.dsdt_line("Name (APRT, Package ()"); + acpi_ops.dsdt_line("{"); pci_walk_lintr(bus, pci_apic_prt_entry, NULL); - dsdt_line("})"); - dsdt_line("Method (_PRT, 0, NotSerialized)"); - dsdt_line("{"); - dsdt_line(" If (PICM)"); - dsdt_line(" {"); - dsdt_line(" Return (APRT)"); - dsdt_line(" }"); - dsdt_line(" Else"); - dsdt_line(" {"); - dsdt_line(" Return (PPRT)"); - dsdt_line(" }"); - dsdt_line("}"); - dsdt_unindent(2); + acpi_ops.dsdt_line("})"); + acpi_ops.dsdt_line("Method (_PRT, 0, NotSerialized)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" If (PICM)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (APRT)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Else"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (PPRT)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line("}"); + acpi_ops.dsdt_unindent(2); } - dsdt_indent(2); + acpi_ops.dsdt_indent(2); for (slot = 0; slot < MAXSLOTS; slot++) { si = &bi->slotinfo[slot]; for (func = 0; func < MAXFUNCS; func++) { @@ -1387,15 +1382,27 @@ pci_bus_write_dsdt(int bus) pi->pi_d->pe_write_dsdt(pi); } } - dsdt_unindent(2); + acpi_ops.dsdt_unindent(2); done: - dsdt_line(" }"); + acpi_ops.dsdt_line(" }"); +} + +/* + * A bhyve virtual machine has a flat PCI hierarchy with a root port + * corresponding to each PCI bus. + */ +static void +pci_bus_write_dsdt(int bus) +{ + if (asl_compiler_path == NULL) { + pci_bus_write_dsdt_precompiled(bus); + } else { + pci_bus_write_dsdt_compile(bus); + } } -#endif -#if ACPITBL_AML void -pci_write_dsdt(void) +pci_write_dsdt_precompiled(void) { int bus; @@ -1403,27 +1410,34 @@ pci_write_dsdt(void) pci_bus_write_dsdt(bus); } } -#else void -pci_write_dsdt(void) +pci_write_dsdt_compile(void) { int bus; - dsdt_indent(1); - dsdt_line("Name (PICM, 0x00)"); - dsdt_line("Method (_PIC, 1, NotSerialized)"); - dsdt_line("{"); - dsdt_line(" Store (Arg0, PICM)"); - dsdt_line("}"); - dsdt_line(""); - dsdt_line("Scope (_SB)"); - dsdt_line("{"); + acpi_ops.dsdt_indent(1); + acpi_ops.dsdt_line("Name (PICM, 0x00)"); + acpi_ops.dsdt_line("Method (_PIC, 1, NotSerialized)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Store (Arg0, PICM)"); + acpi_ops.dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Scope (_SB)"); + acpi_ops.dsdt_line("{"); for (bus = 0; bus < MAXBUSES; bus++) pci_bus_write_dsdt(bus); - dsdt_line("}"); - dsdt_unindent(1); + acpi_ops.dsdt_line("}"); + acpi_ops.dsdt_unindent(1); +} + +void +pci_write_dsdt(void) { + if (asl_compiler_path == NULL) { + pci_write_dsdt_precompiled(); + } else { + pci_write_dsdt_compile(); + } } -#endif int pci_bus_configured(int bus) diff --git a/src/pci_irq.c b/src/pci_irq.c index 7015bdd..387f0c8 100644 --- a/src/pci_irq.c +++ b/src/pci_irq.c @@ -261,83 +261,83 @@ pirq_dsdt(void) * A helper method to validate a link register's value. This * duplicates pirq_valid_irq(). */ - dsdt_line(""); - dsdt_line("Method (PIRV, 1, NotSerialized)"); - dsdt_line("{"); - dsdt_line(" If (And (Arg0, 0x%02X))", PIRQ_DIS); - dsdt_line(" {"); - dsdt_line(" Return (0x00)"); - dsdt_line(" }"); - dsdt_line(" And (Arg0, 0x%02X, Local0)", PIRQ_IRQ); - dsdt_line(" If (LLess (Local0, 0x03))"); - dsdt_line(" {"); - dsdt_line(" Return (0x00)"); - dsdt_line(" }"); - dsdt_line(" If (LEqual (Local0, 0x08))"); - dsdt_line(" {"); - dsdt_line(" Return (0x00)"); - dsdt_line(" }"); - dsdt_line(" If (LEqual (Local0, 0x0D))"); - dsdt_line(" {"); - dsdt_line(" Return (0x00)"); - dsdt_line(" }"); - dsdt_line(" Return (0x01)"); - dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Method (PIRV, 1, NotSerialized)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" If (And (Arg0, 0x%02X))", PIRQ_DIS); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x00)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" And (Arg0, 0x%02X, Local0)", PIRQ_IRQ); + acpi_ops.dsdt_line(" If (LLess (Local0, 0x03))"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x00)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" If (LEqual (Local0, 0x08))"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x00)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" If (LEqual (Local0, 0x0D))"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x00)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Return (0x01)"); + acpi_ops.dsdt_line("}"); for (pin = 0; ((unsigned) pin) < nitems(pirqs); pin++) { - dsdt_line(""); - dsdt_line("Device (LNK%c)", 'A' + pin); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0C0F\"))"); - dsdt_line(" Name (_UID, 0x%02X)", pin + 1); - dsdt_line(" Method (_STA, 0, NotSerialized)"); - dsdt_line(" {"); - dsdt_line(" If (PIRV (PIR%c))", 'A' + pin); - dsdt_line(" {"); - dsdt_line(" Return (0x0B)"); - dsdt_line(" }"); - dsdt_line(" Else"); - dsdt_line(" {"); - dsdt_line(" Return (0x09)"); - dsdt_line(" }"); - dsdt_line(" }"); - dsdt_line(" Name (_PRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_line(" IRQ (Level, ActiveLow, Shared, )"); - dsdt_line(" {%s}", irq_prs); - dsdt_line(" })"); - dsdt_line(" Name (CB%02X, ResourceTemplate ()", pin + 1); - dsdt_line(" {"); - dsdt_line(" IRQ (Level, ActiveLow, Shared, )"); - dsdt_line(" {}"); - dsdt_line(" })"); - dsdt_line(" CreateWordField (CB%02X, 0x01, CIR%c)", + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (LNK%c)", 'A' + pin); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0C0F\"))"); + acpi_ops.dsdt_line(" Name (_UID, 0x%02X)", pin + 1); + acpi_ops.dsdt_line(" Method (_STA, 0, NotSerialized)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" If (PIRV (PIR%c))", 'A' + pin); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x0B)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Else"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Return (0x09)"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Name (_PRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" IRQ (Level, ActiveLow, Shared, )"); + acpi_ops.dsdt_line(" {%s}", irq_prs); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line(" Name (CB%02X, ResourceTemplate ()", pin + 1); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" IRQ (Level, ActiveLow, Shared, )"); + acpi_ops.dsdt_line(" {}"); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line(" CreateWordField (CB%02X, 0x01, CIR%c)", pin + 1, 'A' + pin); - dsdt_line(" Method (_CRS, 0, NotSerialized)"); - dsdt_line(" {"); - dsdt_line(" And (PIR%c, 0x%02X, Local0)", 'A' + pin, + acpi_ops.dsdt_line(" Method (_CRS, 0, NotSerialized)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" And (PIR%c, 0x%02X, Local0)", 'A' + pin, PIRQ_DIS | PIRQ_IRQ); - dsdt_line(" If (PIRV (Local0))"); - dsdt_line(" {"); - dsdt_line(" ShiftLeft (0x01, Local0, CIR%c)", 'A' + pin); - dsdt_line(" }"); - dsdt_line(" Else"); - dsdt_line(" {"); - dsdt_line(" Store (0x00, CIR%c)", 'A' + pin); - dsdt_line(" }"); - dsdt_line(" Return (CB%02X)", pin + 1); - dsdt_line(" }"); - dsdt_line(" Method (_DIS, 0, NotSerialized)"); - dsdt_line(" {"); - dsdt_line(" Store (0x80, PIR%c)", 'A' + pin); - dsdt_line(" }"); - dsdt_line(" Method (_SRS, 1, NotSerialized)"); - dsdt_line(" {"); - dsdt_line(" CreateWordField (Arg0, 0x01, SIR%c)", 'A' + pin); - dsdt_line(" FindSetRightBit (SIR%c, Local0)", 'A' + pin); - dsdt_line(" Store (Decrement (Local0), PIR%c)", 'A' + pin); - dsdt_line(" }"); - dsdt_line("}"); + acpi_ops.dsdt_line(" If (PIRV (Local0))"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" ShiftLeft (0x01, Local0, CIR%c)", 'A' + pin); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Else"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Store (0x00, CIR%c)", 'A' + pin); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Return (CB%02X)", pin + 1); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Method (_DIS, 0, NotSerialized)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Store (0x80, PIR%c)", 'A' + pin); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(" Method (_SRS, 1, NotSerialized)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" CreateWordField (Arg0, 0x01, SIR%c)", 'A' + pin); + acpi_ops.dsdt_line(" FindSetRightBit (SIR%c, Local0)", 'A' + pin); + acpi_ops.dsdt_line(" Store (Decrement (Local0), PIR%c)", 'A' + pin); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line("}"); } free(irq_prs); } diff --git a/src/pci_lpc.c b/src/pci_lpc.c index 427cf46..9df7c6c 100644 --- a/src/pci_lpc.c +++ b/src/pci_lpc.c @@ -224,61 +224,61 @@ pci_lpc_write_dsdt(struct pci_devinst *pi) { struct lpc_dsdt **ldpp, *ldp; - dsdt_line(""); - dsdt_line("Device (ISA)"); - dsdt_line("{"); - dsdt_line(" Name (_ADR, 0x%04X%04X)", pi->pi_slot, pi->pi_func); - dsdt_line(" OperationRegion (LPCR, PCI_Config, 0x00, 0x100)"); - dsdt_line(" Field (LPCR, AnyAcc, NoLock, Preserve)"); - dsdt_line(" {"); - dsdt_line(" Offset (0x60),"); - dsdt_line(" PIRA, 8,"); - dsdt_line(" PIRB, 8,"); - dsdt_line(" PIRC, 8,"); - dsdt_line(" PIRD, 8,"); - dsdt_line(" Offset (0x68),"); - dsdt_line(" PIRE, 8,"); - dsdt_line(" PIRF, 8,"); - dsdt_line(" PIRG, 8,"); - dsdt_line(" PIRH, 8"); - dsdt_line(" }"); - dsdt_line(""); - - dsdt_indent(1); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (ISA)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_ADR, 0x%04X%04X)", pi->pi_slot, pi->pi_func); + acpi_ops.dsdt_line(" OperationRegion (LPCR, PCI_Config, 0x00, 0x100)"); + acpi_ops.dsdt_line(" Field (LPCR, AnyAcc, NoLock, Preserve)"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_line(" Offset (0x60),"); + acpi_ops.dsdt_line(" PIRA, 8,"); + acpi_ops.dsdt_line(" PIRB, 8,"); + acpi_ops.dsdt_line(" PIRC, 8,"); + acpi_ops.dsdt_line(" PIRD, 8,"); + acpi_ops.dsdt_line(" Offset (0x68),"); + acpi_ops.dsdt_line(" PIRE, 8,"); + acpi_ops.dsdt_line(" PIRF, 8,"); + acpi_ops.dsdt_line(" PIRG, 8,"); + acpi_ops.dsdt_line(" PIRH, 8"); + acpi_ops.dsdt_line(" }"); + acpi_ops.dsdt_line(""); + + acpi_ops.dsdt_indent(1); SET_FOREACH(ldpp, lpc_dsdt_set) { ldp = *ldpp; ldp->handler(); } - dsdt_line(""); - dsdt_line("Device (PIC)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0000\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(IO_ICU1, 2); - dsdt_fixed_ioport(IO_ICU2, 2); - dsdt_fixed_irq(2); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); - - dsdt_line(""); - dsdt_line("Device (TIMR)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0100\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(IO_TIMER1_PORT, 4); - dsdt_fixed_irq(0); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); - dsdt_unindent(1); - - dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (PIC)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0000\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(IO_ICU1, 2); + acpi_ops.dsdt_fixed_ioport(IO_ICU2, 2); + acpi_ops.dsdt_fixed_irq(2); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); + + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (TIMR)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0100\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(IO_TIMER1_PORT, 4); + acpi_ops.dsdt_fixed_irq(0); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); + acpi_ops.dsdt_unindent(1); + + acpi_ops.dsdt_line("}"); } static void @@ -286,29 +286,29 @@ pci_lpc_sysres_dsdt(void) { struct lpc_sysres **lspp, *lsp; - dsdt_line(""); - dsdt_line("Device (SIO)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0C02\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (SIO)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0C02\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); - dsdt_indent(2); + acpi_ops.dsdt_indent(2); SET_FOREACH(lspp, lpc_sysres_set) { lsp = *lspp; switch (lsp->type) { case LPC_SYSRES_IO: - dsdt_fixed_ioport(((uint16_t) lsp->base), ((uint16_t) lsp->length)); + acpi_ops.dsdt_fixed_ioport(((uint16_t) lsp->base), ((uint16_t) lsp->length)); break; case LPC_SYSRES_MEM: - dsdt_fixed_mem32(lsp->base, lsp->length); + acpi_ops.dsdt_fixed_mem32(lsp->base, lsp->length); break; } } - dsdt_unindent(2); + acpi_ops.dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); } LPC_DSDT(pci_lpc_sysres_dsdt); @@ -322,19 +322,19 @@ pci_lpc_uart_dsdt(void) sc = &lpc_uart_softc[unit]; if (!sc->enabled) continue; - dsdt_line(""); - dsdt_line("Device (%s)", lpc_uart_names[unit]); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0501\"))"); - dsdt_line(" Name (_UID, %d)", unit + 1); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(((uint16_t) sc->iobase), UART_IO_BAR_SIZE); - dsdt_fixed_irq(((uint8_t) sc->irq)); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (%s)", lpc_uart_names[unit]); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0501\"))"); + acpi_ops.dsdt_line(" Name (_UID, %d)", unit + 1); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(((uint16_t) sc->iobase), UART_IO_BAR_SIZE); + acpi_ops.dsdt_fixed_irq(((uint8_t) sc->irq)); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); } } LPC_DSDT(pci_lpc_uart_dsdt); diff --git a/src/rtc.c b/src/rtc.c index a71fdef..343d99c 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -98,18 +98,18 @@ rtc_init(int use_localtime) static void rtc_dsdt(void) { - dsdt_line(""); - dsdt_line("Device (RTC)"); - dsdt_line("{"); - dsdt_line(" Name (_HID, EisaId (\"PNP0B00\"))"); - dsdt_line(" Name (_CRS, ResourceTemplate ()"); - dsdt_line(" {"); - dsdt_indent(2); - dsdt_fixed_ioport(IO_RTC, 2); - dsdt_fixed_irq(8); - dsdt_unindent(2); - dsdt_line(" })"); - dsdt_line("}"); + acpi_ops.dsdt_line(""); + acpi_ops.dsdt_line("Device (RTC)"); + acpi_ops.dsdt_line("{"); + acpi_ops.dsdt_line(" Name (_HID, EisaId (\"PNP0B00\"))"); + acpi_ops.dsdt_line(" Name (_CRS, ResourceTemplate ()"); + acpi_ops.dsdt_line(" {"); + acpi_ops.dsdt_indent(2); + acpi_ops.dsdt_fixed_ioport(IO_RTC, 2); + acpi_ops.dsdt_fixed_irq(8); + acpi_ops.dsdt_unindent(2); + acpi_ops.dsdt_line(" })"); + acpi_ops.dsdt_line("}"); } LPC_DSDT(rtc_dsdt); diff --git a/src/xhyve.c b/src/xhyve.c index 7edf155..9089139 100644 --- a/src/xhyve.c +++ b/src/xhyve.c @@ -92,6 +92,7 @@ static int strictio; static int strictmsr = 1; static int acpi; +char* asl_compiler_path; static char *progname; static const int BSP = 0; @@ -129,8 +130,9 @@ usage(int code) fprintf(stderr, "Usage: %s [-behuwxMACHPWY] [-c vcpus] [-F ] [-g ] [-l ]\n" - " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] -f \n" + " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] -f [-A [-a ]]\n" " -A: create ACPI tables\n" + " -a: path to asl compiler\n" " -c: # cpus (default 1)\n" " -C: include guest memory in core file\n" " -e: exit on unhandled I/O access\n" @@ -858,11 +860,14 @@ main(int argc, char *argv[]) rtc_localtime = 1; fw = 0; - while ((c = getopt(argc, argv, "behvuwxMACHPWY:f:F:g:c:s:m:l:U:")) != -1) { + while ((c = getopt(argc, argv, "behvuwxMACHPWY:f:F:g:c:s:m:l:U:a:")) != -1) { switch (c) { case 'A': acpi = 1; break; + case 'a': + asl_compiler_path = optarg; + break; case 'b': bvmcons = 1; break; @@ -1013,7 +1018,8 @@ main(int argc, char *argv[]) assert(error == 0); if (acpi) { - error = acpi_build(guest_ncpus); + acpi_init(); + error = acpi_ops.acpi_build(guest_ncpus); assert(error == 0); } diff --git a/xhyve.xcodeproj/project.pbxproj b/xhyve.xcodeproj/project.pbxproj index cb247a9..24e2fc0 100644 --- a/xhyve.xcodeproj/project.pbxproj +++ b/xhyve.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 3F3FFA911BF7C6A7004C89A1 /* xhyve.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F3FFA5A1BF7C6A7004C89A1 /* xhyve.c */; }; 3F3FFA921BF7C6A7004C89A1 /* xmsr.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F3FFA5B1BF7C6A7004C89A1 /* xmsr.c */; }; 3F3FFA971BF7CC0E004C89A1 /* xhyve.1 in Install Man Pages */ = {isa = PBXBuildFile; fileRef = 3F3FF9E41BF7C5DC004C89A1 /* xhyve.1 */; }; + FF94BAD46505AD8294DFEE50 /* acpi.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F3FFA1E1BF7C6A7004C89A1 /* acpi.c */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -693,6 +694,7 @@ 00D3D5B3207C82AB00DDCDF6 /* rfb.c in Sources */, 3F3FFA711BF7C6A7004C89A1 /* pci_virtio_block.c in Sources */, 3F3FFA871BF7C6A7004C89A1 /* vmm_api.c in Sources */, + FF94BAD46505AD8294DFEE50 /* acpi.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };