2 * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
24 #include <ipxe/pcibackup.h>
28 * PCI configuration space backup and restoration
33 * Check PCI configuration space offset against exclusion list
36 * @v offset Offset within PCI configuration space
37 * @v exclude PCI configuration space backup exclusion list, or NULL
40 pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
41 const uint8_t *exclude ) {
45 for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
46 if ( offset == *exclude ) {
47 DBGC ( pci, "PCI %p skipping configuration offset "
48 "%02x\n", pci, offset );
56 * Back up PCI configuration space
59 * @v backup PCI configuration space backup
60 * @v exclude PCI configuration space backup exclusion list, or NULL
62 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
63 const uint8_t *exclude ) {
67 for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
68 offset += sizeof ( *dword ) , dword++ ) {
69 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
70 pci_read_config_dword ( pci, offset, dword );
75 * Restore PCI configuration space
78 * @v backup PCI configuration space backup
79 * @v exclude PCI configuration space backup exclusion list, or NULL
81 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
82 const uint8_t *exclude ) {
86 for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
87 offset += sizeof ( *dword ) , dword++ ) {
88 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
89 pci_write_config_dword ( pci, offset, *dword );