You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcibackup.c 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdint.h>
  25. #include <ipxe/pci.h>
  26. #include <ipxe/pcibackup.h>
  27. /** @file
  28. *
  29. * PCI configuration space backup and restoration
  30. *
  31. */
  32. /**
  33. * Check PCI configuration space offset against exclusion list
  34. *
  35. * @v pci PCI device
  36. * @v offset Offset within PCI configuration space
  37. * @v exclude PCI configuration space backup exclusion list, or NULL
  38. */
  39. static int
  40. pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
  41. const uint8_t *exclude ) {
  42. if ( ! exclude )
  43. return 0;
  44. for ( ; *exclude != PCI_CONFIG_BACKUP_EXCLUDE_END ; exclude++ ) {
  45. if ( offset == *exclude ) {
  46. DBGC ( pci, "PCI %p skipping configuration offset "
  47. "%02x\n", pci, offset );
  48. return 1;
  49. }
  50. }
  51. return 0;
  52. }
  53. /**
  54. * Back up PCI configuration space
  55. *
  56. * @v pci PCI device
  57. * @v backup PCI configuration space backup
  58. * @v exclude PCI configuration space backup exclusion list, or NULL
  59. */
  60. void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
  61. const uint8_t *exclude ) {
  62. unsigned int offset;
  63. uint32_t *dword;
  64. for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
  65. offset += sizeof ( *dword ) , dword++ ) {
  66. if ( ! pci_backup_excluded ( pci, offset, exclude ) )
  67. pci_read_config_dword ( pci, offset, dword );
  68. }
  69. }
  70. /**
  71. * Restore PCI configuration space
  72. *
  73. * @v pci PCI device
  74. * @v backup PCI configuration space backup
  75. * @v exclude PCI configuration space backup exclusion list, or NULL
  76. */
  77. void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
  78. const uint8_t *exclude ) {
  79. unsigned int offset;
  80. uint32_t *dword;
  81. for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
  82. offset += sizeof ( *dword ) , dword++ ) {
  83. if ( ! pci_backup_excluded ( pci, offset, exclude ) )
  84. pci_write_config_dword ( pci, offset, *dword );
  85. }
  86. }