11use std:: os:: fd:: { AsRawFd , OwnedFd } ;
22
3- use memmap2:: { MmapMut , MmapOptions } ;
3+ use memmap2:: { Mmap , MmapMut , MmapOptions } ;
44use nix:: { errno:: Errno , fcntl:: { open, OFlag } , ioctl_readwrite_bad, sys:: stat:: Mode } ;
55
66use crate :: util:: wrap_ioctl_negative_invalid;
77
88#[ repr( C ) ]
99#[ derive( Default , Debug ) ]
10- struct DebugMessage {
10+ pub struct DebugMessage {
1111 pub sys_cnt : u32 ,
1212 pub log_head_addr : u32 ,
1313 pub log_end_addr : u32 ,
@@ -33,16 +33,17 @@ pub struct DspSharespace {
3333 pub debug_msg : DebugMessage ,
3434}
3535
36- #[ derive( Debug ) ]
37- enum ChooseShareSpace {
36+ #[ derive( Debug , Clone , Copy ) ]
37+ pub enum ChooseShareSpace {
3838 ChooseDspWriteSpace = 0 ,
3939 ChooseArmWriteSpace = 1 ,
40+ ChooseLogSpace = 2 ,
4041}
4142
4243ioctl_readwrite_bad ! ( read_debug_message, 0x01 , DspSharespace ) ;
4344ioctl_readwrite_bad ! ( write_debug_message, 0x03 , DspSharespace ) ;
4445
45- fn choose_sharespace (
46+ pub fn choose_sharespace (
4647 fd : & OwnedFd ,
4748 msg : & mut DspSharespace ,
4849 choose : ChooseShareSpace ,
@@ -53,7 +54,15 @@ fn choose_sharespace(
5354 msg. mmap_phy_addr = match choose {
5455 ChooseShareSpace :: ChooseDspWriteSpace => msg. dsp_write_addr ,
5556 ChooseShareSpace :: ChooseArmWriteSpace => msg. arm_write_addr ,
57+ ChooseShareSpace :: ChooseLogSpace => msg. dsp_log_addr ,
5658 } ;
59+
60+ msg. mmap_phy_size = match choose {
61+ ChooseShareSpace :: ChooseDspWriteSpace => msg. dsp_write_size ,
62+ ChooseShareSpace :: ChooseArmWriteSpace => msg. arm_write_size ,
63+ ChooseShareSpace :: ChooseLogSpace => msg. dsp_log_size ,
64+ } ;
65+
5766
5867 println ! ( "Init sharespace {:?} to 0x{:x}" , choose, msg. mmap_phy_addr) ;
5968
@@ -62,16 +71,30 @@ fn choose_sharespace(
6271 Ok ( ( ) )
6372}
6473
65- fn sharespace_open ( ) -> Result < OwnedFd , Errno > {
74+ pub fn sharespace_open ( ) -> Result < OwnedFd , Errno > {
6675 open (
6776 "/dev/dsp_debug" ,
6877 OFlag :: O_RDWR | OFlag :: O_SYNC | OFlag :: O_NONBLOCK ,
6978 Mode :: empty ( ) ,
7079 )
7180}
7281
82+ pub fn mmap_log_buffer ( ) -> Mmap {
83+ let mut dsp_sharespace = DspSharespace :: default ( ) ;
84+ let fd = sharespace_open ( ) . unwrap ( ) ;
85+
86+ choose_sharespace (
87+ & fd,
88+ & mut dsp_sharespace,
89+ ChooseShareSpace :: ChooseLogSpace ,
90+ )
91+ . unwrap ( ) ;
92+
93+ unsafe { MmapOptions :: new ( ) . len ( dsp_sharespace. dsp_log_size as usize ) . map ( & fd) . unwrap ( ) }
94+ }
95+
7396pub struct Sharespace {
74- fd : OwnedFd ,
97+ pub fd : OwnedFd ,
7598 pub dsp_sharespace : DspSharespace ,
7699 pub write_buffer : MmapMut , // ARM buffer - pu8ArmBuf
77100}
@@ -87,7 +110,7 @@ pub fn sharespace_mmap() -> Sharespace {
87110 )
88111 . unwrap ( ) ;
89112
90- let write_buffer = unsafe { MmapOptions :: new ( ) . len ( 0x1000 ) . map_mut ( & fd) . unwrap ( ) } ;
113+ let write_buffer = unsafe { MmapOptions :: new ( ) . len ( dsp_sharespace . mmap_phy_size as usize ) . map_mut ( & fd) . unwrap ( ) } ;
91114
92115 Sharespace {
93116 fd,
0 commit comments