1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  RESET command				File: ui_reset.c
5    *
6    *  Commands to reset the CPU
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
50#include "ui_command.h"
51
52#include "sbmips.h"
53#include "sb1250_regs.h"
54#include "sb1250_scd.h"
55#include "bcm1480_scd.h"
56
57/*  *********************************************************************
58    *  Configuration
59    ********************************************************************* */
60
61/*  *********************************************************************
62    *  prototypes
63    ********************************************************************* */
64
65int ui_init_resetcmds(void);
66static int ui_cmd_reset(ui_cmdline_t *cmd,int argc,char *argv[]);
67
68
69/*  *********************************************************************
70    *  Data
71    ********************************************************************* */
72
73
74/*  *********************************************************************
75    *  ui_init_resetcmds()
76    *
77    *  Add RESET-specific commands to the command table
78    *
79    *  Input parameters:
80    *  	   nothing
81    *
82    *  Return value:
83    *  	   0
84    ********************************************************************* */
85
86
87int ui_init_resetcmds(void)
88{
89    cmd_addcmd("reset",
90	       ui_cmd_reset,
91	       NULL,
92	       "Reset the system.",
93	       "reset [-yes] -softreset|-cpu|-unicpu1|-unicpu0|-ext|-sysreset",
94	       "-yes;Don't ask for confirmation|"
95	       "-softreset;Soft reset of the entire chip|"
96	       "-cpu;Reset the CPUs|"
97#if (!SIBYTE_HDR_FEATURE_CHIP(1480))
98	       "-unicpu1;Reset to uniprocessor using CPU1|"
99	       "-unicpu0;Reset to uniprocessor using CPU0|"
100#endif
101	       "-ext;Reset to external devices only|"
102	       "-sysreset;Full system reset");
103
104
105
106    return 0;
107}
108
109
110
111
112
113/*  *********************************************************************
114    *  ui_cmd_reset(cmd,argc,argv)
115    *
116    *  RESET command.
117    *
118    *  Input parameters:
119    *  	   cmd - command structure
120    *  	   argc,argv - parameters
121    *
122    *  Return value:
123    *  	   -1 if error occured.  Does not return otherwise
124    ********************************************************************* */
125
126static int ui_cmd_reset(ui_cmdline_t *cmd,int argc,char *argv[])
127{
128#if SIBYTE_HDR_FEATURE_1250_112x
129    uint64_t data;
130    uint64_t olddata;
131    int confirm = 1;
132    int extreset = 0;
133    char str[50];
134
135    data = SBREADCSR(A_SCD_SYSTEM_CFG) & ~M_SYS_SB_SOFTRES;
136    olddata = data;
137
138    if (cmd_sw_isset(cmd,"-yes")) confirm = 0;
139
140    if (cmd_sw_isset(cmd,"-softreset")) data |= M_SYS_SB_SOFTRES;
141
142    if (cmd_sw_isset(cmd,"-unicpu0")) data |= M_SYS_UNICPU0;
143    else if (cmd_sw_isset(cmd,"-unicpu1")) data |= M_SYS_UNICPU1;
144
145    if (cmd_sw_isset(cmd,"-sysreset")) data |= M_SYS_SYSTEM_RESET;
146
147    if (cmd_sw_isset(cmd,"-cpu")) data |= (M_SYS_CPU_RESET_0 | M_SYS_CPU_RESET_1);
148
149    if (cmd_sw_isset(cmd,"-ext")) {
150        data |= M_SYS_EXT_RESET;
151        extreset = 1;
152    }
153
154    if (data == olddata) {		/* no changes to reset pins were specified */
155	return ui_showusage(cmd);
156	}
157
158    if (confirm) {
159	console_readline("Are you sure you want to reset? ",str,sizeof(str));
160	if ((str[0] != 'Y') && (str[0] != 'y')) return -1;
161	}
162
163    SBWRITECSR(A_SCD_SYSTEM_CFG,data);
164#elif  SIBYTE_HDR_FEATURE_CHIP(1480)
165    uint64_t data;
166    uint64_t olddata;
167    int confirm = 1;
168    char str[50];
169    int extreset = 0;
170
171    data = SBREADCSR(A_SCD_SYSTEM_CFG) & ~M_BCM1480_SYS_SB_SOFTRES;
172    olddata = data;
173
174    if (cmd_sw_isset(cmd,"-yes")) confirm = 0;
175
176    if (cmd_sw_isset(cmd,"-softreset")) data |= M_BCM1480_SYS_SB_SOFTRES;
177
178    if (cmd_sw_isset(cmd,"-sysreset")) data |= M_BCM1480_SYS_SYSTEM_RESET;
179
180    if (cmd_sw_isset(cmd,"-cpu")) data |= (M_BCM1480_SYS_CPU_RESET_0 | M_BCM1480_SYS_CPU_RESET_1 | M_BCM1480_SYS_CPU_RESET_2 | M_BCM1480_SYS_CPU_RESET_3);
181
182    if (data == olddata) {		/* no changes to reset pins were specified */
183	return ui_showusage(cmd);
184	}
185
186    if (confirm) {
187	console_readline("Are you sure you want to reset? ",str,sizeof(str));
188	if ((str[0] != 'Y') && (str[0] != 'y')) return -1;
189	}
190
191    /*
192     * Workaround for BCM1480 S0 erratum SOC-111:
193     *
194     * When writing to the system config register, do two dummy writes to
195     * another SCD CSR first (RO CSRs are OK, we choose the system revision
196     * register in this case since it's easy).
197     *
198     * This makes the assumption that when this code is run, other processors
199     * will **NOT** be writing any SCD registers.  (If other processors do,
200     * this workaround may not be successful.)
201     *
202     * This workaround doesn't need to be conditional on the chip rev
203     * actually in use; it will cause on harm on revisions in which this
204     * erratum is fixed.
205     */
206#if _BCM1480_PASS1_WORKAROUNDS_
207    SBWRITECSR(A_SCD_SYSTEM_REVISION,data);
208    SBWRITECSR(A_SCD_SYSTEM_REVISION,data);
209#endif
210
211    SBWRITECSR(A_SCD_SYSTEM_CFG,data);
212#endif
213
214    /* should not return unless ext reset only */
215
216    if (extreset) {
217        cfe_usleep(1000);
218        SBWRITECSR(A_SCD_SYSTEM_CFG,olddata);
219        return 0;
220    }
221
222    return -1;
223}
224
225
226