|
| 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 |
0 commit comments