From patchwork Sun Mar 24 11:32:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 230432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E9E0F2C00C4 for ; Sun, 24 Mar 2013 22:36:14 +1100 (EST) Received: from localhost ([::1]:47961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJjDh-0004Aa-6v for incoming@patchwork.ozlabs.org; Sun, 24 Mar 2013 07:36:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJjAa-0008AS-54 for qemu-devel@nongnu.org; Sun, 24 Mar 2013 07:33:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UJjAU-0004xx-Hx for qemu-devel@nongnu.org; Sun, 24 Mar 2013 07:32:58 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:33103 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJjAU-0004ta-AG for qemu-devel@nongnu.org; Sun, 24 Mar 2013 07:32:54 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UJjAG-0001W7-Ce; Sun, 24 Mar 2013 11:32:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Sun, 24 Mar 2013 11:32:37 +0000 Message-Id: <1364124760-5794-8-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1364124760-5794-1-git-send-email-peter.maydell@linaro.org> References: <1364124760-5794-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Arnd Bergmann , "Michael S. Tsirkin" , patches@linaro.org, Will Deacon , Paul Brook , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 07/10] versatile_pci: Implement the correct PCI IRQ mapping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Implement the correct IRQ mapping for the Versatile PCI controller; it differs between realview and versatile boards, but the previous QEMU implementation was correct only for the first PCI card on a versatile board, since we weren't swizzling IRQs based on the slot number. Note that this change will break any uses of PCI on Linux kernels which have an equivalent bug (since they have effectively only been tested against QEMU, not real hardware). Unfortunately this currently means "all Linux kernels" and "all uses of versatilepb with a hard disk" since we default to a PCI SCSI controller. We therefore provide a property for enabling the old broken IRQ mapping; this can be enabled with the command line option: -global versatile_pci.broken-irq-mapping=1 Signed-off-by: Peter Maydell --- hw/versatile_pci.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c index 576e619..7739f4c 100644 --- a/hw/versatile_pci.c +++ b/hw/versatile_pci.c @@ -26,6 +26,7 @@ typedef struct { /* Constant for life of device: */ int realview; + uint8_t broken_irq_mapping; } PCIVPBState; #define TYPE_VERSATILE_PCI "versatile_pci" @@ -61,11 +62,52 @@ static const MemoryRegionOps pci_vpb_config_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int pci_vpb_map_irq(PCIDevice *d, int irq_num) +static int pci_vpb_broken_map_irq(PCIDevice *d, int irq_num) { + /* Map IRQs as old and buggy versions of QEMU have done in the past; + * this is not how hardware behaves, and it will not work with guests + * which drive the hardware correctly, but it allows us to work with + * buggy Linux kernels which were written against the buggy QEMU. + */ return irq_num; } +static int pci_vpb_map_irq(PCIDevice *d, int irq_num) +{ + /* Slot to IRQ mapping for RealView Platform Baseboard 926 backplane + * name slot IntA IntB IntC IntD + * A 31 IRQ28 IRQ29 IRQ30 IRQ27 + * B 30 IRQ27 IRQ28 IRQ29 IRQ30 + * C 29 IRQ30 IRQ27 IRQ28 IRQ29 + * Slot C is for the host bridge; A and B the peripherals. + * Our output irqs 0..3 correspond to the baseboard's 27..30. + * + * This mapping function takes account of an oddity in the PB926 + * board wiring, where the FPGA's P_nINTA input is connected to + * the INTB connection on the board PCI edge connector, P_nINTB + * is connected to INTC, and so on, so everything is one number + * further round from where you might expect. + */ + return (PCI_SLOT(d->devfn) + irq_num - 2) % PCI_NUM_PINS; +} + +static int pci_vpb_rv_map_irq(PCIDevice *d, int irq_num) +{ + /* Slot to IRQ mapping for RealView EB and PB1176 backplane + * name slot IntA IntB IntC IntD + * A 31 IRQ50 IRQ51 IRQ48 IRQ49 + * B 30 IRQ49 IRQ50 IRQ51 IRQ48 + * C 29 IRQ48 IRQ49 IRQ50 IRQ51 + * Slot C is for the host bridge; A and B the peripherals. + * Our output irqs 0..3 correspond to the baseboard's 48..51. + * + * The PB1176 and EB boards don't have the PB926 wiring oddity + * described above; P_nINTA connects to INTA, P_nINTB to INTB + * and so on, which is why this mapping function is different. + */ + return (PCI_SLOT(d->devfn) + irq_num - 1) % PCI_NUM_PINS; +} + static void pci_vpb_set_irq(void *opaque, int irq_num, int level) { qemu_irq *pic = opaque; @@ -95,13 +137,22 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp) { PCIVPBState *s = PCI_VPB(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + pci_map_irq_fn mapfn; int i; for (i = 0; i < 4; i++) { sysbus_init_irq(sbd, &s->irq[i]); } - pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, pci_vpb_map_irq, s->irq, 4); + if (s->broken_irq_mapping) { + mapfn = pci_vpb_broken_map_irq; + } else if (s->realview) { + mapfn = pci_vpb_rv_map_irq; + } else { + mapfn = pci_vpb_map_irq; + } + + pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, mapfn, s->irq, 4); /* ??? Register memory space. */ @@ -154,11 +205,17 @@ static const TypeInfo versatile_pci_host_info = { .class_init = versatile_pci_host_class_init, }; +static Property pci_vpb_properties[] = { + DEFINE_PROP_UINT8("broken-irq-mapping", PCIVPBState, broken_irq_mapping, 0), + DEFINE_PROP_END_OF_LIST() +}; + static void pci_vpb_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->realize = pci_vpb_realize; + dc->props = pci_vpb_properties; } static const TypeInfo pci_vpb_info = {