starnix_modules_gralloc/
device.rs1use super::file::GrallocFile;
6use starnix_core::device::DeviceOps;
7use starnix_core::task::CurrentTask;
8use starnix_core::vfs::{FileOps, NamespaceNode};
9use starnix_sync::{FileOpsCore, LockEqualOrBefore, Locked};
10use starnix_uapi::device_type::DeviceType;
11use starnix_uapi::errors::Errno;
12use starnix_uapi::open_flags::OpenFlags;
13
14#[derive(Clone)]
15struct GrallocDevice;
16
17impl DeviceOps for GrallocDevice {
18 fn open(
19 &self,
20 _locked: &mut Locked<FileOpsCore>,
21 current_task: &CurrentTask,
22 _id: DeviceType,
23 _node: &NamespaceNode,
24 _flags: OpenFlags,
25 ) -> Result<Box<dyn FileOps>, Errno> {
26 GrallocFile::new_file(current_task)
27 }
28}
29
30pub fn gralloc_device_init<L>(locked: &mut Locked<L>, current_task: &CurrentTask)
31where
32 L: LockEqualOrBefore<FileOpsCore>,
33{
34 let kernel = current_task.kernel();
35 let registry = &kernel.device_registry;
36 registry
37 .register_dyn_device(
38 locked,
39 current_task,
40 "virtgralloc0".into(),
41 registry.objects.starnix_class(),
42 GrallocDevice,
43 )
44 .expect("can register virtgralloc0");
45}