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