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