Skip to main content

starnix_modules_kgsl/
init.rs

1// Copyright 2025 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 crate::KgslFile;
6use starnix_core::device::DeviceOps;
7use starnix_core::task::CurrentTask;
8use starnix_core::vfs::{FileOps, NamespaceNode};
9use starnix_logging::log_info;
10use starnix_sync::{FileOpsCore, LockEqualOrBefore, Locked};
11use starnix_uapi::device_type::DeviceType;
12use starnix_uapi::errors::Errno;
13use starnix_uapi::open_flags::OpenFlags;
14
15#[derive(Clone)]
16struct KgslDeviceBuilder {}
17
18impl DeviceOps for KgslDeviceBuilder {
19    fn open(
20        &self,
21        _locked: &mut Locked<FileOpsCore>,
22        current_task: &CurrentTask,
23        id: DeviceType,
24        node: &NamespaceNode,
25        flags: OpenFlags,
26    ) -> Result<Box<dyn FileOps>, Errno> {
27        log_info!("kgsl: open");
28        KgslFile::new_file(current_task, id, &node.entry.node, flags)
29    }
30}
31
32pub fn kgsl_device_init<L>(locked: &mut Locked<L>, current_task: &CurrentTask)
33where
34    L: LockEqualOrBefore<FileOpsCore>,
35{
36    log_info!("kgsl: kgsl_device_init");
37
38    let kernel = current_task.kernel();
39    let registry = &kernel.device_registry;
40    let class = registry.objects.get_or_create_class("kgsl".into(), registry.objects.virtual_bus());
41    let builder = KgslDeviceBuilder {};
42
43    registry
44        .register_dyn_device(locked, current_task, "kgsl-3d0".into(), class, builder)
45        .expect("can register kgsl-3d0");
46}