aboutsummaryrefslogtreecommitdiff
path: root/board-js2x/rtas/rtas_board.c
blob: 7f7409d9f311c5d0895532cf34c9d65b0db22b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/******************************************************************************
 * Copyright (c) 2004, 2008 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/

#include <stdint.h>
#include <rtas.h>
#include "rtas_board.h"
#include <bmc.h>
#include <rtas_i2c_bmc.h>
#include <rtas_ipmi_bmc.h>
#include "libipmi.h"
#include <hw.h>

void io_init(void);
short reg_get_flashside(void);
void rtas_init(void);

typedef struct {
	uint64_t r3;
	uint64_t addr;
	volatile uint64_t id;
} slave_t;

volatile slave_t rtas_slave_interface;

static void
rtas_slave_loop(volatile slave_t * pIface)
{
	uint64_t mask = pIface->id;
	pIface->id = 0;
	while (pIface->id != mask); {
		int dly = 0x1000;
		while (dly--);
	}
	pIface->id = 0;
	asm volatile ("  mr 3,%0 ; mtctr %1 ; bctr "
			::"r"(pIface->r3), "r"(pIface->addr));
}

void
rtas_fetch_slaves(rtas_args_t * pArgs)
{
	int retVal = 0;
	int idx = 0;
	uint32_t mask = pArgs->args[0] & 0xFFFFFFFE;
	uint64_t *rtas_slave_loop_ptr = (uint64_t *)rtas_slave_loop;
	while (mask) {
		if (mask & 0x1) {
			rtas_slave_interface.id = idx | 0x100;
			*(int *) 0x3fc0 = (int)(unsigned long) &rtas_slave_interface;	// r3
			*(int *) 0x3f80 = *rtas_slave_loop_ptr;		// addr
			*(int *) 0x3fa0 = idx | 0x100;	// pid
			while (rtas_slave_interface.id);
		}
		mask >>= 1;
		idx++;
	}
	pArgs->args[pArgs->nargs] = retVal;
}

void
rtas_start_cpu(rtas_args_t * pArgs)
{
	int retVal = 0;
	int idx = pArgs->args[0];	// pid
	rtas_slave_interface.r3 = pArgs->args[2];	// r3
	rtas_slave_interface.addr = pArgs->args[1];	// addr
	asm(" sync ");
	rtas_slave_interface.id = idx | 0x100;	// pid
	while (rtas_slave_interface.id);
	pArgs->args[pArgs->nargs] = retVal;
}

void
rtas_read_vpd(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] =
	    bmc_read_vpd((uint8_t *) (uint64_t) pArgs->args[2], pArgs->args[1],
			 pArgs->args[0]);
}

void
rtas_write_vpd(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] =
	    bmc_write_vpd((uint8_t *) (uint64_t) pArgs->args[2], pArgs->args[1],
			  pArgs->args[0]);
}

void
rtas_set_indicator(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = -1;
}

void
rtas_event_scan(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = -1;
}

void
rtas_stop_bootwatchdog(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = bmc_stop_bootwatchdog();
}

void
rtas_set_bootwatchdog(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = bmc_set_bootwatchdog(pArgs->args[0]);
}

void
rtas_set_flashside(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = bmc_set_flashside(pArgs->args[0]);
}

void
rtas_get_flashside(rtas_args_t * pArgs)
{
	int retVal = bmc_get_flashside();
	pArgs->args[pArgs->nargs] = retVal;
}

void
rtas_flash_test(rtas_args_t * pArgs)
{
	pArgs->args[pArgs->nargs] = -1;
}

void
rtas_system_reboot(rtas_args_t * pArgs)
{
	bmc_system_reboot();
	pArgs->args[pArgs->nargs] = -1;
}

void
rtas_power_off(rtas_args_t * pArgs)
{
	bmc_power_off();
	pArgs->args[pArgs->nargs] = -1;
}

void
rtas_get_blade_descr(rtas_args_t * pArgs)
{
	uint8_t *buffer = (uint8_t *) (uint64_t) pArgs->args[0];
	uint32_t maxlen = pArgs->args[1];
	uint32_t retlen = 0;
	uint32_t retval = bmc_get_blade_descr(buffer, maxlen, &retlen);
	pArgs->args[pArgs->nargs] = retlen;
	pArgs->args[pArgs->nargs + 1] = retval;
}

// for JS20 cannot read blade descr
static uint32_t
dummy_get_blade_descr(uint8_t *dst, uint32_t maxlen, uint32_t *len)
{
	// to not have a warning we need to do _something_ with *dst and maxlen...
	*dst = *dst;
	maxlen = maxlen;
	*len = 0;
	return -1;
}

/* read flashside from register */
short
reg_get_flashside(void)
{
	short retVal;
	uint8_t val = load8_ci(0xf4003fe3);
	if (val & 0x80) {
		// temp
		retVal = 1;
	} else {
		// perm
		retVal = 0;
	}
	return retVal;
}

void
rtas_init(void)
{
	io_init();
	if (u4Flag) {
		bmc_system_reboot = ipmi_system_reboot;
		bmc_power_off = ipmi_power_off;
		bmc_set_flashside = ipmi_set_flashside;
		bmc_get_flashside = reg_get_flashside;
		bmc_stop_bootwatchdog = ipmi_oem_stop_bootwatchdog;
		bmc_set_bootwatchdog = ipmi_oem_set_bootwatchdog;
		bmc_read_vpd = ipmi_oem_read_vpd;
		bmc_write_vpd = ipmi_oem_write_vpd;
		bmc_get_blade_descr = ipmi_oem_get_blade_descr;
	} else {
		bmc_system_reboot = i2c_system_reboot;
		bmc_power_off = i2c_power_off;
		bmc_set_flashside = i2c_set_flashside;
		bmc_get_flashside = i2c_get_flashside;
		bmc_stop_bootwatchdog = i2c_stop_bootwatchdog;
		bmc_set_bootwatchdog = i2c_set_bootwatchdog;
		bmc_read_vpd = i2c_read_vpd;
		bmc_write_vpd = i2c_write_vpd;
		bmc_get_blade_descr = dummy_get_blade_descr;
	}
}