diff options
author | sephe <sephe@FreeBSD.org> | 2016-10-14 02:36:51 +0000 |
---|---|---|
committer | sephe <sephe@FreeBSD.org> | 2016-10-14 02:36:51 +0000 |
commit | 94d495c23f86bd6b35307d652e8e6665796aa822 (patch) | |
tree | 100fb447923f7e8274ed5de962803146320076a5 /sys/dev/pci/pci.c | |
parent | 02ccdee968df1b858b40f2bce6dd0614871b967d (diff) | |
download | FreeBSD-src-94d495c23f86bd6b35307d652e8e6665796aa822.zip FreeBSD-src-94d495c23f86bd6b35307d652e8e6665796aa822.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
Diffstat (limited to 'sys/dev/pci/pci.c')
-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 bb90375c..9bf37bc 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -4576,6 +4576,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; @@ -4660,8 +4661,17 @@ pci_reserve_map(device_t dev, device_t child, int type, int *rid, device_printf(child, "Lazy allocation of %#lx bytes rid %#x type %d at %#lx\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); } |