From 777a02cbe96afa84dd5474b6763d9558f8cfe5a6 Mon Sep 17 00:00:00 2001 From: joevt Date: Sat, 10 Jun 2023 01:32:39 -0700 Subject: [PATCH] pci: Use SIZE_ARG for logging arg size. The SIZE_ARG macro defined in pcibase can be used outside pcibase with a small modification. --- devices/common/pci/pcibase.h | 12 ++++++------ devices/common/pci/pcihost.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/devices/common/pci/pcibase.h b/devices/common/pci/pcibase.h index d26f292..4a3f88c 100644 --- a/devices/common/pci/pcibase.h +++ b/devices/common/pci/pcibase.h @@ -197,8 +197,8 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) { } } -#define SIZE_ARGS details.size == 4 ? 'l' : details.size == 2 ? 'w' : \ - details.size == 1 ? 'b' : '0' + details.size +#define SIZE_ARG(size) (size == 4 ? 'l' : size == 2 ? 'w' : \ + size == 1 ? 'b' : '0' + size) #define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \ do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \ @@ -206,7 +206,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) { (~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \ "%s: read unimplemented config register @%02x.%c", \ this->name.c_str(), reg_offs + details.offset, \ - SIZE_ARGS \ + SIZE_ARG(details.size) \ ); \ } } while(0) @@ -215,7 +215,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) { (~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \ "%s: %s %s register @%02x.%c = %0*x", \ this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \ - SIZE_ARGS, \ + SIZE_ARG(details.size), \ details.size * 2, pci_cfg_log(value, details) \ ) @@ -238,7 +238,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) { ERROR, \ "%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \ this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \ - SIZE_ARGS \ + SIZE_ARG(details.size) \ ) #define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \ @@ -246,7 +246,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) { ERROR, \ "%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \ this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \ - SIZE_ARGS, \ + SIZE_ARG(details.size), \ details.size * 2, BYTESWAP_SIZED(value, details.size) \ ) diff --git a/devices/common/pci/pcihost.cpp b/devices/common/pci/pcihost.cpp index 3713b7f..009331c 100644 --- a/devices/common/pci/pcihost.cpp +++ b/devices/common/pci/pcihost.cpp @@ -160,7 +160,7 @@ uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size) LOG_F( ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c", hwc ? hwc->get_name().c_str() : "PCIHost", offset, - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size + SIZE_ARG(size) ); // FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200) return 0; @@ -177,7 +177,7 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value) LOG_F( ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x", hwc ? hwc->get_name().c_str() : "PCIHost", offset, - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + SIZE_ARG(size), size * 2, BYTESWAP_SIZED(value, size) ); }