1 // SPDX-License-Identifier: GPL-2.0-only
3 * PS3 repository routines.
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
9 #include <asm/lv1call.h>
14 PS3_VENDOR_ID_NONE = 0,
15 PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
19 PS3_LPAR_ID_CURRENT = 0,
23 #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
24 static void _dump_field(const char *hdr, u64 n, const char *func, int line)
28 const char *const in = (const char *)&n;
31 for (i = 0; i < 8; i++)
32 s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
35 pr_devel("%s:%d: %s%016llx : %s\n", func, line, hdr, n, s);
39 #define dump_node_name(_a, _b, _c, _d, _e) \
40 _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
41 static void _dump_node_name(unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
42 u64 n4, const char *func, int line)
44 pr_devel("%s:%d: lpar: %u\n", func, line, lpar_id);
45 _dump_field("n1: ", n1, func, line);
46 _dump_field("n2: ", n2, func, line);
47 _dump_field("n3: ", n3, func, line);
48 _dump_field("n4: ", n4, func, line);
51 #define dump_node(_a, _b, _c, _d, _e, _f, _g) \
52 _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
53 static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
54 u64 v1, u64 v2, const char *func, int line)
56 pr_devel("%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 pr_devel("%s:%d: v1: %016llx\n", func, line, v1);
62 pr_devel("%s:%d: v2: %016llx\n", func, line, v2);
66 * make_first_field - Make the first field of a repository node name.
67 * @text: Text portion of the field.
68 * @index: Numeric index portion of the field. Use zero for 'don't care'.
70 * This routine sets the vendor id to zero (non-vendor specific).
71 * Returns field value.
74 static u64 make_first_field(const char *text, u64 index)
78 strncpy((char *)&n, text, 8);
79 return PS3_VENDOR_ID_NONE + (n >> 32) + index;
83 * make_field - Make subsequent fields of a repository node name.
84 * @text: Text portion of the field. Use "" for 'don't care'.
85 * @index: Numeric index portion of the field. Use zero for 'don't care'.
87 * Returns field value.
90 static u64 make_field(const char *text, u64 index)
94 memcpy((char *)&n, text, strnlen(text, sizeof(n)));
99 * read_node - Read a repository node from raw fields.
100 * @n1: First field of node name.
101 * @n2: Second field of node name. Use zero for 'don't care'.
102 * @n3: Third field of node name. Use zero for 'don't care'.
103 * @n4: Fourth field of node name. Use zero for 'don't care'.
104 * @v1: First repository value (high word).
105 * @v2: Second repository value (low word). Optional parameter, use zero
109 static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
116 if (lpar_id == PS3_LPAR_ID_CURRENT) {
118 lv1_get_logical_partition_id(&id);
122 result = lv1_read_repository_node(lpar_id, n1, n2, n3, n4, &v1,
126 pr_warn("%s:%d: lv1_read_repository_node failed: %s\n",
127 __func__, __LINE__, ps3_result(result));
128 dump_node_name(lpar_id, n1, n2, n3, n4);
132 dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
140 pr_devel("%s:%d: warning: discarding non-zero v1: %016llx\n",
141 __func__, __LINE__, v1);
143 pr_devel("%s:%d: warning: discarding non-zero v2: %016llx\n",
144 __func__, __LINE__, v2);
149 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
152 return read_node(PS3_LPAR_ID_PME,
153 make_first_field("bus", bus_index),
154 make_field(bus_str, 0),
159 int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id)
161 return read_node(PS3_LPAR_ID_PME, make_first_field("bus", bus_index),
162 make_field("id", 0), 0, 0, bus_id, NULL);
165 int ps3_repository_read_bus_type(unsigned int bus_index,
166 enum ps3_bus_type *bus_type)
171 result = read_node(PS3_LPAR_ID_PME,
172 make_first_field("bus", bus_index),
173 make_field("type", 0),
180 int ps3_repository_read_bus_num_dev(unsigned int bus_index,
181 unsigned int *num_dev)
186 result = read_node(PS3_LPAR_ID_PME,
187 make_first_field("bus", bus_index),
188 make_field("num_dev", 0),
195 int ps3_repository_read_dev_str(unsigned int bus_index,
196 unsigned int dev_index, const char *dev_str, u64 *value)
198 return read_node(PS3_LPAR_ID_PME,
199 make_first_field("bus", bus_index),
200 make_field("dev", dev_index),
201 make_field(dev_str, 0),
206 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
209 return read_node(PS3_LPAR_ID_PME, make_first_field("bus", bus_index),
210 make_field("dev", dev_index), make_field("id", 0), 0,
214 int ps3_repository_read_dev_type(unsigned int bus_index,
215 unsigned int dev_index, enum ps3_dev_type *dev_type)
220 result = read_node(PS3_LPAR_ID_PME,
221 make_first_field("bus", bus_index),
222 make_field("dev", dev_index),
223 make_field("type", 0),
230 int ps3_repository_read_dev_intr(unsigned int bus_index,
231 unsigned int dev_index, unsigned int intr_index,
232 enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id)
238 result = read_node(PS3_LPAR_ID_PME,
239 make_first_field("bus", bus_index),
240 make_field("dev", dev_index),
241 make_field("intr", intr_index),
249 int ps3_repository_read_dev_reg_type(unsigned int bus_index,
250 unsigned int dev_index, unsigned int reg_index,
251 enum ps3_reg_type *reg_type)
256 result = read_node(PS3_LPAR_ID_PME,
257 make_first_field("bus", bus_index),
258 make_field("dev", dev_index),
259 make_field("reg", reg_index),
260 make_field("type", 0),
266 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
267 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
269 return read_node(PS3_LPAR_ID_PME,
270 make_first_field("bus", bus_index),
271 make_field("dev", dev_index),
272 make_field("reg", reg_index),
273 make_field("data", 0),
277 int ps3_repository_read_dev_reg(unsigned int bus_index,
278 unsigned int dev_index, unsigned int reg_index,
279 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
281 int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
282 reg_index, reg_type);
283 return result ? result
284 : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
285 reg_index, bus_addr, len);
290 int ps3_repository_find_device(struct ps3_repository_device *repo)
293 struct ps3_repository_device tmp = *repo;
294 unsigned int num_dev;
296 BUG_ON(repo->bus_index > 10);
297 BUG_ON(repo->dev_index > 10);
299 result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
302 pr_devel("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
306 pr_devel("%s:%d: bus_type %u, bus_index %u, bus_id %llu, num_dev %u\n",
307 __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
310 if (tmp.dev_index >= num_dev) {
311 pr_devel("%s:%d: no device found\n", __func__, __LINE__);
315 result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
319 pr_devel("%s:%d read_dev_type failed\n", __func__, __LINE__);
323 result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
327 pr_devel("%s:%d ps3_repository_read_dev_id failed\n", __func__,
332 pr_devel("%s:%d: found: dev_type %u, dev_index %u, dev_id %llu\n",
333 __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
339 int ps3_repository_find_device_by_id(struct ps3_repository_device *repo,
340 u64 bus_id, u64 dev_id)
342 int result = -ENODEV;
343 struct ps3_repository_device tmp;
344 unsigned int num_dev;
346 pr_devel(" -> %s:%u: find device by id %llu:%llu\n", __func__, __LINE__,
349 for (tmp.bus_index = 0; tmp.bus_index < 10; tmp.bus_index++) {
350 result = ps3_repository_read_bus_id(tmp.bus_index,
353 pr_devel("%s:%u read_bus_id(%u) failed\n", __func__,
354 __LINE__, tmp.bus_index);
358 if (tmp.bus_id == bus_id)
361 pr_devel("%s:%u: skip, bus_id %llu\n", __func__, __LINE__,
364 pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__);
368 result = ps3_repository_read_bus_type(tmp.bus_index, &tmp.bus_type);
370 pr_devel("%s:%u read_bus_type(%u) failed\n", __func__,
371 __LINE__, tmp.bus_index);
375 result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
377 pr_devel("%s:%u read_bus_num_dev failed\n", __func__,
382 for (tmp.dev_index = 0; tmp.dev_index < num_dev; tmp.dev_index++) {
383 result = ps3_repository_read_dev_id(tmp.bus_index,
387 pr_devel("%s:%u read_dev_id(%u:%u) failed\n", __func__,
388 __LINE__, tmp.bus_index, tmp.dev_index);
392 if (tmp.dev_id == dev_id)
395 pr_devel("%s:%u: skip, dev_id %llu\n", __func__, __LINE__,
398 pr_devel(" <- %s:%u: dev not found\n", __func__, __LINE__);
402 result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
405 pr_devel("%s:%u read_dev_type failed\n", __func__, __LINE__);
409 pr_devel(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%llu:%llu)\n",
410 __func__, __LINE__, tmp.bus_type, tmp.dev_type, tmp.bus_index,
411 tmp.dev_index, tmp.bus_id, tmp.dev_id);
416 int ps3_repository_find_devices(enum ps3_bus_type bus_type,
417 int (*callback)(const struct ps3_repository_device *repo))
420 struct ps3_repository_device repo;
422 pr_devel(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
424 repo.bus_type = bus_type;
425 result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
427 pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__);
431 result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
433 pr_devel("%s:%d read_bus_id(%u) failed\n", __func__, __LINE__,
438 for (repo.dev_index = 0; ; repo.dev_index++) {
439 result = ps3_repository_find_device(&repo);
440 if (result == -ENODEV) {
446 result = callback(&repo);
448 pr_devel("%s:%d: abort at callback\n", __func__,
454 pr_devel(" <- %s:%d\n", __func__, __LINE__);
458 int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
459 unsigned int *bus_index)
462 enum ps3_bus_type type;
465 for (i = from; i < 10; i++) {
466 error = ps3_repository_read_bus_type(i, &type);
468 pr_devel("%s:%d read_bus_type failed\n",
470 *bus_index = UINT_MAX;
473 if (type == bus_type) {
478 *bus_index = UINT_MAX;
482 int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
483 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
486 unsigned int res_index;
488 pr_devel("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
490 *interrupt_id = UINT_MAX;
492 for (res_index = 0; res_index < 10; res_index++) {
493 enum ps3_interrupt_type t;
496 result = ps3_repository_read_dev_intr(repo->bus_index,
497 repo->dev_index, res_index, &t, &id);
500 pr_devel("%s:%d read_dev_intr failed\n",
505 if (t == intr_type) {
514 pr_devel("%s:%d: found intr_type %u at res_index %u\n",
515 __func__, __LINE__, intr_type, res_index);
520 int ps3_repository_find_reg(const struct ps3_repository_device *repo,
521 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
524 unsigned int res_index;
526 pr_devel("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
528 *bus_addr = *len = 0;
530 for (res_index = 0; res_index < 10; res_index++) {
535 result = ps3_repository_read_dev_reg(repo->bus_index,
536 repo->dev_index, res_index, &t, &a, &l);
539 pr_devel("%s:%d read_dev_reg failed\n",
554 pr_devel("%s:%d: found reg_type %u at res_index %u\n",
555 __func__, __LINE__, reg_type, res_index);
560 int ps3_repository_read_stor_dev_port(unsigned int bus_index,
561 unsigned int dev_index, u64 *port)
563 return read_node(PS3_LPAR_ID_PME,
564 make_first_field("bus", bus_index),
565 make_field("dev", dev_index),
566 make_field("port", 0),
570 int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
571 unsigned int dev_index, u64 *blk_size)
573 return read_node(PS3_LPAR_ID_PME,
574 make_first_field("bus", bus_index),
575 make_field("dev", dev_index),
576 make_field("blk_size", 0),
580 int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
581 unsigned int dev_index, u64 *num_blocks)
583 return read_node(PS3_LPAR_ID_PME,
584 make_first_field("bus", bus_index),
585 make_field("dev", dev_index),
586 make_field("n_blocks", 0),
587 0, num_blocks, NULL);
590 int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
591 unsigned int dev_index, unsigned int *num_regions)
596 result = read_node(PS3_LPAR_ID_PME,
597 make_first_field("bus", bus_index),
598 make_field("dev", dev_index),
599 make_field("n_regs", 0),
605 int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
606 unsigned int dev_index, unsigned int region_index,
607 unsigned int *region_id)
612 result = read_node(PS3_LPAR_ID_PME,
613 make_first_field("bus", bus_index),
614 make_field("dev", dev_index),
615 make_field("region", region_index),
622 int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
623 unsigned int dev_index, unsigned int region_index, u64 *region_size)
625 return read_node(PS3_LPAR_ID_PME,
626 make_first_field("bus", bus_index),
627 make_field("dev", dev_index),
628 make_field("region", region_index),
629 make_field("size", 0),
633 int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
634 unsigned int dev_index, unsigned int region_index, u64 *region_start)
636 return 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("start", 0),
644 int ps3_repository_read_stor_dev_info(unsigned int bus_index,
645 unsigned int dev_index, u64 *port, u64 *blk_size,
646 u64 *num_blocks, unsigned int *num_regions)
650 result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
654 result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
659 result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
664 result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
669 int ps3_repository_read_stor_dev_region(unsigned int bus_index,
670 unsigned int dev_index, unsigned int region_index,
671 unsigned int *region_id, u64 *region_start, u64 *region_size)
675 result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
676 region_index, region_id);
680 result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
681 region_index, region_start);
685 result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
686 region_index, region_size);
691 * ps3_repository_read_num_pu - Number of logical PU processors for this lpar.
694 int ps3_repository_read_num_pu(u64 *num_pu)
697 return read_node(PS3_LPAR_ID_CURRENT,
698 make_first_field("bi", 0),
699 make_field("pun", 0),
705 * ps3_repository_read_pu_id - Read the logical PU id.
706 * @pu_index: Zero based index.
707 * @pu_id: The logical PU id.
710 int ps3_repository_read_pu_id(unsigned int pu_index, u64 *pu_id)
712 return read_node(PS3_LPAR_ID_CURRENT,
713 make_first_field("bi", 0),
714 make_field("pu", pu_index),
719 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
721 return read_node(PS3_LPAR_ID_CURRENT,
722 make_first_field("bi", 0),
725 make_field("rm_size", 0),
729 int ps3_repository_read_region_total(u64 *region_total)
731 return read_node(PS3_LPAR_ID_CURRENT,
732 make_first_field("bi", 0),
733 make_field("rgntotal", 0),
739 * ps3_repository_read_mm_info - Read mm info for single pu system.
740 * @rm_base: Real mode memory base address.
741 * @rm_size: Real mode memory size.
742 * @region_total: Maximum memory region size.
745 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
750 lv1_get_logical_ppe_id(&ppe_id);
752 result = ps3_repository_read_rm_size(ppe_id, rm_size);
753 return result ? result
754 : ps3_repository_read_region_total(region_total);
758 * ps3_repository_read_highmem_region_count - Read the number of highmem regions
760 * Bootloaders must arrange the repository nodes such that regions are indexed
761 * with a region_index from 0 to region_count-1.
764 int ps3_repository_read_highmem_region_count(unsigned int *region_count)
769 result = read_node(PS3_LPAR_ID_CURRENT,
770 make_first_field("highmem", 0),
771 make_field("region", 0),
772 make_field("count", 0),
780 int ps3_repository_read_highmem_base(unsigned int region_index,
783 return read_node(PS3_LPAR_ID_CURRENT,
784 make_first_field("highmem", 0),
785 make_field("region", region_index),
786 make_field("base", 0),
791 int ps3_repository_read_highmem_size(unsigned int region_index,
794 return read_node(PS3_LPAR_ID_CURRENT,
795 make_first_field("highmem", 0),
796 make_field("region", region_index),
797 make_field("size", 0),
803 * ps3_repository_read_highmem_info - Read high memory region info
804 * @region_index: Region index, {0,..,region_count-1}.
805 * @highmem_base: High memory base address.
806 * @highmem_size: High memory size.
808 * Bootloaders that preallocate highmem regions must place the
809 * region info into the repository at these well known nodes.
812 int ps3_repository_read_highmem_info(unsigned int region_index,
813 u64 *highmem_base, u64 *highmem_size)
818 result = ps3_repository_read_highmem_base(region_index, highmem_base);
819 return result ? result
820 : ps3_repository_read_highmem_size(region_index, highmem_size);
824 * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
825 * @num_spu: Number of physical spus.
828 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
833 result = read_node(PS3_LPAR_ID_CURRENT,
834 make_first_field("bi", 0),
835 make_field("spun", 0),
838 *num_spu_reserved = v1;
843 * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
844 * @num_resource_id: Number of spu resource ids.
847 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
852 result = read_node(PS3_LPAR_ID_CURRENT,
853 make_first_field("bi", 0),
854 make_field("spursvn", 0),
857 *num_resource_id = v1;
862 * ps3_repository_read_spu_resource_id - spu resource reservation id value.
863 * @res_index: Resource reservation index.
864 * @resource_type: Resource reservation type.
865 * @resource_id: Resource reservation id.
868 int ps3_repository_read_spu_resource_id(unsigned int res_index,
869 enum ps3_spu_resource_type *resource_type, unsigned int *resource_id)
875 result = read_node(PS3_LPAR_ID_CURRENT,
876 make_first_field("bi", 0),
877 make_field("spursv", 0),
886 static int ps3_repository_read_boot_dat_address(u64 *address)
888 return read_node(PS3_LPAR_ID_CURRENT,
889 make_first_field("bi", 0),
890 make_field("boot_dat", 0),
891 make_field("address", 0),
896 int ps3_repository_read_boot_dat_size(unsigned int *size)
901 result = read_node(PS3_LPAR_ID_CURRENT,
902 make_first_field("bi", 0),
903 make_field("boot_dat", 0),
904 make_field("size", 0),
911 int ps3_repository_read_vuart_av_port(unsigned int *port)
916 result = read_node(PS3_LPAR_ID_CURRENT,
917 make_first_field("bi", 0),
918 make_field("vir_uart", 0),
919 make_field("port", 0),
920 make_field("avset", 0),
926 int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
931 result = read_node(PS3_LPAR_ID_CURRENT,
932 make_first_field("bi", 0),
933 make_field("vir_uart", 0),
934 make_field("port", 0),
935 make_field("sysmgr", 0),
942 * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
943 * address: lpar address of cell_ext_os_area
944 * @size: size of cell_ext_os_area
947 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
952 result = ps3_repository_read_boot_dat_address(lpar_addr);
953 return result ? result
954 : ps3_repository_read_boot_dat_size(size);
958 * ps3_repository_read_num_be - Number of physical BE processors in the system.
961 int ps3_repository_read_num_be(unsigned int *num_be)
966 result = read_node(PS3_LPAR_ID_PME,
967 make_first_field("ben", 0),
977 * ps3_repository_read_be_node_id - Read the physical BE processor node id.
978 * @be_index: Zero based index.
979 * @node_id: The BE processor node id.
982 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
984 return read_node(PS3_LPAR_ID_PME,
985 make_first_field("be", be_index),
993 * ps3_repository_read_be_id - Read the physical BE processor id.
994 * @node_id: The BE processor node id.
995 * @be_id: The BE processor id.
998 int ps3_repository_read_be_id(u64 node_id, u64 *be_id)
1000 return read_node(PS3_LPAR_ID_PME,
1001 make_first_field("be", 0),
1008 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
1010 return read_node(PS3_LPAR_ID_PME,
1011 make_first_field("be", 0),
1013 make_field("clock", 0),
1018 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
1024 result = ps3_repository_read_be_node_id(be_index, &node_id);
1025 return result ? result
1026 : ps3_repository_read_tb_freq(node_id, tb_freq);
1029 int ps3_repository_read_lpm_privileges(unsigned int be_index, u64 *lpar,
1037 result = ps3_repository_read_be_node_id(be_index, &node_id);
1038 return result ? result
1039 : read_node(PS3_LPAR_ID_PME,
1040 make_first_field("be", 0),
1042 make_field("lpm", 0),
1043 make_field("priv", 0),
1047 #if defined(CONFIG_PS3_REPOSITORY_WRITE)
1049 static int create_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2)
1053 dump_node(0, n1, n2, n3, n4, v1, v2);
1055 result = lv1_create_repository_node(n1, n2, n3, n4, v1, v2);
1058 pr_devel("%s:%d: lv1_create_repository_node failed: %s\n",
1059 __func__, __LINE__, ps3_result(result));
1066 static int delete_node(u64 n1, u64 n2, u64 n3, u64 n4)
1070 dump_node(0, n1, n2, n3, n4, 0, 0);
1072 result = lv1_delete_repository_node(n1, n2, n3, n4);
1075 pr_devel("%s:%d: lv1_delete_repository_node failed: %s\n",
1076 __func__, __LINE__, ps3_result(result));
1083 static int write_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2)
1087 result = create_node(n1, n2, n3, n4, v1, v2);
1092 result = lv1_write_repository_node(n1, n2, n3, n4, v1, v2);
1095 pr_devel("%s:%d: lv1_write_repository_node failed: %s\n",
1096 __func__, __LINE__, ps3_result(result));
1103 int ps3_repository_write_highmem_region_count(unsigned int region_count)
1106 u64 v1 = (u64)region_count;
1108 result = write_node(
1109 make_first_field("highmem", 0),
1110 make_field("region", 0),
1111 make_field("count", 0),
1117 int ps3_repository_write_highmem_base(unsigned int region_index,
1121 make_first_field("highmem", 0),
1122 make_field("region", region_index),
1123 make_field("base", 0),
1128 int ps3_repository_write_highmem_size(unsigned int region_index,
1132 make_first_field("highmem", 0),
1133 make_field("region", region_index),
1134 make_field("size", 0),
1139 int ps3_repository_write_highmem_info(unsigned int region_index,
1140 u64 highmem_base, u64 highmem_size)
1144 result = ps3_repository_write_highmem_base(region_index, highmem_base);
1145 return result ? result
1146 : ps3_repository_write_highmem_size(region_index, highmem_size);
1149 static int ps3_repository_delete_highmem_base(unsigned int region_index)
1152 make_first_field("highmem", 0),
1153 make_field("region", region_index),
1154 make_field("base", 0),
1158 static int ps3_repository_delete_highmem_size(unsigned int region_index)
1161 make_first_field("highmem", 0),
1162 make_field("region", region_index),
1163 make_field("size", 0),
1167 int ps3_repository_delete_highmem_info(unsigned int region_index)
1171 result = ps3_repository_delete_highmem_base(region_index);
1172 result += ps3_repository_delete_highmem_size(region_index);
1174 return result ? -1 : 0;
1177 #endif /* defined(CONFIG_PS3_REPOSITORY_WRITE) */
1181 int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
1184 unsigned int res_index;
1186 pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
1187 repo->bus_index, repo->dev_index);
1189 for (res_index = 0; res_index < 10; res_index++) {
1190 enum ps3_interrupt_type intr_type;
1191 unsigned int interrupt_id;
1193 result = ps3_repository_read_dev_intr(repo->bus_index,
1194 repo->dev_index, res_index, &intr_type, &interrupt_id);
1197 if (result != LV1_NO_ENTRY)
1198 pr_devel("%s:%d ps3_repository_read_dev_intr"
1199 " (%u:%u) failed\n", __func__, __LINE__,
1200 repo->bus_index, repo->dev_index);
1204 pr_devel("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
1205 __func__, __LINE__, repo->bus_index, repo->dev_index,
1206 intr_type, interrupt_id);
1209 for (res_index = 0; res_index < 10; res_index++) {
1210 enum ps3_reg_type reg_type;
1214 result = ps3_repository_read_dev_reg(repo->bus_index,
1215 repo->dev_index, res_index, ®_type, &bus_addr, &len);
1218 if (result != LV1_NO_ENTRY)
1219 pr_devel("%s:%d ps3_repository_read_dev_reg"
1220 " (%u:%u) failed\n", __func__, __LINE__,
1221 repo->bus_index, repo->dev_index);
1225 pr_devel("%s:%d (%u:%u) reg_type %u, bus_addr %llxh, len %llxh\n",
1226 __func__, __LINE__, repo->bus_index, repo->dev_index,
1227 reg_type, bus_addr, len);
1230 pr_devel(" <- %s:%d\n", __func__, __LINE__);
1234 static int dump_stor_dev_info(struct ps3_repository_device *repo)
1237 unsigned int num_regions, region_index;
1238 u64 port, blk_size, num_blocks;
1240 pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
1241 repo->bus_index, repo->dev_index);
1243 result = ps3_repository_read_stor_dev_info(repo->bus_index,
1244 repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
1246 pr_devel("%s:%d ps3_repository_read_stor_dev_info"
1247 " (%u:%u) failed\n", __func__, __LINE__,
1248 repo->bus_index, repo->dev_index);
1252 pr_devel("%s:%d (%u:%u): port %llu, blk_size %llu, num_blocks "
1253 "%llu, num_regions %u\n",
1254 __func__, __LINE__, repo->bus_index, repo->dev_index,
1255 port, blk_size, num_blocks, num_regions);
1257 for (region_index = 0; region_index < num_regions; region_index++) {
1258 unsigned int region_id;
1259 u64 region_start, region_size;
1261 result = ps3_repository_read_stor_dev_region(repo->bus_index,
1262 repo->dev_index, region_index, ®ion_id,
1263 ®ion_start, ®ion_size);
1265 pr_devel("%s:%d ps3_repository_read_stor_dev_region"
1266 " (%u:%u) failed\n", __func__, __LINE__,
1267 repo->bus_index, repo->dev_index);
1271 pr_devel("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
1272 __func__, __LINE__, repo->bus_index, repo->dev_index,
1273 region_id, (unsigned long)region_start,
1274 (unsigned long)region_size);
1278 pr_devel(" <- %s:%d\n", __func__, __LINE__);
1282 static int dump_device_info(struct ps3_repository_device *repo,
1283 unsigned int num_dev)
1287 pr_devel(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
1289 for (repo->dev_index = 0; repo->dev_index < num_dev;
1290 repo->dev_index++) {
1292 result = ps3_repository_read_dev_type(repo->bus_index,
1293 repo->dev_index, &repo->dev_type);
1296 pr_devel("%s:%d ps3_repository_read_dev_type"
1297 " (%u:%u) failed\n", __func__, __LINE__,
1298 repo->bus_index, repo->dev_index);
1302 result = ps3_repository_read_dev_id(repo->bus_index,
1303 repo->dev_index, &repo->dev_id);
1306 pr_devel("%s:%d ps3_repository_read_dev_id"
1307 " (%u:%u) failed\n", __func__, __LINE__,
1308 repo->bus_index, repo->dev_index);
1312 pr_devel("%s:%d (%u:%u): dev_type %u, dev_id %lu\n", __func__,
1313 __LINE__, repo->bus_index, repo->dev_index,
1314 repo->dev_type, (unsigned long)repo->dev_id);
1316 ps3_repository_dump_resource_info(repo);
1318 if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
1319 dump_stor_dev_info(repo);
1322 pr_devel(" <- %s:%d\n", __func__, __LINE__);
1326 int ps3_repository_dump_bus_info(void)
1329 struct ps3_repository_device repo;
1331 pr_devel(" -> %s:%d\n", __func__, __LINE__);
1333 memset(&repo, 0, sizeof(repo));
1335 for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
1336 unsigned int num_dev;
1338 result = ps3_repository_read_bus_type(repo.bus_index,
1342 pr_devel("%s:%d read_bus_type(%u) failed\n",
1343 __func__, __LINE__, repo.bus_index);
1347 result = ps3_repository_read_bus_id(repo.bus_index,
1351 pr_devel("%s:%d read_bus_id(%u) failed\n",
1352 __func__, __LINE__, repo.bus_index);
1356 if (repo.bus_index != repo.bus_id)
1357 pr_devel("%s:%d bus_index != bus_id\n",
1358 __func__, __LINE__);
1360 result = ps3_repository_read_bus_num_dev(repo.bus_index,
1364 pr_devel("%s:%d read_bus_num_dev(%u) failed\n",
1365 __func__, __LINE__, repo.bus_index);
1369 pr_devel("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n",
1370 __func__, __LINE__, repo.bus_index, repo.bus_type,
1371 (unsigned long)repo.bus_id, num_dev);
1373 dump_device_info(&repo, num_dev);
1376 pr_devel(" <- %s:%d\n", __func__, __LINE__);
1380 #endif /* defined(DEBUG) */