Skip to content

Commit

Permalink
drm, bpf: Move drm_mm.c to lib to be used by bpf arena
Browse files Browse the repository at this point in the history
Move drm_mm.c to lib. The next commit will use drm_mm to manage
memory regions in bpf arena. Move drm_mm_print to
drivers/gpu/drm/drm_print.c, since it's not a core functionality
of drm_mm and it depeneds on drm_printer while drm_mm is
generic and usuable as-is by other subsystems.
Also add __maybe_unused to suppress compiler warnings.
Update MAINTAINERS file as well.

Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Kumar Kartikeya Dwivedi <[email protected]>
  • Loading branch information
Alexei Starovoitov authored and Kernel Patches Daemon committed Nov 3, 2024
1 parent a37c487 commit 5ae897b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -7504,6 +7504,7 @@ F: drivers/gpu/vga/
F: include/drm/drm
F: include/linux/vga*
F: include/uapi/drm/
F: lib/drm_mm.c
X: drivers/gpu/drm/amd/
X: drivers/gpu/drm/armada/
X: drivers/gpu/drm/etnaviv/
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ drm-y := \
drm_ioctl.o \
drm_lease.o \
drm_managed.o \
drm_mm.o \
drm_mode_config.o \
drm_mode_object.o \
drm_modes.o \
Expand Down
39 changes: 39 additions & 0 deletions drivers/gpu/drm/drm_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <drm/drm.h>
#include <drm/drm_drv.h>
#include <drm/drm_print.h>
#include <drm/drm_mm.h>

/*
* __drm_debug: Enable debug output.
Expand Down Expand Up @@ -267,6 +268,44 @@ void drm_printf(struct drm_printer *p, const char *f, ...)
}
EXPORT_SYMBOL(drm_printf);

static u64 drm_mm_dump_hole(struct drm_printer *p, const struct drm_mm_node *entry)
{
u64 start, size;

size = entry->hole_size;
if (size) {
start = drm_mm_hole_node_start(entry);
drm_printf(p, "%#018llx-%#018llx: %llu: free\n",
start, start + size, size);
}

return size;
}
/**
* drm_mm_print - print allocator state
* @mm: drm_mm allocator to print
* @p: DRM printer to use
*/
void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p)
{
const struct drm_mm_node *entry;
u64 total_used = 0, total_free = 0, total = 0;

total_free += drm_mm_dump_hole(p, &mm->head_node);

drm_mm_for_each_node(entry, mm) {
drm_printf(p, "%#018llx-%#018llx: %llu: used\n", entry->start,
entry->start + entry->size, entry->size);
total_used += entry->size;
total_free += drm_mm_dump_hole(p, entry);
}
total = total_free + total_used;

drm_printf(p, "total: %llu, used %llu free %llu\n", total,
total_used, total_free);
}
EXPORT_SYMBOL(drm_mm_print);

/**
* drm_print_bits - print bits to a &drm_printer stream
*
Expand Down
1 change: 1 addition & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
obj-y += kstrtox.o
obj-$(CONFIG_FIND_BIT_BENCHMARK) += find_bit_benchmark.o
obj-$(CONFIG_TEST_BPF) += test_bpf.o
obj-$(CONFIG_DRM) += drm_mm.o
test_dhry-objs := dhry_1.o dhry_2.o dhry_run.o
obj-$(CONFIG_TEST_DHRY) += test_dhry.o
obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
Expand Down
40 changes: 1 addition & 39 deletions drivers/gpu/drm/drm_mm.c → lib/drm_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static void show_leaks(struct drm_mm *mm) { }

INTERVAL_TREE_DEFINE(struct drm_mm_node, rb,
u64, __subtree_last,
START, LAST, static inline, drm_mm_interval_tree)
START, LAST, static inline __maybe_unused, drm_mm_interval_tree)

struct drm_mm_node *
__drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last)
Expand Down Expand Up @@ -966,41 +966,3 @@ void drm_mm_takedown(struct drm_mm *mm)
show_leaks(mm);
}
EXPORT_SYMBOL(drm_mm_takedown);

static u64 drm_mm_dump_hole(struct drm_printer *p, const struct drm_mm_node *entry)
{
u64 start, size;

size = entry->hole_size;
if (size) {
start = drm_mm_hole_node_start(entry);
drm_printf(p, "%#018llx-%#018llx: %llu: free\n",
start, start + size, size);
}

return size;
}
/**
* drm_mm_print - print allocator state
* @mm: drm_mm allocator to print
* @p: DRM printer to use
*/
void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p)
{
const struct drm_mm_node *entry;
u64 total_used = 0, total_free = 0, total = 0;

total_free += drm_mm_dump_hole(p, &mm->head_node);

drm_mm_for_each_node(entry, mm) {
drm_printf(p, "%#018llx-%#018llx: %llu: used\n", entry->start,
entry->start + entry->size, entry->size);
total_used += entry->size;
total_free += drm_mm_dump_hole(p, entry);
}
total = total_free + total_used;

drm_printf(p, "total: %llu, used %llu free %llu\n", total,
total_used, total_free);
}
EXPORT_SYMBOL(drm_mm_print);

0 comments on commit 5ae897b

Please sign in to comment.