diff options
| author | Alistair Popple <apopple@nvidia.com> | 2025-11-14 14:55:52 -0500 |
|---|---|---|
| committer | Alexandre Courbot <acourbot@nvidia.com> | 2025-11-15 21:54:18 +0900 |
| commit | 13f85988d4fa31bda73a9504d71b10f7a14f1856 (patch) | |
| tree | 5eb98bfad3afdd73bb9cd0c0cebd1ab6a4c74b53 /drivers/gpu/nova-core/util.rs | |
| parent | 0e7d572b4baa64c582dafc4af36cfc8a4c3c1252 (diff) | |
gpu: nova-core: gsp: Retrieve GSP static info to gather GPU information
After GSP initialization is complete, retrieve the static configuration
information from GSP-RM. This information includes GPU name, capabilities,
memory configuration, and other properties. On some GPU variants, it is
also required to do this for initialization to complete.
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Co-developed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
[acourbot@nvidia.com: properly abstract the command's bindings, add
relevant methods, make str_from_null_terminated return an Option, fix
size of GPU name array.]
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251114195552.739371-14-joelagnelf@nvidia.com>
Diffstat (limited to 'drivers/gpu/nova-core/util.rs')
| -rw-r--r-- | drivers/gpu/nova-core/util.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/gpu/nova-core/util.rs b/drivers/gpu/nova-core/util.rs new file mode 100644 index 000000000000..4b503249a3ef --- /dev/null +++ b/drivers/gpu/nova-core/util.rs @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +/// Converts a null-terminated byte slice to a string, or `None` if the array does not +/// contains any null byte or contains invalid characters. +/// +/// Contrary to [`kernel::str::CStr::from_bytes_with_nul`], the null byte can be anywhere in the +/// slice, and not only in the last position. +pub(crate) fn str_from_null_terminated(bytes: &[u8]) -> Option<&str> { + use kernel::str::CStr; + + bytes + .iter() + .position(|&b| b == 0) + .and_then(|null_pos| CStr::from_bytes_with_nul(&bytes[..=null_pos]).ok()) + .and_then(|cstr| cstr.to_str().ok()) +} |