Lines Matching +full:firmware +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
3 //! Firmware abstraction
5 //! C header: [`include/linux/firmware.h`](srctree/include/linux/firmware.h)
16 *mut *const bindings::firmware,
19 ) -> i32,
23 fn request() -> Self { in request()
27 fn request_nowarn() -> Self { in request_nowarn()
32 /// Abstraction around a C `struct firmware`.
34 /// This is a simple abstraction around the C firmware API. Just like with the C API, firmware can
35 /// be requested. Once requested the abstraction provides direct access to the firmware buffer as
36 /// `&[u8]`. The firmware is released once [`Firmware`] is dropped.
40 /// The pointer is valid, and has ownership over the instance of `struct firmware`.
42 /// The `Firmware`'s backing buffer is not modified.
47 /// # use kernel::{c_str, device::Device, firmware::Firmware};
49 /// # fn no_run() -> Result<(), Error> {
53 /// let fw = Firmware::request(c_str!("path/to/firmware.bin"), &dev)?;
59 pub struct Firmware(NonNull<bindings::firmware>); struct
61 impl Firmware { impl
62 fn request_internal(name: &CStr, dev: &Device, func: FwFunc) -> Result<Self> { in request_internal()
63 let mut fw: *mut bindings::firmware = core::ptr::null_mut(); in request_internal()
64 let pfw: *mut *mut bindings::firmware = &mut fw; in request_internal()
66 // SAFETY: `pfw` is a valid pointer to a NULL initialized `bindings::firmware` pointer. in request_internal()
67 // `name` and `dev` are valid as by their type invariants. in request_internal()
68 let ret = unsafe { func.0(pfw as _, name.as_char_ptr(), dev.as_raw()) }; in request_internal()
73 // SAFETY: `func` not bailing out with a non-zero error code, guarantees that `fw` is a in request_internal()
74 // valid pointer to `bindings::firmware`. in request_internal()
75 Ok(Firmware(unsafe { NonNull::new_unchecked(fw) })) in request_internal()
78 /// Send a firmware request and wait for it. See also `bindings::request_firmware`.
79 pub fn request(name: &CStr, dev: &Device) -> Result<Self> { in request()
80 Self::request_internal(name, dev, FwFunc::request()) in request()
83 /// Send a request for an optional firmware module. See also
85 pub fn request_nowarn(name: &CStr, dev: &Device) -> Result<Self> { in request_nowarn()
86 Self::request_internal(name, dev, FwFunc::request_nowarn()) in request_nowarn()
89 fn as_raw(&self) -> *mut bindings::firmware { in as_raw() argument
93 /// Returns the size of the requested firmware in bytes.
94 pub fn size(&self) -> usize { in size()
99 /// Returns the requested firmware as `&[u8]`.
100 pub fn data(&self) -> &[u8] { in data()
102 // `bindings::firmware` guarantees, if successfully requested, that in data()
103 // `bindings::firmware::data` has a size of `bindings::firmware::size` bytes. in data()
108 impl Drop for Firmware { implementation
115 // SAFETY: `Firmware` only holds a pointer to a C `struct firmware`, which is safe to be used from
117 unsafe impl Send for Firmware {} implementation
119 // SAFETY: `Firmware` only holds a pointer to a C `struct firmware`, references to which are safe to
121 unsafe impl Sync for Firmware {} implementation
123 /// Create firmware .modinfo entries.
126 /// simple string literals, which is already covered by the `firmware` field of
128 /// [`ModInfoBuilder`], which can create the firmware modinfo strings in a more flexible way.
134 /// `const fn create(module_name: &'static CStr) -> ModInfoBuilder`
137 /// it construct the corresponding firmware modinfo.
146 /// # use kernel::firmware;
152 /// # fn init(_module: &'static ThisModule) -> Result<Self> {
164 /// const fn create(module_name: &'static kernel::str::CStr) -> firmware::ModInfoBuilder<N> {
165 /// let mut builder = firmware::ModInfoBuilder::new(module_name);
183 /// name: "module_firmware_test",
201 <LocalModule as $crate::ModuleMetadata>::NAME
212 /// Builder for firmware module info.
214 /// [`ModInfoBuilder`] is a helper component to flexibly compose firmware paths strings for the
233 pub const fn new(module_name: &'static CStr) -> Self { in new()
241 const fn push_internal(mut self, bytes: &[u8]) -> Self { in push_internal()
267 /// use kernel::firmware::ModInfoBuilder;
279 pub const fn push(self, s: &str) -> Self { in push()
288 const fn push_module_name(self) -> Self { in push_module_name()
296 // Re-use the space taken by the NULL terminator and swap it with the '.' separator. in push_module_name()
297 this.buf[this.n - 1] = b'.'; in push_module_name()
306 /// This method acts as a separator between module firmware path entries.
312 pub const fn new_entry(self) -> Self { in new_entry()
315 .push_internal(b"firmware=") in new_entry()
319 pub const fn build(self) -> [u8; N] { in build()
333 pub const fn build_length(self) -> usize { in build_length()