setup.c 20 KB

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