From: BALATON Zoltan Date: Sun, 4 May 2025 16:01:35 +0000 (+0200) Subject: hw/pci-host/raven: Simplify direct config access address decoding X-Git-Tag: v10.2.0-rc1~53^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62ef928312a981d0e25672f72dd467f4a0c05463;p=thirdparty%2Fqemu.git hw/pci-host/raven: Simplify direct config access address decoding Use ctz instead of an open coded version and rename function to better show what it does. Signed-off-by: BALATON Zoltan Reviewed-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daudé Message-ID: <68c038fd225463db282d0277d80cb525e0551413.1760795082.git.balaton@eik.bme.hu> Signed-off-by: Philippe Mathieu-Daudé --- diff --git a/hw/pci-host/raven.c b/hw/pci-host/raven.c index f8c0be5d21..ee9058e262 100644 --- a/hw/pci-host/raven.c +++ b/hw/pci-host/raven.c @@ -72,16 +72,9 @@ struct PRePPCIState { #define PCI_IO_BASE_ADDR 0x80000000 /* Physical address on main bus */ -static inline uint32_t raven_pci_io_config(hwaddr addr) +static inline uint32_t raven_idsel_to_addr(hwaddr addr) { - int i; - - for (i = 0; i < 11; i++) { - if ((addr & (1 << (11 + i))) != 0) { - break; - } - } - return (addr & 0x7ff) | (i << 11); + return (ctz16(addr >> 11) << 11) | (addr & 0x7ff); } static void raven_pci_io_write(void *opaque, hwaddr addr, @@ -89,7 +82,7 @@ static void raven_pci_io_write(void *opaque, hwaddr addr, { PREPPCIState *s = opaque; PCIHostState *phb = PCI_HOST_BRIDGE(s); - pci_data_write(phb->bus, raven_pci_io_config(addr), val, size); + pci_data_write(phb->bus, raven_idsel_to_addr(addr), val, size); } static uint64_t raven_pci_io_read(void *opaque, hwaddr addr, @@ -97,7 +90,7 @@ static uint64_t raven_pci_io_read(void *opaque, hwaddr addr, { PREPPCIState *s = opaque; PCIHostState *phb = PCI_HOST_BRIDGE(s); - return pci_data_read(phb->bus, raven_pci_io_config(addr), size); + return pci_data_read(phb->bus, raven_idsel_to_addr(addr), size); } static const MemoryRegionOps raven_pci_io_ops = {