From e69c357e78e9058bd400013fb161e3ea87a565f1 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Fri, 5 Feb 2021 08:17:49 +0100 Subject: [PATCH] drivers/virtualization: Fix ivshmem PCIE reg bar lookup on ivshmem-plain This is a fix for ACRN targets. Qemu ivshmem original specs do not states that, if ivshmem-plain is selected, bar0 (the register bar) will not be present. It just says that bar2 will only be sufficient. And that is what happens on qemu: whether ivshmem-plain or ivshmem-doorbell is selected, bar0 is always present no matter what. This does not seem to be the case in ACRN which does not expose the bar0 if ivshmem-plain is selected. Signed-off-by: Tomasz Bursztyka --- drivers/virtualization/virt_ivshmem.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/virtualization/virt_ivshmem.c b/drivers/virtualization/virt_ivshmem.c index afa3524d728..01a986e0bc1 100644 --- a/drivers/virtualization/virt_ivshmem.c +++ b/drivers/virtualization/virt_ivshmem.c @@ -95,8 +95,12 @@ static void register_signal(const struct device *dev, } #else + +static const struct ivshmem_reg no_reg; + #define ivshmem_configure_interrupts(...) true #define register_signal(...) + #endif /* CONFIG_IVSHMEM_DOORBELL */ static bool ivshmem_check_on_bdf(pcie_bdf_t bdf) @@ -142,15 +146,21 @@ static bool ivshmem_configure(const struct device *dev) struct pcie_mbar mbar_regs, mbar_mem; if (!pcie_get_mbar(data->bdf, IVSHMEM_PCIE_REG_BAR_IDX, &mbar_regs)) { +#ifdef CONFIG_IVSHMEM_DOORBELL LOG_ERR("ivshmem regs bar not found"); return false; +#else + LOG_DBG("ivshmem regs bar not found"); + device_map(DEVICE_MMIO_RAM_PTR(dev), (uintptr_t)&no_reg, + sizeof(struct ivshmem_reg), K_MEM_CACHE_NONE); +#endif /* CONFIG_IVSHMEM_DOORBELL */ + } else { + pcie_set_cmd(data->bdf, PCIE_CONF_CMDSTAT_MEM, true); + + device_map(DEVICE_MMIO_RAM_PTR(dev), mbar_regs.phys_addr, + mbar_regs.size, K_MEM_CACHE_NONE); } - pcie_set_cmd(data->bdf, PCIE_CONF_CMDSTAT_MEM, true); - - device_map(DEVICE_MMIO_RAM_PTR(dev), mbar_regs.phys_addr, - mbar_regs.size, K_MEM_CACHE_NONE); - if (!pcie_get_mbar(data->bdf, IVSHMEM_PCIE_SHMEM_BAR_IDX, &mbar_mem)) { LOG_ERR("ivshmem mem bar not found"); return false;