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