Skip to content

Conversation

ziuziakowska
Copy link

This implements target mode address masking as described in the documentation - OT I2C target mode will accept a transaction if the bitwise AND of an address and the device's address mask matches the device's address.

This is implemented by overriding the default I2CSlaveClass match_and_add method. See i2c_slave_match in hw/i2c/core.c.

@ziuziakowska ziuziakowska force-pushed the ot_i2c_address_masking branch 2 times, most recently from fac75c0 to 91e5071 Compare October 7, 2025 10:07
s->address_mask = mask;

if (mask != 0u && address != 0u) {
ARRAY_FIELD_DP32(s->regs, TARGET_ID, ADDRESS0, address);
Copy link

@AlexJones0 AlexJones0 Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: is the existing code correct here? Should we only be updating the address field and the I2C address on the bus if non-zero? We shouldn't match the address if the mask is non-zero (even though that should probably be handled in match_and_add instead), but we should probably still reflect the write in the register at least. Is there a way to de-register the device instead of just setting its address?

Also, sorry I missed this in previous PRs, but do we need to also i2c_slave_set_address(s->target, 0u) on reset to match the resetval? Or is this behaviour already implemented by resetting the I2C bus?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to de-register the device instead of just setting its address?
I do not think so. address is a property of I2CSlaveClass.

There is some weirdness around address 0 as QEMU uses it as a "broadcast" address (hw/i2c/core.c) - it uses that to make the default i2c_slave_match add each I2C device.

@ziuziakowska ziuziakowska force-pushed the ot_i2c_address_masking branch 2 times, most recently from 8ce934c to c2f9b09 Compare October 7, 2025 13:02
@AlexJones0 AlexJones0 changed the title OT_I2C: Implement Target Mode Address Masking ot_i2c: Implement Target Mode Address Masking Oct 7, 2025
This implements target mode address masking as described in the
documentation - OT I2C target mode will accept a transaction if the
bitwise AND of an address and the device's address mask matches the
device's address.

This is implemented by overriding the default `I2CSlaveClass`
`match_and_add` method. See `i2c_slave_match` in `hw/i2c/core.c`.

Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
@ziuziakowska ziuziakowska force-pushed the ot_i2c_address_masking branch from c2f9b09 to 5b961b2 Compare October 7, 2025 13:13
@AlexJones0 AlexJones0 merged commit d72ef41 into lowRISC:ot-9.2.0 Oct 7, 2025
9 checks passed
@ziuziakowska ziuziakowska deleted the ot_i2c_address_masking branch October 8, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants