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.6KB

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