1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * MSI[X} related functions which are available unconditionally.
4  */
5 #include "../pci.h"
6 
7 /*
8  * Disable the MSI[X] hardware to avoid screaming interrupts during boot.
9  * This is the power on reset default so usually this should be a noop.
10  */
11 
pci_msi_init(struct pci_dev * dev)12 void pci_msi_init(struct pci_dev *dev)
13 {
14 	u16 ctrl;
15 
16 	dev->msi_cap = pci_find_capability(dev, PCI_CAP_ID_MSI);
17 	if (!dev->msi_cap)
18 		return;
19 
20 	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &ctrl);
21 	if (ctrl & PCI_MSI_FLAGS_ENABLE) {
22 		pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS,
23 				      ctrl & ~PCI_MSI_FLAGS_ENABLE);
24 	}
25 
26 	if (!(ctrl & PCI_MSI_FLAGS_64BIT))
27 		dev->no_64bit_msi = 1;
28 }
29 
pci_msix_init(struct pci_dev * dev)30 void pci_msix_init(struct pci_dev *dev)
31 {
32 	u16 ctrl;
33 
34 	dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
35 	if (!dev->msix_cap)
36 		return;
37 
38 	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
39 	if (ctrl & PCI_MSIX_FLAGS_ENABLE) {
40 		pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS,
41 				      ctrl & ~PCI_MSIX_FLAGS_ENABLE);
42 	}
43 }
44