hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Procfs for reserved memory blocks.
 *
 * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
 */
 
#include <linux/init.h>
#include <linux/memblock.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
 
#define K(size) ((unsigned long)((size) >> 10))
 
static int memblock_procfs_show(struct seq_file *m, void *private)
{
   struct memblock_type *type = m->private;
   struct memblock_region *reg;
   int i;
   phys_addr_t end;
   unsigned long z = 0, t = 0;
 
   for (i = 0; i < type->cnt; i++) {
       reg = &type->regions[i];
       end = reg->base + reg->size - 1;
       z = (unsigned long)reg->size;
       t += z;
 
       seq_printf(m, "%4d: ", i);
       seq_printf(m, "%pa..%pa (%10lu %s)\n", &reg->base, &end,
              (z >= 1024) ? (K(z)) : z,
              (z >= 1024) ? "KiB" : "Bytes");
   }
   seq_printf(m, "Total: %lu KiB\n", K(t));
 
   return 0;
}
 
static int __init rk_memblock_procfs_init(void)
{
   struct proc_dir_entry *root = proc_mkdir("rk_memblock", NULL);
 
   proc_create_single_data("memory", 0, root, memblock_procfs_show,
       &memblock.memory);
   proc_create_single_data("reserved", 0, root, memblock_procfs_show,
       &memblock.reserved);
 
   return 0;
}
late_initcall_sync(rk_memblock_procfs_init);