2024-08-15 10:30:26 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Non-trivial C macros cannot be used in Rust. Similarly, inlined C functions
|
|
|
|
* cannot be called either. This file explicitly creates functions ("helpers")
|
|
|
|
* that wrap those so that they can be called from Rust.
|
|
|
|
*
|
|
|
|
* Sorted alphabetically.
|
|
|
|
*/
|
|
|
|
|
2025-04-14 13:18:06 +00:00
|
|
|
#include "auxiliary.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "blk.c"
|
|
|
|
#include "bug.c"
|
|
|
|
#include "build_assert.c"
|
|
|
|
#include "build_bug.c"
|
2025-02-20 11:04:00 +00:00
|
|
|
#include "clk.c"
|
2025-06-09 11:14:16 +00:00
|
|
|
#include "cpu.c"
|
2025-01-07 07:21:08 +00:00
|
|
|
#include "cpufreq.c"
|
2025-02-24 23:39:35 +00:00
|
|
|
#include "cpumask.c"
|
2024-09-15 14:31:30 +00:00
|
|
|
#include "cred.c"
|
2024-12-19 17:04:10 +00:00
|
|
|
#include "device.c"
|
rust: helpers: Add dma_alloc_attrs() and dma_free_attrs()
Add dma_alloc_attrs() and dma_free_attrs() helpers to fix a build
error when CONFIG_HAS_DMA is not enabled.
Note that when CONFIG_HAS_DMA is enabled, dma_alloc_attrs() and
dma_free_attrs() are included in both bindings_generated.rs and
bindings_helpers_generated.rs. The former takes precedence so behavior
remains unchanged in that case.
This fixes the following build error on UML:
error[E0425]: cannot find function `dma_alloc_attrs` in crate `bindings`
--> rust/kernel/dma.rs:171:23
|
171 | bindings::dma_alloc_attrs(
| ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_alloc_pages`
|
::: rust/bindings/bindings_generated.rs:44568:5
|
44568 | / pub fn dma_alloc_pages(
44569 | | dev: *mut device,
44570 | | size: usize,
44571 | | dma_handle: *mut dma_addr_t,
44572 | | dir: dma_data_direction,
44573 | | gfp: gfp_t,
44574 | | ) -> *mut page;
| |___________________- similarly named function `dma_alloc_pages` defined here
error[E0425]: cannot find function `dma_free_attrs` in crate `bindings`
--> rust/kernel/dma.rs:293:23
|
293 | bindings::dma_free_attrs(
| ^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_free_pages`
|
::: rust/bindings/bindings_generated.rs:44577:5
|
44577 | / pub fn dma_free_pages(
44578 | | dev: *mut device,
44579 | | size: usize,
44580 | | page: *mut page,
44581 | | dma_handle: dma_addr_t,
44582 | | dir: dma_data_direction,
44583 | | );
| |______- similarly named function `dma_free_pages` defined here
Fixes: ad2907b4e308 ("rust: add dma coherent allocator abstraction")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20250412000507.157000-1-fujita.tomonori@gmail.com
[ Reworded for relative paths. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-04-12 00:05:06 +00:00
|
|
|
#include "dma.c"
|
2025-04-10 23:55:26 +00:00
|
|
|
#include "drm.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "err.c"
|
rust: file: add Rust abstraction for `struct file`
This abstraction makes it possible to manipulate the open files for a
process. The new `File` struct wraps the C `struct file`. When accessing
it using the smart pointer `ARef<File>`, the pointer will own a
reference count to the file. When accessing it as `&File`, then the
reference does not own a refcount, but the borrow checker will ensure
that the reference count does not hit zero while the `&File` is live.
Since this is intended to manipulate the open files of a process, we
introduce an `fget` constructor that corresponds to the C `fget`
method. In future patches, it will become possible to create a new fd in
a process and bind it to a `File`. Rust Binder will use these to send
fds from one process to another.
We also provide a method for accessing the file's flags. Rust Binder
will use this to access the flags of the Binder fd to check whether the
non-blocking flag is set, which affects what the Binder ioctl does.
This introduces a struct for the EBADF error type, rather than just
using the Error type directly. This has two advantages:
* `File::fget` returns a `Result<ARef<File>, BadFdError>`, which the
compiler will represent as a single pointer, with null being an error.
This is possible because the compiler understands that `BadFdError`
has only one possible value, and it also understands that the
`ARef<File>` smart pointer is guaranteed non-null.
* Additionally, we promise to users of the method that the method can
only fail with EBADF, which means that they can rely on this promise
without having to inspect its implementation.
That said, there are also two disadvantages:
* Defining additional error types involves boilerplate.
* The question mark operator will only utilize the `From` trait once,
which prevents you from using the question mark operator on
`BadFdError` in methods that return some third error type that the
kernel `Error` is convertible into. (However, it works fine in methods
that return `Error`.)
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Co-developed-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240915-alice-file-v10-3-88484f7a3dcf@google.com
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-09-15 14:31:29 +00:00
|
|
|
#include "fs.c"
|
rust: add `io::{Io, IoRaw}` base types
I/O memory is typically either mapped through direct calls to ioremap()
or subsystem / bus specific ones such as pci_iomap().
Even though subsystem / bus specific functions to map I/O memory are
based on ioremap() / iounmap() it is not desirable to re-implement them
in Rust.
Instead, implement a base type for I/O mapped memory, which generically
provides the corresponding accessors, such as `Io::readb` or
`Io:try_readb`.
`Io` supports an optional const generic, such that a driver can indicate
the minimal expected and required size of the mapping at compile time.
Correspondingly, calls to the 'non-try' accessors, support compile time
checks of the I/O memory offset to read / write, while the 'try'
accessors, provide boundary checks on runtime.
`IoRaw` is meant to be embedded into a structure (e.g. pci::Bar or
io::IoMem) which creates the actual I/O memory mapping and initializes
`IoRaw` accordingly.
To ensure that I/O mapped memory can't out-live the device it may be
bound to, subsystems must embed the corresponding I/O memory type (e.g.
pci::Bar) into a `Devres` container, such that it gets revoked once the
device is unbound.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Link: https://lore.kernel.org/r/20241219170425.12036-8-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-12-19 17:04:09 +00:00
|
|
|
#include "io.c"
|
2024-10-30 16:04:24 +00:00
|
|
|
#include "jump_label.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "kunit.c"
|
2025-04-08 09:22:38 +00:00
|
|
|
#include "mm.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "mutex.c"
|
|
|
|
#include "page.c"
|
2024-12-19 17:04:16 +00:00
|
|
|
#include "platform.c"
|
2024-12-19 17:04:11 +00:00
|
|
|
#include "pci.c"
|
2024-10-02 11:38:10 +00:00
|
|
|
#include "pid_namespace.c"
|
2024-08-22 16:37:53 +00:00
|
|
|
#include "rbtree.c"
|
2024-12-19 17:04:06 +00:00
|
|
|
#include "rcu.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "refcount.c"
|
2024-09-15 14:31:31 +00:00
|
|
|
#include "security.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "signal.c"
|
|
|
|
#include "slab.c"
|
|
|
|
#include "spinlock.c"
|
2025-03-07 23:27:01 +00:00
|
|
|
#include "sync.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "task.c"
|
|
|
|
#include "uaccess.c"
|
2024-10-04 15:41:12 +00:00
|
|
|
#include "vmalloc.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "wait.c"
|
|
|
|
#include "workqueue.c"
|
2025-04-23 13:54:38 +00:00
|
|
|
#include "xarray.c"
|