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 (mpl@broadcom.com)
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
49#include "sbmips.h"
50#include "lib_types.h"
51#include "lib_string.h"
52#include "lib_queue.h"
53#include "lib_malloc.h"
54#include "lib_printf.h"
55
56#include "cfe_error.h"
57#include "cfe_console.h"
58
59#include "ui_command.h"
60#include "cfe.h"
61
62#include "socregs.h"
63
64#include "sb1250_regs.h"
65#include "sb1250_socregs.inc"
66
67#include "exchandler.h"
68
69
70static int ui_cmd_soc(ui_cmdline_t *cmd,int argc,char *argv[]);
71static int ui_cmd_socagents(ui_cmdline_t *cmd,int argc,char *argv[]);
72
73int ui_init_soccmds(void);
74
75
76/*
77 * Command formats:
78 *
79 * show soc agentname instance subinstance
80 *
81 * show soc mac 		Show all MACs
82 * show soc mac 0 		Show just MAC0
83 * show soc macdma 0 tx0	Show just TX channel 0 of MAC DMA 0
84 */
85
86static void ui_showreg(const socreg_t *reg,int verbose)
87{
88    char buffer[100];
89    char number[30];
90    char *ptr = buffer;
91    uint64_t value = 0;
92    int res;
93
94    ptr += sprintf(ptr,"%s",socagents[reg->reg_agent]);
95    if (reg->reg_inst[0] != '*') {
96	ptr += sprintf(ptr," %s",reg->reg_inst);
97	}
98    if (reg->reg_subinst[0] != '*') {
99	ptr += sprintf(ptr," %s",reg->reg_subinst);
100	}
101    ptr += sprintf(ptr," %s",reg->reg_descr);
102
103    res = mem_peek(&value,PHYS_TO_K1(reg->reg_addr),MEM_QUADWORD);
104
105//    value = *((volatile uint64_t *) PHYS_TO_K1(reg->reg_addr));
106
107    if (res == 0) sprintf(number,"%016llX",value);
108    else sprintf(number,"N/A N/A N/A N/A ");
109
110    xprintf("%30s  0x%08X  %4s_%4s_%4s_%4s\n",
111	    buffer,reg->reg_addr,
112	    &number[0],&number[4],&number[8],&number[12]);
113
114
115    if (verbose && (reg->reg_printfunc)) {
116	xprintf("    ");
117	(*(reg->reg_printfunc))(reg,value);
118	xprintf("\n");
119	}
120
121
122}
123
124static int ui_cmd_soc(ui_cmdline_t *cmd,int argc,char *argv[])
125{
126    char *agent = NULL;
127    char *inst = NULL;
128    char *subinst = NULL;
129    const socreg_t *reg;
130    int verbose;
131
132    reg = socregs;
133
134    agent   = cmd_getarg(cmd,0);
135    inst    = cmd_getarg(cmd,1);
136    subinst = cmd_getarg(cmd,2);
137
138    if (!cmd_sw_isset(cmd,"-all")) {
139	if (!agent) return ui_showusage(cmd);
140	}
141
142    if (cmd_sw_isset(cmd,"-v")) verbose = 1;
143    else verbose = 0;
144
145    xprintf("Register Name                   Address     Value\n");
146    xprintf("------------------------------  ----------  -------------------\n");
147
148    while (reg->reg_descr) {
149	if (!agent || (strcmpi(agent,socagents[reg->reg_agent]) == 0)) {
150	    /* Handle the case of subinstances of something we have only one of */
151	    if (reg->reg_inst[0] != '*') {
152		if ((!inst || (strcmpi(inst,reg->reg_inst) == 0)) &&
153		    (!subinst || (strcmpi(subinst,reg->reg_subinst) == 0))) {
154		    ui_showreg(reg,verbose);
155		    }
156		}
157	    else {
158		if (!inst || (strcmpi(inst,reg->reg_subinst) == 0)) {
159		    ui_showreg(reg,verbose);
160		    }
161		}
162	    }
163	reg++;
164	}
165
166    return 0;
167}
168
169static int ui_cmd_socagents(ui_cmdline_t *cmd,int argc,char *argv[])
170{
171    char **aptr;
172
173    aptr = socagents;
174
175    xprintf("Available SOC agents: ");
176    while (*aptr) {
177	xprintf("%s",*aptr);
178	aptr++;
179	if (*aptr) xprintf(", ");
180	}
181    xprintf("\n");
182
183    return 0;
184}
185
186
187int ui_init_soccmds(void)
188{
189    cmd_addcmd("show soc",
190	       ui_cmd_soc,
191	       NULL,
192	       "Display SOC register contents",
193	       "show soc agentname [instance [section]]\n\n"
194	       "Display register values for SOC registers.\n",
195	       "-v;Verbose information: Display register fields where available|"
196	       "-all;Display all registers in all agents");
197
198    cmd_addcmd("show agents",
199	       ui_cmd_socagents,
200	       NULL,
201	       "Display list of SOC agents",
202	       "show agents\n\n"
203	       "Display the names of the available SOC agents that can be examined\n"
204	       "using the 'show soc' command",
205	       "");
206
207    return 0;
208}
209