1*eafedbc7SAlice Ryhl // SPDX-License-Identifier: GPL-2.0 2*eafedbc7SAlice Ryhl 3*eafedbc7SAlice Ryhl // Copyright (C) 2025 Google LLC. 4*eafedbc7SAlice Ryhl 5*eafedbc7SAlice Ryhl use kernel::{list::ListArc, prelude::*, seq_file::SeqFile, seq_print, sync::UniqueArc}; 6*eafedbc7SAlice Ryhl 7*eafedbc7SAlice Ryhl use crate::{node::Node, thread::Thread, BinderReturnWriter, DArc, DLArc, DTRWrap, DeliverToRead}; 8*eafedbc7SAlice Ryhl 9*eafedbc7SAlice Ryhl use core::mem::MaybeUninit; 10*eafedbc7SAlice Ryhl 11*eafedbc7SAlice Ryhl pub(crate) struct CritIncrWrapper { 12*eafedbc7SAlice Ryhl inner: UniqueArc<MaybeUninit<DTRWrap<NodeWrapper>>>, 13*eafedbc7SAlice Ryhl } 14*eafedbc7SAlice Ryhl 15*eafedbc7SAlice Ryhl impl CritIncrWrapper { 16*eafedbc7SAlice Ryhl pub(crate) fn new() -> Result<Self> { 17*eafedbc7SAlice Ryhl Ok(CritIncrWrapper { 18*eafedbc7SAlice Ryhl inner: UniqueArc::new_uninit(GFP_KERNEL)?, 19*eafedbc7SAlice Ryhl }) 20*eafedbc7SAlice Ryhl } 21*eafedbc7SAlice Ryhl 22*eafedbc7SAlice Ryhl pub(super) fn init(self, node: DArc<Node>) -> DLArc<dyn DeliverToRead> { 23*eafedbc7SAlice Ryhl match self.inner.pin_init_with(DTRWrap::new(NodeWrapper { node })) { 24*eafedbc7SAlice Ryhl Ok(initialized) => ListArc::from(initialized) as _, 25*eafedbc7SAlice Ryhl Err(err) => match err {}, 26*eafedbc7SAlice Ryhl } 27*eafedbc7SAlice Ryhl } 28*eafedbc7SAlice Ryhl } 29*eafedbc7SAlice Ryhl 30*eafedbc7SAlice Ryhl struct NodeWrapper { 31*eafedbc7SAlice Ryhl node: DArc<Node>, 32*eafedbc7SAlice Ryhl } 33*eafedbc7SAlice Ryhl 34*eafedbc7SAlice Ryhl kernel::list::impl_list_arc_safe! { 35*eafedbc7SAlice Ryhl impl ListArcSafe<0> for NodeWrapper { 36*eafedbc7SAlice Ryhl untracked; 37*eafedbc7SAlice Ryhl } 38*eafedbc7SAlice Ryhl } 39*eafedbc7SAlice Ryhl 40*eafedbc7SAlice Ryhl impl DeliverToRead for NodeWrapper { 41*eafedbc7SAlice Ryhl fn do_work( 42*eafedbc7SAlice Ryhl self: DArc<Self>, 43*eafedbc7SAlice Ryhl _thread: &Thread, 44*eafedbc7SAlice Ryhl writer: &mut BinderReturnWriter<'_>, 45*eafedbc7SAlice Ryhl ) -> Result<bool> { 46*eafedbc7SAlice Ryhl let node = &self.node; 47*eafedbc7SAlice Ryhl let mut owner_inner = node.owner.inner.lock(); 48*eafedbc7SAlice Ryhl let inner = node.inner.access_mut(&mut owner_inner); 49*eafedbc7SAlice Ryhl 50*eafedbc7SAlice Ryhl let ds = &mut inner.delivery_state; 51*eafedbc7SAlice Ryhl 52*eafedbc7SAlice Ryhl assert!(ds.has_pushed_wrapper); 53*eafedbc7SAlice Ryhl assert!(ds.has_strong_zero2one); 54*eafedbc7SAlice Ryhl ds.has_pushed_wrapper = false; 55*eafedbc7SAlice Ryhl ds.has_strong_zero2one = false; 56*eafedbc7SAlice Ryhl 57*eafedbc7SAlice Ryhl node.do_work_locked(writer, owner_inner) 58*eafedbc7SAlice Ryhl } 59*eafedbc7SAlice Ryhl 60*eafedbc7SAlice Ryhl fn cancel(self: DArc<Self>) {} 61*eafedbc7SAlice Ryhl 62*eafedbc7SAlice Ryhl fn should_sync_wakeup(&self) -> bool { 63*eafedbc7SAlice Ryhl false 64*eafedbc7SAlice Ryhl } 65*eafedbc7SAlice Ryhl 66*eafedbc7SAlice Ryhl #[inline(never)] 67*eafedbc7SAlice Ryhl fn debug_print(&self, m: &SeqFile, prefix: &str, _tprefix: &str) -> Result<()> { 68*eafedbc7SAlice Ryhl seq_print!( 69*eafedbc7SAlice Ryhl m, 70*eafedbc7SAlice Ryhl "{}node work {}: u{:016x} c{:016x}\n", 71*eafedbc7SAlice Ryhl prefix, 72*eafedbc7SAlice Ryhl self.node.debug_id, 73*eafedbc7SAlice Ryhl self.node.ptr, 74*eafedbc7SAlice Ryhl self.node.cookie, 75*eafedbc7SAlice Ryhl ); 76*eafedbc7SAlice Ryhl Ok(()) 77*eafedbc7SAlice Ryhl } 78*eafedbc7SAlice Ryhl } 79