iPXE
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., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdint.h>
00027 #include <ipxe/pci.h>
00028 #include <ipxe/pcibackup.h>
00029 
00030 /** @file
00031  *
00032  * PCI configuration space backup and restoration
00033  *
00034  */
00035 
00036 /**
00037  * Check PCI configuration space offset against exclusion list
00038  *
00039  * @v pci               PCI device
00040  * @v offset            Offset within PCI configuration space
00041  * @v exclude           PCI configuration space backup exclusion list, or NULL
00042  */
00043 static int
00044 pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
00045                       const uint8_t *exclude ) {
00046 
00047         if ( ! exclude )
00048                 return 0;
00049         for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
00050                 if ( offset == *exclude ) {
00051                         DBGC ( pci, "PCI %p skipping configuration offset "
00052                                "%02x\n", pci, offset );
00053                         return 1;
00054                 }
00055         }
00056         return 0;
00057 }
00058 
00059 /**
00060  * Back up PCI configuration space
00061  *
00062  * @v pci               PCI device
00063  * @v backup            PCI configuration space backup
00064  * @v exclude           PCI configuration space backup exclusion list, or NULL
00065  */
00066 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
00067                   const uint8_t *exclude ) {
00068         unsigned int offset;
00069         uint32_t *dword;
00070 
00071         for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
00072               offset += sizeof ( *dword ) , dword++ ) {
00073                 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
00074                         pci_read_config_dword ( pci, offset, dword );
00075         }
00076 }
00077 
00078 /**
00079  * Restore PCI configuration space
00080  *
00081  * @v pci               PCI device
00082  * @v backup            PCI configuration space backup
00083  * @v exclude           PCI configuration space backup exclusion list, or NULL
00084  */
00085 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
00086                    const uint8_t *exclude ) {
00087         unsigned int offset;
00088         uint32_t *dword;
00089 
00090         for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
00091               offset += sizeof ( *dword ) , dword++ ) {
00092                 if ( ! pci_backup_excluded ( pci, offset, exclude ) )
00093                         pci_write_config_dword ( pci, offset, *dword );
00094         }
00095 }