|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12:
13: #include <stdint.h>
14: #include <rtas.h>
15: #include "rtas_board.h"
16: #include <bmc.h>
17: #include <rtas_i2c_bmc.h>
18: #include <rtas_ipmi_bmc.h>
19: #include "libipmi.h"
20: #include <hw.h>
21:
22: void io_init(void);
23:
24: typedef struct {
25: uint64_t r3;
26: uint64_t addr;
27: volatile uint64_t id;
28: } slave_t;
29:
30: volatile slave_t rtas_slave_interface;
31:
32: void
33: rtas_slave_loop(volatile slave_t * pIface)
34: {
35: uint64_t mask = pIface->id;
36: pIface->id = 0;
37: while (pIface->id != mask); {
38: int dly = 0x1000;
39: while (dly--);
40: }
41: pIface->id = 0;
42: asm(" mr 3,%0 ; mtctr %1 ; bctr "::"r"(pIface->r3), "r"(pIface->addr));
43:
44: }
45:
46: void
47: rtas_fetch_slaves(rtas_args_t * pArgs)
48: {
49: int retVal = 0;
50: int idx = 0;
51: uint32_t mask = pArgs->args[0] & 0xFFFFFFFE;
52: uint64_t *rtas_slave_loop_ptr = (uint64_t *)rtas_slave_loop;
53: while (mask) {
54: if (mask & 0x1) {
55: rtas_slave_interface.id = idx | 0x100;
56: *(int *) 0x3fc0 = (int)(unsigned long) &rtas_slave_interface; // r3
57: *(int *) 0x3f80 = *rtas_slave_loop_ptr; // addr
58: *(int *) 0x3fa0 = idx | 0x100; // pid
59: while (rtas_slave_interface.id);
60: }
61: mask >>= 1;
62: idx++;
63: }
64: pArgs->args[pArgs->nargs] = retVal;
65: }
66:
67: void
68: rtas_start_cpu(rtas_args_t * pArgs)
69: {
70: int retVal = 0;
71: int idx = pArgs->args[0]; // pid
72: rtas_slave_interface.r3 = pArgs->args[2]; // r3
73: rtas_slave_interface.addr = pArgs->args[1]; // addr
74: asm(" sync ");
75: rtas_slave_interface.id = idx | 0x100; // pid
76: while (rtas_slave_interface.id);
77: pArgs->args[pArgs->nargs] = retVal;
78: }
79:
80: void
81: rtas_read_vpd(rtas_args_t * pArgs)
82: {
83: pArgs->args[pArgs->nargs] =
84: bmc_read_vpd((uint8_t *) (uint64_t) pArgs->args[2], pArgs->args[1],
85: pArgs->args[0]);
86: }
87:
88: void
89: rtas_write_vpd(rtas_args_t * pArgs)
90: {
91: pArgs->args[pArgs->nargs] =
92: bmc_write_vpd((uint8_t *) (uint64_t) pArgs->args[2], pArgs->args[1],
93: pArgs->args[0]);
94: }
95:
96: void
97: rtas_set_indicator(rtas_args_t * pArgs)
98: {
99: pArgs->args[pArgs->nargs] = -1;
100: }
101:
102: void
103: rtas_event_scan(rtas_args_t * pArgs)
104: {
105: pArgs->args[pArgs->nargs] = -1;
106: }
107:
108: void
109: rtas_stop_bootwatchdog(rtas_args_t * pArgs)
110: {
111: pArgs->args[pArgs->nargs] = bmc_stop_bootwatchdog();
112: }
113:
114: void
115: rtas_set_bootwatchdog(rtas_args_t * pArgs)
116: {
117: pArgs->args[pArgs->nargs] = bmc_set_bootwatchdog(pArgs->args[0]);
118: }
119:
120: void
121: rtas_set_flashside(rtas_args_t * pArgs)
122: {
123: pArgs->args[pArgs->nargs] = bmc_set_flashside(pArgs->args[0]);
124: }
125:
126: void
127: rtas_get_flashside(rtas_args_t * pArgs)
128: {
129: int retVal = bmc_get_flashside();
130: pArgs->args[pArgs->nargs] = retVal;
131: }
132:
133: void
134: rtas_flash_test(rtas_args_t * pArgs)
135: {
136: pArgs->args[pArgs->nargs] = -1;
137: }
138:
139: void
140: rtas_system_reboot(rtas_args_t * pArgs)
141: {
142: bmc_system_reboot();
143: pArgs->args[pArgs->nargs] = -1;
144: }
145:
146: void
147: rtas_power_off(rtas_args_t * pArgs)
148: {
149: bmc_power_off();
150: pArgs->args[pArgs->nargs] = -1;
151: }
152:
153: void
154: rtas_get_blade_descr(rtas_args_t * pArgs)
155: {
156: uint8_t *buffer = (uint8_t *) (uint64_t) pArgs->args[0];
157: uint32_t maxlen = pArgs->args[1];
158: uint32_t retlen = 0;
159: uint32_t retval = bmc_get_blade_descr(buffer, maxlen, &retlen);
160: pArgs->args[pArgs->nargs] = retlen;
161: pArgs->args[pArgs->nargs + 1] = retval;
162: }
163:
164: // for JS20 cannot read blade descr
165: uint32_t
166: dummy_get_blade_descr(uint8_t *dst, uint32_t maxlen, uint32_t *len)
167: {
168: // to not have a warning we need to do _something_ with *dst and maxlen...
169: *dst = *dst;
170: maxlen = maxlen;
171: *len = 0;
172: return -1;
173: }
174:
175: /* read flashside from register */
176: short
177: reg_get_flashside(void)
178: {
179: short retVal;
180: uint8_t val = load8_ci(0xf4003fe3);
181: if (val & 0x80) {
182: // temp
183: retVal = 1;
184: } else {
185: // perm
186: retVal = 0;
187: }
188: return retVal;
189: }
190:
191: void
192: rtas_init(void)
193: {
194: io_init();
195: if (u4Flag) {
196: bmc_system_reboot = ipmi_system_reboot;
197: bmc_power_off = ipmi_power_off;
198: bmc_set_flashside = ipmi_set_flashside;
199: bmc_get_flashside = reg_get_flashside;
200: bmc_stop_bootwatchdog = ipmi_oem_stop_bootwatchdog;
201: bmc_set_bootwatchdog = ipmi_oem_set_bootwatchdog;
202: bmc_read_vpd = ipmi_oem_read_vpd;
203: bmc_write_vpd = ipmi_oem_write_vpd;
204: bmc_get_blade_descr = ipmi_oem_get_blade_descr;
205: } else {
206: bmc_system_reboot = i2c_system_reboot;
207: bmc_power_off = i2c_power_off;
208: bmc_set_flashside = i2c_set_flashside;
209: bmc_get_flashside = i2c_get_flashside;
210: bmc_stop_bootwatchdog = i2c_stop_bootwatchdog;
211: bmc_set_bootwatchdog = i2c_set_bootwatchdog;
212: bmc_read_vpd = i2c_read_vpd;
213: bmc_write_vpd = i2c_write_vpd;
214: bmc_get_blade_descr = dummy_get_blade_descr;
215: }
216: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.