projects/linux·blob master · refs

77 lines · 1.8 KiB

1// SPDX-License-Identifier: GPL-2.0
2
3//! Nova Core GPU Driver
4
5use kernel::{
6 debugfs,
7 driver::Registration,
8 pci,
9 prelude::*,
10 InPlaceModule, //
11};
12
13mod driver;
14mod falcon;
15mod fb;
16mod firmware;
17mod fsp;
18mod gpu;
19mod gsp;
20mod mctp;
21#[macro_use]
22mod num;
23mod regs;
24mod sbuffer;
25mod vbios;
26mod vgpu;
27
28pub(crate) const MODULE_NAME: &core::ffi::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
29
30// TODO: Move this into per-module data once that exists.
31static mut DEBUGFS_ROOT: Option<debugfs::Dir> = None;
32
33/// Guard that clears `DEBUGFS_ROOT` when dropped.
34struct DebugfsRootGuard;
35
36impl Drop for DebugfsRootGuard {
37 fn drop(&mut self) {
38 // SAFETY: This guard is dropped after `_driver` (due to field order),
39 // so the driver is unregistered and no probe() can be running.
40 unsafe { DEBUGFS_ROOT = None };
41 }
42}
43
44#[pin_data]
45struct NovaCoreModule {
46 // Fields are dropped in declaration order, so `_driver` is dropped first,
47 // then `_debugfs_guard` clears `DEBUGFS_ROOT`.
48 #[pin]
49 _driver: Registration<pci::Adapter<driver::NovaCoreDriver>>,
50 _debugfs_guard: DebugfsRootGuard,
51}
52
53impl InPlaceModule for NovaCoreModule {
54 fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
55 let dir = debugfs::Dir::new(c"nova-core");
56
57 // SAFETY: We are the only driver code running during init, so there
58 // cannot be any concurrent access to `DEBUGFS_ROOT`.
59 unsafe { DEBUGFS_ROOT = Some(dir) };
60
61 try_pin_init!(Self {
62 _driver <- Registration::new(MODULE_NAME, module),
63 _debugfs_guard: DebugfsRootGuard,
64 })
65 }
66}
67
68module! {
69 type: NovaCoreModule,
70 name: "nova-core",
71 authors: ["Danilo Krummrich"],
72 description: "Nova Core GPU driver",
73 license: "GPL v2",
74 firmware: [],
75}
76
77kernel::module_firmware!(firmware::ModInfoBuilder);