setup.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1999,2001-2006 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/delay.h>
  11. #include <linux/kernel.h>
  12. #include <linux/kdev_t.h>
  13. #include <linux/string.h>
  14. #include <linux/screen_info.h>
  15. #include <linux/console.h>
  16. #include <linux/timex.h>
  17. #include <linux/sched.h>
  18. #include <linux/ioport.h>
  19. #include <linux/mm.h>
  20. #include <linux/serial.h>
  21. #include <linux/irq.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/mmzone.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/acpi.h>
  26. #include <linux/compiler.h>
  27. #include <linux/sched.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/nodemask.h>
  30. #include <linux/pm.h>
  31. #include <linux/efi.h>
  32. #include <asm/io.h>
  33. #include <asm/sal.h>
  34. #include <asm/machvec.h>
  35. #include <asm/system.h>
  36. #include <asm/processor.h>
  37. #include <asm/vga.h>
  38. #include <asm/sn/arch.h>
  39. #include <asm/sn/addrs.h>
  40. #include <asm/sn/pda.h>
  41. #include <asm/sn/nodepda.h>
  42. #include <asm/sn/sn_cpuid.h>
  43. #include <asm/sn/simulator.h>
  44. #include <asm/sn/leds.h>
  45. #include <asm/sn/bte.h>
  46. #include <asm/sn/shub_mmr.h>
  47. #include <asm/sn/clksupport.h>
  48. #include <asm/sn/sn_sal.h>
  49. #include <asm/sn/geo.h>
  50. #include <asm/sn/sn_feature_sets.h>
  51. #include "xtalk/xwidgetdev.h"
  52. #include "xtalk/hubdev.h"
  53. #include <asm/sn/klconfig.h>
  54. DEFINE_PER_CPU(struct pda_s, pda_percpu);
  55. #define MAX_PHYS_MEMORY (1UL << IA64_MAX_PHYS_BITS) /* Max physical address supported */
  56. extern void bte_init_node(nodepda_t *, cnodeid_t);
  57. extern void sn_timer_init(void);
  58. extern unsigned long last_time_offset;
  59. extern void (*ia64_mark_idle) (int);
  60. extern void snidle(int);
  61. extern unsigned long long (*ia64_printk_clock)(void);
  62. unsigned long sn_rtc_cycles_per_second;
  63. EXPORT_SYMBOL(sn_rtc_cycles_per_second);
  64. DEFINE_PER_CPU(struct sn_hub_info_s, __sn_hub_info);
  65. EXPORT_PER_CPU_SYMBOL(__sn_hub_info);
  66. DEFINE_PER_CPU(short, __sn_cnodeid_to_nasid[MAX_COMPACT_NODES]);
  67. EXPORT_PER_CPU_SYMBOL(__sn_cnodeid_to_nasid);
  68. DEFINE_PER_CPU(struct nodepda_s *, __sn_nodepda);
  69. EXPORT_PER_CPU_SYMBOL(__sn_nodepda);
  70. char sn_system_serial_number_string[128];
  71. EXPORT_SYMBOL(sn_system_serial_number_string);
  72. u64 sn_partition_serial_number;
  73. EXPORT_SYMBOL(sn_partition_serial_number);
  74. u8 sn_partition_id;
  75. EXPORT_SYMBOL(sn_partition_id);
  76. u8 sn_system_size;
  77. EXPORT_SYMBOL(sn_system_size);
  78. u8 sn_sharing_domain_size;
  79. EXPORT_SYMBOL(sn_sharing_domain_size);
  80. u8 sn_coherency_id;
  81. EXPORT_SYMBOL(sn_coherency_id);
  82. u8 sn_region_size;
  83. EXPORT_SYMBOL(sn_region_size);
  84. int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */
  85. short physical_node_map[MAX_NUMALINK_NODES];
  86. static unsigned long sn_prom_features[MAX_PROM_FEATURE_SETS];
  87. EXPORT_SYMBOL(physical_node_map);
  88. int num_cnodes;
  89. static void sn_init_pdas(char **);
  90. static void build_cnode_tables(void);
  91. static nodepda_t *nodepdaindr[MAX_COMPACT_NODES];
  92. /*
  93. * The format of "screen_info" is strange, and due to early i386-setup
  94. * code. This is just enough to make the console code think we're on a
  95. * VGA color display.
  96. */
  97. struct screen_info sn_screen_info = {
  98. .orig_x = 0,
  99. .orig_y = 0,
  100. .orig_video_mode = 3,
  101. .orig_video_cols = 80,
  102. .orig_video_ega_bx = 3,
  103. .orig_video_lines = 25,
  104. .orig_video_isVGA = 1,
  105. .orig_video_points = 16
  106. };
  107. /*
  108. * This routine can only be used during init, since
  109. * smp_boot_data is an init data structure.
  110. * We have to use smp_boot_data.cpu_phys_id to find
  111. * the physical id of the processor because the normal
  112. * cpu_physical_id() relies on data structures that
  113. * may not be initialized yet.
  114. */
  115. static int __init pxm_to_nasid(int pxm)
  116. {
  117. int i;
  118. int nid;
  119. nid = pxm_to_node(pxm);
  120. for (i = 0; i < num_node_memblks; i++) {
  121. if (node_memblk[i].nid == nid) {
  122. return NASID_GET(node_memblk[i].start_paddr);
  123. }
  124. }
  125. return -1;
  126. }
  127. /**
  128. * early_sn_setup - early setup routine for SN platforms
  129. *
  130. * Sets up an initial console to aid debugging. Intended primarily
  131. * for bringup. See start_kernel() in init/main.c.
  132. */
  133. void __init early_sn_setup(void)
  134. {
  135. efi_system_table_t *efi_systab;
  136. efi_config_table_t *config_tables;
  137. struct ia64_sal_systab *sal_systab;
  138. struct ia64_sal_desc_entry_point *ep;
  139. char *p;
  140. int i, j;
  141. /*
  142. * Parse enough of the SAL tables to locate the SAL entry point. Since, console
  143. * IO on SN2 is done via SAL calls, early_printk won't work without this.
  144. *
  145. * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
  146. * Any changes to those file may have to be made hereas well.
  147. */
  148. efi_systab = (efi_system_table_t *) __va(ia64_boot_param->efi_systab);
  149. config_tables = __va(efi_systab->tables);
  150. for (i = 0; i < efi_systab->nr_tables; i++) {
  151. if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) ==
  152. 0) {
  153. sal_systab = __va(config_tables[i].table);
  154. p = (char *)(sal_systab + 1);
  155. for (j = 0; j < sal_systab->entry_count; j++) {
  156. if (*p == SAL_DESC_ENTRY_POINT) {
  157. ep = (struct ia64_sal_desc_entry_point
  158. *)p;
  159. ia64_sal_handler_init(__va
  160. (ep->sal_proc),
  161. __va(ep->gp));
  162. return;
  163. }
  164. p += SAL_DESC_SIZE(*p);
  165. }
  166. }
  167. }
  168. /* Uh-oh, SAL not available?? */
  169. printk(KERN_ERR "failed to find SAL entry point\n");
  170. }
  171. extern int platform_intr_list[];
  172. static int __initdata shub_1_1_found;
  173. /*
  174. * sn_check_for_wars
  175. *
  176. * Set flag for enabling shub specific wars
  177. */
  178. static inline int __init is_shub_1_1(int nasid)
  179. {
  180. unsigned long id;
  181. int rev;
  182. if (is_shub2())
  183. return 0;
  184. id = REMOTE_HUB_L(nasid, SH1_SHUB_ID);
  185. rev = (id & SH1_SHUB_ID_REVISION_MASK) >> SH1_SHUB_ID_REVISION_SHFT;
  186. return rev <= 2;
  187. }
  188. static void __init sn_check_for_wars(void)
  189. {
  190. int cnode;
  191. if (is_shub2()) {
  192. /* none yet */
  193. } else {
  194. for_each_online_node(cnode) {
  195. if (is_shub_1_1(cnodeid_to_nasid(cnode)))
  196. shub_1_1_found = 1;
  197. }
  198. }
  199. }
  200. /*
  201. * Scan the EFI PCDP table (if it exists) for an acceptable VGA console
  202. * output device. If one exists, pick it and set sn_legacy_{io,mem} to
  203. * reflect the bus offsets needed to address it.
  204. *
  205. * Since pcdp support in SN is not supported in the 2.4 kernel (or at least
  206. * the one lbs is based on) just declare the needed structs here.
  207. *
  208. * Reference spec http://www.dig64.org/specifications/DIG64_PCDPv20.pdf
  209. *
  210. * Returns 0 if no acceptable vga is found, !0 otherwise.
  211. *
  212. * Note: This stuff is duped here because Altix requires the PCDP to
  213. * locate a usable VGA device due to lack of proper ACPI support. Structures
  214. * could be used from drivers/firmware/pcdp.h, but it was decided that moving
  215. * this file to a more public location just for Altix use was undesireable.
  216. */
  217. struct hcdp_uart_desc {
  218. u8 pad[45];
  219. };
  220. struct pcdp {
  221. u8 signature[4]; /* should be 'HCDP' */
  222. u32 length;
  223. u8 rev; /* should be >=3 for pcdp, <3 for hcdp */
  224. u8 sum;
  225. u8 oem_id[6];
  226. u64 oem_tableid;
  227. u32 oem_rev;
  228. u32 creator_id;
  229. u32 creator_rev;
  230. u32 num_type0;
  231. struct hcdp_uart_desc uart[0]; /* num_type0 of these */
  232. /* pcdp descriptors follow */
  233. } __attribute__((packed));
  234. struct pcdp_device_desc {
  235. u8 type;
  236. u8 primary;
  237. u16 length;
  238. u16 index;
  239. /* interconnect specific structure follows */
  240. /* device specific structure follows that */
  241. } __attribute__((packed));
  242. struct pcdp_interface_pci {
  243. u8 type; /* 1 == pci */
  244. u8 reserved;
  245. u16 length;
  246. u8 segment;
  247. u8 bus;
  248. u8 dev;
  249. u8 fun;
  250. u16 devid;
  251. u16 vendid;
  252. u32 acpi_interrupt;
  253. u64 mmio_tra;
  254. u64 ioport_tra;
  255. u8 flags;
  256. u8 translation;
  257. } __attribute__((packed));
  258. struct pcdp_vga_device {
  259. u8 num_eas_desc;
  260. /* ACPI Extended Address Space Desc follows */
  261. } __attribute__((packed));
  262. /* from pcdp_device_desc.primary */
  263. #define PCDP_PRIMARY_CONSOLE 0x01
  264. /* from pcdp_device_desc.type */
  265. #define PCDP_CONSOLE_INOUT 0x0
  266. #define PCDP_CONSOLE_DEBUG 0x1
  267. #define PCDP_CONSOLE_OUT 0x2
  268. #define PCDP_CONSOLE_IN 0x3
  269. #define PCDP_CONSOLE_TYPE_VGA 0x8
  270. #define PCDP_CONSOLE_VGA (PCDP_CONSOLE_TYPE_VGA | PCDP_CONSOLE_OUT)
  271. /* from pcdp_interface_pci.type */
  272. #define PCDP_IF_PCI 1
  273. /* from pcdp_interface_pci.translation */
  274. #define PCDP_PCI_TRANS_IOPORT 0x02
  275. #define PCDP_PCI_TRANS_MMIO 0x01
  276. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  277. static void
  278. sn_scan_pcdp(void)
  279. {
  280. u8 *bp;
  281. struct pcdp *pcdp;
  282. struct pcdp_device_desc device;
  283. struct pcdp_interface_pci if_pci;
  284. extern struct efi efi;
  285. if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
  286. return; /* no hcdp/pcdp table */
  287. pcdp = __va(efi.hcdp);
  288. if (pcdp->rev < 3)
  289. return; /* only support PCDP (rev >= 3) */
  290. for (bp = (u8 *)&pcdp->uart[pcdp->num_type0];
  291. bp < (u8 *)pcdp + pcdp->length;
  292. bp += device.length) {
  293. memcpy(&device, bp, sizeof(device));
  294. if (! (device.primary & PCDP_PRIMARY_CONSOLE))
  295. continue; /* not primary console */
  296. if (device.type != PCDP_CONSOLE_VGA)
  297. continue; /* not VGA descriptor */
  298. memcpy(&if_pci, bp+sizeof(device), sizeof(if_pci));
  299. if (if_pci.type != PCDP_IF_PCI)
  300. continue; /* not PCI interconnect */
  301. if (if_pci.translation & PCDP_PCI_TRANS_IOPORT)
  302. vga_console_iobase = if_pci.ioport_tra;
  303. if (if_pci.translation & PCDP_PCI_TRANS_MMIO)
  304. vga_console_membase =
  305. if_pci.mmio_tra | __IA64_UNCACHED_OFFSET;
  306. break; /* once we find the primary, we're done */
  307. }
  308. }
  309. #endif
  310. static unsigned long sn2_rtc_initial;
  311. static unsigned long long ia64_sn2_printk_clock(void)
  312. {
  313. unsigned long rtc_now = rtc_time();
  314. return (rtc_now - sn2_rtc_initial) *
  315. (1000000000 / sn_rtc_cycles_per_second);
  316. }
  317. /**
  318. * sn_setup - SN platform setup routine
  319. * @cmdline_p: kernel command line
  320. *
  321. * Handles platform setup for SN machines. This includes determining
  322. * the RTC frequency (via a SAL call), initializing secondary CPUs, and
  323. * setting up per-node data areas. The console is also initialized here.
  324. */
  325. void __init sn_setup(char **cmdline_p)
  326. {
  327. long status, ticks_per_sec, drift;
  328. u32 version = sn_sal_rev();
  329. extern void sn_cpu_init(void);
  330. sn2_rtc_initial = rtc_time();
  331. ia64_sn_plat_set_error_handling_features(); // obsolete
  332. ia64_sn_set_os_feature(OSF_MCA_SLV_TO_OS_INIT_SLV);
  333. ia64_sn_set_os_feature(OSF_FEAT_LOG_SBES);
  334. /*
  335. * Note: The calls to notify the PROM of ACPI and PCI Segment
  336. * support must be done prior to acpi_load_tables(), as
  337. * an ACPI capable PROM will rebuild the DSDT as result
  338. * of the call.
  339. */
  340. ia64_sn_set_os_feature(OSF_PCISEGMENT_ENABLE);
  341. ia64_sn_set_os_feature(OSF_ACPI_ENABLE);
  342. /* Load the new DSDT and SSDT tables into the global table list. */
  343. acpi_table_init();
  344. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  345. /*
  346. * Handle SN vga console.
  347. *
  348. * SN systems do not have enough ACPI table information
  349. * being passed from prom to identify VGA adapters and the legacy
  350. * addresses to access them. Until that is done, SN systems rely
  351. * on the PCDP table to identify the primary VGA console if one
  352. * exists.
  353. *
  354. * However, kernel PCDP support is optional, and even if it is built
  355. * into the kernel, it will not be used if the boot cmdline contains
  356. * console= directives.
  357. *
  358. * So, to work around this mess, we duplicate some of the PCDP code
  359. * here so that the primary VGA console (as defined by PCDP) will
  360. * work on SN systems even if a different console (e.g. serial) is
  361. * selected on the boot line (or CONFIG_EFI_PCDP is off).
  362. */
  363. if (! vga_console_membase)
  364. sn_scan_pcdp();
  365. /*
  366. * Setup legacy IO space.
  367. * vga_console_iobase maps to PCI IO Space address 0 on the
  368. * bus containing the VGA console.
  369. */
  370. if (vga_console_iobase) {
  371. io_space[0].mmio_base =
  372. (unsigned long) ioremap(vga_console_iobase, 0);
  373. io_space[0].sparse = 0;
  374. }
  375. if (vga_console_membase) {
  376. /* usable vga ... make tty0 the preferred default console */
  377. if (!strstr(*cmdline_p, "console="))
  378. add_preferred_console("tty", 0, NULL);
  379. } else {
  380. printk(KERN_DEBUG "SGI: Disabling VGA console\n");
  381. if (!strstr(*cmdline_p, "console="))
  382. add_preferred_console("ttySG", 0, NULL);
  383. #ifdef CONFIG_DUMMY_CONSOLE
  384. conswitchp = &dummy_con;
  385. #else
  386. conswitchp = NULL;
  387. #endif /* CONFIG_DUMMY_CONSOLE */
  388. }
  389. #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
  390. MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
  391. /*
  392. * Build the tables for managing cnodes.
  393. */
  394. build_cnode_tables();
  395. status =
  396. ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec,
  397. &drift);
  398. if (status != 0 || ticks_per_sec < 100000) {
  399. printk(KERN_WARNING
  400. "unable to determine platform RTC clock frequency, guessing.\n");
  401. /* PROM gives wrong value for clock freq. so guess */
  402. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  403. } else
  404. sn_rtc_cycles_per_second = ticks_per_sec;
  405. platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
  406. ia64_printk_clock = ia64_sn2_printk_clock;
  407. printk("SGI SAL version %x.%02x\n", version >> 8, version & 0x00FF);
  408. /*
  409. * we set the default root device to /dev/hda
  410. * to make simulation easy
  411. */
  412. ROOT_DEV = Root_HDA1;
  413. /*
  414. * Create the PDAs and NODEPDAs for all the cpus.
  415. */
  416. sn_init_pdas(cmdline_p);
  417. ia64_mark_idle = &snidle;
  418. /*
  419. * For the bootcpu, we do this here. All other cpus will make the
  420. * call as part of cpu_init in slave cpu initialization.
  421. */
  422. sn_cpu_init();
  423. #ifdef CONFIG_SMP
  424. init_smp_config();
  425. #endif
  426. screen_info = sn_screen_info;
  427. sn_timer_init();
  428. /*
  429. * set pm_power_off to a SAL call to allow
  430. * sn machines to power off. The SAL call can be replaced
  431. * by an ACPI interface call when ACPI is fully implemented
  432. * for sn.
  433. */
  434. pm_power_off = ia64_sn_power_down;
  435. current->thread.flags |= IA64_THREAD_MIGRATION;
  436. }
  437. /**
  438. * sn_init_pdas - setup node data areas
  439. *
  440. * One time setup for Node Data Area. Called by sn_setup().
  441. */
  442. static void __init sn_init_pdas(char **cmdline_p)
  443. {
  444. cnodeid_t cnode;
  445. /*
  446. * Allocate & initalize the nodepda for each node.
  447. */
  448. for_each_online_node(cnode) {
  449. nodepdaindr[cnode] =
  450. alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
  451. memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
  452. memset(nodepdaindr[cnode]->phys_cpuid, -1,
  453. sizeof(nodepdaindr[cnode]->phys_cpuid));
  454. spin_lock_init(&nodepdaindr[cnode]->ptc_lock);
  455. }
  456. /*
  457. * Allocate & initialize nodepda for TIOs. For now, put them on node 0.
  458. */
  459. for (cnode = num_online_nodes(); cnode < num_cnodes; cnode++) {
  460. nodepdaindr[cnode] =
  461. alloc_bootmem_node(NODE_DATA(0), sizeof(nodepda_t));
  462. memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
  463. }
  464. /*
  465. * Now copy the array of nodepda pointers to each nodepda.
  466. */
  467. for (cnode = 0; cnode < num_cnodes; cnode++)
  468. memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr,
  469. sizeof(nodepdaindr));
  470. /*
  471. * Set up IO related platform-dependent nodepda fields.
  472. * The following routine actually sets up the hubinfo struct
  473. * in nodepda.
  474. */
  475. for_each_online_node(cnode) {
  476. bte_init_node(nodepdaindr[cnode], cnode);
  477. }
  478. /*
  479. * Initialize the per node hubdev. This includes IO Nodes and
  480. * headless/memless nodes.
  481. */
  482. for (cnode = 0; cnode < num_cnodes; cnode++) {
  483. hubdev_init_node(nodepdaindr[cnode], cnode);
  484. }
  485. }
  486. /**
  487. * sn_cpu_init - initialize per-cpu data areas
  488. * @cpuid: cpuid of the caller
  489. *
  490. * Called during cpu initialization on each cpu as it starts.
  491. * Currently, initializes the per-cpu data area for SNIA.
  492. * Also sets up a few fields in the nodepda. Also known as
  493. * platform_cpu_init() by the ia64 machvec code.
  494. */
  495. void __cpuinit sn_cpu_init(void)
  496. {
  497. int cpuid;
  498. int cpuphyid;
  499. int nasid;
  500. int subnode;
  501. int slice;
  502. int cnode;
  503. int i;
  504. static int wars_have_been_checked, set_cpu0_number;
  505. cpuid = smp_processor_id();
  506. if (cpuid == 0 && IS_MEDUSA()) {
  507. if (ia64_sn_is_fake_prom())
  508. sn_prom_type = 2;
  509. else
  510. sn_prom_type = 1;
  511. printk(KERN_INFO "Running on medusa with %s PROM\n",
  512. (sn_prom_type == 1) ? "real" : "fake");
  513. }
  514. memset(pda, 0, sizeof(pda));
  515. if (ia64_sn_get_sn_info(0, &sn_hub_info->shub2,
  516. &sn_hub_info->nasid_bitmask,
  517. &sn_hub_info->nasid_shift,
  518. &sn_system_size, &sn_sharing_domain_size,
  519. &sn_partition_id, &sn_coherency_id,
  520. &sn_region_size))
  521. BUG();
  522. sn_hub_info->as_shift = sn_hub_info->nasid_shift - 2;
  523. /*
  524. * Don't check status. The SAL call is not supported on all PROMs
  525. * but a failure is harmless.
  526. * Architechtuallly, cpu_init is always called twice on cpu 0. We
  527. * should set cpu_number on cpu 0 once.
  528. */
  529. if (cpuid == 0) {
  530. if (!set_cpu0_number) {
  531. (void) ia64_sn_set_cpu_number(cpuid);
  532. set_cpu0_number = 1;
  533. }
  534. } else
  535. (void) ia64_sn_set_cpu_number(cpuid);
  536. /*
  537. * The boot cpu makes this call again after platform initialization is
  538. * complete.
  539. */
  540. if (nodepdaindr[0] == NULL)
  541. return;
  542. for (i = 0; i < MAX_PROM_FEATURE_SETS; i++)
  543. if (ia64_sn_get_prom_feature_set(i, &sn_prom_features[i]) != 0)
  544. break;
  545. cpuphyid = get_sapicid();
  546. if (ia64_sn_get_sapic_info(cpuphyid, &nasid, &subnode, &slice))
  547. BUG();
  548. for (i=0; i < MAX_NUMNODES; i++) {
  549. if (nodepdaindr[i]) {
  550. nodepdaindr[i]->phys_cpuid[cpuid].nasid = nasid;
  551. nodepdaindr[i]->phys_cpuid[cpuid].slice = slice;
  552. nodepdaindr[i]->phys_cpuid[cpuid].subnode = subnode;
  553. }
  554. }
  555. cnode = nasid_to_cnodeid(nasid);
  556. sn_nodepda = nodepdaindr[cnode];
  557. pda->led_address =
  558. (typeof(pda->led_address)) (LED0 + (slice << LED_CPU_SHIFT));
  559. pda->led_state = LED_ALWAYS_SET;
  560. pda->hb_count = HZ / 2;
  561. pda->hb_state = 0;
  562. pda->idle_flag = 0;
  563. if (cpuid != 0) {
  564. /* copy cpu 0's sn_cnodeid_to_nasid table to this cpu's */
  565. memcpy(sn_cnodeid_to_nasid,
  566. (&per_cpu(__sn_cnodeid_to_nasid, 0)),
  567. sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
  568. }
  569. /*
  570. * Check for WARs.
  571. * Only needs to be done once, on BSP.
  572. * Has to be done after loop above, because it uses this cpu's
  573. * sn_cnodeid_to_nasid table which was just initialized if this
  574. * isn't cpu 0.
  575. * Has to be done before assignment below.
  576. */
  577. if (!wars_have_been_checked) {
  578. sn_check_for_wars();
  579. wars_have_been_checked = 1;
  580. }
  581. sn_hub_info->shub_1_1_found = shub_1_1_found;
  582. /*
  583. * Set up addresses of PIO/MEM write status registers.
  584. */
  585. {
  586. u64 pio1[] = {SH1_PIO_WRITE_STATUS_0, 0, SH1_PIO_WRITE_STATUS_1, 0};
  587. u64 pio2[] = {SH2_PIO_WRITE_STATUS_0, SH2_PIO_WRITE_STATUS_2,
  588. SH2_PIO_WRITE_STATUS_1, SH2_PIO_WRITE_STATUS_3};
  589. u64 *pio;
  590. pio = is_shub1() ? pio1 : pio2;
  591. pda->pio_write_status_addr =
  592. (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid, pio[slice]);
  593. pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
  594. }
  595. /*
  596. * WAR addresses for SHUB 1.x.
  597. */
  598. if (local_node_data->active_cpu_count++ == 0 && is_shub1()) {
  599. int buddy_nasid;
  600. buddy_nasid =
  601. cnodeid_to_nasid(numa_node_id() ==
  602. num_online_nodes() - 1 ? 0 : numa_node_id() + 1);
  603. pda->pio_shub_war_cam_addr =
  604. (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid,
  605. SH1_PI_CAM_CONTROL);
  606. }
  607. }
  608. /*
  609. * Build tables for converting between NASIDs and cnodes.
  610. */
  611. static inline int __init board_needs_cnode(int type)
  612. {
  613. return (type == KLTYPE_SNIA || type == KLTYPE_TIO);
  614. }
  615. void __init build_cnode_tables(void)
  616. {
  617. int nasid;
  618. int node;
  619. lboard_t *brd;
  620. memset(physical_node_map, -1, sizeof(physical_node_map));
  621. memset(sn_cnodeid_to_nasid, -1,
  622. sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
  623. /*
  624. * First populate the tables with C/M bricks. This ensures that
  625. * cnode == node for all C & M bricks.
  626. */
  627. for_each_online_node(node) {
  628. nasid = pxm_to_nasid(node_to_pxm(node));
  629. sn_cnodeid_to_nasid[node] = nasid;
  630. physical_node_map[nasid] = node;
  631. }
  632. /*
  633. * num_cnodes is total number of C/M/TIO bricks. Because of the 256 node
  634. * limit on the number of nodes, we can't use the generic node numbers
  635. * for this. Note that num_cnodes is incremented below as TIOs or
  636. * headless/memoryless nodes are discovered.
  637. */
  638. num_cnodes = num_online_nodes();
  639. /* fakeprom does not support klgraph */
  640. if (IS_RUNNING_ON_FAKE_PROM())
  641. return;
  642. /* Find TIOs & headless/memoryless nodes and add them to the tables */
  643. for_each_online_node(node) {
  644. kl_config_hdr_t *klgraph_header;
  645. nasid = cnodeid_to_nasid(node);
  646. klgraph_header = ia64_sn_get_klconfig_addr(nasid);
  647. if (klgraph_header == NULL)
  648. BUG();
  649. brd = NODE_OFFSET_TO_LBOARD(nasid, klgraph_header->ch_board_info);
  650. while (brd) {
  651. if (board_needs_cnode(brd->brd_type) && physical_node_map[brd->brd_nasid] < 0) {
  652. sn_cnodeid_to_nasid[num_cnodes] = brd->brd_nasid;
  653. physical_node_map[brd->brd_nasid] = num_cnodes++;
  654. }
  655. brd = find_lboard_next(brd);
  656. }
  657. }
  658. }
  659. int
  660. nasid_slice_to_cpuid(int nasid, int slice)
  661. {
  662. long cpu;
  663. for (cpu = 0; cpu < NR_CPUS; cpu++)
  664. if (cpuid_to_nasid(cpu) == nasid &&
  665. cpuid_to_slice(cpu) == slice)
  666. return cpu;
  667. return -1;
  668. }
  669. int sn_prom_feature_available(int id)
  670. {
  671. if (id >= BITS_PER_LONG * MAX_PROM_FEATURE_SETS)
  672. return 0;
  673. return test_bit(id, sn_prom_features);
  674. }
  675. void
  676. sn_kernel_launch_event(void)
  677. {
  678. /* ignore status until we understand possible failure, if any*/
  679. if (ia64_sn_kernel_launch_event())
  680. printk(KERN_ERR "KEXEC is not supported in this PROM, Please update the PROM.\n");
  681. }
  682. EXPORT_SYMBOL(sn_prom_feature_available);