fix BCM2835_I2C_CLKT
Subsystems (2)
PATCH 1/1 fix BCM2835_I2C_CLKT
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset 0x1c, not 0x20.
The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the BCM2835_I2C_CLKT macro to match the hardware specification.
--- include/hw/i2c/bcm2835_i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/i2c/bcm2835_i2c.h +1 -1
@@ -38,7 +38,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)#define BCM2835_I2C_FIFO 0x10/* FIFO */ #define BCM2835_I2C_DIV 0x14/* Clock Divider */ #define BCM2835_I2C_DEL 0x18/* Data Delay */ -#define BCM2835_I2C_CLKT 0x20/* Clock Stretch Timeout */ +#define BCM2835_I2C_CLKT 0x1c/* Clock Stretch Timeout */ #define BCM2835_I2C_C_I2CEN BIT(15)/* I2C enable */ #define BCM2835_I2C_C_INTR BIT(10)/* Interrupt on RXR */
Signature · 1 line
2.43.0
botszhuang <[email protected]> 於 2026年7月24日週五 下午8:51寫道:
Quoted 28 lines
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Signed-off-by botszhuang <[email protected]>--- include/hw/i2c/bcm2835_i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/i2c/bcm2835_i2c.h +1
-2@@ -38,7 +38,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)#define BCM2835_I2C_FIFO 0x10/* FIFO */ #define BCM2835_I2C_DIV 0x14/* Clock Divider */ #define BCM2835_I2C_DEL 0x18/* Data Delay */ -#define BCM2835_I2C_CLKT 0x20/* Clock Stretch Timeout */ +#define BCM2835_I2C_CLKT 0x1c/* Clock Stretch Timeout */ #define BCM2835_I2C_C_I2CEN BIT(15)/* I2C enable */ #define BCM2835_I2C_C_INTR BIT(10)/* Interrupt on RXR */ --
Quoted 2 lines
2.43.0
Hi
Signature · 2 lines
Regards, Nick Huang
botszhuang <[email protected]> 於 2026年7月24日週五 下午8:51寫道:
Quoted 28 lines
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Signed-off-by botszhuang <[email protected]>--- include/hw/i2c/bcm2835_i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/i2c/bcm2835_i2c.h +1
-2@@ -38,7 +38,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)#define BCM2835_I2C_FIFO 0x10/* FIFO */ #define BCM2835_I2C_DIV 0x14/* Clock Divider */ #define BCM2835_I2C_DEL 0x18/* Data Delay */ -#define BCM2835_I2C_CLKT 0x20/* Clock Stretch Timeout */ +#define BCM2835_I2C_CLKT 0x1c/* Clock Stretch Timeout */ #define BCM2835_I2C_C_I2CEN BIT(15)/* I2C enable */ #define BCM2835_I2C_C_INTR BIT(10)/* Interrupt on RXR */ --
Quoted 2 lines
2.43.0
Signature · 2 lines
Regards, Nick Huang
botszhuang <[email protected]> 於 2026年7月24日週五 下午8:51寫道:
Quoted 28 lines
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Signed-off-by botszhuang <[email protected]>--- include/hw/i2c/bcm2835_i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/i2c/bcm2835_i2c.h +1
-2@@ -38,7 +38,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)#define BCM2835_I2C_FIFO 0x10/* FIFO */ #define BCM2835_I2C_DIV 0x14/* Clock Divider */ #define BCM2835_I2C_DEL 0x18/* Data Delay */ -#define BCM2835_I2C_CLKT 0x20/* Clock Stretch Timeout */ +#define BCM2835_I2C_CLKT 0x1c/* Clock Stretch Timeout */ #define BCM2835_I2C_C_I2CEN BIT(15)/* I2C enable */ #define BCM2835_I2C_C_INTR BIT(10)/* Interrupt on RXR */ --
Quoted 2 lines
2.43.0
Hi
Signature · 2 lines
Regards, Nick Huang
botszhuang <[email protected]> 於 2026年7月24日週五 下午8:51寫道:
Quoted 28 lines
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Signed-off-by botszhuang <[email protected]>--- include/hw/i2c/bcm2835_i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/i2c/bcm2835_i2c.h +1
-2@@ -38,7 +38,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)#define BCM2835_I2C_FIFO 0x10/* FIFO */ #define BCM2835_I2C_DIV 0x14/* Clock Divider */ #define BCM2835_I2C_DEL 0x18/* Data Delay */ -#define BCM2835_I2C_CLKT 0x20/* Clock Stretch Timeout */ +#define BCM2835_I2C_CLKT 0x1c/* Clock Stretch Timeout */ #define BCM2835_I2C_C_I2CEN BIT(15)/* I2C enable */ #define BCM2835_I2C_C_INTR BIT(10)/* Interrupt on RXR */ --
Quoted 2 lines
2.43.0
Signature · 2 lines
Regards, Nick Huang
Peter Maydell
AppliedQuoted 8 lines · botszhuang
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.
Checking the datasheet, this is definitely the wrong value, so the fix is correct. I'm a bit confused by your commit message, though. The value here in QEMU can't cause the guest OS to write to the wrong memory address, because the guest OS doesn't ever see what we have defined here. It has the offset hardcoded into its own source code.
It looks to me like the effect of getting this wrong is that when the guest writes to CLKT (at its actual 0x1c offset) we will log a guest error and give read-as-zero behaviour. That's not correct, but I expect for most guest OSes it'll be pretty harmless because the guest probably doesn't write the value it wants to configure and then read it back to check. (QEMU ignores the value written anyway.)
I've applied this to target-arm.next.
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 8 lines · botszhuang
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C controller is actually located at offset
0x1c, not0x20.The previous incorrect value caused the guest OS to read from and write to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Checking the datasheet, this is definitely the wrong value, so the fix is correct. I'm a bit confused by your commit message, though. The value here in QEMU can't cause the guest OS to write to the wrong memory address, because the guest OS doesn't ever see what we have defined here. It has the offset hardcoded into its own source code.
It looks to me like the effect of getting this wrong is that when the guest writes to CLKT (at its actual
0x1coffset) we will log a guest error and give read-as-zero behaviour. That's not correct, but I expect for most guest OSes it'll be pretty harmless because the guest probably doesn't write the value it wants to configure and then read it back to check. (QEMU ignores the value written anyway.)
Quoted 1 line
I've applied this to target-arm.next.
Should we also reduce the region size?
-- >8 --
hw/i2c/bcm2835_i2c.c +1 -1
@@ -222,7 +222,7 @@ static void bcm2835_i2c_realize(DeviceState *dev, Error **errp) s->bus =i2c_init_bus (dev,NULL );memory_region_init_io (&s->iomem,OBJECT (dev), &bcm2835_i2c_ops, s, -TYPE_BCM2835_I2C ,0x24 ); +TYPE_BCM2835_I2C ,0x20 );sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem);sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->irq); }
---
Dear all,
Thanks for applying the patch and for the detailed explanation!
You are completely right—my commit message reasoning was flawed. QEMU's macro doesn't change the guest's behavior, it only affects how QEMU handles the guest's access (logging a guest error and returning read-as-zero, as you noted). I appreciate you clarifying that.
Regarding the register layout, since the CLKT register is at offset 0x1c (and assuming it's the last 32-bit register), the total memory region size should technically be 0x20 instead of 0x24.
Do you think we should also reduce the region size, as shown in the diff below? If it looks good to you, I can send this as a separate follow-up patch.
-- >8 --
hw/i2c/bcm2835_i2c.c +0 -0
@@ -222,7 +222,7 @@ static void bcm2835_i2c_realize(DeviceState *dev, Error
**errp)
s->bus = i2c_init_bus(dev, NULL);
memory_region_init_io(&s->iomem, OBJECT(dev), &bcm2835_i2c_ops, s,
- TYPE_BCM2835_I2C, 0x24);
+ TYPE_BCM2835_I2C, 0x20);
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); }
---
Best regards,
Botsz HUANG
Philippe Mathieu-Daudé <[email protected]> 於 2026年7月27日週一 下午7:54寫道:
Quoted 50 lines · Peter Maydell
Quoted 5 lines · botszhuang
Quoted 4 lines
hw/i2c/bcm2835_i2c: Correct CLKT register offset
The Clock Stretch Timeout (CLKT) register for the BCM2835 I2C
controller is actually located at offset
0x1c, not0x20.Quoted 2 lines
Quoted 2 lines
The previous incorrect value caused the guest OS to read from and write
to the wrong memory address when configuring the I2C timeout, which could lead to unexpected controller behavior.
Quoted 18 lines
Quoted 2 lines
Update the
BCM2835_I2C_CLKTmacro to match the hardware specification.Checking the datasheet, this is definitely the wrong value, so the fix is correct. I'm a bit confused by your commit message, though. The value here in QEMU can't cause the guest OS to write to the wrong memory address, because the guest OS doesn't ever see what we have defined here. It has the offset hardcoded into its own source code.
It looks to me like the effect of getting this wrong is that when the guest writes to CLKT (at its actual
0x1coffset) we will log a guest error and give read-as-zero behaviour. That's not correct, but I expect for most guest OSes it'll be pretty harmless because the guest probably doesn't write the value it wants to configure and then read it back to check. (QEMU ignores the value written anyway.)Quoted 1 line
I've applied this to target-arm.next.
Should we also reduce the region size?
-- >8 --
hw/i2c/bcm2835_i2c.c +1
-1@@ -222,7 +222,7 @@ static void bcm2835_i2c_realize(DeviceState *dev, Error **errp) s->bus = i2c_init_bus(dev, NULL);memory_region_init_io (&s->iomem,OBJECT (dev), &bcm2835_i2c_ops, s, -TYPE_BCM2835_I2C ,0x24 ); +TYPE_BCM2835_I2C ,0x20 );sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem);sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->irq);}
---