Skip to content

Commit 3606620

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: update and annotate TODO list
A few new dependencies are required to remove some of the TODO items: - A way to safely convert from byte slices to types implementing `FromBytes`, - A way to obtain slices and write into a `CoherentAllocation`, - Several improvements to the `register!()` macro, - Alignment operations to powers of two, and an equivalent to the C `fls`, - Support for `xa_alloc` in the XAlloc bindings. Some items have also become obsolete: - The auxiliary bus abstractions have been implemented and are in use, - The ELF utilities are not considered for being part of the core kernel bindings anymore. - VBIOS, falcon and GPU timer have been completed. We now have quite a few TODO entries in the code, so annotate them with a 4 letter code representing the corresponding task in `todo.rst`. This allows to easily find which part of the code corresponds to a given entry (and conversely). Signed-off-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 859aa3d commit 3606620

File tree

13 files changed

+84
-71
lines changed

13 files changed

+84
-71
lines changed

Documentation/gpu/nova/core/todo.rst

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ Tasks may have the following fields:
1414
- ``Contact``: The person that can be contacted for further information about
1515
the task.
1616

17+
A task might have `[ABCD]` code after its name. This code can be used to grep
18+
into the code for `TODO` entries related to it.
19+
1720
Enablement (Rust)
1821
=================
1922

2023
Tasks that are not directly related to nova-core, but are preconditions in terms
2124
of required APIs.
2225

23-
FromPrimitive API
24-
-----------------
26+
FromPrimitive API [FPRI]
27+
------------------------
2528

2629
Sometimes the need arises to convert a number to a value of an enum or a
2730
structure.
@@ -41,8 +44,27 @@ automatically generates the corresponding mappings between a value and a number.
4144
| Complexity: Beginner
4245
| Link: https://docs.rs/num/latest/num/trait.FromPrimitive.html
4346
44-
Generic register abstraction
45-
----------------------------
47+
Conversion from byte slices for types implementing FromBytes [TRSM]
48+
-------------------------------------------------------------------
49+
50+
We retrieve several structures from byte streams coming from the BIOS or loaded
51+
firmware. At the moment converting the bytes slice into the proper type require
52+
an inelegant `unsafe` operation; this will go away once `FromBytes` implements
53+
a proper `from_bytes` method.
54+
55+
| Complexity: Beginner
56+
57+
CoherentAllocation improvements [COHA]
58+
--------------------------------------
59+
60+
`CoherentAllocation` needs a safe way to write into the allocation, and to
61+
obtain slices within the allocation.
62+
63+
| Complexity: Beginner
64+
| Contact: Abdiel Janulgue
65+
66+
Generic register abstraction [REGA]
67+
-----------------------------------
4668

4769
Work out how register constants and structures can be automatically generated
4870
through generalized macros.
@@ -102,16 +124,40 @@ Usage:
102124
let boot0 = Boot0::read(&bar);
103125
pr_info!("Revision: {}\n", boot0.revision());
104126
105-
Note: a work-in-progress implementation currently resides in
127+
A work-in-progress implementation currently resides in
106128
`drivers/gpu/nova-core/regs/macros.rs` and is used in nova-core. It would be
107129
nice to improve it (possibly using proc macros) and move it to the `kernel`
108130
crate so it can be used by other components as well.
109131

132+
Features desired before this happens:
133+
134+
* Relative register with build-time base address validation,
135+
* Arrays of registers with build-time index validation,
136+
* Make I/O optional I/O (for field values that are not registers),
137+
* Support other sizes than `u32`,
138+
* Allow visibility control for registers and individual fields,
139+
* Use Rust slice syntax to express fields ranges.
140+
110141
| Complexity: Advanced
111142
| Contact: Alexandre Courbot
112143
113-
Delay / Sleep abstractions
114-
--------------------------
144+
Numerical operations [NUMM]
145+
---------------------------
146+
147+
Nova uses integer operations that are not part of the standard library (or not
148+
implemented in an optimized way for the kernel). These include:
149+
150+
- Aligning up and down to a power of two,
151+
- The "Find Last Set Bit" (`fls` function of the C part of the kernel)
152+
operation.
153+
154+
A `num` core kernel module is being designed to provide these operations.
155+
156+
| Complexity: Intermediate
157+
| Contact: Alexandre Courbot
158+
159+
Delay / Sleep abstractions [DLAY]
160+
---------------------------------
115161

116162
Rust abstractions for the kernel's delay() and sleep() functions.
117163

@@ -159,18 +205,6 @@ mailing list yet.
159205
| Complexity: Intermediate
160206
| Contact: Abdiel Janulgue
161207
162-
ELF utils
163-
---------
164-
165-
Rust implementation of ELF header representation to retrieve section header
166-
tables, names, and data from an ELF-formatted images.
167-
168-
There is preceding work from Abdiel Janulgue, which hasn't made it to the
169-
mailing list yet.
170-
171-
| Complexity: Beginner
172-
| Contact: Abdiel Janulgue
173-
174208
PCI MISC APIs
175209
-------------
176210

@@ -179,12 +213,11 @@ capability, MSI API abstractions.
179213

180214
| Complexity: Beginner
181215
182-
Auxiliary bus abstractions
183-
--------------------------
184-
185-
Rust abstraction for the auxiliary bus APIs.
216+
XArray bindings [XARR]
217+
----------------------
186218

187-
This is needed to connect nova-core to the nova-drm driver.
219+
We need bindings for `xa_alloc`/`xa_alloc_cyclic` in order to generate the
220+
auxiliary device IDs.
188221

189222
| Complexity: Intermediate
190223
@@ -216,15 +249,6 @@ Build the radix3 page table to map the firmware.
216249
| Complexity: Intermediate
217250
| Contact: Abdiel Janulgue
218251
219-
vBIOS support
220-
-------------
221-
222-
Parse the vBIOS and probe the structures required for driver initialization.
223-
224-
| Contact: Dave Airlie
225-
| Reference: Vec extensions
226-
| Complexity: Intermediate
227-
228252
Initial Devinit support
229253
-----------------------
230254

@@ -234,23 +258,6 @@ configuration.
234258
| Contact: Dave Airlie
235259
| Complexity: Beginner
236260
237-
Boot Falcon controller
238-
----------------------
239-
240-
Infrastructure to load and execute falcon (sec2) firmware images; handle the
241-
GSP falcon processor and fwsec loading.
242-
243-
| Complexity: Advanced
244-
| Contact: Dave Airlie
245-
246-
GPU Timer support
247-
-----------------
248-
249-
Support for the GPU's internal timer peripheral.
250-
251-
| Complexity: Beginner
252-
| Contact: Dave Airlie
253-
254261
MMU / PT management
255262
-------------------
256263

drivers/gpu/nova-core/dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl DmaObject {
2626

2727
pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> {
2828
Self::new(dev, data.len()).map(|mut dma_obj| {
29-
// TODO: replace with `CoherentAllocation::write()` once available.
29+
// TODO[COHA]: replace with `CoherentAllocation::write()` once available.
3030
// SAFETY:
3131
// - `dma_obj`'s size is at least `data.len()`.
3232
// - We have just created this object and there is no other user at this stage.

drivers/gpu/nova-core/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl pci::Driver for NovaCore {
4242
_reg: auxiliary::Registration::new(
4343
pdev.as_ref(),
4444
c_str!("nova-drm"),
45-
0, // TODO: Once it lands, use XArray; for now we don't use the ID.
45+
0, // TODO[XARR]: Once it lands, use XArray; for now we don't use the ID.
4646
crate::MODULE_NAME
4747
)?,
4848
}),

drivers/gpu/nova-core/falcon.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) enum FalconCoreRev {
3535
Rev7 = 7,
3636
}
3737

38+
// TODO[FPRI]: replace with `FromPrimitive`.
3839
impl TryFrom<u8> for FalconCoreRev {
3940
type Error = Error;
4041

@@ -68,6 +69,7 @@ pub(crate) enum FalconCoreRevSubversion {
6869
Subversion3 = 3,
6970
}
7071

72+
// TODO[FPRI]: replace with `FromPrimitive`.
7173
impl TryFrom<u8> for FalconCoreRevSubversion {
7274
type Error = Error;
7375

@@ -101,6 +103,7 @@ pub(crate) enum FalconSecurityModel {
101103
Heavy = 3,
102104
}
103105

106+
// TODO[FPRI]: replace with `FromPrimitive`.
104107
impl TryFrom<u8> for FalconSecurityModel {
105108
type Error = Error;
106109

@@ -128,6 +131,7 @@ pub(crate) enum FalconModSelAlgo {
128131
Rsa3k = 1,
129132
}
130133

134+
// TODO[FPRI]: replace with `FromPrimitive`.
131135
impl TryFrom<u8> for FalconModSelAlgo {
132136
type Error = Error;
133137

@@ -148,6 +152,7 @@ pub(crate) enum DmaTrfCmdSize {
148152
Size256B = 0x6,
149153
}
150154

155+
// TODO[FPRI]: replace with `FromPrimitive`.
151156
impl TryFrom<u8> for DmaTrfCmdSize {
152157
type Error = Error;
153158

@@ -199,6 +204,7 @@ pub(crate) enum FalconFbifTarget {
199204
NoncoherentSysmem = 2,
200205
}
201206

207+
// TODO[FPRI]: replace with `FromPrimitive`.
202208
impl TryFrom<u8> for FalconFbifTarget {
203209
type Error = Error;
204210

@@ -354,7 +360,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
354360

355361
regs::NV_PFALCON_FALCON_ENGINE::alter(bar, E::BASE, |v| v.set_reset(true));
356362

357-
// TODO: replace with udelay() or equivalent once available.
363+
// TODO[DLAY]: replace with udelay() or equivalent once available.
358364
// TIMEOUT: falcon engine should not take more than 10us to reset.
359365
let _: Result = util::wait_on(Duration::from_micros(10), || None);
360366

drivers/gpu/nova-core/falcon/hal/ga102.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ fn signature_reg_fuse_version_ga102(
4242
engine_id_mask: u16,
4343
ucode_id: u8,
4444
) -> Result<u32> {
45-
// TODO: The ucode fuse versions are contained in the FUSE_OPT_FPF_<ENGINE>_UCODE<X>_VERSION
46-
// registers, which are an array. Our register definition macros do not allow us to manage them
47-
// properly, so we need to hardcode their addresses for now. Clean this up once we support
48-
// register arrays.
45+
// TODO[REGA]: The ucode fuse versions are contained in the
46+
// FUSE_OPT_FPF_<ENGINE>_UCODE<X>_VERSION registers, which are an array. Our register
47+
// definition macros do not allow us to manage them properly, so we need to hardcode their
48+
// addresses for now. Clean this up once we support register arrays.
4949

5050
// Each engine has 16 ucode version registers numbered from 1 to 16.
5151
if ucode_id == 0 || ucode_id > 16 {
@@ -69,7 +69,7 @@ fn signature_reg_fuse_version_ga102(
6969
let reg_fuse_version =
7070
bar.read32(reg_fuse_base + ((ucode_id - 1) as usize * core::mem::size_of::<u32>()));
7171

72-
// TODO: replace with `last_set_bit` once it lands.
72+
// TODO[NUMM]: replace with `last_set_bit` once it lands.
7373
Ok(u32::BITS - reg_fuse_version.leading_zeros())
7474
}
7575

drivers/gpu/nova-core/fb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl FbLayout {
122122
let frts = {
123123
const FRTS_DOWN_ALIGN: u64 = SZ_128K as u64;
124124
const FRTS_SIZE: u64 = SZ_1M as u64;
125-
// TODO: replace with `align_down` once it lands.
125+
// TODO[NUMM]: replace with `align_down` once it lands.
126126
let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN - 1)) - FRTS_SIZE;
127127

128128
frts_base..frts_base + FRTS_SIZE

drivers/gpu/nova-core/firmware/fwsec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ impl FirmwareSignature<FwsecFirmware> for Bcrt30Rsa3kSignature {}
150150
/// Callers must ensure that the region of memory returned is not written for as long as the
151151
/// returned reference is alive.
152152
///
153-
/// TODO: Remove this and `transmute_mut` once `CoherentAllocation::as_slice` is available and we
154-
/// have a way to transmute objects implementing FromBytes, e.g.:
153+
/// TODO[TRSM][COHA]: Remove this and `transmute_mut` once `CoherentAllocation::as_slice` is
154+
/// available and we have a way to transmute objects implementing FromBytes, e.g.:
155155
/// https://lore.kernel.org/lkml/[email protected]/
156156
unsafe fn transmute<'a, 'b, T: Sized + FromBytes>(
157157
fw: &'a DmaObject,
@@ -218,7 +218,7 @@ impl FalconLoadParams for FwsecFirmware {
218218
FalconLoadTarget {
219219
src_start: self.desc.imem_load_size,
220220
dst_start: self.desc.dmem_phys_base,
221-
// TODO: replace with `align_up` once it lands.
221+
// TODO[NUMM]: replace with `align_up` once it lands.
222222
len: self
223223
.desc
224224
.dmem_load_size

drivers/gpu/nova-core/gfw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn wait_gfw_boot_completion(bar: &Bar0) -> Result {
2929
if gfw_booted {
3030
Some(())
3131
} else {
32-
// TODO: replace with [1] once merged.
32+
// TODO[DLAY]: replace with [1] once it merges.
3333
// [1] https://lore.kernel.org/rust-for-linux/[email protected]/
3434
//
3535
// SAFETY: `msleep()` is safe to call with any parameter.

drivers/gpu/nova-core/gpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ macro_rules! define_chipset {
3737
];
3838
}
3939

40-
// TODO replace with something like derive(FromPrimitive)
40+
// TODO[FPRI]: replace with something like derive(FromPrimitive)
4141
impl TryFrom<u32> for Chipset {
4242
type Error = kernel::error::Error;
4343

drivers/gpu/nova-core/regs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl NV_PMC_BOOT_0 {
4444

4545
/* PBUS */
4646

47-
// TODO: this is an array of registers.
47+
// TODO[REGA]: this is an array of registers.
4848
register!(NV_PBUS_SW_SCRATCH_0E@0x00001438 {
4949
31:16 frts_err_code as u16;
5050
});
@@ -110,7 +110,7 @@ register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128 {
110110
0:0 read_protection_level0 as bool, "Set after FWSEC lowers its protection level";
111111
});
112112

113-
// TODO: This is an array of registers.
113+
// TODO[REGA]: This is an array of registers.
114114
register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05 @ 0x00118234 {
115115
31:0 value as u32;
116116
});
@@ -272,7 +272,7 @@ register!(NV_PFALCON_FALCON_ENGINE @ +0x000003c0 {
272272
0:0 reset as bool;
273273
});
274274

275-
// TODO: this is an array of registers.
275+
// TODO[REGA]: this is an array of registers.
276276
register!(NV_PFALCON_FBIF_TRANSCFG @ +0x00000600 {
277277
1:0 target as u8 ?=> FalconFbifTarget;
278278
2:2 mem_type as bool => FalconFbifMemType;
@@ -294,7 +294,7 @@ register!(NV_PFALCON2_FALCON_BROM_ENGIDMASK @ +0x0000119c {
294294
31:0 value as u32;
295295
});
296296

297-
// TODO: this is an array of registers.
297+
// TODO[REGA]: this is an array of registers.
298298
register!(NV_PFALCON2_FALCON_BROM_PARAADDR @ +0x00001210 {
299299
31:0 value as u32;
300300
});

0 commit comments

Comments
 (0)