setup.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:29k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/arch/alpha/kernel/setup.c
  3.  *
  4.  *  Copyright (C) 1995  Linus Torvalds
  5.  */
  6. /* 2.3.x bootmem, 1999 Andrea Arcangeli <andrea@suse.de> */
  7. /*
  8.  * Bootup setup stuff.
  9.  */
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/stddef.h>
  14. #include <linux/unistd.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/slab.h>
  17. #include <linux/user.h>
  18. #include <linux/a.out.h>
  19. #include <linux/tty.h>
  20. #include <linux/delay.h>
  21. #include <linux/config.h> /* CONFIG_ALPHA_LCA etc */
  22. #include <linux/mc146818rtc.h>
  23. #include <linux/console.h>
  24. #include <linux/errno.h>
  25. #include <linux/init.h>
  26. #include <linux/string.h>
  27. #include <linux/ioport.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/pci.h>
  30. #include <linux/seq_file.h>
  31. #ifdef CONFIG_BLK_DEV_INITRD
  32. #include <linux/blk.h>
  33. #endif
  34. #include <linux/notifier.h>
  35. extern struct notifier_block *panic_notifier_list;
  36. static int alpha_panic_event(struct notifier_block *, unsigned long, void *);
  37. static struct notifier_block alpha_panic_block = {
  38. alpha_panic_event,
  39.         NULL,
  40.         INT_MAX /* try to do it first */
  41. };
  42. #include <asm/uaccess.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/system.h>
  45. #include <asm/hwrpb.h>
  46. #include <asm/dma.h>
  47. #include <asm/io.h>
  48. #include <asm/mmu_context.h>
  49. #include <asm/console.h>
  50. #include "proto.h"
  51. #include "pci_impl.h"
  52. struct hwrpb_struct *hwrpb;
  53. unsigned long srm_hae;
  54. /* Which processor we booted from.  */
  55. int boot_cpuid;
  56. /*
  57.  * Using SRM callbacks for initial console output. This works from
  58.  * setup_arch() time through the end of time_init(), as those places
  59.  * are under our (Alpha) control.
  60.  * "srmcons" specified in the boot command arguments allows us to
  61.  * see kernel messages during the period of time before the true
  62.  * console device is "registered" during console_init(). As of this
  63.  * version (2.4.10), time_init() is the last Alpha-specific code
  64.  * called before console_init(), so we put "unregister" code
  65.  * there to prevent schizophrenic console behavior later... ;-}
  66.  *
  67.  * By default, OFF; set it with a bootcommand arg of "srmcons".
  68.  */
  69. int srmcons_output = 0;
  70. /* Enforce a memory size limit; useful for testing. By default, none. */
  71. unsigned long mem_size_limit = 0;
  72. #ifdef CONFIG_ALPHA_GENERIC
  73. struct alpha_machine_vector alpha_mv;
  74. int alpha_using_srm;
  75. #endif
  76. unsigned char aux_device_present = 0xaa;
  77. #define N(a) (sizeof(a)/sizeof(a[0]))
  78. static struct alpha_machine_vector *get_sysvec(long, long, long);
  79. static struct alpha_machine_vector *get_sysvec_byname(const char *);
  80. static void get_sysnames(long, long, long, char **, char **);
  81. static char command_line[COMMAND_LINE_SIZE];
  82. char saved_command_line[COMMAND_LINE_SIZE];
  83. /*
  84.  * The format of "screen_info" is strange, and due to early
  85.  * i386-setup code. This is just enough to make the console
  86.  * code think we're on a VGA color display.
  87.  */
  88. struct screen_info screen_info = {
  89. orig_x: 0,
  90. orig_y: 25,
  91. orig_video_cols: 80,
  92. orig_video_lines: 25,
  93. orig_video_isVGA: 1,
  94. orig_video_points: 16
  95. };
  96. /*
  97.  * The direct map I/O window, if any.  This should be the same
  98.  * for all busses, since it's used by virt_to_bus.
  99.  */
  100. unsigned long __direct_map_base;
  101. unsigned long __direct_map_size;
  102. /*
  103.  * Declare all of the machine vectors.
  104.  */
  105. /* GCC 2.7.2 (on alpha at least) is lame.  It does not support either 
  106.    __attribute__((weak)) or #pragma weak.  Bypass it and talk directly
  107.    to the assembler.  */
  108. #define WEAK(X) 
  109. extern struct alpha_machine_vector X; 
  110. asm(".weak "#X)
  111. WEAK(alcor_mv);
  112. WEAK(alphabook1_mv);
  113. WEAK(avanti_mv);
  114. WEAK(cabriolet_mv);
  115. WEAK(clipper_mv);
  116. WEAK(dp264_mv);
  117. WEAK(eb164_mv);
  118. WEAK(eb64p_mv);
  119. WEAK(eb66_mv);
  120. WEAK(eb66p_mv);
  121. WEAK(eiger_mv);
  122. WEAK(jensen_mv);
  123. WEAK(lx164_mv);
  124. WEAK(miata_mv);
  125. WEAK(mikasa_mv);
  126. WEAK(mikasa_primo_mv);
  127. WEAK(monet_mv);
  128. WEAK(nautilus_mv);
  129. WEAK(noname_mv);
  130. WEAK(noritake_mv);
  131. WEAK(noritake_primo_mv);
  132. WEAK(p2k_mv);
  133. WEAK(pc164_mv);
  134. WEAK(privateer_mv);
  135. WEAK(rawhide_mv);
  136. WEAK(ruffian_mv);
  137. WEAK(rx164_mv);
  138. WEAK(sable_mv);
  139. WEAK(sable_gamma_mv);
  140. WEAK(shark_mv);
  141. WEAK(sx164_mv);
  142. WEAK(takara_mv);
  143. WEAK(webbrick_mv);
  144. WEAK(wildfire_mv);
  145. WEAK(xl_mv);
  146. WEAK(xlt_mv);
  147. #undef WEAK
  148. /*
  149.  * I/O resources inherited from PeeCees.  Except for perhaps the
  150.  * turbochannel alphas, everyone has these on some sort of SuperIO chip.
  151.  *
  152.  * ??? If this becomes less standard, move the struct out into the
  153.  * machine vector.
  154.  */
  155. static void __init
  156. reserve_std_resources(void)
  157. {
  158. static struct resource standard_io_resources[] = {
  159. { "rtc", -1, -1 },
  160.          { "dma1", 0x00, 0x1f },
  161.          { "pic1", 0x20, 0x3f },
  162.          { "timer", 0x40, 0x5f },
  163.          { "keyboard", 0x60, 0x6f },
  164.          { "dma page reg", 0x80, 0x8f },
  165.          { "pic2", 0xa0, 0xbf },
  166.          { "dma2", 0xc0, 0xdf },
  167. };
  168. struct resource *io = &ioport_resource;
  169. long i;
  170. if (hose_head) {
  171. struct pci_controller *hose;
  172. for (hose = hose_head; hose; hose = hose->next)
  173. if (hose->index == 0) {
  174. io = hose->io_space;
  175. break;
  176. }
  177. }
  178. /* Fix up for the Jensen's queer RTC placement.  */
  179. standard_io_resources[0].start = RTC_PORT(0);
  180. standard_io_resources[0].end = RTC_PORT(0) + 0x10;
  181. for (i = 0; i < N(standard_io_resources); ++i)
  182. request_resource(io, standard_io_resources+i);
  183. }
  184. #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
  185. #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
  186. #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
  187. #define PFN_MAX PFN_DOWN(0x80000000)
  188. #define for_each_mem_cluster(memdesc, cluster, i)
  189. for ((cluster) = (memdesc)->cluster, (i) = 0;
  190.      (i) < (memdesc)->numclusters; (i)++, (cluster)++)
  191. static unsigned long __init
  192. get_mem_size_limit(char *s)
  193. {
  194.         unsigned long end = 0;
  195.         char *from = s;
  196.         end = simple_strtoul(from, &from, 0);
  197.         if ( *from == 'K' || *from == 'k' ) {
  198.                 end = end << 10;
  199.                 from++;
  200.         } else if ( *from == 'M' || *from == 'm' ) {
  201.                 end = end << 20;
  202.                 from++;
  203.         } else if ( *from == 'G' || *from == 'g' ) {
  204.                 end = end << 30;
  205.                 from++;
  206.         }
  207.         return end >> PAGE_SHIFT; /* Return the PFN of the limit. */
  208. }
  209. #ifndef CONFIG_DISCONTIGMEM
  210. static void __init
  211. setup_memory(void *kernel_end)
  212. {
  213. struct memclust_struct * cluster;
  214. struct memdesc_struct * memdesc;
  215. unsigned long start_kernel_pfn, end_kernel_pfn;
  216. unsigned long bootmap_size, bootmap_pages, bootmap_start;
  217. unsigned long start, end;
  218. int i;
  219. /* Find free clusters, and init and free the bootmem accordingly.  */
  220. memdesc = (struct memdesc_struct *)
  221.   (hwrpb->mddt_offset + (unsigned long) hwrpb);
  222. for_each_mem_cluster(memdesc, cluster, i) {
  223. printk("memcluster %d, usage %01lx, start %8lu, end %8lun",
  224.        i, cluster->usage, cluster->start_pfn,
  225.        cluster->start_pfn + cluster->numpages);
  226. /* Bit 0 is console/PALcode reserved.  Bit 1 is
  227.    non-volatile memory -- we might want to mark
  228.    this for later.  */
  229. if (cluster->usage & 3)
  230. continue;
  231. end = cluster->start_pfn + cluster->numpages;
  232. if (end > max_low_pfn)
  233. max_low_pfn = end;
  234. }
  235. if (mem_size_limit && max_low_pfn >= mem_size_limit)
  236. {
  237. printk("setup: forcing memory size to %ldK (from %ldK).n",
  238.        mem_size_limit << (PAGE_SHIFT - 10),
  239.        max_low_pfn    << (PAGE_SHIFT - 10));
  240. max_low_pfn = mem_size_limit;
  241. }
  242. /* Find the bounds of kernel memory.  */
  243. start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
  244. end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
  245. bootmap_start = -1;
  246.  try_again:
  247. if (max_low_pfn <= end_kernel_pfn)
  248. panic("not enough memory to boot");
  249. /* We need to know how many physically contiguous pages
  250.    we'll need for the bootmap.  */
  251. bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
  252. /* Now find a good region where to allocate the bootmap.  */
  253. for_each_mem_cluster(memdesc, cluster, i) {
  254. if (cluster->usage & 3)
  255. continue;
  256. start = cluster->start_pfn;
  257. end = start + cluster->numpages;
  258. if (start >= max_low_pfn)
  259. continue;
  260. if (end > max_low_pfn)
  261. end = max_low_pfn;
  262. if (start < start_kernel_pfn) {
  263. if (end > end_kernel_pfn
  264.     && end - end_kernel_pfn >= bootmap_pages) {
  265. bootmap_start = end_kernel_pfn;
  266. break;
  267. } else if (end > start_kernel_pfn)
  268. end = start_kernel_pfn;
  269. } else if (start < end_kernel_pfn)
  270. start = end_kernel_pfn;
  271. if (end - start >= bootmap_pages) {
  272. bootmap_start = start;
  273. break;
  274. }
  275. }
  276. if (bootmap_start == -1) {
  277. max_low_pfn >>= 1;
  278. goto try_again;
  279. }
  280. /* Allocate the bootmap and mark the whole MM as reserved.  */
  281. bootmap_size = init_bootmem(bootmap_start, max_low_pfn);
  282. /* Mark the free regions.  */
  283. for_each_mem_cluster(memdesc, cluster, i) {
  284. if (cluster->usage & 3)
  285. continue;
  286. start = cluster->start_pfn;
  287. end = cluster->start_pfn + cluster->numpages;
  288. if (start >= max_low_pfn)
  289. continue;
  290. if (end > max_low_pfn)
  291. end = max_low_pfn;
  292. if (start < start_kernel_pfn) {
  293. if (end > end_kernel_pfn) {
  294. free_bootmem(PFN_PHYS(start),
  295.      (PFN_PHYS(start_kernel_pfn)
  296.       - PFN_PHYS(start)));
  297. printk("freeing pages %ld:%ldn",
  298.        start, start_kernel_pfn);
  299. start = end_kernel_pfn;
  300. } else if (end > start_kernel_pfn)
  301. end = start_kernel_pfn;
  302. } else if (start < end_kernel_pfn)
  303. start = end_kernel_pfn;
  304. if (start >= end)
  305. continue;
  306. free_bootmem(PFN_PHYS(start), PFN_PHYS(end) - PFN_PHYS(start));
  307. printk("freeing pages %ld:%ldn", start, end);
  308. }
  309. /* Reserve the bootmap memory.  */
  310. reserve_bootmem(PFN_PHYS(bootmap_start), bootmap_size);
  311. printk("reserving pages %ld:%ldn", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
  312. #ifdef CONFIG_BLK_DEV_INITRD
  313. initrd_start = INITRD_START;
  314. if (initrd_start) {
  315. initrd_end = initrd_start+INITRD_SIZE;
  316. printk("Initial ramdisk at: 0x%p (%lu bytes)n",
  317.        (void *) initrd_start, INITRD_SIZE);
  318. if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
  319. printk("initrd extends beyond end of memory "
  320.        "(0x%08lx > 0x%p)ndisabling initrdn",
  321.        initrd_end,
  322.        phys_to_virt(PFN_PHYS(max_low_pfn)));
  323. initrd_start = initrd_end = 0;
  324. } else {
  325. reserve_bootmem(virt_to_phys((void *)initrd_start),
  326. INITRD_SIZE);
  327. }
  328. }
  329. #endif /* CONFIG_BLK_DEV_INITRD */
  330. }
  331. #else
  332. extern void setup_memory(void *);
  333. #endif /* !CONFIG_DISCONTIGMEM */
  334. int __init
  335. page_is_ram(unsigned long pfn)
  336. {
  337. struct memclust_struct * cluster;
  338. struct memdesc_struct * memdesc;
  339. int i;
  340. memdesc = (struct memdesc_struct *)
  341. (hwrpb->mddt_offset + (unsigned long) hwrpb);
  342. for_each_mem_cluster(memdesc, cluster, i)
  343. {
  344. if (pfn >= cluster->start_pfn  &&
  345.     pfn < cluster->start_pfn + cluster->numpages) {
  346. return (cluster->usage & 3) ? 0 : 1;
  347. }
  348. }
  349. return 0;
  350. }
  351. #undef PFN_UP
  352. #undef PFN_DOWN
  353. #undef PFN_PHYS
  354. #undef PFN_MAX
  355. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
  356. /*
  357.  *      Manage the SRM callbacks as a "console".
  358.  */
  359. static struct console srmcons;
  360. void __init register_srm_console(void)
  361. {
  362.         register_console(&srmcons);
  363. }
  364. void __init unregister_srm_console(void)
  365. {
  366.         unregister_console(&srmcons);
  367. }
  368. static void srm_console_write(struct console *co, const char *s,
  369.                                 unsigned count)
  370. {
  371. srm_printk(s);
  372. }
  373. static kdev_t srm_console_device(struct console *c)
  374. {
  375.   /* Huh? */
  376.         return MKDEV(TTY_MAJOR, 64 + c->index);
  377. }
  378. static int __init srm_console_setup(struct console *co, char *options)
  379. {
  380. return 1;
  381. }
  382. static struct console srmcons = {
  383. name: "srm0",
  384. write: srm_console_write,
  385. device: srm_console_device,
  386. setup: srm_console_setup,
  387. flags: CON_PRINTBUFFER | CON_ENABLED, /* fake it out */
  388. index: -1,
  389. };
  390. #else
  391. void __init register_srm_console(void)
  392. {
  393. }
  394. void __init unregister_srm_console(void)
  395. {
  396. }
  397. #endif
  398. void __init
  399. setup_arch(char **cmdline_p)
  400. {
  401. extern char _end[];
  402. struct alpha_machine_vector *vec = NULL;
  403. struct percpu_struct *cpu;
  404. char *type_name, *var_name, *p;
  405. void *kernel_end = _end; /* end of kernel */
  406. hwrpb = (struct hwrpb_struct*) __va(INIT_HWRPB->phys_addr);
  407. boot_cpuid = hard_smp_processor_id();
  408. /* Register a call for panic conditions. */
  409. notifier_chain_register(&panic_notifier_list, &alpha_panic_block);
  410. #ifdef CONFIG_ALPHA_GENERIC
  411. /* Assume that we've booted from SRM if we havn't booted from MILO.
  412.    Detect the later by looking for "MILO" in the system serial nr.  */
  413. alpha_using_srm = strncmp((const char *)hwrpb->ssn, "MILO", 4) != 0;
  414. #endif
  415. /* If we are using SRM, we want to allow callbacks
  416.    as early as possible, so do this NOW, and then
  417.    they should work immediately thereafter.
  418. */
  419. kernel_end = callback_init(kernel_end);
  420. /* 
  421.  * Locate the command line.
  422.  */
  423. /* Hack for Jensen... since we're restricted to 8 or 16 chars for
  424.    boot flags depending on the boot mode, we need some shorthand.
  425.    This should do for installation.  */
  426. if (strcmp(COMMAND_LINE, "INSTALL") == 0) {
  427. strcpy(command_line, "root=/dev/fd0 load_ramdisk=1");
  428. } else {
  429. strncpy(command_line, COMMAND_LINE, sizeof command_line);
  430. command_line[sizeof(command_line)-1] = 0;
  431. }
  432. strcpy(saved_command_line, command_line);
  433. *cmdline_p = command_line;
  434. /* 
  435.  * Process command-line arguments.
  436.  */
  437. for (p = strtok(command_line, " t"); p ; p = strtok(NULL, " t")) {
  438. if (strncmp(p, "alpha_mv=", 9) == 0) {
  439. vec = get_sysvec_byname(p+9);
  440. continue;
  441. }
  442. if (strncmp(p, "cycle=", 6) == 0) {
  443. est_cycle_freq = simple_strtol(p+6, NULL, 0);
  444. continue;
  445. }
  446. if (strncmp(p, "mem=", 4) == 0) {
  447. mem_size_limit = get_mem_size_limit(p+4);
  448. continue;
  449. }
  450. if (strncmp(p, "srmcons", 7) == 0) {
  451. srmcons_output = 1;
  452. continue;
  453. }
  454. }
  455. /* Replace the command line, now that we've killed it with strtok.  */
  456. strcpy(command_line, saved_command_line);
  457. /* If we want SRM console printk echoing early, do it now. */
  458. if (alpha_using_srm && srmcons_output) {
  459. register_srm_console();
  460. }
  461. /*
  462.  * Indentify and reconfigure for the current system.
  463.  */
  464. cpu = (struct percpu_struct*)((char*)hwrpb + hwrpb->processor_offset);
  465. get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
  466.      cpu->type, &type_name, &var_name);
  467. if (*var_name == '0')
  468. var_name = "";
  469. if (!vec) {
  470. vec = get_sysvec(hwrpb->sys_type, hwrpb->sys_variation,
  471.  cpu->type);
  472. }
  473. if (!vec) {
  474. panic("Unsupported system type: %s%s%s (%ld %ld)n",
  475.       type_name, (*var_name ? " variation " : ""), var_name,
  476.       hwrpb->sys_type, hwrpb->sys_variation);
  477. }
  478. if (vec != &alpha_mv) {
  479. alpha_mv = *vec;
  480. }
  481. printk("Booting "
  482. #ifdef CONFIG_ALPHA_GENERIC
  483.        "GENERIC "
  484. #endif
  485.        "on %s%s%s using machine vector %s from %sn",
  486.        type_name, (*var_name ? " variation " : ""),
  487.        var_name, alpha_mv.vector_name,
  488.        (alpha_using_srm ? "SRM" : "MILO"));
  489. printk("Command line: %sn", command_line);
  490. /* 
  491.  * Sync up the HAE.
  492.  * Save the SRM's current value for restoration.
  493.  */
  494. srm_hae = *alpha_mv.hae_register;
  495. __set_hae(alpha_mv.hae_cache);
  496. /* Reset enable correctable error reports.  */
  497. wrmces(0x7);
  498. /* Find our memory.  */
  499. setup_memory(kernel_end);
  500. /* Initialize the machine.  Usually has to do with setting up
  501.    DMA windows and the like.  */
  502. if (alpha_mv.init_arch)
  503. alpha_mv.init_arch();
  504. /* Reserve standard resources.  */
  505. reserve_std_resources();
  506. /* 
  507.  * Give us a default console.  TGA users will see nothing until
  508.  * chr_dev_init is called, rather late in the boot sequence.
  509.  */
  510. #ifdef CONFIG_VT
  511. #if defined(CONFIG_VGA_CONSOLE)
  512. conswitchp = &vga_con;
  513. #elif defined(CONFIG_DUMMY_CONSOLE)
  514. conswitchp = &dummy_con;
  515. #endif
  516. #endif
  517. /* Default root filesystem to sda2.  */
  518. ROOT_DEV = to_kdev_t(0x0802);
  519.   /*
  520.  * Check ASN in HWRPB for validity, report if bad.
  521.  * FIXME: how was this failing?  Should we trust it instead,
  522.  * and copy the value into alpha_mv.max_asn?
  523.    */
  524.   if (hwrpb->max_asn != MAX_ASN) {
  525. printk("Max ASN from HWRPB is bad (0x%lx)n", hwrpb->max_asn);
  526.   }
  527. /*
  528.  * Identify the flock of penguins.
  529.  */
  530. #ifdef CONFIG_SMP
  531. setup_smp();
  532. #endif
  533. paging_init();
  534. }
  535. static char sys_unknown[] = "Unknown";
  536. static char systype_names[][16] = {
  537. "0",
  538. "ADU", "Cobra", "Ruby", "Flamingo", "Mannequin", "Jensen",
  539. "Pelican", "Morgan", "Sable", "Medulla", "Noname",
  540. "Turbolaser", "Avanti", "Mustang", "Alcor", "Tradewind",
  541. "Mikasa", "EB64", "EB66", "EB64+", "AlphaBook1",
  542. "Rawhide", "K2", "Lynx", "XL", "EB164", "Noritake",
  543. "Cortex", "29", "Miata", "XXM", "Takara", "Yukon",
  544. "Tsunami", "Wildfire", "CUSCO", "Eiger", "Titan"
  545. };
  546. static char unofficial_names[][8] = {"100", "Ruffian"};
  547. static char api_names[][16] = {"200", "Nautilus"};
  548. static char eb164_names[][8] = {"EB164", "PC164", "LX164", "SX164", "RX164"};
  549. static int eb164_indices[] = {0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,4};
  550. static char alcor_names[][16] = {"Alcor", "Maverick", "Bret"};
  551. static int alcor_indices[] = {0,0,0,1,1,1,0,0,0,0,0,0,2,2,2,2,2,2};
  552. static char eb64p_names[][16] = {"EB64+", "Cabriolet", "AlphaPCI64"};
  553. static int eb64p_indices[] = {0,0,1,2};
  554. static char eb66_names[][8] = {"EB66", "EB66+"};
  555. static int eb66_indices[] = {0,0,1};
  556. static char rawhide_names[][16] = {
  557. "Dodge", "Wrangler", "Durango", "Tincup", "DaVinci"
  558. };
  559. static int rawhide_indices[] = {0,0,0,1,1,2,2,3,3,4,4};
  560. static char titan_names[][16] = {
  561. "0", "Privateer"
  562. };
  563. static int titan_indices[] = {0,1};
  564. static char tsunami_names[][16] = {
  565. "0", "DP264", "Warhol", "Windjammer", "Monet", "Clipper",
  566. "Goldrush", "Webbrick", "Catamaran", "Brisbane", "Melbourne",
  567. "Flying Clipper", "Shark"
  568. };
  569. static int tsunami_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12};
  570. static struct alpha_machine_vector * __init
  571. get_sysvec(long type, long variation, long cpu)
  572. {
  573. static struct alpha_machine_vector *systype_vecs[] __initdata =
  574. {
  575. NULL, /* 0 */
  576. NULL, /* ADU */
  577. NULL, /* Cobra */
  578. NULL, /* Ruby */
  579. NULL, /* Flamingo */
  580. NULL, /* Mannequin */
  581. &jensen_mv,
  582. NULL,  /* Pelican */
  583. NULL, /* Morgan */
  584. NULL, /* Sable -- see below.  */
  585. NULL, /* Medulla */
  586. &noname_mv,
  587. NULL, /* Turbolaser */
  588. &avanti_mv,
  589. NULL, /* Mustang */
  590. &alcor_mv, /* Alcor, Bret, Maverick.  */
  591. NULL, /* Tradewind */
  592. NULL, /* Mikasa -- see below.  */
  593. NULL, /* EB64 */
  594. NULL, /* EB66 -- see variation.  */
  595. NULL, /* EB64+ -- see variation.  */
  596. &alphabook1_mv,
  597. &rawhide_mv,
  598. NULL, /* K2 */
  599. NULL, /* Lynx */
  600. &xl_mv,
  601. NULL, /* EB164 -- see variation.  */
  602. NULL, /* Noritake -- see below.  */
  603. NULL, /* Cortex */
  604. NULL, /* 29 */
  605. &miata_mv,
  606. NULL, /* XXM */
  607. &takara_mv,
  608. NULL, /* Yukon */
  609. NULL, /* Tsunami -- see variation.  */
  610. &wildfire_mv, /* Wildfire */
  611. NULL, /* CUSCO */
  612. &eiger_mv, /* Eiger */
  613. NULL, /* Titan */
  614. };
  615. static struct alpha_machine_vector *unofficial_vecs[] __initdata =
  616. {
  617. NULL, /* 100 */
  618. &ruffian_mv,
  619. };
  620. static struct alpha_machine_vector *api_vecs[] __initdata =
  621. {
  622. NULL, /* 200 */
  623. &nautilus_mv,
  624. };
  625. static struct alpha_machine_vector *alcor_vecs[] __initdata = 
  626. {
  627. &alcor_mv, &xlt_mv, &xlt_mv
  628. };
  629. static struct alpha_machine_vector *eb164_vecs[] __initdata =
  630. {
  631. &eb164_mv, &pc164_mv, &lx164_mv, &sx164_mv, &rx164_mv
  632. };
  633. static struct alpha_machine_vector *eb64p_vecs[] __initdata =
  634. {
  635. &eb64p_mv,
  636. &cabriolet_mv,
  637. &cabriolet_mv /* AlphaPCI64 */
  638. };
  639. static struct alpha_machine_vector *eb66_vecs[] __initdata =
  640. {
  641. &eb66_mv,
  642. &eb66p_mv
  643. };
  644. static struct alpha_machine_vector *titan_vecs[] __initdata =
  645. {
  646. NULL,
  647. &privateer_mv, /* privateer */
  648. };
  649. static struct alpha_machine_vector *tsunami_vecs[]  __initdata =
  650. {
  651. NULL,
  652. &dp264_mv, /* dp264 */
  653. &dp264_mv, /* warhol */
  654. &dp264_mv, /* windjammer */
  655. &monet_mv, /* monet */
  656. &clipper_mv, /* clipper */
  657. &dp264_mv, /* goldrush */
  658. &webbrick_mv, /* webbrick */
  659. &dp264_mv, /* catamaran */
  660. NULL, /* brisbane? */
  661. NULL, /* melbourne? */
  662. NULL, /* flying clipper? */
  663. &shark_mv, /* shark */
  664. };
  665. /* ??? Do we need to distinguish between Rawhides?  */
  666. struct alpha_machine_vector *vec;
  667. /* Restore real CABRIO and EB66+ family names, ie EB64+ and EB66 */
  668. if (type < 0)
  669. type = -type;
  670. /* Search the system tables first... */
  671. vec = NULL;
  672. if (type < N(systype_vecs)) {
  673. vec = systype_vecs[type];
  674. } else if ((type > ST_API_BIAS) &&
  675.    (type - ST_API_BIAS) < N(api_vecs)) {
  676. vec = api_vecs[type - ST_API_BIAS];
  677. } else if ((type > ST_UNOFFICIAL_BIAS) &&
  678.    (type - ST_UNOFFICIAL_BIAS) < N(unofficial_vecs)) {
  679. vec = unofficial_vecs[type - ST_UNOFFICIAL_BIAS];
  680. }
  681. /* If we've not found one, try for a variation.  */
  682. if (!vec) {
  683. /* Member ID is a bit-field. */
  684. long member = (variation >> 10) & 0x3f;
  685. cpu &= 0xffffffff; /* make it usable */
  686. switch (type) {
  687. case ST_DEC_ALCOR:
  688. if (member < N(alcor_indices))
  689. vec = alcor_vecs[alcor_indices[member]];
  690. break;
  691. case ST_DEC_EB164:
  692. if (member < N(eb164_indices))
  693. vec = eb164_vecs[eb164_indices[member]];
  694. /* PC164 may show as EB164 variation with EV56 CPU,
  695.    but, since no true EB164 had anything but EV5... */
  696. if (vec == &eb164_mv && cpu == EV56_CPU)
  697. vec = &pc164_mv;
  698. break;
  699. case ST_DEC_EB64P:
  700. if (member < N(eb64p_indices))
  701. vec = eb64p_vecs[eb64p_indices[member]];
  702. break;
  703. case ST_DEC_EB66:
  704. if (member < N(eb66_indices))
  705. vec = eb66_vecs[eb66_indices[member]];
  706. break;
  707. case ST_DEC_TITAN:
  708. if (member < N(titan_indices))
  709. vec = titan_vecs[titan_indices[member]];
  710. break;
  711. case ST_DEC_TSUNAMI:
  712. if (member < N(tsunami_indices))
  713. vec = tsunami_vecs[tsunami_indices[member]];
  714. break;
  715. case ST_DEC_1000:
  716. if (cpu == EV5_CPU || cpu == EV56_CPU)
  717. vec = &mikasa_primo_mv;
  718. else
  719. vec = &mikasa_mv;
  720. break;
  721. case ST_DEC_NORITAKE:
  722. if (cpu == EV5_CPU || cpu == EV56_CPU)
  723. vec = &noritake_primo_mv;
  724. else
  725. vec = &noritake_mv;
  726. break;
  727. case ST_DEC_2100_A500:
  728. if (cpu == EV5_CPU || cpu == EV56_CPU)
  729. vec = &sable_gamma_mv;
  730. else
  731. vec = &sable_mv;
  732. break;
  733. }
  734. }
  735. return vec;
  736. }
  737. static struct alpha_machine_vector * __init
  738. get_sysvec_byname(const char *name)
  739. {
  740. static struct alpha_machine_vector *all_vecs[] __initdata =
  741. {
  742. &alcor_mv,
  743. &alphabook1_mv,
  744. &avanti_mv,
  745. &cabriolet_mv,
  746. &clipper_mv,
  747. &dp264_mv,
  748. &eb164_mv,
  749. &eb64p_mv,
  750. &eb66_mv,
  751. &eb66p_mv,
  752. &eiger_mv,
  753. &jensen_mv,
  754. &lx164_mv,
  755. &miata_mv,
  756. &mikasa_mv,
  757. &mikasa_primo_mv,
  758. &monet_mv,
  759. &nautilus_mv,
  760. &noname_mv,
  761. &noritake_mv,
  762. &noritake_primo_mv,
  763. &p2k_mv,
  764. &pc164_mv,
  765. &privateer_mv,
  766. &rawhide_mv,
  767. &ruffian_mv,
  768. &rx164_mv,
  769. &sable_mv,
  770. &sable_gamma_mv,
  771. &shark_mv,
  772. &sx164_mv,
  773. &takara_mv,
  774. &webbrick_mv,
  775. &wildfire_mv,
  776. &xl_mv,
  777. &xlt_mv
  778. };
  779. int i, n = sizeof(all_vecs)/sizeof(*all_vecs);
  780. for (i = 0; i < n; ++i) {
  781. struct alpha_machine_vector *mv = all_vecs[i];
  782. if (strcasecmp(mv->vector_name, name) == 0)
  783. return mv;
  784. }
  785. return NULL;
  786. }
  787. static void
  788. get_sysnames(long type, long variation, long cpu,
  789.      char **type_name, char **variation_name)
  790. {
  791. long member;
  792. /* Restore real CABRIO and EB66+ family names, ie EB64+ and EB66 */
  793. if (type < 0)
  794. type = -type;
  795. /* If not in the tables, make it UNKNOWN,
  796.    else set type name to family */
  797. if (type < N(systype_names)) {
  798. *type_name = systype_names[type];
  799. } else if ((type > ST_API_BIAS) &&
  800.    (type - ST_API_BIAS) < N(api_names)) {
  801. *type_name = api_names[type - ST_API_BIAS];
  802. } else if ((type > ST_UNOFFICIAL_BIAS) &&
  803.    (type - ST_UNOFFICIAL_BIAS) < N(unofficial_names)) {
  804. *type_name = unofficial_names[type - ST_UNOFFICIAL_BIAS];
  805. } else {
  806. *type_name = sys_unknown;
  807. *variation_name = sys_unknown;
  808. return;
  809. }
  810. /* Set variation to "0"; if variation is zero, done */
  811. *variation_name = systype_names[0];
  812. if (variation == 0) {
  813. return;
  814. }
  815. member = (variation >> 10) & 0x3f; /* member ID is a bit-field */
  816. cpu &= 0xffffffff; /* make it usable */
  817. switch (type) { /* select by family */
  818. default: /* default to variation "0" for now */
  819. break;
  820. case ST_DEC_EB164:
  821. if (member < N(eb164_indices))
  822. *variation_name = eb164_names[eb164_indices[member]];
  823. /* PC164 may show as EB164 variation, but with EV56 CPU,
  824.    so, since no true EB164 had anything but EV5... */
  825. if (eb164_indices[member] == 0 && cpu == EV56_CPU)
  826. *variation_name = eb164_names[1]; /* make it PC164 */
  827. break;
  828. case ST_DEC_ALCOR:
  829. if (member < N(alcor_indices))
  830. *variation_name = alcor_names[alcor_indices[member]];
  831. break;
  832. case ST_DEC_EB64P:
  833. if (member < N(eb64p_indices))
  834. *variation_name = eb64p_names[eb64p_indices[member]];
  835. break;
  836. case ST_DEC_EB66:
  837. if (member < N(eb66_indices))
  838. *variation_name = eb66_names[eb66_indices[member]];
  839. break;
  840. case ST_DEC_RAWHIDE:
  841. if (member < N(rawhide_indices))
  842. *variation_name = rawhide_names[rawhide_indices[member]];
  843. break;
  844. case ST_DEC_TITAN:
  845. if (member < N(titan_indices))
  846. *variation_name = titan_names[titan_indices[member]];
  847. break;
  848. case ST_DEC_TSUNAMI:
  849. if (member < N(tsunami_indices))
  850. *variation_name = tsunami_names[tsunami_indices[member]];
  851. break;
  852. }
  853. }
  854. /*
  855.  * A change was made to the HWRPB via an ECO and the following code
  856.  * tracks a part of the ECO.  In HWRPB versions less than 5, the ECO
  857.  * was not implemented in the console firmware.  If it's revision 5 or
  858.  * greater we can get the name of the platform as an ASCII string from
  859.  * the HWRPB.  That's what this function does.  It checks the revision
  860.  * level and if the string is in the HWRPB it returns the address of
  861.  * the string--a pointer to the name of the platform.
  862.  *
  863.  * Returns:
  864.  *      - Pointer to a ASCII string if it's in the HWRPB
  865.  *      - Pointer to a blank string if the data is not in the HWRPB.
  866.  */
  867. static char *
  868. platform_string(void)
  869. {
  870. struct dsr_struct *dsr;
  871. static char unk_system_string[] = "N/A";
  872. /* Go to the console for the string pointer.
  873.  * If the rpb_vers is not 5 or greater the rpb
  874.  * is old and does not have this data in it.
  875.  */
  876. if (hwrpb->revision < 5)
  877. return (unk_system_string);
  878. else {
  879. /* The Dynamic System Recognition struct
  880.  * has the system platform name starting
  881.  * after the character count of the string.
  882.  */
  883. dsr =  ((struct dsr_struct *)
  884. ((char *)hwrpb + hwrpb->dsr_offset));
  885. return ((char *)dsr + (dsr->sysname_off +
  886.        sizeof(long)));
  887. }
  888. }
  889. static int
  890. get_nr_processors(struct percpu_struct *cpubase, unsigned long num)
  891. {
  892. struct percpu_struct *cpu;
  893. int i, count = 0;
  894. for (i = 0; i < num; i++) {
  895. cpu = (struct percpu_struct *)
  896. ((char *)cpubase + i*hwrpb->processor_size);
  897. if ((cpu->flags & 0x1cc) == 0x1cc)
  898. count++;
  899. }
  900. return count;
  901. }
  902. static int
  903. show_cpuinfo(struct seq_file *f, void *slot)
  904. {
  905. extern struct unaligned_stat {
  906. unsigned long count, va, pc;
  907. } unaligned[2];
  908. static char cpu_names[][8] = {
  909. "EV3", "EV4", "Simulate", "LCA4", "EV5", "EV45", "EV56",
  910. "EV6", "PCA56", "PCA57", "EV67", "EV68CB", "EV68AL",
  911. "EV68CX", "EV7", "EV79", "EV69"
  912. };
  913. struct percpu_struct *cpu = slot;
  914. unsigned int cpu_index;
  915. char *cpu_name;
  916. char *systype_name;
  917. char *sysvariation_name;
  918. int nr_processors;
  919. cpu_index = (unsigned) (cpu->type - 1);
  920. cpu_name = "Unknown";
  921. if (cpu_index < N(cpu_names))
  922. cpu_name = cpu_names[cpu_index];
  923. get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
  924.      cpu->type, &systype_name, &sysvariation_name);
  925. nr_processors = get_nr_processors(cpu, hwrpb->nr_processors);
  926. seq_printf(f, "cputtt: Alphan"
  927.       "cpu modeltt: %sn"
  928.       "cpu variationtt: %ldn"
  929.       "cpu revisiontt: %ldn"
  930.       "cpu serial numbert: %sn"
  931.       "system typett: %sn"
  932.       "system variationt: %sn"
  933.       "system revisiontt: %ldn"
  934.       "system serial numbert: %sn"
  935.       "cycle frequency [Hz]t: %lu %sn"
  936.       "timer frequency [Hz]t: %lu.%02lun"
  937.       "page size [bytes]t: %ldn"
  938.       "phys. address bitst: %ldn"
  939.       "max. addr. space #t: %ldn"
  940.       "BogoMIPStt: %lu.%02lun"
  941.       "kernel unaligned acct: %ld (pc=%lx,va=%lx)n"
  942.       "user unaligned acct: %ld (pc=%lx,va=%lx)n"
  943.       "platform stringtt: %sn"
  944.       "cpus detectedtt: %dn",
  945.        cpu_name, cpu->variation, cpu->revision,
  946.        (char*)cpu->serial_no,
  947.        systype_name, sysvariation_name, hwrpb->sys_revision,
  948.        (char*)hwrpb->ssn,
  949.        est_cycle_freq ? : hwrpb->cycle_freq,
  950.        est_cycle_freq ? "est." : "",
  951.        hwrpb->intr_freq / 4096,
  952.        (100 * hwrpb->intr_freq / 4096) % 100,
  953.        hwrpb->pagesize,
  954.        hwrpb->pa_bits,
  955.        hwrpb->max_asn,
  956.        loops_per_jiffy / (500000/HZ),
  957.        (loops_per_jiffy / (5000/HZ)) % 100,
  958.        unaligned[0].count, unaligned[0].pc, unaligned[0].va,
  959.        unaligned[1].count, unaligned[1].pc, unaligned[1].va,
  960.        platform_string(), nr_processors);
  961. #ifdef CONFIG_SMP
  962. seq_printf(f, "cpus activett: %dn"
  963.       "cpu active masktt: %016lxn",
  964.        smp_num_cpus, cpu_present_mask);
  965. #endif
  966. return 0;
  967. }
  968. /*
  969.  * We show only CPU #0 info.
  970.  */
  971. static void *
  972. c_start(struct seq_file *f, loff_t *pos)
  973. {
  974. return *pos ? NULL : (char *)hwrpb + hwrpb->processor_offset;
  975. }
  976. static void *
  977. c_next(struct seq_file *f, void *v, loff_t *pos)
  978. {
  979. return NULL;
  980. }
  981. static void
  982. c_stop(struct seq_file *f, void *v)
  983. {
  984. }
  985. struct seq_operations cpuinfo_op = {
  986. start: c_start,
  987. next: c_next,
  988. stop: c_stop,
  989. show: show_cpuinfo,
  990. };
  991. static int alpha_panic_event(struct notifier_block *this,
  992.      unsigned long event,
  993.      void *ptr)
  994. {
  995. #if 1
  996. /* FIXME FIXME FIXME */
  997. /* If we are using SRM and serial console, just hard halt here. */
  998. if (alpha_using_srm && srmcons_output)
  999. __halt();
  1000. #endif
  1001.         return NOTIFY_DONE;
  1002. }