From 09d374f626af814cb69b501cd69cc9aefd3c6f22 Mon Sep 17 00:00:00 2001 From: joevt Date: Fri, 2 Sep 2022 01:42:52 -0700 Subject: [PATCH] Log PCI config write values MSB first Writes to config registers of invalid or non-existent PCI devices are logged. They should be logged with most significant byte first. The values enter the methods in reverse byte order so they need to be byte swapped (except when size is 1) for logging. The result is that this command in Open Firmware: `12345678 16800 config-l!` will log this: `VCI0 err: write attempt to non-existing VCI device ??:0d.0 @00.l = 12345678` --- devices/common/pci/bandit.cpp | 12 ++++++------ devices/common/pci/pcidevice.cpp | 2 +- devices/memctrl/mpc106.cpp | 6 +++--- memaccess.h | 9 +++++++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/devices/common/pci/bandit.cpp b/devices/common/pci/bandit.cpp index 6ebd6a1..4ed2697 100644 --- a/devices/common/pci/bandit.cpp +++ b/devices/common/pci/bandit.cpp @@ -196,7 +196,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size LOG_F( WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -208,7 +208,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x", this->name.c_str(), idsel, this->config_addr, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -225,7 +225,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size LOG_F( ERROR, "%s err: write attempt to non-existing PCI device ??:%02x.%x @%02x.%c = %0*x", this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } else { @@ -358,7 +358,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) LOG_F( WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -370,7 +370,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x", this->name.c_str(), idsel, this->config_addr, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -382,7 +382,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) LOG_F( ERROR, "%s err: write attempt to non-existing VCI device ??:%02x.%x @%02x.%c = %0*x", this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } else { diff --git a/devices/common/pci/pcidevice.cpp b/devices/common/pci/pcidevice.cpp index ea060b0..9148e6a 100644 --- a/devices/common/pci/pcidevice.cpp +++ b/devices/common/pci/pcidevice.cpp @@ -156,7 +156,7 @@ void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) LOG_F( WARNING, "%s: attempt to write to reserved/unimplemented register @%02x.%c = %0*x", this->pci_name.c_str(), reg_offs, - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } diff --git a/devices/memctrl/mpc106.cpp b/devices/memctrl/mpc106.cpp index 7ca2ab4..3c85aef 100644 --- a/devices/memctrl/mpc106.cpp +++ b/devices/memctrl/mpc106.cpp @@ -169,8 +169,8 @@ void MPC106::pci_write(uint32_t value, uint32_t size) { "%s err: write attempt to non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs, size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, - size * 2, value - ); + size * 2, flip_sized(value, size) + ); return; } @@ -185,7 +185,7 @@ void MPC106::pci_write(uint32_t value, uint32_t size) { "%s err: write attempt to non-existing PCI device %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs, size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, - size * 2, value + size * 2, flip_sized(value, size) ); } } diff --git a/memaccess.h b/memaccess.h index 46bc60c..9f2d81b 100644 --- a/memaccess.h +++ b/memaccess.h @@ -177,6 +177,15 @@ inline uint32_t read_mem_rev(const uint8_t* buf, uint32_t size) { } } +inline uint32_t flip_sized(uint32_t value, uint32_t size) { + switch (size) { + case 1: return value; + case 2: return BYTESWAP_16(value); + case 4: return BYTESWAP_32(value); + default: LOG_F(ERROR, "flip_sized: invalid size %d!", size); return 0xffffffff; + } +} + /* write the specified value of the specified size to memory pointed to by addr, perform necessary byte swapping so that the byte order of the destination remains unchanged. */