]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[pci] Allow PCI config space backup to be limited by maximum offset
authorMichael Brown <mcb30@ipxe.org>
Sun, 13 Nov 2022 20:42:09 +0000 (20:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 13 Nov 2022 20:42:09 +0000 (20:42 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/bus/pcibackup.c
src/drivers/infiniband/arbel.c
src/drivers/infiniband/hermon.c
src/drivers/infiniband/qib7322.c
src/include/ipxe/pcibackup.h

index fecad81920e87f80b55324867281790b9a8635ec..4cf126f83acb905121ed2062b943a5dacd67322c 100644 (file)
@@ -61,14 +61,15 @@ pci_backup_excluded ( struct pci_device *pci, unsigned int offset,
  *
  * @v pci              PCI device
  * @v backup           PCI configuration space backup
+ * @v limit            Maximum offset in PCI configuration space
  * @v exclude          PCI configuration space backup exclusion list, or NULL
  */
 void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
-                 const uint8_t *exclude ) {
+                 unsigned int limit, const uint8_t *exclude ) {
        unsigned int offset;
        uint32_t *dword;
 
-       for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
+       for ( offset = 0, dword = backup->dwords ; offset < limit ;
              offset += sizeof ( *dword ) , dword++ ) {
                if ( ! pci_backup_excluded ( pci, offset, exclude ) )
                        pci_read_config_dword ( pci, offset, dword );
@@ -80,14 +81,15 @@ void pci_backup ( struct pci_device *pci, struct pci_config_backup *backup,
  *
  * @v pci              PCI device
  * @v backup           PCI configuration space backup
+ * @v limit            Maximum offset in PCI configuration space
  * @v exclude          PCI configuration space backup exclusion list, or NULL
  */
 void pci_restore ( struct pci_device *pci, struct pci_config_backup *backup,
-                  const uint8_t *exclude ) {
+                  unsigned int limit, const uint8_t *exclude ) {
        unsigned int offset;
        uint32_t *dword;
 
-       for ( offset = 0, dword = backup->dwords ; offset < 0x100 ;
+       for ( offset = 0, dword = backup->dwords ; offset < limit ;
              offset += sizeof ( *dword ) , dword++ ) {
                if ( ! pci_backup_excluded ( pci, offset, exclude ) )
                        pci_write_config_dword ( pci, offset, *dword );
index fbef3f8a6453b6a8496c45798953b5b440b90b0d..293c1b64743ea546395ada7b2db91140384d4dbb 100644 (file)
@@ -2561,7 +2561,7 @@ static void arbel_reset ( struct arbel *arbel ) {
        unsigned int i;
 
        /* Perform device reset and preserve PCI configuration */
-       pci_backup ( pci, &backup, backup_exclude );
+       pci_backup ( pci, &backup, PCI_CONFIG_BACKUP_ALL, backup_exclude );
        writel ( ARBEL_RESET_MAGIC,
                 ( arbel->config + ARBEL_RESET_OFFSET ) );
        for ( i = 0 ; i < ARBEL_RESET_WAIT_TIME_MS ; i++ ) {
@@ -2570,7 +2570,7 @@ static void arbel_reset ( struct arbel *arbel ) {
                if ( vendor != 0xffff )
                        break;
        }
-       pci_restore ( pci, &backup, backup_exclude );
+       pci_restore ( pci, &backup, PCI_CONFIG_BACKUP_ALL, backup_exclude );
 }
 
 /**
index 2afaaf99138c6acaa8c378795f7e7e1c7cfd6ed6..c09baf7aeb38ef1c7802a0fb9f058e642d9c6782 100644 (file)
@@ -2840,7 +2840,7 @@ static int hermon_reset ( struct hermon *hermon ) {
        hermon->toggle = 0;
 
        /* Perform device reset and preserve PCI configuration */
-       pci_backup ( pci, &backup, backup_exclude );
+       pci_backup ( pci, &backup, PCI_CONFIG_BACKUP_ALL, backup_exclude );
        writel ( HERMON_RESET_MAGIC,
                 ( hermon->config + HERMON_RESET_OFFSET ) );
 
@@ -2852,7 +2852,8 @@ static int hermon_reset ( struct hermon *hermon ) {
                if ( vendor == pci->vendor ) {
 
                        /* Restore PCI configuration */
-                       pci_restore ( pci, &backup, backup_exclude );
+                       pci_restore ( pci, &backup, PCI_CONFIG_BACKUP_ALL,
+                                     backup_exclude );
 
                        DBGC ( hermon, "Hermon %p reset after %dms\n",
                               hermon, i );
index a4b51db05c2a1c863d2af5a2ac0f6aee93e3ee70..da055b744c378929b3f4a423e5c5fed74e0d5fd8 100644 (file)
@@ -2256,7 +2256,7 @@ static void qib7322_reset ( struct qib7322 *qib7322, struct pci_device *pci ) {
        struct pci_config_backup backup;
 
        /* Back up PCI configuration space */
-       pci_backup ( pci, &backup, NULL );
+       pci_backup ( pci, &backup, PCI_CONFIG_BACKUP_ALL, NULL );
 
        /* Assert reset */
        memset ( &control, 0, sizeof ( control ) );
@@ -2267,7 +2267,7 @@ static void qib7322_reset ( struct qib7322 *qib7322, struct pci_device *pci ) {
        mdelay ( 1000 );
 
        /* Restore PCI configuration space */
-       pci_restore ( pci, &backup, NULL );
+       pci_restore ( pci, &backup, PCI_CONFIG_BACKUP_ALL, NULL );
 }
 
 /**
index 159d25392982eeb0c6092586acbf61e1741ea6cc..e5249df99ed58d0f59f4f16e07b0b194aa22e348 100644 (file)
@@ -11,9 +11,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <stdint.h>
 
+/** Limit of PCI configuration space */
+#define PCI_CONFIG_BACKUP_ALL 0x100
+
+/** Limit of standard PCI configuration space */
+#define PCI_CONFIG_BACKUP_STANDARD 0x40
+
 /** A PCI configuration space backup */
 struct pci_config_backup {
-       uint32_t dwords[64];
+       uint32_t dwords[ PCI_CONFIG_BACKUP_ALL / sizeof ( uint32_t ) ];
 };
 
 /** PCI configuration space backup exclusion list end marker */
@@ -25,9 +31,9 @@ struct pci_config_backup {
 
 extern void pci_backup ( struct pci_device *pci,
                         struct pci_config_backup *backup,
-                        const uint8_t *exclude );
+                        unsigned int limit, const uint8_t *exclude );
 extern void pci_restore ( struct pci_device *pci,
                          struct pci_config_backup *backup,
-                         const uint8_t *exclude );
+                         unsigned int limit, const uint8_t *exclude );
 
 #endif /* _IPXE_PCIBACKUP_H */