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 limit Maximum offset in PCI configuration space
65  * @v exclude PCI configuration space backup exclusion list, or NULL
66  */
67 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
68  unsigned int limit, const uint8_t *exclude ) {
69  unsigned int offset;
70  uint32_t *dword;
71 
72  for ( offset = 0, dword = backup->dwords ; offset < limit ;
73  offset += sizeof ( *dword ) , dword++ ) {
74  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
76  }
77 }
78 
79 /**
80  * Restore PCI configuration space
81  *
82  * @v pci PCI device
83  * @v backup PCI configuration space backup
84  * @v limit Maximum offset in PCI configuration space
85  * @v exclude PCI configuration space backup exclusion list, or NULL
86  */
87 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
88  unsigned int limit, const uint8_t *exclude ) {
89  unsigned int offset;
90  uint32_t *dword;
91 
92  for ( offset = 0, dword = backup->dwords ; offset < limit ;
93  offset += sizeof ( *dword ) , dword++ ) {
94  if ( ! pci_backup_excluded ( pci, offset, exclude ) )
96  }
97 }
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:87
#define DBGC(...)
Definition: compiler.h:505
uint32_t dwords[PCI_CONFIG_BACKUP_ALL/sizeof(uint32_t)]
Definition: pcibackup.h:22
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
uint16_t limit
Limit.
Definition: librm.h:250
PCI bus.
A PCI device.
Definition: pci.h:206
A PCI configuration space backup.
Definition: pcibackup.h:21
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:26
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:67
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
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.