Kyösti Mälkki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/42074 )
Change subject: [WIP] soc/amd/common: Avoid MMIO aliasing on SMBus ......................................................................
[WIP] soc/amd/common: Avoid MMIO aliasing on SMBus
Change-Id: I5e0ebd7609c5c83d0e443ffba74dae68017d3ebc Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/soc/amd/common/block/include/amdblocks/acpimmio.h M src/soc/amd/common/block/smbus/smbus.c M src/soc/amd/stoneyridge/southbridge.c 3 files changed, 20 insertions(+), 64 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/74/42074/1
diff --git a/src/soc/amd/common/block/include/amdblocks/acpimmio.h b/src/soc/amd/common/block/include/amdblocks/acpimmio.h index b95a347..ac48538 100644 --- a/src/soc/amd/common/block/include/amdblocks/acpimmio.h +++ b/src/soc/amd/common/block/include/amdblocks/acpimmio.h @@ -250,46 +250,6 @@ write32(acpimmio_acpi + reg, value); }
-static inline uint8_t asf_read8(uint8_t reg) -{ - return read8(acpimmio_asf + reg); -} - -static inline uint16_t asf_read16(uint8_t reg) -{ - return read16(acpimmio_asf + reg); -} - -static inline void asf_write8(uint8_t reg, uint8_t value) -{ - write8(acpimmio_asf + reg, value); -} - -static inline void asf_write16(uint8_t reg, uint16_t value) -{ - write16(acpimmio_asf + reg, value); -} - -static inline uint8_t smbus_read8(uint8_t reg) -{ - return read8(acpimmio_smbus + reg); -} - -static inline uint16_t smbus_read16(uint8_t reg) -{ - return read16(acpimmio_smbus + reg); -} - -static inline void smbus_write8(uint8_t reg, uint8_t value) -{ - write8(acpimmio_smbus + reg, value); -} - -static inline void smbus_write16(uint8_t reg, uint16_t value) -{ - write16(acpimmio_smbus + reg, value); -} - static inline uint8_t iomux_read8(uint8_t reg) { return read8(acpimmio_iomux + reg); diff --git a/src/soc/amd/common/block/smbus/smbus.c b/src/soc/amd/common/block/smbus/smbus.c index b5db56b..f8bab62 100644 --- a/src/soc/amd/common/block/smbus/smbus.c +++ b/src/soc/amd/common/block/smbus/smbus.c @@ -3,7 +3,7 @@ #include <stdint.h> #include <console/console.h> #include <device/smbus_host.h> -#include <amdblocks/acpimmio.h> +#include <amdblocks/acpimmio_map.h> #include <soc/southbridge.h>
/* @@ -12,37 +12,31 @@ */ #define SMBUS_TIMEOUT (100 * 1000 * 10)
-static u8 controller_read8(uintptr_t base, u8 reg) +union reg_bank { + uint8_t reg8[0x100]; + uint16_t reg16[0x100 / sizeof(uint16_t)]; +}; + +static __always_inline u8 controller_read8(const u32 base, const u8 reg) { - switch (base) { - case ACPIMMIO_SMBUS_BASE: - return smbus_read8(reg); - case ACPIMMIO_ASF_BASE: - return asf_read8(reg); - default: - printk(BIOS_ERR, "Error attempting to read SMBus at address 0x%lx\n", - base); - } - return 0xff; + volatile union reg_bank *controller = (void *)(uintptr_t)base; + return controller->reg8[reg]; }
-static void controller_write8(uintptr_t base, u8 reg, u8 val) +static __always_inline void controller_write8(const u32 base, const u8 reg, const u8 val) { - switch (base) { - case ACPIMMIO_SMBUS_BASE: - smbus_write8(reg, val); - break; - case ACPIMMIO_ASF_BASE: - asf_write8(reg, val); - break; - default: - printk(BIOS_ERR, "Error attempting to write SMBus at address 0x%lx\n", - base); - } + volatile union reg_bank *controller = (void *)(uintptr_t)base; + controller->reg8[reg] = val; }
static int smbus_wait_until_ready(uintptr_t mmio) { + if ((mmio != (uintptr_t)acpimmio_smbus) && + (mmio != (uintptr_t)acpimmio_asf)) { + printk(BIOS_ERR, "Invalid SMBus or ASF base %#zx\n", mmio); + return -1; + } + u32 loops; loops = SMBUS_TIMEOUT; do { diff --git a/src/soc/amd/stoneyridge/southbridge.c b/src/soc/amd/stoneyridge/southbridge.c index e90fe1b..7bdc4a4 100644 --- a/src/soc/amd/stoneyridge/southbridge.c +++ b/src/soc/amd/stoneyridge/southbridge.c @@ -366,6 +366,7 @@
static void fch_smbus_init(void) { +#if 0 /* 400 kHz smbus speed. */ const uint8_t smbus_speed = (66000000 / (400000 * 4));
@@ -376,6 +377,7 @@ smbus_write8(SMBSLVSTAT, SMBSLV_STAT_CLEAR); asf_write8(SMBHSTSTAT, SMBHST_STAT_CLEAR); asf_write8(SMBSLVSTAT, SMBSLV_STAT_CLEAR); +#endif }
/* Before console init */