setup.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 udbg_printf
  37. #else
  38. #define DBG pr_debug
  39. #endif
  40. #if !defined(CONFIG_SMP)
  41. static void smp_send_stop(void) {}
  42. #endif
  43. static union ps3_firmware_version ps3_firmware_version;
  44. void ps3_get_firmware_version(union ps3_firmware_version *v)
  45. {
  46. *v = ps3_firmware_version;
  47. }
  48. EXPORT_SYMBOL_GPL(ps3_get_firmware_version);
  49. int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev)
  50. {
  51. union ps3_firmware_version x;
  52. x.pad = 0;
  53. x.major = major;
  54. x.minor = minor;
  55. x.rev = rev;
  56. return (ps3_firmware_version.raw - x.raw);
  57. }
  58. EXPORT_SYMBOL_GPL(ps3_compare_firmware_version);
  59. static void ps3_power_save(void)
  60. {
  61. /*
  62. * lv1_pause() puts the PPE thread into inactive state until an
  63. * irq on an unmasked plug exists. MSR[EE] has no effect.
  64. * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
  65. */
  66. lv1_pause(0);
  67. }
  68. static void ps3_restart(char *cmd)
  69. {
  70. DBG("%s:%d cmd '%s'\n", __func__, __LINE__, cmd);
  71. smp_send_stop();
  72. ps3_sys_manager_restart(); /* never returns */
  73. }
  74. static void ps3_power_off(void)
  75. {
  76. DBG("%s:%d\n", __func__, __LINE__);
  77. smp_send_stop();
  78. ps3_sys_manager_power_off(); /* never returns */
  79. }
  80. static void ps3_panic(char *str)
  81. {
  82. DBG("%s:%d %s\n", __func__, __LINE__, str);
  83. smp_send_stop();
  84. printk("\n");
  85. printk(" System does not reboot automatically.\n");
  86. printk(" Please press POWER button.\n");
  87. printk("\n");
  88. while(1);
  89. }
  90. #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
  91. defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
  92. static void __init prealloc(struct ps3_prealloc *p)
  93. {
  94. if (!p->size)
  95. return;
  96. p->address = __alloc_bootmem(p->size, p->align, __pa(MAX_DMA_ADDRESS));
  97. if (!p->address) {
  98. printk(KERN_ERR "%s: Cannot allocate %s\n", __FUNCTION__,
  99. p->name);
  100. return;
  101. }
  102. printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size,
  103. p->address);
  104. }
  105. #endif
  106. #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
  107. struct ps3_prealloc ps3fb_videomemory = {
  108. .name = "ps3fb videomemory",
  109. .size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024,
  110. .align = 1024*1024 /* the GPU requires 1 MiB alignment */
  111. };
  112. EXPORT_SYMBOL_GPL(ps3fb_videomemory);
  113. #define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
  114. static int __init early_parse_ps3fb(char *p)
  115. {
  116. if (!p)
  117. return 1;
  118. ps3fb_videomemory.size = _ALIGN_UP(memparse(p, &p),
  119. ps3fb_videomemory.align);
  120. return 0;
  121. }
  122. early_param("ps3fb", early_parse_ps3fb);
  123. #else
  124. #define prealloc_ps3fb_videomemory() do { } while (0)
  125. #endif
  126. #if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
  127. struct ps3_prealloc ps3flash_bounce_buffer = {
  128. .name = "ps3flash bounce buffer",
  129. .size = 256*1024,
  130. .align = 256*1024
  131. };
  132. EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer);
  133. #define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer)
  134. static int __init early_parse_ps3flash(char *p)
  135. {
  136. if (!p)
  137. return 1;
  138. if (!strcmp(p, "off"))
  139. ps3flash_bounce_buffer.size = 0;
  140. return 0;
  141. }
  142. early_param("ps3flash", early_parse_ps3flash);
  143. #else
  144. #define prealloc_ps3flash_bounce_buffer() do { } while (0)
  145. #endif
  146. static int ps3_set_dabr(u64 dabr)
  147. {
  148. enum {DABR_USER = 1, DABR_KERNEL = 2,};
  149. return lv1_set_dabr(dabr, DABR_KERNEL | DABR_USER) ? -1 : 0;
  150. }
  151. static void __init ps3_setup_arch(void)
  152. {
  153. DBG(" -> %s:%d\n", __func__, __LINE__);
  154. lv1_get_version_info(&ps3_firmware_version.raw);
  155. printk(KERN_INFO "PS3 firmware version %u.%u.%u\n",
  156. ps3_firmware_version.major, ps3_firmware_version.minor,
  157. ps3_firmware_version.rev);
  158. ps3_spu_set_platform();
  159. ps3_map_htab();
  160. #ifdef CONFIG_SMP
  161. smp_init_ps3();
  162. #endif
  163. #ifdef CONFIG_DUMMY_CONSOLE
  164. conswitchp = &dummy_con;
  165. #endif
  166. prealloc_ps3fb_videomemory();
  167. prealloc_ps3flash_bounce_buffer();
  168. ppc_md.power_save = ps3_power_save;
  169. DBG(" <- %s:%d\n", __func__, __LINE__);
  170. }
  171. static void __init ps3_progress(char *s, unsigned short hex)
  172. {
  173. printk("*** %04x : %s\n", hex, s ? s : "");
  174. }
  175. static int __init ps3_probe(void)
  176. {
  177. unsigned long htab_size;
  178. unsigned long dt_root;
  179. DBG(" -> %s:%d\n", __func__, __LINE__);
  180. dt_root = of_get_flat_dt_root();
  181. if (!of_flat_dt_is_compatible(dt_root, "sony,ps3"))
  182. return 0;
  183. powerpc_firmware_features |= FW_FEATURE_PS3_POSSIBLE;
  184. ps3_os_area_init();
  185. ps3_mm_init();
  186. ps3_mm_vas_create(&htab_size);
  187. ps3_hpte_init(htab_size);
  188. DBG(" <- %s:%d\n", __func__, __LINE__);
  189. return 1;
  190. }
  191. #if defined(CONFIG_KEXEC)
  192. static void ps3_kexec_cpu_down(int crash_shutdown, int secondary)
  193. {
  194. int cpu = smp_processor_id();
  195. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  196. ps3_smp_cleanup_cpu(cpu);
  197. ps3_shutdown_IRQ(cpu);
  198. DBG(" <- %s:%d\n", __func__, __LINE__);
  199. }
  200. #endif
  201. define_machine(ps3) {
  202. .name = "PS3",
  203. .probe = ps3_probe,
  204. .setup_arch = ps3_setup_arch,
  205. .init_IRQ = ps3_init_IRQ,
  206. .panic = ps3_panic,
  207. .get_boot_time = ps3_get_boot_time,
  208. .set_rtc_time = ps3_set_rtc_time,
  209. .get_rtc_time = ps3_get_rtc_time,
  210. .set_dabr = ps3_set_dabr,
  211. .calibrate_decr = ps3_calibrate_decr,
  212. .progress = ps3_progress,
  213. .restart = ps3_restart,
  214. .power_off = ps3_power_off,
  215. #if defined(CONFIG_KEXEC)
  216. .kexec_cpu_down = ps3_kexec_cpu_down,
  217. .machine_kexec = default_machine_kexec,
  218. .machine_kexec_prepare = default_machine_kexec_prepare,
  219. .machine_crash_shutdown = default_machine_crash_shutdown,
  220. #endif
  221. };