The existing VPCI support available for X86 is adapted for Arm.
When the device is added to XEN via the hyper call
“PHYSDEVOP_pci_device_add”, VPCI handler for the config space
access is added to the Xen to emulate the PCI devices config space.
A MMIO trap handler for the PCI ECAM space is registered in XEN
so that when guest is trying to access the PCI config space,XEN
will trap the access and emulate read/write using the VPCI and
not the real PCI hardware.
For Dom0less systems scan_pci_devices() would be used to discover the
PCI device in XEN and VPCI handler will be added during XEN boots.
This patch is also doing some small fixes to fix compilation errors on
arm32 of vpci and prevent 64bit accesses on 32bit:
- use %zu instead of lu in header.c for print
- prevent 64bit accesses in vpci_access_allowed
- ifdef out using CONFIG_64BIT handling of len 8 in
vpci_ecam_{read/write}
TODO: currently vpci_add_handlers is marked as __hwdom_init, but on ARM
vpci_add_handlers can be called after boot from
PHYSDEVOP_pci_device_add. Consider removing __hwdom_init.
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
[stefano: add TODO item to commit message]
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
obj-y += platforms/
endif
obj-$(CONFIG_TEE) += tee/
+obj-$(CONFIG_HAS_VPCI) += vpci.o
obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
obj-y += bootfdt.init.o
#include <asm/vgic.h>
#include <asm/vtimer.h>
+#include "vpci.h"
#include "vuart.h"
DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
if ( is_hardware_domain(d) && (rc = domain_vuart_init(d)) )
goto fail;
+ if ( (rc = domain_vpci_init(d)) != 0 )
+ goto fail;
+
return 0;
fail:
--- /dev/null
+/*
+ * xen/arch/arm/vpci.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include <xen/sched.h>
+#include <xen/vpci.h>
+
+#include <asm/mmio.h>
+
+static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
+ register_t *r, void *p)
+{
+ pci_sbdf_t sbdf;
+ /* data is needed to prevent a pointer cast on 32bit */
+ unsigned long data;
+
+ /* We ignore segment part and always handle segment 0 */
+ sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+
+ if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
+ 1U << info->dabt.size, &data) )
+ {
+ *r = data;
+ return 1;
+ }
+
+ *r = ~0ul;
+
+ return 0;
+}
+
+static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
+ register_t r, void *p)
+{
+ pci_sbdf_t sbdf;
+
+ /* We ignore segment part and always handle segment 0 */
+ sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+
+ return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa),
+ 1U << info->dabt.size, r);
+}
+
+static const struct mmio_handler_ops vpci_mmio_handler = {
+ .read = vpci_mmio_read,
+ .write = vpci_mmio_write,
+};
+
+int domain_vpci_init(struct domain *d)
+{
+ if ( !has_vpci(d) )
+ return 0;
+
+ register_mmio_handler(d, &vpci_mmio_handler,
+ GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL);
+
+ return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+
--- /dev/null
+/*
+ * xen/arch/arm/vpci.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __ARCH_ARM_VPCI_H__
+#define __ARCH_ARM_VPCI_H__
+
+#ifdef CONFIG_HAS_VPCI
+int domain_vpci_init(struct domain *d);
+#else
+static inline int domain_vpci_init(struct domain *d)
+{
+ return 0;
+}
+#endif
+
+#endif /* __ARCH_ARM_VPCI_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
if ( !pdev->domain )
{
pdev->domain = hardware_domain;
+#ifdef CONFIG_ARM
+ /*
+ * On ARM PCI devices discovery will be done by Dom0. Add vpci handler
+ * when Dom0 inform XEN to add the PCI devices in XEN.
+ */
+ ret = vpci_add_handlers(pdev);
+ if ( ret )
+ {
+ printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret);
+ pdev->domain = NULL;
+ goto out;
+ }
+#endif
ret = iommu_add_device(pdev);
if ( ret )
{
/* If the value written is the current one avoid printing a warning. */
if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) )
gprintk(XENLOG_WARNING,
- "%pp: ignored BAR %lu write with memory decoding enabled\n",
+ "%pp: ignored BAR %zu write with memory decoding enabled\n",
&pdev->sbdf, bar - pdev->vpci->header.bars + hi);
return;
}
if ( len != 1 && len != 2 && len != 4 && len != 8 )
return false;
+#ifndef CONFIG_64BIT
+ /* Prevent 64bit accesses on 32bit */
+ if ( len == 8 )
+ return false;
+#endif
+
/* Check that access is size aligned. */
if ( (reg & (len - 1)) )
return false;
return false;
vpci_write(sbdf, reg, min(4u, len), data);
+#ifdef CONFIG_64BIT
if ( len == 8 )
vpci_write(sbdf, reg + 4, 4, data >> 32);
+#endif
return true;
}
* 4byte accesses.
*/
*data = vpci_read(sbdf, reg, min(4u, len));
+#ifdef CONFIG_64BIT
if ( len == 8 )
*data |= (uint64_t)vpci_read(sbdf, reg + 4, 4) << 32;
+#endif
return true;
}
#define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_flag)
+/* vPCI is not available on Arm */
#define has_vpci(d) ({ (void)(d); false; })
#endif /* __ASM_DOMAIN_H__ */
#define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000) /* vCPU0..127 */
#define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000)
+/*
+ * 256 MB is reserved for VPCI configuration space based on calculation
+ * 256 buses x 32 devices x 8 functions x 4 KB = 256 MB
+ */
+#define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000)
+#define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000)
+
/* ACPI tables physical address */
#define GUEST_ACPI_BASE xen_mk_ullong(0x20000000)
#define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000)
#define PCI_SBDF3(s,b,df) \
((pci_sbdf_t){ .sbdf = (((s) & 0xffff) << 16) | PCI_BDF2(b, df) })
+#define ECAM_REG_OFFSET(addr) ((addr) & 0x00000fff)
+
typedef union {
uint32_t sbdf;
struct {