diff --git a/hypervisor/arch/x86/Kconfig b/hypervisor/arch/x86/Kconfig index 744e01d4d..e5b808f8a 100644 --- a/hypervisor/arch/x86/Kconfig +++ b/hypervisor/arch/x86/Kconfig @@ -150,15 +150,15 @@ config SERIAL_PIO_BASE config COM_BASE hex "Base address of the vuart port" - depends on !RELEASE - default 0x3f8 + default 0 if RELEASE + default 0x3f8 if !RELEASE help Base address of the vuart port. config COM_IRQ int "IRQ of the vuart port" - depends on !RELEASE - default 4 + default 0 if RELEASE + default 4 if !RELEASE help IRQ of the vuart port. diff --git a/hypervisor/include/arch/x86/vm_config.h b/hypervisor/include/arch/x86/vm_config.h index 953332759..47607015e 100644 --- a/hypervisor/include/arch/x86/vm_config.h +++ b/hypervisor/include/arch/x86/vm_config.h @@ -15,6 +15,7 @@ #include #define PLUG_CPU(n) (1U << (n)) +#define MAX_VUART_NUM_PER_VM 2U /* * PRE_LAUNCHED_VM is launched by ACRN hypervisor, with LAPIC_PT; @@ -33,6 +34,32 @@ struct acrn_vm_mem_config { uint64_t size; /* VM memory size configuration */ }; +struct target_vuart { + uint8_t vm_id; /* target VM id */ + uint8_t vuart_id; /* target vuart index in a VM */ +}; + +enum vuart_type { + VUART_LEGACY_PIO = 0, /* legacy PIO vuart */ + VUART_PCI, /* PCI vuart, may removed */ +}; + +union vuart_addr { + uint16_t port_base; /* addr for legacy type */ + struct { /* addr for pci type */ + uint8_t f : 3; /* BITs 0-2 */ + uint8_t d : 5; /* BITs 3-7 */ + uint8_t b; /* BITs 8-15 */ + } bdf; +}; + +struct vuart_config { + enum vuart_type type; /* legacy PIO or PCI */ + union vuart_addr addr; /* port addr if in legacy type, or bdf addr if in pci type */ + uint16_t irq; + struct target_vuart t_vuart; /* target vuart */ +} __aligned(8); + struct acrn_vm_os_config { char name[MAX_VM_OS_NAME_LEN]; /* OS name, useful for debug */ char bootargs[MAX_BOOTARGS_SIZE]; /* boot args/cmdline */ @@ -62,6 +89,7 @@ struct acrn_vm_config { uint16_t clos; /* if guest_flags has GUEST_FLAG_CLOS_REQUIRED, then VM use this CLOS */ bool vm_vuart; + struct vuart_config vuart[MAX_VUART_NUM_PER_VM];/* vuart configuration for VM */ struct mptable_info *mptable; /* Pointer to mptable struct if VM type is pre-launched */ } __aligned(8); diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h index 524e5c3bf..8818881c4 100644 --- a/hypervisor/include/debug/vuart.h +++ b/hypervisor/include/debug/vuart.h @@ -35,6 +35,17 @@ #define RX_BUF_SIZE 256U #define TX_BUF_SIZE 8192U +#define COM1_BASE 0x3F8U +#define COM2_BASE 0x2F8U +#define COM3_BASE 0x3E8U +#define COM4_BASE 0x2E8U +#define INVALID_COM_BASE 0U + +#define COM1_IRQ 4U +#define COM2_IRQ 3U +#define COM3_IRQ 6U +#define COM4_IRQ 7U + struct fifo { char *buf; uint32_t rindex; /* index to read from */ diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.c b/hypervisor/scenarios/logical_partition/vm_configurations.c index 6f4650aa1..40ec02e4c 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.c +++ b/hypervisor/scenarios/logical_partition/vm_configurations.c @@ -7,6 +7,7 @@ #include #include #include +#include extern struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[VM0_CONFIG_PCI_PTDEV_NUM]; extern struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM]; @@ -37,6 +38,18 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { consoleblank=0 tsc=reliable xapic_phys" }, .vm_vuart = true, + .vuart[0] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = COM1_BASE, + .irq = COM1_IRQ, + }, + .vuart[1] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = COM2_BASE, + .irq = COM2_IRQ, + .t_vuart.vm_id = 1U, + .t_vuart.vuart_id = 1U, + }, .pci_ptdev_num = VM0_CONFIG_PCI_PTDEV_NUM, .pci_ptdevs = vm0_pci_ptdevs, .mptable = &vm_mptables[0], @@ -65,6 +78,18 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { consoleblank=0 tsc=reliable xapic_phys" }, .vm_vuart = true, + .vuart[0] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = COM1_BASE, + .irq = COM1_IRQ, + }, + .vuart[1] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = COM2_BASE, + .irq = COM2_IRQ, + .t_vuart.vm_id = 0U, + .t_vuart.vuart_id = 1U, + }, .pci_ptdev_num = VM1_CONFIG_PCI_PTDEV_NUM, .pci_ptdevs = vm1_pci_ptdevs, .mptable = &vm_mptables[1], diff --git a/hypervisor/scenarios/sdc/vm_configurations.c b/hypervisor/scenarios/sdc/vm_configurations.c index 30df5b93e..cdaae077b 100644 --- a/hypervisor/scenarios/sdc/vm_configurations.c +++ b/hypervisor/scenarios/sdc/vm_configurations.c @@ -7,6 +7,7 @@ #include #include #include +#include struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { @@ -24,11 +25,29 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .os_config = { .name = "ACRN Service OS", }, + .vuart[0] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = CONFIG_COM_BASE, + .irq = CONFIG_COM_IRQ, + }, + .vuart[1] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = INVALID_COM_BASE, + } }, { .type = NORMAL_VM, .uuid = {0xd2U, 0x79U, 0x54U, 0x38U, 0x25U, 0xd6U, 0x11U, 0xe8U, \ 0x86U, 0x4eU, 0xcbU, 0x7aU, 0x18U, 0xb3U, 0x46U, 0x43U}, /* d2795438-25d6-11e8-864e-cb7a18b34643 */ + .vuart[0] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = INVALID_COM_BASE, + }, + .vuart[1] = { + .type = VUART_LEGACY_PIO, + .addr.port_base = INVALID_COM_BASE, + } + } };