From owner-svn-src-all@freebsd.org Mon Dec 14 17:08:41 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A0E7A4417E; Mon, 14 Dec 2015 17:08:41 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 27F471B71; Mon, 14 Dec 2015 17:08:41 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBEH8eI0059048; Mon, 14 Dec 2015 17:08:40 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBEH8e1D059047; Mon, 14 Dec 2015 17:08:40 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201512141708.tBEH8e1D059047@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Mon, 14 Dec 2015 17:08:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292215 - head/sys/dev/pci X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2015 17:08:41 -0000 Author: andrew Date: Mon Dec 14 17:08:40 2015 New Revision: 292215 URL: https://svnweb.freebsd.org/changeset/base/292215 Log: Update the handling of interrupts on the generic PCIe driver: * Use the interrupt-map property to route interrupts * Remove the IRQ rman, it's now unneeded * Support MSI/MSI-X interrupts With this I'm able to use the two NICs I've tested (em and msk), however while I can boot with an AHCI devie attached it fails when any drives are connected. Obtained from: ABT Systems Ltd Sponsored by: SoftIron Inc Modified: head/sys/dev/pci/pci_host_generic.c Modified: head/sys/dev/pci/pci_host_generic.c ============================================================================== --- head/sys/dev/pci/pci_host_generic.c Mon Dec 14 16:07:20 2015 (r292214) +++ head/sys/dev/pci/pci_host_generic.c Mon Dec 14 17:08:40 2015 (r292215) @@ -43,12 +43,15 @@ __FBSDID("$FreeBSD$"); #include #include #include + #include #include #include +#include #include #include #include + #include #include #include @@ -75,8 +78,6 @@ __FBSDID("$FreeBSD$"); #define MIN_RANGES_TUPLES 2 #define PCI_IO_WINDOW_OFFSET 0x1000 -#define PCI_IRQ_START 32 -#define PCI_IRQ_END (PCI_IRQ_START + 4) #define SPACE_CODE_SHIFT 24 #define SPACE_CODE_MASK 0x3 @@ -98,7 +99,6 @@ struct generic_pcie_softc { int nranges; struct rman mem_rman; struct rman io_rman; - struct rman irq_rman; struct resource *res; struct resource *res1; int ecam; @@ -106,6 +106,7 @@ struct generic_pcie_softc { bus_space_handle_t bsh; device_t dev; bus_space_handle_t ioh; + struct ofw_bus_iinfo pci_iinfo; }; /* Forward prototypes */ @@ -216,14 +217,9 @@ generic_pcie_attach(device_t dev) } } - /* TODO: get IRQ numbers from FDT */ - sc->irq_rman.rm_type = RMAN_ARRAY; - sc->irq_rman.rm_descr = "Generic PCIe IRQs"; - if (rman_init(&sc->irq_rman) != 0 || - rman_manage_region(&sc->irq_rman, PCI_IRQ_START, - PCI_IRQ_END) != 0) { - panic("Generic PCI: failed to set up IRQ rman"); - } + ofw_bus_setup_iinfo(ofw_bus_get_node(dev), &sc->pci_iinfo, + sizeof(cell_t)); + device_add_child(dev, "pci", -1); return (bus_generic_attach(dev)); @@ -341,10 +337,6 @@ generic_pcie_read_config(device_t dev, u return (~0U); } - if (reg == PCIR_INTLINE) { - data += PCI_IRQ_START; - } - return (data); } @@ -390,6 +382,37 @@ generic_pcie_maxslots(device_t dev) } static int +generic_pcie_route_interrupt(device_t bus, device_t dev, int pin) +{ + struct generic_pcie_softc *sc; + struct ofw_pci_register reg; + uint32_t pintr, mintr[2]; + phandle_t iparent; + int intrcells; + + sc = device_get_softc(bus); + pintr = pin; + + bzero(®, sizeof(reg)); + reg.phys_hi = (pci_get_bus(dev) << OFW_PCI_PHYS_HI_BUSSHIFT) | + (pci_get_slot(dev) << OFW_PCI_PHYS_HI_DEVICESHIFT) | + (pci_get_function(dev) << OFW_PCI_PHYS_HI_FUNCTIONSHIFT); + + intrcells = ofw_bus_lookup_imap(ofw_bus_get_node(dev), + &sc->pci_iinfo, ®, sizeof(reg), &pintr, sizeof(pintr), + mintr, sizeof(mintr), &iparent); + if (intrcells) { + pintr = ofw_bus_map_intr(dev, iparent, intrcells, mintr); + return (pintr); + } + + device_printf(bus, "could not route pin %d for device %d.%d\n", + pin, pci_get_slot(dev), pci_get_function(dev)); + return (PCI_INVALID_IRQ); +} + + +static int generic_pcie_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) { @@ -432,8 +455,6 @@ generic_pcie_rman(struct generic_pcie_so return (&sc->io_rman); case SYS_RES_MEMORY: return (&sc->mem_rman); - case SYS_RES_IRQ: - return (&sc->irq_rman); default: break; } @@ -606,9 +627,20 @@ static device_method_t generic_pcie_meth DEVMETHOD(bus_deactivate_resource, generic_pcie_deactivate_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + + /* pcib interface */ DEVMETHOD(pcib_maxslots, generic_pcie_maxslots), + DEVMETHOD(pcib_route_interrupt, generic_pcie_route_interrupt), DEVMETHOD(pcib_read_config, generic_pcie_read_config), DEVMETHOD(pcib_write_config, generic_pcie_write_config), +#if defined(__aarch64__) + DEVMETHOD(pcib_alloc_msi, arm_alloc_msi), + DEVMETHOD(pcib_release_msi, arm_release_msi), + DEVMETHOD(pcib_alloc_msix, arm_alloc_msix), + DEVMETHOD(pcib_release_msix, arm_release_msix), + DEVMETHOD(pcib_map_msi, arm_map_msi), +#endif + DEVMETHOD_END };