wii.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * arch/powerpc/boot/wii.c
  3. *
  4. * Nintendo Wii bootwrapper support
  5. * Copyright (C) 2008-2009 The GameCube Linux Team
  6. * Copyright (C) 2008,2009 Albert Herranz
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. */
  14. #include <stddef.h>
  15. #include "stdio.h"
  16. #include "types.h"
  17. #include "io.h"
  18. #include "ops.h"
  19. #include "ugecon.h"
  20. BSS_STACK(8192);
  21. #define HW_REG(x) ((void *)(x))
  22. #define EXI_CTRL HW_REG(0x0d800070)
  23. #define EXI_CTRL_ENABLE (1<<0)
  24. #define MEM2_TOP (0x10000000 + 64*1024*1024)
  25. #define FIRMWARE_DEFAULT_SIZE (12*1024*1024)
  26. struct mipc_infohdr {
  27. char magic[3];
  28. u8 version;
  29. u32 mem2_boundary;
  30. u32 ipc_in;
  31. size_t ipc_in_size;
  32. u32 ipc_out;
  33. size_t ipc_out_size;
  34. };
  35. static int mipc_check_address(u32 pa)
  36. {
  37. /* only MEM2 addresses */
  38. if (pa < 0x10000000 || pa > 0x14000000)
  39. return -EINVAL;
  40. return 0;
  41. }
  42. static struct mipc_infohdr *mipc_get_infohdr(void)
  43. {
  44. struct mipc_infohdr **hdrp, *hdr;
  45. /* 'mini' header pointer is the last word of MEM2 memory */
  46. hdrp = (struct mipc_infohdr **)0x13fffffc;
  47. if (mipc_check_address((u32)hdrp)) {
  48. printf("mini: invalid hdrp %08X\n", (u32)hdrp);
  49. hdr = NULL;
  50. goto out;
  51. }
  52. hdr = *hdrp;
  53. if (mipc_check_address((u32)hdr)) {
  54. printf("mini: invalid hdr %08X\n", (u32)hdr);
  55. hdr = NULL;
  56. goto out;
  57. }
  58. if (memcmp(hdr->magic, "IPC", 3)) {
  59. printf("mini: invalid magic\n");
  60. hdr = NULL;
  61. goto out;
  62. }
  63. out:
  64. return hdr;
  65. }
  66. static int mipc_get_mem2_boundary(u32 *mem2_boundary)
  67. {
  68. struct mipc_infohdr *hdr;
  69. int error;
  70. hdr = mipc_get_infohdr();
  71. if (!hdr) {
  72. error = -1;
  73. goto out;
  74. }
  75. if (mipc_check_address(hdr->mem2_boundary)) {
  76. printf("mini: invalid mem2_boundary %08X\n",
  77. hdr->mem2_boundary);
  78. error = -EINVAL;
  79. goto out;
  80. }
  81. *mem2_boundary = hdr->mem2_boundary;
  82. error = 0;
  83. out:
  84. return error;
  85. }
  86. static void platform_fixups(void)
  87. {
  88. void *mem;
  89. u32 reg[4];
  90. u32 mem2_boundary;
  91. int len;
  92. int error;
  93. mem = finddevice("/memory");
  94. if (!mem)
  95. fatal("Can't find memory node\n");
  96. /* two ranges of (address, size) words */
  97. len = getprop(mem, "reg", reg, sizeof(reg));
  98. if (len != sizeof(reg)) {
  99. /* nothing to do */
  100. goto out;
  101. }
  102. /* retrieve MEM2 boundary from 'mini' */
  103. error = mipc_get_mem2_boundary(&mem2_boundary);
  104. if (error) {
  105. /* if that fails use a sane value */
  106. mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
  107. }
  108. if (mem2_boundary > reg[2] && mem2_boundary < reg[2] + reg[3]) {
  109. reg[3] = mem2_boundary - reg[2];
  110. printf("top of MEM2 @ %08X\n", reg[2] + reg[3]);
  111. setprop(mem, "reg", reg, sizeof(reg));
  112. }
  113. out:
  114. return;
  115. }
  116. void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
  117. {
  118. u32 heapsize = 24*1024*1024 - (u32)_end;
  119. simple_alloc_init(_end, heapsize, 32, 64);
  120. fdt_init(_dtb_start);
  121. /*
  122. * 'mini' boots the Broadway processor with EXI disabled.
  123. * We need it enabled before probing for the USB Gecko.
  124. */
  125. out_be32(EXI_CTRL, in_be32(EXI_CTRL) | EXI_CTRL_ENABLE);
  126. if (ug_probe())
  127. console_ops.write = ug_console_write;
  128. platform_ops.fixups = platform_fixups;
  129. }