Skip to content

Commit 9bdbf7e

Browse files
committed
Merge tag 'drm-rust-next-2026-03-30' of https://gitlab.freedesktop.org/drm/rust/kernel into drm-next
DRM Rust changes for v7.1-rc1 - DMA: - Rework the DMA coherent API: introduce Coherent<T> as a generalized container for arbitrary types, replacing the slice-only CoherentAllocation<T>. Add CoherentBox for memory initialization before exposing a buffer to hardware (converting to Coherent when ready), and CoherentHandle for allocations without kernel mapping. - Add Coherent::init() / init_with_attrs() for one-shot initialization via pin-init, and from-slice constructors for both Coherent and CoherentBox - Add uaccess write_dma() for copying from DMA buffers to userspace and BinaryWriter support for Coherent<T> - DRM: - Add GPU buddy allocator abstraction - Add DRM shmem GEM helper abstraction - Allow drm::Device to dispatch work and delayed work items to driver private data - Add impl_aref_for_gem_obj!() macro to reduce GEM refcount boilerplate, and introduce DriverObject::Args for constructor context - Add dma_resv_lock helper and raw_dma_resv() accessor on GEM objects - Clean up imports across the DRM module - I/O: - Merged via a signed tag from the driver-core tree: register!() macro and I/O infrastructure improvements (IoCapable refactor, RelaxedMmio wrapper, IoLoc trait, generic accessors, write_reg / LocatedRegister) - Nova (Core): - Fix and harden the GSP command queue: correct write pointer advancing, empty slot handling, and ring buffer indexing; add mutex locking and make Cmdq a pinned type; distinguish wait vs no-wait commands - Add support for large RPCs via continuation records, splitting oversized commands across multiple queue slots - Simplify GSP sequencer and message handling code: remove unused trait and Display impls, derive Debug and Zeroable where applicable, warn on unconsumed message data - Refactor Falcon firmware handling: create DMA objects lazily, add PIO upload support, and use the Generic Bootloader to boot FWSEC on Turing - Convert all register definitions (PMC, PBUS, PFB, GC6, FUSE, PDISP, Falcon) to the kernel register!() macro; add bounded_enum macro to define enums usable as register fields - Migrate all DMA usage to the new Coherent, CoherentBox, and CoherentHandle APIs - Harden firmware parsing with checked arithmetic throughout FWSEC, Booter, RISC-V parsing paths - Add debugfs support for reading GSP-RM log buffers; replace module_pci_driver!() with explicit module init to support module-level debugfs setup - Fix auxiliary device registration for multi-GPU systems - Various cleanups: import style, firmware parsing refactoring, framebuffer size logging - Rust: - Add interop::list module providing a C linked list interface - Extend num::Bounded with shift operations, into_bool(), and const get() to support register bitfield manipulation - Enable the generic_arg_infer Rust feature and add EMSGSIZE error code - Tyr: - Adopt vertical import style per kernel Rust guidelines - Clarify driver/device type names and use DRM device type alias consistently across the driver - Fix GPU model/version decoding in GpuInfo - Workqueue: - Add ARef<T> support for work and delayed work Signed-off-by: Dave Airlie <airlied@redhat.com> From: "Danilo Krummrich" <dakr@kernel.org> Link: https://patch.msgid.link/DHGH4BLT03BU.ZJH5U52WE8BY@kernel.org
2 parents 2889903 + 7c50d74 commit 9bdbf7e

74 files changed

Lines changed: 7125 additions & 3058 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/gpu/nova/core/todo.rst

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -51,82 +51,6 @@ There also have been considerations of ToPrimitive [2].
5151
| Link: https://lore.kernel.org/all/cover.1750689857.git.y.j3ms.n@gmail.com/ [1]
5252
| Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Implement.20.60FromPrimitive.60.20trait.20.2B.20derive.20macro.20for.20nova-core/with/541971854 [2]
5353
54-
Generic register abstraction [REGA]
55-
-----------------------------------
56-
57-
Work out how register constants and structures can be automatically generated
58-
through generalized macros.
59-
60-
Example:
61-
62-
.. code-block:: rust
63-
64-
register!(BOOT0, 0x0, u32, pci::Bar<SIZE>, Fields [
65-
MINOR_REVISION(3:0, RO),
66-
MAJOR_REVISION(7:4, RO),
67-
REVISION(7:0, RO), // Virtual register combining major and minor rev.
68-
])
69-
70-
This could expand to something like:
71-
72-
.. code-block:: rust
73-
74-
const BOOT0_OFFSET: usize = 0x00000000;
75-
const BOOT0_MINOR_REVISION_SHIFT: u8 = 0;
76-
const BOOT0_MINOR_REVISION_MASK: u32 = 0x0000000f;
77-
const BOOT0_MAJOR_REVISION_SHIFT: u8 = 4;
78-
const BOOT0_MAJOR_REVISION_MASK: u32 = 0x000000f0;
79-
const BOOT0_REVISION_SHIFT: u8 = BOOT0_MINOR_REVISION_SHIFT;
80-
const BOOT0_REVISION_MASK: u32 = BOOT0_MINOR_REVISION_MASK | BOOT0_MAJOR_REVISION_MASK;
81-
82-
struct Boot0(u32);
83-
84-
impl Boot0 {
85-
#[inline]
86-
fn read(bar: &RevocableGuard<'_, pci::Bar<SIZE>>) -> Self {
87-
Self(bar.readl(BOOT0_OFFSET))
88-
}
89-
90-
#[inline]
91-
fn minor_revision(&self) -> u32 {
92-
(self.0 & BOOT0_MINOR_REVISION_MASK) >> BOOT0_MINOR_REVISION_SHIFT
93-
}
94-
95-
#[inline]
96-
fn major_revision(&self) -> u32 {
97-
(self.0 & BOOT0_MAJOR_REVISION_MASK) >> BOOT0_MAJOR_REVISION_SHIFT
98-
}
99-
100-
#[inline]
101-
fn revision(&self) -> u32 {
102-
(self.0 & BOOT0_REVISION_MASK) >> BOOT0_REVISION_SHIFT
103-
}
104-
}
105-
106-
Usage:
107-
108-
.. code-block:: rust
109-
110-
let bar = bar.try_access().ok_or(ENXIO)?;
111-
112-
let boot0 = Boot0::read(&bar);
113-
pr_info!("Revision: {}\n", boot0.revision());
114-
115-
A work-in-progress implementation currently resides in
116-
`drivers/gpu/nova-core/regs/macros.rs` and is used in nova-core. It would be
117-
nice to improve it (possibly using proc macros) and move it to the `kernel`
118-
crate so it can be used by other components as well.
119-
120-
Features desired before this happens:
121-
122-
* Make I/O optional I/O (for field values that are not registers),
123-
* Support other sizes than `u32`,
124-
* Allow visibility control for registers and individual fields,
125-
* Use Rust slice syntax to express fields ranges.
126-
127-
| Complexity: Advanced
128-
| Contact: Alexandre Courbot
129-
13054
Numerical operations [NUMM]
13155
---------------------------
13256

MAINTAINERS

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7534,6 +7534,7 @@ F: include/linux/*fence.h
75347534
F: include/linux/dma-buf.h
75357535
F: include/linux/dma-buf/
75367536
F: include/linux/dma-resv.h
7537+
F: rust/helpers/dma-resv.c
75377538
K: \bdma_(?:buf|fence|resv)\b
75387539

75397540
DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
@@ -8513,7 +8514,10 @@ T: git https://gitlab.freedesktop.org/drm/rust/kernel.git
85138514
F: drivers/gpu/drm/nova/
85148515
F: drivers/gpu/drm/tyr/
85158516
F: drivers/gpu/nova-core/
8517+
F: rust/helpers/gpu.c
85168518
F: rust/kernel/drm/
8519+
F: rust/kernel/gpu.rs
8520+
F: rust/kernel/gpu/
85178521

85188522
DRM DRIVERS FOR ALLWINNER A10
85198523
M: Chen-Yu Tsai <wens@kernel.org>
@@ -8931,7 +8935,7 @@ F: include/drm/ttm/
89318935
GPU BUDDY ALLOCATOR
89328936
M: Matthew Auld <matthew.auld@intel.com>
89338937
M: Arun Pravin <arunpravin.paneerselvam@amd.com>
8934-
R: Christian Koenig <christian.koenig@amd.com>
8938+
R: Joel Fernandes <joelagnelf@nvidia.com>
89358939
L: dri-devel@lists.freedesktop.org
89368940
S: Maintained
89378941
T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -8940,6 +8944,9 @@ F: drivers/gpu/drm/drm_buddy.c
89408944
F: drivers/gpu/tests/gpu_buddy_test.c
89418945
F: include/drm/drm_buddy.h
89428946
F: include/linux/gpu_buddy.h
8947+
F: rust/helpers/gpu.c
8948+
F: rust/kernel/gpu.rs
8949+
F: rust/kernel/gpu/
89438950

89448951
DRM AUTOMATED TESTING
89458952
M: Helen Koike <helen.fornazier@gmail.com>
@@ -23208,6 +23215,15 @@ T: git https://github.com/Rust-for-Linux/linux.git alloc-next
2320823215
F: rust/kernel/alloc.rs
2320923216
F: rust/kernel/alloc/
2321023217

23218+
RUST [INTEROP]
23219+
M: Joel Fernandes <joelagnelf@nvidia.com>
23220+
M: Alexandre Courbot <acourbot@nvidia.com>
23221+
L: rust-for-linux@vger.kernel.org
23222+
S: Maintained
23223+
T: git https://github.com/Rust-for-Linux/linux.git interop-next
23224+
F: rust/kernel/interop.rs
23225+
F: rust/kernel/interop/
23226+
2321123227
RUST [NUM]
2321223228
M: Alexandre Courbot <acourbot@nvidia.com>
2321323229
R: Yury Norov <yury.norov@gmail.com>

drivers/gpu/drm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ config DRM_GEM_SHMEM_HELPER
268268
help
269269
Choose this if you need the GEM shmem helper functions
270270

271+
config RUST_DRM_GEM_SHMEM_HELPER
272+
bool
273+
depends on DRM && MMU
274+
select DRM_GEM_SHMEM_HELPER
275+
help
276+
Choose this if you need the GEM shmem helper functions In Rust
277+
271278
config DRM_SUBALLOC_HELPER
272279
tristate
273280
depends on DRM

drivers/gpu/drm/nova/gem.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ pub(crate) struct NovaObject {}
1919

2020
impl gem::DriverObject for NovaObject {
2121
type Driver = NovaDriver;
22+
type Args = ();
2223

23-
fn new(_dev: &NovaDevice, _size: usize) -> impl PinInit<Self, Error> {
24+
fn new(_dev: &NovaDevice, _size: usize, _args: Self::Args) -> impl PinInit<Self, Error> {
2425
try_pin_init!(NovaObject {})
2526
}
2627
}
@@ -33,7 +34,7 @@ impl NovaObject {
3334
}
3435
let aligned_size = page::page_align(size).ok_or(EINVAL)?;
3536

36-
gem::Object::new(dev, aligned_size)
37+
gem::Object::new(dev, aligned_size, ())
3738
}
3839

3940
/// Look up a GEM object handle for a `File` and return an `ObjectRef` for it.

drivers/gpu/drm/tyr/driver.rs

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
11
// SPDX-License-Identifier: GPL-2.0 or MIT
22

3-
use kernel::clk::Clk;
4-
use kernel::clk::OptionalClk;
5-
use kernel::device::Bound;
6-
use kernel::device::Core;
7-
use kernel::device::Device;
8-
use kernel::devres::Devres;
9-
use kernel::drm;
10-
use kernel::drm::ioctl;
11-
use kernel::io::poll;
12-
use kernel::new_mutex;
13-
use kernel::of;
14-
use kernel::platform;
15-
use kernel::prelude::*;
16-
use kernel::regulator;
17-
use kernel::regulator::Regulator;
18-
use kernel::sizes::SZ_2M;
19-
use kernel::sync::aref::ARef;
20-
use kernel::sync::Arc;
21-
use kernel::sync::Mutex;
22-
use kernel::time;
23-
24-
use crate::file::File;
25-
use crate::gem::TyrObject;
26-
use crate::gpu;
27-
use crate::gpu::GpuInfo;
28-
use crate::regs;
3+
use kernel::{
4+
clk::{
5+
Clk,
6+
OptionalClk, //
7+
},
8+
device::{
9+
Bound,
10+
Core,
11+
Device, //
12+
},
13+
devres::Devres,
14+
drm,
15+
drm::ioctl,
16+
io::poll,
17+
new_mutex,
18+
of,
19+
platform,
20+
prelude::*,
21+
regulator,
22+
regulator::Regulator,
23+
sizes::SZ_2M,
24+
sync::{
25+
aref::ARef,
26+
Arc,
27+
Mutex, //
28+
},
29+
time, //
30+
};
31+
32+
use crate::{
33+
file::TyrDrmFileData,
34+
gem::TyrObject,
35+
gpu,
36+
gpu::GpuInfo,
37+
regs, //
38+
};
2939

3040
pub(crate) type IoMem = kernel::io::mem::IoMem<SZ_2M>;
3141

42+
pub(crate) struct TyrDrmDriver;
43+
3244
/// Convenience type alias for the DRM device type for this driver.
33-
pub(crate) type TyrDevice = drm::Device<TyrDriver>;
45+
pub(crate) type TyrDrmDevice = drm::Device<TyrDrmDriver>;
3446

3547
#[pin_data(PinnedDrop)]
36-
pub(crate) struct TyrDriver {
37-
_device: ARef<TyrDevice>,
48+
pub(crate) struct TyrPlatformDriverData {
49+
_device: ARef<TyrDrmDevice>,
3850
}
3951

4052
#[pin_data(PinnedDrop)]
41-
pub(crate) struct TyrData {
53+
pub(crate) struct TyrDrmDeviceData {
4254
pub(crate) pdev: ARef<platform::Device>,
4355

4456
#[pin]
@@ -61,9 +73,9 @@ pub(crate) struct TyrData {
6173
// that it will be removed in a future patch.
6274
//
6375
// SAFETY: This will be removed in a future patch.
64-
unsafe impl Send for TyrData {}
76+
unsafe impl Send for TyrDrmDeviceData {}
6577
// SAFETY: This will be removed in a future patch.
66-
unsafe impl Sync for TyrData {}
78+
unsafe impl Sync for TyrDrmDeviceData {}
6779

6880
fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
6981
regs::GPU_CMD.write(dev, iomem, regs::GPU_CMD_SOFT_RESET)?;
@@ -82,14 +94,14 @@ fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
8294
kernel::of_device_table!(
8395
OF_TABLE,
8496
MODULE_OF_TABLE,
85-
<TyrDriver as platform::Driver>::IdInfo,
97+
<TyrPlatformDriverData as platform::Driver>::IdInfo,
8698
[
8799
(of::DeviceId::new(c"rockchip,rk3588-mali"), ()),
88100
(of::DeviceId::new(c"arm,mali-valhall-csf"), ())
89101
]
90102
);
91103

92-
impl platform::Driver for TyrDriver {
104+
impl platform::Driver for TyrPlatformDriverData {
93105
type IdInfo = ();
94106
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
95107

@@ -119,7 +131,7 @@ impl platform::Driver for TyrDriver {
119131

120132
let platform: ARef<platform::Device> = pdev.into();
121133

122-
let data = try_pin_init!(TyrData {
134+
let data = try_pin_init!(TyrDrmDeviceData {
123135
pdev: platform.clone(),
124136
clks <- new_mutex!(Clocks {
125137
core: core_clk,
@@ -133,10 +145,10 @@ impl platform::Driver for TyrDriver {
133145
gpu_info,
134146
});
135147

136-
let tdev: ARef<TyrDevice> = drm::Device::new(pdev.as_ref(), data)?;
137-
drm::driver::Registration::new_foreign_owned(&tdev, pdev.as_ref(), 0)?;
148+
let ddev: ARef<TyrDrmDevice> = drm::Device::new(pdev.as_ref(), data)?;
149+
drm::driver::Registration::new_foreign_owned(&ddev, pdev.as_ref(), 0)?;
138150

139-
let driver = TyrDriver { _device: tdev };
151+
let driver = TyrPlatformDriverData { _device: ddev };
140152

141153
// We need this to be dev_info!() because dev_dbg!() does not work at
142154
// all in Rust for now, and we need to see whether probe succeeded.
@@ -146,12 +158,12 @@ impl platform::Driver for TyrDriver {
146158
}
147159

148160
#[pinned_drop]
149-
impl PinnedDrop for TyrDriver {
161+
impl PinnedDrop for TyrPlatformDriverData {
150162
fn drop(self: Pin<&mut Self>) {}
151163
}
152164

153165
#[pinned_drop]
154-
impl PinnedDrop for TyrData {
166+
impl PinnedDrop for TyrDrmDeviceData {
155167
fn drop(self: Pin<&mut Self>) {
156168
// TODO: the type-state pattern for Clks will fix this.
157169
let clks = self.clks.lock();
@@ -172,15 +184,15 @@ const INFO: drm::DriverInfo = drm::DriverInfo {
172184
};
173185

174186
#[vtable]
175-
impl drm::Driver for TyrDriver {
176-
type Data = TyrData;
177-
type File = File;
187+
impl drm::Driver for TyrDrmDriver {
188+
type Data = TyrDrmDeviceData;
189+
type File = TyrDrmFileData;
178190
type Object = drm::gem::Object<TyrObject>;
179191

180192
const INFO: drm::DriverInfo = INFO;
181193

182194
kernel::declare_drm_ioctls! {
183-
(PANTHOR_DEV_QUERY, drm_panthor_dev_query, ioctl::RENDER_ALLOW, File::dev_query),
195+
(PANTHOR_DEV_QUERY, drm_panthor_dev_query, ioctl::RENDER_ALLOW, TyrDrmFileData::dev_query),
184196
}
185197
}
186198

0 commit comments

Comments
 (0)