--- //depot/projects/smpng/sys/dev/bce/if_bce.c 2006/11/01 16:51:48 +++ //depot/user/jhb/msi/dev/bce/if_bce.c 2006/11/09 20:28:47 @@ -452,7 +452,7 @@ struct bce_softc *sc; struct ifnet *ifp; u32 val; - int mbuf, rid, rc = 0; + int count, mbuf, rid, rc = 0; sc = device_get_softc(dev); sc->bce_dev = dev; @@ -485,7 +485,12 @@ sc->bce_vhandle = (vm_offset_t) rman_get_virtual(sc->bce_res); /* Allocate PCI IRQ resources. */ - rid = 0; + count = pci_msi_count(dev); + if (count == 1 && pci_alloc_msi(dev, &count) == 0) { + rid = 1; + sc->bce_flags |= BCE_USING_MSI_FLAG; + } else + rid = 0; sc->bce_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); @@ -2539,9 +2544,12 @@ if (sc->bce_irq != NULL) bus_release_resource(dev, SYS_RES_IRQ, - 0, + sc->bce_flags & BCE_USING_MSI_FLAG ? 1 : 0, sc->bce_irq); + if (sc->bce_flags & BCE_USING_MSI_FLAG) + pci_release_msi(dev); + if (sc->bce_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, --- //depot/projects/smpng/sys/dev/em/if_em.c 2006/11/08 19:13:38 +++ //depot/user/jhb/msi/dev/em/if_em.c 2006/11/09 20:28:47 @@ -2196,7 +2196,12 @@ rman_get_bushandle(adapter->flash_mem); } - rid = 0x0; + val = pci_msi_count(dev); + if (val == 1 && pci_alloc_msi(dev, &val) == 0) { + rid = 1; + adapter->msi = 1; + } else + rid = 0; adapter->res_interrupt = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); if (adapter->res_interrupt == NULL) { @@ -2275,7 +2280,11 @@ device_t dev = adapter->dev; if (adapter->res_interrupt != NULL) - bus_release_resource(dev, SYS_RES_IRQ, 0, adapter->res_interrupt); + bus_release_resource(dev, SYS_RES_IRQ, adapter->msi ? 1 : 0, + adapter->res_interrupt); + + if (adapter->msi) + pci_release_msi(dev); if (adapter->res_memory != NULL) bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), --- //depot/projects/smpng/sys/dev/em/if_em.h 2006/11/01 16:51:48 +++ //depot/user/jhb/msi/dev/em/if_em.h 2006/11/06 20:00:59 @@ -287,6 +287,7 @@ struct callout timer; struct callout tx_fifo_timer; int io_rid; + int msi; int if_flags; struct mtx mtx; int em_insert_vlan_header; --- //depot/projects/smpng/sys/dev/mpt/mpt.h 2006/10/11 18:45:33 +++ //depot/user/jhb/msi/dev/mpt/mpt.h 2006/11/10 01:18:57 @@ -599,6 +599,7 @@ /* * PCI Hardware info */ + int pci_msi_count; struct resource * pci_irq; /* Interrupt map for chip */ void * ih; /* Interupt handle */ struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ --- //depot/projects/smpng/sys/dev/mpt/mpt_pci.c 2006/10/11 18:45:33 +++ //depot/user/jhb/msi/dev/mpt/mpt_pci.c 2006/11/13 20:57:17 @@ -512,6 +512,13 @@ /* Get a handle to the interrupt */ iqd = 0; + if (pci_msi_count(dev) == 1) { + mpt->pci_msi_count = 1; + if (pci_alloc_msi(dev, &mpt->pci_msi_count) == 0) + iqd = 1; + else + mpt->pci_msi_count = 0; + } mpt->pci_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &iqd, RF_ACTIVE | RF_SHAREABLE); if (mpt->pci_irq == NULL) { @@ -608,10 +615,16 @@ } if (mpt->pci_irq) { - bus_release_resource(mpt->dev, SYS_RES_IRQ, 0, mpt->pci_irq); + bus_release_resource(mpt->dev, SYS_RES_IRQ, + mpt->pci_msi_count ? 1 : 0, mpt->pci_irq); mpt->pci_irq = 0; } + if (mpt->pci_msi_count) { + pci_release_msi(mpt->dev); + mpt->pci_msi_count = 0; + } + if (mpt->pci_pio_reg) { bus_release_resource(mpt->dev, SYS_RES_IOPORT, mpt->pci_pio_rid, mpt->pci_pio_reg);