Skip to contentSkip to conversation

hw/pci-host/designware: Fix ATU_UPPER_TARGET register access

PATCH In review Philippe Mathieu-Daudé 2 participants 5 messages Mar 31, 2025

lore
Share & tools
lore
#0 lore raw

cover hw/pci-host/designware: Fix ATU_UPPER_TARGET register access

Trivial fix for issue #2861.

Philippe Mathieu-Daudé (2):
hw/pci-host/designware: Fix access to ATU_UPPER_TARGET register hw/pci-host/designware: Use deposit/extract API

 hw/pci-host/designware.c | 47 ++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 31 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/2 hw/pci-host/designware: Fix access to ATU_UPPER_TARGET register

Fix copy/paste error writing to the ATU_UPPER_TARGET register, we want to update the upper 32 bits.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2861

Fixes d64e5eabc4c ("pci: Add support for Designware IP block")
---
 hw/pci-host/designware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-host/designware.c +1 -1
index c07740bfaa4..5598d18f478 100644
@@ -371,7 +371,7 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
 
     case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
         viewport->target &= 0x00000000FFFFFFFFULL;
-        viewport->target |= val;
+        viewport->target |= (uint64_t)val << 32;
         break;
 
     case DESIGNWARE_PCIE_ATU_LIMIT:
Signature · 1 line
2.47.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH-for-10.0 1/2] hw/pci-host/designware: Fix access to ATU_UPPER_TARGET register

Hi Phil,

Quoted 17 lines · Philippe Mathieu-Daudé

Fix copy/paste error writing to the ATU_UPPER_TARGET register, we want to update the upper 32 bits.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2861

Fixes d64e5eabc4c ("pci: Add support for Designware IP block")
---
  hw/pci-host/designware.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-host/designware.c +0 -0
index c07740bfaa4..5598d18f478 100644

hw/pci-host/designware.c static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address, · line 377

Quoted 8 lines
hw/pci-host/designware.c +1 -1
@@ -371,7 +371,7 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
 
      case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
          viewport->target &= 0x00000000FFFFFFFFULL;
-        viewport->target |= val;
+        viewport->target |= (uint64_t)val << 32;
          break;
 
      case DESIGNWARE_PCIE_ATU_LIMIT:

Cheers,
Gustavo

#3 lore raw

PATCH 2/2 hw/pci-host/designware: Use deposit/extract API

In reply to Philippe Mathieu-Daudé

Prefer the safer (less bug-prone) deposit/extract API to access lower/upper 32-bit of 64-bit registers.

---
 hw/pci-host/designware.c | 47 ++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 31 deletions(-)
hw/pci-host/designware.c +16 -31
index 5598d18f478..3f2282b2596 100644
@@ -22,6 +22,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qemu/log.h"
+#include "qemu/bitops.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/pci_host.h"
@@ -162,11 +163,9 @@ designware_pcie_root_config_read(PCIDevice *d, uint32_t address, int len)
         break;
 
     case DESIGNWARE_PCIE_MSI_ADDR_LO:
-        val = root->msi.base;
-        break;
-
     case DESIGNWARE_PCIE_MSI_ADDR_HI:
-        val = root->msi.base >> 32;
+        val = extract64(root->msi.base,
+                        address == DESIGNWARE_PCIE_MSI_ADDR_LO ? 0 : 32, 32);
         break;
 
     case DESIGNWARE_PCIE_MSI_INTR0_ENABLE:
@@ -190,19 +189,15 @@ designware_pcie_root_config_read(PCIDevice *d, uint32_t address, int len)
         break;
 
     case DESIGNWARE_PCIE_ATU_LOWER_BASE:
-        val = viewport->base;
-        break;
-
     case DESIGNWARE_PCIE_ATU_UPPER_BASE:
-        val = viewport->base >> 32;
+        val = extract64(viewport->base,
+                        address == DESIGNWARE_PCIE_ATU_LOWER_BASE ? 0 : 32, 32);
         break;
 
     case DESIGNWARE_PCIE_ATU_LOWER_TARGET:
-        val = viewport->target;
-        break;
-
     case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
-        val = viewport->target >> 32;
+        val = extract64(viewport->target,
+                        address == DESIGNWARE_PCIE_ATU_LOWER_TARGET ? 0 : 32, 32);
         break;
 
     case DESIGNWARE_PCIE_ATU_LIMIT:
@@ -321,14 +316,10 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
         break;
 
     case DESIGNWARE_PCIE_MSI_ADDR_LO:
-        root->msi.base &= 0xFFFFFFFF00000000ULL;
-        root->msi.base |= val;
-        designware_pcie_root_update_msi_mapping(root);
-        break;
-
     case DESIGNWARE_PCIE_MSI_ADDR_HI:
-        root->msi.base &= 0x00000000FFFFFFFFULL;
-        root->msi.base |= (uint64_t)val << 32;
+        root->msi.base = deposit64(root->msi.base,
+                                   address == DESIGNWARE_PCIE_MSI_ADDR_LO
+                                   ? 0 : 32, 32, val);
         designware_pcie_root_update_msi_mapping(root);
         break;
 
@@ -355,23 +346,17 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
         break;
 
     case DESIGNWARE_PCIE_ATU_LOWER_BASE:
-        viewport->base &= 0xFFFFFFFF00000000ULL;
-        viewport->base |= val;
-        break;
-
     case DESIGNWARE_PCIE_ATU_UPPER_BASE:
-        viewport->base &= 0x00000000FFFFFFFFULL;
-        viewport->base |= (uint64_t)val << 32;
+        viewport->base = deposit64(root->msi.base,
+                                   address == DESIGNWARE_PCIE_ATU_LOWER_BASE
+                                   ? 0 : 32, 32, val);
         break;
 
     case DESIGNWARE_PCIE_ATU_LOWER_TARGET:
-        viewport->target &= 0xFFFFFFFF00000000ULL;
-        viewport->target |= val;
-        break;
-
     case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
-        viewport->target &= 0x00000000FFFFFFFFULL;
-        viewport->target |= (uint64_t)val << 32;
+        viewport->target = deposit64(root->msi.base,
+                                     address == DESIGNWARE_PCIE_ATU_LOWER_TARGET
+                                     ? 0 : 32, 32, val);
         break;
 
     case DESIGNWARE_PCIE_ATU_LIMIT:
Signature · 1 line
2.47.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH-for-10.1 2/2] hw/pci-host/designware: Use deposit/extract API

Hi Phil,

Quoted 96 lines · Philippe Mathieu-Daudé

Prefer the safer (less bug-prone) deposit/extract API to access lower/upper 32-bit of 64-bit registers.

---
  hw/pci-host/designware.c | 47 ++++++++++++++--------------------------
  1 file changed, 16 insertions(+), 31 deletions(-)
hw/pci-host/designware.c +13 -28
index 5598d18f478..3f2282b2596 100644
@@ -22,6 +22,7 @@
  #include "qapi/error.h"
  #include "qemu/module.h"
  #include "qemu/log.h"
+#include "qemu/bitops.h"
  #include "hw/pci/msi.h"
  #include "hw/pci/pci_bridge.h"
  #include "hw/pci/pci_host.h"
@@ -162,11 +163,9 @@ designware_pcie_root_config_read(PCIDevice *d, uint32_t address, int len)
          break;
 
      case DESIGNWARE_PCIE_MSI_ADDR_LO:
-        val = root->msi.base;
-        break;
-
      case DESIGNWARE_PCIE_MSI_ADDR_HI:
-        val = root->msi.base >> 32;
+        val = extract64(root->msi.base,
+                        address == DESIGNWARE_PCIE_MSI_ADDR_LO ? 0 : 32, 32);
          break;
 
      case DESIGNWARE_PCIE_MSI_INTR0_ENABLE:
@@ -190,19 +189,15 @@ designware_pcie_root_config_read(PCIDevice *d, uint32_t address, int len)
          break;
 
      case DESIGNWARE_PCIE_ATU_LOWER_BASE:
-        val = viewport->base;
-        break;
-
      case DESIGNWARE_PCIE_ATU_UPPER_BASE:
-        val = viewport->base >> 32;
+        val = extract64(viewport->base,
+                        address == DESIGNWARE_PCIE_ATU_LOWER_BASE ? 0 : 32, 32);
          break;
 
      case DESIGNWARE_PCIE_ATU_LOWER_TARGET:
-        val = viewport->target;
-        break;
-
      case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
-        val = viewport->target >> 32;
+        val = extract64(viewport->target,
+                        address == DESIGNWARE_PCIE_ATU_LOWER_TARGET ? 0 : 32, 32);
          break;
 
      case DESIGNWARE_PCIE_ATU_LIMIT:
@@ -321,14 +316,10 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
          break;
 
      case DESIGNWARE_PCIE_MSI_ADDR_LO:
-        root->msi.base &= 0xFFFFFFFF00000000ULL;
-        root->msi.base |= val;
-        designware_pcie_root_update_msi_mapping(root);
-        break;
-
      case DESIGNWARE_PCIE_MSI_ADDR_HI:
-        root->msi.base &= 0x00000000FFFFFFFFULL;
-        root->msi.base |= (uint64_t)val << 32;
+        root->msi.base = deposit64(root->msi.base,
+                                   address == DESIGNWARE_PCIE_MSI_ADDR_LO
+                                   ? 0 : 32, 32, val);
          designware_pcie_root_update_msi_mapping(root);
          break;
 
@@ -355,23 +346,17 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
          break;
 
      case DESIGNWARE_PCIE_ATU_LOWER_BASE:
-        viewport->base &= 0xFFFFFFFF00000000ULL;
-        viewport->base |= val;
-        break;
-
      case DESIGNWARE_PCIE_ATU_UPPER_BASE:
-        viewport->base &= 0x00000000FFFFFFFFULL;
-        viewport->base |= (uint64_t)val << 32;
+        viewport->base = deposit64(root->msi.base,
+                                   address == DESIGNWARE_PCIE_ATU_LOWER_BASE
+                                   ? 0 : 32, 32, val);
          break;
 
      case DESIGNWARE_PCIE_ATU_LOWER_TARGET:
-        viewport->target &= 0xFFFFFFFF00000000ULL;
-        viewport->target |= val;
-        break;

hw/pci-host/designware.c static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address, · line 362

Quoted 10 lines
hw/pci-host/designware.c +3 -3
-
      case DESIGNWARE_PCIE_ATU_UPPER_TARGET:
-        viewport->target &= 0x00000000FFFFFFFFULL;
-        viewport->target |= (uint64_t)val << 32;
+        viewport->target = deposit64(root->msi.base,
+                                     address == DESIGNWARE_PCIE_ATU_LOWER_TARGET
+                                     ? 0 : 32, 32, val);
          break;
 
      case DESIGNWARE_PCIE_ATU_LIMIT:

Cheers,
Gustavo