1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  VAPI commands				File: ui_vapi.c
5    *
6    *  User interface for the verification API
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 "env_subr.h"
50#include "ui_command.h"
51
52#if CFG_VAPI
53
54#include "vapi.h"
55
56int ui_init_vapicmds(void);
57
58extern void vapitest(void);
59
60extern void vapi_run(int);
61
62extern uint64_t vapi_logstart;
63extern uint64_t vapi_logend;
64extern uint64_t vapi_logptr;
65extern uint64_t vapi_status;
66
67int ui_cmd_vapirun(ui_cmdline_t *cmd,int argc,char *argv[]);
68int ui_cmd_vapitest(ui_cmdline_t *cmd,int argc,char *argv[]);
69int ui_cmd_vapishow(ui_cmdline_t *cmd,int argc,char *argv[]);
70int ui_cmd_vapidump(ui_cmdline_t *cmd,int argc,char *argv[]);
71int ui_cmd_vapistatus(ui_cmdline_t *cmd,int argc,char *argv[]);
72
73static char *rectypes[7] = {
74    "GPRS ",
75    "SOC  ",
76    "DATA ",
77    "BUF  ",
78    "TRC  ",
79    "EXIT ",
80    "FPRS "
81};
82
83int ui_cmd_vapidump(ui_cmdline_t *cmd,int argc,char *argv[])
84{
85    uint64_t *ptr;
86    uint64_t *eptr;
87    int recnum = 0;
88
89    if (vapi_logptr == 0) {
90	xprintf("Diagnostic did not record any log records\n");
91	return -1;
92	}
93
94    ptr = (uint64_t *) (intptr_t) vapi_logstart;
95    eptr = (uint64_t *) (intptr_t) vapi_logptr;
96
97    xprintf("*** VAPI LOG START %s\n",
98#ifdef __MIPSEB
99	    "big-endian"
100#else
101	    "little-endian"
102#endif
103	);
104
105    while (ptr < eptr) {
106	xprintf("%6d %016llX %016llX %016llX %016llX\n",
107		recnum,
108		ptr[0],ptr[1],ptr[2],ptr[3]);
109	ptr += 4;
110	recnum++;
111	}
112
113    xprintf("*** VAPI LOG END\n");
114
115    return 0;
116
117
118}
119
120int ui_cmd_vapishow(ui_cmdline_t *cmd,int argc,char *argv[])
121{
122    uint64_t *ptr;
123    uint64_t *eptr;
124    uint32_t a,b;
125    uint32_t ts,len,fmt;
126    unsigned int idx;
127    int recnum = 0;
128
129    if (vapi_logptr == 0) {
130	xprintf("Diagnostic did not record any log records\n");
131	return -1;
132	}
133
134    ptr = (uint64_t *) (intptr_t) vapi_logstart;
135    eptr = (uint64_t *) (intptr_t) vapi_logptr;
136
137    while (ptr < eptr) {
138	a = (ptr[VAPI_IDX_SIGNATURE]) >> 32;
139	b = (ptr[VAPI_IDX_SIGNATURE]) & 0xFFFFFFFF;
140	if ((a & VAPI_SEAL_MASK) != VAPI_CFESEAL) {
141	    xprintf("Incorrect record seal at %08X\n",ptr);
142	    break;
143	    }
144
145	fmt = (a & VAPI_FMT_MASK);
146
147	xprintf("%5d ID=%08X CPU%d %s RA=%08X ",
148		recnum,
149		b,
150		(a & VAPI_PRID_MASK) >> VAPI_PRNUM_SHIFT,
151		rectypes[fmt],
152		ptr[VAPI_IDX_RA]);
153
154	ts =  (ptr[VAPI_IDX_SIZE]) >> 32;
155	len = ((ptr[VAPI_IDX_SIZE]) & 0xFFFFFFFF);
156
157	xprintf("TS=%08X ",ts);
158
159	switch (fmt) {
160	    case VAPI_FMT_GPRS:
161		xprintf("Len=%d\n",len);
162		for (idx = 0; idx < len; idx += 2) {
163		    xprintf("      %016llX  %016llX\n",
164			    ptr[VAPI_IDX_DATA+idx],
165			    ptr[VAPI_IDX_DATA+idx+1]);
166		    }
167		break;
168	    case VAPI_FMT_SOC:
169		xprintf("Len=%d\n",len);
170		for (idx = 0; idx < len; idx += 2) {
171		    xprintf("      Reg=%016llX  Val=%016llX\n",
172			    ptr[VAPI_IDX_DATA+idx],
173			    ptr[VAPI_IDX_DATA+idx+1]);
174		    }
175		break;
176	    case VAPI_FMT_DATA:
177		xprintf("Data=%016llX\n",ptr[VAPI_IDX_DATA]);
178		break;
179	    case VAPI_FMT_BUFFER:
180		xprintf("Addr=%08X\n",(intptr_t) ptr[VAPI_IDX_DATA]);
181		for (idx = 0; idx < len-1; idx += 2) {
182		    xprintf("      %016llX  %016llX\n",
183			    ptr[VAPI_IDX_DATA+idx+1],
184			    ptr[VAPI_IDX_DATA+idx+2]);
185		    }
186		if (idx != (len-1)) {
187		    xprintf("      %016llX\n",
188			    ptr[VAPI_IDX_DATA+idx+1]);
189		    }
190		break;
191	    case VAPI_FMT_TRACE:
192		xprintf("\n");
193		break;
194	    case VAPI_FMT_EXIT:
195		xprintf("Stat=%016llX\n",ptr[VAPI_IDX_DATA]);
196		break;
197	    default:
198		xprintf("\n");
199		break;
200	    }
201
202	ptr += 3 + len;
203	recnum++;
204	}
205
206    return 0;
207
208}
209
210int ui_cmd_vapitest(ui_cmdline_t *cmd,int argc,char *argv[])
211{
212
213    vapitest();
214
215    xprintf("LogStart=%llX LogEnd=%llX LogPtr=%llX\n",
216	    vapi_logstart,vapi_logend,vapi_logptr);
217
218    return 0;
219}
220
221int ui_cmd_vapistatus(ui_cmdline_t *cmd,int argc,char *argv[])
222{
223
224    xprintf("VAPI Exit Status = <%016llX>\n", vapi_status);
225    return 0;
226}
227
228int ui_cmd_vapirun(ui_cmdline_t *cmd,int argc,char *argv[])
229{
230    int mode;		/* 0 = cached, 1 = uncached, 2 = mc mode */
231
232    mode = 0;
233    if (cmd_sw_isset(cmd,"-uncached")) mode = 1;
234    if (cmd_sw_isset(cmd,"-mc")) mode = 2;
235
236    vapi_run(mode);
237    return -1;
238}
239
240
241int ui_init_vapicmds(void)
242{
243    cmd_addcmd("vapi run",
244	       ui_cmd_vapirun,
245	       NULL,
246	       "Run a program using the VAPI reset vector.",
247	       "vapi run\n"
248	       "Executes a previously loaded VAPI program by resetting the\n"
249	       "CPUs and jumping directly to user code.  The program\n"
250	       "must be located at absolute address 0x8002_0000\n",
251	       "-uncached;Start execution at 0xA002_0000 (KSEG1)|"
252	       "-mc;Start execution at 0xBFD0_0000");
253
254    cmd_addcmd("vapi test",
255	       ui_cmd_vapitest,
256	       NULL,
257	       "Test VAPI interface.",
258	       "vapi test\n\n"
259	       "Do some basic calls to the VAPI interface, then return to CFE\n\n",
260	       "");
261
262    cmd_addcmd("vapi dump",
263	       ui_cmd_vapidump,
264	       NULL,
265	       "Show VAPI log in an easily processed format.",
266	       "vapi dump\n\n"
267	       "Display the VAPI log in a format that is more easily postprocessed\n"
268	       "by external programs.\n\n",
269	       "");
270
271    cmd_addcmd("vapi show",
272	       ui_cmd_vapishow,
273	       NULL,
274	       "Show VAPI log.\n",
275	       "vapi show\n\n"
276	       "Display the VAPI log in a human readable form (sort of)\n\n",
277	       "");
278
279    cmd_addcmd("vapi status",
280	       ui_cmd_vapistatus,
281	       NULL,
282	       "Print last VAPI exit status.\n",
283	       "vapi status\n\n"
284	       "Display the exit status of the last VAPI program that was run\n",
285	       "");
286
287    return 0;
288}
289
290#endif
291