Commit 66082ed6 authored by Peter Xu's avatar Peter Xu Committed by Paolo Bonzini
Browse files

pci: provide pci_enable_defaults()



One helper function to set/clear specific bit in PCI_COMMAND register is
introduced. Then, provide a function to do most of the common PCI init
work.
Suggested-by: Andrew Jones's avatarAndrew Jones <drjones@redhat.com>
Reviewed-by: Andrew Jones's avatarAndrew Jones <drjones@redhat.com>
Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent e954ce23
......@@ -7,6 +7,18 @@
#include "pci.h"
#include "asm/pci.h"
void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr)
{
uint16_t val = pci_config_readw(dev->bdf, PCI_COMMAND);
/* No overlap is allowed */
assert((set & clr) == 0);
val |= set;
val &= ~clr;
pci_config_writew(dev->bdf, PCI_COMMAND, val);
}
bool pci_dev_exists(pcidevaddr_t dev)
{
return (pci_config_readw(dev, PCI_VENDOR_ID) != 0xffff &&
......@@ -246,3 +258,10 @@ void pci_scan_bars(struct pci_dev *dev)
}
}
}
void pci_enable_defaults(struct pci_dev *dev)
{
pci_scan_bars(dev);
/* Enable device DMA operations */
pci_cmd_set_clr(dev, PCI_COMMAND_MASTER, 0);
}
......@@ -25,6 +25,8 @@ struct pci_dev {
extern void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf);
extern void pci_scan_bars(struct pci_dev *dev);
extern void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr);
extern void pci_enable_defaults(struct pci_dev *dev);
extern bool pci_probe(void);
extern void pci_print(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