diff options
author | sephe <sephe@FreeBSD.org> | 2016-10-19 02:20:48 +0000 |
---|---|---|
committer | sephe <sephe@FreeBSD.org> | 2016-10-19 02:20:48 +0000 |
commit | f15b3cbb14ab376fb350b0d1cbff7c6f913770e7 (patch) | |
tree | 8b7660d6a65bc6fe19a9c09832934510d7f4d0b8 | |
parent | fc290a654fe270f7221e8ac3b4813936aed2f639 (diff) | |
download | FreeBSD-src-f15b3cbb14ab376fb350b0d1cbff7c6f913770e7.zip FreeBSD-src-f15b3cbb14ab376fb350b0d1cbff7c6f913770e7.tar.gz |
MFC 306359
pci: Clear the MEM/PORT_EN bit when updating PCI BAR
It's unsafe to update the BAR when the related EN bit is set.
Submitted by: Dexuan Cui <decui microsoft com>
Reviewed by: jhb
Sponsored by: Microsoft
Differential Revision: https://reviews.freebsd.org/D7914
-rw-r--r-- | sys/dev/pci/pci.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index fa807a6..5bc938b 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -4999,6 +4999,7 @@ pci_reserve_map(device_t dev, device_t child, int type, int *rid, struct resource_list *rl = &dinfo->resources; struct resource *res; struct pci_map *pm; + uint16_t cmd; pci_addr_t map, testval; int mapsize; @@ -5088,8 +5089,17 @@ pci_reserve_map(device_t dev, device_t child, int type, int *rid, device_printf(child, "Lazy allocation of %#jx bytes rid %#x type %d at %#jx\n", count, *rid, type, rman_get_start(res)); + + /* Disable decoding via the CMD register before updating the BAR */ + cmd = pci_read_config(child, PCIR_COMMAND, 2); + pci_write_config(child, PCIR_COMMAND, + cmd & ~(PCI_BAR_MEM(map) ? PCIM_CMD_MEMEN : PCIM_CMD_PORTEN), 2); + map = rman_get_start(res); pci_write_bar(child, pm, map); + + /* Restore the original value of the CMD register */ + pci_write_config(child, PCIR_COMMAND, cmd, 2); out: return (res); } |