Skip to content

Commit 11bfc78

Browse files
committed
Add iomem parser
Signed-off-by: quic_wya <[email protected]>
1 parent 3679ad3 commit 11bfc78

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ list(APPEND PLUGIN_SOURCES
3333
binder/binder.cpp
3434
memory/cma.cpp
3535
memory/reserved.cpp
36-
memory/memblock.cpp
36+
memory/memblock.cpp
37+
memory/iomem.cpp
3738
procrank/procrank.cpp
3839
devicetree/dts.cpp
3940
devicetree/devicetree.cpp
@@ -77,4 +78,9 @@ add_library(reserved SHARED
7778
memory/reserved.cpp
7879
devicetree/devicetree.cpp)
7980
set_target_properties(reserved PROPERTIES PREFIX "")
81+
82+
add_library(iomem SHARED
83+
${PLUGIN_SOURCES}
84+
memory/iomem.cpp)
85+
set_target_properties(iomem PROPERTIES PREFIX "")
8086
endif()

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Supprot command:
6666
| memblock ||| parser memblock info |
6767
| workqueue ||| parser workqueue info |
6868
| reserved ||| parser reserved memory info |
69+
| iomem ||| parser memory layout info |
6970
| buddy | x | x | |
7071
| vmalloc | x | x | |
7172
| dmabuf | x | x | |

memory/iomem.cpp

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
2+
// SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
#include "iomem.h"
5+
6+
#pragma GCC diagnostic push
7+
#pragma GCC diagnostic ignored "-Wpointer-arith"
8+
9+
#ifndef BUILD_TARGET_TOGETHER
10+
DEFINE_PLUGIN_COMMAND(IoMem)
11+
#endif
12+
13+
void IoMem::cmd_main(void) {
14+
int c;
15+
if (argcnt < 2) cmd_usage(pc->curcmd, SYNOPSIS);
16+
if(iomem_list.size() == 0){
17+
parser_iomem();
18+
}
19+
while ((c = getopt(argcnt, args, "a")) != EOF) {
20+
switch(c) {
21+
case 'a':
22+
print_iomem(iomem_list,0);
23+
break;
24+
default:
25+
argerrs++;
26+
break;
27+
}
28+
}
29+
if (argerrs)
30+
cmd_usage(pc->curcmd, SYNOPSIS);
31+
}
32+
33+
IoMem::IoMem(){
34+
field_init(resource,start);
35+
field_init(resource,end);
36+
field_init(resource,name);
37+
field_init(resource,flags);
38+
field_init(resource,parent);
39+
field_init(resource,sibling);
40+
field_init(resource,child);
41+
struct_init(resource);
42+
cmd_name = "iomem";
43+
help_str_list={
44+
"iomem", /* command name */
45+
"dump io memory information", /* short description */
46+
"-a \n"
47+
"\n",
48+
"EXAMPLES",
49+
" Display io memory info:",
50+
" %s> iomem -a",
51+
" 0x0-0xffffffff 4.00Gb : PCI mem",
52+
" 0x500000-0x7fffff 3.00Mb : 500000.pinctrl pinctrl@500000",
53+
" 0x1400000-0x15dffff 1.87Mb : 1400000.clock-controller cc_base",
54+
" 0x1612000-0x1612003 3b : 1613000.hsphy eud_enable_reg",
55+
" 0x1613000-0x161311f 287b : 1613000.hsphy hsusb_phy_base",
56+
" 0x1880000-0x18de1ff 376.50Kb : 1880000.interconnect interconnect@1880000",
57+
"\n",
58+
};
59+
initialize();
60+
}
61+
62+
void IoMem::print_iomem(std::vector<std::shared_ptr<resource>>& res_list,int level){
63+
char buf_size[BUFSIZE];
64+
for (const auto& res_ptr : res_list) {
65+
for (int i = 0; i < level; i++) {
66+
fprintf(fp, "\t");
67+
}
68+
convert_size((res_ptr->end - res_ptr->start),buf_size);
69+
fprintf(fp, "0x%lx-0x%lx %s : %s\n",
70+
res_ptr->start,res_ptr->end,
71+
mkstring(buf_size, 10, LJUST, buf_size),
72+
res_ptr->name.c_str());
73+
if(res_ptr->childs.size() > 0){
74+
print_iomem(res_ptr->childs,(level+1));
75+
}
76+
}
77+
}
78+
79+
void IoMem::parser_iomem(){
80+
if (csymbol_exists("iomem_resource")){
81+
parser_resource(csymbol_value("iomem_resource"),iomem_list);
82+
}
83+
}
84+
85+
void IoMem::parser_resource(ulong addr,std::vector<std::shared_ptr<resource>>& res_list){
86+
if (!is_kvaddr(addr)) return;
87+
void *res_buf = read_struct(addr,"resource");
88+
if(res_buf == nullptr) return;
89+
std::shared_ptr<resource> res_ptr = std::make_shared<resource>();
90+
res_ptr->addr = addr;
91+
ulong name_addr = ULONG(res_buf + field_offset(resource,name));
92+
res_ptr->name = read_cstring(name_addr,64, "resource_name");
93+
res_ptr->start = ULONG(res_buf + field_offset(resource,start));
94+
res_ptr->end = ULONG(res_buf + field_offset(resource,end));
95+
res_ptr->flags = ULONG(res_buf + field_offset(resource,flags));
96+
res_list.push_back(res_ptr);
97+
ulong sibling = ULONG(res_buf + field_offset(resource,sibling));
98+
if (is_kvaddr(sibling)){
99+
parser_resource(sibling,res_list);
100+
}
101+
ulong child = ULONG(res_buf + field_offset(resource,child));
102+
if (is_kvaddr(child)){
103+
parser_resource(child,res_ptr->childs);
104+
}
105+
FREEBUF(res_buf);
106+
}
107+
#pragma GCC diagnostic pop

memory/iomem.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
2+
// SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
#ifndef IOMEM_DEFS_H_
5+
#define IOMEM_DEFS_H_
6+
7+
#include "plugin.h"
8+
#include "devicetree/devicetree.h"
9+
10+
struct resource {
11+
ulong addr;
12+
ulong start;
13+
ulong end;
14+
std::string name;
15+
ulong flags;
16+
std::vector<std::shared_ptr<resource>> childs;
17+
};
18+
19+
class IoMem : public PaserPlugin {
20+
public:
21+
std::vector<std::shared_ptr<resource>> iomem_list;
22+
IoMem();
23+
void cmd_main(void) override;
24+
void parser_iomem();
25+
void print_iomem(std::vector<std::shared_ptr<resource>>& res_list,int level);
26+
void parser_resource(ulong addr,std::vector<std::shared_ptr<resource>>& res_list);
27+
DEFINE_PLUGIN_INSTANCE(IoMem)
28+
};
29+
30+
31+
#endif // IOMEM_DEFS_H_

plugins.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "devicetree/dts.h"
77
#include "memory/memblock.h"
88
#include "memory/reserved.h"
9+
#include "memory/iomem.h"
910
#include "workqueue/workqueue.h"
1011

1112
#pragma GCC diagnostic push
@@ -22,6 +23,7 @@ std::unique_ptr<Dts> Dts::instance = nullptr;
2223
std::unique_ptr<Memblock> Memblock::instance = nullptr;
2324
std::unique_ptr<Workqueue> Workqueue::instance = nullptr;
2425
std::unique_ptr<Reserved> Reserved::instance = nullptr;
26+
std::unique_ptr<IoMem> IoMem::instance = nullptr;
2527

2628
extern "C" void __attribute__((constructor)) plugin_init(void) {
2729
// fprintf(fp, "plugin_init\n");
@@ -32,6 +34,8 @@ extern "C" void __attribute__((constructor)) plugin_init(void) {
3234
Memblock::instance = std::make_unique<Memblock>();
3335
Workqueue::instance = std::make_unique<Workqueue>();
3436
Reserved::instance = std::make_unique<Reserved>();
37+
IoMem::instance = std::make_unique<IoMem>();
38+
3539
static struct command_table_entry command_table[] = {
3640
{ &Binder::instance->cmd_name[0], &Binder::wrapper_func, Binder::instance->cmd_help, 0 },
3741
{ &Procrank::instance->cmd_name[0], &Procrank::wrapper_func, Procrank::instance->cmd_help, 0 },
@@ -40,6 +44,7 @@ extern "C" void __attribute__((constructor)) plugin_init(void) {
4044
{ &Memblock::instance->cmd_name[0], &Memblock::wrapper_func, Memblock::instance->cmd_help, 0 },
4145
{ &Workqueue::instance->cmd_name[0], &Workqueue::wrapper_func, Workqueue::instance->cmd_help, 0 },
4246
{ &Reserved::instance->cmd_name[0], &Reserved::wrapper_func, Reserved::instance->cmd_help, 0 },
47+
{ &IoMem::instance->cmd_name[0], &IoMem::wrapper_func, IoMem::instance->cmd_help, 0 },
4348
{ NULL }
4449
};
4550
register_extension(command_table);
@@ -54,6 +59,7 @@ extern "C" void __attribute__((destructor)) plugin_fini(void) {
5459
Memblock::instance.reset();
5560
Workqueue::instance.reset();
5661
Reserved::instance.reset();
62+
IoMem::instance.reset();
5763
}
5864

5965
#endif // BUILD_TARGET_TOGETHER

0 commit comments

Comments
 (0)