Skip to main content

starnix_modules_gralloc/
device.rs

1// Copyright 2023 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use 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}