1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * P5064-specific commands File: P5064_COMMANDS.C
6 * This module contains special command extensions for the
7 * Algorithmics P5064 port of CFE.
9 * NOTE: Some of the routines in this module were borrowed
12 * Author: Mitch Lichtenberg (mpl@broadcom.com)
14 *********************************************************************
16 * Copyright 2000,2001,2002,2003
17 * Broadcom Corporation. All rights reserved.
19 * This software is furnished under license and may be used and
20 * copied only in accordance with the following terms and
21 * conditions. Subject to these conditions, you may download,
22 * copy, install, use, modify and distribute modified or unmodified
23 * copies of this software in source and/or binary form. No title
24 * or ownership is transferred hereby.
26 * 1) Any source code used, modified or distributed must reproduce
27 * and retain this copyright notice and list of conditions
28 * as they appear in the source file.
30 * 2) No right is granted to use any trade name, trademark, or
31 * logo of Broadcom Corporation. The "Broadcom Corporation"
32 * name may not be used to endorse or promote products derived
33 * from this software without the prior written permission of
34 * Broadcom Corporation.
36 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
40 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
41 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
45 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
46 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
47 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
48 * THE POSSIBILITY OF SUCH DAMAGE.
49 ********************************************************************* */
53 #include "lib_types.h"
54 #include "lib_string.h"
55 #include "lib_queue.h"
56 #include "lib_malloc.h"
57 #include "lib_printf.h"
60 #include "cfe_device.h"
61 #include "cfe_console.h"
62 #include "cfe_devfuncs.h"
63 #include "cfe_timer.h"
64 #include "cfe_ioctl.h"
66 #include "cfe_error.h"
68 #include "ui_command.h"
76 #include "dev_flash.h"
79 #if !defined(__MIPSEB) && !defined(__MIPSEL)
80 #error "You must define either __MIPSEB or __MIPSEL"
84 int ui_init_p5064cmds(void);
85 static int ui_cmd_pcmcia(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
86 static int ui_cmd_poweroff(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
89 static int ui_cmd_vgadump(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
90 static int ui_cmd_vgainit(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
91 extern int vga_biosinit(void);
92 extern void vgaraw_dump(char *tail
);
94 static int ui_cmd_flashtest(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
100 #define OUTB(x,y) outb(x,y)
101 #define OUTW(x,y) outw(x,y)
102 #define OUTL(x,y) outl(x,y)
107 int ui_init_p5064cmds(void)
117 cmd_addcmd("power off",
120 "Power off the system.",
122 "This command turns off the power for systems that support it.",
126 cmd_addcmd("vga init",
129 "Initialize the VGA adapter.",
133 cmd_addcmd("vga dumpbios",
136 "Dump the VGA BIOS to the console",
141 cmd_addcmd("test flash",
144 "Read manufacturer ID from flash",
153 apc_bis (int reg
, unsigned int val
)
155 unsigned int rtcsa
, o
, n
;
157 if (BOARD_REVISION
< 'C')
160 OUTB(RTC_ADDR_PORT
, RTC_STATUSA
);
161 rtcsa
= INB(RTC_DATA_PORT
);
162 if ((rtcsa
& RTCSA_DVMASK
) != RTC_DV2_OSC_ON
)
163 OUTB(RTC_DATA_PORT
, (rtcsa
& ~RTCSA_DVMASK
) | RTC_DV2_OSC_ON
);
165 OUTB(RTC_ADDR_PORT
, reg
);
166 o
= INB(RTC_DATA_PORT
);
169 OUTB(RTC_DATA_PORT
, n
);
172 /* paranoia - switch back to bank 0 */
173 OUTB(RTC_ADDR_PORT
, RTC_STATUSA
);
174 OUTB(RTC_DATA_PORT
, (rtcsa
& ~RTCSA_DVMASK
) | RTC_DV0_OSC_ON
);
181 static int ui_cmd_vgainit(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
185 res
= vga_biosinit();
187 xprintf("vgaraw_init returns %d\n",res
);
192 static int ui_cmd_vgadump(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
196 x
= cmd_getarg(cmd
,0);
206 static void pcicdump(int slot
)
211 for (idx
= 0; idx
< 63; idx
+=16) {
212 xprintf("%02X: ",idx
);
213 for (idx2
= 0; idx2
< 16; idx2
++) {
214 OUTB(0x3E0,idx
+idx2
+slot
*64);
222 #define PCICSET(reg,val) OUTB(0x3E0,(reg)); OUTB(0x3E1,(val))
223 #define PCICGET(reg,val) OUTB(0x3E0,(reg)); val = INB(0x3E1)
225 static int ui_cmd_pcmcia(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
233 tok
= cmd_getarg(cmd
,0);
234 if (!tok
) tok
= "dump";
236 if (strcmp(tok
,"dump") == 0) {
237 xprintf("Slot 0:\n"); pcicdump(0);
239 xprintf("Slot 1:\n"); pcicdump(1);
241 if (strcmp(tok
,"set") == 0) {
242 reg
= cmd_getarg(cmd
,1);
243 val
= cmd_getarg(cmd
,2);
245 xprintf("pcmcia set reg val\n");
248 PCICSET(xtoi(reg
),xtoi(val
));
250 if (strcmp(tok
,"on") == 0) {
256 if (strcmp(tok
,"map") == 0) {
257 reg
= cmd_getarg(cmd
,1);
258 val
= cmd_getarg(cmd
,2);
260 xprintf("pcmcia map start stop [a]\n");
266 PCICSET(0x10,(start
>> 12) & 0xFF);
267 PCICSET(0x11,((start
>> 20) & 0x0F) | 0x00);
268 PCICSET(0x12,(stop
>> 12) & 0xFF);
269 PCICSET(0x13,((stop
>> 20) & 0x0F) | 0x00);
271 offset
= (uint32_t) ((int32_t) 0 - (int32_t) start
);
272 xprintf("Offset = %08X\n",offset
);
274 PCICSET(0x14,(offset
>> 12) & 0xFF);
275 PCICSET(0x15,(((offset
>> 20) & 0x3F) | (cmd_getarg(cmd
,3) ? 0x40 : 0)));
280 if (strcmp(tok
,"detect") == 0) {
283 xprintf("%02X ",det
);
284 while (!console_status()) {
285 PCICGET(0x01,newdet
);
288 xprintf("%02X ",det
);
292 if (strcmp(tok
,"tuples") == 0) {
293 reg
= cmd_getarg(cmd
,1);
295 xprintf("pcmcia tuples isa-addr\n");
299 ptr
= (uint8_t *) (intptr_t) (0xB0000000 | start
);
300 while (*ptr
!= 0xFF) {
307 xprintf("Tuple @ %04X type %02X len %d Data ",
308 (((uint32_t) (intptr_t) ptr
) & 0xFFFF) >> 1,tpl
,len
);
310 xprintf("%02X ",*ptr
);
322 static int ui_cmd_poweroff(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
324 xprintf("Power off.\n");
325 apc_bis(RTC_BANK2_APCR1
, APCR1_SOC
);
331 static char *flashtypes
[] = {
332 "Unknown","SRAM","ROM","Flash"
335 static int ui_cmd_flashtest(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
342 flash_sector_t sector
;
343 nvram_info_t nvraminfo
;
346 devname
= cmd_getarg(cmd
,0);
347 if (!devname
) return ui_showusage(cmd
);
349 fd
= cfe_open(devname
);
351 ui_showerror(fd
,"Could not open flash device %s",devname
);
355 res
= cfe_ioctl(fd
,IOCTL_FLASH_GETINFO
,(uint8_t *) &info
,sizeof(flash_info_t
),&retlen
,0);
357 printf("FLASH: Base %016llX size %08X type %02X(%s) flags %08X\n",
358 info
.flash_base
,info
.flash_size
,info
.flash_type
,flashtypes
[info
.flash_type
],
362 printf("FLASH: Could not determine flash information\n");
365 res
= cfe_ioctl(fd
,IOCTL_NVRAM_GETINFO
,(uint8_t *) &nvraminfo
,sizeof(nvram_info_t
),&retlen
,0);
367 printf("NVRAM: Offset %08X Size %08X EraseFlg %d\n",
368 nvraminfo
.nvram_offset
,nvraminfo
.nvram_size
,nvraminfo
.nvram_eraseflg
);
371 printf("NVRAM: Not supported by this flash\n");
374 if (info
.flash_type
== FLASH_TYPE_FLASH
) {
375 printf("Flash sector information:\n");
379 sector
.flash_sector_idx
= idx
;
380 res
= cfe_ioctl(fd
,IOCTL_FLASH_GETSECTORS
,(uint8_t *) §or
,sizeof(flash_sector_t
),&retlen
,0);
382 printf("ioctl error\n");
385 if (sector
.flash_sector_status
== FLASH_SECTOR_INVALID
) break;
386 printf(" Sector %d offset %08X size %d\n",
387 sector
.flash_sector_idx
,
388 sector
.flash_sector_offset
,
389 sector
.flash_sector_size
);