setup.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * PS3 platform setup routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 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 <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/fs.h>
  23. #include <linux/root_dev.h>
  24. #include <linux/console.h>
  25. #include <linux/kexec.h>
  26. #include <linux/bootmem.h>
  27. #include <asm/machdep.h>
  28. #include <asm/firmware.h>
  29. #include <asm/time.h>
  30. #include <asm/iommu.h>
  31. #include <asm/udbg.h>
  32. #include <asm/prom.h>
  33. #include <asm/lv1call.h>
  34. #include "platform.h"
  35. #if defined(DEBUG)
  36. #define DBG(fmt...) udbg_printf(fmt)
  37. #else
  38. #define DBG(fmt...) do{if(0)printk(fmt);}while(0)
  39. #endif
  40. int ps3_get_firmware_version(union ps3_firmware_version *v)
  41. {
  42. int result = lv1_get_version_info(&v->raw);
  43. if (result) {
  44. v->raw = 0;
  45. return -1;
  46. }
  47. return result;
  48. }
  49. EXPORT_SYMBOL_GPL(ps3_get_firmware_version);
  50. static void ps3_power_save(void)
  51. {
  52. /*
  53. * lv1_pause() puts the PPE thread into inactive state until an
  54. * irq on an unmasked plug exists. MSR[EE] has no effect.
  55. * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
  56. */
  57. lv1_pause(0);
  58. }
  59. static void ps3_panic(char *str)
  60. {
  61. DBG("%s:%d %s\n", __func__, __LINE__, str);
  62. #ifdef CONFIG_SMP
  63. smp_send_stop();
  64. #endif
  65. printk("\n");
  66. printk(" System does not reboot automatically.\n");
  67. printk(" Please press POWER button.\n");
  68. printk("\n");
  69. for (;;) ;
  70. }
  71. static void prealloc(struct ps3_prealloc *p)
  72. {
  73. if (!p->size)
  74. return;
  75. p->address = __alloc_bootmem(p->size, p->align, __pa(MAX_DMA_ADDRESS));
  76. if (!p->address) {
  77. printk(KERN_ERR "%s: Cannot allocate %s\n", __FUNCTION__,
  78. p->name);
  79. return;
  80. }
  81. printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size,
  82. p->address);
  83. }
  84. #ifdef CONFIG_FB_PS3
  85. struct ps3_prealloc ps3fb_videomemory = {
  86. .name = "ps3fb videomemory",
  87. .size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024,
  88. .align = 1024*1024 /* the GPU requires 1 MiB alignment */
  89. };
  90. #define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
  91. static int __init early_parse_ps3fb(char *p)
  92. {
  93. if (!p)
  94. return 1;
  95. ps3fb_videomemory.size = _ALIGN_UP(memparse(p, &p),
  96. ps3fb_videomemory.align);
  97. return 0;
  98. }
  99. early_param("ps3fb", early_parse_ps3fb);
  100. #else
  101. #define prealloc_ps3fb_videomemory() do { } while (0)
  102. #endif
  103. static void __init ps3_setup_arch(void)
  104. {
  105. union ps3_firmware_version v;
  106. DBG(" -> %s:%d\n", __func__, __LINE__);
  107. ps3_get_firmware_version(&v);
  108. printk(KERN_INFO "PS3 firmware version %u.%u.%u\n", v.major, v.minor,
  109. v.rev);
  110. ps3_spu_set_platform();
  111. ps3_map_htab();
  112. #ifdef CONFIG_SMP
  113. smp_init_ps3();
  114. #endif
  115. #ifdef CONFIG_DUMMY_CONSOLE
  116. conswitchp = &dummy_con;
  117. #endif
  118. prealloc_ps3fb_videomemory();
  119. ppc_md.power_save = ps3_power_save;
  120. DBG(" <- %s:%d\n", __func__, __LINE__);
  121. }
  122. static void __init ps3_progress(char *s, unsigned short hex)
  123. {
  124. printk("*** %04x : %s\n", hex, s ? s : "");
  125. }
  126. static int __init ps3_probe(void)
  127. {
  128. unsigned long htab_size;
  129. unsigned long dt_root;
  130. DBG(" -> %s:%d\n", __func__, __LINE__);
  131. dt_root = of_get_flat_dt_root();
  132. if (!of_flat_dt_is_compatible(dt_root, "PS3"))
  133. return 0;
  134. powerpc_firmware_features |= FW_FEATURE_PS3_POSSIBLE;
  135. ps3_os_area_init();
  136. ps3_mm_init();
  137. ps3_mm_vas_create(&htab_size);
  138. ps3_hpte_init(htab_size);
  139. DBG(" <- %s:%d\n", __func__, __LINE__);
  140. return 1;
  141. }
  142. #if defined(CONFIG_KEXEC)
  143. static void ps3_kexec_cpu_down(int crash_shutdown, int secondary)
  144. {
  145. DBG(" -> %s:%d\n", __func__, __LINE__);
  146. if (secondary) {
  147. int cpu;
  148. for_each_online_cpu(cpu)
  149. if (cpu)
  150. ps3_smp_cleanup_cpu(cpu);
  151. } else
  152. ps3_smp_cleanup_cpu(0);
  153. DBG(" <- %s:%d\n", __func__, __LINE__);
  154. }
  155. static void ps3_machine_kexec(struct kimage *image)
  156. {
  157. unsigned long ppe_id;
  158. DBG(" -> %s:%d\n", __func__, __LINE__);
  159. lv1_get_logical_ppe_id(&ppe_id);
  160. lv1_configure_irq_state_bitmap(ppe_id, 0, 0);
  161. ps3_mm_shutdown();
  162. ps3_mm_vas_destroy();
  163. default_machine_kexec(image);
  164. DBG(" <- %s:%d\n", __func__, __LINE__);
  165. }
  166. #endif
  167. define_machine(ps3) {
  168. .name = "PS3",
  169. .probe = ps3_probe,
  170. .setup_arch = ps3_setup_arch,
  171. .init_IRQ = ps3_init_IRQ,
  172. .panic = ps3_panic,
  173. .get_boot_time = ps3_get_boot_time,
  174. .set_rtc_time = ps3_set_rtc_time,
  175. .get_rtc_time = ps3_get_rtc_time,
  176. .calibrate_decr = ps3_calibrate_decr,
  177. .progress = ps3_progress,
  178. #if defined(CONFIG_KEXEC)
  179. .kexec_cpu_down = ps3_kexec_cpu_down,
  180. .machine_kexec = ps3_machine_kexec,
  181. .machine_kexec_prepare = default_machine_kexec_prepare,
  182. .machine_crash_shutdown = default_machine_crash_shutdown,
  183. #endif
  184. };