pcibackup.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00056
00057
00058
00059
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
00075
00076
00077
00078
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 }