Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libmetal/nuttx/io.c: width matched access when read/write size = 1,2,4,8 #279

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

CV-Bowen
Copy link
Contributor

@CV-Bowen CV-Bowen commented Dec 4, 2023

libmetal/nuttx/io.c: width matched access when read/write size = 1,2,4,8

Follow the virtio spec v1.2

4.2.2.2 Driver Requirements: MMIO Device Register Layout:
The driver MUST only use 32 bit wide and aligned reads and writes to access the control registers described in table 4.1. For the device-specific configuration space, the driver MUST use 8 bit wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and 64 bit wide fields.

So change the nuttx implemented io read/write operation.

@CV-Bowen CV-Bowen force-pushed the nuttx-rw branch 2 times, most recently from 51e1585 to 5124f24 Compare December 4, 2023 11:59
@arnopo arnopo requested review from edmooring, arnopo and tnmysh December 5, 2023 13:33
@arnopo
Copy link
Contributor

arnopo commented Dec 5, 2023

If constraint is generic what about using macros metal_io_write/read ( x = 8,16,32 or 64) in open-amp?

@CV-Bowen
Copy link
Contributor Author

CV-Bowen commented Dec 5, 2023

@arnopo Yes, we used libmetal implemented metal_io_write/read() before, but we met a bug when using atomic operation to operate the I/O space in risc-v in QMEU 8.1.2. CPU will hang at the atomic instruction.
See: apache/nuttx#11201

@arnopo
Copy link
Contributor

arnopo commented Dec 8, 2023

@arnopo Yes, we used libmetal implemented metal_io_write/read() before, but we met a bug when using atomic operation to operate the I/O space in risc-v in QMEU 8.1.2. CPU will hang at the atomic instruction. See: apache/nuttx#11201

Thanks for the link!

Something seems missing in you patch. You should check the alignement of the address to respect the virtio specification

Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity.

Follow the virtio spec v1.2:
The driver MUST only use 32 bit wide and aligned reads and writes to access
the control registers described in table 4.1. For the device-specific
configuration space, the driver MUST use 8 bit wide accesses for 8 bit
wide fields, 16 bit wide and aligned accesses for 16 bit wide fields
and 32 bit wide and aligned accesses for 32 and 64 bit wide fields.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
@CV-Bowen
Copy link
Contributor Author

CV-Bowen commented Feb 18, 2024

@arnopo Yes, we used libmetal implemented metal_io_write/read() before, but we met a bug when using atomic operation to operate the I/O space in risc-v in QMEU 8.1.2. CPU will hang at the atomic instruction. See: apache/nuttx#11201

Thanks for the link!

Something seems missing in you patch. You should check the alignement of the address to respect the virtio specification

@arnopo How about leaving virtio devices and drivers to ensure that the address is aligned?

@CV-Bowen
Copy link
Contributor Author

@arnopo And could you check why the CI failed, seems not related to this PR?

@github-actions github-actions bot removed the Stale label Feb 19, 2024
@arnopo
Copy link
Contributor

arnopo commented Feb 19, 2024

@arnopo And could you check why the CI failed, seems not related to this PR?
It seems to be a temporary issue with the server. Restarting the GitHub action fixes the issue.

@arnopo
Copy link
Contributor

arnopo commented Feb 19, 2024

@arnopo Yes, we used libmetal implemented metal_io_write/read() before, but we met a bug when using atomic operation to operate the I/O space in risc-v in QMEU 8.1.2. CPU will hang at the atomic instruction. See: apache/nuttx#11201

Thanks for the link!
Something seems missing in you patch. You should check the alignement of the address to respect the virtio specification

@arnopo How about leaving virtio devices and drivers to ensure that the address is aligned?

yes that can make sense a part of the spec. And checking only the MMIO register base address should ensure the alignement.

*(uint32_t *)dst = *(uint32_t *)va;
else if (len == 8) {
*(uint32_t *)dst = *(uint32_t *)va;
*((uint32_t *)dst + 1) = *((uint32_t *)va + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

what about using uint64_t ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec says:
The driver MUST use 8 bit wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and 64 bit wide fields.

@arnopo arnopo merged commit f21fea6 into OpenAMP:main Feb 23, 2024
4 checks passed
@arnopo arnopo added this to the Release V2024.05 milestone May 20, 2024
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.

4 participants