svn commit: r307597 - stable/11/sys/dev/pci

Sepherosa Ziehau sephe at FreeBSD.org
Wed Oct 19 02:20:50 UTC 2016


Author: sephe
Date: Wed Oct 19 02:20:48 2016
New Revision: 307597
URL: https://svnweb.freebsd.org/changeset/base/307597

Log:
  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

Modified:
  stable/11/sys/dev/pci/pci.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/pci/pci.c
==============================================================================
--- stable/11/sys/dev/pci/pci.c	Wed Oct 19 02:15:41 2016	(r307596)
+++ stable/11/sys/dev/pci/pci.c	Wed Oct 19 02:20:48 2016	(r307597)
@@ -4999,6 +4999,7 @@ pci_reserve_map(device_t dev, device_t c
 	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 c
 		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);
 }


More information about the svn-src-all mailing list