|
1 | 1 | # drm-kmod
|
2 |
| -The DRM drivers ported from Linux to FreeBSD using LinuxKPI |
3 | 2 |
|
4 |
| -## Contributing |
| 3 | +The DRM drivers ported from Linux to FreeBSD using *linuxkpi*. |
| 4 | + |
| 5 | +## Installing from sources |
| 6 | + |
| 7 | +### Requirements |
| 8 | + |
| 9 | +You need to have the sources of FreeBSD kernel available and they MUST |
| 10 | +correspond to the installed version of FreeBSD. |
| 11 | + |
| 12 | +There are several ways to get them: |
| 13 | +* by using the FreeBSD installer |
| 14 | +* by using the `FreeBSD-src-sys` package if you use PkgBase |
| 15 | +* by cloning the Git repository from https://git.FreeBSD.org/src.git or any mirror |
5 | 16 |
|
6 |
| -### Linux source code |
7 |
| -Folders `amd`, `drm`, `i915`, `radeon` contain FreeBSD Makefiles for the driver modules. |
| 17 | +By default, Makefiles expect the sources of the kernel to be in `/usr/src/sys`. |
| 18 | +The installer and the PkgBase package will install them in that directory. If |
| 19 | +you clone from Git, you can set `SYSDIR=/path/to/FreeBSD/src/sys` on the |
| 20 | +make(1) command line or in the environment when compiling the drivers and their |
| 21 | +firmwares. |
8 | 22 |
|
9 |
| -Folder `drivers` contain source code from Linux, patched (minimally) to run on FreeBSD with LinuxKPI. |
10 |
| -Try to keep changes to the code to a minimum but if you have to patch it, leave the Linux source code intact like so: |
| 23 | +### Building |
11 | 24 |
|
| 25 | +```sh |
| 26 | +make -j12 DEBUG_FLAGS=-g SYSDIR=/usr/src/sys |
12 | 27 | ```
|
13 |
| -#ifdef __linux__ |
14 |
| -...intact linux code... |
15 |
| -#elif defined(__FreeBSD__) |
16 |
| -bsd code |
17 |
| -#endif |
| 28 | + |
| 29 | +As stated in the requirements section, set `SYSDIR` to the location where you |
| 30 | +put the FreeBSD kernel sources. The example above shows the default value. |
| 31 | + |
| 32 | +### Installing |
| 33 | + |
| 34 | +```sh |
| 35 | +sudo make install DEBUG_FLAGS=-g SYSDIR=/usr/src/sys KMODDIR=/boot/modules |
18 | 36 | ```
|
19 | 37 |
|
20 |
| -When updating and patching this code with code from Linux there are often merge conflicts where the code has been changed. If there are no markers it is difficult to know what code to keep and what to throw away. |
| 38 | +As stated in the requirements section, set `SYSDIR` to the location where you |
| 39 | +put the FreeBSD kernel sources. The example above shows the default value. |
| 40 | + |
| 41 | +Likewise, set `KMODDIR` to the location of the kernel you want to install the |
| 42 | +drivers for. The example above shows the default value which is the global |
| 43 | +directory, used by all installed kernels |
| 44 | + |
| 45 | +> [!IMPORTANT] |
| 46 | +> The DRM drivers MUST be compiled against the kernel sources corresponding to |
| 47 | +> the installed kernel you want to use them with. |
| 48 | +
|
| 49 | +### GPU firmwares |
| 50 | + |
| 51 | +DRM drivers depend on binary firmwares. They are maintained in a separate Git |
| 52 | +repository at https://github.com/freebsd/drm-kmod-firmware. |
| 53 | + |
| 54 | +The binary firmwares are packaged into kernel modules and loaded automatically |
| 55 | +by the DRM drivers when needed. |
| 56 | + |
| 57 | +The kernel modules can be compiled by following the same instructions as the |
| 58 | +DRM drivers. The same constraint applies: use the matching kernel sources. |
| 59 | + |
| 60 | +## Contributing |
| 61 | + |
| 62 | +> [!TIP] |
| 63 | +> This part is a TL;DR version of the porting process. For the full version, |
| 64 | +> please visit |
| 65 | +> https://github.com/freebsd/drm-kmod/wiki/Porting-a-new-version-of-DRM-drivers-from-Linux. |
| 66 | +
|
| 67 | +1. Clone Linux: |
| 68 | + |
| 69 | + ```sh |
| 70 | + git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git /path/to/linux-src |
| 71 | + ``` |
| 72 | + |
| 73 | +2. Extract Linux patches: |
21 | 74 |
|
22 |
| -Pull requests that do not follow this will not be accepted. |
| 75 | + ```sh |
| 76 | + ./scripts/drmgeneratepatch \ |
| 77 | + /path/to/linux-src \ |
| 78 | + /path/to/patches-6.7 \ |
| 79 | + v6.6..v6.7 |
| 80 | + ``` |
23 | 81 |
|
24 |
| -Unless obvious what your code does, please leave a comment to explain to fellow developers why you patched it. The source code is the documentation! |
| 82 | +3. Filter out already applied patches: |
25 | 83 |
|
26 |
| -If the patch can be avoided by adding functionality to LinuxKPI, please consider the latter. Sooner or later, there will be more places where the functionality is used and having it in LinuxKPI mean we don't have to patch twice. |
| 84 | + ```sh |
| 85 | + ./scripts/drmcheckapplied /path/to/patches-6.7 |
| 86 | + ``` |
27 | 87 |
|
28 |
| -### FreeBSD source code |
29 |
| -Folders `linuxkpi` |
| 88 | +4. Apply patches to `drm-kmod`: |
30 | 89 |
|
31 |
| -Code style and rules same as FreeBSD kernel. |
32 |
| -No new code should be added there, all new linuxkpi functions should be |
33 |
| -added in FreeBSD base. |
| 90 | + ```sh |
| 91 | + ./scripts/drmpatch /path/to/patches-6.7 |
| 92 | + ``` |
0 commit comments