Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Mar 2012 20:20:55 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r232360 - in head: share/man/man9 sys/dev/pci
Message-ID:  <201203012020.q21KKtuG094854@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Thu Mar  1 20:20:55 2012
New Revision: 232360
URL: http://svn.freebsd.org/changeset/base/232360

Log:
  Add pci_save_state() and pci_restore_state() wrappers around
  pci_cfg_save() and pci_cfg_restore() for device drivers to use when
  saving and restoring state (e.g. to handle device-specific resets).
  
  Reviewed by:	imp
  MFC after:	2 weeks

Modified:
  head/share/man/man9/Makefile
  head/share/man/man9/pci.9
  head/sys/dev/pci/pci.c
  head/sys/dev/pci/pcivar.h

Modified: head/share/man/man9/Makefile
==============================================================================
--- head/share/man/man9/Makefile	Thu Mar  1 20:19:21 2012	(r232359)
+++ head/share/man/man9/Makefile	Thu Mar  1 20:20:55 2012	(r232360)
@@ -980,6 +980,8 @@ MLINKS+=pci.9 pci_disable_busmaster.9 \
 	pci.9 pci_find_device.9 \
 	pci.9 pci_get_powerstate.9 \
 	pci.9 pci_read_config.9 \
+	pci.9 pci_restore_state.9 \
+	pci.9 pci_save_state.9 \
 	pci.9 pci_set_powerstate.9 \
 	pci.9 pci_write_config.9
 MLINKS+=pfil.9 pfil_add_hook.9 \

Modified: head/share/man/man9/pci.9
==============================================================================
--- head/share/man/man9/pci.9	Thu Mar  1 20:19:21 2012	(r232359)
+++ head/share/man/man9/pci.9	Thu Mar  1 20:20:55 2012	(r232360)
@@ -38,6 +38,8 @@
 .Nm pci_disable_io ,
 .Nm pci_set_powerstate ,
 .Nm pci_get_powerstate ,
+.Nm pci_save_state ,
+.Nm pci_restore_state ,
 .Nm pci_find_bsf ,
 .Nm pci_find_dbsf ,
 .Nm pci_find_device
@@ -63,6 +65,10 @@
 .Fn pci_get_powerstate "device_t dev"
 .Ft uint32_t
 .Fn pci_read_config "device_t dev" "int reg" "int width"
+.Ft void
+.Fn pci_save_state "device_t dev"
+.Ft void
+.Fn pci_restore_state "device_t dev"
 .Ft device_t
 .Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
 .Ft device_t
@@ -188,6 +194,26 @@ of
 is set.
 .Pp
 The
+.Fn pci_save_state
+and
+.Fn pci_restore_state
+functions can be used by a device driver to save and restore standard PCI
+config registers.
+The
+.Fn pci_save_state
+function must be invoked while the device has valid state before
+.Fn pci_restore_state
+can be used.
+If the device is not in the fully-powered state
+.Pq Dv PCI_POWERSTATE_D0
+when
+.Fn pci_restore_state
+is invoked,
+then the device will be transitioned to
+.Dv PCI_POWERSTATE_D0
+before any config registers are restored.
+.Pp
+The
 .Fn pci_find_bsf
 function looks up the
 .Vt device_t

Modified: head/sys/dev/pci/pci.c
==============================================================================
--- head/sys/dev/pci/pci.c	Thu Mar  1 20:19:21 2012	(r232359)
+++ head/sys/dev/pci/pci.c	Thu Mar  1 20:20:55 2012	(r232360)
@@ -4426,3 +4426,22 @@ pci_cfg_save(device_t dev, struct pci_de
 	if (pci_get_powerstate(dev) != PCI_POWERSTATE_D3)
 		pci_set_powerstate(dev, PCI_POWERSTATE_D3);
 }
+
+/* Wrapper APIs suitable for device driver use. */
+void
+pci_save_state(device_t dev)
+{
+	struct pci_devinfo *dinfo;
+
+	dinfo = device_get_ivars(dev);
+	pci_cfg_save(dev, dinfo, 0);
+}
+
+void
+pci_restore_state(device_t dev)
+{
+	struct pci_devinfo *dinfo;
+
+	dinfo = device_get_ivars(dev);
+	pci_cfg_restore(dev, dinfo);
+}

Modified: head/sys/dev/pci/pcivar.h
==============================================================================
--- head/sys/dev/pci/pcivar.h	Thu Mar  1 20:19:21 2012	(r232359)
+++ head/sys/dev/pci/pcivar.h	Thu Mar  1 20:20:55 2012	(r232360)
@@ -467,6 +467,8 @@ int	pci_msi_device_blacklisted(device_t 
 void	pci_ht_map_msi(device_t dev, uint64_t addr);
 
 int	pci_get_max_read_req(device_t dev);
+void	pci_restore_state(device_t dev);
+void	pci_save_state(device_t dev);
 int	pci_set_max_read_req(device_t dev, int size);
 
 #endif	/* _SYS_BUS_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203012020.q21KKtuG094854>