setup.c 6.7 KB

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