From: Joel Fernandes <joelagnelf@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"John Hubbard" <jhubbard@nvidia.com>,
"Ben Skeggs" <bskeggs@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 13/16] gpu: nova-core: Add support for VBIOS ucode extraction for boot
Date: Thu, 24 Apr 2025 15:54:48 -0400 [thread overview]
Message-ID: <20250424195448.GA182914@joelnvbox> (raw)
In-Reply-To: <aAkBIvfTkKVNbdnm@pollux>
On Wed, Apr 23, 2025 at 05:02:58PM +0200, Danilo Krummrich wrote:
> On Wed, Apr 23, 2025 at 10:52:42AM -0400, Joel Fernandes wrote:
> > Hello, Danilo,
> > Thanks for all the feedback. Due to the volume of feedback, I will respond
> > incrementally in multiple emails so we can discuss as we go - hope that's Ok but
> > let me know if that is annoying.
>
> That's perfectly fine, whatever works best for you. :)
>
> > On 4/23/2025 10:06 AM, Danilo Krummrich wrote:
> >
> > >> +impl Vbios {
> > >> + /// Read bytes from the ROM at the current end of the data vector
> > >> + fn read_more(bar0: &Devres<Bar0>, data: &mut KVec<u8>, len: usize) -> Result {
> > >> + let current_len = data.len();
> > >> + let start = ROM_OFFSET + current_len;
> > >> +
> > >> + // Ensure length is a multiple of 4 for 32-bit reads
> > >> + if len % core::mem::size_of::<u32>() != 0 {
> > >> + pr_err!("VBIOS read length {} is not a multiple of 4\n", len);
> > >
> > > Please don't use any of the pr_*() print macros within a driver, use the dev_*()
> > > ones instead.
> >
> > Ok I'll switch to this. One slight complication is I've to retrieve the 'dev'
> > from the Bar0 and pass that along, but that should be doable.
>
> You can also pass the pci::Device reference to VBios::probe() directly.
This turns out to be rather difficult to do in the whole vbios.rs because
we'd have to them propogate pdev to various class methods which may print
errors (some of which don't make sense to pass pdev to, like try_from()). But
I can do it in probe() (or new() as we call it now). See below for preview
diff doing this for many prints where possible, does this work for you?
Preview diff (give or take rustfmt):
---8<-----------------------
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 43cf34a078ae..808e8446ac79 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -236,7 +236,7 @@ pub(crate) fn new(
falcon: &Falcon<Gsp>,
pdev: &Device,
bar: &Devres<Bar0>,
- bios: &Vbios,
+ bios: &Vbios<'_>,
cmd: FwsecCommand,
) -> Result<Self> {
let v3_desc = bios.fwsec_header()?;
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 0069d6ec8751..aa301e2a7111 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -259,7 +259,7 @@ pub(crate) fn new(pdev: &pci::Device, bar: Devres<Bar0>) -> Result<impl PinInit<
let fb_layout = FbLayout::new(spec.chipset, &bar, &fw.bootloader)?;
pr_info!("{:#x?}\n", fb_layout);
- let bios = Vbios::new(&bar)?;
+ let bios = Vbios::new(pdev, &bar)?;
// TODO: should we write 0x0 back when we drop this object?
let sysmem_flush = DmaObject::new(pdev.as_ref(), 0x1000, "sysmem flush page")?;
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index f0c43a5143d0..c5a8333f00b2 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -8,6 +8,7 @@
use kernel::devres::Devres;
use kernel::error::Result;
use kernel::prelude::*;
+use kernel::pci;
/// The offset of the VBIOS ROM in the BAR0 space.
const ROM_OFFSET: usize = 0x300000;
@@ -24,7 +25,8 @@
const FALCON_UCODE_ENTRY_APPID_FWSEC_DBG: u8 = 0x45;
const FALCON_UCODE_ENTRY_APPID_FWSEC_PROD: u8 = 0x85;
-pub(crate) struct Vbios {
+pub(crate) struct Vbios<'a> {
+ pdev: &'a pci::Device,
pub fwsec_image: Option<FwSecBiosImage>,
// VBIOS data vector: As BIOS images are scanned, they are added to this vector
// for reference or copying into other data structures. It is the entire
@@ -35,7 +37,7 @@ pub(crate) struct Vbios {
data: Option<KVec<u8>>,
}
-impl Vbios {
+impl Vbios<'_> {
/// Read bytes from the ROM at the current end of the data vector
fn read_more(&mut self, bar0: &Devres<Bar0>, len: usize) -> Result {
let data = self.data.as_mut().ok_or(EINVAL)?;
@@ -44,7 +46,7 @@ fn read_more(&mut self, bar0: &Devres<Bar0>, len: usize) -> Result {
// Ensure length is a multiple of 4 for 32-bit reads
if len % core::mem::size_of::<u32>() != 0 {
- pr_err!("VBIOS read length {} is not a multiple of 4\n", len);
+ dev_err!(self.pdev.as_ref(), "VBIOS read length {} is not a multiple of 4\n", len);
return Err(EINVAL);
}
@@ -73,7 +75,7 @@ fn read_more_at_offset(
len: usize,
) -> Result {
if offset > BIOS_MAX_SCAN_LEN {
- pr_err!("Error: exceeded BIOS scan limit.\n");
+ dev_err!(self.pdev.as_ref(), "Error: exceeded BIOS scan limit.\n");
return Err(EINVAL);
}
@@ -101,13 +103,14 @@ fn read_bios_image_at_offset(
let data_len = self.data.as_ref().ok_or(EINVAL)?.len();
if offset + len > data_len {
self.read_more_at_offset(bar0, offset, len).inspect_err(|e| {
- pr_err!("Failed to read more at offset {:#x}: {:?}\n", offset, e)
+ dev_err!(self.pdev.as_ref(), "Failed to read more at offset {:#x}: {:?}\n", offset, e)
})?;
}
let data = self.data.as_ref().ok_or(EINVAL)?;
BiosImage::try_from(&data[offset..offset + len]).inspect_err(|e| {
- pr_err!(
+ dev_err!(
+ self.pdev.as_ref(),
"Failed to create BiosImage at offset {:#x}: {:?}\n",
offset,
e
@@ -117,8 +120,9 @@ fn read_bios_image_at_offset(
/// Probe for VBIOS extraction
/// Once the VBIOS object is built, bar0 is not read for vbios purposes anymore.
- pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
+ pub(crate) fn new(pdev: &pci::Device, bar0: &Devres<Bar0>) -> Result<Self> {
let mut vbios = Self {
+ pdev,
fwsec_image: None,
data: Some(KVec::new()),
};
@@ -137,7 +141,8 @@ pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
vbios.read_bios_image_at_offset(bar0, cur_offset, BIOS_READ_AHEAD_SIZE)
.and_then(|image| image.image_size_bytes())
.inspect_err(|e| {
- pr_err!(
+ dev_err!(
+ vbios.pdev.as_ref(),
"Failed to parse initial BIOS image headers at offset {:#x}: {:?}\n",
cur_offset,
e
@@ -148,7 +153,8 @@ pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
let full_image =
vbios.read_bios_image_at_offset(bar0, cur_offset, image_size)
.inspect_err(|e| {
- pr_err!(
+ dev_err!(
+ vbios.pdev.as_ref(),
"Failed to parse full BIOS image at offset {:#x}: {:?}\n",
cur_offset,
e
@@ -158,7 +164,8 @@ pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
// Determine the image type
let image_type = full_image.image_type_str();
- pr_info!(
+ dev_info!(
+ vbios.pdev.as_ref(),
"Found BIOS image at offset {:#x}, size: {:#x}, type: {}\n",
cur_offset,
image_size,
@@ -195,7 +202,7 @@ pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
// Safety check - don't go beyond BIOS_MAX_SCAN_LEN (1MB)
if cur_offset > BIOS_MAX_SCAN_LEN {
- pr_err!("Error: exceeded BIOS scan limit, stopping scan\n");
+ dev_err!(vbios.pdev.as_ref(), "Error: exceeded BIOS scan limit, stopping scan\n");
break;
}
} // end of loop
@@ -212,9 +219,9 @@ pub(crate) fn new(bar0: &Devres<Bar0>) -> Result<Self> {
{
second
.setup_falcon_data(pci_at, first)
- .inspect_err(|e| pr_err!("Falcon data setup failed: {:?}\n", e))?;
+ .inspect_err(|e| dev_err!(vbios.pdev.as_ref(), "Falcon data setup failed: {:?}\n", e))?;
} else {
- pr_err!("Missing required images for falcon data setup, skipping\n");
+ dev_err!(vbios.pdev.as_ref(), "Missing required images for falcon data setup, skipping\n");
}
second // Return the potentially modified second image
};
next prev parent reply other threads:[~2025-04-24 19:54 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-20 12:19 [PATCH 00/16] nova-core: run FWSEC-FRTS to perform first stage of GSP initialization Alexandre Courbot
2025-04-20 12:19 ` [PATCH 01/16] rust: add useful ops for u64 Alexandre Courbot
2025-04-20 12:19 ` [PATCH 02/16] rust: make ETIMEDOUT error available Alexandre Courbot
2025-04-20 12:19 ` [PATCH 03/16] gpu: nova-core: derive useful traits for Chipset Alexandre Courbot
2025-04-22 16:23 ` Joel Fernandes
2025-04-24 7:50 ` Alexandre Courbot
2025-04-20 12:19 ` [PATCH 04/16] gpu: nova-core: add missing GA100 definition Alexandre Courbot
2025-04-20 12:19 ` [PATCH 05/16] gpu: nova-core: take bound device in Gpu::new Alexandre Courbot
2025-04-20 12:19 ` [PATCH 06/16] gpu: nova-core: define registers layout using helper macro Alexandre Courbot
2025-04-22 10:29 ` Danilo Krummrich
2025-04-28 14:27 ` Alexandre Courbot
2025-04-20 12:19 ` [PATCH 07/16] gpu: nova-core: move Firmware to firmware module Alexandre Courbot
2025-04-20 12:19 ` [PATCH 08/16] gpu: nova-core: wait for GFW_BOOT completion Alexandre Courbot
2025-04-21 21:45 ` Joel Fernandes
2025-04-22 11:28 ` Danilo Krummrich
2025-04-22 13:06 ` Alexandre Courbot
2025-04-22 13:46 ` Joel Fernandes
2025-04-22 11:36 ` Danilo Krummrich
2025-04-29 12:48 ` Alexandre Courbot
2025-04-30 22:45 ` Joel Fernandes
2025-04-20 12:19 ` [PATCH 09/16] gpu: nova-core: register sysmem flush page Alexandre Courbot
2025-04-22 11:45 ` Danilo Krummrich
2025-04-23 13:03 ` Alexandre Courbot
2025-04-22 18:50 ` Joel Fernandes
2025-04-20 12:19 ` [PATCH 10/16] gpu: nova-core: add basic timer device Alexandre Courbot
2025-04-22 12:07 ` Danilo Krummrich
2025-04-29 13:13 ` Alexandre Courbot
2025-04-20 12:19 ` [PATCH 11/16] gpu: nova-core: add falcon register definitions and base code Alexandre Courbot
2025-04-22 14:44 ` Danilo Krummrich
2025-04-30 6:58 ` Joel Fernandes
2025-04-30 10:32 ` Danilo Krummrich
2025-04-30 13:25 ` Alexandre Courbot
2025-04-30 14:38 ` Joel Fernandes
2025-04-30 18:16 ` Danilo Krummrich
2025-04-30 23:08 ` Joel Fernandes
2025-05-01 0:09 ` Alexandre Courbot
2025-05-01 0:22 ` Joel Fernandes
2025-05-01 14:07 ` Alexandre Courbot
2025-04-20 12:19 ` [PATCH 12/16] gpu: nova-core: firmware: add ucode descriptor used by FWSEC-FRTS Alexandre Courbot
2025-04-22 14:46 ` Danilo Krummrich
2025-04-20 12:19 ` [PATCH 13/16] gpu: nova-core: Add support for VBIOS ucode extraction for boot Alexandre Courbot
2025-04-23 14:06 ` Danilo Krummrich
2025-04-23 14:52 ` Joel Fernandes
2025-04-23 15:02 ` Danilo Krummrich
2025-04-24 19:19 ` Joel Fernandes
2025-04-24 20:01 ` Danilo Krummrich
2025-04-24 19:54 ` Joel Fernandes [this message]
2025-04-24 20:17 ` Danilo Krummrich
2025-04-25 2:32 ` [13/16] " Joel Fernandes
2025-04-25 17:10 ` Joel Fernandes
2025-04-24 18:54 ` [PATCH 13/16] " Joel Fernandes
2025-04-24 20:08 ` Danilo Krummrich
2025-04-25 2:26 ` [13/16] " Joel Fernandes
2025-04-24 20:22 ` [PATCH 13/16] " Joel Fernandes
2025-04-26 23:17 ` [13/16] " Joel Fernandes
2025-04-20 12:19 ` [PATCH 14/16] gpu: nova-core: compute layout of the FRTS region Alexandre Courbot
2025-04-20 12:19 ` [PATCH 15/16] gpu: nova-core: extract FWSEC from BIOS and patch it to run FWSEC-FRTS Alexandre Courbot
2025-04-20 12:19 ` [PATCH 16/16] gpu: nova-core: load and " Alexandre Courbot
2025-04-22 8:40 ` [PATCH 00/16] nova-core: run FWSEC-FRTS to perform first stage of GSP initialization Danilo Krummrich
2025-04-22 14:12 ` Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250424195448.GA182914@joelnvbox \
--to=joelagnelf@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=bskeggs@nvidia.com \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox