Commit 19daf1c5 authored by Peter Xu's avatar Peter Xu Committed by Paolo Bonzini
Browse files

pci: introduce pci_msi_set_enable()



Generalize this function out of pci_setup_msi(), then it can be further
used to enable INTx (or, disable MSI).
Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 352096c7
......@@ -39,6 +39,22 @@ void pci_cap_walk(struct pci_dev *dev)
}
}
void pci_msi_set_enable(struct pci_dev *dev, bool enabled)
{
uint16_t msi_control;
uint16_t offset;
offset = dev->msi_offset;
msi_control = pci_config_readw(dev->bdf, offset + PCI_MSI_FLAGS);
if (enabled)
msi_control |= PCI_MSI_FLAGS_ENABLE;
else
msi_control &= ~PCI_MSI_FLAGS_ENABLE;
pci_config_writew(dev->bdf, offset + PCI_MSI_FLAGS, msi_control);
}
bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
{
uint16_t msi_control;
......@@ -69,8 +85,7 @@ bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
}
printf("addr=0x%lx, data=0x%x\n", msi_addr, msi_data);
msi_control |= PCI_MSI_FLAGS_ENABLE;
pci_config_writew(addr, offset + PCI_MSI_FLAGS, msi_control);
pci_msi_set_enable(dev, true);
return true;
}
......
......@@ -65,6 +65,7 @@ extern bool pci_bar_is_valid(struct pci_dev *dev, int bar_num);
extern void pci_bar_print(struct pci_dev *dev, int bar_num);
extern void pci_dev_print_id(pcidevaddr_t dev);
extern uint8_t pci_intx_line(struct pci_dev *dev);
void pci_msi_set_enable(struct pci_dev *dev, bool enabled);
extern int pci_testdev(void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment