1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Procfs for reserved memory blocks.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/init.h>
9*4882a593Smuzhiyun #include <linux/memblock.h>
10*4882a593Smuzhiyun #include <linux/proc_fs.h>
11*4882a593Smuzhiyun #include <linux/seq_file.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #define K(size) ((unsigned long)((size) >> 10))
14*4882a593Smuzhiyun
memblock_procfs_show(struct seq_file * m,void * private)15*4882a593Smuzhiyun static int memblock_procfs_show(struct seq_file *m, void *private)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun struct memblock_type *type = m->private;
18*4882a593Smuzhiyun struct memblock_region *reg;
19*4882a593Smuzhiyun int i;
20*4882a593Smuzhiyun phys_addr_t end;
21*4882a593Smuzhiyun unsigned long z = 0, t = 0;
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun for (i = 0; i < type->cnt; i++) {
24*4882a593Smuzhiyun reg = &type->regions[i];
25*4882a593Smuzhiyun end = reg->base + reg->size - 1;
26*4882a593Smuzhiyun z = (unsigned long)reg->size;
27*4882a593Smuzhiyun t += z;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun seq_printf(m, "%4d: ", i);
30*4882a593Smuzhiyun seq_printf(m, "%pa..%pa (%10lu %s)\n", ®->base, &end,
31*4882a593Smuzhiyun (z >= 1024) ? (K(z)) : z,
32*4882a593Smuzhiyun (z >= 1024) ? "KiB" : "Bytes");
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun seq_printf(m, "Total: %lu KiB\n", K(t));
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun return 0;
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun
rk_memblock_procfs_init(void)39*4882a593Smuzhiyun static int __init rk_memblock_procfs_init(void)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun struct proc_dir_entry *root = proc_mkdir("rk_memblock", NULL);
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun proc_create_single_data("memory", 0, root, memblock_procfs_show,
44*4882a593Smuzhiyun &memblock.memory);
45*4882a593Smuzhiyun proc_create_single_data("reserved", 0, root, memblock_procfs_show,
46*4882a593Smuzhiyun &memblock.reserved);
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun return 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun late_initcall_sync(rk_memblock_procfs_init);
51