setup.c 20 KB

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