• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/arch/arm/include/asm/
1/*
2 *
3 * Broadcom Buzzz based Kernel Profiling and Debugging
4 *
5 * Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $Id$
20 *
21 */
22
23/*
24 * -----------------------------------------------------------------------------
25 * Filename     : buzzz.h
26 * Description  : Exported interface for buzzz.
27 *                This header file is shared by kernel driver and user mode CLI.
28 *                All kernel mode code must be placed in ifdef __KERNEL__.
29 *
30 * Kernel Config:
31 *      Config BUZZZ: Enable Buzzz and performance monitoring build
32 *      Config BUZZZ_FUNC: Enables Function call tracing build
33 *      Config BUZZZ_KECT: Enable kerbel event tracing
34 *  When Function call tracing or kernel event tracing is enabled, performance
35 *  monitoring may not be used.
36 *
37 * Pre-build requirement:
38 *  Configure the BUZZZ_CYCLES_PER_USEC processor clock speed.
39 *  Configure the Event tracing level: BUZZZ_KEVT_LVL and BUZZZ_KEVT_DPL
40 *
41 * -----------------------------------------------------------------------------
42 */
43#ifndef _BUZZZ_H_INCLUDED_
44#define _BUZZZ_H_INCLUDED_
45
46/*
47 * BUZZZ Subsystem Configuration
48 *
49 * - BUZZZ_CONFIG_UNITTEST: Enables kcall based unittest of buzzz subsystems.
50 * - BUZZZ_CONFIG_SYS_KDBG: Enables debugging of buzzz kernel subsystems.
51 * - BUZZZ_CONFIG_SYS_UDBG: Enables debugging of buzzz user cli subsystem.
52 * - BUZZZ_CONFIG_COLOR_EN: Enables color printing to console.
53 *
54 * - BUZZZ_CONFIG_PMON_USR: Enables logging of a user counter in PMON
55 *
56 * To disable, comment out the corresponding BUZZZ_CONFIG_XYZ defines.
57 */
58#define BUZZZ_CONFIG_UNITTEST
59/* #define BUZZZ_CONFIG_SYS_KDBG */
60/* #define BUZZZ_CONFIG_SYS_UDBG */
61#define BUZZZ_CONFIG_COLOR_EN
62#define BUZZZ_CONFIG_PMON_USR
63
64/* Enable only one CPU family */
65#if defined(CONFIG_MIPS)
66#define BUZZZ_CONFIG_CPU_MIPS_74K   /* MIPS74k */
67#define BUZZZ_CYCLES_PER_USEC   (600)
68#endif  /*  CONFIG_MIPS */
69
70#if defined(CONFIG_ARM)
71#define BUZZZ_CONFIG_CPU_ARMV7_A9   /* ARMv7 Cortex A9 CPU */
72#define BUZZZ_CYCLES_PER_USEC   (800)
73#define BUZZZ_KEVT_NANOSECS     (50) /* overhead subtracted per event */
74#endif  /*  CONFIG_ARM */
75
76/* Linux Kernel and Driver Datapath Tracing Levels */
77#if defined(CONFIG_BUZZZ_KEVT)
78#define BUZZZ_KEVT_LVL          3       /* Kernel tracing level */
79#define BUZZZ_KEVT_DPL          5       /* Datapath tracing level */
80#endif  /*  CONFIG_BUZZZ_KEVT */
81
82/* -------------------------------------------------------------------------- */
83
84#define BUZZZ_NAME              "buzzz"
85
86#define BUZZZ_VERSION(a, b, c)  (((a) << 16) + ((b) << 8) + ((c) << 0))
87#define BUZZZ_VER_A(v)          (((v) >> 16) & 0xff)
88#define BUZZZ_VER_B(v)          (((v) >>  8) & 0xff)
89#define BUZZZ_VER_C(v)          (((v) >>  0) & 0xff)
90
91#define BUZZZ_VER_FMTS          " ver[%u.%u.%u]"
92#define BUZZZ_VER_FMT(v)        BUZZZ_VER_A(v), BUZZZ_VER_B(v), BUZZZ_VER_C(v)
93
94	/* BUZZZ System */
95#define BUZZZ_SYS_VERSION       (BUZZZ_VERSION(01, 00, 00))
96#define BUZZZ_TOOL_HDRSIZE      (4 * 1024)
97#define BUZZZ_LOG_BUFSIZE       (128 * 4 * 1024) /* min 8K, multiple of 16 */
98
99	/* Character device */
100#define BUZZZ_CLI_VERSION       (BUZZZ_VERSION(01, 00, 00))
101#define BUZZZ_DEV_VERSION       (BUZZZ_VERSION(01, 00, 00))
102#define BUZZZ_DEV_PATH          "/dev/" BUZZZ_NAME
103
104
105#if defined(BUZZZ_CONFIG_COLOR_EN)
106#define BUZZZCLR(clr_code)      clr_code
107#else   /* !BUZZZ_CONFIG_COLOR_EN */
108#define BUZZZCLR(clr_code)      ""
109#endif  /* !BUZZZ_CONFIG_COLOR_EN */
110
111	/* BUZZZ defines */
112#define BUZZZ_ERROR             (-1)
113#define BUZZZ_SUCCESS           (0)
114#define BUZZZ_FAILURE           BUZZZ_ERROR
115
116#define BUZZZ_DISABLE           (0)
117#define BUZZZ_ENABLE            (1)
118
119#define BUZZZ_FALSE             (0)
120#define BUZZZ_TRUE              (1)
121
122#define BUZZZ_INVALID           (~0U)
123#define BUZZZ_NULL_STMT         do { /* Nothing */ } while(0)
124
125#define BUZZZ_INLINE        inline  __attribute__ ((always_inline))
126#define BUZZZ_NOINSTR_FUNC  __attribute__ ((no_instrument_function))
127
128#define BUZZZ_RET_IP        (uint32_t)__builtin_return_address(0)
129#define BUZZZ_CUR_IP        {{ __label__ __buzzz; __buzzz: (uint32_t)&&_buzzz;}}
130
131static BUZZZ_INLINE int BUZZZ_NULL_FUNC(void) { return BUZZZ_SUCCESS; }
132
133/* Kernel log events that may be registered */
134#define BUZZZ_KLOG_MAXIMUM     1024
135#define BUZZZ_KLOG_FMT_LENGTH  (128)
136
137#define BUZZZ_PMON_LOGS         (63)    /* Only 63 of 1024 used by PMON */
138
139#define BUZZZ_PMON_EXCP_MODE    (1U << 0)  /* Exception mode counting */
140#define BUZZZ_PMON_KERN_MODE    (1U << 1)  /* Kernel mode counting */
141#define BUZZZ_PMON_SPRV_MODE    (1U << 2)  /* Supervisor mode counting */
142#define BUZZZ_PMON_USER_MODE    (1U << 3)  /* Supervisor mode counting */
143
144#define BUZZZ_PMON_EKSU_MODE                                                   \
145	(BUZZZ_PMON_EXCP_MODE | BUZZZ_PMON_KERN_MODE                               \
146	| BUZZZ_PMON_SPRV_MODE | BUZZZ_PMON_USER_MODE)
147
148#define BUZZZ_PMON_CTRL         BUZZZ_PMON_EKSU_MODE
149
150/*
151 * Following section is shared between userspace command line control utility
152 * and kernel space character device driver.
153 */
154#undef  BUZZZ_ENUM
155#define BUZZZ_ENUM(val)         BUZZZ_TOOL_ ## val,
156typedef /* Only a single user/tool of the logging system is permitted */
157enum buzzz_tool {
158	BUZZZ_ENUM(UNDEF)
159	BUZZZ_ENUM(FUNC)        /* Function call tracing */
160	BUZZZ_ENUM(PMON)        /* Algorithm performance monitoring */
161	BUZZZ_ENUM(KEVT)        /* Kernel space event tracing */
162	BUZZZ_ENUM(MAXIMUM)
163} buzzz_tool_t;
164
165#undef  BUZZZ_ENUM
166#define BUZZZ_ENUM(val)         BUZZZ_STATUS_ ## val,
167typedef /* Runtime state of the tool with respect to logging */
168enum buzzz_status {
169	BUZZZ_ENUM(DISABLED)
170	BUZZZ_ENUM(ENABLED)
171	BUZZZ_ENUM(PAUSED)
172	BUZZZ_ENUM(MAXIMUM)
173} buzzz_status_t;
174
175#undef  BUZZZ_ENUM
176#define BUZZZ_ENUM(val)         BUZZZ_MODE_ ## val,
177typedef /* Auto flushing or bounding the logging */
178enum buzzz_mode {
179	BUZZZ_ENUM(UNDEF)
180	BUZZZ_ENUM(WRAPOVER)    /* wrap around log buffer */
181	BUZZZ_ENUM(LIMITED)     /* limited logging */
182	BUZZZ_ENUM(TRANSMIT)    /* auto tranmission of log upon buffer fill */
183	BUZZZ_ENUM(MAXIMUM)
184} buzzz_mode_t;
185
186#include <linux/major.h>    /* MISC_MAJOR */
187#include <linux/ioctl.h>
188
189#define BUZZZ_IOCTL_BASE            'Z'
190
191#define BUZZZ_IOCTL_KCALL           _IOR(BUZZZ_IOCTL_BASE, 0, uint32_t)
192#define BUZZZ_IOCTL_CONFIG_TOOL     _IOR(BUZZZ_IOCTL_BASE, 1, uint32_t)
193#define BUZZZ_IOCTL_CONFIG_MODE     _IOR(BUZZZ_IOCTL_BASE, 2, uint32_t)
194#define BUZZZ_IOCTL_CONFIG_LIMIT    _IOR(BUZZZ_IOCTL_BASE, 3, uint32_t)
195#define BUZZZ_IOCTL_CONFIG_FUNC     _IOR(BUZZZ_IOCTL_BASE, 4, uint32_t)
196#define BUZZZ_IOCTL_CONFIG_PMON     _IOR(BUZZZ_IOCTL_BASE, 5, uint32_t)
197#define BUZZZ_IOCTL_CONFIG_KEVT     _IOR(BUZZZ_IOCTL_BASE, 6, uint32_t)
198#define BUZZZ_IOCTL_SHOW            _IOR(BUZZZ_IOCTL_BASE, 7, uint32_t)
199#define BUZZZ_IOCTL_START           _IOR(BUZZZ_IOCTL_BASE, 8, uint32_t)
200#define BUZZZ_IOCTL_STOP            _IOR(BUZZZ_IOCTL_BASE, 9, uint32_t)
201#define BUZZZ_IOCTL_PAUSE           _IOR(BUZZZ_IOCTL_BASE, 10, uint32_t)
202#define BUZZZ_IOCTL_PLAY            _IOR(BUZZZ_IOCTL_BASE, 11, uint32_t)
203#define BUZZZ_IOCTL_AUDIT           _IOR(BUZZZ_IOCTL_BASE, 12, uint32_t)
204#define BUZZZ_IOCTL_DUMP            _IOR(BUZZZ_IOCTL_BASE, 13, uint32_t)
205#define BUZZZ_IOCTL_MAXIMUM         14
206
207
208#if defined(CONFIG_MIPS)
209#if defined(BUZZZ_CONFIG_CPU_MIPS_74K)
210/*
211 * MIPS74K performance events are arranged to have all 4 performance counters
212 * counting a unique event, constituting similar events to form a group.
213 * See enum buzzz_pmon_event_t for the grouping of events into 12 groups.
214 */
215
216#undef  BUZZZ_ENUM
217#define BUZZZ_ENUM(group)       BUZZZ_PMON_GROUP_ ## group,
218typedef
219enum buzzz_pmon_group
220{
221	BUZZZ_ENUM(RESET)
222	BUZZZ_ENUM(GENERAL)
223	BUZZZ_ENUM(ICACHE)
224	BUZZZ_ENUM(DCACHE)
225	BUZZZ_ENUM(TLB)
226	BUZZZ_ENUM(CYCLES_COMPLETED)
227	BUZZZ_ENUM(CYCLES_ISSUE_OOO)
228	BUZZZ_ENUM(INSTR_GENERAL)
229	BUZZZ_ENUM(INSTR_MISCELLANEOUS)
230	BUZZZ_ENUM(INSTR_LOAD_STORE)
231	BUZZZ_ENUM(CYCLES_IDLE_FULL)
232	BUZZZ_ENUM(CYCLES_IDLE_WAIT)
233	/* BUZZZ_ENUM(L2_CACHE) */
234	BUZZZ_ENUM(MAXIMUM)
235} buzzz_pmon_group_t;
236
237#undef  BUZZZ_ENUM
238#define BUZZZ_ENUM(event)       BUZZZ_PMON_EVENT_ ## event,
239typedef /* MIPS 74K Performance counters supported by BUZZZ PMon tool */
240enum buzzz_pmon_event
241{                                           /* evt: cnter  */
242	/* group  0: RESET */
243	BUZZZ_ENUM(CTR0_SKIP)                   /* 127 */
244	BUZZZ_ENUM(CTR1_SKIP)                   /* 127 */
245	BUZZZ_ENUM(CTR2_SKIP)                   /* 127 */
246	BUZZZ_ENUM(CTR3_SKIP)                   /* 127 */
247
248	/* group  1 GENERAL */
249	BUZZZ_ENUM(COMPL0_MISPRED)              /* 56: 0,  2   */
250	BUZZZ_ENUM(CYCLES_ELAPSED)              /*  0: 0,1,2,3 */
251	BUZZZ_ENUM(EXCEPTIONS)                  /* 58: 0,  2   */
252	BUZZZ_ENUM(COMPLETED)                   /*  1: 0,1,2,3 */
253
254	/* group  2 ICACHE */
255	BUZZZ_ENUM(IC_ACCESS)                   /*  6: 0,  2   */
256	BUZZZ_ENUM(IC_REFILL)                   /*  6:   1,  3 */
257	BUZZZ_ENUM(CYCLES_IC_MISS)              /*  7: 0,  2   */
258	BUZZZ_ENUM(CYCLES_L2_MISS)              /*  7:   1,  3 */
259
260	/* group  3 DCACHE */
261	BUZZZ_ENUM(LOAD_DC_ACCESS)              /* 23: 0,  2   */
262	BUZZZ_ENUM(LSP_DC_ACCESS)               /* 23:   1,  3 */
263	BUZZZ_ENUM(WB_DC_ACCESS)                /* 24: 0,  2   */
264	BUZZZ_ENUM(LSP_DC_MISS)                 /* 24:   1,  3 */
265
266	/* group  4 TLB */
267	BUZZZ_ENUM(ITLB_ACCESS)                 /*  4: 0,  2   */
268	BUZZZ_ENUM(ITLB_MISS)                   /*  4:   1,  3 */
269	BUZZZ_ENUM(JTLB_DACCESS)                /* 25: 0,  2   */
270	BUZZZ_ENUM(JTLB_XL_FAIL)                /* 25:   1,  3 */
271
272	/* group  5 CYCLES_COMPLETED  */
273	BUZZZ_ENUM(COMPL0_INSTR)                /* 53: 0,  2   */
274	BUZZZ_ENUM(COMPL_LOAD_MISS)             /* 53:   1,  3 */
275	BUZZZ_ENUM(COMPL1_INSTR)                /* 54: 0,  2   */
276	BUZZZ_ENUM(COMPL2_INSTR)                /* 54:   1,  3 */
277
278	/* group  6 CYCLES_ISSUE_OOO */
279	BUZZZ_ENUM(ISS1_INSTR)                  /* 20: 0,  2   */
280	BUZZZ_ENUM(ISS2_INSTR)                  /* 20:   1,  3 */
281	BUZZZ_ENUM(OOO_ALU)                     /* 21: 0,  2   */
282	BUZZZ_ENUM(OOO_AGEN)                    /* 21:   1,  3 */
283
284	/* group  7 INSTR_GENERAL */
285	BUZZZ_ENUM(CONDITIONAL)                 /* 39: 0,  2   */
286	BUZZZ_ENUM(MISPREDICTED)                /* 39:   1,  3 */
287	BUZZZ_ENUM(INTEGER)                     /* 40: 0,  2   */
288	BUZZZ_ENUM(FLOAT)                       /* 40:   1,  3 */
289
290	/* group  8 INSTR_MISCELLANEOUS */
291	BUZZZ_ENUM(JUMP)                        /* 42: 0,  2   */
292	BUZZZ_ENUM(MULDIV)                      /* 43:   1,  3 */
293	BUZZZ_ENUM(PREFETCH)                    /* 52: 0,  2   */
294	BUZZZ_ENUM(PREFETCH_NULL)               /* 52:   1,  3 */
295
296	/* group  9 INSTR_LOAD_STORE */
297	BUZZZ_ENUM(LOAD)                        /* 41: 0,  2   */
298	BUZZZ_ENUM(STORE)                       /* 41:   1,  3 */
299	BUZZZ_ENUM(LOAD_UNCACHE)                /* 46: 0,  2   */
300	BUZZZ_ENUM(STORE_UNCACHE)               /* 46:   1,  3 */
301
302	/* group  10 CYCLES_IDLE_FULL */
303	BUZZZ_ENUM(ALU_CAND_POOL)               /* 13: 0,  2   */
304	BUZZZ_ENUM(AGEN_CAND_POOL)              /* 13:   1,  3 */
305	BUZZZ_ENUM(ALU_COMPL_BUF)               /* 14: 0,  2   */
306	BUZZZ_ENUM(AGEN_COMPL_BUF)              /* 14:   1,  3 */
307
308	/* group 11 CYCLES_IDLE_WAIT */
309	BUZZZ_ENUM(ALU_NO_INSTR)                /* 16: 0,  2   */
310	BUZZZ_ENUM(AGEN_NO_INSTR)               /* 16:   1,  3 */
311	BUZZZ_ENUM(ALU_NO_OPER)                 /* 17: 0,  2   */
312	BUZZZ_ENUM(GEN_NO_OPER)                 /* 17:   1,  3 */
313
314	/* group 12 : L2_CACHE */
315	/* BUZZZ_ENUM(WBACK) */
316	/* BUZZZ_ENUM(ACCESS) */
317	/* BUZZZ_ENUM(MISSES) */
318	/* BUZZZ_ENUM(MISS_CYCLES) */
319
320	BUZZZ_ENUM(MAXIMUM)
321
322} buzzz_pmon_event_t;
323
324#define BUZZZ_PMON_COUNTERS     (4)
325#define BUZZZ_PMON_GROUPS       (BUZZZ_PMON_EVENT_MAXIMUM / BUZZZ_PMON_COUNTERS)
326
327#endif  /*  BUZZZ_CONFIG_CPU_MIPS_74K */
328#endif  /*  CONFIG_MIPS */
329
330
331#if defined(CONFIG_ARM)
332#if defined(BUZZZ_CONFIG_CPU_ARMV7_A9)
333/*
334 * ARMv7 A9 performance events are arranged to have all 4 performance counters
335 * counting a unique event, constituting similar events to form a group.
336 * See enum buzzz_pmon_event_t for the grouping of events into 8 groups.
337 */
338
339#undef  BUZZZ_ENUM
340#define BUZZZ_ENUM(group)       BUZZZ_PMON_GROUP_ ## group,
341typedef
342enum buzzz_pmon_group
343{
344	BUZZZ_ENUM(RESET)
345	BUZZZ_ENUM(GENERAL)
346	BUZZZ_ENUM(ICACHE)
347	BUZZZ_ENUM(DCACHE)
348	BUZZZ_ENUM(TLB)
349	BUZZZ_ENUM(DATA)
350	BUZZZ_ENUM(SPURIOUS)
351	BUZZZ_ENUM(BRANCHES)
352	BUZZZ_ENUM(MISCELLANEOUS)
353	BUZZZ_ENUM(MAXIMUM)
354} buzzz_pmon_group_t;
355
356#undef  BUZZZ_ENUM
357#define BUZZZ_ENUM(event)       BUZZZ_PMON_EVENT_ ## event,
358typedef /* ARMv7 Cortex A9 Performance counters supported by BUZZZ PMon tool */
359enum buzzz_pmon_event
360{                                           /* evt: cnter  */
361	/* group  0: RESET */
362	BUZZZ_ENUM(CTR0_SKIP)                   /* 0x00 */
363	BUZZZ_ENUM(CTR1_SKIP)                   /* 0x00 */
364	BUZZZ_ENUM(CTR2_SKIP)                   /* 0x00 */
365	BUZZZ_ENUM(CTR3_SKIP)                   /* 0x00 */
366
367	/* group  1: GENERAL */
368	BUZZZ_ENUM(BRANCH_MISPRED)              /* 0x10 */
369	BUZZZ_ENUM(CYCLES_ELAPSED)              /* 0x11 */
370	BUZZZ_ENUM(EXCEPTIONS)                  /* 0x09 */
371	BUZZZ_ENUM(SPEC_INSTRCNT)               /* 0x68 */
372
373	/* group  2: ICACHE */
374	BUZZZ_ENUM(INSTRUCTIONS)                /* 0x68 */
375	BUZZZ_ENUM(IC_REFILL)                   /* 0x01 */
376	BUZZZ_ENUM(CYCLES_IC_MISS)              /* 0x60 */
377	BUZZZ_ENUM(CYCLES_NOISSUE)              /* 0x66 */
378
379	/* group  3: DCACHE */
380	BUZZZ_ENUM(DC_ACCESS)                   /* 0x04 */
381	BUZZZ_ENUM(DC_REFILL)                   /* 0x03 */
382	BUZZZ_ENUM(CYCLES_DC_MISS)              /* 0x61 */
383	BUZZZ_ENUM(EVICTIONS)                   /* 0x65 */
384
385	/* group  4: TLB */
386	BUZZZ_ENUM(INSTR_REFILL)                /* 0x02 */
387	BUZZZ_ENUM(DATA_REFILL)                 /* 0x05 */
388	BUZZZ_ENUM(CYCLES_ITLB_MISS)            /* 0x82 */
389	BUZZZ_ENUM(CYCLES_DTLB_MISS)            /* 0x83 */
390
391	/* group  5: DATA */
392	BUZZZ_ENUM(READ_ACCESS)                 /* 0x06 */
393	BUZZZ_ENUM(WRITE_ACCESS)                /* 0x07 */
394	BUZZZ_ENUM(CYCLES_WRITE)                /* 0x81 */
395	BUZZZ_ENUM(CYCLES_DMB)                  /* 0x86 */
396
397	/* group  6: SPURIOUS */
398	BUZZZ_ENUM(INTERRUPTS)                  /* 0x93 */
399	BUZZZ_ENUM(UNALIGNED)                   /* 0x0F */
400	BUZZZ_ENUM(EXCEPTION_RTN)               /* 0x0A */
401	BUZZZ_ENUM(CYCLES_TLB_MISS)             /* 0x62 */
402
403	/* group  7: BRANCHES */
404	BUZZZ_ENUM(SW_PC_CHANGE)                /* 0x0C */
405	BUZZZ_ENUM(IMMED_BRANCHES)              /* 0x0D */
406	BUZZZ_ENUM(PROCEDURE_RTN)               /* 0x0E */
407	BUZZZ_ENUM(PRED_BRANCHES)               /* 0x12 */
408
409	/* group  8: MISCELLANEOUS */
410	BUZZZ_ENUM(STREX_PASSED)                /* 0x63 */
411	BUZZZ_ENUM(STREX_FAILED)                /* 0x64 */
412	BUZZZ_ENUM(DSB_INSTR)                   /* 0x91 */
413	BUZZZ_ENUM(DMB_INSTR)                   /* 0x92 */
414
415	BUZZZ_ENUM(MAXIMUM)
416
417} buzzz_pmon_event_t;
418
419#define BUZZZ_PMON_COUNTERS     (4)
420#define BUZZZ_PMON_GROUPS       (BUZZZ_PMON_EVENT_MAXIMUM / BUZZZ_PMON_COUNTERS)
421
422#undef  BUZZZ_ENUM
423#define BUZZZ_ENUM(group)       BUZZZ_KEVT_GROUP_ ## group,
424typedef
425enum buzzz_kevt_group
426{
427	BUZZZ_ENUM(RESET)
428	BUZZZ_ENUM(GENERAL)
429	BUZZZ_ENUM(ICACHE)
430	BUZZZ_ENUM(DCACHE)
431	BUZZZ_ENUM(TLB)
432	BUZZZ_ENUM(BRANCH)
433	BUZZZ_ENUM(MAXIMUM)
434} buzzz_kevt_group_t;
435
436#undef  BUZZZ_ENUM
437#define BUZZZ_ENUM(event)       BUZZZ_KEVT_EVENT_ ## event,
438typedef /* ARMv7 Cortex A9 Performance counters supported by BUZZZ KEvt tool */
439enum buzzz_kevt_event
440{                                           /* evt: cnter  */
441	/* group  0: RESET */
442	BUZZZ_ENUM(CTR0_NONE)                   /* 0x00 */
443	BUZZZ_ENUM(CTR1_NONE)                   /* 0x00 */
444
445	/* group  1: GENERAL */
446	BUZZZ_ENUM(SPEC_INSTRCNT)               /* 0x68 */
447	BUZZZ_ENUM(CYCLES_ELAPSED)              /* 0x11 */
448
449	/* group  2: ICACHE */
450	BUZZZ_ENUM(INSTRUCTIONS)                /* 0x68 */
451	BUZZZ_ENUM(IC_REFILL)                   /* 0x01 */
452
453	/* group  3: DCACHE */
454	BUZZZ_ENUM(DC_ACCESS)                   /* 0x04 */
455	BUZZZ_ENUM(DC_REFILL)                   /* 0x03 */
456
457	/* group  4: TLB */
458	BUZZZ_ENUM(INSTR_REFILL)                /* 0x02 */
459	BUZZZ_ENUM(DATA_REFILL)                 /* 0x05 */
460
461	/* group  5: MISCELLANEOUS */
462	BUZZZ_ENUM(BRANCH_MISPRED)              /* 0x10 */
463	BUZZZ_ENUM(STREX_FAILED)                /* 0x64 */
464
465	BUZZZ_ENUM(MAXIMUM)
466} buzzz_kevt_event_t;
467
468#define BUZZZ_KEVT_COUNTERS     (2)
469#define BUZZZ_KEVT_GROUPS       (BUZZZ_KEVT_EVENT_MAXIMUM / BUZZZ_KEVT_COUNTERS)
470
471#undef  BUZZZ_ENUM
472#define BUZZZ_ENUM(event)       BUZZZ_KEVT_ID_ ## event,
473typedef
474enum buzzz_kevt_id
475{
476	BUZZZ_ENUM(IRQ_BAD)         /* 1: irq                                     */
477	BUZZZ_ENUM(IRQ_ACK_BAD)     /* 1: irq                                     */
478	BUZZZ_ENUM(IRQ_MISROUTED)   /* 1: irq                                     */
479	BUZZZ_ENUM(IRQ_RESEND)      /* 1: irq                                     */
480	BUZZZ_ENUM(IRQ_CHECK)       /* 1: irq                                     */
481	BUZZZ_ENUM(IRQ_ENTRY)       /* 2: irq, handler                            */
482	BUZZZ_ENUM(IRQ_EXIT)        /* 2: irq, handler                            */
483	BUZZZ_ENUM(SIRQ_ENTRY)      /* 1: action                                  */
484	BUZZZ_ENUM(SIRQ_EXIT)       /* 1: action                                  */
485	BUZZZ_ENUM(WORKQ_ENTRY)     /* 1: function                                */
486	BUZZZ_ENUM(WORKQ_EXIT)      /* 1: function                                */
487	BUZZZ_ENUM(SCHEDULE)        /* 4: prev->[pid,prio], next->[pid,prio]      */
488	BUZZZ_ENUM(SCHED_TICK)      /* 1: jiffies                                 */
489	BUZZZ_ENUM(SCHED_HRTICK)    /* 0:                                         */
490	BUZZZ_ENUM(GTIMER_EVENT)    /* 1: event_handler                           */
491	BUZZZ_ENUM(GTIMER_NEXT)     /* 1: next                                    */
492	BUZZZ_ENUM(BUZZZ_TMR)       /* 0:                                         */
493
494	BUZZZ_ENUM(MAXIMUM)
495} buzzz_kevt_id_t;
496#endif  /*  BUZZZ_CONFIG_CPU_ARMV7_A9 */
497#endif  /*  CONFIG_ARM */
498
499#if defined(CONFIG_BUZZZ)
500
501#ifndef __ASSEMBLY__
502
503#if defined(__cplusplus)
504extern "C" {
505#endif  /*  __cplusplus */
506
507#if defined(__KERNEL__)
508#include <linux/types.h>            /* ISO C99 7.18 Integer types */
509#include <linux/version.h>
510#else   /* !__KERNEL__ */
511#include <stdint.h>                 /* ISO C99 7.18 Integer types */
512#endif  /* !__KERNEL__ */
513
514#if defined(__KERNEL__)
515
516typedef char buzzz_fmt_t[BUZZZ_KLOG_FMT_LENGTH];
517
518/*
519 * APIs exposed for kernel space invocation
520 */
521int buzzz_show(void);
522int buzzz_start(uint32_t u32);
523int buzzz_stop(uint32_t u32);
524int buzzz_pause(void);
525int buzzz_play(void);
526int buzzz_audit(void);
527int buzzz_dump(uint32_t items);
528int buzzz_kcall(uint32_t args);
529
530int buzzz_config_tool(buzzz_tool_t tool);
531int buzzz_config_mode(buzzz_mode_t mode);
532int buzzz_config_limit(uint32_t limit);
533
534void buzzz_klog_reg(uint32_t klog_id, char * klog_fmt);
535
536/*
537 * Function call tracing kernel APIs
538 */
539void __cyg_profile_func_enter(void * called, void * caller);
540void __cyg_profile_func_exit(void * called, void * caller);
541void buzzz_func_log0(uint32_t event);
542void buzzz_func_log1(uint32_t event, uint32_t u1);
543void buzzz_func_log2(uint32_t event, uint32_t u1, uint32_t u2);
544void buzzz_func_log3(uint32_t event, uint32_t u1, uint32_t u2, uint32_t u3);
545void buzzz_func_start(void);
546void buzzz_func_stop(void);
547void buzzz_func_panic(void);
548void buzzz_func_dump(uint32_t limit);
549int  buzzz_func_config(uint32_t config_exit);
550
551#define BUZZZ_FUNC_LOG(func)   \
552	__cyg_profile_func_enter((void*)func, __builtin_return_address(0))
553
554/*
555 * Performance monitoring kernel APIs
556 */
557void buzzz_pmon_bgn(void);
558void buzzz_pmon_clr(void);
559void buzzz_pmon_log(uint32_t event);
560void buzzz_pmon_end(uint32_t event);    /* last event id logged */
561void buzzz_pmon_start(void);
562void buzzz_pmon_stop(void);
563int  buzzz_pmon_config(uint32_t config_samples, uint32_t config_skip);
564
565#if defined(BUZZZ_CONFIG_PMON_USR)
566/*
567 * Counter will be logged on buzzz_pmon_end(), may be used to record an
568 * application state, such as txmpduperampdu.
569 */
570extern unsigned int buzzz_pmon_usr_g;
571#endif  /*  BUZZZ_CONFIG_PMON_USR */
572
573/*
574 * Kernel Event logging APIs
575 */
576void buzzz_kevt_log0(uint32_t event);
577void buzzz_kevt_log1(uint32_t event, uint32_t u1);
578void buzzz_kevt_log2(uint32_t event, uint32_t u1, uint32_t u2);
579void buzzz_kevt_log3(uint32_t event, uint32_t u1, uint32_t u2,
580                                     uint32_t u3);
581void buzzz_kevt_log4(uint32_t event, uint32_t u1, uint32_t u2,
582                                     uint32_t u3, uint32_t u4);
583void buzzz_kevt_start(void);
584void buzzz_kevt_stop(void);
585void buzzz_kevt_dump(uint32_t limit);
586int  buzzz_kevt_config(uint32_t config_exit);
587
588#if defined(BUZZZ_KEVT_DPL) && (BUZZZ_KEVT_DPL >= 1)
589#define BUZZZ_DPL1(ID, N, ARG...)   buzzz_kevt_log ##N(BUZZZ_KEVT__ ##ID, ##ARG)
590#else
591#define BUZZZ_DPL1(ID, N, ARG...)   BUZZZ_NULL_STMT
592#endif  /* ! BUZZZ_KEVT_DPL >= 1 */
593#if defined(BUZZZ_KEVT_DPL) && (BUZZZ_KEVT_DPL >= 2)
594#define BUZZZ_DPL2(ID, N, ARG...)   buzzz_kevt_log ##N(BUZZZ_KEVT__ ##ID, ##ARG)
595#else
596#define BUZZZ_DPL2(ID, N, ARG...)   BUZZZ_NULL_STMT
597#endif  /* ! BUZZZ_KEVT_DPL >= 2 */
598#if defined(BUZZZ_KEVT_DPL) && (BUZZZ_KEVT_DPL >= 3)
599#define BUZZZ_DPL3(ID, N, ARG...)   buzzz_kevt_log ##N(BUZZZ_KEVT__ ##ID, ##ARG)
600#else
601#define BUZZZ_DPL3(ID, N, ARG...)   BUZZZ_NULL_STMT
602#endif  /* ! BUZZZ_KEVT_DPL >= 3 */
603#if defined(BUZZZ_KEVT_DPL) && (BUZZZ_KEVT_DPL >= 4)
604#define BUZZZ_DPL4(ID, N, ARG...)   buzzz_kevt_log ##N(BUZZZ_KEVT__ ##ID, ##ARG)
605#else
606#define BUZZZ_DPL4(ID, N, ARG...)   BUZZZ_NULL_STMT
607#endif  /* ! BUZZZ_KEVT_DPL >= 4 */
608#if defined(BUZZZ_KEVT_DPL) && (BUZZZ_KEVT_DPL >= 5)
609#define BUZZZ_DPL5(ID, N, ARG...)   buzzz_kevt_log ##N(BUZZZ_KEVT__ ##ID, ##ARG)
610#else
611#define BUZZZ_DPL5(ID, N, ARG...)   BUZZZ_NULL_STMT
612#endif  /* ! BUZZZ_KEVT_DPL >= 5 */
613
614#endif  /*  __KERNEL__ */
615
616#if defined(__cplusplus)
617}
618#endif  /*  __cplusplus */
619
620#else   /* !__ASSEMBLY__ */
621
622/*
623 * Kernel mode embedded assembly APIs
624 */
625
626#endif  /* !__ASSEMBLY__ */
627
628
629#else   /* !CONFIG_BUZZZ */
630
631/* BUZZZ APIs */
632#define buzzz_show()                        BUZZZ_NULL_FUNC
633#define buzzz_start(a)                      BUZZZ_NULL_FUNC
634#define buzzz_stop(a)                       BUZZZ_NULL_FUNC
635#define buzzz_pause()                       BUZZZ_NULL_FUNC
636#define buzzz_play()                        BUZZZ_NULL_FUNC
637#define buzzz_audit()                       BUZZZ_NULL_FUNC
638#define buzzz_dump(l)                       BUZZZ_NULL_FUNC
639#define buzzz_config_tool(t)                BUZZZ_NULL_FUNC
640#define buzzz_config_mode(m)                BUZZZ_NULL_FUNC
641#define buzzz_config_limit(l)               BUZZZ_NULL_FUNC
642
643#define buzzz_klog_reg(l, f)                BUZZZ_NULL_STMT
644
645/* Function call tracing kernel APIs */
646#define __cyg_profile_func_enter(ced, cer)  BUZZZ_NULL_STMT
647#define __cyg_profile_func_exit(ced, cer)   BUZZZ_NULL_STMT
648#define buzzz_func_log0(e)                  BUZZZ_NULL_STMT
649#define buzzz_func_log1(e, a1)              BUZZZ_NULL_STMT
650#define buzzz_func_log2(e, a1, a2)          BUZZZ_NULL_STMT
651#define buzzz_func_log3(e, a1, a2, a3)      BUZZZ_NULL_STMT
652#define buzzz_func_start()                  BUZZZ_NULL_STMT
653#define buzzz_func_stop()                   BUZZZ_NULL_STMT
654#define buzzz_func_panic()                  BUZZZ_NULL_STMT
655#define buzzz_func_dump(l)                  BUZZZ_NULL_STMT
656#define buzzz_func_config(e)                BUZZZ_NULL_FUNC
657
658#define BUZZZ_FUNC_LOG(f)                   BUZZZ_NULL_STMT
659
660/* Performance monitoring kernel APIs */
661#define buzzz_pmon_bgn()                    BUZZZ_NULL_STMT
662#define buzzz_pmon_clr()                    BUZZZ_NULL_STMT
663#define buzzz_pmon_log(e)                   BUZZZ_NULL_STMT
664#define buzzz_pmon_end()                    BUZZZ_NULL_STMT
665#define buzzz_pmon_start()                  BUZZZ_NULL_STMT
666#define buzzz_pmon_stop()                   BUZZZ_NULL_STMT
667#define buzzz_pmon_config(i, s)             BUZZZ_NULL_FUNC
668
669#define buzzz_kevt_log0(e)                  BUZZZ_NULL_STMT
670#define buzzz_kevt_log1(e, a1)              BUZZZ_NULL_STMT
671#define buzzz_kevt_log2(e, a1, a2)          BUZZZ_NULL_STMT
672#define buzzz_kevt_log3(e, a1, a2, a3)      BUZZZ_NULL_STMT
673#define buzzz_kevt_log4(e, a1, a2, a3, a4)  BUZZZ_NULL_STMT
674#define buzzz_kevt_start()                  BUZZZ_NULL_STMT
675#define buzzz_kevt_stop()                   BUZZZ_NULL_STMT
676#define buzzz_kevt_dump(l)                  BUZZZ_NULL_STMT
677#define buzzz_kevt_config(g)                BUZZZ_NULL_FUNC
678#define BUZZZ_DPL1(N, ID, ARG...)           BUZZZ_NULL_STMT
679#define BUZZZ_DPL2(N, ID, ARG...)           BUZZZ_NULL_STMT
680#define BUZZZ_DPL3(N, ID, ARG...)           BUZZZ_NULL_STMT
681#define BUZZZ_DPL4(N, ID, ARG...)           BUZZZ_NULL_STMT
682#define BUZZZ_DPL5(N, ID, ARG...)           BUZZZ_NULL_STMT
683
684#endif  /* !CONFIG_BUZZZ */
685
686
687/*
688 * -----------------------------------------------------------------------------
689 * Color coded terminal display
690 * -----------------------------------------------------------------------------
691 */
692	/* White background */
693#define CLRr        BUZZZCLR("\e[0;31m")        /* red              */
694#define CLRg        BUZZZCLR("\e[0;32m")        /* green            */
695#define CLRy        BUZZZCLR("\e[0;33m")        /* yellow           */
696#define CLRb        BUZZZCLR("\e[0;34m")        /* blue             */
697#define CLRm        BUZZZCLR("\e[0;35m")        /* magenta          */
698#define CLRc        BUZZZCLR("\e[0;36m")        /* cyan             */
699
700	/* blacK "inverted" background */
701#define CLRrk       BUZZZCLR("\e[0;31;40m")     /* red     on blacK */
702#define CLRgk       BUZZZCLR("\e[0;32;40m")     /* green   on blacK */
703#define CLRyk       BUZZZCLR("\e[0;33;40m")     /* yellow  on blacK */
704#define CLRmk       BUZZZCLR("\e[0;35;40m")     /* magenta on blacK */
705#define CLRck       BUZZZCLR("\e[0;36;40m")     /* cyan    on blacK */
706#define CLRwk       BUZZZCLR("\e[0;37;40m")     /* whilte  on blacK */
707
708	/* Colored background */
709#define CLRcb       BUZZZCLR("\e[0;36;44m")     /* cyan    on blue  */
710#define CLRyr       BUZZZCLR("\e[0;33;41m")     /* yellow  on red   */
711#define CLRym       BUZZZCLR("\e[0;33;45m")     /* yellow  on magen */
712
713	/* Generic foreground colors */
714#define CLRhigh     CLRm                        /* Highlight color  */
715#define CLRbold     CLRcb                       /* Bold      color  */
716#define CLRbold2    CLRym                       /* Bold2     color  */
717#define CLRerr      CLRyr                       /* Error     color  */
718#define CLRwarn     CLRym                       /* Warn      color  */
719#define CLRnorm     BUZZZCLR("\e[0m")           /* Normal    color  */
720#define CLRnl       CLRnorm "\n"                /* Normal + newline */
721
722#endif  /* !_BUZZZ_H_INCLUDED_ */
723