mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: "airlied@gmail.com" <airlied@gmail.com>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"ajanulgu@redhat.com" <ajanulgu@redhat.com>,
	"lyude@redhat.com" <lyude@redhat.com>,
	"pstanner@redhat.com" <pstanner@redhat.com>,
	"Zhi Wang" <zhiw@nvidia.com>, "Neo Jia" <cjia@nvidia.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Ben Skeggs" <bskeggs@nvidia.com>,
	"Andy Currid" <ACurrid@nvidia.com>,
	"ojeda@kernel.org" <ojeda@kernel.org>,
	"alex.gaynor@gmail.com" <alex.gaynor@gmail.com>,
	"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
	"gary@garyguo.net" <gary@garyguo.net>,
	"bjorn3_gh@protonmail.com" <bjorn3_gh@protonmail.com>,
	"benno.lossin@proton.me" <benno.lossin@proton.me>,
	"a.hindborg@kernel.org" <a.hindborg@kernel.org>,
	"aliceryhl@google.com" <aliceryhl@google.com>,
	"tmgross@umich.edu" <tmgross@umich.edu>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"nouveau@lists.freedesktop.org" <nouveau@lists.freedesktop.org>,
	"rust-for-linux@vger.kernel.org" <rust-for-linux@vger.kernel.org>,
	"Nouveau" <nouveau-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v2 1/2] gpu: nova-core: add initial driver stub
Date: Fri, 07 Feb 2025 10:41:37 +0900	[thread overview]
Message-ID: <D7LTY1FIUOTR.3E6MZ8BD0HW7E@nvidia.com> (raw)
In-Reply-To: <Z6TL5a5SCZoVq8Zt@cassiopeiae>

Hi Danilo,

On Thu Feb 6, 2025 at 11:49 PM JST, Danilo Krummrich wrote:
>> > +impl Spec {
>> > +    fn new(bar: &Devres<Bar0>) -> Result<Spec> {
>> > +        let bar = bar.try_access().ok_or(ENXIO)?;
>> > +        let boot0 = regs::Boot0::read(&bar);
>> > +
>> > +        let Some(chipset) = Chipset::from_u32(boot0.chipset()) else {
>> > +            return Err(ENODEV);
>> > +        };
>> > +
>> > +        let Some(arch) = Architecture::from_u32(boot0.arch()) else {
>> > +            return Err(ENODEV);
>> > +        };
>>
>> Technically the Architecture is already known if the Chipset has been
>> built successfully, so there should be no need to build it again (and
>> test for a failure that cannot happen at this point).
>>
>> Since the architecture information is already embedded in Chipset, maybe
>> we can have an arch() method there?
>>
>> Something like:
>>
>>     impl Chipset {
>>         pub(crate) fn arch(self) -> Architecture {
>>             match self as u32 & !0xf {
>>                 0x160 => Architecture::Turing,
>>                 0x170 => Architecture::Ampere,
>>                 0x190 => Architecture::Ada,
>>                 _ => unreachable!(),
>>             }
>>         }
>>     }
>
> I thought about this, which is also why the comment above says: "consider to
> store within Chipset, if arbitrary_enum_discriminant becomes stable".
>
> I did not go with what you suggest because it leaves us with either
> Chipset::arch() returning a Result, which is annoying, or with Chipset::arch()
> being able to panic the kernel, which I'd dislike even more.
>
> There's also a third option, which would be to have some kind of unknown
> architecture, which we could catch later on, but that's just a worse variation
> of returning a Result.
>
> Another reason was that I did not want to encode register specific masks into
> the Chipset type.

Agreed, none of these solutions are completely satisfying. From the
point that we have successfully built a Chipset, we should be able to
get its architecture without any runtime error or failure path. So I
guess this leaves matching all the variants. It's a bit verbose, but
hopefully later we can gather all the static information about chipsets
in a single place, and generate these implementations (including a
Display implementation - ideally the debug one would also print the hex
representation of the chipset to be more useful for troubleshooting)
using macros.

Cheers,
Alex.


      reply	other threads:[~2025-02-07  1:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 19:03 Danilo Krummrich
2025-02-04 19:03 ` [PATCH v2 2/2] gpu: nova-core: add initial documentation Danilo Krummrich
2025-02-05 13:56   ` Zhi Wang
2025-02-05 14:13     ` Miguel Ojeda
2025-02-05 14:56       ` Zhi Wang
2025-02-05 16:20         ` Danilo Krummrich
2025-02-05 16:10     ` Danilo Krummrich
2025-02-05 19:44       ` Zhi Wang
2025-02-09 15:36         ` Danilo Krummrich
2025-02-07  8:23     ` Alexandre Courbot
2025-02-09 15:25       ` Danilo Krummrich
2025-02-06 14:05 ` [PATCH v2 1/2] gpu: nova-core: add initial driver stub Alexandre Courbot
2025-02-06 14:49   ` Danilo Krummrich
2025-02-07  1:41     ` Alexandre Courbot [this message]

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=D7LTY1FIUOTR.3E6MZ8BD0HW7E@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=ACurrid@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=ajanulgu@redhat.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=bskeggs@nvidia.com \
    --cc=cjia@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-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau-bounces@lists.freedesktop.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=pstanner@redhat.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=tzimmermann@suse.de \
    --cc=zhiw@nvidia.com \
    /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

all inboxes | Powered by JetHome®