hv: vpci: restore physical BARs when writing Command Register if necessary

When PCIe does Conventinal Reset or FLR, almost PCIe configurations and states will
lost. So we should save the configurations and states before do the reset and restore
them after the reset. This was done well by BIOS or Guest now. However, ACRN will trap
these access and handle them properly for security. Almost of these configurations and
states will be written to physical configuration space at last except for BAR values
for now. So we should do the restore for BAR values. One way is to do restore after
one type reset is detected. This will be too complex. Another way is to do the restore
when BIOS or guest tries to write the Command Register. This could work because:
1. The I/O Space Enable bit and Memory Space Enable bits in Command Register will reset
to zero.
2. Before BIOS or guest wants to enable these bits, the BAR couldn't be accessed.
3. So we could restore the BAR values before enable these bits if reset is detected.

Tracked-On: #3475
Signed-off-by: Li Fei1 <fei1.li@intel.com>
This commit is contained in:
Li Fei1
2019-12-26 00:35:34 +08:00
committed by wenlingz
parent 742abaf2e6
commit 6c549d48a8
5 changed files with 66 additions and 0 deletions

View File

@@ -179,11 +179,14 @@ struct pci_msix_cap {
};
struct pci_pdev {
uint8_t hdr_type;
/* IOMMU responsible for DMA and Interrupt Remapping for this device */
uint32_t drhd_index;
/* The bar info of the physical PCI device. */
uint32_t nr_bars; /* 6 for normal device, 2 for bridge, 1 for cardbus */
uint32_t bars[PCI_STD_NUM_BARS];
/* The bus/device/function triple of the physical PCI device. */
union pci_bdf bdf;
@@ -314,5 +317,7 @@ static inline bool is_pci_cfg_bridge(uint8_t header_type)
}
void pdev_do_flr(union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t val);
bool pdev_need_bar_restore(const struct pci_pdev *pdev);
void pdev_restore_bar(const struct pci_pdev *pdev);
#endif /* PCI_H_ */