Skip to content

Commit abcdf6d

Browse files
committed
Merge branch 'bits/210-gpu' into asahi-wip
2 parents 6097cad + 80ef0fa commit abcdf6d

File tree

137 files changed

+31057
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+31057
-612
lines changed

Documentation/process/changes.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,7 @@ docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
8888
Rust (optional)
8989
---------------
9090

91-
A particular version of the Rust toolchain is required. Newer versions may or
92-
may not work because the kernel depends on some unstable Rust features, for
93-
the moment.
94-
95-
Each Rust toolchain comes with several "components", some of which are required
96-
(like ``rustc``) and some that are optional. The ``rust-src`` component (which
97-
is optional) needs to be installed to build the kernel. Other components are
98-
useful for developing.
91+
A recent version of the Rust compiler is required.
9992

10093
Please see Documentation/rust/quick-start.rst for instructions on how to
10194
satisfy the build requirements of Rust support. In particular, the ``Makefile``

Documentation/rust/general-information.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ This document contains useful information to know when working with
77
the Rust support in the kernel.
88

99

10+
``no_std``
11+
----------
12+
13+
The Rust support in the kernel can link only `core <https://doc.rust-lang.org/core/>`_,
14+
but not `std <https://doc.rust-lang.org/std/>`_. Crates for use in the
15+
kernel must opt into this behavior using the ``#![no_std]`` attribute.
16+
17+
1018
Code documentation
1119
------------------
1220

Documentation/rust/quick-start.rst

Lines changed: 100 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,93 @@ Quick Start
55

66
This document describes how to get started with kernel development in Rust.
77

8+
There are a few ways to install a Rust toolchain needed for kernel development.
9+
A simple way is to use the packages from your Linux distribution if they are
10+
suitable -- the first section below explains this approach. An advantage of this
11+
approach is that, typically, the distribution will match the LLVM used by Rust
12+
and Clang.
13+
14+
Another way is using the prebuilt stable versions of LLVM+Rust provided on
15+
`kernel.org <https://kernel.org/pub/tools/llvm/rust/>`_. These are the same slim
16+
and fast LLVM toolchains from :ref:`Getting LLVM <getting_llvm>` with versions
17+
of Rust added to them that Rust for Linux supports. Two sets are provided: the
18+
"latest LLVM" and "matching LLVM" (please see the link for more information).
19+
20+
Alternatively, the next two "Requirements" sections explain each component and
21+
how to install them through ``rustup``, the standalone installers from Rust
22+
and/or building them.
23+
24+
The rest of the document explains other aspects on how to get started.
25+
26+
27+
Distributions
28+
-------------
29+
30+
Arch Linux
31+
**********
32+
33+
Arch Linux provides recent Rust releases and thus it should generally work out
34+
of the box, e.g.::
35+
36+
pacman -S rust rust-src rust-bindgen
37+
38+
39+
Debian
40+
******
41+
42+
Debian Unstable (Sid), outside of the freeze period, provides recent Rust
43+
releases and thus it should generally work out of the box, e.g.::
44+
45+
apt install rustc rust-src bindgen rustfmt rust-clippy
46+
47+
48+
Fedora Linux
49+
************
50+
51+
Fedora Linux provides recent Rust releases and thus it should generally work out
52+
of the box, e.g.::
53+
54+
dnf install rust rust-src bindgen-cli rustfmt clippy
55+
56+
57+
Gentoo Linux
58+
************
59+
60+
Gentoo Linux (and especially the testing branch) provides recent Rust releases
61+
and thus it should generally work out of the box, e.g.::
62+
63+
USE='rust-src rustfmt clippy' emerge dev-lang/rust dev-util/bindgen
64+
65+
``LIBCLANG_PATH`` may need to be set.
66+
67+
68+
Nix
69+
***
70+
71+
Nix (unstable channel) provides recent Rust releases and thus it should
72+
generally work out of the box, e.g.::
73+
74+
{ pkgs ? import <nixpkgs> {} }:
75+
pkgs.mkShell {
76+
nativeBuildInputs = with pkgs; [ rustc rust-bindgen rustfmt clippy ];
77+
RUST_LIB_SRC = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
78+
}
79+
80+
81+
openSUSE
82+
********
83+
84+
openSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus
85+
they should generally work out of the box, e.g.::
86+
87+
zypper install rust rust1.79-src rust-bindgen clang
88+
889

990
Requirements: Building
1091
----------------------
1192

1293
This section explains how to fetch the tools needed for building.
1394

14-
Some of these requirements might be available from Linux distributions
15-
under names like ``rustc``, ``rust-src``, ``rust-bindgen``, etc. However,
16-
at the time of writing, they are likely not to be recent enough unless
17-
the distribution tracks the latest releases.
18-
1995
To easily check whether the requirements are met, the following target
2096
can be used::
2197

@@ -29,16 +105,15 @@ if that is the case.
29105
rustc
30106
*****
31107

32-
A particular version of the Rust compiler is required. Newer versions may or
33-
may not work because, for the moment, the kernel depends on some unstable
34-
Rust features.
108+
A recent version of the Rust compiler is required.
35109

36110
If ``rustup`` is being used, enter the kernel build directory (or use
37-
``--path=<build-dir>`` argument to the ``set`` sub-command) and run::
111+
``--path=<build-dir>`` argument to the ``set`` sub-command) and run,
112+
for instance::
38113

39-
rustup override set $(scripts/min-tool-version.sh rustc)
114+
rustup override set stable
40115

41-
This will configure your working directory to use the correct version of
116+
This will configure your working directory to use the given version of
42117
``rustc`` without affecting your default toolchain.
43118

44119
Note that the override applies to the current working directory (and its
@@ -65,9 +140,9 @@ version later on requires re-adding the component.
65140
Otherwise, if a standalone installer is used, the Rust source tree may be
66141
downloaded into the toolchain's installation folder::
67142

68-
curl -L "https://static.rust-lang.org/dist/rust-src-$(scripts/min-tool-version.sh rustc).tar.gz" |
143+
curl -L "https://static.rust-lang.org/dist/rust-src-$(rustc --version | cut -d' ' -f2).tar.gz" |
69144
tar -xzf - -C "$(rustc --print sysroot)/lib" \
70-
"rust-src-$(scripts/min-tool-version.sh rustc)/rust-src/lib/" \
145+
"rust-src-$(rustc --version | cut -d' ' -f2)/rust-src/lib/" \
71146
--strip-components=3
72147

73148
In this case, upgrading the Rust compiler version later on requires manually
@@ -101,26 +176,22 @@ bindgen
101176
*******
102177

103178
The bindings to the C side of the kernel are generated at build time using
104-
the ``bindgen`` tool. A particular version is required.
179+
the ``bindgen`` tool.
105180

106-
Install it via (note that this will download and build the tool from source)::
181+
Install it, for instance, via (note that this will download and build the tool
182+
from source)::
107183

108-
cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen-cli
184+
cargo install --locked bindgen-cli
109185

110-
``bindgen`` needs to find a suitable ``libclang`` in order to work. If it is
111-
not found (or a different ``libclang`` than the one found should be used),
112-
the process can be tweaked using the environment variables understood by
113-
``clang-sys`` (the Rust bindings crate that ``bindgen`` uses to access
114-
``libclang``):
186+
``bindgen`` uses the ``clang-sys`` crate to find a suitable ``libclang`` (which
187+
may be linked statically, dynamically or loaded at runtime). By default, the
188+
``cargo`` command above will produce a ``bindgen`` binary that will load
189+
``libclang`` at runtime. If it is not found (or a different ``libclang`` than
190+
the one found should be used), the process can be tweaked, e.g. by using the
191+
``LIBCLANG_PATH`` environment variable. For details, please see ``clang-sys``'s
192+
documentation at:
115193

116-
* ``LLVM_CONFIG_PATH`` can be pointed to an ``llvm-config`` executable.
117-
118-
* Or ``LIBCLANG_PATH`` can be pointed to a ``libclang`` shared library
119-
or to the directory containing it.
120-
121-
* Or ``CLANG_PATH`` can be pointed to a ``clang`` executable.
122-
123-
For details, please see ``clang-sys``'s documentation at:
194+
https://github.com/KyleMayes/clang-sys#linking
124195

125196
https://github.com/KyleMayes/clang-sys#environment-variables
126197

@@ -164,20 +235,6 @@ can be installed manually::
164235
The standalone installers also come with ``clippy``.
165236

166237

167-
cargo
168-
*****
169-
170-
``cargo`` is the Rust native build system. It is currently required to run
171-
the tests since it is used to build a custom standard library that contains
172-
the facilities provided by the custom ``alloc`` in the kernel. The tests can
173-
be run using the ``rusttest`` Make target.
174-
175-
If ``rustup`` is being used, all the profiles already install the tool,
176-
thus nothing needs to be done.
177-
178-
The standalone installers also come with ``cargo``.
179-
180-
181238
rustdoc
182239
*******
183240

Documentation/rust/testing.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ Additionally, there are the ``#[test]`` tests. These can be run using the
131131

132132
make LLVM=1 rusttest
133133

134-
This requires the kernel ``.config`` and downloads external repositories. It
135-
runs the ``#[test]`` tests on the host (currently) and thus is fairly limited in
136-
what these tests can test.
134+
This requires the kernel ``.config``. It runs the ``#[test]`` tests on the host
135+
(currently) and thus is fairly limited in what these tests can test.
137136

138137
The Kselftests
139138
--------------

Makefile

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,17 @@ KBUILD_USERLDFLAGS := $(USERLDFLAGS)
461461
# host programs.
462462
export rust_common_flags := --edition=2021 \
463463
-Zbinary_dep_depinfo=y \
464-
-Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
465-
-Dunreachable_pub -Dnon_ascii_idents \
464+
-Dunsafe_op_in_unsafe_fn \
465+
-Dnon_ascii_idents \
466+
-Wrust_2018_idioms \
467+
-Wunreachable_pub \
466468
-Wmissing_docs \
467-
-Drustdoc::missing_crate_level_docs \
468-
-Dclippy::correctness -Dclippy::style \
469-
-Dclippy::suspicious -Dclippy::complexity \
470-
-Dclippy::perf \
471-
-Dclippy::let_unit_value -Dclippy::mut_mut \
472-
-Dclippy::needless_bitwise_bool \
473-
-Dclippy::needless_continue \
474-
-Dclippy::no_mangle_with_rust_abi \
469+
-Wrustdoc::missing_crate_level_docs \
470+
-Wclippy::all \
471+
-Wclippy::mut_mut \
472+
-Wclippy::needless_bitwise_bool \
473+
-Wclippy::needless_continue \
474+
-Wclippy::no_mangle_with_rust_abi \
475475
-Wclippy::dbg_macro
476476

477477
KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
@@ -507,7 +507,6 @@ RUSTDOC = rustdoc
507507
RUSTFMT = rustfmt
508508
CLIPPY_DRIVER = clippy-driver
509509
BINDGEN = bindgen
510-
CARGO = cargo
511510
PAHOLE = pahole
512511
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
513512
LEX = flex
@@ -573,7 +572,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \
573572
-Csymbol-mangling-version=v0 \
574573
-Crelocation-model=static \
575574
-Zfunction-sections=n \
576-
-Dclippy::float_arithmetic
575+
-Wclippy::float_arithmetic
577576

578577
KBUILD_AFLAGS_KERNEL :=
579578
KBUILD_CFLAGS_KERNEL :=
@@ -601,7 +600,7 @@ endif
601600
export RUSTC_BOOTSTRAP := 1
602601

603602
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
604-
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO
603+
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
605604
export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
606605
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
607606
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
@@ -1967,9 +1966,12 @@ quiet_cmd_tags = GEN $@
19671966
tags TAGS cscope gtags: FORCE
19681967
$(call cmd,tags)
19691968

1970-
# IDE support targets
1969+
# Generate rust-project.json (a file that describes the structure of non-Cargo
1970+
# Rust projects) for rust-analyzer (an implementation of the Language Server
1971+
# Protocol).
19711972
PHONY += rust-analyzer
19721973
rust-analyzer:
1974+
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
19731975
$(Q)$(MAKE) $(build)=rust $@
19741976

19751977
# Script to generate missing namespace dependencies

drivers/base/firmware_loader/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ config FW_LOADER_DEBUG
3737
SHA256 checksums to the kernel log for each firmware file that is
3838
loaded.
3939

40+
config RUST_FW_LOADER_ABSTRACTIONS
41+
bool "Rust Firmware Loader abstractions"
42+
depends on RUST
43+
depends on FW_LOADER=y
44+
help
45+
This enables the Rust abstractions for the firmware loader API.
46+
4047
if FW_LOADER
4148

4249
config FW_LOADER_PAGED_BUF

drivers/gpu/drm/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ config DRM_VGEM
325325

326326
source "drivers/gpu/drm/vkms/Kconfig"
327327

328+
source "drivers/gpu/drm/asahi/Kconfig"
329+
328330
source "drivers/gpu/drm/exynos/Kconfig"
329331

330332
source "drivers/gpu/drm/rockchip/Kconfig"

drivers/gpu/drm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,4 @@ obj-y += solomon/
220220
obj-$(CONFIG_DRM_SPRD) += sprd/
221221
obj-$(CONFIG_DRM_LOONGSON) += loongson/
222222
obj-$(CONFIG_DRM_POWERVR) += imagination/
223+
obj-$(CONFIG_DRM_ASAHI) += asahi/

drivers/gpu/drm/asahi/Kconfig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
config RUST_DRM_SCHED
4+
bool
5+
select DRM_SCHED
6+
7+
config RUST_DRM_GEM_SHMEM_HELPER
8+
bool
9+
select DRM_GEM_SHMEM_HELPER
10+
11+
config RUST_DRM_GPUVM
12+
bool
13+
select DRM_GPUVM
14+
15+
config RUST_APPLE_RTKIT
16+
bool
17+
select APPLE_RTKIT
18+
select APPLE_MBOX
19+
20+
config DRM_ASAHI
21+
tristate "Asahi (DRM support for Apple AGX GPUs)"
22+
depends on RUST
23+
depends on DRM
24+
depends on (ARM64 && ARCH_APPLE) || (COMPILE_TEST && !GENERIC_ATOMIC64)
25+
depends on MMU
26+
select RUST_DRM_SCHED
27+
select IOMMU_SUPPORT
28+
select IOMMU_IO_PGTABLE_LPAE
29+
select RUST_DRM_GEM_SHMEM_HELPER
30+
select RUST_DRM_GPUVM
31+
select RUST_APPLE_RTKIT
32+
help
33+
DRM driver for Apple AGX GPUs (G13x, found in the M1 SoC family)
34+
35+
config DRM_ASAHI_DEBUG_ALLOCATOR
36+
bool "Use debug allocator"
37+
depends on DRM_ASAHI
38+
help
39+
Use an alternate, simpler allocator which significantly reduces
40+
performance, but can help find firmware- or GPU-side memory safety
41+
issues. However, it can also trigger firmware bugs more easily,
42+
so expect GPU crashes.
43+
44+
Say N unless you are debugging firmware structures or porting to a
45+
new firmware version.

drivers/gpu/drm/asahi/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
obj-$(CONFIG_DRM_ASAHI) += asahi.o

0 commit comments

Comments
 (0)