mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 09:41:03 +02:00
gpu: nova-core: convert to kernel bitfield macro
Replace uses of the Nova-local `bitfield!` macro with the kernel one. Reviewed-by: Eliot Courtney <ecourtney@nvidia.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260701-nova-bitfield-v2-1-2e949bf1836c@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
parent
24d2581fd9
commit
064375c89b
|
|
@ -11,6 +11,7 @@
|
|||
device,
|
||||
dma::Coherent,
|
||||
io::poll::read_poll_timeout,
|
||||
num::TryIntoBounded,
|
||||
prelude::*,
|
||||
ptr::{
|
||||
Alignable,
|
||||
|
|
@ -300,7 +301,7 @@ fn send_sync_fsp<M>(&mut self, dev: &device::Device, msg: &M) -> Result<KVec<u8>
|
|||
return Err(EIO);
|
||||
}
|
||||
|
||||
if command_nvdm_type != u8::from(M::NVDM_TYPE).into() {
|
||||
if command_nvdm_type.try_into_bounded() != Some(M::NVDM_TYPE.into()) {
|
||||
dev_err!(
|
||||
dev,
|
||||
"Expected NVDM type {:?} in reply, got {:#x}\n",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
use core::ops::Range;
|
||||
|
||||
use kernel::{
|
||||
bitfield,
|
||||
dma::Coherent,
|
||||
prelude::*,
|
||||
ptr::{
|
||||
|
|
@ -740,8 +741,8 @@ unsafe impl AsBytes for MsgqRxHeader {}
|
|||
|
||||
bitfield! {
|
||||
struct MsgHeaderVersion(u32) {
|
||||
31:24 major as u8;
|
||||
23:16 minor as u8;
|
||||
31:24 major;
|
||||
23:16 minor;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -750,9 +751,9 @@ impl MsgHeaderVersion {
|
|||
const MINOR_TOT: u8 = 0;
|
||||
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
.set_major(Self::MAJOR_TOT)
|
||||
.set_minor(Self::MINOR_TOT)
|
||||
Self::zeroed()
|
||||
.with_major(Self::MAJOR_TOT)
|
||||
.with_minor(Self::MINOR_TOT)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,55 +7,51 @@
|
|||
//! Data Model) messages between the kernel driver and GPU firmware processors
|
||||
//! such as FSP and GSP.
|
||||
|
||||
use kernel::pci::Vendor;
|
||||
use kernel::{
|
||||
bitfield,
|
||||
pci::Vendor,
|
||||
prelude::*, //
|
||||
};
|
||||
|
||||
/// NVDM message type identifiers carried over MCTP.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub(crate) enum NvdmType {
|
||||
#[default]
|
||||
/// Chain of Trust boot message.
|
||||
Cot = 0x14,
|
||||
/// FSP command response.
|
||||
FspResponse = 0x15,
|
||||
}
|
||||
use crate::{
|
||||
bounded_enum,
|
||||
num, //
|
||||
};
|
||||
|
||||
impl TryFrom<u8> for NvdmType {
|
||||
type Error = u8;
|
||||
|
||||
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
x if x == u8::from(Self::Cot) => Ok(Self::Cot),
|
||||
x if x == u8::from(Self::FspResponse) => Ok(Self::FspResponse),
|
||||
_ => Err(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NvdmType> for u8 {
|
||||
fn from(value: NvdmType) -> Self {
|
||||
value as u8
|
||||
bounded_enum! {
|
||||
/// NVDM message type identifiers carried over MCTP.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum NvdmType with TryFrom<Bounded<u32, 8>> {
|
||||
/// Chain of Trust boot message.
|
||||
Cot = 0x14,
|
||||
/// FSP command response.
|
||||
FspResponse = 0x15,
|
||||
}
|
||||
}
|
||||
|
||||
bitfield! {
|
||||
pub(crate) struct MctpHeader(u32), "MCTP transport header for NVIDIA firmware messages." {
|
||||
31:31 som as bool, "Start-of-message bit.";
|
||||
30:30 eom as bool, "End-of-message bit.";
|
||||
29:28 seq as u8, "Packet sequence number.";
|
||||
23:16 seid as u8, "Source endpoint ID.";
|
||||
/// MCTP transport header for NVIDIA firmware messages.
|
||||
pub(crate) struct MctpHeader(u32) {
|
||||
/// Start-of-message bit.
|
||||
31:31 som;
|
||||
/// End-of-message bit.
|
||||
30:30 eom;
|
||||
/// Packet sequence number.
|
||||
29:28 seq;
|
||||
/// Source endpoint ID.
|
||||
23:16 seid;
|
||||
}
|
||||
}
|
||||
|
||||
impl MctpHeader {
|
||||
/// Builds a single-packet MCTP header (`SOM=1`, `EOM=1`, `SEQ=0`, `SEID=0`).
|
||||
pub(crate) fn single_packet() -> Self {
|
||||
Self::default().set_som(true).set_eom(true)
|
||||
Self::zeroed().with_som(true).with_eom(true)
|
||||
}
|
||||
|
||||
/// Returns whether this is a complete single-packet message (`SOM=1` and `EOM=1`).
|
||||
pub(crate) fn is_single_packet(self) -> bool {
|
||||
self.som() && self.eom()
|
||||
self.som().into_bool() && self.eom().into_bool()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,26 +59,30 @@ pub(crate) fn is_single_packet(self) -> bool {
|
|||
const MSG_TYPE_VENDOR_PCI: u8 = 0x7e;
|
||||
|
||||
bitfield! {
|
||||
pub(crate) struct NvdmHeader(u32), "NVIDIA Vendor-Defined Message header over MCTP." {
|
||||
31:24 nvdm_type as u8 ?=> NvdmType, "NVDM message type.";
|
||||
23:8 vendor_id as u16, "PCI vendor ID.";
|
||||
6:0 msg_type as u8, "MCTP vendor-defined message type.";
|
||||
/// NVIDIA Vendor-Defined Message header over MCTP.
|
||||
pub(crate) struct NvdmHeader(u32) {
|
||||
/// NVDM message type.
|
||||
31:24 nvdm_type ?=> NvdmType;
|
||||
/// PCI vendor ID.
|
||||
23:8 vendor_id;
|
||||
/// MCTP vendor-defined message type.
|
||||
6:0 msg_type;
|
||||
}
|
||||
}
|
||||
|
||||
impl NvdmHeader {
|
||||
/// Builds an NVDM header for the given message type.
|
||||
pub(crate) fn new(nvdm_type: NvdmType) -> Self {
|
||||
Self::default()
|
||||
.set_msg_type(MSG_TYPE_VENDOR_PCI)
|
||||
.set_vendor_id(Vendor::NVIDIA.as_raw())
|
||||
.set_nvdm_type(nvdm_type)
|
||||
Self::zeroed()
|
||||
.with_const_msg_type::<{ num::u8_as_u32(MSG_TYPE_VENDOR_PCI) }>()
|
||||
.with_vendor_id(Vendor::NVIDIA.as_raw())
|
||||
.with_nvdm_type(nvdm_type)
|
||||
}
|
||||
|
||||
/// Validates this header against the expected NVIDIA NVDM format and type.
|
||||
pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
|
||||
self.msg_type() == MSG_TYPE_VENDOR_PCI
|
||||
&& self.vendor_id() == Vendor::NVIDIA.as_raw()
|
||||
u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
|
||||
&& u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
|
||||
&& matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@
|
|||
InPlaceModule, //
|
||||
};
|
||||
|
||||
#[macro_use]
|
||||
mod bitfield;
|
||||
|
||||
mod driver;
|
||||
mod falcon;
|
||||
mod fb;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user