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
22 #include <asm/lv1call.h>
25 PS3_VENDOR_ID_NONE = 0,
26 PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
30 PS3_LPAR_ID_CURRENT = 0,
34 #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
35 static void _dump_field(const char *hdr, u64 n, const char* func, int line)
39 const char *const in = (const char *)&n;
42 for (i = 0; i < 8; i++)
43 s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
46 pr_debug("%s:%d: %s%016lx : %s\n", func, line, hdr, n, s);
50 #define dump_node_name(_a, _b, _c, _d, _e) \
51 _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
52 static void _dump_node_name (unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
53 u64 n4, const char* func, int line)
55 pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
56 _dump_field("n1: ", n1, func, line);
57 _dump_field("n2: ", n2, func, line);
58 _dump_field("n3: ", n3, func, line);
59 _dump_field("n4: ", n4, func, line);
62 #define dump_node(_a, _b, _c, _d, _e, _f, _g) \
63 _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
64 static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
65 u64 v1, u64 v2, const char* func, int line)
67 pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
68 _dump_field("n1: ", n1, func, line);
69 _dump_field("n2: ", n2, func, line);
70 _dump_field("n3: ", n3, func, line);
71 _dump_field("n4: ", n4, func, line);
72 pr_debug("%s:%d: v1: %016lx\n", func, line, v1);
73 pr_debug("%s:%d: v2: %016lx\n", func, line, v2);
77 * make_first_field - Make the first field of a repository node name.
78 * @text: Text portion of the field.
79 * @index: Numeric index portion of the field. Use zero for 'don't care'.
81 * This routine sets the vendor id to zero (non-vendor specific).
82 * Returns field value.
85 static u64 make_first_field(const char *text, u64 index)
89 strncpy((char *)&n, text, 8);
90 return PS3_VENDOR_ID_NONE + (n >> 32) + index;
94 * make_field - Make subsequent fields of a repository node name.
95 * @text: Text portion of the field. Use "" for 'don't care'.
96 * @index: Numeric index portion of the field. Use zero for 'don't care'.
98 * Returns field value.
101 static u64 make_field(const char *text, u64 index)
105 strncpy((char *)&n, text, 8);
110 * read_node - Read a repository node from raw fields.
111 * @n1: First field of node name.
112 * @n2: Second field of node name. Use zero for 'don't care'.
113 * @n3: Third field of node name. Use zero for 'don't care'.
114 * @n4: Fourth field of node name. Use zero for 'don't care'.
115 * @v1: First repository value (high word).
116 * @v2: Second repository value (low word). Optional parameter, use zero
120 static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
127 if (lpar_id == PS3_LPAR_ID_CURRENT) {
129 lv1_get_logical_partition_id(&id);
133 result = lv1_get_repository_node_value(lpar_id, n1, n2, n3, n4, &v1,
137 pr_debug("%s:%d: lv1_get_repository_node_value failed: %s\n",
138 __func__, __LINE__, ps3_result(result));
139 dump_node_name(lpar_id, n1, n2, n3, n4);
143 dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
151 pr_debug("%s:%d: warning: discarding non-zero v1: %016lx\n",
152 __func__, __LINE__, v1);
154 pr_debug("%s:%d: warning: discarding non-zero v2: %016lx\n",
155 __func__, __LINE__, v2);
160 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
163 return read_node(PS3_LPAR_ID_PME,
164 make_first_field("bus", bus_index),
165 make_field(bus_str, 0),
170 int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id)
176 result = read_node(PS3_LPAR_ID_PME,
177 make_first_field("bus", bus_index),
185 int ps3_repository_read_bus_type(unsigned int bus_index,
186 enum ps3_bus_type *bus_type)
191 result = read_node(PS3_LPAR_ID_PME,
192 make_first_field("bus", bus_index),
193 make_field("type", 0),
200 int ps3_repository_read_bus_num_dev(unsigned int bus_index,
201 unsigned int *num_dev)
206 result = read_node(PS3_LPAR_ID_PME,
207 make_first_field("bus", bus_index),
208 make_field("num_dev", 0),
215 int ps3_repository_read_dev_str(unsigned int bus_index,
216 unsigned int dev_index, const char *dev_str, u64 *value)
218 return read_node(PS3_LPAR_ID_PME,
219 make_first_field("bus", bus_index),
220 make_field("dev", dev_index),
221 make_field(dev_str, 0),
226 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
227 unsigned int *dev_id)
232 result = read_node(PS3_LPAR_ID_PME,
233 make_first_field("bus", bus_index),
234 make_field("dev", dev_index),
242 int ps3_repository_read_dev_type(unsigned int bus_index,
243 unsigned int dev_index, enum ps3_dev_type *dev_type)
248 result = read_node(PS3_LPAR_ID_PME,
249 make_first_field("bus", bus_index),
250 make_field("dev", dev_index),
251 make_field("type", 0),
258 int ps3_repository_read_dev_intr(unsigned int bus_index,
259 unsigned int dev_index, unsigned int intr_index,
260 unsigned int *intr_type, unsigned int* interrupt_id)
266 result = read_node(PS3_LPAR_ID_PME,
267 make_first_field("bus", bus_index),
268 make_field("dev", dev_index),
269 make_field("intr", intr_index),
277 int ps3_repository_read_dev_reg_type(unsigned int bus_index,
278 unsigned int dev_index, unsigned int reg_index, unsigned int *reg_type)
283 result = read_node(PS3_LPAR_ID_PME,
284 make_first_field("bus", bus_index),
285 make_field("dev", dev_index),
286 make_field("reg", reg_index),
287 make_field("type", 0),
293 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
294 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
296 return read_node(PS3_LPAR_ID_PME,
297 make_first_field("bus", bus_index),
298 make_field("dev", dev_index),
299 make_field("reg", reg_index),
300 make_field("data", 0),
304 int ps3_repository_read_dev_reg(unsigned int bus_index,
305 unsigned int dev_index, unsigned int reg_index, unsigned int *reg_type,
306 u64 *bus_addr, u64 *len)
308 int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
309 reg_index, reg_type);
310 return result ? result
311 : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
312 reg_index, bus_addr, len);
316 int ps3_repository_dump_resource_info(unsigned int bus_index,
317 unsigned int dev_index)
320 unsigned int res_index;
322 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
323 bus_index, dev_index);
325 for (res_index = 0; res_index < 10; res_index++) {
326 enum ps3_interrupt_type intr_type;
327 unsigned int interrupt_id;
329 result = ps3_repository_read_dev_intr(bus_index, dev_index,
330 res_index, &intr_type, &interrupt_id);
333 if (result != LV1_NO_ENTRY)
334 pr_debug("%s:%d ps3_repository_read_dev_intr"
335 " (%u:%u) failed\n", __func__, __LINE__,
336 bus_index, dev_index);
340 pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
341 __func__, __LINE__, bus_index, dev_index, intr_type,
345 for (res_index = 0; res_index < 10; res_index++) {
346 enum ps3_region_type reg_type;
350 result = ps3_repository_read_dev_reg(bus_index, dev_index,
351 res_index, ®_type, &bus_addr, &len);
354 if (result != LV1_NO_ENTRY)
355 pr_debug("%s:%d ps3_repository_read_dev_reg"
356 " (%u:%u) failed\n", __func__, __LINE__,
357 bus_index, dev_index);
361 pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
362 __func__, __LINE__, bus_index, dev_index, reg_type,
366 pr_debug(" <- %s:%d\n", __func__, __LINE__);
370 static int dump_device_info(unsigned int bus_index, unsigned int num_dev)
373 unsigned int dev_index;
375 pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, bus_index);
377 for (dev_index = 0; dev_index < num_dev; dev_index++) {
378 enum ps3_dev_type dev_type;
381 result = ps3_repository_read_dev_type(bus_index, dev_index,
385 pr_debug("%s:%d ps3_repository_read_dev_type"
386 " (%u:%u) failed\n", __func__, __LINE__,
387 bus_index, dev_index);
391 result = ps3_repository_read_dev_id(bus_index, dev_index,
395 pr_debug("%s:%d ps3_repository_read_dev_id"
396 " (%u:%u) failed\n", __func__, __LINE__,
397 bus_index, dev_index);
401 pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %u\n", __func__,
402 __LINE__, bus_index, dev_index, dev_type, dev_id);
404 ps3_repository_dump_resource_info(bus_index, dev_index);
407 pr_debug(" <- %s:%d\n", __func__, __LINE__);
411 int ps3_repository_dump_bus_info(void)
414 unsigned int bus_index;
416 pr_debug(" -> %s:%d\n", __func__, __LINE__);
418 for (bus_index = 0; bus_index < 10; bus_index++) {
419 enum ps3_bus_type bus_type;
421 unsigned int num_dev;
423 result = ps3_repository_read_bus_type(bus_index, &bus_type);
426 pr_debug("%s:%d read_bus_type(%u) failed\n",
427 __func__, __LINE__, bus_index);
431 result = ps3_repository_read_bus_id(bus_index, &bus_id);
434 pr_debug("%s:%d read_bus_id(%u) failed\n",
435 __func__, __LINE__, bus_index);
439 if (bus_index != bus_id)
440 pr_debug("%s:%d bus_index != bus_id\n",
443 result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
446 pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
447 __func__, __LINE__, bus_index);
451 pr_debug("%s:%d bus_%u: bus_type %u, bus_id %u, num_dev %u\n",
452 __func__, __LINE__, bus_index, bus_type, bus_id,
455 dump_device_info(bus_index, num_dev);
458 pr_debug(" <- %s:%d\n", __func__, __LINE__);
461 #endif /* defined(DEBUG) */
463 static int find_device(unsigned int bus_index, unsigned int num_dev,
464 unsigned int start_dev_index, enum ps3_dev_type dev_type,
465 struct ps3_repository_device *dev)
468 unsigned int dev_index;
470 pr_debug("%s:%d: find dev_type %u\n", __func__, __LINE__, dev_type);
472 dev->dev_index = UINT_MAX;
474 for (dev_index = start_dev_index; dev_index < num_dev; dev_index++) {
477 result = ps3_repository_read_dev_type(bus_index, dev_index,
481 pr_debug("%s:%d read_dev_type failed\n",
490 BUG_ON(dev_index == num_dev);
492 pr_debug("%s:%d: found dev_type %u at dev_index %u\n",
493 __func__, __LINE__, dev_type, dev_index);
495 result = ps3_repository_read_dev_id(bus_index, dev_index,
499 pr_debug("%s:%d read_dev_id failed\n",
504 dev->dev_index = dev_index;
506 pr_debug("%s:%d found: dev_id %u\n", __func__, __LINE__,
512 int ps3_repository_find_device (enum ps3_bus_type bus_type,
513 enum ps3_dev_type dev_type,
514 const struct ps3_repository_device *start_dev,
515 struct ps3_repository_device *dev)
518 unsigned int bus_index;
519 unsigned int num_dev;
521 pr_debug("%s:%d: find bus_type %u, dev_type %u\n", __func__, __LINE__,
524 dev->bus_index = UINT_MAX;
526 for (bus_index = start_dev ? start_dev->bus_index : 0; bus_index < 10;
530 result = ps3_repository_read_bus_type(bus_index, &x);
533 pr_debug("%s:%d read_bus_type failed\n",
541 BUG_ON(bus_index == 10);
543 pr_debug("%s:%d: found bus_type %u at bus_index %u\n",
544 __func__, __LINE__, bus_type, bus_index);
546 result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
549 pr_debug("%s:%d read_bus_num_dev failed\n",
554 result = find_device(bus_index, num_dev, start_dev
555 ? start_dev->dev_index + 1 : 0, dev_type, dev);
558 pr_debug("%s:%d get_did failed\n", __func__, __LINE__);
562 result = ps3_repository_read_bus_id(bus_index, &dev->did.bus_id);
565 pr_debug("%s:%d read_bus_id failed\n",
570 dev->bus_index = bus_index;
572 pr_debug("%s:%d found: bus_id %u, dev_id %u\n",
573 __func__, __LINE__, dev->did.bus_id, dev->did.dev_id);
578 int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
579 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
582 unsigned int res_index;
584 pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
586 *interrupt_id = UINT_MAX;
588 for (res_index = 0; res_index < 10; res_index++) {
589 enum ps3_interrupt_type t;
592 result = ps3_repository_read_dev_intr(dev->bus_index,
593 dev->dev_index, res_index, &t, &id);
596 pr_debug("%s:%d read_dev_intr failed\n",
601 if (t == intr_type) {
607 BUG_ON(res_index == 10);
609 pr_debug("%s:%d: found intr_type %u at res_index %u\n",
610 __func__, __LINE__, intr_type, res_index);
615 int ps3_repository_find_region(const struct ps3_repository_device *dev,
616 enum ps3_region_type reg_type, u64 *bus_addr, u64 *len)
619 unsigned int res_index;
621 pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
623 *bus_addr = *len = 0;
625 for (res_index = 0; res_index < 10; res_index++) {
626 enum ps3_region_type t;
630 result = ps3_repository_read_dev_reg(dev->bus_index,
631 dev->dev_index, res_index, &t, &a, &l);
634 pr_debug("%s:%d read_dev_reg failed\n",
646 BUG_ON(res_index == 10);
648 pr_debug("%s:%d: found reg_type %u at res_index %u\n",
649 __func__, __LINE__, reg_type, res_index);
654 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
656 return read_node(PS3_LPAR_ID_CURRENT,
657 make_first_field("bi", 0),
660 make_field("rm_size", 0),
664 int ps3_repository_read_region_total(u64 *region_total)
666 return read_node(PS3_LPAR_ID_CURRENT,
667 make_first_field("bi", 0),
668 make_field("rgntotal", 0),
674 * ps3_repository_read_mm_info - Read mm info for single pu system.
675 * @rm_base: Real mode memory base address.
676 * @rm_size: Real mode memory size.
677 * @region_total: Maximum memory region size.
680 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
685 lv1_get_logical_ppe_id(&ppe_id);
687 result = ps3_repository_read_rm_size(ppe_id, rm_size);
688 return result ? result
689 : ps3_repository_read_region_total(region_total);
693 * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
694 * @num_spu: Number of physical spus.
697 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
702 result = read_node(PS3_LPAR_ID_CURRENT,
703 make_first_field("bi", 0),
704 make_field("spun", 0),
707 *num_spu_reserved = v1;
712 * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
713 * @num_resource_id: Number of spu resource ids.
716 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
721 result = read_node(PS3_LPAR_ID_CURRENT,
722 make_first_field("bi", 0),
723 make_field("spursvn", 0),
726 *num_resource_id = v1;
731 * ps3_repository_read_spu_resource_id - spu resource reservation id value.
732 * @res_index: Resource reservation index.
733 * @resource_type: Resource reservation type.
734 * @resource_id: Resource reservation id.
737 int ps3_repository_read_spu_resource_id(unsigned int res_index,
738 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id)
744 result = read_node(PS3_LPAR_ID_CURRENT,
745 make_first_field("bi", 0),
746 make_field("spursv", 0),
755 int ps3_repository_read_boot_dat_address(u64 *address)
757 return read_node(PS3_LPAR_ID_CURRENT,
758 make_first_field("bi", 0),
759 make_field("boot_dat", 0),
760 make_field("address", 0),
765 int ps3_repository_read_boot_dat_size(unsigned int *size)
770 result = read_node(PS3_LPAR_ID_CURRENT,
771 make_first_field("bi", 0),
772 make_field("boot_dat", 0),
773 make_field("size", 0),
781 * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
782 * address: lpar address of cell_ext_os_area
783 * @size: size of cell_ext_os_area
786 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
791 result = ps3_repository_read_boot_dat_address(lpar_addr);
792 return result ? result
793 : ps3_repository_read_boot_dat_size(size);
796 int ps3_repository_read_num_be(unsigned int *num_be)
801 result = read_node(PS3_LPAR_ID_PME,
802 make_first_field("ben", 0),
811 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
813 return read_node(PS3_LPAR_ID_PME,
814 make_first_field("be", be_index),
821 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
823 return read_node(PS3_LPAR_ID_PME,
824 make_first_field("be", 0),
826 make_field("clock", 0),
831 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
837 result = ps3_repository_read_be_node_id(0, &node_id);
838 return result ? result
839 : ps3_repository_read_tb_freq(node_id, tb_freq);