Skip to content

[Tracking/Asahi] Rust DRM abstractions #969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 82 commits into
base: rust-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
38717bd
rust: kernel: Mark rust_fmt_argument as extern "C"
sulix Feb 14, 2023
bcfd851
soc: apple: rtkit: Add a private pointer to apple_rtkit_shmem
asahilina Jan 21, 2023
5f9a6ba
soc: apple: rtkit: Export non-devm init/free functions
asahilina Jan 21, 2023
3c3f227
drm/gem-shmem: Fix locking for drm_gem_shmem_get_pages_sgt()
asahilina Sep 7, 2022
a38c023
arm64: rust: Enable Rust support for AArch64
ojeda Jan 25, 2023
135e133
arm64: rust: Enable PAC support for Rust.
JamieCunliffe Jan 25, 2023
3ca7478
arm64: rust: Disable neon and fp target features.
JamieCunliffe Jan 25, 2023
4c9658b
rust: sync: impl {Debug,Display} for {Unique,}Arc
fbq Feb 7, 2023
a0fe4ac
sample: rust: print: Add sampe code for Arc printing
fbq Feb 7, 2023
05228e7
rust: time: New module for timekeeping functions
asahilina Oct 19, 2022
ea1e536
rust: macros: Make expect_punct() return the Punct directly
asahilina Jan 26, 2023
5341cab
rust: concat_idents: Allow :: paths in first argument
asahilina Nov 4, 2022
b41f846
rust: macros: Allow specifying multiple module aliases
asahilina Dec 5, 2022
8f9792c
rust: ioctl: Add ioctl number manipulation functions
asahilina Sep 24, 2022
4c2677a
rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
asahilina Feb 15, 2023
7402be1
rust: Enable feature new_uninit for the kernel crate
asahilina Feb 11, 2023
b5907a1
rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
asahilina Nov 11, 2022
d898a36
rust: error: Add Error::to_ptr()
asahilina Sep 7, 2022
8b14bb1
rust: error: Add Error::from_kernel_errno()
asahilina Feb 5, 2023
86dcd64
rust: error: Add to_result() helper
asahilina Feb 5, 2023
b376b28
rust: error: Add a helper to convert a C ERR_PTR to a `Result`
May 13, 2021
f325dc8
rust: error: Add from_kernel_result!() macro
asahilina Feb 16, 2023
834ba12
rust: Import upstream `alloc::vec::set_len_on_drop` module
asahilina Feb 16, 2023
25c7313
rust: Import upstream `alloc::vec::spec_extend` module
asahilina Feb 16, 2023
bdeae64
rust: alloc: vec: Add some try_* methods we need
ojeda Feb 16, 2023
9a99c88
rust: xarray: Add an abstraction for XArray
asahilina Jan 11, 2023
3a1cbaa
rust: Add a Sealed trait
asahilina Feb 5, 2023
8d62ad9
rust: device: Add an abstraction for devices
wedsonaf Nov 18, 2021
6f5b56e
rust: io_pgtable: Add io_pgtable abstraction
asahilina Sep 7, 2022
07df4ec
rust: soc: apple: rtkit: Add Apple RTKit abstraction
asahilina Aug 17, 2022
45ac60a
rust: Add `container_of` and `offset_of` macros
wedsonaf Apr 1, 2021
0a8027a
Merge branch 'gpu/rust-for-next' into gpu/rust-for-next-merged
asahilina Feb 16, 2023
2adeb84
rust: sync: Add LockClassKey
asahilina Feb 11, 2023
7027dcc
*RFL import: kernel::types::Bool
asahilina Feb 11, 2023
795cb5a
*RFL import: sync::{NeedsLockClass, init_with_lockdep}
asahilina Feb 11, 2023
d15b9a8
*RFL import: kernel::sync::guard
asahilina Feb 11, 2023
07da528
*RFL import: kernel::sync::revocable
asahilina Feb 11, 2023
34fdf36
*RFL import: kernel::sync::mutex
asahilina Feb 11, 2023
016856e
*RFL import: kernel::sync::condvar
asahilina Feb 11, 2023
b1c6823
*RFL import: kernel::io_buffer
asahilina Feb 16, 2023
08177ac
*RFL import: kernel::user_ptr
asahilina Feb 16, 2023
d16349a
MISSING SIGNOFFS: rust: Add PAGE_SIZE constant to kernel crate
asahilina Feb 16, 2023
4629538
rust: Enable const_mut_refs feature for the kernel crate
asahilina Feb 16, 2023
22baf01
*RFL import: kernel::module_param
asahilina Feb 16, 2023
a6ee5e4
rust: upgrade to Rust 1.66.0
ojeda Dec 24, 2022
ea8a2f3
*RFL import: kernel::sync::rcu
asahilina Feb 16, 2023
78b035f
*RFL import: kernel::revocable
asahilina Feb 16, 2023
655b626
rust: Add `name` argument to Module::init()
asahilina Feb 16, 2023
902093b
*RFL import: kernel::driver
asahilina Feb 16, 2023
ec02e27
*RFL import: The rest of kernel::device (minus clk stuff)
asahilina Feb 16, 2023
de5c754
*RFL import: kernel::io_mem
asahilina Feb 16, 2023
39c35af
*RFL import: kernel::of
asahilina Feb 16, 2023
3377089
*RFL import: kernel::platform
asahilina Feb 16, 2023
34ec403
*RFL import: kernel::delay
asahilina Feb 16, 2023
e4ba141
rust: of: Add OF node abstraction
asahilina Oct 21, 2022
7b95ca3
rust: driver,of: Support passing ID tables to modpost for alias gener…
asahilina Dec 8, 2022
e51694e
rust: platform: add `ioremap_resource` and `get_resource` methods
Feb 8, 2022
397a8e5
rust: kernel: platform: Add Device.set_dma_masks()
asahilina Sep 7, 2022
f3abda2
rust: Add ioremap_np support to io_mem & friends
asahilina Sep 21, 2022
be407a2
*RFL import: macros::module params functionality & deps
asahilina Feb 16, 2023
0114070
*RFL import: Rest of kernel::error::code::*
asahilina Feb 16, 2023
a4e674e
rust: bindings: Add resource_size wrapper
asahilina Sep 7, 2022
e4cde92
rust: Allow feature new_uninit
asahilina Sep 8, 2022
46ada3b
rust: Allow feature allocator_api
asahilina Feb 16, 2023
191e859
*RFL import: kernel::KParamGuard & friends
asahilina Feb 16, 2023
b58c395
*RFL import: kernel::error::Error Debug impl & dependencies
asahilina Feb 16, 2023
bbff966
*RFL import: kernel::sync::smutex
asahilina Feb 16, 2023
eb5fa47
iommu/io-pgtable: Add Apple UAT variant format
asahilina Aug 17, 2022
c8f9f69
rust: io_pgtable: Add the Apple UAT format abstraction
asahilina Feb 16, 2023
e4d397a
rust: drm: ioctl: Add DRM ioctl abstraction
asahilina Feb 5, 2023
510d27b
rust: drm: Add Device and Driver abstractions
asahilina Feb 5, 2023
7f760a8
rust: drm: file: Add File abstraction
asahilina Feb 5, 2023
b89a9da
rust: drm: gem: Add GEM object abstraction
asahilina Feb 5, 2023
a640ef1
drm/gem-shmem: Export VM ops functions
asahilina Sep 7, 2022
36a79c2
rust: drm: gem: shmem: Add DRM shmem helper abstraction
asahilina Feb 5, 2023
bc228ef
rust: drm: mm: Add DRM MM Range Allocator abstraction
asahilina Feb 11, 2023
fe6eb9c
rust: dma_fence: Add DMA Fence abstraction
asahilina Feb 11, 2023
3b08232
rust: drm: syncobj: Add DRM Sync Object abstraction
asahilina Feb 11, 2023
6fbf03a
drm/sched: Add can_run_job callback
asahilina Feb 11, 2023
689f400
rust: drm: sched: Add GPU scheduler abstraction
asahilina Feb 11, 2023
62bdaa1
drm/gem: Add a flag to control whether objects can be exported
asahilina Feb 10, 2023
e37ed51
rust: drm: gem: Add set_exportable() method
asahilina Feb 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rust: ioctl: Add ioctl number manipulation functions
Add simple 1:1 wrappers of the C ioctl number manipulation functions.
Since these are macros we cannot bindgen them directly, and since they
should be usable in const context we cannot use helper wrappers, so
we'll have to reimplement them in Rust. Thankfully, the C headers do
declare defines for the relevant bitfield positions, so we don't need
to duplicate that.

Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina committed Feb 16, 2023
commit 8f9792c1cfbd2131916453f92e15488e6e435b5d
1 change: 1 addition & 0 deletions rust/bindings/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/refcount.h>
#include <linux/slab.h>
#include <linux/timekeeping.h>
#include <uapi/asm-generic/ioctl.h>

/* `bindgen` gets confused at certain things. */
const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL;
Expand Down
64 changes: 64 additions & 0 deletions rust/kernel/ioctl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-2.0
#![allow(non_snake_case)]

//! ioctl() number definitions
//!
//! C header: [`include/asm-generic/ioctl.h`](../../../../include/asm-generic/ioctl.h)

/// Build an ioctl number, analogous to the C macro of the same name.
const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 {
core::assert!(dir <= bindings::_IOC_DIRMASK);
core::assert!(ty <= bindings::_IOC_TYPEMASK);
core::assert!(nr <= bindings::_IOC_NRMASK);
core::assert!(size <= (bindings::_IOC_SIZEMASK as usize));

(dir << bindings::_IOC_DIRSHIFT)
| (ty << bindings::_IOC_TYPESHIFT)
| (nr << bindings::_IOC_NRSHIFT)
| ((size as u32) << bindings::_IOC_SIZESHIFT)
}

/// Build an ioctl number for an argumentless ioctl.
pub const fn _IO(ty: u32, nr: u32) -> u32 {
_IOC(bindings::_IOC_NONE, ty, nr, 0)
}

/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(ty: u32, nr: u32) -> u32 {
_IOC(bindings::_IOC_READ, ty, nr, core::mem::size_of::<T>())
}

/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(ty: u32, nr: u32) -> u32 {
_IOC(bindings::_IOC_WRITE, ty, nr, core::mem::size_of::<T>())
}

/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(ty: u32, nr: u32) -> u32 {
_IOC(
bindings::_IOC_READ | bindings::_IOC_WRITE,
ty,
nr,
core::mem::size_of::<T>(),
)
}

/// Get the ioctl direction from an ioctl number.
pub const fn _IOC_DIR(nr: u32) -> u32 {
(nr >> bindings::_IOC_DIRSHIFT) & bindings::_IOC_DIRMASK
}

/// Get the ioctl type from an ioctl number.
pub const fn _IOC_TYPE(nr: u32) -> u32 {
(nr >> bindings::_IOC_TYPESHIFT) & bindings::_IOC_TYPEMASK
}

/// Get the ioctl number from an ioctl number.
pub const fn _IOC_NR(nr: u32) -> u32 {
(nr >> bindings::_IOC_NRSHIFT) & bindings::_IOC_NRMASK
}

/// Get the ioctl size from an ioctl number.
pub const fn _IOC_SIZE(nr: u32) -> usize {
((nr >> bindings::_IOC_SIZESHIFT) & bindings::_IOC_SIZEMASK) as usize
}
1 change: 1 addition & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ compile_error!("Missing kernel configuration for conditional compilation");
mod allocator;
mod build_assert;
pub mod error;
pub mod ioctl;
pub mod prelude;
pub mod print;
mod static_assert;
Expand Down