8000 Switch SPI master HIL to leasable buffers instead of raw slices by alevy · Pull Request #4173 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Switch SPI master HIL to leasable buffers instead of raw slices #4173

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

Merged
merged 14 commits into from
Sep 24, 2024

Conversation

alevy
Copy link
Member
@alevy alevy commented Sep 13, 2024

Pull Request Overview

This pull request migrates the SPI master HIL to use leasable buffers (SubSliceMut) rather than raw
slices, in accordance with the draft SPI TRD. As a result, this touches every module that either implements or uses the SPI master HIL, as well as a some dependencies in some cases (e.g. DMA modules).

While it is mostly a mechanical transformation aided by some additional helper methods in leasable buffers, the length parameter, is notably, redundant for both the read_write_bytes downcall and client callback, which requires adapting some of the length computations in various implementations. In cases where the implementation is shared with other HIL implementations that have not migrated to SubSliceMut there is some ultimately unnecessary complexity.

Testing Strategy

This touches many chips and thus almost every board as well as a few capsules for peripherals I don't have currently access to. The shared code is fairly straight forward, but the devil is mostly going to be in specific chip implementations.

I've tested on an NRF52-based platform with a SPI peripheral, but that's it for now.

TODO or Help Wanted

  • Double checking my logic for length computations as well as for resetting and slicing the SubSliceMuts in capsules... kind of everywhere?
  • What's the bar for testing this? One option is to block merging until everything is properly tested, though we don't necessarily have infrastructure for that. Another is to defer that to release testing.
  • Should write_buffer also be an Option?

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@github-actions github-actions bot added kernel sam4l Change pertains to the SAM4L MCU. nrf Change pertains to the nRF5x family of MCUs. HIL This affects a Tock HIL interface. WG-OpenTitan In the purview of the OpenTitan working group. stm32 Change pertains to the stm32 family of MCUSs WG-Network In the purview of the Network working group. labels Sep 13, 2024
status: Result<(), ErrorCode>,
write_buffer: SubSliceMut<'static, u8>,
read_buffer: Option<SubSliceMut<'static, u8>>,
status: Result<usize, ErrorCode>,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the usize?

Copy link
Member Author

Choose a reason for hiding this comment

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

Length

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@bradjc bradjc added the last-call Final review period for a pull request. label Sep 23, 2024
@alevy
Copy link
Member Author
alevy commented Sep 23, 2024

@tock/core-wg note last call on this

@alevy alevy added this pull request to the merge queue Sep 24, 2024
Merged via the queue into tock:master with commit fe99a8a Sep 24, 2024
12 checks passed
@alevy alevy deleted the spi/trd/leasable-buffer branch September 24, 2024 18:24
@alistair23
Copy link
Contributor

This breaks SPI on the Apollo3

Comment on lines -138 to +143
self.spi_master
.read_write_bytes(self.kernel_write.take().unwrap(), None, write_len)
let kwbuf = self
.kernel_write
.take()
.unwrap_or((&mut [] as &'static mut [u8]).into());
self.spi_master.read_write_bytes(kwbuf, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens to write_len here? It seems like it's being lost

Comment on lines +172 to +177
let kwbuf = self
.kernel_write
.take()
.unwrap_or((&mut [] as &'static mut [u8]).into());
self.spi_master
.read_write_bytes(kwbuf, self.kernel_read.take())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with read_len here.

Userspace might use a single large buffer, but want to do smaller SPI operations at times. It seems like that might be broken now

Comment on lines -174 to +184
self.spi_master.read_write_bytes(
self.kernel_write.take().unwrap(),
self.kernel_read.take(),
write_len,
)
let kwbuf = self
.kernel_write
.take()
.unwrap_or((&mut [] as &'static mut [u8]).into());
self.spi_master
.read_write_bytes(kwbuf, self.kernel_read.take())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with write_len here

@alistair23
Copy link
Contributor

@alevy ping!

alistair23 added a commit to alistair23/tock that referenced this pull request Nov 13, 2024
tock#4173 broke userspace SPI operations as
the length of the operation that the application requested was ignored
see [1] and [2].

This commit fixes SPI operations by ensuring that we only write the data
requested by the application, not just the entire buffer.

1: https://github.com/tock/tock/pull/4173/files#r1783773610
2: https://github.com/tock/tock/pull/4173/files#r1783774331

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
alistair23 added a commit to alistair23/tock that referenced this pull request Nov 13, 2024
tock#4173 drops the length specified by
the application for read only operations. This commit fixes the read
buffer length before calling the SPI operation.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HIL This affects a Tock HIL interface. kernel last-call Final review period for a pull request. nrf Change pertains to the nRF5x family of MCUs. sam4l Change pertains to the SAM4L MCU. stm32 Change pertains to the stm32 family of MCUSs WG-Network In the purview of the Network working group. WG-OpenTitan In the purview of the OpenTitan working group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0