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 enum ps3_interrupt_type *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,
279 enum ps3_reg_type *reg_type)
284 result = read_node(PS3_LPAR_ID_PME,
285 make_first_field("bus", bus_index),
286 make_field("dev", dev_index),
287 make_field("reg", reg_index),
288 make_field("type", 0),
294 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
295 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
297 return read_node(PS3_LPAR_ID_PME,
298 make_first_field("bus", bus_index),
299 make_field("dev", dev_index),
300 make_field("reg", reg_index),
301 make_field("data", 0),
305 int ps3_repository_read_dev_reg(unsigned int bus_index,
306 unsigned int dev_index, unsigned int reg_index,
307 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
309 int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
310 reg_index, reg_type);
311 return result ? result
312 : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
313 reg_index, bus_addr, len);
317 int ps3_repository_dump_resource_info(unsigned int bus_index,
318 unsigned int dev_index)
321 unsigned int res_index;
323 pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
324 bus_index, dev_index);
326 for (res_index = 0; res_index < 10; res_index++) {
327 enum ps3_interrupt_type intr_type;
328 unsigned int interrupt_id;
330 result = ps3_repository_read_dev_intr(bus_index, dev_index,
331 res_index, &intr_type, &interrupt_id);
334 if (result != LV1_NO_ENTRY)
335 pr_debug("%s:%d ps3_repository_read_dev_intr"
336 " (%u:%u) failed\n", __func__, __LINE__,
337 bus_index, dev_index);
341 pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
342 __func__, __LINE__, bus_index, dev_index, intr_type,
346 for (res_index = 0; res_index < 10; res_index++) {
347 enum ps3_reg_type reg_type;
351 result = ps3_repository_read_dev_reg(bus_index, dev_index,
352 res_index, ®_type, &bus_addr, &len);
355 if (result != LV1_NO_ENTRY)
356 pr_debug("%s:%d ps3_repository_read_dev_reg"
357 " (%u:%u) failed\n", __func__, __LINE__,
358 bus_index, dev_index);
362 pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
363 __func__, __LINE__, bus_index, dev_index, reg_type,
367 pr_debug(" <- %s:%d\n", __func__, __LINE__);
371 static int dump_device_info(unsigned int bus_index, unsigned int num_dev)
374 unsigned int dev_index;
376 pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, bus_index);
378 for (dev_index = 0; dev_index < num_dev; dev_index++) {
379 enum ps3_dev_type dev_type;
382 result = ps3_repository_read_dev_type(bus_index, dev_index,
386 pr_debug("%s:%d ps3_repository_read_dev_type"
387 " (%u:%u) failed\n", __func__, __LINE__,
388 bus_index, dev_index);
392 result = ps3_repository_read_dev_id(bus_index, dev_index,
396 pr_debug("%s:%d ps3_repository_read_dev_id"
397 " (%u:%u) failed\n", __func__, __LINE__,
398 bus_index, dev_index);
402 pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %u\n", __func__,
403 __LINE__, bus_index, dev_index, dev_type, dev_id);
405 ps3_repository_dump_resource_info(bus_index, dev_index);
408 pr_debug(" <- %s:%d\n", __func__, __LINE__);
412 int ps3_repository_dump_bus_info(void)
415 unsigned int bus_index;
417 pr_debug(" -> %s:%d\n", __func__, __LINE__);
419 for (bus_index = 0; bus_index < 10; bus_index++) {
420 enum ps3_bus_type bus_type;
422 unsigned int num_dev;
424 result = ps3_repository_read_bus_type(bus_index, &bus_type);
427 pr_debug("%s:%d read_bus_type(%u) failed\n",
428 __func__, __LINE__, bus_index);
432 result = ps3_repository_read_bus_id(bus_index, &bus_id);
435 pr_debug("%s:%d read_bus_id(%u) failed\n",
436 __func__, __LINE__, bus_index);
440 if (bus_index != bus_id)
441 pr_debug("%s:%d bus_index != bus_id\n",
444 result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
447 pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
448 __func__, __LINE__, bus_index);
452 pr_debug("%s:%d bus_%u: bus_type %u, bus_id %u, num_dev %u\n",
453 __func__, __LINE__, bus_index, bus_type, bus_id,
456 dump_device_info(bus_index, num_dev);
459 pr_debug(" <- %s:%d\n", __func__, __LINE__);
462 #endif /* defined(DEBUG) */
464 static int find_device(unsigned int bus_index, unsigned int num_dev,
465 unsigned int start_dev_index, enum ps3_dev_type dev_type,
466 struct ps3_repository_device *dev)
469 unsigned int dev_index;
471 pr_debug("%s:%d: find dev_type %u\n", __func__, __LINE__, dev_type);
473 dev->dev_index = UINT_MAX;
475 for (dev_index = start_dev_index; dev_index < num_dev; dev_index++) {
478 result = ps3_repository_read_dev_type(bus_index, dev_index,
482 pr_debug("%s:%d read_dev_type failed\n",
491 if (dev_index == num_dev)
494 pr_debug("%s:%d: found dev_type %u at dev_index %u\n",
495 __func__, __LINE__, dev_type, dev_index);
497 result = ps3_repository_read_dev_id(bus_index, dev_index,
501 pr_debug("%s:%d read_dev_id failed\n",
506 dev->dev_index = dev_index;
508 pr_debug("%s:%d found: dev_id %u\n", __func__, __LINE__,
514 int ps3_repository_find_device (enum ps3_bus_type bus_type,
515 enum ps3_dev_type dev_type,
516 const struct ps3_repository_device *start_dev,
517 struct ps3_repository_device *dev)
520 unsigned int bus_index;
521 unsigned int num_dev;
523 pr_debug("%s:%d: find bus_type %u, dev_type %u\n", __func__, __LINE__,
526 BUG_ON(start_dev && start_dev->bus_index > 10);
528 for (bus_index = start_dev ? start_dev->bus_index : 0; bus_index < 10;
532 result = ps3_repository_read_bus_type(bus_index, &x);
535 pr_debug("%s:%d read_bus_type failed\n",
537 dev->bus_index = UINT_MAX;
547 pr_debug("%s:%d: found bus_type %u at bus_index %u\n",
548 __func__, __LINE__, bus_type, bus_index);
550 result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
553 pr_debug("%s:%d read_bus_num_dev failed\n",
558 result = find_device(bus_index, num_dev, start_dev
559 ? start_dev->dev_index + 1 : 0, dev_type, dev);
562 pr_debug("%s:%d get_did failed\n", __func__, __LINE__);
566 result = ps3_repository_read_bus_id(bus_index, &dev->did.bus_id);
569 pr_debug("%s:%d read_bus_id failed\n",
574 dev->bus_index = bus_index;
576 pr_debug("%s:%d found: bus_id %u, dev_id %u\n",
577 __func__, __LINE__, dev->did.bus_id, dev->did.dev_id);
582 int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
583 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
586 unsigned int res_index;
588 pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
590 *interrupt_id = UINT_MAX;
592 for (res_index = 0; res_index < 10; res_index++) {
593 enum ps3_interrupt_type t;
596 result = ps3_repository_read_dev_intr(dev->bus_index,
597 dev->dev_index, res_index, &t, &id);
600 pr_debug("%s:%d read_dev_intr failed\n",
605 if (t == intr_type) {
614 pr_debug("%s:%d: found intr_type %u at res_index %u\n",
615 __func__, __LINE__, intr_type, res_index);
620 int ps3_repository_find_reg(const struct ps3_repository_device *dev,
621 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
624 unsigned int res_index;
626 pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
628 *bus_addr = *len = 0;
630 for (res_index = 0; res_index < 10; res_index++) {
635 result = ps3_repository_read_dev_reg(dev->bus_index,
636 dev->dev_index, res_index, &t, &a, &l);
639 pr_debug("%s:%d read_dev_reg failed\n",
654 pr_debug("%s:%d: found reg_type %u at res_index %u\n",
655 __func__, __LINE__, reg_type, res_index);
660 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
662 return read_node(PS3_LPAR_ID_CURRENT,
663 make_first_field("bi", 0),
666 make_field("rm_size", 0),
670 int ps3_repository_read_region_total(u64 *region_total)
672 return read_node(PS3_LPAR_ID_CURRENT,
673 make_first_field("bi", 0),
674 make_field("rgntotal", 0),
680 * ps3_repository_read_mm_info - Read mm info for single pu system.
681 * @rm_base: Real mode memory base address.
682 * @rm_size: Real mode memory size.
683 * @region_total: Maximum memory region size.
686 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
691 lv1_get_logical_ppe_id(&ppe_id);
693 result = ps3_repository_read_rm_size(ppe_id, rm_size);
694 return result ? result
695 : ps3_repository_read_region_total(region_total);
699 * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
700 * @num_spu: Number of physical spus.
703 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
708 result = read_node(PS3_LPAR_ID_CURRENT,
709 make_first_field("bi", 0),
710 make_field("spun", 0),
713 *num_spu_reserved = v1;
718 * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
719 * @num_resource_id: Number of spu resource ids.
722 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
727 result = read_node(PS3_LPAR_ID_CURRENT,
728 make_first_field("bi", 0),
729 make_field("spursvn", 0),
732 *num_resource_id = v1;
737 * ps3_repository_read_spu_resource_id - spu resource reservation id value.
738 * @res_index: Resource reservation index.
739 * @resource_type: Resource reservation type.
740 * @resource_id: Resource reservation id.
743 int ps3_repository_read_spu_resource_id(unsigned int res_index,
744 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id)
750 result = read_node(PS3_LPAR_ID_CURRENT,
751 make_first_field("bi", 0),
752 make_field("spursv", 0),
761 int ps3_repository_read_boot_dat_address(u64 *address)
763 return read_node(PS3_LPAR_ID_CURRENT,
764 make_first_field("bi", 0),
765 make_field("boot_dat", 0),
766 make_field("address", 0),
771 int ps3_repository_read_boot_dat_size(unsigned int *size)
776 result = read_node(PS3_LPAR_ID_CURRENT,
777 make_first_field("bi", 0),
778 make_field("boot_dat", 0),
779 make_field("size", 0),
787 * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
788 * address: lpar address of cell_ext_os_area
789 * @size: size of cell_ext_os_area
792 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
797 result = ps3_repository_read_boot_dat_address(lpar_addr);
798 return result ? result
799 : ps3_repository_read_boot_dat_size(size);
802 int ps3_repository_read_num_be(unsigned int *num_be)
807 result = read_node(PS3_LPAR_ID_PME,
808 make_first_field("ben", 0),
817 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
819 return read_node(PS3_LPAR_ID_PME,
820 make_first_field("be", be_index),
827 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
829 return read_node(PS3_LPAR_ID_PME,
830 make_first_field("be", 0),
832 make_field("clock", 0),
837 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
843 result = ps3_repository_read_be_node_id(0, &node_id);
844 return result ? result
845 : ps3_repository_read_tb_freq(node_id, tb_freq);