1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  SWARM-specific commands			File: ui_swarm.c
5    *
6    *  A temporary sandbox for misc test routines and commands.
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 "ui_command.h"
50
51#if CFG_PCI
52#include "pcivar.h"
53#endif
54
55#include "sbmips.h"
56#include "sb1250_regs.h"
57#include "sb1250_scd.h"
58
59#include "swarm.h"
60
61/*  *********************************************************************
62    *  Configuration
63    ********************************************************************* */
64
65/*  *********************************************************************
66    *  prototypes
67    ********************************************************************* */
68
69int ui_init_swarmcmds(void);
70
71#if CFG_PCI
72static int ui_cmd_map_pci(ui_cmdline_t *cmd,int argc,char *argv[]);
73#endif
74
75#if CFG_VGACONSOLE
76static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[]);
77static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[]);
78extern int vga_biosinit(void);
79extern void vgaraw_dump(char *tail);
80#endif
81
82
83/*  *********************************************************************
84    *  Data
85    ********************************************************************* */
86
87
88/*  *********************************************************************
89    *  ui_init_swarmcmds()
90    *
91    *  Add SWARM-specific commands to the command table
92    *
93    *  Input parameters:
94    *  	   nothing
95    *
96    *  Return value:
97    *  	   0
98    ********************************************************************* */
99
100
101int ui_init_swarmcmds(void)
102{
103#if CFG_PCI
104    cmd_addcmd("map pci",
105	       ui_cmd_map_pci,
106	       NULL,
107	       "Define a BAR0 window available to PCI devices",
108	       "map pci offset size paddr [-off] [-l2ca] [-matchbits]\n\n"
109	       "Map the region of size bytes starting at paddr to appear\n"
110	       "at offset relative to BAR0\n",
111	       "-off;Remove the region|"
112	       "-l2ca;Make L2 cachable|"
113	       "-matchbits;Use match bits policy");
114#endif
115#if CFG_VGACONSOLE
116    cmd_addcmd("vga init",
117	       ui_cmd_vgainit,
118	       NULL,
119	       "Initialize the VGA adapter.",
120	       "vgainit",
121	       "");
122
123    cmd_addcmd("vga dumpbios",
124	       ui_cmd_vgadump,
125	       NULL,
126	       "Dump the VGA BIOS to the console",
127	       "vga dumpbios",
128	       "");
129#endif
130
131    return 0;
132}
133
134
135#if CFG_PCI
136static uint64_t parse_hex(const char *num)
137{
138    uint64_t x = 0;
139    unsigned int digit;
140
141    if ((*num == '0') && (*(num+1) == 'x')) num += 2;
142
143    while (*num) {
144        if ((*num >= '0') && (*num <= '9')) {
145            digit = *num - '0';
146            }
147        else if ((*num >= 'A') && (*num <= 'F')) {
148            digit = 10 + *num - 'A';
149            }
150        else if ((*num >= 'a') && (*num <= 'f')) {
151            digit = 10 + *num - 'a';
152            }
153        else {
154            break;
155            }
156        x *= 16;
157        x += digit;
158        num++;
159        }
160
161    return x;
162}
163
164static int ui_cmd_map_pci(ui_cmdline_t *cmd,int argc,char *argv[])
165{
166    unsigned long offset, size;
167    uint64_t paddr;
168    int l2ca, endian;
169    int enable;
170    int result;
171
172    enable = !cmd_sw_isset(cmd, "-off");
173    if (enable) {
174	offset = parse_hex(cmd_getarg(cmd, 0));
175	size = parse_hex(cmd_getarg(cmd, 1));
176	paddr = parse_hex(cmd_getarg(cmd, 2));
177	l2ca = cmd_sw_isset(cmd,"-l2ca");
178	endian = cmd_sw_isset(cmd, "-matchbits");
179	result = pci_map_window(paddr, offset, size, l2ca, endian);
180	}
181    else {
182	offset = parse_hex(cmd_getarg(cmd, 0));
183	size = parse_hex(cmd_getarg(cmd, 1));
184	result = pci_unmap_window(offset, size);
185	}
186
187    return result;
188}
189#endif
190
191
192#if CFG_VGACONSOLE
193static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[])
194{
195    int res;
196
197    res = vga_biosinit();
198
199    xprintf("vgaraw_init returns %d\n",res);
200
201    return 0;
202}
203
204static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[])
205{
206    char *x;
207
208    x = cmd_getarg(cmd,0);
209    if (!x) x = "";
210
211    vgaraw_dump(x);
212
213    return 0;
214}
215#endif
216
217
218