diff mbox series

[2/5] hw/pci-host: Use the PCI_BUILD_BDF() macro from 'hw/pci/pci.h'

Message ID 20201012124506.3406909-3-philmd@redhat.com
State New
Headers show
Series hw: Use PCI macros from 'hw/pci/pci.h' | expand

Commit Message

Philippe Mathieu-Daudé Oct. 12, 2020, 12:45 p.m. UTC
From: Philippe Mathieu-Daudé <f4bug@amsat.org>

We already have a generic PCI_BUILD_BDF() macro in "hw/pci/pci.h"
to pack these values, use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/pci-host/bonito.c   | 3 +--
 hw/pci-host/pnv_phb4.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

Comments

David Gibson Oct. 13, 2020, 12:42 a.m. UTC | #1
On Mon, Oct 12, 2020 at 02:45:03PM +0200, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>

> 

> We already have a generic PCI_BUILD_BDF() macro in "hw/pci/pci.h"

> to pack these values, use it.

> 

> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


pnv part

Acked-by: David Gibson <david@gibson.dropbear.id.au>


> ---

>  hw/pci-host/bonito.c   | 3 +--

>  hw/pci-host/pnv_phb4.c | 2 +-

>  2 files changed, 2 insertions(+), 3 deletions(-)

> 

> diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c

> index abb3ee86769..b05295639a6 100644

> --- a/hw/pci-host/bonito.c

> +++ b/hw/pci-host/bonito.c

> @@ -196,8 +196,7 @@ FIELD(BONGENCFG, PCIQUEUE,      12, 1)

>  #define PCI_IDSEL_VIA686B          (1 << PCI_IDSEL_VIA686B_BIT)

>  

>  #define PCI_ADDR(busno , devno , funno , regno)  \

> -    ((((busno) << 8) & 0xff00) + (((devno) << 3) & 0xf8) + \

> -    (((funno) & 0x7) << 8) + (regno))

> +    ((PCI_BUILD_BDF(busno, PCI_DEVFN(devno , funno)) << 8) + (regno))

>  

>  typedef struct BonitoState BonitoState;

>  

> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c

> index 03daf40a237..6328e985f81 100644

> --- a/hw/pci-host/pnv_phb4.c

> +++ b/hw/pci-host/pnv_phb4.c

> @@ -889,7 +889,7 @@ static bool pnv_phb4_resolve_pe(PnvPhb4DMASpace *ds)

>      /* Read RTE */

>      bus_num = pci_bus_num(ds->bus);

>      addr = rtt & PHB_RTT_BASE_ADDRESS_MASK;

> -    addr += 2 * ((bus_num << 8) | ds->devfn);

> +    addr += 2 * PCI_BUILD_BDF(bus_num, ds->devfn);

>      if (dma_memory_read(&address_space_memory, addr, &rte, sizeof(rte))) {

>          phb_error(ds->phb, "Failed to read RTT entry at 0x%"PRIx64, addr);

>          /* Set error bits ? fence ? ... */


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
diff mbox series

Patch

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index abb3ee86769..b05295639a6 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -196,8 +196,7 @@  FIELD(BONGENCFG, PCIQUEUE,      12, 1)
 #define PCI_IDSEL_VIA686B          (1 << PCI_IDSEL_VIA686B_BIT)
 
 #define PCI_ADDR(busno , devno , funno , regno)  \
-    ((((busno) << 8) & 0xff00) + (((devno) << 3) & 0xf8) + \
-    (((funno) & 0x7) << 8) + (regno))
+    ((PCI_BUILD_BDF(busno, PCI_DEVFN(devno , funno)) << 8) + (regno))
 
 typedef struct BonitoState BonitoState;
 
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 03daf40a237..6328e985f81 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -889,7 +889,7 @@  static bool pnv_phb4_resolve_pe(PnvPhb4DMASpace *ds)
     /* Read RTE */
     bus_num = pci_bus_num(ds->bus);
     addr = rtt & PHB_RTT_BASE_ADDRESS_MASK;
-    addr += 2 * ((bus_num << 8) | ds->devfn);
+    addr += 2 * PCI_BUILD_BDF(bus_num, ds->devfn);
     if (dma_memory_read(&address_space_memory, addr, &rte, sizeof(rte))) {
         phb_error(ds->phb, "Failed to read RTT entry at 0x%"PRIx64, addr);
         /* Set error bits ? fence ? ... */