msix: Rework MSI-X allocation, step 2/3
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 16 Jan 2012 08:38:36 +0000 (16:38 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 16 Jan 2012 08:38:36 +0000 (16:38 +0800)
Add pci_{enable,disable}_msix(), which enable/disable MSI-X globally

sys/bus/pci/pci.c
sys/bus/pci/pcivar.h

index 26f39eb..a5f297e 100644 (file)
@@ -1741,6 +1741,39 @@ pci_teardown_msix(device_t dev)
        msix->msix_pba_res = NULL;
 }
 
+void
+pci_enable_msix(device_t dev)
+{
+       struct pci_devinfo *dinfo = device_get_ivars(dev);
+       struct pcicfg_msix *msix = &dinfo->cfg.msix;
+
+       KASSERT(msix->msix_table_res != NULL &&
+           msix->msix_pba_res != NULL, ("MSI-X is not setup yet\n"));
+
+       /* Update control register to enable MSI-X. */
+       msix->msix_ctrl |= PCIM_MSIXCTRL_MSIX_ENABLE;
+       pci_write_config(dev, msix->msix_location + PCIR_MSIX_CTRL,
+           msix->msix_ctrl, 2);
+}
+
+void
+pci_disable_msix(device_t dev)
+{
+       struct pci_devinfo *dinfo = device_get_ivars(dev);
+       struct pcicfg_msix *msix = &dinfo->cfg.msix;
+
+       KASSERT(msix->msix_table_res != NULL &&
+           msix->msix_pba_res != NULL, ("MSI-X is not setup yet\n"));
+
+       /* Disable MSI -> HT mapping. */
+       pci_ht_map_msi(dev, 0);
+
+       /* Update control register to disable MSI-X. */
+       msix->msix_ctrl &= ~PCIM_MSIXCTRL_MSIX_ENABLE;
+       pci_write_config(dev, msix->msix_location + PCIR_MSIX_CTRL,
+           msix->msix_ctrl, 2);
+}
+
 static void
 pci_mask_msix_allvectors(device_t dev)
 {
@@ -1771,7 +1804,7 @@ pci_ht_map_msi(device_t dev, uint64_t addr)
                    ht->ht_msictrl, 2);
        }
 
-       if (!addr && ht->ht_msictrl & PCIM_HTCMD_MSI_ENABLE) {
+       if (!addr && (ht->ht_msictrl & PCIM_HTCMD_MSI_ENABLE)) {
                /* Disable MSI -> HT mapping. */
                ht->ht_msictrl &= ~PCIM_HTCMD_MSI_ENABLE;
                pci_write_config(dev, ht->ht_msimap + PCIR_HT_COMMAND,
index b031f89..b7298f5 100644 (file)
@@ -502,6 +502,8 @@ device_t pci_find_device(uint16_t, uint16_t);
 int    pci_pending_msix_vector(device_t dev, u_int index);
 int    pci_setup_msix(device_t dev);
 void   pci_teardown_msix(device_t dev);
+void   pci_enable_msix(device_t dev);
+void   pci_disable_msix(device_t dev);
 
 int    pci_msi_device_blacklisted(device_t dev);