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 FILE_SECBOOT ( PERMITTED );
26 
27 #include <stdint.h>
28 #include <ipxe/pci.h>
29 #include <ipxe/pcibackup.h>
30 
31 /** @file
32  *
33  * PCI configuration space backup and restoration
34  *
35  */
36 
37 /**
38  * Check PCI configuration space offset against exclusion list
39  *
40  * @v pci PCI device
41  * @v offset Offset within PCI configuration space
42  * @v exclude PCI configuration space backup exclusion list, or NULL
43  */
44 static int
45 pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
46  const uint8_t *exclude ) {
47 
48  if ( ! exclude )
49  return 0;
50  for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
51  if ( offset == *exclude ) {
52  DBGC ( pci, "PCI %p skipping configuration offset "
53  "%02x\n", pci, offset );
54  return 1;
55  }
56  }
57  return 0;
58 }
59 
60 /**
61  * Back up PCI configuration space
62  *
63  * @v pci PCI device
64  * @v backup PCI configuration space backup
65  * @v limit Maximum offset in PCI configuration space
66  * @v exclude PCI configuration space backup exclusion list, or NULL
67  */
68 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
69  unsigned int limit, const uint8_t *exclude ) {
70  unsigned int offset;
71  uint32_t *dword;
72 
73  for ( offset = 0, dword = backup->dwords ; offset < limit ;
74  offset += sizeof ( *dword ) , dword++ ) {
75  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
77  }
78 }
79 
80 /**
81  * Restore PCI configuration space
82  *
83  * @v pci PCI device
84  * @v backup PCI configuration space backup
85  * @v limit Maximum offset in PCI configuration space
86  * @v exclude PCI configuration space backup exclusion list, or NULL
87  */
88 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
89  unsigned int limit, const uint8_t *exclude ) {
90  unsigned int offset;
91  uint32_t *dword;
92 
93  for ( offset = 0, dword = backup->dwords ; offset < limit ;
94  offset += sizeof ( *dword ) , dword++ ) {
95  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
97  }
98 }
void pci_restore(struct pci_device *pci, struct pci_config_backup *backup, unsigned int limit, const uint8_t *exclude)
Restore PCI configuration space.
Definition: pcibackup.c:88
#define DBGC(...)
Definition: compiler.h:505
uint32_t dwords[PCI_CONFIG_BACKUP_ALL/sizeof(uint32_t)]
Definition: pcibackup.h:23
FILE_SECBOOT(PERMITTED)
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
uint16_t limit
Limit.
Definition: librm.h:136
PCI bus.
A PCI device.
Definition: pci.h:211
A PCI configuration space backup.
Definition: pcibackup.h:22
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:27
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void pci_backup(struct pci_device *pci, struct pci_config_backup *backup, unsigned int limit, const uint8_t *exclude)
Back up PCI configuration space.
Definition: pcibackup.c:68
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
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:45
PCI configuration space backup and restoration.