Expand description
Zero-size ownership tokens for peripherals with shared state.
One token exists per device whose state two drivers could otherwise
fight over: the GPU’s DMA channel (an in-flight linked-list walk and a
GP0 write interleave), the ordering-table clear, MDEC and SPU channels, the CD-ROM
controller (three drivers program it) and the controller port (pads and memory
cards share it). An API that drives one of them takes the token by &mut, so
the borrow checker sees the conflict. The tokens are empty, so passing
them costs nothing at run time.
Get the whole set once with psx_rt::Peripherals::take(). Who owns what:
| Token | Owner | Others borrow it as |
|---|---|---|
GpuDma | psx_gpu::Gpu | Gpu::dma_mut, Gpu::from_dma_mut |
Cd | the program, or cd::reader::SectorReader / cd::xa::Player while one exists | &mut Cd methods (command, play_track, …), SectorReader::cd_mut |
ControllerPort | the program | &mut ControllerPort into psx_pad polls and psx_mc::HardwareCard |
SpuDma | psx_spu::Spu | Spu::upload_adpcm |
MdecDma | psx_fmv::mdec::Mdec | its methods |
OrderingTableClearDma | the program | OrderingTableClearDma::clear_table, OrderingTable::clear_with_dma |
A token is a logic guard, not a memory-safety one: the SDK’s DMA APIs prove
buffer lifetimes through references and slices whether or not a token is
involved. That is why GpuDma::steal and friends are unsafe only in
the “you are breaking an ownership invariant” sense. The deprecated free
functions that predate the tokens steal one per call.
Structs§
- Cd
- The CD-ROM controller and DMA channel 3.
- Controller
Port - The controller and memory-card port.
- GpuDma
- DMA channel 2 (RAM to GP0, and GPUREAD to RAM) and the GP0 command stream it feeds.
- MdecDma
- DMA channels 0 and 1, into and out of the MDEC.
- Ordering
Table Clear Dma - DMA channel 6, the ordering-table clear.
- SpuDma
- DMA channel 4 (RAM to SPU RAM and back) and the SPU transfer port.