summaryrefslogtreecommitdiff
path: root/rust/helpers.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* rust: helpers: sort `#include`sMiguel Ojeda2022-08-011-1/+1
| | | | Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: add support for file system parametersWedson Almeida Filho2022-07-141-0/+10
| | | | | | | This allows file system contexts to be further initialised with parameters from userspace before a fs is mounted or reconfigured. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: define fs contextWedson Almeida Filho2022-07-111-0/+12
| | | | | | Also make fs mountable, but empty for now. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add definitions for ref-counted inodes and dentriesWedson Almeida Filho2022-07-041-0/+6
| | | | | | | This is in preparation for adding support for the implementation of file systems in Rust. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add support for work queuesWedson Almeida Filho2022-07-011-0/+7
| | | | | | | This is a primitive widely used on the C side. We'll need it for Binder and to implement the workqueue-based executor. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: helpers: cleanup `checkpatch.pl` issuesMiguel Ojeda2022-05-281-18/+23
| | | | | | | | | | Make the file a bit more `checkpatch.pl`-clean by fixing a couple style issues and replace bad indentation (spaces). Furthermore, re-sort the `#include`s too and prefer `linux/` to `asm/`. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: add async tcp connection supportWedson Almeida Filho2022-04-261-0/+7
| | | | | | | This allows us to write async tcp socket code similar to what we have in userspace. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add `RawSpinLock`Wedson Almeida Filho2022-03-291-0/+38
| | | | | | | | | | This is needed when code sections cannot sleep even in real-time variants of the kernel. For example, when a callback is called with a raw spinlock held, the callee cannot use mutexes or spinlocks, they must use a raw spinlock as well. (This happens in gpio; pl061 will be updated to use a raw spinlock.) Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #722 from wedsonaf/file-arefWedson Almeida Filho2022-03-281-0/+6
|\ | | | | rust: convert `File` to use `ARef`
| * rust: convert `File` to use `ARef`Wedson Almeida Filho2022-03-281-0/+6
| | | | | | | | | | | | This is to unify the usage of all ref-counted C structures. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: add `net::filter` moduleWedson Almeida Filho2022-03-281-0/+6
|/ | | | | | This allows us to add network packet filters written in Rust. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add `net` moduleWedson Almeida Filho2022-03-241-0/+38
| | | | | | | | | This adds basic abstractions for network namespaces, devices and buffers. This is in preparation for adding support for netfilters. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #717 from wedsonaf/smutexWedson Almeida Filho2022-03-231-0/+6
|\ | | | | rust: add a simple Rust mutex implementation
| * rust: add a simple Rust mutex implementationWedson Almeida Filho2022-03-171-0/+6
| | | | | | | | | | | | | | | | | | | | | | It doesn't have to be pinned, so its ergonomics are much better than the one based on the C version. In particular, it doesn't require users to use any unsafe code. This is a temporary solution for users can live with the simpler implementation while we don't have a better way of dealing with pinning. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: iomem: add `try_memcpy_fromio` method for `IoMem<T>`Maciej Falkowski2022-03-171-0/+7
|/ | | | | | | | This patch adds only runtime-checked bindings version of `memcpy_fromio()` function prefixed with `try_` similarly to read/write methods of `IoMem<T>` that is `readx` and `try_readx`. Signed-off-by: Maciej Falkowski <m.falkowski@samsung.com>
* rust: helpers: use MarkdownMiguel Ojeda2022-03-161-9/+9
| | | | Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: fix C code comment style to match kernel styleMiguel Ojeda2022-03-161-19/+21
| | | | Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: helpers: explain file with a top-level commentMiguel Ojeda2022-01-201-0/+17
| | | | | | | | Also copy the same `EXPORT_SYMBOL_GPL` explanation to `exports.c`. This also sums up the discussion at https://github.com/Rust-for-Linux/linux/pull/637 about exporting or not the helpers that are not technically required at the moment (thanks @bjorn3 for the note about `rustc` not guaranteeing codegen for non-inline functions). Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: helpers: export more functionsWei Liu2022-01-201-0/+4
| | | | | | Export them so that they can be used by modules. Signed-off-by: Wei Liu <wei.liu@kernel.org>
* rust: convert `platform` to use `driver`Wedson Almeida Filho2022-01-131-0/+8
| | | | | | | | | A platform driver is now defined by implementing a trait, very much like `amba`. There is also a module macro used that can used if a module is just a platform driver. Lastly, drivers can specify additional data with each supported id (to be passed back to them on `probe`). Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #621 from m-falkowski1/add_readx_writex_relaxedWedson Almeida Filho2022-01-121-0/+51
|\ | | | | rust: iomem: add readx/writex relaxed family of functions
| * rust: iomem: add readx/writex relaxed family of functionsMaciej Falkowski2022-01-121-0/+51
| | | | | | | | | | | | | | | | | | This patch adds a set of functions for the `IoMem<T>` type by reusing existing macros used for generating read/write methods for that type. The handling of arch-specific cross-compilation is done entirely on the C's side. Signed-off-by: Maciej Falkowski <m.falkowski@samsung.com>
* | rust: add initial common clock framework bindingsMaciej Falkowski2022-01-121-0/+13
|/ | | | | | | | | | | | | | This patch adds initial abstractions including: - `Clk` wrapper around `struct clk *`. - Binding of clk_get() method implemented as a method of `device::RawDevice` trait. - `EnableClk` that is an invariant of the `Clk` type that manages usage of the disable_unprepare() function. - Routines get_rate() and prepare_enable() implemented as methods of `Clk` type. Signed-off-by: Maciej Falkowski <m.falkowski@samsung.com>
* rust: add abstraction for credentials.Wedson Almeida Filho2021-11-291-0/+11
| | | | | | We need this in binder for the new security callbacks. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: gpio: add support for registering irq chips with gpio chip.Wedson Almeida Filho2021-11-261-0/+28
| | | | | | This is used by the PL061 driver. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add GPIO support.Wedson Almeida Filho2021-11-231-0/+6
| | | | | | | | This allows drivers to register with the GPIO subsystem, so that they can be exposed to clients. It does not include IRQ chip support, which will come in a subsequent patch. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #546 from wedsonaf/revocableWedson Almeida Filho2021-11-151-0/+18
|\ | | | | rust: add `Revocable` type.
| * rust: add `Revocable` type.Wedson Almeida Filho2021-11-151-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | It allows access to objects to be safely revoked at run time. This is useful, for example, for resources allocated during device probe; when the device is removed, the driver should stop accessing the device resources even if other state is kept in memory due to existing references (i.e., device context data is ref-counted and has a non-zero refcount after removal of the device). Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: add support for Amba device drivers.Wedson Almeida Filho2021-11-151-0/+13
| | | | | | | | | | | | This is used by the PL061 gpio driver. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: add support for defining irq chips.Wedson Almeida Filho2021-11-111-0/+14
|/ | | | | | This is used by the PL061 driver. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: Add support for irqsave/irqrestore variant of spin lock/unlock.Wedson Almeida Filho2021-11-061-0/+14
| | | | | | | | | | | We make the guard context an optional ulong. When locking without disabling interrupts, we store `None` in the context; when disabling interrupts, we store `Some(x)`, where `x` is the interrupt state before locking. During unlock we choose which variant to use based on whether the guard context is `None` or `Some(x)` (this check is short-circuited by the optimiser in most cases). Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #526 from wedsonaf/seqlockWedson Almeida Filho2021-11-051-8/+39
|\ | | | | rust: add `SeqLock`.
| * rust: fix indentation in some `rust/helpers.c` functions.Wedson Almeida Filho2021-10-221-14/+14
| | | | | | | | | | | | Some functions accidently used spaces instead of tabs. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: add `SeqLock`.Wedson Almeida Filho2021-10-211-0/+31
| | | | | | | | | | | | | | | | | | | | This is based on the discussion in: https://lore.kernel.org/rust-for-linux/YWccYPLUOH7t9JtB@google.com/ It has one modification where the `SeqLock` embeds a lock to serialise the write-side critical section implicitly. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: security: temporary fix for build error on Rust BinderMiguel Ojeda2021-11-041-7/+7
|/ | | | | | We likely need to create a `Cred` abstraction. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: use the generated helper bindingsGary Guo2021-08-241-11/+12
| | | | Signed-off-by: Gary Guo <gary@garyguo.net>
* rust: add `IoMem` abstraction.Wedson Almeida Filho2021-07-301-0/+59
| | | | | | | | | | This is based on what I described in LKML (https://lore.kernel.org/lkml/YIbQ3dHOpyD%2FyymW@google.com/) back in April. This is in preparation for the PL061 driver to be merged. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add a power management module.Wedson Almeida Filho2021-07-291-0/+6
| | | | | | | | | This allows drivers to implement the methods in `dev_pm_ops`. This is in preparation for adding the PL061 GPIO driver, which implements some power management methods. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add support for calling some security functions.Wedson Almeida Filho2021-07-021-0/+29
| | | | | | | | This allows drivers to call functions in security modules that take objects for which we have abstractions (e.g., files and tasks) as arguments. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add a `Task` abstraction.Wedson Almeida Filho2021-07-011-8/+20
| | | | | | | | | This allows users of the `kernel` crate to get tasks (e.g., the current task), access their properties (e.g., pid, group_leader, etc.), and hold on to them if desired. When holding on to tasks, the reference count is automatically incremented and decremented. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Add red-black tree implementation backed by the C version.Wedson Almeida Filho2021-06-301-0/+7
| | | | Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: update `Ref` to use the kernel's `refcount_t`.Wedson Almeida Filho2021-06-251-0/+18
| | | | | | | `Ref` now has an interface similar to that of `Arc` but is backed by the kernel's `refcount_t` type. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust/kernel/platdev: add support for device driver dataSven Van Asbroeck2021-06-121-0/+16
| | | | | | | Device driver data corresponds to per-device context data or state. It is allocated on `probe()` and de-allocated in `remove()`. Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
* rust/kernel: remove config `#ifdef` in mutex.rs fileSven Van Asbroeck2021-06-051-0/+7
| | | | | | | | | | | The use of `#ifdef CONFIG_` statements in .c/.rs files should be avoided: it makes the code much more unmaintainable over time. See: https://lore.kernel.org/lkml/YLjWKwhp7akqyR1S@kroah.com/ Use a Rust-C helper instead to leverage automatic `CONFIG` selection in C kernel headers. Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
* rust/kernel: remove config `#ifdef` in Error.rs fileSven Van Asbroeck2021-06-041-0/+6
| | | | | | | | | | | The use of `#ifdef CONFIG_` statements in .c/.rs files should be avoided: it makes the code much more unmaintainable over time. See: https://lore.kernel.org/lkml/YLjWKwhp7akqyR1S@kroah.com/ Use a Rust-C helper instead to leverage automatic `CONFIG` selection in C kernel headers. Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
* rust: helpers: Clarify comment on size_t = uintptr_t guardGeoffrey Thomas2021-06-031-5/+21
| | | | | | | | Also fix the guard to not fail spriously on ARM. We just need the types to be ABI-compatible; we don't need C to be willing to implicitly convert between them. Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
* rust/error: add helper function to convert a C error pointer to a `Result`Sven Van Asbroeck2021-05-191-0/+12
| | | | | | | | | | | | | | | | Some kernel C API functions return a pointer which embeds an optional `errno`. Callers are supposed to check the returned pointer with `IS_ERR()` and if this returns `true`, retrieve the `errno` using `PTR_ERR()`. Create a Rust helper function to implement the Rust equivalent: transform a `*mut T` to `Result<*mut T>`. Co-developed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Co-developed-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
* Add support for `read_iter` and `write_iter`.Wedson Almeida Filho2021-04-281-0/+13
| | | | | | | | Implementations only need to declare their desire to have the appropriate fields in `struct file_operations` set, there is no need to implement a variant of `read` or `write`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #222 from wedsonaf/clearMiguel Ojeda2021-04-271-0/+5
|\ | | | | Add `UserSlicePtrWriter::clear`.
| * Add `UserSlicePtrWriter::clear`.Wedson Almeida Filho2021-04-271-0/+5
| | | | | | | | Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>