Skip to content

Commit 8021393

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: compute layout of the FRTS region
FWSEC-FRTS is run with the desired address of the FRTS region as parameter, which we need to compute depending on some hardware parameters. Do this in a `FbLayout` structure, that will be later extended to describe more memory regions used to boot the GSP. Reviewed-by: Lyude Paul <[email protected]> Signed-off-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ In doc-comment of FbLayout s/bootup process/boot process/ - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 47c4846 commit 8021393

File tree

7 files changed

+224
-2
lines changed

7 files changed

+224
-2
lines changed

drivers/gpu/nova-core/fb.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
use core::ops::Range;
4+
35
use kernel::prelude::*;
6+
use kernel::sizes::*;
47
use kernel::types::ARef;
58
use kernel::{dev_warn, device};
69

710
use crate::dma::DmaObject;
811
use crate::driver::Bar0;
912
use crate::gpu::Chipset;
13+
use crate::regs;
1014

1115
mod hal;
1216

@@ -65,3 +69,69 @@ impl SysmemFlush {
6569
}
6670
}
6771
}
72+
73+
/// Layout of the GPU framebuffer memory.
74+
///
75+
/// Contains ranges of GPU memory reserved for a given purpose during the GSP boot process.
76+
#[derive(Debug)]
77+
#[expect(dead_code)]
78+
pub(crate) struct FbLayout {
79+
pub(crate) fb: Range<u64>,
80+
pub(crate) vga_workspace: Range<u64>,
81+
pub(crate) frts: Range<u64>,
82+
}
83+
84+
impl FbLayout {
85+
/// Computes the FB layout.
86+
pub(crate) fn new(chipset: Chipset, bar: &Bar0) -> Result<Self> {
87+
let hal = hal::fb_hal(chipset);
88+
89+
let fb = {
90+
let fb_size = hal.vidmem_size(bar);
91+
92+
0..fb_size
93+
};
94+
95+
let vga_workspace = {
96+
let vga_base = {
97+
const NV_PRAMIN_SIZE: u64 = SZ_1M as u64;
98+
let base = fb.end - NV_PRAMIN_SIZE;
99+
100+
if hal.supports_display(bar) {
101+
match regs::NV_PDISP_VGA_WORKSPACE_BASE::read(bar).vga_workspace_addr() {
102+
Some(addr) => {
103+
if addr < base {
104+
const VBIOS_WORKSPACE_SIZE: u64 = SZ_128K as u64;
105+
106+
// Point workspace address to end of framebuffer.
107+
fb.end - VBIOS_WORKSPACE_SIZE
108+
} else {
109+
addr
110+
}
111+
}
112+
None => base,
113+
}
114+
} else {
115+
base
116+
}
117+
};
118+
119+
vga_base..fb.end
120+
};
121+
122+
let frts = {
123+
const FRTS_DOWN_ALIGN: u64 = SZ_128K as u64;
124+
const FRTS_SIZE: u64 = SZ_1M as u64;
125+
// TODO: replace with `align_down` once it lands.
126+
let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN - 1)) - FRTS_SIZE;
127+
128+
frts_base..frts_base + FRTS_SIZE
129+
};
130+
131+
Ok(Self {
132+
fb,
133+
vga_workspace,
134+
frts,
135+
})
136+
}
137+
}

drivers/gpu/nova-core/fb/hal.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::driver::Bar0;
66
use crate::gpu::Chipset;
77

88
mod ga100;
9+
mod ga102;
910
mod tu102;
1011

1112
pub(crate) trait FbHal {
@@ -16,6 +17,12 @@ pub(crate) trait FbHal {
1617
///
1718
/// This might fail if the address is too large for the receiving register.
1819
fn write_sysmem_flush_page(&self, bar: &Bar0, addr: u64) -> Result;
20+
21+
/// Returns `true` is display is supported.
22+
fn supports_display(&self, bar: &Bar0) -> bool;
23+
24+
/// Returns the VRAM size, in bytes.
25+
fn vidmem_size(&self, bar: &Bar0) -> u64;
1926
}
2027

2128
/// Returns the HAL corresponding to `chipset`.
@@ -24,8 +31,9 @@ pub(super) fn fb_hal(chipset: Chipset) -> &'static dyn FbHal {
2431

2532
match chipset {
2633
TU102 | TU104 | TU106 | TU117 | TU116 => tu102::TU102_HAL,
27-
GA100 | GA102 | GA103 | GA104 | GA106 | GA107 | AD102 | AD103 | AD104 | AD106 | AD107 => {
28-
ga100::GA100_HAL
34+
GA100 => ga100::GA100_HAL,
35+
GA102 | GA103 | GA104 | GA106 | GA107 | AD102 | AD103 | AD104 | AD106 | AD107 => {
36+
ga102::GA102_HAL
2937
}
3038
}
3139
}

drivers/gpu/nova-core/fb/hal/ga100.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub(super) fn write_sysmem_flush_page_ga100(bar: &Bar0, addr: u64) {
2525
.write(bar);
2626
}
2727

28+
pub(super) fn display_enabled_ga100(bar: &Bar0) -> bool {
29+
!regs::ga100::NV_FUSE_STATUS_OPT_DISPLAY::read(bar).display_disabled()
30+
}
31+
2832
/// Shift applied to the sysmem address before it is written into
2933
/// `NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI`,
3034
const FLUSH_SYSMEM_ADDR_SHIFT_HI: u32 = 40;
@@ -39,6 +43,14 @@ impl FbHal for Ga100 {
3943

4044
Ok(())
4145
}
46+
47+
fn supports_display(&self, bar: &Bar0) -> bool {
48+
display_enabled_ga100(bar)
49+
}
50+
51+
fn vidmem_size(&self, bar: &Bar0) -> u64 {
52+
super::tu102::vidmem_size_gp102(bar)
53+
}
4254
}
4355

4456
const GA100: Ga100 = Ga100;

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
use kernel::prelude::*;
4+
5+
use crate::driver::Bar0;
6+
use crate::fb::hal::FbHal;
7+
use crate::regs;
8+
9+
fn vidmem_size_ga102(bar: &Bar0) -> u64 {
10+
regs::NV_USABLE_FB_SIZE_IN_MB::read(bar).usable_fb_size()
11+
}
12+
13+
struct Ga102;
14+
15+
impl FbHal for Ga102 {
16+
fn read_sysmem_flush_page(&self, bar: &Bar0) -> u64 {
17+
super::ga100::read_sysmem_flush_page_ga100(bar)
18+
}
19+
20+
fn write_sysmem_flush_page(&self, bar: &Bar0, addr: u64) -> Result {
21+
super::ga100::write_sysmem_flush_page_ga100(bar, addr);
22+
23+
Ok(())
24+
}
25+
26+
fn supports_display(&self, bar: &Bar0) -> bool {
27+
super::ga100::display_enabled_ga100(bar)
28+
}
29+
30+
fn vidmem_size(&self, bar: &Bar0) -> u64 {
31+
vidmem_size_ga102(bar)
32+
}
33+
}
34+
35+
const GA102: Ga102 = Ga102;
36+
pub(super) const GA102_HAL: &dyn FbHal = &GA102;

drivers/gpu/nova-core/fb/hal/tu102.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ pub(super) fn write_sysmem_flush_page_gm107(bar: &Bar0, addr: u64) -> Result {
2626
}
2727
}
2828

29+
pub(super) fn display_enabled_gm107(bar: &Bar0) -> bool {
30+
!regs::gm107::NV_FUSE_STATUS_OPT_DISPLAY::read(bar).display_disabled()
31+
}
32+
33+
pub(super) fn vidmem_size_gp102(bar: &Bar0) -> u64 {
34+
regs::NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE::read(bar).usable_fb_size()
35+
}
36+
2937
struct Tu102;
3038

3139
impl FbHal for Tu102 {
@@ -36,6 +44,14 @@ impl FbHal for Tu102 {
3644
fn write_sysmem_flush_page(&self, bar: &Bar0, addr: u64) -> Result {
3745
write_sysmem_flush_page_gm107(bar, addr)
3846
}
47+
48+
fn supports_display(&self, bar: &Bar0) -> bool {
49+
display_enabled_gm107(bar)
50+
}
51+
52+
fn vidmem_size(&self, bar: &Bar0) -> u64 {
53+
vidmem_size_gp102(bar)
54+
}
3955
}
4056

4157
const TU102: Tu102 = Tu102;

drivers/gpu/nova-core/gpu.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use kernel::{device, devres::Devres, error::code::*, pci, prelude::*};
44

55
use crate::driver::Bar0;
66
use crate::falcon::{gsp::Gsp, sec2::Sec2, Falcon};
7+
use crate::fb::FbLayout;
78
use crate::fb::SysmemFlush;
89
use crate::firmware::{Firmware, FIRMWARE_VERSION};
910
use crate::gfw;
@@ -215,6 +216,9 @@ impl Gpu {
215216

216217
let _sec2_falcon = Falcon::<Sec2>::new(pdev.as_ref(), spec.chipset, bar, true)?;
217218

219+
let fb_layout = FbLayout::new(spec.chipset, bar)?;
220+
dev_dbg!(pdev.as_ref(), "{:#x?}\n", fb_layout);
221+
218222
// Will be used in a later patch when fwsec firmware is needed.
219223
let _bios = Vbios::new(pdev, bar)?;
220224

drivers/gpu/nova-core/regs.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ register!(NV_PFB_NISO_FLUSH_SYSMEM_ADDR_HI @ 0x00100c40 {
5252
23:0 adr_63_40 as u32;
5353
});
5454

55+
register!(NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE @ 0x00100ce0 {
56+
3:0 lower_scale as u8;
57+
9:4 lower_mag as u8;
58+
30:30 ecc_mode_enabled as bool;
59+
});
60+
61+
impl NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE {
62+
/// Returns the usable framebuffer size, in bytes.
63+
pub(crate) fn usable_fb_size(self) -> u64 {
64+
let size = ((self.lower_mag() as u64) << (self.lower_scale() as u64))
65+
* kernel::sizes::SZ_1M as u64;
66+
67+
if self.ecc_mode_enabled() {
68+
// Remove the amount of memory reserved for ECC (one per 16 units).
69+
size / 16 * 15
70+
} else {
71+
size
72+
}
73+
}
74+
}
75+
5576
/* PGC6 */
5677

5778
register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @ 0x00118128 {
@@ -77,6 +98,42 @@ impl NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT {
7798
}
7899
}
79100

101+
register!(NV_PGC6_AON_SECURE_SCRATCH_GROUP_42 @ 0x001183a4 {
102+
31:0 value as u32;
103+
});
104+
105+
register!(
106+
NV_USABLE_FB_SIZE_IN_MB => NV_PGC6_AON_SECURE_SCRATCH_GROUP_42,
107+
"Scratch group 42 register used as framebuffer size" {
108+
31:0 value as u32, "Usable framebuffer size, in megabytes";
109+
}
110+
);
111+
112+
impl NV_USABLE_FB_SIZE_IN_MB {
113+
/// Returns the usable framebuffer size, in bytes.
114+
pub(crate) fn usable_fb_size(self) -> u64 {
115+
u64::from(self.value()) * kernel::sizes::SZ_1M as u64
116+
}
117+
}
118+
119+
/* PDISP */
120+
121+
register!(NV_PDISP_VGA_WORKSPACE_BASE @ 0x00625f04 {
122+
3:3 status_valid as bool, "Set if the `addr` field is valid";
123+
31:8 addr as u32, "VGA workspace base address divided by 0x10000";
124+
});
125+
126+
impl NV_PDISP_VGA_WORKSPACE_BASE {
127+
/// Returns the base address of the VGA workspace, or `None` if none exists.
128+
pub(crate) fn vga_workspace_addr(self) -> Option<u64> {
129+
if self.status_valid() {
130+
Some((self.addr() as u64) << 16)
131+
} else {
132+
None
133+
}
134+
}
135+
}
136+
80137
/* FUSE */
81138

82139
register!(NV_FUSE_OPT_FPF_NVDEC_UCODE1_VERSION @ 0x00824100 {
@@ -218,3 +275,22 @@ register!(NV_PRISCV_RISCV_BCR_CTRL @ +0x00001668 {
218275
4:4 core_select as bool => PeregrineCoreSelect;
219276
8:8 br_fetch as bool;
220277
});
278+
279+
// The modules below provide registers that are not identical on all supported chips. They should
280+
// only be used in HAL modules.
281+
282+
pub(crate) mod gm107 {
283+
/* FUSE */
284+
285+
register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00021c04 {
286+
0:0 display_disabled as bool;
287+
});
288+
}
289+
290+
pub(crate) mod ga100 {
291+
/* FUSE */
292+
293+
register!(NV_FUSE_STATUS_OPT_DISPLAY @ 0x00820c04 {
294+
0:0 display_disabled as bool;
295+
});
296+
}

0 commit comments

Comments
 (0)