@@ -17,6 +17,7 @@ use crate::guest::bridge::common::{
1717const CROSS_DOMAIN_CHANNEL_TYPE_PW : u32 = 0x10 ;
1818const CROSS_DOMAIN_CMD_READ_EVENTFD_NEW : u8 = 11 ;
1919const CROSS_DOMAIN_CMD_READ : u8 = 6 ;
20+ const CROSS_DOMAIN_CMD_WRITE : u8 = 7 ;
2021
2122const SPA_TYPE_STRUCT : u32 = 14 ;
2223
@@ -149,6 +150,7 @@ impl MessageResourceFinalizer for PipeWireResourceFinalizer {
149150
150151struct CrossDomainEventFd {
151152 event_fd : EventFd ,
153+ resource : u32 ,
152154}
153155
154156struct ClientNodeData {
@@ -172,14 +174,22 @@ struct PipeWireProtocolHandler {
172174}
173175
174176impl PipeWireProtocolHandler {
175- fn create_guest_to_host_eventfd ( this : & mut Client < Self > , node_id : u32 ) -> Result < OwnedFd > {
177+ fn create_guest_to_host_eventfd (
178+ this : & mut Client < Self > ,
179+ node_id : u32 ,
180+ resource : CrossDomainResource ,
181+ ) -> Result < OwnedFd > {
176182 let efd = EventFd :: from_flags ( EfdFlags :: EFD_NONBLOCK ) ?;
177183 let ofd = efd. as_fd ( ) . try_clone_to_owned ( ) ?;
178184 this. sub_poll . add ( efd. as_fd ( ) , EpollFlags :: EPOLLIN ) ;
179185 let raw = efd. as_raw_fd ( ) as u64 ;
180- this. protocol_handler
181- . guest_to_host_eventfds
182- . insert ( raw, CrossDomainEventFd { event_fd : efd } ) ;
186+ this. protocol_handler . guest_to_host_eventfds . insert (
187+ raw,
188+ CrossDomainEventFd {
189+ event_fd : efd,
190+ resource : resource. identifier ,
191+ } ,
192+ ) ;
183193 this. protocol_handler
184194 . client_nodes
185195 . get_mut ( & node_id)
@@ -208,10 +218,14 @@ impl PipeWireProtocolHandler {
208218 . unwrap ( )
209219 . host_to_guest
210220 . push ( resource. identifier ) ;
211- this. gpu_ctx . submit_cmd ( & msg, msg_size, None , None ) ?;
212- this. protocol_handler
213- . host_to_guest_eventfds
214- . insert ( resource. identifier , CrossDomainEventFd { event_fd : efd } ) ;
221+ this. gpu_ctx . submit_cmd ( & msg, msg_size, None ) ?;
222+ this. protocol_handler . host_to_guest_eventfds . insert (
223+ resource. identifier ,
224+ CrossDomainEventFd {
225+ event_fd : efd,
226+ resource : resource. identifier ,
227+ } ,
228+ ) ;
215229 Ok ( ofd)
216230 }
217231}
@@ -249,13 +263,13 @@ impl ProtocolHandler for PipeWireProtocolHandler {
249263 fds. push ( this. virtgpu_id_to_prime ( rsc) ?) ;
250264 } else if this. protocol_handler . client_nodes . contains_key ( & hdr. id ) {
251265 if hdr. opcode == PW_OPC_CLIENT_NODE_SET_ACTIVATION {
252- resources. pop_front ( ) . ok_or ( Errno :: EIO ) ?;
253- fds. push ( Self :: create_guest_to_host_eventfd ( this, hdr. id ) ?) ;
266+ let rsc = resources. pop_front ( ) . ok_or ( Errno :: EIO ) ?;
267+ fds. push ( Self :: create_guest_to_host_eventfd ( this, hdr. id , rsc ) ?) ;
254268 } else if hdr. opcode == PW_OPC_CLIENT_NODE_TRANSPORT {
255269 let rsc1 = resources. pop_front ( ) . ok_or ( Errno :: EIO ) ?;
256270 fds. push ( Self :: create_host_to_guest_eventfd ( this, hdr. id , rsc1) ?) ;
257- resources. pop_front ( ) . ok_or ( Errno :: EIO ) ?;
258- fds. push ( Self :: create_guest_to_host_eventfd ( this, hdr. id ) ?) ;
271+ let rsc2 = resources. pop_front ( ) . ok_or ( Errno :: EIO ) ?;
272+ fds. push ( Self :: create_guest_to_host_eventfd ( this, hdr. id , rsc2 ) ?) ;
259273 } else {
260274 unimplemented ! ( )
261275 }
@@ -332,6 +346,25 @@ impl ProtocolHandler for PipeWireProtocolHandler {
332346 Err ( Errno :: ENOENT . into ( ) )
333347 }
334348 }
349+
350+ fn process_fd_extra ( this : & mut Client < Self > , fd : u64 , _: EpollFlags ) -> Result < ( ) > {
351+ let efd = this
352+ . protocol_handler
353+ . guest_to_host_eventfds
354+ . get ( & fd)
355+ . ok_or ( Errno :: ENOENT ) ?;
356+ let msg_size = mem:: size_of :: < CrossDomainReadWrite < [ u8 ; mem:: size_of :: < u64 > ( ) ] > > ( ) ;
357+ let val = efd. event_fd . read ( ) ?;
358+ let msg = CrossDomainReadWrite {
359+ hdr : CrossDomainHeader :: new ( CROSS_DOMAIN_CMD_WRITE , msg_size as u16 ) ,
360+ identifier : efd. resource ,
361+ hang_up : 0 ,
362+ opaque_data_size : mem:: size_of :: < u64 > ( ) as u32 ,
363+ pad : 0 ,
364+ data : val. to_ne_bytes ( ) ,
365+ } ;
366+ this. gpu_ctx . submit_cmd ( & msg, msg_size, None )
367+ }
335368}
336369
337370pub fn start_pwbridge ( ) {
0 commit comments