setup.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * linux/arch/powerpc/platforms/cell/cell_setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Adapted from 'alpha' version by Gary Thomas
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. * Modified by PPC64 Team, IBM Corp
  8. * Modified by Cell Team, IBM Deutschland Entwicklung GmbH
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #undef DEBUG
  16. #include <linux/config.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/slab.h>
  23. #include <linux/user.h>
  24. #include <linux/reboot.h>
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/irq.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/root_dev.h>
  30. #include <linux/console.h>
  31. #include <asm/mmu.h>
  32. #include <asm/processor.h>
  33. #include <asm/io.h>
  34. #include <asm/kexec.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/prom.h>
  37. #include <asm/rtas.h>
  38. #include <asm/pci-bridge.h>
  39. #include <asm/iommu.h>
  40. #include <asm/dma.h>
  41. #include <asm/machdep.h>
  42. #include <asm/time.h>
  43. #include <asm/nvram.h>
  44. #include <asm/cputable.h>
  45. #include <asm/ppc-pci.h>
  46. #include <asm/irq.h>
  47. #include "interrupt.h"
  48. #include "iommu.h"
  49. #include "pervasive.h"
  50. #ifdef DEBUG
  51. #define DBG(fmt...) udbg_printf(fmt)
  52. #else
  53. #define DBG(fmt...)
  54. #endif
  55. static void cell_show_cpuinfo(struct seq_file *m)
  56. {
  57. struct device_node *root;
  58. const char *model = "";
  59. root = of_find_node_by_path("/");
  60. if (root)
  61. model = get_property(root, "model", NULL);
  62. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  63. of_node_put(root);
  64. }
  65. #ifdef CONFIG_SPARSEMEM
  66. static int __init find_spu_node_id(struct device_node *spe)
  67. {
  68. unsigned int *id;
  69. #ifdef CONFIG_NUMA
  70. struct device_node *cpu;
  71. cpu = spe->parent->parent;
  72. id = (unsigned int *)get_property(cpu, "node-id", NULL);
  73. #else
  74. id = NULL;
  75. #endif
  76. return id ? *id : 0;
  77. }
  78. static void __init cell_spuprop_present(struct device_node *spe,
  79. const char *prop, int early)
  80. {
  81. struct address_prop {
  82. unsigned long address;
  83. unsigned int len;
  84. } __attribute__((packed)) *p;
  85. int proplen;
  86. unsigned long start_pfn, end_pfn, pfn;
  87. int node_id;
  88. p = (void*)get_property(spe, prop, &proplen);
  89. WARN_ON(proplen != sizeof (*p));
  90. node_id = find_spu_node_id(spe);
  91. start_pfn = p->address >> PAGE_SHIFT;
  92. end_pfn = (p->address + p->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  93. /* We need to call memory_present *before* the call to sparse_init,
  94. but we can initialize the page structs only *after* that call.
  95. Thus, we're being called twice. */
  96. if (early)
  97. memory_present(node_id, start_pfn, end_pfn);
  98. else {
  99. /* As the pages backing SPU LS and I/O are outside the range
  100. of regular memory, their page structs were not initialized
  101. by free_area_init. Do it here instead. */
  102. for (pfn = start_pfn; pfn < end_pfn; pfn++) {
  103. struct page *page = pfn_to_page(pfn);
  104. set_page_links(page, ZONE_DMA, node_id, pfn);
  105. init_page_count(page);
  106. reset_page_mapcount(page);
  107. SetPageReserved(page);
  108. INIT_LIST_HEAD(&page->lru);
  109. }
  110. }
  111. }
  112. static void __init cell_spumem_init(int early)
  113. {
  114. struct device_node *node;
  115. for (node = of_find_node_by_type(NULL, "spe");
  116. node; node = of_find_node_by_type(node, "spe")) {
  117. cell_spuprop_present(node, "local-store", early);
  118. cell_spuprop_present(node, "problem", early);
  119. cell_spuprop_present(node, "priv1", early);
  120. cell_spuprop_present(node, "priv2", early);
  121. }
  122. }
  123. #else
  124. static void __init cell_spumem_init(int early)
  125. {
  126. }
  127. #endif
  128. static void cell_progress(char *s, unsigned short hex)
  129. {
  130. printk("*** %04x : %s\n", hex, s ? s : "");
  131. }
  132. static void __init cell_setup_arch(void)
  133. {
  134. ppc_md.init_IRQ = iic_init_IRQ;
  135. ppc_md.get_irq = iic_get_irq;
  136. #ifdef CONFIG_SMP
  137. smp_init_cell();
  138. #endif
  139. /* init to some ~sane value until calibrate_delay() runs */
  140. loops_per_jiffy = 50000000;
  141. if (ROOT_DEV == 0) {
  142. printk("No ramdisk, default root is /dev/hda2\n");
  143. ROOT_DEV = Root_HDA2;
  144. }
  145. /* Find and initialize PCI host bridges */
  146. init_pci_config_tokens();
  147. find_and_init_phbs();
  148. spider_init_IRQ();
  149. cell_pervasive_init();
  150. #ifdef CONFIG_DUMMY_CONSOLE
  151. conswitchp = &dummy_con;
  152. #endif
  153. mmio_nvram_init();
  154. cell_spumem_init(0);
  155. }
  156. /*
  157. * Early initialization. Relocation is on but do not reference unbolted pages
  158. */
  159. static void __init cell_init_early(void)
  160. {
  161. DBG(" -> cell_init_early()\n");
  162. hpte_init_native();
  163. cell_init_iommu();
  164. ppc64_interrupt_controller = IC_CELL_PIC;
  165. cell_spumem_init(1);
  166. DBG(" <- cell_init_early()\n");
  167. }
  168. static int __init cell_probe(void)
  169. {
  170. /* XXX This is temporary, the Cell maintainer will come up with
  171. * more appropriate detection logic
  172. */
  173. unsigned long root = of_get_flat_dt_root();
  174. if (!of_flat_dt_is_compatible(root, "IBM,CPBW-1.0"))
  175. return 0;
  176. return 1;
  177. }
  178. /*
  179. * Cell has no legacy IO; anything calling this function has to
  180. * fail or bad things will happen
  181. */
  182. static int cell_check_legacy_ioport(unsigned int baseport)
  183. {
  184. return -ENODEV;
  185. }
  186. define_machine(cell) {
  187. .name = "Cell",
  188. .probe = cell_probe,
  189. .setup_arch = cell_setup_arch,
  190. .init_early = cell_init_early,
  191. .show_cpuinfo = cell_show_cpuinfo,
  192. .restart = rtas_restart,
  193. .power_off = rtas_power_off,
  194. .halt = rtas_halt,
  195. .get_boot_time = rtas_get_boot_time,
  196. .get_rtc_time = rtas_get_rtc_time,
  197. .set_rtc_time = rtas_set_rtc_time,
  198. .calibrate_decr = generic_calibrate_decr,
  199. .check_legacy_ioport = cell_check_legacy_ioport,
  200. .progress = cell_progress,
  201. #ifdef CONFIG_KEXEC
  202. .machine_kexec = default_machine_kexec,
  203. .machine_kexec_prepare = default_machine_kexec_prepare,
  204. .machine_crash_shutdown = default_machine_crash_shutdown,
  205. #endif
  206. };