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