Browse Source

[pci] Add generic configuration space backup/restore facility

Some devices can only be reset via a mechanism that also resets the
card's PCI core, thus necessitating a backup and restore of all or
part of the PCI configuration space across a reset.
tags/v0.9.8
Michael Brown 14 years ago
parent
commit
4175b778c2
2 changed files with 123 additions and 0 deletions
  1. 90
    0
      src/drivers/bus/pcibackup.c
  2. 33
    0
      src/include/gpxe/pcibackup.h

+ 90
- 0
src/drivers/bus/pcibackup.c View File

@@ -0,0 +1,90 @@
1
+/*
2
+ * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+#include <stdint.h>
22
+#include <gpxe/pci.h>
23
+#include <gpxe/pcibackup.h>
24
+
25
+/** @file
26
+ *
27
+ * PCI configuration space backup and restoration
28
+ *
29
+ */
30
+
31
+/**
32
+ * Check PCI configuration space offset against exclusion list
33
+ *
34
+ * @v pci		PCI device
35
+ * @v offset		Offset within PCI configuration space
36
+ * @v exclude		PCI configuration space backup exclusion list, or NULL
37
+ */
38
+static int
39
+pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
40
+		      const uint8_t *exclude ) {
41
+
42
+	if ( ! exclude )
43
+		return 0;
44
+	for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
45
+		if ( offset == *exclude ) {
46
+			DBGC ( pci, "PCI %p skipping configuration offset "
47
+			       "%02x\n", pci, offset );
48
+			return 1;
49
+		}
50
+	}
51
+	return 0;
52
+}
53
+
54
+/**
55
+ * Back up PCI configuration space
56
+ *
57
+ * @v pci		PCI device
58
+ * @v backup		PCI configuration space backup
59
+ * @v exclude		PCI configuration space backup exclusion list, or NULL
60
+ */
61
+void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
62
+		  const uint8_t *exclude ) {
63
+	unsigned int offset;
64
+	uint32_t *dword;
65
+
66
+	for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
67
+	      offset += sizeof ( *dword ) , dword++ ) {
68
+		if ( ! pci_backup_excluded ( pci, offset, exclude ) )
69
+			pci_read_config_dword ( pci, offset, dword );
70
+	}
71
+}
72
+
73
+/**
74
+ * Restore PCI configuration space
75
+ *
76
+ * @v pci		PCI device
77
+ * @v backup		PCI configuration space backup
78
+ * @v exclude		PCI configuration space backup exclusion list, or NULL
79
+ */
80
+void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
81
+		   const uint8_t *exclude ) {
82
+	unsigned int offset;
83
+	uint32_t *dword;
84
+
85
+	for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
86
+	      offset += sizeof ( *dword ) , dword++ ) {
87
+		if ( ! pci_backup_excluded ( pci, offset, exclude ) )
88
+			pci_write_config_dword ( pci, offset, *dword );
89
+	}
90
+}

+ 33
- 0
src/include/gpxe/pcibackup.h View File

@@ -0,0 +1,33 @@
1
+#ifndef _GPXE_PCIBACKUP_H
2
+#define _GPXE_PCIBACKUP_H
3
+
4
+/** @file
5
+ *
6
+ * PCI configuration space backup and restoration
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <stdint.h>
13
+
14
+/** A PCI configuration space backup */
15
+struct pci_config_backup {
16
+	uint32_t dwords[64];
17
+};
18
+
19
+/** PCI configuration space backup exclusion list end marker */
20
+#define PCI_CONFIG_BACKUP_EXCLUDE_END 0xff
21
+
22
+/** Define a PCI configuration space backup exclusion list */
23
+#define PCI_CONFIG_BACKUP_EXCLUDE(...) \
24
+	{ __VA_ARGS__, PCI_CONFIG_BACKUP_EXCLUDE_END }
25
+
26
+extern void pci_backup ( struct pci_device *pci,
27
+			 struct pci_config_backup *backup,
28
+			 const uint8_t *exclude );
29
+extern void pci_restore ( struct pci_device *pci,
30
+			  struct pci_config_backup *backup,
31
+			  const uint8_t *exclude );
32
+
33
+#endif /* _GPXE_PCIBACKUP_H */

Loading…
Cancel
Save