diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -31,7 +31,6 @@ gdb.c \ hda_codec.c \ inout.c \ - ioapic.c \ iov.c \ mem.c \ mevent.c \ @@ -40,8 +39,6 @@ pci_emul.c \ pci_fbuf.c \ pci_hostbridge.c \ - pci_irq.c \ - pci_lpc.c \ pci_nvme.c \ pci_passthru.c \ pci_virtio_9p.c \ diff --git a/usr.sbin/bhyve/amd64/Makefile.inc b/usr.sbin/bhyve/amd64/Makefile.inc --- a/usr.sbin/bhyve/amd64/Makefile.inc +++ b/usr.sbin/bhyve/amd64/Makefile.inc @@ -4,12 +4,15 @@ atkbdc.c \ e820.c \ fwctl.c \ + ioapic.c \ kernemu_dev.c \ mptbl.c \ pci_ahci.c \ pci_e82545.c \ pci_gvt-d.c \ pci_hda.c \ + pci_irq.c \ + pci_lpc.c \ pci_uart.c \ pci_xhci.c \ pctestdev.c \ diff --git a/usr.sbin/bhyve/ioapic.h b/usr.sbin/bhyve/amd64/ioapic.h rename from usr.sbin/bhyve/ioapic.h rename to usr.sbin/bhyve/amd64/ioapic.h diff --git a/usr.sbin/bhyve/ioapic.c b/usr.sbin/bhyve/amd64/ioapic.c rename from usr.sbin/bhyve/ioapic.c rename to usr.sbin/bhyve/amd64/ioapic.c diff --git a/usr.sbin/bhyve/pci_irq.h b/usr.sbin/bhyve/amd64/pci_irq.h rename from usr.sbin/bhyve/pci_irq.h rename to usr.sbin/bhyve/amd64/pci_irq.h diff --git a/usr.sbin/bhyve/pci_irq.c b/usr.sbin/bhyve/amd64/pci_irq.c rename from usr.sbin/bhyve/pci_irq.c rename to usr.sbin/bhyve/amd64/pci_irq.c --- a/usr.sbin/bhyve/pci_irq.c +++ b/usr.sbin/bhyve/amd64/pci_irq.c @@ -31,9 +31,6 @@ #include __FBSDID("$FreeBSD$"); -#include -#include - #include #include #include diff --git a/usr.sbin/bhyve/pci_lpc.h b/usr.sbin/bhyve/amd64/pci_lpc.h rename from usr.sbin/bhyve/pci_lpc.h rename to usr.sbin/bhyve/amd64/pci_lpc.h diff --git a/usr.sbin/bhyve/pci_lpc.c b/usr.sbin/bhyve/amd64/pci_lpc.c rename from usr.sbin/bhyve/pci_lpc.c rename to usr.sbin/bhyve/amd64/pci_lpc.c diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -89,8 +89,8 @@ #include "amd64/fwctl.h" #endif #include "gdb.h" -#include "ioapic.h" #ifdef __amd64__ +#include "amd64/ioapic.h" #include "amd64/kernemu_dev.h" #endif #include "mem.h" @@ -99,8 +99,10 @@ #include "amd64/mptbl.h" #endif #include "pci_emul.h" -#include "pci_irq.h" -#include "pci_lpc.h" +#ifdef __amd64__ +#include "amd64/pci_irq.h" +#include "amd64/pci_lpc.h" +#endif #include "qemu_fwcfg.h" #include "smbiostbl.h" #ifdef BHYVE_SNAPSHOT @@ -637,8 +639,10 @@ reinit = romboot = false; +#ifdef __amd64__ if (lpc_bootrom()) romboot = true; +#endif error = vm_create(vmname); if (error) { @@ -854,6 +858,7 @@ case 'K': set_config_value("keyboard.layout", optarg); break; +#ifdef __amd64__ case 'l': if (strncmp(optarg, "help", strlen(optarg)) == 0) { lpc_print_supported_devices(); @@ -863,6 +868,7 @@ "configuration '%s'", optarg); } break; +#endif #ifdef BHYVE_SNAPSHOT case 'r': restore_file = optarg; @@ -1036,9 +1042,9 @@ init_bootrom(ctx); #ifdef __amd64__ atkbdc_init(ctx); -#endif pci_irq_init(ctx); ioapic_init(ctx); +#endif #ifdef __amd64__ rtc_init(ctx); @@ -1080,6 +1086,7 @@ init_gdb(ctx); +#ifdef __amd64__ if (lpc_bootrom()) { if (vm_set_capability(bsp, VM_CAP_UNRESTRICTED_GUEST, 1)) { fprintf(stderr, "ROM boot failed: unrestricted guest " @@ -1089,6 +1096,7 @@ error = vcpu_reset(bsp); assert(error == 0); } +#endif /* * Add all vCPUs. diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h --- a/usr.sbin/bhyve/pci_emul.h +++ b/usr.sbin/bhyve/pci_emul.h @@ -117,12 +117,6 @@ #define MAX_MSIX_TABLE_ENTRIES 2048 #define PBA_SIZE(msgnum) (roundup2((msgnum), 64) / 8) -enum lintr_stat { - IDLE, - ASSERTED, - PENDING -}; - struct pci_devinst { struct pci_devemu *pi_d; struct vmctx *pi_vmctx; @@ -132,13 +126,19 @@ int pi_prevcap; int pi_capend; +#ifdef __amd64__ struct { int8_t pin; - enum lintr_stat state; + enum { + IDLE, + ASSERTED, + PENDING, + } state; int pirq_pin; int ioapic_irq; pthread_mutex_t lock; } pi_lintr; +#endif struct { int enabled; @@ -223,8 +223,15 @@ } __packed; static_assert(sizeof(struct pciecap) == 60, "compile-time assertion failed"); +#ifdef __amd64__ typedef void (*pci_lintr_cb)(int b, int s, int pin, int pirq_pin, int ioapic_irq, void *arg); +void pci_lintr_assert(struct pci_devinst *pi); +void pci_lintr_deassert(struct pci_devinst *pi); +void pci_lintr_request(struct pci_devinst *pi); +int pci_count_lintr(int bus); +void pci_walk_lintr(int bus, pci_lintr_cb cb, void *arg); +#endif int init_pci(struct vmctx *ctx); void pci_callback(void); @@ -243,9 +250,6 @@ void pci_emul_cmd_changed(struct pci_devinst *pi, uint16_t old); void pci_generate_msi(struct pci_devinst *pi, int msgnum); void pci_generate_msix(struct pci_devinst *pi, int msgnum); -void pci_lintr_assert(struct pci_devinst *pi); -void pci_lintr_deassert(struct pci_devinst *pi); -void pci_lintr_request(struct pci_devinst *pi); int pci_msi_enabled(struct pci_devinst *pi); int pci_msix_enabled(struct pci_devinst *pi); int pci_msix_table_bar(struct pci_devinst *pi); @@ -259,11 +263,10 @@ int pci_emul_msix_twrite(struct pci_devinst *pi, uint64_t offset, int size, uint64_t value); uint64_t pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size); -int pci_count_lintr(int bus); -void pci_walk_lintr(int bus, pci_lintr_cb cb, void *arg); void pci_write_dsdt(void); uint64_t pci_ecfg_base(void); int pci_bus_configured(int bus); + #ifdef BHYVE_SNAPSHOT struct pci_devinst *pci_next(const struct pci_devinst *cursor); int pci_snapshot(struct vm_snapshot_meta *meta); diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -56,11 +56,15 @@ #include "config.h" #include "debug.h" #include "inout.h" -#include "ioapic.h" +#ifdef __amd64__ +#include "amd64/ioapic.h" +#endif #include "mem.h" #include "pci_emul.h" -#include "pci_irq.h" -#include "pci_lpc.h" +#ifdef __amd64__ +#include "amd64/pci_irq.h" +#include "amd64/pci_lpc.h" +#endif #include "pci_passthru.h" #include "qemu_fwcfg.h" @@ -147,9 +151,12 @@ #define PCI_EMUL_MEMLIMIT32 PCI_EMUL_ECFG_BASE #define PCI_EMUL_MEMSIZE64 (32*GB) -static struct pci_devemu *pci_emul_finddev(const char *name); +#ifdef __amd64__ static void pci_lintr_route(struct pci_devinst *pi); static void pci_lintr_update(struct pci_devinst *pi); +#endif + +static struct pci_devemu *pci_emul_finddev(const char *name); static void pci_cfgrw(int in, int bus, int slot, int func, int coff, int bytes, uint32_t *val); @@ -1071,11 +1078,13 @@ pdi->pi_bus = bus; pdi->pi_slot = slot; pdi->pi_func = func; +#ifdef __amd64__ pthread_mutex_init(&pdi->pi_lintr.lock, NULL); pdi->pi_lintr.pin = 0; pdi->pi_lintr.state = IDLE; pdi->pi_lintr.pirq_pin = 0; pdi->pi_lintr.ioapic_irq = 0; +#endif pdi->pi_d = pde; snprintf(pdi->pi_name, PI_NAMESZ, "%s@pci.%d.%d.%d", pde->pe_emu, bus, slot, func); @@ -1213,7 +1222,9 @@ pi->pi_msix.enabled = val & PCIM_MSIXCTRL_MSIX_ENABLE; pi->pi_msix.function_mask = val & PCIM_MSIXCTRL_FUNCTION_MASK; +#ifdef __amd64__ pci_lintr_update(pi); +#endif } CFGWRITE(pi, offset, val, bytes); @@ -1255,7 +1266,9 @@ } else { pi->pi_msi.maxmsgnum = 0; } +#ifdef __amd64__ pci_lintr_update(pi); +#endif } static void @@ -1548,6 +1561,7 @@ bi->memlimit64 = pci_emul_membase64; } +#ifdef __amd64__ /* * PCI backends are initialized before routing INTx interrupts * so that LPC devices are able to reserve ISA IRQs before @@ -1568,6 +1582,7 @@ } } lpc_pirq_routed(); +#endif if ((error = init_bootorder()) != 0) { warnx("%s: Unable to init bootorder", __func__); @@ -1611,6 +1626,7 @@ return (0); } +#ifdef __amd64__ static void pci_apic_prt_entry(int bus __unused, int slot, int pin, int pirq_pin __unused, int ioapic_irq, void *arg __unused) @@ -1643,6 +1659,7 @@ dsdt_line(" },"); free(name); } +#endif /* * A bhyve virtual machine has a flat PCI hierarchy with a root port @@ -1654,7 +1671,7 @@ struct businfo *bi; struct slotinfo *si; struct pci_devinst *pi; - int count, func, slot; + int func, slot; /* * If there are no devices on this 'bus' then just return. @@ -1757,7 +1774,8 @@ dsdt_line(" ,, , AddressRangeMemory, TypeStatic)"); dsdt_line(" })"); - count = pci_count_lintr(bus); +#ifdef __amd64__ + int count = pci_count_lintr(bus); if (count != 0) { dsdt_indent(2); dsdt_line("Name (PPRT, Package ()"); @@ -1781,6 +1799,7 @@ dsdt_line("}"); dsdt_unindent(2); } +#endif dsdt_indent(2); for (slot = 0; slot < MAXSLOTS; slot++) { @@ -1876,6 +1895,7 @@ } } +#ifdef __amd64__ static bool pci_lintr_permitted(struct pci_devinst *pi) { @@ -2036,6 +2056,7 @@ } } } +#endif /* __amd64__ */ /* * Return 1 if the emulated device in 'slot' is a multi-function device. @@ -2140,11 +2161,13 @@ } } +#ifdef __amd64__ /* * If INTx has been unmasked and is pending, assert the * interrupt. */ pci_lintr_update(pi); +#endif } static void diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -23,7 +23,9 @@ #include "acpi_device.h" #include "bhyverun.h" #include "inout.h" -#include "pci_lpc.h" +#ifdef __amd64__ +#include "amd64/pci_lpc.h" +#endif #include "qemu_fwcfg.h" #define QEMU_FWCFG_ACPI_DEVICE_NAME "FWCF" @@ -423,6 +425,13 @@ qemu_fwcfg_init(struct vmctx *const ctx) { int error; + bool fwcfg_enabled; + +#ifdef __amd64__ + fwcfg_enabled = strcmp(lpc_fwcfg(), "qemu") == 0; +#else + fwcfg_enabled = false; +#endif /* * Bhyve supports fwctl (bhyve) and fwcfg (qemu) as firmware interfaces. @@ -430,7 +439,7 @@ * interfaces at the same time to the guest. Therefore, only create acpi * tables and register io ports for fwcfg, if it's used. */ - if (strcmp(lpc_fwcfg(), "qemu") == 0) { + if (fwcfg_enabled) { error = acpi_device_create(&fwcfg_sc.acpi_dev, &fwcfg_sc, ctx, &qemu_fwcfg_acpi_device_emul); if (error) { diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h --- a/usr.sbin/bhyve/virtio.h +++ b/usr.sbin/bhyve/virtio.h @@ -360,7 +360,9 @@ VS_LOCK(vs); vs->vs_isr |= isr; pci_generate_msi(vs->vs_pi, 0); +#ifdef __amd64__ pci_lintr_assert(vs->vs_pi); +#endif VS_UNLOCK(vs); } }