blob: 8baf0503d92bdc3b6578f28909ea9c90303e33c2 [file] [log] [blame]
Geoff Levand6e74b382006-11-23 00:46:55 +01001/*
2 * PS3 repository routines.
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
Geoff Levand6e74b382006-11-23 00:46:55 +010021#include <asm/lv1call.h>
22
Geoff Levand2a08ea62007-01-30 15:20:27 -080023#include "platform.h"
24
Geoff Levand6e74b382006-11-23 00:46:55 +010025enum ps3_vendor_id {
26 PS3_VENDOR_ID_NONE = 0,
27 PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
28};
29
30enum ps3_lpar_id {
31 PS3_LPAR_ID_CURRENT = 0,
32 PS3_LPAR_ID_PME = 1,
33};
34
35#define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
36static void _dump_field(const char *hdr, u64 n, const char* func, int line)
37{
38#if defined(DEBUG)
39 char s[16];
40 const char *const in = (const char *)&n;
41 unsigned int i;
42
43 for (i = 0; i < 8; i++)
44 s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
45 s[i] = 0;
46
47 pr_debug("%s:%d: %s%016lx : %s\n", func, line, hdr, n, s);
48#endif
49}
50
51#define dump_node_name(_a, _b, _c, _d, _e) \
52 _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
53static void _dump_node_name (unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
54 u64 n4, const char* func, int line)
55{
56 pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
57 _dump_field("n1: ", n1, func, line);
58 _dump_field("n2: ", n2, func, line);
59 _dump_field("n3: ", n3, func, line);
60 _dump_field("n4: ", n4, func, line);
61}
62
63#define dump_node(_a, _b, _c, _d, _e, _f, _g) \
64 _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
65static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
66 u64 v1, u64 v2, const char* func, int line)
67{
68 pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
69 _dump_field("n1: ", n1, func, line);
70 _dump_field("n2: ", n2, func, line);
71 _dump_field("n3: ", n3, func, line);
72 _dump_field("n4: ", n4, func, line);
73 pr_debug("%s:%d: v1: %016lx\n", func, line, v1);
74 pr_debug("%s:%d: v2: %016lx\n", func, line, v2);
75}
76
77/**
78 * make_first_field - Make the first field of a repository node name.
79 * @text: Text portion of the field.
80 * @index: Numeric index portion of the field. Use zero for 'don't care'.
81 *
82 * This routine sets the vendor id to zero (non-vendor specific).
83 * Returns field value.
84 */
85
86static u64 make_first_field(const char *text, u64 index)
87{
88 u64 n;
89
90 strncpy((char *)&n, text, 8);
91 return PS3_VENDOR_ID_NONE + (n >> 32) + index;
92}
93
94/**
95 * make_field - Make subsequent fields of a repository node name.
96 * @text: Text portion of the field. Use "" for 'don't care'.
97 * @index: Numeric index portion of the field. Use zero for 'don't care'.
98 *
99 * Returns field value.
100 */
101
102static u64 make_field(const char *text, u64 index)
103{
104 u64 n;
105
106 strncpy((char *)&n, text, 8);
107 return n + index;
108}
109
110/**
111 * read_node - Read a repository node from raw fields.
112 * @n1: First field of node name.
113 * @n2: Second field of node name. Use zero for 'don't care'.
114 * @n3: Third field of node name. Use zero for 'don't care'.
115 * @n4: Fourth field of node name. Use zero for 'don't care'.
116 * @v1: First repository value (high word).
117 * @v2: Second repository value (low word). Optional parameter, use zero
118 * for 'don't care'.
119 */
120
121static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
122 u64 *_v1, u64 *_v2)
123{
124 int result;
125 u64 v1;
126 u64 v2;
127
128 if (lpar_id == PS3_LPAR_ID_CURRENT) {
129 u64 id;
130 lv1_get_logical_partition_id(&id);
131 lpar_id = id;
132 }
133
134 result = lv1_get_repository_node_value(lpar_id, n1, n2, n3, n4, &v1,
135 &v2);
136
137 if (result) {
138 pr_debug("%s:%d: lv1_get_repository_node_value failed: %s\n",
139 __func__, __LINE__, ps3_result(result));
140 dump_node_name(lpar_id, n1, n2, n3, n4);
Geoff Levanda3323d12007-06-16 07:55:58 +1000141 return -ENOENT;
Geoff Levand6e74b382006-11-23 00:46:55 +0100142 }
143
144 dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
145
146 if (_v1)
147 *_v1 = v1;
148 if (_v2)
149 *_v2 = v2;
150
151 if (v1 && !_v1)
152 pr_debug("%s:%d: warning: discarding non-zero v1: %016lx\n",
153 __func__, __LINE__, v1);
154 if (v2 && !_v2)
155 pr_debug("%s:%d: warning: discarding non-zero v2: %016lx\n",
156 __func__, __LINE__, v2);
157
Geoff Levanda3323d12007-06-16 07:55:58 +1000158 return 0;
Geoff Levand6e74b382006-11-23 00:46:55 +0100159}
160
161int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
162 u64 *value)
163{
164 return read_node(PS3_LPAR_ID_PME,
165 make_first_field("bus", bus_index),
166 make_field(bus_str, 0),
167 0, 0,
168 value, 0);
169}
170
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100171int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id)
Geoff Levand6e74b382006-11-23 00:46:55 +0100172{
173 int result;
Geoff Levand6e74b382006-11-23 00:46:55 +0100174
175 result = read_node(PS3_LPAR_ID_PME,
176 make_first_field("bus", bus_index),
177 make_field("id", 0),
178 0, 0,
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100179 bus_id, NULL);
Geoff Levand6e74b382006-11-23 00:46:55 +0100180 return result;
181}
182
183int ps3_repository_read_bus_type(unsigned int bus_index,
184 enum ps3_bus_type *bus_type)
185{
186 int result;
187 u64 v1;
188
189 result = read_node(PS3_LPAR_ID_PME,
190 make_first_field("bus", bus_index),
191 make_field("type", 0),
192 0, 0,
193 &v1, 0);
194 *bus_type = v1;
195 return result;
196}
197
198int ps3_repository_read_bus_num_dev(unsigned int bus_index,
199 unsigned int *num_dev)
200{
201 int result;
202 u64 v1;
203
204 result = read_node(PS3_LPAR_ID_PME,
205 make_first_field("bus", bus_index),
206 make_field("num_dev", 0),
207 0, 0,
208 &v1, 0);
209 *num_dev = v1;
210 return result;
211}
212
213int ps3_repository_read_dev_str(unsigned int bus_index,
214 unsigned int dev_index, const char *dev_str, u64 *value)
215{
216 return read_node(PS3_LPAR_ID_PME,
217 make_first_field("bus", bus_index),
218 make_field("dev", dev_index),
219 make_field(dev_str, 0),
220 0,
221 value, 0);
222}
223
224int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100225 u64 *dev_id)
Geoff Levand6e74b382006-11-23 00:46:55 +0100226{
227 int result;
Geoff Levand6e74b382006-11-23 00:46:55 +0100228
229 result = read_node(PS3_LPAR_ID_PME,
230 make_first_field("bus", bus_index),
231 make_field("dev", dev_index),
232 make_field("id", 0),
233 0,
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100234 dev_id, 0);
Geoff Levand6e74b382006-11-23 00:46:55 +0100235 return result;
236}
237
238int ps3_repository_read_dev_type(unsigned int bus_index,
239 unsigned int dev_index, enum ps3_dev_type *dev_type)
240{
241 int result;
242 u64 v1;
243
244 result = read_node(PS3_LPAR_ID_PME,
245 make_first_field("bus", bus_index),
246 make_field("dev", dev_index),
247 make_field("type", 0),
248 0,
249 &v1, 0);
250 *dev_type = v1;
251 return result;
252}
253
254int ps3_repository_read_dev_intr(unsigned int bus_index,
255 unsigned int dev_index, unsigned int intr_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800256 enum ps3_interrupt_type *intr_type, unsigned int* interrupt_id)
Geoff Levand6e74b382006-11-23 00:46:55 +0100257{
258 int result;
259 u64 v1;
260 u64 v2;
261
262 result = read_node(PS3_LPAR_ID_PME,
263 make_first_field("bus", bus_index),
264 make_field("dev", dev_index),
265 make_field("intr", intr_index),
266 0,
267 &v1, &v2);
268 *intr_type = v1;
269 *interrupt_id = v2;
270 return result;
271}
272
273int ps3_repository_read_dev_reg_type(unsigned int bus_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800274 unsigned int dev_index, unsigned int reg_index,
275 enum ps3_reg_type *reg_type)
Geoff Levand6e74b382006-11-23 00:46:55 +0100276{
277 int result;
278 u64 v1;
279
280 result = read_node(PS3_LPAR_ID_PME,
281 make_first_field("bus", bus_index),
282 make_field("dev", dev_index),
283 make_field("reg", reg_index),
284 make_field("type", 0),
285 &v1, 0);
286 *reg_type = v1;
287 return result;
288}
289
290int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
291 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
292{
293 return read_node(PS3_LPAR_ID_PME,
294 make_first_field("bus", bus_index),
295 make_field("dev", dev_index),
296 make_field("reg", reg_index),
297 make_field("data", 0),
298 bus_addr, len);
299}
300
301int ps3_repository_read_dev_reg(unsigned int bus_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800302 unsigned int dev_index, unsigned int reg_index,
303 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
Geoff Levand6e74b382006-11-23 00:46:55 +0100304{
305 int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
306 reg_index, reg_type);
307 return result ? result
308 : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
309 reg_index, bus_addr, len);
310}
311
Geoff Levanda3323d12007-06-16 07:55:58 +1000312
313
314int ps3_repository_find_device(struct ps3_repository_device *repo)
Geoff Levand6e74b382006-11-23 00:46:55 +0100315{
Geoff Levanda3323d12007-06-16 07:55:58 +1000316 int result;
317 struct ps3_repository_device tmp = *repo;
318 unsigned int num_dev;
Geoff Levand6e74b382006-11-23 00:46:55 +0100319
Geoff Levanda3323d12007-06-16 07:55:58 +1000320 BUG_ON(repo->bus_index > 10);
321 BUG_ON(repo->dev_index > 10);
Geoff Levand6e74b382006-11-23 00:46:55 +0100322
Geoff Levanda3323d12007-06-16 07:55:58 +1000323 result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
Geoff Levand6e74b382006-11-23 00:46:55 +0100324
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800325 if (result) {
Geoff Levanda3323d12007-06-16 07:55:58 +1000326 pr_debug("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
327 return result;
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800328 }
329
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100330 pr_debug("%s:%d: bus_type %u, bus_index %u, bus_id %lu, num_dev %u\n",
Geoff Levanda3323d12007-06-16 07:55:58 +1000331 __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
332 num_dev);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800333
Geoff Levanda3323d12007-06-16 07:55:58 +1000334 if (tmp.dev_index >= num_dev) {
335 pr_debug("%s:%d: no device found\n", __func__, __LINE__);
336 return -ENODEV;
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800337 }
338
Geoff Levanda3323d12007-06-16 07:55:58 +1000339 result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
340 &tmp.dev_type);
341
342 if (result) {
343 pr_debug("%s:%d read_dev_type failed\n", __func__, __LINE__);
344 return result;
345 }
346
Geert Uytterhoevend51dd3d2007-09-06 18:14:57 +0200347 if (tmp.bus_type == PS3_BUS_TYPE_STORAGE) {
348 /*
349 * A storage device may show up in the repository before the
350 * hypervisor has finished probing its type and regions
351 */
352 unsigned int num_regions;
353
354 if (tmp.dev_type == PS3_DEV_TYPE_STOR_DUMMY) {
355 pr_debug("%s:%u storage device not ready\n", __func__,
356 __LINE__);
357 return -ENODEV;
358 }
359
360 result = ps3_repository_read_stor_dev_num_regions(tmp.bus_index,
361 tmp.dev_index,
362 &num_regions);
363 if (result) {
364 pr_debug("%s:%d read_stor_dev_num_regions failed\n",
365 __func__, __LINE__);
366 return result;
367 }
368
369 if (!num_regions) {
370 pr_debug("%s:%u storage device has no regions yet\n",
371 __func__, __LINE__);
372 return -ENODEV;
373 }
374 }
375
Geoff Levanda3323d12007-06-16 07:55:58 +1000376 result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
377 &tmp.dev_id);
378
379 if (result) {
380 pr_debug("%s:%d ps3_repository_read_dev_id failed\n", __func__,
381 __LINE__);
382 return result;
383 }
384
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +1100385 pr_debug("%s:%d: found: dev_type %u, dev_index %u, dev_id %lu\n",
Geoff Levanda3323d12007-06-16 07:55:58 +1000386 __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
387
388 *repo = tmp;
389 return 0;
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800390}
391
Geoff Levanda3323d12007-06-16 07:55:58 +1000392int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
393 int (*callback)(const struct ps3_repository_device *repo))
Geoff Levand6e74b382006-11-23 00:46:55 +0100394{
395 int result = 0;
Geoff Levanda3323d12007-06-16 07:55:58 +1000396 struct ps3_repository_device repo;
Geoff Levand6e74b382006-11-23 00:46:55 +0100397
Geoff Levanda3323d12007-06-16 07:55:58 +1000398 pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
Geoff Levand6e74b382006-11-23 00:46:55 +0100399
Geoff Levanda3323d12007-06-16 07:55:58 +1000400 for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
Geoff Levand6e74b382006-11-23 00:46:55 +0100401
Geoff Levanda3323d12007-06-16 07:55:58 +1000402 result = ps3_repository_read_bus_type(repo.bus_index,
403 &repo.bus_type);
Geoff Levand6e74b382006-11-23 00:46:55 +0100404
405 if (result) {
406 pr_debug("%s:%d read_bus_type(%u) failed\n",
Geoff Levanda3323d12007-06-16 07:55:58 +1000407 __func__, __LINE__, repo.bus_index);
Geoff Levand6e74b382006-11-23 00:46:55 +0100408 break;
409 }
410
Geoff Levanda3323d12007-06-16 07:55:58 +1000411 if (repo.bus_type != bus_type) {
412 pr_debug("%s:%d: skip, bus_type %u\n", __func__,
413 __LINE__, repo.bus_type);
414 continue;
415 }
416
417 result = ps3_repository_read_bus_id(repo.bus_index,
418 &repo.bus_id);
Geoff Levand6e74b382006-11-23 00:46:55 +0100419
420 if (result) {
421 pr_debug("%s:%d read_bus_id(%u) failed\n",
Geoff Levanda3323d12007-06-16 07:55:58 +1000422 __func__, __LINE__, repo.bus_index);
Geoff Levand6e74b382006-11-23 00:46:55 +0100423 continue;
424 }
425
Geoff Levanda3323d12007-06-16 07:55:58 +1000426 for (repo.dev_index = 0; ; repo.dev_index++) {
427 result = ps3_repository_find_device(&repo);
Geoff Levand6e74b382006-11-23 00:46:55 +0100428
Geoff Levanda3323d12007-06-16 07:55:58 +1000429 if (result == -ENODEV) {
430 result = 0;
431 break;
432 } else if (result)
433 break;
Geoff Levand6e74b382006-11-23 00:46:55 +0100434
Geoff Levanda3323d12007-06-16 07:55:58 +1000435 result = callback(&repo);
436
437 if (result) {
438 pr_debug("%s:%d: abort at callback\n", __func__,
439 __LINE__);
440 break;
441 }
Geoff Levand6e74b382006-11-23 00:46:55 +0100442 }
Geoff Levanda3323d12007-06-16 07:55:58 +1000443 break;
Geoff Levand6e74b382006-11-23 00:46:55 +0100444 }
445
446 pr_debug(" <- %s:%d\n", __func__, __LINE__);
447 return result;
448}
Geoff Levand6e74b382006-11-23 00:46:55 +0100449
Geoff Levanda3323d12007-06-16 07:55:58 +1000450int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
451 unsigned int *bus_index)
Geoff Levand6e74b382006-11-23 00:46:55 +0100452{
Geoff Levanda3323d12007-06-16 07:55:58 +1000453 unsigned int i;
454 enum ps3_bus_type type;
455 int error;
Geoff Levand6e74b382006-11-23 00:46:55 +0100456
Geoff Levanda3323d12007-06-16 07:55:58 +1000457 for (i = from; i < 10; i++) {
458 error = ps3_repository_read_bus_type(i, &type);
459 if (error) {
Geoff Levand6e74b382006-11-23 00:46:55 +0100460 pr_debug("%s:%d read_bus_type failed\n",
461 __func__, __LINE__);
Geoff Levanda3323d12007-06-16 07:55:58 +1000462 *bus_index = UINT_MAX;
463 return error;
Geoff Levand6e74b382006-11-23 00:46:55 +0100464 }
Geoff Levanda3323d12007-06-16 07:55:58 +1000465 if (type == bus_type) {
466 *bus_index = i;
467 return 0;
468 }
Geoff Levand6e74b382006-11-23 00:46:55 +0100469 }
Geoff Levanda3323d12007-06-16 07:55:58 +1000470 *bus_index = UINT_MAX;
471 return -ENODEV;
Geoff Levand6e74b382006-11-23 00:46:55 +0100472}
473
Geoff Levanda3323d12007-06-16 07:55:58 +1000474int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
Geoff Levand6e74b382006-11-23 00:46:55 +0100475 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
476{
477 int result = 0;
478 unsigned int res_index;
479
480 pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
481
482 *interrupt_id = UINT_MAX;
483
484 for (res_index = 0; res_index < 10; res_index++) {
485 enum ps3_interrupt_type t;
486 unsigned int id;
487
Geoff Levanda3323d12007-06-16 07:55:58 +1000488 result = ps3_repository_read_dev_intr(repo->bus_index,
489 repo->dev_index, res_index, &t, &id);
Geoff Levand6e74b382006-11-23 00:46:55 +0100490
491 if (result) {
492 pr_debug("%s:%d read_dev_intr failed\n",
493 __func__, __LINE__);
494 return result;
495 }
496
497 if (t == intr_type) {
498 *interrupt_id = id;
499 break;
500 }
501 }
502
Geoff Levandeebb81c2007-01-26 19:07:47 -0800503 if (res_index == 10)
504 return -ENODEV;
Geoff Levand6e74b382006-11-23 00:46:55 +0100505
506 pr_debug("%s:%d: found intr_type %u at res_index %u\n",
507 __func__, __LINE__, intr_type, res_index);
508
509 return result;
510}
511
Geoff Levanda3323d12007-06-16 07:55:58 +1000512int ps3_repository_find_reg(const struct ps3_repository_device *repo,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800513 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
Geoff Levand6e74b382006-11-23 00:46:55 +0100514{
515 int result = 0;
516 unsigned int res_index;
517
518 pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
519
520 *bus_addr = *len = 0;
521
522 for (res_index = 0; res_index < 10; res_index++) {
Geoff Levandeebb81c2007-01-26 19:07:47 -0800523 enum ps3_reg_type t;
Geoff Levand6e74b382006-11-23 00:46:55 +0100524 u64 a;
525 u64 l;
526
Geoff Levanda3323d12007-06-16 07:55:58 +1000527 result = ps3_repository_read_dev_reg(repo->bus_index,
528 repo->dev_index, res_index, &t, &a, &l);
Geoff Levand6e74b382006-11-23 00:46:55 +0100529
530 if (result) {
531 pr_debug("%s:%d read_dev_reg failed\n",
532 __func__, __LINE__);
533 return result;
534 }
535
536 if (t == reg_type) {
537 *bus_addr = a;
538 *len = l;
539 break;
540 }
541 }
542
Geoff Levandeebb81c2007-01-26 19:07:47 -0800543 if (res_index == 10)
544 return -ENODEV;
Geoff Levand6e74b382006-11-23 00:46:55 +0100545
546 pr_debug("%s:%d: found reg_type %u at res_index %u\n",
547 __func__, __LINE__, reg_type, res_index);
548
549 return result;
550}
551
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800552int ps3_repository_read_stor_dev_port(unsigned int bus_index,
553 unsigned int dev_index, u64 *port)
554{
555 return read_node(PS3_LPAR_ID_PME,
556 make_first_field("bus", bus_index),
557 make_field("dev", dev_index),
558 make_field("port", 0),
559 0, port, 0);
560}
561
562int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
563 unsigned int dev_index, u64 *blk_size)
564{
565 return read_node(PS3_LPAR_ID_PME,
566 make_first_field("bus", bus_index),
567 make_field("dev", dev_index),
568 make_field("blk_size", 0),
569 0, blk_size, 0);
570}
571
572int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
573 unsigned int dev_index, u64 *num_blocks)
574{
575 return read_node(PS3_LPAR_ID_PME,
576 make_first_field("bus", bus_index),
577 make_field("dev", dev_index),
578 make_field("n_blocks", 0),
579 0, num_blocks, 0);
580}
581
582int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
583 unsigned int dev_index, unsigned int *num_regions)
584{
585 int result;
586 u64 v1;
587
588 result = read_node(PS3_LPAR_ID_PME,
589 make_first_field("bus", bus_index),
590 make_field("dev", dev_index),
591 make_field("n_regs", 0),
592 0, &v1, 0);
593 *num_regions = v1;
594 return result;
595}
596
597int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
598 unsigned int dev_index, unsigned int region_index,
599 unsigned int *region_id)
600{
601 int result;
602 u64 v1;
603
604 result = read_node(PS3_LPAR_ID_PME,
605 make_first_field("bus", bus_index),
606 make_field("dev", dev_index),
607 make_field("region", region_index),
608 make_field("id", 0),
609 &v1, 0);
610 *region_id = v1;
611 return result;
612}
613
614int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
615 unsigned int dev_index, unsigned int region_index, u64 *region_size)
616{
617 return read_node(PS3_LPAR_ID_PME,
618 make_first_field("bus", bus_index),
619 make_field("dev", dev_index),
620 make_field("region", region_index),
621 make_field("size", 0),
622 region_size, 0);
623}
624
625int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
626 unsigned int dev_index, unsigned int region_index, u64 *region_start)
627{
628 return read_node(PS3_LPAR_ID_PME,
629 make_first_field("bus", bus_index),
630 make_field("dev", dev_index),
631 make_field("region", region_index),
632 make_field("start", 0),
633 region_start, 0);
634}
635
636int ps3_repository_read_stor_dev_info(unsigned int bus_index,
637 unsigned int dev_index, u64 *port, u64 *blk_size,
638 u64 *num_blocks, unsigned int *num_regions)
639{
640 int result;
641
642 result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
643 if (result)
644 return result;
645
646 result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
647 blk_size);
648 if (result)
649 return result;
650
651 result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
652 num_blocks);
653 if (result)
654 return result;
655
656 result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
657 num_regions);
658 return result;
659}
660
661int ps3_repository_read_stor_dev_region(unsigned int bus_index,
662 unsigned int dev_index, unsigned int region_index,
663 unsigned int *region_id, u64 *region_start, u64 *region_size)
664{
665 int result;
666
667 result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
668 region_index, region_id);
669 if (result)
670 return result;
671
672 result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
673 region_index, region_start);
674 if (result)
675 return result;
676
677 result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
678 region_index, region_size);
679 return result;
680}
681
Geoff Levand6e74b382006-11-23 00:46:55 +0100682int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
683{
684 return read_node(PS3_LPAR_ID_CURRENT,
685 make_first_field("bi", 0),
686 make_field("pu", 0),
687 ppe_id,
688 make_field("rm_size", 0),
689 rm_size, 0);
690}
691
692int ps3_repository_read_region_total(u64 *region_total)
693{
694 return read_node(PS3_LPAR_ID_CURRENT,
695 make_first_field("bi", 0),
696 make_field("rgntotal", 0),
697 0, 0,
698 region_total, 0);
699}
700
701/**
702 * ps3_repository_read_mm_info - Read mm info for single pu system.
703 * @rm_base: Real mode memory base address.
704 * @rm_size: Real mode memory size.
705 * @region_total: Maximum memory region size.
706 */
707
708int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
709{
710 int result;
711 u64 ppe_id;
712
713 lv1_get_logical_ppe_id(&ppe_id);
714 *rm_base = 0;
715 result = ps3_repository_read_rm_size(ppe_id, rm_size);
716 return result ? result
717 : ps3_repository_read_region_total(region_total);
718}
719
720/**
721 * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
722 * @num_spu: Number of physical spus.
723 */
724
725int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
726{
727 int result;
728 u64 v1;
729
730 result = read_node(PS3_LPAR_ID_CURRENT,
731 make_first_field("bi", 0),
732 make_field("spun", 0),
733 0, 0,
734 &v1, 0);
735 *num_spu_reserved = v1;
736 return result;
737}
738
739/**
740 * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
741 * @num_resource_id: Number of spu resource ids.
742 */
743
744int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
745{
746 int result;
747 u64 v1;
748
749 result = read_node(PS3_LPAR_ID_CURRENT,
750 make_first_field("bi", 0),
751 make_field("spursvn", 0),
752 0, 0,
753 &v1, 0);
754 *num_resource_id = v1;
755 return result;
756}
757
758/**
759 * ps3_repository_read_spu_resource_id - spu resource reservation id value.
760 * @res_index: Resource reservation index.
761 * @resource_type: Resource reservation type.
762 * @resource_id: Resource reservation id.
763 */
764
765int ps3_repository_read_spu_resource_id(unsigned int res_index,
766 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id)
767{
768 int result;
769 u64 v1;
770 u64 v2;
771
772 result = read_node(PS3_LPAR_ID_CURRENT,
773 make_first_field("bi", 0),
774 make_field("spursv", 0),
775 res_index,
776 0,
777 &v1, &v2);
778 *resource_type = v1;
779 *resource_id = v2;
780 return result;
781}
782
783int ps3_repository_read_boot_dat_address(u64 *address)
784{
785 return read_node(PS3_LPAR_ID_CURRENT,
786 make_first_field("bi", 0),
787 make_field("boot_dat", 0),
788 make_field("address", 0),
789 0,
790 address, 0);
791}
792
793int ps3_repository_read_boot_dat_size(unsigned int *size)
794{
795 int result;
796 u64 v1;
797
798 result = read_node(PS3_LPAR_ID_CURRENT,
799 make_first_field("bi", 0),
800 make_field("boot_dat", 0),
801 make_field("size", 0),
802 0,
803 &v1, 0);
804 *size = v1;
805 return result;
806}
807
Geoff Levanda3323d12007-06-16 07:55:58 +1000808int ps3_repository_read_vuart_av_port(unsigned int *port)
809{
810 int result;
811 u64 v1;
812
813 result = read_node(PS3_LPAR_ID_CURRENT,
814 make_first_field("bi", 0),
815 make_field("vir_uart", 0),
816 make_field("port", 0),
817 make_field("avset", 0),
818 &v1, 0);
819 *port = v1;
820 return result;
821}
822
823int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
824{
825 int result;
826 u64 v1;
827
828 result = read_node(PS3_LPAR_ID_CURRENT,
829 make_first_field("bi", 0),
830 make_field("vir_uart", 0),
831 make_field("port", 0),
832 make_field("sysmgr", 0),
833 &v1, 0);
834 *port = v1;
835 return result;
836}
837
Geoff Levand6e74b382006-11-23 00:46:55 +0100838/**
839 * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
840 * address: lpar address of cell_ext_os_area
841 * @size: size of cell_ext_os_area
842 */
843
844int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
845{
846 int result;
847
848 *size = 0;
849 result = ps3_repository_read_boot_dat_address(lpar_addr);
850 return result ? result
851 : ps3_repository_read_boot_dat_size(size);
852}
853
854int ps3_repository_read_num_be(unsigned int *num_be)
855{
856 int result;
857 u64 v1;
858
859 result = read_node(PS3_LPAR_ID_PME,
860 make_first_field("ben", 0),
861 0,
862 0,
863 0,
864 &v1, 0);
865 *num_be = v1;
866 return result;
867}
868
869int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
870{
871 return read_node(PS3_LPAR_ID_PME,
872 make_first_field("be", be_index),
873 0,
874 0,
875 0,
876 node_id, 0);
877}
878
879int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
880{
881 return read_node(PS3_LPAR_ID_PME,
882 make_first_field("be", 0),
883 node_id,
884 make_field("clock", 0),
885 0,
886 tb_freq, 0);
887}
888
889int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
890{
891 int result;
892 u64 node_id;
893
894 *tb_freq = 0;
895 result = ps3_repository_read_be_node_id(0, &node_id);
896 return result ? result
897 : ps3_repository_read_tb_freq(node_id, tb_freq);
898}
Geoff Levanda3323d12007-06-16 07:55:58 +1000899
900#if defined(DEBUG)
901
902int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
903{
904 int result = 0;
905 unsigned int res_index;
906
907 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
908 repo->bus_index, repo->dev_index);
909
910 for (res_index = 0; res_index < 10; res_index++) {
911 enum ps3_interrupt_type intr_type;
912 unsigned int interrupt_id;
913
914 result = ps3_repository_read_dev_intr(repo->bus_index,
915 repo->dev_index, res_index, &intr_type, &interrupt_id);
916
917 if (result) {
918 if (result != LV1_NO_ENTRY)
919 pr_debug("%s:%d ps3_repository_read_dev_intr"
920 " (%u:%u) failed\n", __func__, __LINE__,
921 repo->bus_index, repo->dev_index);
922 break;
923 }
924
925 pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
926 __func__, __LINE__, repo->bus_index, repo->dev_index,
927 intr_type, interrupt_id);
928 }
929
930 for (res_index = 0; res_index < 10; res_index++) {
931 enum ps3_reg_type reg_type;
932 u64 bus_addr;
933 u64 len;
934
935 result = ps3_repository_read_dev_reg(repo->bus_index,
936 repo->dev_index, res_index, &reg_type, &bus_addr, &len);
937
938 if (result) {
939 if (result != LV1_NO_ENTRY)
940 pr_debug("%s:%d ps3_repository_read_dev_reg"
941 " (%u:%u) failed\n", __func__, __LINE__,
942 repo->bus_index, repo->dev_index);
943 break;
944 }
945
946 pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
947 __func__, __LINE__, repo->bus_index, repo->dev_index,
948 reg_type, bus_addr, len);
949 }
950
951 pr_debug(" <- %s:%d\n", __func__, __LINE__);
952 return result;
953}
954
955static int dump_stor_dev_info(struct ps3_repository_device *repo)
956{
957 int result = 0;
958 unsigned int num_regions, region_index;
959 u64 port, blk_size, num_blocks;
960
961 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
962 repo->bus_index, repo->dev_index);
963
964 result = ps3_repository_read_stor_dev_info(repo->bus_index,
965 repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
966 if (result) {
967 pr_debug("%s:%d ps3_repository_read_stor_dev_info"
968 " (%u:%u) failed\n", __func__, __LINE__,
969 repo->bus_index, repo->dev_index);
970 goto out;
971 }
972
973 pr_debug("%s:%d (%u:%u): port %lu, blk_size %lu, num_blocks "
974 "%lu, num_regions %u\n",
975 __func__, __LINE__, repo->bus_index, repo->dev_index, port,
976 blk_size, num_blocks, num_regions);
977
978 for (region_index = 0; region_index < num_regions; region_index++) {
979 unsigned int region_id;
980 u64 region_start, region_size;
981
982 result = ps3_repository_read_stor_dev_region(repo->bus_index,
983 repo->dev_index, region_index, &region_id,
984 &region_start, &region_size);
985 if (result) {
986 pr_debug("%s:%d ps3_repository_read_stor_dev_region"
987 " (%u:%u) failed\n", __func__, __LINE__,
988 repo->bus_index, repo->dev_index);
989 break;
990 }
991
992 pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
993 __func__, __LINE__, repo->bus_index, repo->dev_index,
994 region_id, region_start, region_size);
995 }
996
997out:
998 pr_debug(" <- %s:%d\n", __func__, __LINE__);
999 return result;
1000}
1001
1002static int dump_device_info(struct ps3_repository_device *repo,
1003 unsigned int num_dev)
1004{
1005 int result = 0;
1006
1007 pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
1008
1009 for (repo->dev_index = 0; repo->dev_index < num_dev;
1010 repo->dev_index++) {
1011
1012 result = ps3_repository_read_dev_type(repo->bus_index,
1013 repo->dev_index, &repo->dev_type);
1014
1015 if (result) {
1016 pr_debug("%s:%d ps3_repository_read_dev_type"
1017 " (%u:%u) failed\n", __func__, __LINE__,
1018 repo->bus_index, repo->dev_index);
1019 break;
1020 }
1021
1022 result = ps3_repository_read_dev_id(repo->bus_index,
1023 repo->dev_index, &repo->dev_id);
1024
1025 if (result) {
1026 pr_debug("%s:%d ps3_repository_read_dev_id"
1027 " (%u:%u) failed\n", __func__, __LINE__,
1028 repo->bus_index, repo->dev_index);
1029 continue;
1030 }
1031
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +11001032 pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %lu\n", __func__,
Geoff Levanda3323d12007-06-16 07:55:58 +10001033 __LINE__, repo->bus_index, repo->dev_index,
1034 repo->dev_type, repo->dev_id);
1035
1036 ps3_repository_dump_resource_info(repo);
1037
1038 if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
1039 dump_stor_dev_info(repo);
1040 }
1041
1042 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1043 return result;
1044}
1045
1046int ps3_repository_dump_bus_info(void)
1047{
1048 int result = 0;
1049 struct ps3_repository_device repo;
1050
1051 pr_debug(" -> %s:%d\n", __func__, __LINE__);
1052
1053 memset(&repo, 0, sizeof(repo));
1054
1055 for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
1056 unsigned int num_dev;
1057
1058 result = ps3_repository_read_bus_type(repo.bus_index,
1059 &repo.bus_type);
1060
1061 if (result) {
1062 pr_debug("%s:%d read_bus_type(%u) failed\n",
1063 __func__, __LINE__, repo.bus_index);
1064 break;
1065 }
1066
1067 result = ps3_repository_read_bus_id(repo.bus_index,
1068 &repo.bus_id);
1069
1070 if (result) {
1071 pr_debug("%s:%d read_bus_id(%u) failed\n",
1072 __func__, __LINE__, repo.bus_index);
1073 continue;
1074 }
1075
1076 if (repo.bus_index != repo.bus_id)
1077 pr_debug("%s:%d bus_index != bus_id\n",
1078 __func__, __LINE__);
1079
1080 result = ps3_repository_read_bus_num_dev(repo.bus_index,
1081 &num_dev);
1082
1083 if (result) {
1084 pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
1085 __func__, __LINE__, repo.bus_index);
1086 continue;
1087 }
1088
Geert Uytterhoeven034e0ab2008-01-19 07:30:09 +11001089 pr_debug("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n",
Geoff Levanda3323d12007-06-16 07:55:58 +10001090 __func__, __LINE__, repo.bus_index, repo.bus_type,
1091 repo.bus_id, num_dev);
1092
1093 dump_device_info(&repo, num_dev);
1094 }
1095
1096 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1097 return result;
1098}
1099
1100#endif /* defined(DEBUG) */