forked from NixOS/nixos-hardware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modesetting.nix
113 lines (98 loc) · 3.04 KB
/
modesetting.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{ config, lib, ... }:
let
cfg = config.hardware.raspberry-pi."4".fkms-3d;
in
{
options.hardware = {
raspberry-pi."4".fkms-3d = {
enable = lib.mkEnableOption ''
Enable modesetting through fkms-3d
'';
cma = lib.mkOption {
type = lib.types.int;
default = 512;
description = ''
Amount of CMA (contiguous memory allocator) to reserve, in MiB.
The foundation overlay defaults to 256MiB, for backward compatibility.
As the Raspberry Pi 4 family of hardware has ample amount of memory, we
can reserve more without issue.
Additionally, reserving too much is not an issue. The kernel will use
CMA last if the memory is needed.
'';
};
};
};
config = lib.mkIf cfg.enable {
# fixes a crash: https://github.com/raspberrypi/linux/issues/5568
# can be removed for >= nixos 23.11: https://github.com/NixOS/nixpkgs/pull/247826
boot.kernelParams = [ "kunit.enable=0" ];
# doesn't work for the CM module, so we exclude e.g. bcm2711-rpi-cm4.dts
hardware.deviceTree.filter = "bcm2711-rpi-4*.dtb";
# Configure for modesetting in the device tree
hardware.deviceTree = {
overlays = [
# Equivalent to:
# https://github.com/raspberrypi/linux/blob/rpi-6.1.y/arch/arm/boot/dts/overlays/cma-overlay.dts
{
name = "rpi4-cma-overlay";
dtsText = ''
// SPDX-License-Identifier: GPL-2.0
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&cma>;
__overlay__ {
size = <(${toString cfg.cma} * 1024 * 1024)>;
};
};
};
'';
}
# Equivalent to:
# https://github.com/raspberrypi/linux/blob/rpi-6.1.y/arch/arm/boot/dts/overlays/vc4-fkms-v3d-overlay.dts
{
name = "rpi4-vc4-fkms-v3d-overlay";
dtsText = ''
// SPDX-License-Identifier: GPL-2.0
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@1 {
target = <&fb>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&firmwarekms>;
__overlay__ {
status = "okay";
};
};
fragment@3 {
target = <&v3d>;
__overlay__ {
status = "okay";
};
};
fragment@4 {
target = <&vc4>;
__overlay__ {
status = "okay";
};
};
};
'';
}
];
};
# Also configure the system for modesetting.
services.xserver.videoDrivers = lib.mkBefore [
"modesetting" # Prefer the modesetting driver in X11
"fbdev" # Fallback to fbdev
];
};
}