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: 15561 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9D86A23E3E for ; Sun, 24 Mar 2013 11:32:48 +0000 (UTC) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by fiordland.canonical.com (Postfix) with ESMTP id 47B03A18D67 for ; Sun, 24 Mar 2013 11:32:48 +0000 (UTC) Received: by mail-ve0-f182.google.com with SMTP id ox1so4351842veb.41 for ; Sun, 24 Mar 2013 04:32:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=XDWqH0R4Y2ME7TNP+XAoLmdb/2euIVAuO4XhD55MWn4=; b=JN43V8aQDUebI5zVPTU4zDU1n5YayRiuL1PCaPyZd4znag01+QQm0rEzOvmBeZaTMT RLqXxaJOQo9ptYnEmUaxflThs9LrrzFAbcT3bw4EGI1HaVZ4pJgfS3mZsG2QGJffa0I6 8uWuyVZXMwL60E586z5PAWFHtQq01EE7Kh3R2ex4WWTKHcg7xJmc1RlmssU7e6on6j5A HQCbiTJmqFSPqJuOHIhK1Nx5Y373CYmba92feKIPrAxbYrRLkRcqAR5I2hkmDit/LBg+ GQHHXX5qZaodjIuELUHanz4dpKazo4tjPHla3jgWIzy6/W/xG+wzoU4pgn1Ixf/C0qKr b/GA== X-Received: by 10.220.150.74 with SMTP id x10mr10723656vcv.68.1364124767792; Sun, 24 Mar 2013 04:32:47 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp4956ved; Sun, 24 Mar 2013 04:32:47 -0700 (PDT) X-Received: by 10.15.100.202 with SMTP id bn50mr22672493eeb.36.1364124764417; Sun, 24 Mar 2013 04:32:44 -0700 (PDT) Received: from mnementh.archaic.org.uk (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]) by mx.google.com with ESMTPS id g8si14083547eem.59.2013.03.24.04.32.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 24 Mar 2013 04:32:44 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk 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 Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , "Michael S. Tsirkin" , Paul Brook , Arnd Bergmann , Will Deacon Subject: [PATCH 07/10] versatile_pci: Implement the correct PCI IRQ mapping 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-Gm-Message-State: ALoCoQmNl3haGrRFUbjVtJMiSX4O1PLOH4DeXgf61JseEOp1tTO+yaqkfP5jr+JI0JYY/3iI0BPT 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 = {