1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  SOC Display functions			File: ui_soccmds.c
5    *
6    *  UI functions for examining SOC registers
7    *
8    *  Author:  Mitch Lichtenberg
9    *
10    *********************************************************************
11    *
12    *  Copyright 2000,2001,2002,2003
13    *  Broadcom Corporation. All rights reserved.
14    *
15    *  This software is furnished under license and may be used and
16    *  copied only in accordance with the following terms and
17    *  conditions.  Subject to these conditions, you may download,
18    *  copy, install, use, modify and distribute modified or unmodified
19    *  copies of this software in source and/or binary form.  No title
20    *  or ownership is transferred hereby.
21    *
22    *  1) Any source code used, modified or distributed must reproduce
23    *     and retain this copyright notice and list of conditions
24    *     as they appear in the source file.
25    *
26    *  2) No right is granted to use any trade name, trademark, or
27    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
28    *     name may not be used to endorse or promote products derived
29    *     from this software without the prior written permission of
30    *     Broadcom Corporation.
31    *
32    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44    *     THE POSSIBILITY OF SUCH DAMAGE.
45    ********************************************************************* */
46
47
48#include "cfe.h"
49#include "sbmips.h"
50#include "ui_command.h"
51
52#include "socregs.h"
53
54#include "cpu_socregs.inc"
55#include "lib_try.h"
56#include "lib_memfuncs.h"
57#include "lib_physio.h"
58
59static int ui_cmd_soc(ui_cmdline_t *cmd,int argc,char *argv[]);
60static int ui_cmd_socagents(ui_cmdline_t *cmd,int argc,char *argv[]);
61
62int ui_init_soccmds(void);
63
64
65/*
66 * Command formats:
67 *
68 * show soc agentname instance subinstance
69 *
70 * show soc mac 		Show all MACs
71 * show soc mac 0 		Show just MAC0
72 * show soc macdma 0 tx0	Show just TX channel 0 of MAC DMA 0
73 */
74
75static void ui_showreg(const socreg_t *reg,int verbose)
76{
77    char buffer[100];
78    char number[30];
79    char *ptr = buffer;
80    uint64_t value = 0;
81    hsaddr_t addr;
82    int res;
83
84    ptr += sprintf(ptr,"%s",socagents[reg->reg_agent]);
85    if (reg->reg_inst[0] != '*') {
86	ptr += sprintf(ptr," %s",reg->reg_inst);
87	}
88    if (reg->reg_subinst[0] != '*') {
89	ptr += sprintf(ptr," %s",reg->reg_subinst);
90	}
91    ptr += sprintf(ptr," %s",reg->reg_descr);
92
93#if 0
94    /* XXX this code should be fixed to use the exception handler like it used to */
95    addr = (long)PHYS_TO_K1(reg->reg_addr);
96    res = mem_peek(&value,addr,MEM_QUADWORD);
97#else
98    addr = reg->reg_addr;
99    value = phys_read64(addr);
100    res = 0;
101#endif
102
103    if (res == 0) sprintf(number,"%016llX",value);
104    else sprintf(number,"N/A N/A N/A N/A ");
105
106    xprintf("%30s  0x%08X  %4s_%4s_%4s_%4s\n",
107	    buffer,addr,
108	    &number[0],&number[4],&number[8],&number[12]);
109
110
111    if (verbose && (reg->reg_printfunc)) {
112	xprintf("    ");
113	(*(reg->reg_printfunc))(reg,value);
114	xprintf("\n");
115	}
116
117
118}
119
120static int ui_cmd_soc(ui_cmdline_t *cmd,int argc,char *argv[])
121{
122    char *agent = NULL;
123    char *inst = NULL;
124    char *subinst = NULL;
125    const socreg_t *reg;
126    int verbose;
127
128    reg = socregs;
129
130    agent   = cmd_getarg(cmd,0);
131    inst    = cmd_getarg(cmd,1);
132    subinst = cmd_getarg(cmd,2);
133
134    if (!cmd_sw_isset(cmd,"-all")) {
135	if (!agent) return ui_showusage(cmd);
136	}
137
138    if (cmd_sw_isset(cmd,"-v")) verbose = 1;
139    else verbose = 0;
140
141    xprintf("Register Name                   PhysAddr    Value\n");
142    xprintf("------------------------------  ----------  -------------------\n");
143
144    while (reg->reg_descr) {
145	if (!agent || (strcmpi(agent,socagents[reg->reg_agent]) == 0)) {
146	    /* Handle the case of subinstances of something we have only one of */
147	    if (reg->reg_inst[0] != '*') {
148		if ((!inst || (strcmpi(inst,reg->reg_inst) == 0)) &&
149		    (!subinst || (strcmpi(subinst,reg->reg_subinst) == 0))) {
150		    ui_showreg(reg,verbose);
151		    }
152		}
153	    else {
154		if (!inst || (strcmpi(inst,reg->reg_subinst) == 0)) {
155		    ui_showreg(reg,verbose);
156		    }
157		}
158	    }
159	reg++;
160	}
161
162    return 0;
163}
164
165static int ui_cmd_socagents(ui_cmdline_t *cmd,int argc,char *argv[])
166{
167    char **aptr;
168
169    aptr = socagents;
170
171    xprintf("Available SOC agents: ");
172    while (*aptr) {
173	xprintf("%s",*aptr);
174	aptr++;
175	if (*aptr) xprintf(", ");
176	}
177    xprintf("\n");
178
179    return 0;
180}
181
182
183int ui_init_soccmds(void)
184{
185    cmd_addcmd("show soc",
186	       ui_cmd_soc,
187	       NULL,
188	       "Display SOC register contents",
189	       "show soc agentname [instance [section]]\n\n"
190	       "Display register values for SOC registers.\n",
191	       "-v;Verbose information: Display register fields where available|"
192	       "-all;Display all registers in all agents");
193
194    cmd_addcmd("show agents",
195	       ui_cmd_socagents,
196	       NULL,
197	       "Display list of SOC agents",
198	       "show agents\n\n"
199	       "Display the names of the available SOC agents that can be examined\n"
200	       "using the 'show soc' command",
201	       "");
202
203    return 0;
204}
205