ps3.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * PS3 bootwrapper support.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2007 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. #include <stdarg.h>
  21. #include <stddef.h>
  22. #include "types.h"
  23. #include "elf.h"
  24. #include "string.h"
  25. #include "stdio.h"
  26. #include "page.h"
  27. #include "ops.h"
  28. extern int lv1_panic(u64 in_1);
  29. extern int lv1_get_logical_partition_id(u64 *out_1);
  30. extern int lv1_get_logical_ppe_id(u64 *out_1);
  31. extern int lv1_get_repository_node_value(u64 in_1, u64 in_2, u64 in_3,
  32. u64 in_4, u64 in_5, u64 *out_1, u64 *out_2);
  33. #ifdef DEBUG
  34. #define DBG(fmt...) printf(fmt)
  35. #else
  36. static inline int __attribute__ ((format (printf, 1, 2))) DBG(
  37. const char *fmt, ...) {return 0;}
  38. #endif
  39. BSS_STACK(4096);
  40. /* A buffer that may be edited by tools operating on a zImage binary so as to
  41. * edit the command line passed to vmlinux (by setting /chosen/bootargs).
  42. * The buffer is put in it's own section so that tools may locate it easier.
  43. */
  44. static char cmdline[BOOT_COMMAND_LINE_SIZE]
  45. __attribute__((__section__("__builtin_cmdline")));
  46. static void prep_cmdline(void *chosen)
  47. {
  48. if (cmdline[0] == '\0')
  49. getprop(chosen, "bootargs", cmdline, BOOT_COMMAND_LINE_SIZE-1);
  50. else
  51. setprop_str(chosen, "bootargs", cmdline);
  52. printf("cmdline: '%s'\n", cmdline);
  53. }
  54. static void ps3_console_write(const char *buf, int len)
  55. {
  56. }
  57. static void ps3_exit(void)
  58. {
  59. printf("ps3_exit\n");
  60. /* lv1_panic will shutdown the lpar. */
  61. lv1_panic(0); /* zero = do not reboot */
  62. while (1);
  63. }
  64. static int ps3_repository_read_rm_size(u64 *rm_size)
  65. {
  66. int result;
  67. u64 lpar_id;
  68. u64 ppe_id;
  69. u64 v2;
  70. result = lv1_get_logical_partition_id(&lpar_id);
  71. if (result)
  72. return -1;
  73. result = lv1_get_logical_ppe_id(&ppe_id);
  74. if (result)
  75. return -1;
  76. /*
  77. * n1: 0000000062690000 : ....bi..
  78. * n2: 7075000000000000 : pu......
  79. * n3: 0000000000000001 : ........
  80. * n4: 726d5f73697a6500 : rm_size.
  81. */
  82. result = lv1_get_repository_node_value(lpar_id, 0x0000000062690000ULL,
  83. 0x7075000000000000ULL, ppe_id, 0x726d5f73697a6500ULL, rm_size,
  84. &v2);
  85. printf("%s:%d: ppe_id %lu \n", __func__, __LINE__,
  86. (unsigned long)ppe_id);
  87. printf("%s:%d: lpar_id %lu \n", __func__, __LINE__,
  88. (unsigned long)lpar_id);
  89. printf("%s:%d: rm_size %llxh \n", __func__, __LINE__, *rm_size);
  90. return result ? -1 : 0;
  91. }
  92. void ps3_copy_vectors(void)
  93. {
  94. extern char __system_reset_kernel[];
  95. memcpy((void *)0x100, __system_reset_kernel, 512);
  96. flush_cache((void *)0x100, 512);
  97. }
  98. void platform_init(void)
  99. {
  100. const u32 heapsize = 0x1000000 - (u32)_end; /* 16MiB */
  101. void *chosen;
  102. unsigned long ft_addr;
  103. u64 rm_size;
  104. console_ops.write = ps3_console_write;
  105. platform_ops.exit = ps3_exit;
  106. printf("\n-- PS3 bootwrapper --\n");
  107. simple_alloc_init(_end, heapsize, 32, 64);
  108. fdt_init(_dtb_start);
  109. chosen = finddevice("/chosen");
  110. ps3_repository_read_rm_size(&rm_size);
  111. dt_fixup_memory(0, rm_size);
  112. if (_initrd_end > _initrd_start) {
  113. setprop_val(chosen, "linux,initrd-start", (u32)(_initrd_start));
  114. setprop_val(chosen, "linux,initrd-end", (u32)(_initrd_end));
  115. }
  116. prep_cmdline(chosen);
  117. ft_addr = dt_ops.finalize();
  118. ps3_copy_vectors();
  119. printf(" flat tree at 0x%lx\n\r", ft_addr);
  120. ((kernel_entry_t)0)(ft_addr, 0, NULL);
  121. ps3_exit();
  122. }