iPXE
pcibackup.c
Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <ipxe/pci.h>
28 #include <ipxe/pcibackup.h>
29 
30 /** @file
31  *
32  * PCI configuration space backup and restoration
33  *
34  */
35 
36 /**
37  * Check PCI configuration space offset against exclusion list
38  *
39  * @v pci PCI device
40  * @v offset Offset within PCI configuration space
41  * @v exclude PCI configuration space backup exclusion list, or NULL
42  */
43 static int
44 pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
45  const uint8_t *exclude ) {
46 
47  if ( ! exclude )
48  return 0;
49  for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
50  if ( offset == *exclude ) {
51  DBGC ( pci, "PCI %p skipping configuration offset "
52  "%02x\n", pci, offset );
53  return 1;
54  }
55  }
56  return 0;
57 }
58 
59 /**
60  * Back up PCI configuration space
61  *
62  * @v pci PCI device
63  * @v backup PCI configuration space backup
64  * @v exclude PCI configuration space backup exclusion list, or NULL
65  */
66 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
67  const uint8_t *exclude ) {
68  unsigned int offset;
69  uint32_t *dword;
70 
71  for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
72  offset += sizeof ( *dword ) , dword++ ) {
73  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
75  }
76 }
77 
78 /**
79  * Restore PCI configuration space
80  *
81  * @v pci PCI device
82  * @v backup PCI configuration space backup
83  * @v exclude PCI configuration space backup exclusion list, or NULL
84  */
85 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
86  const uint8_t *exclude ) {
87  unsigned int offset;
88  uint32_t *dword;
89 
90  for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
91  offset += sizeof ( *dword ) , dword++ ) {
92  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
94  }
95 }
#define DBGC(...)
Definition: compiler.h:505
void pci_backup(struct pci_device *pci, struct pci_config_backup *backup, const uint8_t *exclude)
Back up PCI configuration space.
Definition: pcibackup.c:66
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
PCI bus.
A PCI device.
Definition: pci.h:187
A PCI configuration space backup.
Definition: pcibackup.h:15
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define PCI_CONFIG_BACKUP_EXCLUDE_END
PCI configuration space backup exclusion list end marker.
Definition: pcibackup.h:20
void pci_restore(struct pci_device *pci, struct pci_config_backup *backup, const uint8_t *exclude)
Restore PCI configuration space.
Definition: pcibackup.c:85
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
uint32_t dwords[64]
Definition: pcibackup.h:16
unsigned long int dword
Definition: smc9000.h:40
static int pci_backup_excluded(struct pci_device *pci, unsigned int offset, const uint8_t *exclude)
Check PCI configuration space offset against exclusion list.
Definition: pcibackup.c:44
PCI configuration space backup and restoration.