]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpu: Move DRM buddy allocator one level up (part one)
authorJoel Fernandes <joelagnelf@nvidia.com>
Thu, 5 Feb 2026 22:52:38 +0000 (08:52 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 6 Feb 2026 01:34:02 +0000 (11:34 +1000)
Move the DRM buddy allocator one level up so that it can be used by GPU
drivers (example, nova-core) that have usecases other than DRM (such as
VFIO vGPU support). Modify the API, structures and Kconfigs to use
"gpu_buddy" terminology. Adapt the drivers and tests to use the new API.

The commit cannot be split due to bisectability, however no functional
change is intended. Verified by running K-UNIT tests and build tested
various configurations.

Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
[airlied: I've split this into two so git can find copies easier.
I've also just nuked drm_random library, that stuff needs to be done
elsewhere and only the buddy tests seem to be using it].
Signed-off-by: Dave Airlie <airlied@redhat.com>
20 files changed:
Documentation/gpu/drm-mm.rst
drivers/gpu/Makefile
drivers/gpu/buddy.c [moved from drivers/gpu/drm/drm_buddy.c with 99% similarity]
drivers/gpu/drm/Kconfig
drivers/gpu/drm/Kconfig.debug
drivers/gpu/drm/Makefile
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
drivers/gpu/drm/i915/gem/i915_gem_ttm.c
drivers/gpu/drm/i915/i915_scatterlist.c
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
drivers/gpu/drm/tests/Makefile
drivers/gpu/drm/tests/drm_exec_test.c
drivers/gpu/drm/tests/drm_mm_test.c
drivers/gpu/drm/ttm/tests/ttm_mock_manager.h
drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
drivers/gpu/tests/Makefile [new file with mode: 0644]
drivers/gpu/tests/gpu_buddy_test.c [moved from drivers/gpu/drm/tests/drm_buddy_test.c with 99% similarity]
drivers/gpu/tests/gpu_random.c [moved from drivers/gpu/drm/lib/drm_random.c with 97% similarity]
drivers/gpu/tests/gpu_random.h [moved from drivers/gpu/drm/lib/drm_random.h with 100% similarity]
include/linux/gpu_buddy.h [moved from include/drm/drm_buddy.h with 100% similarity]

index f22433470c7614745bea7f8d087688a7e35da9ee..ceee0e6632373cb8944be872fb613991ecc139c6 100644 (file)
@@ -526,10 +526,10 @@ DRM GPUVM Function References
 DRM Buddy Allocator
 ===================
 
-DRM Buddy Function References
------------------------------
+Buddy Allocator Function References (GPU buddy)
+-----------------------------------------------
 
-.. kernel-doc:: drivers/gpu/drm/drm_buddy.c
+.. kernel-doc:: drivers/gpu/buddy.c
    :export:
 
 DRM Cache Handling and Fast WC memcpy()
index 36a54d45663030c33405e297868a41c2d287c224..c5292ee2c85245782e2cc4380f9a714b57cf82d9 100644 (file)
@@ -2,7 +2,7 @@
 # drm/tegra depends on host1x, so if both drivers are built-in care must be
 # taken to initialize them in the correct order. Link order is the only way
 # to ensure this currently.
-obj-y                  += host1x/ drm/ vga/
+obj-y                  += host1x/ drm/ vga/ tests/
 obj-$(CONFIG_IMX_IPUV3_CORE)   += ipu-v3/
 obj-$(CONFIG_TRACE_GPU_MEM)            += trace/
 obj-$(CONFIG_NOVA_CORE)                += nova-core/
similarity index 99%
rename from drivers/gpu/drm/drm_buddy.c
rename to drivers/gpu/buddy.c
index fd34d3755f7c5c9bb648fa1c3b71a617c990ecc9..4cc63d961d261ce2d5b2edfc84fc58b9e9a167d7 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/module.h>
 #include <linux/sizes.h>
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 #include <drm/drm_print.h>
 
 enum drm_buddy_free_tree {
index 5888eb147ed14ae81912fbae25448d6155dded31..862ff4000969a2cec81f0538a53d5602ab8cc911 100644 (file)
@@ -269,10 +269,6 @@ config DRM_SCHED
 config DRM_PANEL_BACKLIGHT_QUIRKS
        tristate
 
-config DRM_LIB_RANDOM
-       bool
-       default n
-
 config DRM_PRIVACY_SCREEN
        bool
        default n
index 05dc43c0b8c5af4fe2a1a615e5c607d466758b30..3b7886865335a353330d39074b6bbf62aa9dde4d 100644 (file)
@@ -69,7 +69,6 @@ config DRM_KUNIT_TEST
        select DRM_EXPORT_FOR_TESTS if m
        select DRM_GEM_SHMEM_HELPER
        select DRM_KUNIT_TEST_HELPERS
-       select DRM_LIB_RANDOM
        select DRM_SYSFB_HELPER
        select PRIME_NUMBERS
        default KUNIT_ALL_TESTS
index 75840ec4d78226b27c2a3116391c449b36b5bde1..892859cfe95fe480951783029052d0f0eebf1be6 100644 (file)
@@ -79,7 +79,6 @@ drm-$(CONFIG_DRM_CLIENT) += \
        drm_client_event.o \
        drm_client_modeset.o \
        drm_client_sysrq.o
-drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o
@@ -115,7 +114,7 @@ drm_gpusvm_helper-$(CONFIG_ZONE_DEVICE) += \
 
 obj-$(CONFIG_DRM_GPUSVM) += drm_gpusvm_helper.o
 
-obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
+obj-$(CONFIG_DRM_BUDDY) += ../buddy.o
 
 drm_dma_helper-y := drm_gem_dma_helper.o
 drm_dma_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fbdev_dma.o
index 5f5fd9a911c2680610eba5bdfd0b2d32811103e9..8747796180565be483f2727b94218618b79f5b24 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef __AMDGPU_VRAM_MGR_H__
 #define __AMDGPU_VRAM_MGR_H__
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 
 struct amdgpu_vram_mgr {
        struct ttm_resource_manager manager;
index f65fe86c02b5b316a24872f57f32a6fb112b7988..eeda5daa544f0f374636abc679b228affc09adaf 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <linux/shmem_fs.h>
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 #include <drm/drm_print.h>
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_tt.h>
index 4d830740946da39d9f690bbb1daa86814ea3a1ac..30246f02bcfe793631819e7c17ca7a1e67203344 100644 (file)
@@ -7,7 +7,7 @@
 #include "i915_scatterlist.h"
 #include "i915_ttm_buddy_manager.h"
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 #include <drm/drm_mm.h>
 
 #include <linux/slab.h>
index d5c6e6605086fec49634deb034ce2986ab5b6c37..6b256d95badda36cc083d06bb70f483b60ecb2b7 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <linux/slab.h>
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 #include <drm/drm_print.h>
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_bo.h>
index 87d5d5f9332acbf730bd28c1de049a6855167c9b..d2e2e3d8349aee4189209ccfd15039baa1a2f0a9 100644 (file)
@@ -7,7 +7,6 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \
        drm_atomic_test.o \
        drm_atomic_state_test.o \
        drm_bridge_test.o \
-       drm_buddy_test.o \
        drm_cmdline_parser_test.o \
        drm_connector_test.o \
        drm_damage_helper_test.o \
index 3a20c788c51f89719207e096d28a184ee84909bf..2fc47f3b463b7e99b2ac5773683d5ffc333f03b6 100644 (file)
@@ -16,8 +16,6 @@
 #include <drm/drm_gem.h>
 #include <drm/drm_kunit_helpers.h>
 
-#include "../lib/drm_random.h"
-
 struct drm_exec_priv {
        struct device *dev;
        struct drm_device *drm;
index aec9eccdeae9e0bd8e0f4fda1cec9b562a99c6c9..e24a619059d85a3f57b768560acfab5207da02be 100644 (file)
@@ -16,8 +16,6 @@
 #include <drm/drm_mm.h>
 #include <drm/drm_print.h>
 
-#include "../lib/drm_random.h"
-
 enum {
        BEST,
        BOTTOMUP,
index e4c95f86a4670aca2a35c8b3d4bfc5314cca5b79..96ea8c9aae343314d87f1fdb4f162f2d8cc5ae13 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef TTM_MOCK_MANAGER_H
 #define TTM_MOCK_MANAGER_H
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 
 struct ttm_mock_manager {
        struct ttm_resource_manager man;
index a71e14818ec2a6c4685f0292bd368966ee0a462a..babeec5511d944de41bef5ae44e913de1de130b3 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef _XE_TTM_VRAM_MGR_TYPES_H_
 #define _XE_TTM_VRAM_MGR_TYPES_H_
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 #include <drm/ttm/ttm_device.h>
 
 /**
diff --git a/drivers/gpu/tests/Makefile b/drivers/gpu/tests/Makefile
new file mode 100644 (file)
index 0000000..8e7654e
--- /dev/null
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+gpu_buddy_tests-y = gpu_buddy_test.o gpu_random.o
+obj-$(CONFIG_DRM_KUNIT_TEST) += gpu_buddy_tests.o
similarity index 99%
rename from drivers/gpu/drm/tests/drm_buddy_test.c
rename to drivers/gpu/tests/gpu_buddy_test.c
index e6f8459c6c54e321713afa56af92b8fe04f13c98..b905932da9905ddf59f0810a0a12c9d564732c23 100644 (file)
@@ -10,9 +10,9 @@
 #include <linux/sched/signal.h>
 #include <linux/sizes.h>
 
-#include <drm/drm_buddy.h>
+#include <linux/gpu_buddy.h>
 
-#include "../lib/drm_random.h"
+#include "gpu_random.h"
 
 static unsigned int random_seed;
 
similarity index 97%
rename from drivers/gpu/drm/lib/drm_random.c
rename to drivers/gpu/tests/gpu_random.c
index 0e9dba1ef4af51c0a683385105d726f826d42d7a..ddd1f594b5d5b1970de467854eaba24a7ec92699 100644 (file)
@@ -6,7 +6,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 
-#include "drm_random.h"
+#include "gpu_random.h"
 
 u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
 {