pcibackup.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <stdint.h>
00022 #include <gpxe/pci.h>
00023 #include <gpxe/pcibackup.h>
00024 
00025 /** @file
00026  *
00027  * PCI configuration space backup and restoration
00028  *
00029  */
00030 
00031 /**
00032  * Check PCI configuration space offset against exclusion list
00033  *
00034  * @v pci               PCI device
00035  * @v offset            Offset within PCI configuration space
00036  * @v exclude           PCI configuration space backup exclusion list, or NULL
00037  */
00038 static int
00039 pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
00040                       const uint8_t *exclude ) {
00041 
00042         if ( ! exclude )
00043                 return 0;
00044         for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
00045                 if ( offset == *exclude ) {
00046                         DBGC ( pci, "PCI %p skipping configuration offset "
00047                                "%02x\n", pci, offset );
00048                         return 1;
00049                 }
00050         }
00051         return 0;
00052 }
00053 
00054 /**
00055  * Back up PCI configuration space
00056  *
00057  * @v pci               PCI device
00058  * @v backup            PCI configuration space backup
00059  * @v exclude           PCI configuration space backup exclusion list, or NULL
00060  */
00061 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
00062                   const uint8_t *exclude ) {
00063         unsigned int offset;
00064         uint32_t *dword;
00065 
00066         for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
00067               offset += sizeof ( *dword ) , dword++ ) {
00068                 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
00069                         pci_read_config_dword ( pci, offset, dword );
00070         }
00071 }
00072 
00073 /**
00074  * Restore PCI configuration space
00075  *
00076  * @v pci               PCI device
00077  * @v backup            PCI configuration space backup
00078  * @v exclude           PCI configuration space backup exclusion list, or NULL
00079  */
00080 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
00081                    const uint8_t *exclude ) {
00082         unsigned int offset;
00083         uint32_t *dword;
00084 
00085         for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
00086               offset += sizeof ( *dword ) , dword++ ) {
00087                 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
00088                         pci_write_config_dword ( pci, offset, *dword );
00089         }
00090 }

Generated on Tue Apr 6 20:00:52 2010 for gPXE by  doxygen 1.5.7.1