gpu: nova-core: add fwctl driver
Subsystems (5)
Zhi Wang
maintainercover gpu: nova-core: add fwctl driver
This series adds a fwctl driver to nova-core, enabling userspace to issue firmware commands to the GSP through the standard fwctl ioctl interface. E.g. uploading the vGPU type blobs and managing the vGPU lifecycle, which is previously implemented in sysfs.
Patch 1 fixes a boot-order issue: since Rust fwctl abstractions force fwctl to be built-in (Kconfig bool), the fwctl class must be registered before PCI drivers probe. Switching from module_init to subsys_initcall ensures this.
Patch 2 adds the nova-core fwctl driver itself. It defines a UAPI for nova-core specific RPC commands and wires them through to the GSP via the existing RM control command infrastructure. As a first user, the UPLOAD_VGPU_TYPE command is added, which uploads vGPU type definitions to the GSP. It is a required step before any vGPU can be created.
This patchset depends on several series:
- [PATCH v5 0/9] gpu: nova-core: gsp: add continuation record support [1]
- [PATCH v3 0/5] gpu: nova-core: gsp: add locking to Cmdq [2]
- [PATCH v3 0/1] rust: introduce abstractions for fwctl [3]
And a tree with all the patches can be found here.[4]
[1] https://lore.kernel.org/nouveau/[email protected]/T/#t
[2] https://lore.kernel.org/nouveau/[email protected]/T/#t
[3] https://lore.kernel.org/all/[email protected]/
[4] https://github.com/zhiwang-nvidia/nova-core/tree/nova-core/fwctl-driver-v1
Zhi Wang (2):
fwctl: use subsys_initcall for built-in configuration
gpu: nova-core: add fwctl driver for firmware control interface
drivers/fwctl/main.c | 2 +- drivers/gpu/nova-core/fwctl.rs | 99 +++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 4 +- drivers/gpu/nova-core/gsp.rs | 25 ++++- drivers/gpu/nova-core/gsp/boot.rs | 6 +- .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 1 + drivers/gpu/nova-core/gsp/fw/rm.rs | 5 + drivers/gpu/nova-core/gsp/rm/commands.rs | 4 +- drivers/gpu/nova-core/nova_core.rs | 2 + include/uapi/fwctl/fwctl.h | 1 + include/uapi/fwctl/nova-core.h | 52 ++++++++++ rust/kernel/fwctl.rs | 2 + rust/uapi/uapi_helper.h | 1 + 13 files changed, 194 insertions(+), 10 deletions(-) create mode 100644 drivers/gpu/nova-core/fwctl.rs create mode 100644 include/uapi/fwctl/nova-core.h
Signature · 1 line
2.51.0
Zhi Wang
maintainerPATCH 1/2 fwctl: use subsys_initcall for built-in configuration
Rust does not yet support loadable kernel modules, so RUST_FWCTL_ABSTRACTIONS is a Kconfig bool, which forces fwctl to be built-in. With module_init, fwctl initializes too late and PCI drivers probe before the fwctl class is registered.
Switch to subsys_initcall.
--- drivers/fwctl/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fwctl/main.c +1 -1
@@ -415,7 +415,7 @@ static void __exit fwctl_exit(void)unregister_chrdev_region (fwctl_dev,FWCTL_MAX_DEVICES ); } -module_init (fwctl_init); +subsys_initcall (fwctl_init);module_exit (fwctl_exit);MODULE_DESCRIPTION ("fwctl device firmware access framework" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.51.0
Zhi Wang
maintainerPATCH 2/2 gpu: nova-core: add fwctl driver for firmware control interface
In reply to Zhi WangAdd a fwctl driver that provides an infrastructure for userspace to issue firmware commands to the GSP. New commands can be added by extending RmControlMsgFunction and the fwctl command dispatch table.
As a first user, add FWCTL_CMD_NOVA_CORE_UPLOAD_VGPU_TYPE, which uploads vGPU type definitions to the GSP. It is a required step before any vGPU can be created.
--- drivers/gpu/nova-core/fwctl.rs | 99 +++++++++++++++++++ drivers/gpu/nova-core/gpu.rs | 4 +- drivers/gpu/nova-core/gsp.rs | 25 ++++- drivers/gpu/nova-core/gsp/boot.rs | 6 +- .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 1 + drivers/gpu/nova-core/gsp/fw/rm.rs | 5 + drivers/gpu/nova-core/gsp/rm/commands.rs | 4 +- drivers/gpu/nova-core/nova_core.rs | 2 + include/uapi/fwctl/fwctl.h | 1 + include/uapi/fwctl/nova-core.h | 52 ++++++++++ rust/kernel/fwctl.rs | 2 + rust/uapi/uapi_helper.h | 1 + 12 files changed, 193 insertions(+), 9 deletions(-) create mode 100644 drivers/gpu/nova-core/fwctl.rs create mode 100644 include/uapi/fwctl/nova-core.h
drivers/gpu/nova-core/fwctl.rs new file +99 -0
@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 + +use kernel::{ + fwctl::{ + self, +DeviceType , +FwRpcResponse , +Operations , +RpcScope ,// + }, + prelude::*, + transmute::{AsBytes ,FromBytes }, + uapi,// +}; + +use crate ::{ + driver::NovaCore , + gsp::{ +RmControlMsgFunction , + rm::commands::send_rm_control,// + }, +}; + +/// Byte-serializable wrapper for [`uapi::fwctl_rpc_nova_core_request_hdr`]. +#[repr(transparent)] +struct FwctlNovaCoreReqHdr (uapi::fwctl_rpc_nova_core_request_hdr ); + +// SAFETY: All fields are plain `__u32` with no padding. +unsafe impl FromBytes for FwctlNovaCoreReqHdr {} + +/// Byte-serializable wrapper for [`uapi::fwctl_rpc_nova_core_resp_hdr`]. +#[repr(transparent)] +struct FwctlNovaCoreRespHdr (uapi::fwctl_rpc_nova_core_resp_hdr ); + +// SAFETY: All fields are plain `__u32` with no padding. +unsafe impl AsBytes for FwctlNovaCoreRespHdr {} + +/// Per-FD fwctl user context and operations for nova-core. +pub (crate )struct NovaCoreFwCtl ; + +impl Operations for NovaCoreFwCtl { +type DeviceData = (); + +const DEVICE_TYPE :DeviceType =DeviceType ::NovaCore ; + +fn open (_device: &fwctl::Device <Self >) ->Result <impl PinInit <Self ,Error >,Error > { +Ok (Ok (NovaCoreFwCtl )) + } + +fn fw_rpc ( + _this: &Self , + device: &fwctl::Device <Self >, + scope:RpcScope , + rpc_in: &mut [u8 ], + ) ->Result <FwRpcResponse ,Error > { +let hdr_size =size_of ::<FwctlNovaCoreReqHdr >(); + +if rpc_in.len () < hdr_size { +return Err (EINVAL ); + } + +if scope !=RpcScope ::Configuration { +return Err (EPERM ); + } + +let (hdr, _) =FwctlNovaCoreReqHdr ::from_bytes_prefix (rpc_in).ok_or (EINVAL )?; +let cmd = hdr.0 .cmd; + +let rm_cmd =match cmd { + uapi::fwctl_cmd_nova_core_FWCTL_CMD_NOVA_CORE_UPLOAD_VGPU_TYPE => { +RmControlMsgFunction ::VgpuMgrInternalPgpuAddVgpuType + } + _ =>return Err (EINVAL ), + }; + +let parent = device.parent (); +let data = parent.drvdata ::<NovaCore >()?; +let bar = data.gpu.bar.as_ref ().access (parent)?; + +let params = &rpc_in[hdr_size..]; +let reply_params =send_rm_control ( + &data.gpu.gsp.cmdq, + bar, + data.gpu.gsp.h_client, + data.gpu.gsp.h_subdevice, + rm_cmd, + params, + )?; + +let resp_hdr =FwctlNovaCoreRespHdr (uapi::fwctl_rpc_nova_core_resp_hdr { + mctp_header:0 , + nvdm_header:0 , + }); +let mut out =KVec ::new (); + out.extend_from_slice (resp_hdr.as_bytes (),GFP_KERNEL )?; + out.extend_from_slice (&reply_params,GFP_KERNEL )?; +Ok (FwRpcResponse ::NewBuffer (out)) + } +}
drivers/gpu/nova-core/gpu.rs +2 -2
@@ -241,7 +241,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {pub (crate )struct Gpu { spec:Spec ,/// MMIO mapping of PCI BAR 0 - bar:Arc <Devres <Bar0 >>, +pub (crate ) bar:Arc <Devres <Bar0 >>,/// System memory page required for flushing all pending GPU-side memory writes done through /// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). sysmem_flush:SysmemFlush ,
@@ -251,7 +251,7 @@ pub(crate) struct Gpu { sec2_falcon: Falcon<Sec2Falcon>,/// GSP runtime data. Temporarily an empty placeholder. #[pin] - gsp: Gsp, + pub(crate) gsp: Gsp, }impl Gpu {
drivers/gpu/nova-core/gsp.rs +21 -4
@@ -4,11 +4,13 @@use kernel::{ device, + devres::Devres , dma::{CoherentAllocation ,DmaAddress ,// }, dma_write, + fwctl, pci, prelude::*, transmute::AsBytes ,//
@@ -21,15 +23,19 @@mod sequencer;pub (crate )use fw::{ + rm::RmControlMsgFunction ,GspFwWprMeta ,LibosParams ,// };use crate ::{ - gsp::cmdq::Cmdq , - gsp::fw::{ -GspArgumentsPadded , -LibosMemoryRegionInitArgument ,// + fwctl::NovaCoreFwCtl , + gsp::{ + cmdq::Cmdq , + fw::{ +GspArgumentsPadded , +LibosMemoryRegionInitArgument ,// + }, }, num, };
@@ -117,6 +123,12 @@ pub(crate) struct Gsp { pub(crate) cmdq: Cmdq,/// RM arguments. rmargs: CoherentAllocation<GspArgumentsPadded>, +/// Cached RM internal client handle from GSP static info. + pub(crate) h_client: u32, +/// Cached RM internal subdevice handle from GSP static info. + pub(crate) h_subdevice: u32, +/// fwctl registration for userspace RM control. + fwctl: Pin<KBox<Devres<fwctl::Registration<NovaCoreFwCtl>>>>, }impl Gsp {
@@ -125,6 +137,8 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error pin_init::pin_init_scope(move || { let dev = pdev.as_ref(); + let fwctl_dev = fwctl::Device::<NovaCoreFwCtl>::new(pdev.as_ref(), Ok(()))?; + Ok(try_pin_init!(Self { libos: CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent( dev,
@@ -140,6 +154,9 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error 1, GFP_KERNEL | __GFP_ZERO, )?, + h_client: 0, + h_subdevice: 0, + fwctl: KBox::pin_init(fwctl::Registration::new(pdev.as_ref(), &fwctl_dev), GFP_KERNEL)?, _: {// Initialise the logging structures. The OpenRM equivalents are in: // _kgspInitLibosLoggingStructures (allocates memory for buffers)
drivers/gpu/nova-core/gsp/boot.rs +5 -1
@@ -128,7 +128,7 @@ fn run_fwsec_frts(/// /// Upon return, the GSP is up and running, and its runtime object given as return value. pub (crate )fn boot ( - self:Pin <&mut Self >, +mut self:Pin <&mut Self >, pdev: &pci::Device <device::Bound >, bar: &Bar0 , chipset: Chipset,
@@ -221,6 +221,10 @@ pub(crate) fn boot(// Obtain and display basic GPU information. let info = commands::get_gsp_info (&self.cmdq, bar)?; +// SAFETY: h_client and h_subdevice are not structurally pinned. +let this =unsafe { self.as_mut ().get_unchecked_mut () }; + this.h_client = info.h_client (); + this.h_subdevice = info.h_subdevice ();match info.gpu_name () {Ok (name) =>dev_info! (pdev,"GPU name: {}\n" , name),Err (e) =>dev_warn! (pdev,"GPU name unavailable: {:?}\n" , e),
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +1 -0
@@ -45,6 +45,7 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {pub const REGISTRY_TABLE_ENTRY_TYPE_DWORD :u32 =1 ;pub const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX :u32 =65536 ;pub const NV2080_CTRL_CMD_CE_GET_FAULT_METHOD_BUFFER_SIZE :u32 =545270280 ; +pub const NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPE :u32 =545275907 ;pub type __u8 = ffi::c_uchar ;pub type __u16 = ffi::c_ushort ;pub type __u32 = ffi::c_uint ;
drivers/gpu/nova-core/gsp/fw/rm.rs +5 -0
@@ -19,6 +19,8 @@pub (crate )enum RmControlMsgFunction {/// Get the CE fault method buffer size. CeGetFaultMethodBufferSize = bindings::NV2080_CTRL_CMD_CE_GET_FAULT_METHOD_BUFFER_SIZE , +/// Upload vGPU type definitions to GSP. +VgpuMgrInternalPgpuAddVgpuType = bindings::NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPE , }impl TryFrom <u32 >for RmControlMsgFunction {
@@ -29,6 +31,9 @@ fn try_from(value: u32) -> Result<Self> { bindings::NV2080_CTRL_CMD_CE_GET_FAULT_METHOD_BUFFER_SIZE => { Ok(Self::CeGetFaultMethodBufferSize) } + bindings::NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPE => { +Ok (Self ::VgpuMgrInternalPgpuAddVgpuType ) + } _ => Err(EINVAL), } }
drivers/gpu/nova-core/gsp/rm/commands.rs +2 -2
@@ -98,7 +98,7 @@ fn read( }/// Sends an RM control command, checks the reply status, and returns the raw parameter bytes. -fn send_rm_control ( +pub (crate )fn send_rm_control ( cmdq: &Cmdq , bar: &Bar0 , h_client: u32,
@@ -106,7 +106,7 @@ fn send_rm_control( cmd: RmControlMsgFunction, params: &[u8], ) -> Result<KVVec<u8>> { -let reply = cmdq.send_sync_command (bar,RmControl ::new (h_client, h_object, cmd, params))?; +let reply = cmdq.send_command (bar,RmControl ::new (h_client, h_object, cmd, params))?;Result ::from (reply.status)?;
drivers/gpu/nova-core/nova_core.rs +2 -0
@@ -10,6 +10,7 @@mod falcon;mod fb;mod firmware; +mod fwctl;mod gfw;mod gpu;mod gsp;
@@ -27,6 +28,7 @@ description: "Nova Core GPU driver", license: "GPL v2", firmware: [], + imports_ns: ["FWCTL"], } kernel::module_firmware!(firmware::ModInfoBuilder );
include/uapi/fwctl/fwctl.h +1 -0
@@ -45,6 +45,7 @@ enum fwctl_device_type {FWCTL_DEVICE_TYPE_MLX5 =1 ,FWCTL_DEVICE_TYPE_CXL =2 ,FWCTL_DEVICE_TYPE_PDS =4 , + FWCTL_DEVICE_TYPE_NOVA_CORE = 5, };/**
include/uapi/fwctl/nova-core.h new file +52 -0
52 lines not on this page · raw message
rust/kernel/fwctl.rs +2 -0
@@ -34,6 +34,8 @@ pub enum DeviceType { Cxl = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_CXL,/// AMD/Pensando PDS device. Pds = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_PDS, +/// NVIDIA Nova Core GPU device. + NovaCore = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_NOVA_CORE, }impl From <DeviceType >for u32 {
rust/uapi/uapi_helper.h +1 -0
@@ -10,6 +10,7 @@#include <uapi/drm/drm.h> #include <uapi/drm/nova_drm.h> #include <uapi/drm/panthor_drm.h> +#include <uapi/fwctl/nova-core.h> #include <uapi/linux/android/binder.h> #include <uapi/linux/mdio.h> #include <uapi/linux/mii.h>
Signature · 1 line
2.51.0
Danilo Krummrich
maintainerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
drivers/gpu/nova-core/fwctl.rs line 12
Quoted 10 lines · Zhi Wang
drivers/gpu/nova-core/fwctl.rs new file +10
-0+use kernel::{ + fwctl::{ + self, +DeviceType , +FwRpcResponse , +Operations , +RpcScope ,// + }, + prelude::*, + transmute::{AsBytes ,FromBytes },
NIT: Formatting.
Quoted 33 lines
drivers/gpu/nova-core/fwctl.rs new file +33
-0+ uapi, // +}; + +use crate ::{ + driver::NovaCore , + gsp::{ +RmControlMsgFunction , + rm::commands::send_rm_control,// + }, +}; + +/// Byte-serializable wrapper for [`uapi::fwctl_rpc_nova_core_request_hdr`]. +#[repr(transparent)] +struct FwctlNovaCoreReqHdr (uapi::fwctl_rpc_nova_core_request_hdr ); + +// SAFETY: All fields are plain `__u32` with no padding. +unsafe impl FromBytes for FwctlNovaCoreReqHdr {} + +/// Byte-serializable wrapper for [`uapi::fwctl_rpc_nova_core_resp_hdr`]. +#[repr(transparent)] +struct FwctlNovaCoreRespHdr (uapi::fwctl_rpc_nova_core_resp_hdr ); + +// SAFETY: All fields are plain `__u32` with no padding. +unsafe impl AsBytes for FwctlNovaCoreRespHdr {} + +/// Per-FD fwctl user context and operations for nova-core. +pub (crate )struct NovaCoreFwCtl ; + +impl Operations for NovaCoreFwCtl { +type DeviceData = (); + +const DEVICE_TYPE :DeviceType =DeviceType ::NovaCore ; +
drivers/gpu/nova-core/fwctl.rs line 55
Quoted 10 lines
drivers/gpu/nova-core/fwctl.rs new file +10
-0+fn open (_device: &fwctl::Device <Self >) ->Result <impl PinInit <Self ,Error >,Error > { +Ok (Ok (NovaCoreFwCtl )) + } + +fn fw_rpc ( + _this: &Self , + device: &fwctl::Device <Self >, + scope:RpcScope , + rpc_in: &mut [u8 ], + ) ->Result <FwRpcResponse ,Error > {
Result<FwRpcResponse>
Quoted 12 lines
drivers/gpu/nova-core/fwctl.rs new file +12
-0+let hdr_size =size_of ::<FwctlNovaCoreReqHdr >(); + +if rpc_in.len () < hdr_size { +return Err (EINVAL ); + } + +if scope !=RpcScope ::Configuration { +return Err (EPERM ); + } + +let (hdr, _) =FwctlNovaCoreReqHdr ::from_bytes_prefix (rpc_in).ok_or (EINVAL )?; +let cmd = hdr.0 .cmd;
drivers/gpu/nova-core/fwctl.rs line 77
Quoted 10 lines
drivers/gpu/nova-core/fwctl.rs new file +10
-0+ +let rm_cmd =match cmd { + uapi::fwctl_cmd_nova_core_FWCTL_CMD_NOVA_CORE_UPLOAD_VGPU_TYPE => { +RmControlMsgFunction ::VgpuMgrInternalPgpuAddVgpuType + } + _ =>return Err (EINVAL ), + }; + +let parent = device.parent (); +let data = parent.drvdata ::<NovaCore >()?;
Please don't use drvdata() for this, it is not what it is intended for and I kinda regret a bit that I added it in the first place.
Instead, please use your fwctl::Device private data, i.e. Self.
Quoted 87 lines
drivers/gpu/nova-core/fwctl.rs new file +22
-0+let bar = data.gpu.bar.as_ref ().access (parent)?; + +let params = &rpc_in[hdr_size..]; +let reply_params =send_rm_control ( + &data.gpu.gsp.cmdq, + bar, + data.gpu.gsp.h_client, + data.gpu.gsp.h_subdevice, + rm_cmd, + params, + )?; + +let resp_hdr =FwctlNovaCoreRespHdr (uapi::fwctl_rpc_nova_core_resp_hdr { + mctp_header:0 , + nvdm_header:0 , + }); +let mut out =KVec ::new (); + out.extend_from_slice (resp_hdr.as_bytes (),GFP_KERNEL )?; + out.extend_from_slice (&reply_params,GFP_KERNEL )?; +Ok (FwRpcResponse ::NewBuffer (out)) + } +}drivers/gpu/nova-core/gpu.rs +2
-2@@ -241,7 +241,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {pub (crate )struct Gpu { spec:Spec ,/// MMIO mapping of PCI BAR 0 - bar:Arc <Devres <Bar0 >>, +pub (crate ) bar:Arc <Devres <Bar0 >>,/// System memory page required for flushing all pending GPU-side memory writes done through /// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). sysmem_flush:SysmemFlush ,@@ -251,7 +251,7 @@ pub(crate) struct Gpu { sec2_falcon: Falcon<Sec2Falcon>,/// GSP runtime data. Temporarily an empty placeholder. #[pin] - gsp: Gsp, + pub(crate) gsp: Gsp, }impl Gpu {drivers/gpu/nova-core/gsp.rs +10
-4@@ -4,11 +4,13 @@use kernel::{ device, + devres::Devres , dma::{CoherentAllocation ,DmaAddress ,// }, dma_write, + fwctl, pci, prelude::*, transmute::AsBytes ,// @@ -21,15 +23,19 @@mod sequencer;pub (crate )use fw::{ + rm::RmControlMsgFunction ,GspFwWprMeta ,LibosParams ,// };use crate ::{ - gsp::cmdq::Cmdq , - gsp::fw::{ -GspArgumentsPadded , -LibosMemoryRegionInitArgument ,// + fwctl::NovaCoreFwCtl , + gsp::{ + cmdq::Cmdq , + fw::{ +GspArgumentsPadded , +LibosMemoryRegionInitArgument ,// + }, }, num, };
drivers/gpu/nova-core/gsp.rs pub(crate) struct Gsp { · line 131
Quoted 9 lines
drivers/gpu/nova-core/gsp.rs +6
-0@@ -117,6 +123,12 @@ pub(crate) struct Gsp { pub(crate) cmdq: Cmdq,/// RM arguments. rmargs: CoherentAllocation<GspArgumentsPadded>, +/// Cached RM internal client handle from GSP static info. + pub(crate) h_client: u32, +/// Cached RM internal subdevice handle from GSP static info. + pub(crate) h_subdevice: u32, +/// fwctl registration for userspace RM control. + fwctl: Pin<KBox<Devres<fwctl::Registration<NovaCoreFwCtl>>>>,
This does not need to be in a separate allocation.
drivers/gpu/nova-core/gsp.rs pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error · line 140
Quoted 8 lines
drivers/gpu/nova-core/gsp.rs +1
-0}impl Gsp {@@ -125,6 +137,8 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error pin_init::pin_init_scope (move || {let dev = pdev.as_ref (); +let fwctl_dev = fwctl::Device ::<NovaCoreFwCtl >::new (pdev.as_ref (),Ok (()))?;
You should store everything you need in the private data of your fwctl::Device to properly tie it to its lifetime, e.g.
struct NovaCoreFwCtl {
gpu: Arc<Gpu>,
bar: Arc<Devres<Bar0>>,
}drivers/gpu/nova-core/gsp.rs pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error · line 159
Quoted 11 lines
drivers/gpu/nova-core/gsp.rs +4
-0+ Ok(try_pin_init!(Self { libos: CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent( dev,@@ -140,6 +154,9 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error 1, GFP_KERNEL | __GFP_ZERO, )?, + h_client: 0, + h_subdevice: 0, + fwctl: KBox::pin_init(fwctl::Registration::new(pdev.as_ref(), &fwctl_dev), GFP_KERNEL)?,
I don't think this should live in the Gsp structure, please move this to probe() and store the registration in struct NovaCore after the Gpu structure.
Quoted 17 lines
drivers/gpu/nova-core/gsp.rs +0
-0_: {// Initialise the logging structures. The OpenRM equivalents are in: // _kgspInitLibosLoggingStructures (allocates memory for buffers) drivers/gpu/nova-core/gsp/boot.rs +1
-1@@ -128,7 +128,7 @@ fn run_fwsec_frts(/// /// Upon return, the GSP is up and running, and its runtime object given as return value. pub (crate )fn boot ( - self:Pin <&mut Self >, +mut self:Pin <&mut Self >, pdev: &pci::Device <device::Bound >, bar: &Bar0 , chipset: Chipset,
drivers/gpu/nova-core/gsp/boot.rs pub(crate) fn boot( · line 227
Quoted 7 lines
drivers/gpu/nova-core/gsp/boot.rs +4
-0@@ -221,6 +221,10 @@ pub(crate) fn boot(// Obtain and display basic GPU information. let info = commands::get_gsp_info (&self.cmdq, bar)?; +// SAFETY: h_client and h_subdevice are not structurally pinned. +let this =unsafe { self.as_mut ().get_unchecked_mut () }; + this.h_client = info.h_client (); + this.h_subdevice = info.h_subdevice ();
Ick! If this is only needed from the fwctl callbacks, just move those into your fwctl::Device private data.
But I think this is needed in other cases as well. So, more generally I think Gsp::boot() should just be part of the constructor, as we won't be able to properly construct a Gsp object without having a chance to interact with the Gsp before.
drivers/gpu/nova-core/gsp/boot.rs fn send_rm_control( · line 109
Quoted 12 lines
drivers/gpu/nova-core/gsp/boot.rs +1
-1/// Sends an RM control command, checks the reply status, and returns the raw parameter bytes. -fn send_rm_control ( +pub (crate )fn send_rm_control ( cmdq: &Cmdq,bar: &Bar0, h_client: u32,drivers/gpu/nova-core/gsp/boot.rs +1
-1@@ -106,7 +106,7 @@ fn send_rm_control( cmd: RmControlMsgFunction, params: &[u8], ) -> Result<KVVec<u8>> { -let reply = cmdq.send_sync_command (bar,RmControl ::new (h_client, h_object, cmd, params))?; +let reply = cmdq.send_command (bar,RmControl ::new (h_client, h_object, cmd, params))?;
This looks like it should be a separate patch, or fixed in one of the dependencies of this patch.
include/uapi/fwctl/nova-core.h
Quoted 40 lines
drivers/gpu/nova-core/gsp/boot.rs +0
-0Result ::from (reply.status)?;drivers/gpu/nova-core/nova_core.rs +2
-0@@ -10,6 +10,7 @@mod falcon;mod fb;mod firmware; +mod fwctl;mod gfw;mod gpu;mod gsp;@@ -27,6 +28,7 @@ description: "Nova Core GPU driver", license: "GPL v2", firmware: [], + imports_ns: ["FWCTL"], } kernel::module_firmware!(firmware::ModInfoBuilder );include/uapi/fwctl/fwctl.h +1
-0@@ -45,6 +45,7 @@ enum fwctl_device_type {FWCTL_DEVICE_TYPE_MLX5 =1 ,FWCTL_DEVICE_TYPE_CXL =2 ,FWCTL_DEVICE_TYPE_PDS =4 , + FWCTL_DEVICE_TYPE_NOVA_CORE = 5, };/** include/uapi/fwctl/nova-core.h new file +0
-0
Why is this not include/uapi/gpu/nova-core.h? This driver does not live under drivers/fwctl/.
If we want to separate it, I suggest include/uapi/gpu/nova-core/fwctl.h, but it doesn't seem necessary as we don't have any other UAPIs.
Jason Gunthorpe
maintainerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
Quoted 9 lines · Danilo Krummrich
include/uapi/fwctl/nova-core.h
Quoted 6 lines
/**
include/uapi/fwctl/nova-core.h new file +0
-0Why is this not
include/uapi/gpu/nova-core.h? This driver does not live underdrivers/fwctl/.
I would prefer if it did, but understand if it doesn't want to for reasons.
But the uapi headers still must live in uapi/fwctl/ not someplace else, that is important.
Jason
Jason Gunthorpe
maintainerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
In reply to Zhi Wangdrivers/gpu/nova-core/fwctl.rs line 74
Quoted 6 lines · Zhi Wang
drivers/gpu/nova-core/fwctl.rs new file +6
-0+let rm_cmd =match cmd { + uapi::fwctl_cmd_nova_core_FWCTL_CMD_NOVA_CORE_UPLOAD_VGPU_TYPE => { +RmControlMsgFunction ::VgpuMgrInternalPgpuAddVgpuType + } + _ =>return Err (EINVAL ), + };
fwctl drivers should not be changing the commands as they flow through, the idea is to put the raw command mailbox directly into the FW, and only access control them. So userspace should be setting the NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPE constant directly and it should be ABI stable.
Quoted 18 lines
include/uapi/fwctl/nova-core.h new file +18
-0+/** +* struct fwctl_rpc_nova_core_request_hdr - ioctl(FWCTL_RPC) input header +* @cmd: Command identifier from &enum fwctl_cmd_nova_core. +* @mctp_header: MCTP transport header (packed u32). +* @nvdm_header: NVDM vendor-defined message header (packed u32). +* +* Placed at &struct fwctl_rpc.in with total length &struct fwctl_rpc.in_len. +* The access scope is specified through &struct fwctl_rpc.scope. +* Followed by command-specific input parameters. +*/ +struct fwctl_rpc_nova_core_request_hdr { +__u32 mctp_header; +__u32 nvdm_header; +__u32 cmd; +}; + +/** +* struct fwctl_rpc_nova_core_resp_hdr - ioctl(FWCTL_RPC) output header
include/uapi/fwctl/nova-core.h line 50
Quoted 10 lines
include/uapi/fwctl/nova-core.h new file +10
-0+* @mctp_header: MCTP transport header (packed u32). +* @nvdm_header: NVDM vendor-defined message header (packed u32). +* +* Placed at &struct fwctl_rpc.out with total length &struct fwctl_rpc.out_len. +* Followed by command-specific output parameters. +*/ +struct fwctl_rpc_nova_core_resp_hdr { +__u32 mctp_header; +__u32 nvdm_header; +};
I'm also confused what this is about, are these headers words from the FW definition?
Jason
Re: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
Quoted 8 lines · Jason Gunthorpe
drivers/gpu/nova-core/fwctl.rs line 74
Quoted 6 lines · Zhi Wang
drivers/gpu/nova-core/fwctl.rs new file +6
-0+let rm_cmd =match cmd { + uapi::fwctl_cmd_nova_core_FWCTL_CMD_NOVA_CORE_UPLOAD_VGPU_TYPE => { +RmControlMsgFunction ::VgpuMgrInternalPgpuAddVgpuType + } + _ =>return Err (EINVAL ), + };
Quoted 5 lines
fwctl drivers should not be changing the commands as they flow through, the idea is to put the raw command mailbox directly into the FW, and only access control them. So userspace should be setting the
NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPEconstant directly and it should be ABI stable.
Just trying to confirm my understanding: Doesn't that mean NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPE becomes a part of UAPI then? On the one hand, there is the argument that userspace should not deal with GSP-RM specific commands directly (lest they change in the future or get removed or whatever, and nova-core is the abstraction. On the other hand, I think idea behind fwctl is as Jason put it above. So which path is correct and makes sense for nova-core?
Quoted 23 lines
Quoted 23 lines
include/uapi/fwctl/nova-core.h new file +23
-0+/** +* struct fwctl_rpc_nova_core_request_hdr - ioctl(FWCTL_RPC) input header +* @cmd: Command identifier from &enum fwctl_cmd_nova_core. +* @mctp_header: MCTP transport header (packed u32). +* @nvdm_header: NVDM vendor-defined message header (packed u32). +* +* Placed at &struct fwctl_rpc.in with total length &struct fwctl_rpc.in_len. +* The access scope is specified through &struct fwctl_rpc.scope. +* Followed by command-specific input parameters. +*/ +struct fwctl_rpc_nova_core_request_hdr { +__u32 mctp_header; +__u32 nvdm_header; +__u32 cmd; +}; + +/** +* struct fwctl_rpc_nova_core_resp_hdr - ioctl(FWCTL_RPC) output header +* @mctp_header: MCTP transport header (packed u32). +* @nvdm_header: NVDM vendor-defined message header (packed u32). +* +* Placed at &struct fwctl_rpc.out with total length &struct fwctl_rpc.out_len. +* Followed by command-specific output parameters.
Quoted 8 lines
include/uapi/fwctl/nova-core.h line 50
Quoted 5 lines
+ */
include/uapi/fwctl/nova-core.h new file +4
-0+struct fwctl_rpc_nova_core_resp_hdr { +__u32 mctp_header; +__u32 nvdm_header; +};I'm also confused what this is about, are these headers words from the FW definition?
These are transport-layer headers for the GSP RPC message queue, MCTP provides packet framing (it is a standard protocol like networking protocols) and NVDM is NVIDIA specific header carried inside MCTP. IMO they are internal to the nova-core <-> GSP transport and should be filled in by the kernel driver, not exposed to userspace.
Thanks.
Jason Gunthorpe
maintainerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
Quoted 3 lines · Joel Fernandes
Just trying to confirm my understanding: Doesn't that mean
NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPEbecomes a part of UAPI then?
Yes.
Quoted 6 lines
On the one hand, there is the argument that userspace should not deal with GSP-RM specific commands directly (lest they change in the future or get removed or whatever, and nova-core is the abstraction. On the other hand, I think idea behind fwctl is as Jason put it above. So which path is correct and makes sense for nova-core?
If you use fwctl it should be as I described, it is not an generic interface to send SW command to the kernel, the commands have to be delivered to FW.
Quoted 5 lines
These are transport-layer headers for the GSP RPC message queue, MCTP provides packet framing (it is a standard protocol like networking protocols) and NVDM is NVIDIA specific header carried inside MCTP. IMO they are internal to the nova-core <-> GSP transport and should be filled in by the kernel driver, not exposed to userspace.
That makes more sense to me. I would expect only the actual payload to be part of fwctl. Any transport details must be managed by the kernel.
Jason
Gary Guo
reviewerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Joel Fernandes
Just trying to confirm my understanding: Doesn't that mean
NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPEbecomes a part of UAPI then?Yes.
I think it is probably undesirable for nova-core to expose GSP firmware detail to userspace directly.
Quoted 11 lines
Quoted 7 lines
On the one hand, there is the argument that userspace should not deal with GSP-RM specific commands directly (lest they change in the future or get removed or whatever, and nova-core is the abstraction. On the other hand, I think idea behind fwctl is as Jason put it above. So which path is correct and makes sense for nova-core?
If you use fwctl it should be as I described, it is not an generic interface to send SW command to the kernel, the commands have to be delivered to FW.
If fwctl isn't designed to provide abstraction layer between userspace/FW and is for raw access only, then an alternative mechanism should be used instead.
The cover letter says this:
Quoted 4 lines
This series adds a fwctl driver to nova-core, enabling userspace to issue firmware commands to the GSP through the standard fwctl ioctl interface. E.g. uploading the vGPU type blobs and managing the vGPU lifecycle, which is previously implemented in sysfs.
Zhi, is there a reason that sysfs is undesirable interface for this?
Best,
Gary
Quoted 11 lines
Quoted 6 lines
These are transport-layer headers for the GSP RPC message queue, MCTP provides packet framing (it is a standard protocol like networking protocols) and NVDM is NVIDIA specific header carried inside MCTP. IMO they are internal to the nova-core <-> GSP transport and should be filled in by the kernel driver, not exposed to userspace.
That makes more sense to me. I would expect only the actual payload to be part of fwctl. Any transport details must be managed by the kernel.
Jason
Jason Gunthorpe
maintainerRe: [PATCH 2/2] gpu: nova-core: add fwctl driver for firmware control interface
Quoted 11 lines · Gary Guo
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Joel Fernandes
Just trying to confirm my understanding: Doesn't that mean
NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_PGPU_ADD_VGPU_TYPEbecomes a part of UAPI then?Yes.
I think it is probably undesirable for nova-core to expose GSP firmware detail to userspace directly.
Why? That is the whole point of this mechanism to remove kernel involvement in the communication channel.
GSP firmware is supposed to commit to a stable ABI for anything enabled for fwctl.
Quoted 6 lines
Quoted 3 lines
If you use fwctl it should be as I described, it is not an generic interface to send SW command to the kernel, the commands have to be delivered to FW.
If fwctl isn't designed to provide abstraction layer between userspace/FW and is for raw access only, then an alternative mechanism should be used instead.
Why?
The purpose here is to upload a chunk of data to the FW. That is what fwctl does.
Quoted 6 lines
Quoted 4 lines
This series adds a fwctl driver to nova-core, enabling userspace to issue firmware commands to the GSP through the standard fwctl ioctl interface. E.g. uploading the vGPU type blobs and managing the vGPU lifecycle, which is previously implemented in sysfs.
Zhi, is there a reason that sysfs is undesirable interface for this?
Please no, sysfs should not be abused for things like this.
Jason