1 /* 2 * HND Run Time Environment debug info area 3 * 4 * Copyright (C) 2020, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef _HND_DEBUG_H 25 #define _HND_DEBUG_H 26 27 /* Magic number at a magic location to find HND_DEBUG pointers */ 28 #define HND_DEBUG_PTR_PTR_MAGIC 0x50504244u /* DBPP */ 29 30 #ifndef _LANGUAGE_ASSEMBLY 31 32 #include <typedefs.h> 33 34 /* Includes only when building dongle code */ 35 #ifdef _RTE_ 36 #include <event_log.h> 37 #include <hnd_trap.h> 38 #include <hnd_cons.h> 39 #endif 40 41 /* We use explicit sizes here since this gets included from different 42 * systems. The sizes must be the size of the creating system 43 * (currently 32 bit ARM) since this is gleaned from dump. 44 */ 45 46 #ifdef FWID 47 extern uint32 gFWID; 48 #endif 49 50 enum hnd_debug_reloc_entry_type { 51 HND_DEBUG_RELOC_ENTRY_TYPE_ROM = 0u, 52 HND_DEBUG_RELOC_ENTRY_TYPE_RAM = 1u, 53 HND_DEBUG_RELOC_ENTRY_TYPE_MTH_STACK = 2u, /* main thread stack */ 54 }; 55 typedef uint32 hnd_debug_reloc_entry_type_t; 56 57 typedef struct hnd_debug_reloc_entry { 58 /* Identifies the type(hnd_debug_reloc_entry_type) of the data */ 59 hnd_debug_reloc_entry_type_t type; 60 uint32 phys_addr; /* Physical address */ 61 uint32 virt_addr; /* Virtual address */ 62 uint32 size; /* Specifies the size of the segment */ 63 } hnd_debug_reloc_entry_t; 64 65 #ifdef _RTE_ 66 /* Define pointers for normal ARM use */ 67 #define _HD_EVLOG_P event_log_top_t * 68 #define _HD_CONS_P hnd_cons_t * 69 #define _HD_TRAP_P trap_t * 70 #define _HD_DEBUG_RELOC_ENTRY_P hnd_debug_reloc_entry_t * 71 #define _HD_DEBUG_RELOC_P hnd_debug_reloc_t * 72 73 #else 74 /* Define pointers for use on other systems */ 75 #define _HD_EVLOG_P uint32 76 #define _HD_CONS_P uint32 77 #define _HD_TRAP_P uint32 78 #define _HD_DEBUG_RELOC_ENTRY_P uint32 79 #define _HD_DEBUG_RELOC_P uint32 80 81 #endif /* _RTE_ */ 82 83 /* MMU relocation info in the debug area */ 84 typedef struct hnd_debug_reloc { 85 _HD_DEBUG_RELOC_ENTRY_P hnd_reloc_ptr; /* contains the pointer to the MMU reloc table */ 86 uint32 hnd_reloc_ptr_size; /* Specifies the size of the MMU reloc table */ 87 } hnd_debug_reloc_t; 88 89 /* Number of MMU relocation entries supported in v2 */ 90 #define RELOC_NUM_ENTRIES 4u 91 92 /* Total MMU relocation table size for v2 */ 93 #define HND_DEBUG_RELOC_PTR_SIZE (RELOC_NUM_ENTRIES * sizeof(hnd_debug_reloc_entry_t)) 94 95 #define HND_DEBUG_VERSION_1 1u /* Legacy, version 1 */ 96 #define HND_DEBUG_VERSION_2 2u /* Version 2 contains the MMU information 97 * used for stack virtualization, etc. 98 */ 99 100 /* Legacy debug version for older branches. */ 101 #define HND_DEBUG_VERSION HND_DEBUG_VERSION_1 102 103 /* This struct is placed at a well-defined location, and contains a pointer to hnd_debug. */ 104 typedef struct hnd_debug_ptr { 105 uint32 magic; 106 107 /* RAM address of 'hnd_debug'. For legacy versions of this struct, it is a 0-indexed 108 * offset instead. 109 */ 110 uint32 hnd_debug_addr; 111 112 /* Base address of RAM. This field does not exist for legacy versions of this struct. */ 113 uint32 ram_base_addr; 114 115 } hnd_debug_ptr_t; 116 extern hnd_debug_ptr_t debug_info_ptr; 117 118 #define HND_DEBUG_EPIVERS_MAX_STR_LEN 32u 119 120 /* chip id string is 8 bytes long with null terminator. Example 43452a3 */ 121 #define HND_DEBUG_BUILD_SIGNATURE_CHIPID_LEN 13u 122 123 #define HND_DEBUG_BUILD_SIGNATURE_FWID_LEN 17u 124 125 /* ver=abc.abc.abc.abcdefgh size = 24bytes. 6 bytes extra for expansion */ 126 #define HND_DEBUG_BUILD_SIGNATURE_VER_LEN 30u 127 128 typedef struct hnd_debug { 129 uint32 magic; 130 #define HND_DEBUG_MAGIC 0x47424544u /* 'DEBG' */ 131 132 #ifndef HND_DEBUG_USE_V2 133 uint32 version; /* Legacy, debug struct version */ 134 #else 135 /* Note: The original uint32 version is split into two fields: 136 * uint16 version and uint16 length to accomidate future expansion 137 * of the strucutre. 138 * 139 * The length field is not populated for the version 1 of the structure. 140 */ 141 uint16 version; /* Debug struct version */ 142 uint16 length; /* Size of the whole structure in bytes */ 143 #endif /* HND_DEBUG_USE_V2 */ 144 145 uint32 fwid; /* 4 bytes of fw info */ 146 char epivers[HND_DEBUG_EPIVERS_MAX_STR_LEN]; 147 148 _HD_TRAP_P PHYS_ADDR_N(trap_ptr); /* trap_t data struct physical address. */ 149 _HD_CONS_P PHYS_ADDR_N(console); /* Console physical address. */ 150 151 uint32 ram_base; 152 uint32 ram_size; 153 154 uint32 rom_base; 155 uint32 rom_size; 156 157 _HD_EVLOG_P event_log_top; /* EVENT_LOG address. */ 158 159 /* To populated fields below, 160 * INCLUDE_BUILD_SIGNATURE_IN_SOCRAM needs to be enabled 161 */ 162 char fwid_signature[HND_DEBUG_BUILD_SIGNATURE_FWID_LEN]; /* fwid=<FWID> */ 163 /* ver=abc.abc.abc.abcdefgh size = 24bytes. 6 bytes extra for expansion */ 164 char ver_signature[HND_DEBUG_BUILD_SIGNATURE_VER_LEN]; 165 char chipid_signature[HND_DEBUG_BUILD_SIGNATURE_CHIPID_LEN]; /* chip=12345a3 */ 166 167 #ifdef HND_DEBUG_USE_V2 168 /* Version 2 fields */ 169 /* Specifies the hnd debug MMU info */ 170 _HD_DEBUG_RELOC_P hnd_debug_reloc_ptr; 171 #endif /* HND_DEBUG_USE_V2 */ 172 } hnd_debug_t; 173 174 #ifdef HND_DEBUG_USE_V2 175 #define HND_DEBUG_V1_SIZE (OFFSETOF(hnd_debug_t, chipid_signature) + \ 176 sizeof(((hnd_debug_t *)0)->chipid_signature)) 177 178 #define HND_DEBUG_V2_BASE_SIZE (OFFSETOF(hnd_debug_t, hnd_debug_reloc_ptr) + \ 179 sizeof(((hnd_debug_t *)0)->hnd_debug_reloc_ptr)) 180 #endif /* HND_DEBUG_USE_V2 */ 181 182 /* The following structure is used in populating build information */ 183 typedef struct hnd_build_info { 184 uint8 version; /* Same as HND_DEBUG_VERSION */ 185 uint8 rsvd[3]; /* Reserved fields for padding purposes */ 186 /* To populated fields below, 187 * INCLUDE_BUILD_SIGNATURE_IN_SOCRAM needs to be enabled 188 */ 189 uint32 fwid; 190 uint32 ver[4]; 191 char chipid_signature[HND_DEBUG_BUILD_SIGNATURE_CHIPID_LEN]; /* chip=12345a3 */ 192 } hnd_build_info_t; 193 194 /* 195 * timeval_t and prstatus_t are copies of the Linux structures. 196 * Included here because we need the definitions for the target processor 197 * (32 bits) and not the definition on the host this is running on 198 * (which could be 64 bits). 199 */ 200 201 typedef struct { /* Time value with microsecond resolution */ 202 uint32 tv_sec; /* Seconds */ 203 uint32 tv_usec; /* Microseconds */ 204 } timeval_t; 205 206 /* Linux/ARM 32 prstatus for notes section */ 207 typedef struct prstatus { 208 int32 si_signo; /* Signal number */ 209 int32 si_code; /* Extra code */ 210 int32 si_errno; /* Errno */ 211 uint16 pr_cursig; /* Current signal. */ 212 uint16 unused; 213 uint32 pr_sigpend; /* Set of pending signals. */ 214 uint32 pr_sighold; /* Set of held signals. */ 215 uint32 pr_pid; 216 uint32 pr_ppid; 217 uint32 pr_pgrp; 218 uint32 pr_sid; 219 timeval_t pr_utime; /* User time. */ 220 timeval_t pr_stime; /* System time. */ 221 timeval_t pr_cutime; /* Cumulative user time. */ 222 timeval_t pr_cstime; /* Cumulative system time. */ 223 uint32 uregs[18]; 224 int32 pr_fpvalid; /* True if math copro being used. */ 225 } prstatus_t; 226 227 /* for mkcore and other utilities use */ 228 #define DUMP_INFO_PTR_PTR_0 0x74 229 #define DUMP_INFO_PTR_PTR_1 0x78 230 #define DUMP_INFO_PTR_PTR_2 0xf0 231 #define DUMP_INFO_PTR_PTR_3 0xf8 232 #define DUMP_INFO_PTR_PTR_4 0x874 233 #define DUMP_INFO_PTR_PTR_5 0x878 234 #define DUMP_INFO_PTR_PTR_END 0xffffffff 235 #define DUMP_INFO_PTR_PTR_LIST DUMP_INFO_PTR_PTR_0, \ 236 DUMP_INFO_PTR_PTR_1, \ 237 DUMP_INFO_PTR_PTR_2, \ 238 DUMP_INFO_PTR_PTR_3, \ 239 DUMP_INFO_PTR_PTR_4, \ 240 DUMP_INFO_PTR_PTR_5, \ 241 DUMP_INFO_PTR_PTR_END 242 243 extern bool hnd_debug_info_in_trap_context(void); 244 245 /* Get build information. */ 246 extern int hnd_build_info_get(void *ctx, void *arg2, uint32 *buf, uint16 *len); 247 248 #endif /* !LANGUAGE_ASSEMBLY */ 249 250 #endif /* _HND_DEBUG_H */ 251