hw/pci-host/designware: Fix ATU_UPPER_TARGET register access
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
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
--- hw/pci-host/designware.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 :
Signature · 1 line
2.47.1
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_TARGETregister, we want to update the upper 32 bits.Reported-by Joey <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2861
Fixes d64e5eabc4c ("pci: Add support for Designware IP block")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/designware.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci-host/designware.c +0
-0
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
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
@@ -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
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.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/designware.c | 47 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 31 deletions(-)hw/pci-host/designware.c +13
-28@@ -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