PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/powerpc/platforms/ps3/setup.c

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