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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/system/nuttx/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ static int metal_io_block_read_(struct metal_io_region *io,
void *va = metal_io_virt(io, offset);

metal_cache_invalidate(va, len);
memcpy(dst, va, len);
if (len == 1)
*(uint8_t *)dst = *(uint8_t *)va;
else if (len == 2)
*(uint16_t *)dst = *(uint16_t *)va;
else if (len == 4)
*(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.

} else
memcpy(dst, va, len);

return len;
}
Expand All @@ -50,7 +60,18 @@ static int metal_io_block_write_(struct metal_io_region *io,
{
void *va = metal_io_virt(io, offset);

memcpy(va, src, len);
if (len == 1)
*(uint8_t *)va = *(uint8_t *)src;
else if (len == 2)
*(uint16_t *)va = *(uint16_t *)src;
else if (len == 4)
*(uint32_t *)va = *(uint32_t *)src;
else if (len == 8) {
*(uint32_t *)va = *(uint32_t *)src;
*((uint32_t *)va + 1) = *((uint32_t *)src + 1);
} else
memcpy(va, src, len);

metal_cache_flush(va, len);

return len;
Expand Down
Loading