setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /*
  2. * Initial setup-routines for HP 9000 based hardware.
  3. *
  4. * Copyright (C) 1991, 1992, 1995 Linus Torvalds
  5. * Modifications for PA-RISC (C) 1999 Helge Deller <deller@gmx.de>
  6. * Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)
  7. * Modifications copyright 2000 Martin K. Petersen <mkp@mkp.net>
  8. * Modifications copyright 2000 Philipp Rumpf <prumpf@tux.org>
  9. * Modifications copyright 2001 Ryan Bradetich <rbradetich@uswest.net>
  10. *
  11. * Initial PA-RISC Version: 04-23-1999 by Helge Deller
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/initrd.h>
  30. #include <linux/init.h>
  31. #include <linux/console.h>
  32. #include <linux/seq_file.h>
  33. #define PCI_DEBUG
  34. #include <linux/pci.h>
  35. #undef PCI_DEBUG
  36. #include <linux/proc_fs.h>
  37. #include <linux/export.h>
  38. #include <linux/sched.h>
  39. #include <linux/sched/clock.h>
  40. #include <linux/start_kernel.h>
  41. #include <asm/processor.h>
  42. #include <asm/sections.h>
  43. #include <asm/pdc.h>
  44. #include <asm/led.h>
  45. #include <asm/machdep.h> /* for pa7300lc_init() proto */
  46. #include <asm/pdc_chassis.h>
  47. #include <asm/io.h>
  48. #include <asm/setup.h>
  49. #include <asm/unwind.h>
  50. #include <asm/smp.h>
  51. static char __initdata command_line[COMMAND_LINE_SIZE];
  52. /* Intended for ccio/sba/cpu statistics under /proc/bus/{runway|gsc} */
  53. struct proc_dir_entry * proc_runway_root __read_mostly = NULL;
  54. struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
  55. struct proc_dir_entry * proc_mckinley_root __read_mostly = NULL;
  56. void __init setup_cmdline(char **cmdline_p)
  57. {
  58. extern unsigned int boot_args[];
  59. /* Collect stuff passed in from the boot loader */
  60. /* boot_args[0] is free-mem start, boot_args[1] is ptr to command line */
  61. if (boot_args[0] < 64) {
  62. /* called from hpux boot loader */
  63. boot_command_line[0] = '\0';
  64. } else {
  65. strlcpy(boot_command_line, (char *)__va(boot_args[1]),
  66. COMMAND_LINE_SIZE);
  67. #ifdef CONFIG_BLK_DEV_INITRD
  68. if (boot_args[2] != 0) /* did palo pass us a ramdisk? */
  69. {
  70. initrd_start = (unsigned long)__va(boot_args[2]);
  71. initrd_end = (unsigned long)__va(boot_args[3]);
  72. }
  73. #endif
  74. }
  75. strcpy(command_line, boot_command_line);
  76. *cmdline_p = command_line;
  77. }
  78. #ifdef CONFIG_PA11
  79. void __init dma_ops_init(void)
  80. {
  81. switch (boot_cpu_data.cpu_type) {
  82. case pcx:
  83. /*
  84. * We've got way too many dependencies on 1.1 semantics
  85. * to support 1.0 boxes at this point.
  86. */
  87. panic( "PA-RISC Linux currently only supports machines that conform to\n"
  88. "the PA-RISC 1.1 or 2.0 architecture specification.\n");
  89. case pcxl2:
  90. pa7300lc_init();
  91. case pcxl: /* falls through */
  92. case pcxs:
  93. case pcxt:
  94. hppa_dma_ops = &dma_direct_ops;
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. #endif
  101. extern void collect_boot_cpu_data(void);
  102. void __init setup_arch(char **cmdline_p)
  103. {
  104. #ifdef CONFIG_64BIT
  105. extern int parisc_narrow_firmware;
  106. #endif
  107. unwind_init();
  108. init_per_cpu(smp_processor_id()); /* Set Modes & Enable FP */
  109. #ifdef CONFIG_64BIT
  110. printk(KERN_INFO "The 64-bit Kernel has started...\n");
  111. #else
  112. printk(KERN_INFO "The 32-bit Kernel has started...\n");
  113. #endif
  114. printk(KERN_INFO "Kernel default page size is %d KB. Huge pages ",
  115. (int)(PAGE_SIZE / 1024));
  116. #ifdef CONFIG_HUGETLB_PAGE
  117. printk(KERN_CONT "enabled with %d MB physical and %d MB virtual size",
  118. 1 << (REAL_HPAGE_SHIFT - 20), 1 << (HPAGE_SHIFT - 20));
  119. #else
  120. printk(KERN_CONT "disabled");
  121. #endif
  122. printk(KERN_CONT ".\n");
  123. /*
  124. * Check if initial kernel page mappings are sufficient.
  125. * panic early if not, else we may access kernel functions
  126. * and variables which can't be reached.
  127. */
  128. if (__pa((unsigned long) &_end) >= KERNEL_INITIAL_SIZE)
  129. panic("KERNEL_INITIAL_ORDER too small!");
  130. pdc_console_init();
  131. #ifdef CONFIG_64BIT
  132. if(parisc_narrow_firmware) {
  133. printk(KERN_INFO "Kernel is using PDC in 32-bit mode.\n");
  134. }
  135. #endif
  136. setup_pdc();
  137. setup_cmdline(cmdline_p);
  138. collect_boot_cpu_data();
  139. do_memory_inventory(); /* probe for physical memory */
  140. parisc_cache_init();
  141. paging_init();
  142. #ifdef CONFIG_CHASSIS_LCD_LED
  143. /* initialize the LCD/LED after boot_cpu_data is available ! */
  144. led_init(); /* LCD/LED initialization */
  145. #endif
  146. #ifdef CONFIG_PA11
  147. dma_ops_init();
  148. #endif
  149. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  150. conswitchp = &dummy_con; /* we use do_take_over_console() later ! */
  151. #endif
  152. clear_sched_clock_stable();
  153. }
  154. /*
  155. * Display CPU info for all CPUs.
  156. * for parisc this is in processor.c
  157. */
  158. extern int show_cpuinfo (struct seq_file *m, void *v);
  159. static void *
  160. c_start (struct seq_file *m, loff_t *pos)
  161. {
  162. /* Looks like the caller will call repeatedly until we return
  163. * 0, signaling EOF perhaps. This could be used to sequence
  164. * through CPUs for example. Since we print all cpu info in our
  165. * show_cpuinfo() disregarding 'pos' (which I assume is 'v' above)
  166. * we only allow for one "position". */
  167. return ((long)*pos < 1) ? (void *)1 : NULL;
  168. }
  169. static void *
  170. c_next (struct seq_file *m, void *v, loff_t *pos)
  171. {
  172. ++*pos;
  173. return c_start(m, pos);
  174. }
  175. static void
  176. c_stop (struct seq_file *m, void *v)
  177. {
  178. }
  179. const struct seq_operations cpuinfo_op = {
  180. .start = c_start,
  181. .next = c_next,
  182. .stop = c_stop,
  183. .show = show_cpuinfo
  184. };
  185. static void __init parisc_proc_mkdir(void)
  186. {
  187. /*
  188. ** Can't call proc_mkdir() until after proc_root_init() has been
  189. ** called by start_kernel(). In other words, this code can't
  190. ** live in arch/.../setup.c because start_parisc() calls
  191. ** start_kernel().
  192. */
  193. switch (boot_cpu_data.cpu_type) {
  194. case pcxl:
  195. case pcxl2:
  196. if (NULL == proc_gsc_root)
  197. {
  198. proc_gsc_root = proc_mkdir("bus/gsc", NULL);
  199. }
  200. break;
  201. case pcxt_:
  202. case pcxu:
  203. case pcxu_:
  204. case pcxw:
  205. case pcxw_:
  206. case pcxw2:
  207. if (NULL == proc_runway_root)
  208. {
  209. proc_runway_root = proc_mkdir("bus/runway", NULL);
  210. }
  211. break;
  212. case mako:
  213. case mako2:
  214. if (NULL == proc_mckinley_root)
  215. {
  216. proc_mckinley_root = proc_mkdir("bus/mckinley", NULL);
  217. }
  218. break;
  219. default:
  220. /* FIXME: this was added to prevent the compiler
  221. * complaining about missing pcx, pcxs and pcxt
  222. * I'm assuming they have neither gsc nor runway */
  223. break;
  224. }
  225. }
  226. static struct resource central_bus = {
  227. .name = "Central Bus",
  228. .start = F_EXTEND(0xfff80000),
  229. .end = F_EXTEND(0xfffaffff),
  230. .flags = IORESOURCE_MEM,
  231. };
  232. static struct resource local_broadcast = {
  233. .name = "Local Broadcast",
  234. .start = F_EXTEND(0xfffb0000),
  235. .end = F_EXTEND(0xfffdffff),
  236. .flags = IORESOURCE_MEM,
  237. };
  238. static struct resource global_broadcast = {
  239. .name = "Global Broadcast",
  240. .start = F_EXTEND(0xfffe0000),
  241. .end = F_EXTEND(0xffffffff),
  242. .flags = IORESOURCE_MEM,
  243. };
  244. static int __init parisc_init_resources(void)
  245. {
  246. int result;
  247. result = request_resource(&iomem_resource, &central_bus);
  248. if (result < 0) {
  249. printk(KERN_ERR
  250. "%s: failed to claim %s address space!\n",
  251. __FILE__, central_bus.name);
  252. return result;
  253. }
  254. result = request_resource(&iomem_resource, &local_broadcast);
  255. if (result < 0) {
  256. printk(KERN_ERR
  257. "%s: failed to claim %saddress space!\n",
  258. __FILE__, local_broadcast.name);
  259. return result;
  260. }
  261. result = request_resource(&iomem_resource, &global_broadcast);
  262. if (result < 0) {
  263. printk(KERN_ERR
  264. "%s: failed to claim %s address space!\n",
  265. __FILE__, global_broadcast.name);
  266. return result;
  267. }
  268. return 0;
  269. }
  270. static int no_alternatives __initdata;
  271. static int __init setup_no_alternatives(char *str)
  272. {
  273. no_alternatives = 1;
  274. return 1;
  275. }
  276. __setup("no-alternatives", setup_no_alternatives);
  277. static void __init apply_alternatives_all(void)
  278. {
  279. struct alt_instr *entry;
  280. int index = 0, applied = 0;
  281. pr_info("alternatives: %spatching kernel code\n",
  282. no_alternatives ? "NOT " : "");
  283. if (no_alternatives)
  284. return;
  285. set_kernel_text_rw(1);
  286. for (entry = (struct alt_instr *) &__alt_instructions;
  287. entry < (struct alt_instr *) &__alt_instructions_end;
  288. entry++, index++) {
  289. u32 *from, len, cond, replacement;
  290. from = (u32 *)((ulong)&entry->orig_offset + entry->orig_offset);
  291. len = entry->len;
  292. cond = entry->cond;
  293. replacement = entry->replacement;
  294. WARN_ON(!cond);
  295. pr_debug("Check %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n",
  296. index, cond, len, from, replacement);
  297. if ((cond & ALT_COND_NO_SMP) && (num_online_cpus() != 1))
  298. continue;
  299. if ((cond & ALT_COND_NO_DCACHE) && (cache_info.dc_size != 0))
  300. continue;
  301. if ((cond & ALT_COND_NO_ICACHE) && (cache_info.ic_size != 0))
  302. continue;
  303. /*
  304. * If the PDC_MODEL capabilities has Non-coherent IO-PDIR bit
  305. * set (bit #61, big endian), we have to flush and sync every
  306. * time IO-PDIR is changed in Ike/Astro.
  307. */
  308. if ((cond & ALT_COND_NO_IOC_FDC) &&
  309. (boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC))
  310. continue;
  311. /* Want to replace pdtlb by a pdtlb,l instruction? */
  312. if (replacement == INSN_PxTLB) {
  313. replacement = *from;
  314. if (boot_cpu_data.cpu_type >= pcxu) /* >= pa2.0 ? */
  315. replacement |= (1 << 10); /* set el bit */
  316. }
  317. /*
  318. * Replace instruction with NOPs?
  319. * For long distance insert a branch instruction instead.
  320. */
  321. if (replacement == INSN_NOP && len > 1)
  322. replacement = 0xe8000002 + (len-2)*8; /* "b,n .+8" */
  323. pr_debug("Do %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n",
  324. index, cond, len, from, replacement);
  325. /* Replace instruction */
  326. *from = replacement;
  327. applied++;
  328. }
  329. pr_info("alternatives: applied %d out of %d patches\n", applied, index);
  330. set_kernel_text_rw(0);
  331. }
  332. extern void gsc_init(void);
  333. extern void processor_init(void);
  334. extern void ccio_init(void);
  335. extern void hppb_init(void);
  336. extern void dino_init(void);
  337. extern void iosapic_init(void);
  338. extern void lba_init(void);
  339. extern void sba_init(void);
  340. extern void eisa_init(void);
  341. static int __init parisc_init(void)
  342. {
  343. u32 osid = (OS_ID_LINUX << 16);
  344. parisc_proc_mkdir();
  345. parisc_init_resources();
  346. do_device_inventory(); /* probe for hardware */
  347. parisc_pdc_chassis_init();
  348. /* set up a new led state on systems shipped LED State panel */
  349. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BSTART);
  350. /* tell PDC we're Linux. Nevermind failure. */
  351. pdc_stable_write(0x40, &osid, sizeof(osid));
  352. /* start with known state */
  353. flush_cache_all_local();
  354. flush_tlb_all_local(NULL);
  355. processor_init();
  356. #ifdef CONFIG_SMP
  357. pr_info("CPU(s): %d out of %d %s at %d.%06d MHz online\n",
  358. num_online_cpus(), num_present_cpus(),
  359. #else
  360. pr_info("CPU(s): 1 x %s at %d.%06d MHz\n",
  361. #endif
  362. boot_cpu_data.cpu_name,
  363. boot_cpu_data.cpu_hz / 1000000,
  364. boot_cpu_data.cpu_hz % 1000000 );
  365. apply_alternatives_all();
  366. parisc_setup_cache_timing();
  367. /* These are in a non-obvious order, will fix when we have an iotree */
  368. #if defined(CONFIG_IOSAPIC)
  369. iosapic_init();
  370. #endif
  371. #if defined(CONFIG_IOMMU_SBA)
  372. sba_init();
  373. #endif
  374. #if defined(CONFIG_PCI_LBA)
  375. lba_init();
  376. #endif
  377. /* CCIO before any potential subdevices */
  378. #if defined(CONFIG_IOMMU_CCIO)
  379. ccio_init();
  380. #endif
  381. /*
  382. * Need to register Asp & Wax before the EISA adapters for the IRQ
  383. * regions. EISA must come before PCI to be sure it gets IRQ region
  384. * 0.
  385. */
  386. #if defined(CONFIG_GSC_LASI) || defined(CONFIG_GSC_WAX)
  387. gsc_init();
  388. #endif
  389. #ifdef CONFIG_EISA
  390. eisa_init();
  391. #endif
  392. #if defined(CONFIG_HPPB)
  393. hppb_init();
  394. #endif
  395. #if defined(CONFIG_GSC_DINO)
  396. dino_init();
  397. #endif
  398. #ifdef CONFIG_CHASSIS_LCD_LED
  399. register_led_regions(); /* register LED port info in procfs */
  400. #endif
  401. return 0;
  402. }
  403. arch_initcall(parisc_init);
  404. void __init start_parisc(void)
  405. {
  406. extern void early_trap_init(void);
  407. int ret, cpunum;
  408. struct pdc_coproc_cfg coproc_cfg;
  409. cpunum = smp_processor_id();
  410. init_cpu_topology();
  411. set_firmware_width_unlocked();
  412. ret = pdc_coproc_cfg_unlocked(&coproc_cfg);
  413. if (ret >= 0 && coproc_cfg.ccr_functional) {
  414. mtctl(coproc_cfg.ccr_functional, 10);
  415. per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;
  416. per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;
  417. asm volatile ("fstd %fr0,8(%sp)");
  418. } else {
  419. panic("must have an fpu to boot linux");
  420. }
  421. early_trap_init(); /* initialize checksum of fault_vector */
  422. start_kernel();
  423. // not reached
  424. }