Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/qemu_fwcfg.c
| Show All 17 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include "acpi_device.h" | #include "acpi_device.h" | ||||
| #include "bhyverun.h" | #include "bhyverun.h" | ||||
| #include "inout.h" | #include "inout.h" | ||||
| #include "pci_lpc.h" | #ifdef __amd64__ | ||||
| #include "amd64/pci_lpc.h" | |||||
| #endif | |||||
| #include "qemu_fwcfg.h" | #include "qemu_fwcfg.h" | ||||
| #define QEMU_FWCFG_ACPI_DEVICE_NAME "FWCF" | #define QEMU_FWCFG_ACPI_DEVICE_NAME "FWCF" | ||||
| #define QEMU_FWCFG_ACPI_HARDWARE_ID "QEMU0002" | #define QEMU_FWCFG_ACPI_HARDWARE_ID "QEMU0002" | ||||
| #define QEMU_FWCFG_SELECTOR_PORT_NUMBER 0x510 | #define QEMU_FWCFG_SELECTOR_PORT_NUMBER 0x510 | ||||
| #define QEMU_FWCFG_SELECTOR_PORT_SIZE 1 | #define QEMU_FWCFG_SELECTOR_PORT_SIZE 1 | ||||
| #define QEMU_FWCFG_SELECTOR_PORT_FLAGS IOPORT_F_INOUT | #define QEMU_FWCFG_SELECTOR_PORT_FLAGS IOPORT_F_INOUT | ||||
| ▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | static const struct acpi_device_emul qemu_fwcfg_acpi_device_emul = { | ||||
| .name = QEMU_FWCFG_ACPI_DEVICE_NAME, | .name = QEMU_FWCFG_ACPI_DEVICE_NAME, | ||||
| .hid = QEMU_FWCFG_ACPI_HARDWARE_ID, | .hid = QEMU_FWCFG_ACPI_HARDWARE_ID, | ||||
| }; | }; | ||||
| int | int | ||||
| qemu_fwcfg_init(struct vmctx *const ctx) | qemu_fwcfg_init(struct vmctx *const ctx) | ||||
| { | { | ||||
| int error; | int error; | ||||
| bool fwcfg_enabled; | |||||
| /* | /* | ||||
| * The fwcfg implementation currently only provides an I/O port | |||||
corvink: fwcfg is mainly used for hypervisor <-> guest firmware communication. That's why it's tied to… | |||||
Done Inline ActionsWe could also repurpose the -l option on arm64 to mean something other than "LPC devices". It can be used for generic platform configuration variables, e.g., bootrom and fwcfg. markj: We could also repurpose the `-l` option on arm64 to mean something other than "LPC devices". It… | |||||
| * interface and thus is amd64-specific for now. An MMIO interface is | |||||
| * required for other platforms. | |||||
Done Inline ActionsI do think that we want to have fwcfg for arm64 too. Maybe add a comment which explains that we want to have fwcfg for arm64 but that we can't enable it yet because we do not implement the mmio interface yet. corvink: I do think that we want to have fwcfg for arm64 too. Maybe add a comment which explains that we… | |||||
Done Inline ActionsIndeed, I'll add a comment. markj: Indeed, I'll add a comment. | |||||
| */ | |||||
| #ifdef __amd64__ | |||||
| fwcfg_enabled = strcmp(lpc_fwcfg(), "qemu") == 0; | |||||
| #else | |||||
| fwcfg_enabled = false; | |||||
| #endif | |||||
| /* | |||||
| * Bhyve supports fwctl (bhyve) and fwcfg (qemu) as firmware interfaces. | * Bhyve supports fwctl (bhyve) and fwcfg (qemu) as firmware interfaces. | ||||
| * Both are using the same ports. So, it's not possible to provide both | * Both are using the same ports. So, it's not possible to provide both | ||||
| * interfaces at the same time to the guest. Therefore, only create acpi | * interfaces at the same time to the guest. Therefore, only create acpi | ||||
| * tables and register io ports for fwcfg, if it's used. | * 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, | error = acpi_device_create(&fwcfg_sc.acpi_dev, &fwcfg_sc, ctx, | ||||
| &qemu_fwcfg_acpi_device_emul); | &qemu_fwcfg_acpi_device_emul); | ||||
| if (error) { | if (error) { | ||||
| warnx("%s: failed to create ACPI device for QEMU FwCfg", | warnx("%s: failed to create ACPI device for QEMU FwCfg", | ||||
| __func__); | __func__); | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines | |||||
fwcfg is mainly used for hypervisor <-> guest firmware communication. That's why it's tied to the bootrom option which is tied to the lpc. Btw: I was told to do it that way. See https://reviews.freebsd.org/D31578#712764