From patchwork Thu Dec 24 12:29:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 69708 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id nBOCTwfs031697 for ; Thu, 24 Dec 2009 12:29:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751690AbZLXM34 (ORCPT ); Thu, 24 Dec 2009 07:29:56 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751478AbZLXM34 (ORCPT ); Thu, 24 Dec 2009 07:29:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23576 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441AbZLXM3z (ORCPT ); Thu, 24 Dec 2009 07:29:55 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBOCTjjV011856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Dec 2009 07:29:45 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBOCTihP009177; Thu, 24 Dec 2009 07:29:44 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id A2D211336CD; Thu, 24 Dec 2009 14:29:43 +0200 (IST) Date: Thu, 24 Dec 2009 14:29:43 +0200 From: Gleb Natapov To: seabios@seabios.org Cc: kvm@vger.kernel.org Subject: [PATCHv2] provide correct pci routing information in mptable Message-ID: <20091224122943.GA22901@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/src/mptable.c b/src/mptable.c index 1920dfe..2409fcf 100644 --- a/src/mptable.c +++ b/src/mptable.c @@ -9,6 +9,8 @@ #include "config.h" // CONFIG_* #include "mptable.h" // MPTABLE_SIGNATURE #include "paravirt.h" // qemu_cfg_irq0_override +#include "pci.h" +#include "pci_regs.h" void mptable_init(void) @@ -21,9 +23,9 @@ mptable_init(void) // Allocate memory int length = (sizeof(struct mptable_config_s) + sizeof(struct mpt_cpu) * MaxCountCPUs - + sizeof(struct mpt_bus) + + sizeof(struct mpt_bus) * 2 + sizeof(struct mpt_ioapic) - + sizeof(struct mpt_intsrc) * 18); + + sizeof(struct mpt_intsrc) * 34); struct mptable_config_s *config = malloc_fseg(length); struct mptable_floating_s *floating = malloc_fseg(sizeof(*floating)); if (!config || !floating) { @@ -85,9 +87,17 @@ mptable_init(void) struct mpt_bus *bus = (void*)cpu; memset(bus, 0, sizeof(*bus)); bus->type = MPT_TYPE_BUS; + bus->busid = 1; memcpy(bus->bustype, "ISA ", sizeof(bus->bustype)); entrycount++; + bus++; + memset(bus, 0, sizeof(*bus)); + bus->type = MPT_TYPE_BUS; + bus->busid = 0; + memcpy(bus->bustype, "PCI ", sizeof(bus->bustype)); + entrycount++; + /* ioapic */ u8 ioapic_id = CountCPUs; struct mpt_ioapic *ioapic = (void*)&bus[1]; @@ -101,9 +111,41 @@ mptable_init(void) /* irqs */ struct mpt_intsrc *intsrcs = (void*)&ioapic[1], *intsrc = intsrcs; + int bdf, max, dev = -1; + unsigned short mask = 0, pinmask; + + foreachpci(bdf, max) { + int pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN); + int irq = pci_config_readb(bdf, PCI_INTERRUPT_LINE); + if (pin == 0) + continue; + if (dev != pci_bdf_to_dev(bdf)) { + dev = pci_bdf_to_dev(bdf); + pinmask = 0; + } + if (pinmask & (1 << pin)) /* pin was seen already */ + continue; + pinmask |= (1 << pin); + mask |= (1 << irq); + memset(intsrc, 0, sizeof(*intsrc)); + intsrc->type = MPT_TYPE_INTSRC; + intsrc->irqtype = 0; /* INT */ + intsrc->irqflag = 1; /* active high */ + intsrc->srcbus = 0; /* PCI bus */ + intsrc->srcbusirq = (dev << 2) | (pin - 1); + intsrc->dstapic = ioapic_id; + intsrc->dstirq = irq; + intsrc++; + } + for (i = 0; i < 16; i++) { memset(intsrc, 0, sizeof(*intsrc)); + if (mask & (1 << i)) + continue; intsrc->type = MPT_TYPE_INTSRC; + intsrc->irqtype = 0; /* INT */ + intsrc->irqflag = 0; /* conform to bus spec */ + intsrc->srcbus = 1; /* ISA bus */ intsrc->srcbusirq = i; intsrc->dstapic = ioapic_id; intsrc->dstirq = i; @@ -123,7 +165,7 @@ mptable_init(void) intsrc->type = MPT_TYPE_LOCAL_INT; intsrc->irqtype = 3; /* ExtINT */ intsrc->irqflag = 0; /* PO, EL default */ - intsrc->srcbus = 0; + intsrc->srcbus = 1; /* ISA */ intsrc->srcbusirq = 0; intsrc->dstapic = 0; /* BSP == APIC #0 */ intsrc->dstirq = 0; /* LINTIN0 */ @@ -133,7 +175,7 @@ mptable_init(void) intsrc->type = MPT_TYPE_LOCAL_INT; intsrc->irqtype = 1; /* NMI */ intsrc->irqflag = 0; /* PO, EL default */ - intsrc->srcbus = 0; + intsrc->srcbus = 1; /* ISA */ intsrc->srcbusirq = 0; intsrc->dstapic = 0; /* BSP == APIC #0 */ intsrc->dstirq = 1; /* LINTIN1 */