[POWERPC] PS3: Checkpatch cleanups for arch/powerpc/platforms/ps3/repository.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / powerpc / platforms / ps3 / repository.c
blobcded41eab10fec9bedcffad7f9882cb85a51d565
1 /*
2 * PS3 repository routines.
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
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.
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.
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
21 #include <asm/lv1call.h>
23 #include "platform.h"
25 enum ps3_vendor_id {
26 PS3_VENDOR_ID_NONE = 0,
27 PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
30 enum ps3_lpar_id {
31 PS3_LPAR_ID_CURRENT = 0,
32 PS3_LPAR_ID_PME = 1,
35 #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
36 static void _dump_field(const char *hdr, u64 n, const char *func, int line)
38 #if defined(DEBUG)
39 char s[16];
40 const char *const in = (const char *)&n;
41 unsigned int i;
43 for (i = 0; i < 8; i++)
44 s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
45 s[i] = 0;
47 pr_debug("%s:%d: %s%016lx : %s\n", func, line, hdr, n, s);
48 #endif
51 #define dump_node_name(_a, _b, _c, _d, _e) \
52 _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
53 static void _dump_node_name(unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
54 u64 n4, const char *func, int line)
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);
63 #define dump_node(_a, _b, _c, _d, _e, _f, _g) \
64 _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
65 static 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)
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);
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'.
82 * This routine sets the vendor id to zero (non-vendor specific).
83 * Returns field value.
86 static u64 make_first_field(const char *text, u64 index)
88 u64 n;
90 strncpy((char *)&n, text, 8);
91 return PS3_VENDOR_ID_NONE + (n >> 32) + index;
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'.
99 * Returns field value.
102 static u64 make_field(const char *text, u64 index)
104 u64 n;
106 strncpy((char *)&n, text, 8);
107 return n + index;
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'.
121 static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
122 u64 *_v1, u64 *_v2)
124 int result;
125 u64 v1;
126 u64 v2;
128 if (lpar_id == PS3_LPAR_ID_CURRENT) {
129 u64 id;
130 lv1_get_logical_partition_id(&id);
131 lpar_id = id;
134 result = lv1_get_repository_node_value(lpar_id, n1, n2, n3, n4, &v1,
135 &v2);
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);
141 return -ENOENT;
144 dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
146 if (_v1)
147 *_v1 = v1;
148 if (_v2)
149 *_v2 = v2;
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);
158 return 0;
161 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
162 u64 *value)
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, NULL);
171 int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id)
173 int result;
175 result = read_node(PS3_LPAR_ID_PME,
176 make_first_field("bus", bus_index),
177 make_field("id", 0),
178 0, 0,
179 bus_id, NULL);
180 return result;
183 int ps3_repository_read_bus_type(unsigned int bus_index,
184 enum ps3_bus_type *bus_type)
186 int result;
187 u64 v1;
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, NULL);
194 *bus_type = v1;
195 return result;
198 int ps3_repository_read_bus_num_dev(unsigned int bus_index,
199 unsigned int *num_dev)
201 int result;
202 u64 v1;
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, NULL);
209 *num_dev = v1;
210 return result;
213 int ps3_repository_read_dev_str(unsigned int bus_index,
214 unsigned int dev_index, const char *dev_str, u64 *value)
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),
221 value, NULL);
224 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
225 u64 *dev_id)
227 int result;
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),
234 dev_id, NULL);
235 return result;
238 int ps3_repository_read_dev_type(unsigned int bus_index,
239 unsigned int dev_index, enum ps3_dev_type *dev_type)
241 int result;
242 u64 v1;
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),
249 &v1, NULL);
250 *dev_type = v1;
251 return result;
254 int ps3_repository_read_dev_intr(unsigned int bus_index,
255 unsigned int dev_index, unsigned int intr_index,
256 enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id)
258 int result;
259 u64 v1;
260 u64 v2;
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),
267 &v1, &v2);
268 *intr_type = v1;
269 *interrupt_id = v2;
270 return result;
273 int ps3_repository_read_dev_reg_type(unsigned int bus_index,
274 unsigned int dev_index, unsigned int reg_index,
275 enum ps3_reg_type *reg_type)
277 int result;
278 u64 v1;
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, NULL);
286 *reg_type = v1;
287 return result;
290 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
291 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
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);
301 int ps3_repository_read_dev_reg(unsigned int bus_index,
302 unsigned int dev_index, unsigned int reg_index,
303 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
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);
314 int ps3_repository_find_device(struct ps3_repository_device *repo)
316 int result;
317 struct ps3_repository_device tmp = *repo;
318 unsigned int num_dev;
320 BUG_ON(repo->bus_index > 10);
321 BUG_ON(repo->dev_index > 10);
323 result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
325 if (result) {
326 pr_debug("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
327 return result;
330 pr_debug("%s:%d: bus_type %u, bus_index %u, bus_id %lu, num_dev %u\n",
331 __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
332 num_dev);
334 if (tmp.dev_index >= num_dev) {
335 pr_debug("%s:%d: no device found\n", __func__, __LINE__);
336 return -ENODEV;
339 result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
340 &tmp.dev_type);
342 if (result) {
343 pr_debug("%s:%d read_dev_type failed\n", __func__, __LINE__);
344 return result;
347 result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
348 &tmp.dev_id);
350 if (result) {
351 pr_debug("%s:%d ps3_repository_read_dev_id failed\n", __func__,
352 __LINE__);
353 return result;
356 pr_debug("%s:%d: found: dev_type %u, dev_index %u, dev_id %lu\n",
357 __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
359 *repo = tmp;
360 return 0;
363 int ps3_repository_find_device_by_id(struct ps3_repository_device *repo,
364 u64 bus_id, u64 dev_id)
366 int result = -ENODEV;
367 struct ps3_repository_device tmp;
368 unsigned int num_dev;
370 pr_debug(" -> %s:%u: find device by id %lu:%lu\n", __func__, __LINE__,
371 bus_id, dev_id);
373 for (tmp.bus_index = 0; tmp.bus_index < 10; tmp.bus_index++) {
374 result = ps3_repository_read_bus_id(tmp.bus_index,
375 &tmp.bus_id);
376 if (result) {
377 pr_debug("%s:%u read_bus_id(%u) failed\n", __func__,
378 __LINE__, tmp.bus_index);
379 return result;
382 if (tmp.bus_id == bus_id)
383 goto found_bus;
385 pr_debug("%s:%u: skip, bus_id %lu\n", __func__, __LINE__,
386 tmp.bus_id);
388 pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
389 return result;
391 found_bus:
392 result = ps3_repository_read_bus_type(tmp.bus_index, &tmp.bus_type);
393 if (result) {
394 pr_debug("%s:%u read_bus_type(%u) failed\n", __func__,
395 __LINE__, tmp.bus_index);
396 return result;
399 result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
400 if (result) {
401 pr_debug("%s:%u read_bus_num_dev failed\n", __func__,
402 __LINE__);
403 return result;
406 for (tmp.dev_index = 0; tmp.dev_index < num_dev; tmp.dev_index++) {
407 result = ps3_repository_read_dev_id(tmp.bus_index,
408 tmp.dev_index,
409 &tmp.dev_id);
410 if (result) {
411 pr_debug("%s:%u read_dev_id(%u:%u) failed\n", __func__,
412 __LINE__, tmp.bus_index, tmp.dev_index);
413 return result;
416 if (tmp.dev_id == dev_id)
417 goto found_dev;
419 pr_debug("%s:%u: skip, dev_id %lu\n", __func__, __LINE__,
420 tmp.dev_id);
422 pr_debug(" <- %s:%u: dev not found\n", __func__, __LINE__);
423 return result;
425 found_dev:
426 result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
427 &tmp.dev_type);
428 if (result) {
429 pr_debug("%s:%u read_dev_type failed\n", __func__, __LINE__);
430 return result;
433 pr_debug(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%lu:%lu)\n",
434 __func__, __LINE__, tmp.bus_type, tmp.dev_type, tmp.bus_index,
435 tmp.dev_index, tmp.bus_id, tmp.dev_id);
436 *repo = tmp;
437 return 0;
440 int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
441 int (*callback)(const struct ps3_repository_device *repo))
443 int result = 0;
444 struct ps3_repository_device repo;
446 pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
448 repo.bus_type = bus_type;
449 result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
450 if (result) {
451 pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
452 return result;
455 result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
456 if (result) {
457 pr_debug("%s:%d read_bus_id(%u) failed\n", __func__, __LINE__,
458 repo.bus_index);
459 return result;
462 for (repo.dev_index = 0; ; repo.dev_index++) {
463 result = ps3_repository_find_device(&repo);
464 if (result == -ENODEV) {
465 result = 0;
466 break;
467 } else if (result)
468 break;
470 result = callback(&repo);
471 if (result) {
472 pr_debug("%s:%d: abort at callback\n", __func__,
473 __LINE__);
474 break;
478 pr_debug(" <- %s:%d\n", __func__, __LINE__);
479 return result;
482 int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
483 unsigned int *bus_index)
485 unsigned int i;
486 enum ps3_bus_type type;
487 int error;
489 for (i = from; i < 10; i++) {
490 error = ps3_repository_read_bus_type(i, &type);
491 if (error) {
492 pr_debug("%s:%d read_bus_type failed\n",
493 __func__, __LINE__);
494 *bus_index = UINT_MAX;
495 return error;
497 if (type == bus_type) {
498 *bus_index = i;
499 return 0;
502 *bus_index = UINT_MAX;
503 return -ENODEV;
506 int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
507 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
509 int result = 0;
510 unsigned int res_index;
512 pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
514 *interrupt_id = UINT_MAX;
516 for (res_index = 0; res_index < 10; res_index++) {
517 enum ps3_interrupt_type t;
518 unsigned int id;
520 result = ps3_repository_read_dev_intr(repo->bus_index,
521 repo->dev_index, res_index, &t, &id);
523 if (result) {
524 pr_debug("%s:%d read_dev_intr failed\n",
525 __func__, __LINE__);
526 return result;
529 if (t == intr_type) {
530 *interrupt_id = id;
531 break;
535 if (res_index == 10)
536 return -ENODEV;
538 pr_debug("%s:%d: found intr_type %u at res_index %u\n",
539 __func__, __LINE__, intr_type, res_index);
541 return result;
544 int ps3_repository_find_reg(const struct ps3_repository_device *repo,
545 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
547 int result = 0;
548 unsigned int res_index;
550 pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
552 *bus_addr = *len = 0;
554 for (res_index = 0; res_index < 10; res_index++) {
555 enum ps3_reg_type t;
556 u64 a;
557 u64 l;
559 result = ps3_repository_read_dev_reg(repo->bus_index,
560 repo->dev_index, res_index, &t, &a, &l);
562 if (result) {
563 pr_debug("%s:%d read_dev_reg failed\n",
564 __func__, __LINE__);
565 return result;
568 if (t == reg_type) {
569 *bus_addr = a;
570 *len = l;
571 break;
575 if (res_index == 10)
576 return -ENODEV;
578 pr_debug("%s:%d: found reg_type %u at res_index %u\n",
579 __func__, __LINE__, reg_type, res_index);
581 return result;
584 int ps3_repository_read_stor_dev_port(unsigned int bus_index,
585 unsigned int dev_index, u64 *port)
587 return read_node(PS3_LPAR_ID_PME,
588 make_first_field("bus", bus_index),
589 make_field("dev", dev_index),
590 make_field("port", 0),
591 0, port, NULL);
594 int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
595 unsigned int dev_index, u64 *blk_size)
597 return read_node(PS3_LPAR_ID_PME,
598 make_first_field("bus", bus_index),
599 make_field("dev", dev_index),
600 make_field("blk_size", 0),
601 0, blk_size, NULL);
604 int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
605 unsigned int dev_index, u64 *num_blocks)
607 return read_node(PS3_LPAR_ID_PME,
608 make_first_field("bus", bus_index),
609 make_field("dev", dev_index),
610 make_field("n_blocks", 0),
611 0, num_blocks, NULL);
614 int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
615 unsigned int dev_index, unsigned int *num_regions)
617 int result;
618 u64 v1;
620 result = read_node(PS3_LPAR_ID_PME,
621 make_first_field("bus", bus_index),
622 make_field("dev", dev_index),
623 make_field("n_regs", 0),
624 0, &v1, NULL);
625 *num_regions = v1;
626 return result;
629 int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
630 unsigned int dev_index, unsigned int region_index,
631 unsigned int *region_id)
633 int result;
634 u64 v1;
636 result = read_node(PS3_LPAR_ID_PME,
637 make_first_field("bus", bus_index),
638 make_field("dev", dev_index),
639 make_field("region", region_index),
640 make_field("id", 0),
641 &v1, NULL);
642 *region_id = v1;
643 return result;
646 int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
647 unsigned int dev_index, unsigned int region_index, u64 *region_size)
649 return read_node(PS3_LPAR_ID_PME,
650 make_first_field("bus", bus_index),
651 make_field("dev", dev_index),
652 make_field("region", region_index),
653 make_field("size", 0),
654 region_size, NULL);
657 int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
658 unsigned int dev_index, unsigned int region_index, u64 *region_start)
660 return read_node(PS3_LPAR_ID_PME,
661 make_first_field("bus", bus_index),
662 make_field("dev", dev_index),
663 make_field("region", region_index),
664 make_field("start", 0),
665 region_start, NULL);
668 int ps3_repository_read_stor_dev_info(unsigned int bus_index,
669 unsigned int dev_index, u64 *port, u64 *blk_size,
670 u64 *num_blocks, unsigned int *num_regions)
672 int result;
674 result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
675 if (result)
676 return result;
678 result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
679 blk_size);
680 if (result)
681 return result;
683 result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
684 num_blocks);
685 if (result)
686 return result;
688 result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
689 num_regions);
690 return result;
693 int ps3_repository_read_stor_dev_region(unsigned int bus_index,
694 unsigned int dev_index, unsigned int region_index,
695 unsigned int *region_id, u64 *region_start, u64 *region_size)
697 int result;
699 result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
700 region_index, region_id);
701 if (result)
702 return result;
704 result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
705 region_index, region_start);
706 if (result)
707 return result;
709 result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
710 region_index, region_size);
711 return result;
714 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
716 return read_node(PS3_LPAR_ID_CURRENT,
717 make_first_field("bi", 0),
718 make_field("pu", 0),
719 ppe_id,
720 make_field("rm_size", 0),
721 rm_size, NULL);
724 int ps3_repository_read_region_total(u64 *region_total)
726 return read_node(PS3_LPAR_ID_CURRENT,
727 make_first_field("bi", 0),
728 make_field("rgntotal", 0),
729 0, 0,
730 region_total, NULL);
734 * ps3_repository_read_mm_info - Read mm info for single pu system.
735 * @rm_base: Real mode memory base address.
736 * @rm_size: Real mode memory size.
737 * @region_total: Maximum memory region size.
740 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
742 int result;
743 u64 ppe_id;
745 lv1_get_logical_ppe_id(&ppe_id);
746 *rm_base = 0;
747 result = ps3_repository_read_rm_size(ppe_id, rm_size);
748 return result ? result
749 : ps3_repository_read_region_total(region_total);
753 * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
754 * @num_spu: Number of physical spus.
757 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
759 int result;
760 u64 v1;
762 result = read_node(PS3_LPAR_ID_CURRENT,
763 make_first_field("bi", 0),
764 make_field("spun", 0),
765 0, 0,
766 &v1, NULL);
767 *num_spu_reserved = v1;
768 return result;
772 * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
773 * @num_resource_id: Number of spu resource ids.
776 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
778 int result;
779 u64 v1;
781 result = read_node(PS3_LPAR_ID_CURRENT,
782 make_first_field("bi", 0),
783 make_field("spursvn", 0),
784 0, 0,
785 &v1, NULL);
786 *num_resource_id = v1;
787 return result;
791 * ps3_repository_read_spu_resource_id - spu resource reservation id value.
792 * @res_index: Resource reservation index.
793 * @resource_type: Resource reservation type.
794 * @resource_id: Resource reservation id.
797 int ps3_repository_read_spu_resource_id(unsigned int res_index,
798 enum ps3_spu_resource_type *resource_type, unsigned int *resource_id)
800 int result;
801 u64 v1;
802 u64 v2;
804 result = read_node(PS3_LPAR_ID_CURRENT,
805 make_first_field("bi", 0),
806 make_field("spursv", 0),
807 res_index,
809 &v1, &v2);
810 *resource_type = v1;
811 *resource_id = v2;
812 return result;
815 static int ps3_repository_read_boot_dat_address(u64 *address)
817 return read_node(PS3_LPAR_ID_CURRENT,
818 make_first_field("bi", 0),
819 make_field("boot_dat", 0),
820 make_field("address", 0),
822 address, NULL);
825 int ps3_repository_read_boot_dat_size(unsigned int *size)
827 int result;
828 u64 v1;
830 result = read_node(PS3_LPAR_ID_CURRENT,
831 make_first_field("bi", 0),
832 make_field("boot_dat", 0),
833 make_field("size", 0),
835 &v1, NULL);
836 *size = v1;
837 return result;
840 int ps3_repository_read_vuart_av_port(unsigned int *port)
842 int result;
843 u64 v1;
845 result = read_node(PS3_LPAR_ID_CURRENT,
846 make_first_field("bi", 0),
847 make_field("vir_uart", 0),
848 make_field("port", 0),
849 make_field("avset", 0),
850 &v1, NULL);
851 *port = v1;
852 return result;
855 int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
857 int result;
858 u64 v1;
860 result = read_node(PS3_LPAR_ID_CURRENT,
861 make_first_field("bi", 0),
862 make_field("vir_uart", 0),
863 make_field("port", 0),
864 make_field("sysmgr", 0),
865 &v1, NULL);
866 *port = v1;
867 return result;
871 * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
872 * address: lpar address of cell_ext_os_area
873 * @size: size of cell_ext_os_area
876 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
878 int result;
880 *size = 0;
881 result = ps3_repository_read_boot_dat_address(lpar_addr);
882 return result ? result
883 : ps3_repository_read_boot_dat_size(size);
886 int ps3_repository_read_num_be(unsigned int *num_be)
888 int result;
889 u64 v1;
891 result = read_node(PS3_LPAR_ID_PME,
892 make_first_field("ben", 0),
896 &v1, NULL);
897 *num_be = v1;
898 return result;
901 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
903 return read_node(PS3_LPAR_ID_PME,
904 make_first_field("be", be_index),
908 node_id, NULL);
911 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
913 return read_node(PS3_LPAR_ID_PME,
914 make_first_field("be", 0),
915 node_id,
916 make_field("clock", 0),
918 tb_freq, NULL);
921 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
923 int result;
924 u64 node_id;
926 *tb_freq = 0;
927 result = ps3_repository_read_be_node_id(0, &node_id);
928 return result ? result
929 : ps3_repository_read_tb_freq(node_id, tb_freq);
932 #if defined(DEBUG)
934 int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
936 int result = 0;
937 unsigned int res_index;
939 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
940 repo->bus_index, repo->dev_index);
942 for (res_index = 0; res_index < 10; res_index++) {
943 enum ps3_interrupt_type intr_type;
944 unsigned int interrupt_id;
946 result = ps3_repository_read_dev_intr(repo->bus_index,
947 repo->dev_index, res_index, &intr_type, &interrupt_id);
949 if (result) {
950 if (result != LV1_NO_ENTRY)
951 pr_debug("%s:%d ps3_repository_read_dev_intr"
952 " (%u:%u) failed\n", __func__, __LINE__,
953 repo->bus_index, repo->dev_index);
954 break;
957 pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
958 __func__, __LINE__, repo->bus_index, repo->dev_index,
959 intr_type, interrupt_id);
962 for (res_index = 0; res_index < 10; res_index++) {
963 enum ps3_reg_type reg_type;
964 u64 bus_addr;
965 u64 len;
967 result = ps3_repository_read_dev_reg(repo->bus_index,
968 repo->dev_index, res_index, &reg_type, &bus_addr, &len);
970 if (result) {
971 if (result != LV1_NO_ENTRY)
972 pr_debug("%s:%d ps3_repository_read_dev_reg"
973 " (%u:%u) failed\n", __func__, __LINE__,
974 repo->bus_index, repo->dev_index);
975 break;
978 pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
979 __func__, __LINE__, repo->bus_index, repo->dev_index,
980 reg_type, bus_addr, len);
983 pr_debug(" <- %s:%d\n", __func__, __LINE__);
984 return result;
987 static int dump_stor_dev_info(struct ps3_repository_device *repo)
989 int result = 0;
990 unsigned int num_regions, region_index;
991 u64 port, blk_size, num_blocks;
993 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
994 repo->bus_index, repo->dev_index);
996 result = ps3_repository_read_stor_dev_info(repo->bus_index,
997 repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
998 if (result) {
999 pr_debug("%s:%d ps3_repository_read_stor_dev_info"
1000 " (%u:%u) failed\n", __func__, __LINE__,
1001 repo->bus_index, repo->dev_index);
1002 goto out;
1005 pr_debug("%s:%d (%u:%u): port %lu, blk_size %lu, num_blocks "
1006 "%lu, num_regions %u\n",
1007 __func__, __LINE__, repo->bus_index, repo->dev_index, port,
1008 blk_size, num_blocks, num_regions);
1010 for (region_index = 0; region_index < num_regions; region_index++) {
1011 unsigned int region_id;
1012 u64 region_start, region_size;
1014 result = ps3_repository_read_stor_dev_region(repo->bus_index,
1015 repo->dev_index, region_index, &region_id,
1016 &region_start, &region_size);
1017 if (result) {
1018 pr_debug("%s:%d ps3_repository_read_stor_dev_region"
1019 " (%u:%u) failed\n", __func__, __LINE__,
1020 repo->bus_index, repo->dev_index);
1021 break;
1024 pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
1025 __func__, __LINE__, repo->bus_index, repo->dev_index,
1026 region_id, region_start, region_size);
1029 out:
1030 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1031 return result;
1034 static int dump_device_info(struct ps3_repository_device *repo,
1035 unsigned int num_dev)
1037 int result = 0;
1039 pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
1041 for (repo->dev_index = 0; repo->dev_index < num_dev;
1042 repo->dev_index++) {
1044 result = ps3_repository_read_dev_type(repo->bus_index,
1045 repo->dev_index, &repo->dev_type);
1047 if (result) {
1048 pr_debug("%s:%d ps3_repository_read_dev_type"
1049 " (%u:%u) failed\n", __func__, __LINE__,
1050 repo->bus_index, repo->dev_index);
1051 break;
1054 result = ps3_repository_read_dev_id(repo->bus_index,
1055 repo->dev_index, &repo->dev_id);
1057 if (result) {
1058 pr_debug("%s:%d ps3_repository_read_dev_id"
1059 " (%u:%u) failed\n", __func__, __LINE__,
1060 repo->bus_index, repo->dev_index);
1061 continue;
1064 pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %lu\n", __func__,
1065 __LINE__, repo->bus_index, repo->dev_index,
1066 repo->dev_type, repo->dev_id);
1068 ps3_repository_dump_resource_info(repo);
1070 if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
1071 dump_stor_dev_info(repo);
1074 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1075 return result;
1078 int ps3_repository_dump_bus_info(void)
1080 int result = 0;
1081 struct ps3_repository_device repo;
1083 pr_debug(" -> %s:%d\n", __func__, __LINE__);
1085 memset(&repo, 0, sizeof(repo));
1087 for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
1088 unsigned int num_dev;
1090 result = ps3_repository_read_bus_type(repo.bus_index,
1091 &repo.bus_type);
1093 if (result) {
1094 pr_debug("%s:%d read_bus_type(%u) failed\n",
1095 __func__, __LINE__, repo.bus_index);
1096 break;
1099 result = ps3_repository_read_bus_id(repo.bus_index,
1100 &repo.bus_id);
1102 if (result) {
1103 pr_debug("%s:%d read_bus_id(%u) failed\n",
1104 __func__, __LINE__, repo.bus_index);
1105 continue;
1108 if (repo.bus_index != repo.bus_id)
1109 pr_debug("%s:%d bus_index != bus_id\n",
1110 __func__, __LINE__);
1112 result = ps3_repository_read_bus_num_dev(repo.bus_index,
1113 &num_dev);
1115 if (result) {
1116 pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
1117 __func__, __LINE__, repo.bus_index);
1118 continue;
1121 pr_debug("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n",
1122 __func__, __LINE__, repo.bus_index, repo.bus_type,
1123 repo.bus_id, num_dev);
1125 dump_device_info(&repo, num_dev);
1128 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1129 return result;
1132 #endif /* defined(DEBUG) */