blob: 1f38a3a68390f0502a04c2a3fca273b37e7d3a7d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Brent Casavante08e6c52006-01-26 15:55:52 -08006 * Copyright (C) 1999,2001-2006 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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>
Jon Smirl894673e2006-07-10 04:44:13 -070015#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/root_dev.h>
29#include <linux/nodemask.h>
Aaron J Youngc1298c52005-04-25 13:11:14 -070030#include <linux/pm.h>
Mark Mauleff512242005-11-11 11:52:43 -060031#include <linux/efi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
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>
Mark Maulea9f9de72005-04-26 08:01:00 -070038#include <asm/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#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>
Jack Steinera1cddb82005-08-31 08:05:00 -070051#include <asm/sn/sn_feature_sets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "xtalk/xwidgetdev.h"
53#include "xtalk/hubdev.h"
54#include <asm/sn/klconfig.h>
55
56
57DEFINE_PER_CPU(struct pda_s, pda_percpu);
58
Jack Steiner9b17e7e2005-09-08 15:28:28 -050059#define MAX_PHYS_MEMORY (1UL << IA64_MAX_PHYS_BITS) /* Max physical address supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061extern void bte_init_node(nodepda_t *, cnodeid_t);
62
63extern void sn_timer_init(void);
64extern unsigned long last_time_offset;
65extern void (*ia64_mark_idle) (int);
66extern void snidle(int);
Tony Luckd6e56a22006-02-07 15:25:57 -080067extern unsigned long long (*ia64_printk_clock)(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69unsigned long sn_rtc_cycles_per_second;
70EXPORT_SYMBOL(sn_rtc_cycles_per_second);
71
72DEFINE_PER_CPU(struct sn_hub_info_s, __sn_hub_info);
73EXPORT_PER_CPU_SYMBOL(__sn_hub_info);
74
Dean Roec2a49692006-02-14 15:01:23 -060075DEFINE_PER_CPU(short, __sn_cnodeid_to_nasid[MAX_COMPACT_NODES]);
Dean Nelson2e34f072005-03-21 19:41:00 -070076EXPORT_PER_CPU_SYMBOL(__sn_cnodeid_to_nasid);
77
Dean Nelson9b48b462005-03-22 16:00:00 -070078DEFINE_PER_CPU(struct nodepda_s *, __sn_nodepda);
79EXPORT_PER_CPU_SYMBOL(__sn_nodepda);
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081char sn_system_serial_number_string[128];
82EXPORT_SYMBOL(sn_system_serial_number_string);
83u64 sn_partition_serial_number;
84EXPORT_SYMBOL(sn_partition_serial_number);
85u8 sn_partition_id;
86EXPORT_SYMBOL(sn_partition_id);
87u8 sn_system_size;
88EXPORT_SYMBOL(sn_system_size);
89u8 sn_sharing_domain_size;
90EXPORT_SYMBOL(sn_sharing_domain_size);
91u8 sn_coherency_id;
92EXPORT_SYMBOL(sn_coherency_id);
93u8 sn_region_size;
94EXPORT_SYMBOL(sn_region_size);
Jack Steiner71a5d022005-05-10 08:01:00 -070095int sn_prom_type; /* 0=hardware, 1=medusa/realprom, 2=medusa/fakeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Jack Steiner24ee0a62005-09-12 12:15:43 -050097short physical_node_map[MAX_NUMALINK_NODES];
Jack Steinera1cddb82005-08-31 08:05:00 -070098static unsigned long sn_prom_features[MAX_PROM_FEATURE_SETS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100EXPORT_SYMBOL(physical_node_map);
101
Jack Steiner24ee0a62005-09-12 12:15:43 -0500102int num_cnodes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104static void sn_init_pdas(char **);
Jack Steiner24ee0a62005-09-12 12:15:43 -0500105static void build_cnode_tables(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static nodepda_t *nodepdaindr[MAX_COMPACT_NODES];
108
109/*
110 * The format of "screen_info" is strange, and due to early i386-setup
111 * code. This is just enough to make the console code think we're on a
112 * VGA color display.
113 */
114struct screen_info sn_screen_info = {
115 .orig_x = 0,
116 .orig_y = 0,
117 .orig_video_mode = 3,
118 .orig_video_cols = 80,
119 .orig_video_ega_bx = 3,
120 .orig_video_lines = 25,
121 .orig_video_isVGA = 1,
122 .orig_video_points = 16
123};
124
125/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 * This routine can only be used during init, since
127 * smp_boot_data is an init data structure.
128 * We have to use smp_boot_data.cpu_phys_id to find
129 * the physical id of the processor because the normal
130 * cpu_physical_id() relies on data structures that
131 * may not be initialized yet.
132 */
133
134static int __init pxm_to_nasid(int pxm)
135{
136 int i;
137 int nid;
138
Yasunori Goto762834e2006-06-23 02:03:19 -0700139 nid = pxm_to_node(pxm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 for (i = 0; i < num_node_memblks; i++) {
141 if (node_memblk[i].nid == nid) {
142 return NASID_GET(node_memblk[i].start_paddr);
143 }
144 }
145 return -1;
146}
147
148/**
149 * early_sn_setup - early setup routine for SN platforms
150 *
151 * Sets up an initial console to aid debugging. Intended primarily
152 * for bringup. See start_kernel() in init/main.c.
153 */
154
155void __init early_sn_setup(void)
156{
157 efi_system_table_t *efi_systab;
158 efi_config_table_t *config_tables;
159 struct ia64_sal_systab *sal_systab;
160 struct ia64_sal_desc_entry_point *ep;
161 char *p;
162 int i, j;
163
164 /*
165 * Parse enough of the SAL tables to locate the SAL entry point. Since, console
166 * IO on SN2 is done via SAL calls, early_printk won't work without this.
167 *
168 * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700169 * Any changes to those file may have to be made here as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
171 efi_systab = (efi_system_table_t *) __va(ia64_boot_param->efi_systab);
172 config_tables = __va(efi_systab->tables);
173 for (i = 0; i < efi_systab->nr_tables; i++) {
174 if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) ==
175 0) {
176 sal_systab = __va(config_tables[i].table);
177 p = (char *)(sal_systab + 1);
178 for (j = 0; j < sal_systab->entry_count; j++) {
179 if (*p == SAL_DESC_ENTRY_POINT) {
180 ep = (struct ia64_sal_desc_entry_point
181 *)p;
182 ia64_sal_handler_init(__va
183 (ep->sal_proc),
184 __va(ep->gp));
185 return;
186 }
187 p += SAL_DESC_SIZE(*p);
188 }
189 }
190 }
191 /* Uh-oh, SAL not available?? */
192 printk(KERN_ERR "failed to find SAL entry point\n");
193}
194
195extern int platform_intr_list[];
Tony Lucka8c8be02007-05-18 15:11:34 -0700196static int __cpuinitdata shub_1_1_found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198/*
199 * sn_check_for_wars
200 *
201 * Set flag for enabling shub specific wars
202 */
203
204static inline int __init is_shub_1_1(int nasid)
205{
206 unsigned long id;
207 int rev;
208
209 if (is_shub2())
210 return 0;
211 id = REMOTE_HUB_L(nasid, SH1_SHUB_ID);
212 rev = (id & SH1_SHUB_ID_REVISION_MASK) >> SH1_SHUB_ID_REVISION_SHFT;
213 return rev <= 2;
214}
215
216static void __init sn_check_for_wars(void)
217{
218 int cnode;
219
220 if (is_shub2()) {
221 /* none yet */
222 } else {
223 for_each_online_node(cnode) {
224 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
Dean Nelsonff89bf32005-06-03 05:25:00 -0700225 shub_1_1_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227 }
228}
229
Mark Mauleff512242005-11-11 11:52:43 -0600230/*
231 * Scan the EFI PCDP table (if it exists) for an acceptable VGA console
232 * output device. If one exists, pick it and set sn_legacy_{io,mem} to
233 * reflect the bus offsets needed to address it.
234 *
235 * Since pcdp support in SN is not supported in the 2.4 kernel (or at least
236 * the one lbs is based on) just declare the needed structs here.
237 *
238 * Reference spec http://www.dig64.org/specifications/DIG64_PCDPv20.pdf
239 *
240 * Returns 0 if no acceptable vga is found, !0 otherwise.
241 *
242 * Note: This stuff is duped here because Altix requires the PCDP to
243 * locate a usable VGA device due to lack of proper ACPI support. Structures
244 * could be used from drivers/firmware/pcdp.h, but it was decided that moving
245 * this file to a more public location just for Altix use was undesireable.
246 */
247
248struct hcdp_uart_desc {
249 u8 pad[45];
250};
251
252struct pcdp {
253 u8 signature[4]; /* should be 'HCDP' */
254 u32 length;
255 u8 rev; /* should be >=3 for pcdp, <3 for hcdp */
256 u8 sum;
257 u8 oem_id[6];
258 u64 oem_tableid;
259 u32 oem_rev;
260 u32 creator_id;
261 u32 creator_rev;
262 u32 num_type0;
263 struct hcdp_uart_desc uart[0]; /* num_type0 of these */
264 /* pcdp descriptors follow */
265} __attribute__((packed));
266
267struct pcdp_device_desc {
268 u8 type;
269 u8 primary;
270 u16 length;
271 u16 index;
272 /* interconnect specific structure follows */
273 /* device specific structure follows that */
274} __attribute__((packed));
275
276struct pcdp_interface_pci {
277 u8 type; /* 1 == pci */
278 u8 reserved;
279 u16 length;
280 u8 segment;
281 u8 bus;
282 u8 dev;
283 u8 fun;
284 u16 devid;
285 u16 vendid;
286 u32 acpi_interrupt;
287 u64 mmio_tra;
288 u64 ioport_tra;
289 u8 flags;
290 u8 translation;
291} __attribute__((packed));
292
293struct pcdp_vga_device {
294 u8 num_eas_desc;
295 /* ACPI Extended Address Space Desc follows */
296} __attribute__((packed));
297
298/* from pcdp_device_desc.primary */
299#define PCDP_PRIMARY_CONSOLE 0x01
300
301/* from pcdp_device_desc.type */
302#define PCDP_CONSOLE_INOUT 0x0
303#define PCDP_CONSOLE_DEBUG 0x1
304#define PCDP_CONSOLE_OUT 0x2
305#define PCDP_CONSOLE_IN 0x3
306#define PCDP_CONSOLE_TYPE_VGA 0x8
307
308#define PCDP_CONSOLE_VGA (PCDP_CONSOLE_TYPE_VGA | PCDP_CONSOLE_OUT)
309
310/* from pcdp_interface_pci.type */
311#define PCDP_IF_PCI 1
312
313/* from pcdp_interface_pci.translation */
314#define PCDP_PCI_TRANS_IOPORT 0x02
315#define PCDP_PCI_TRANS_MMIO 0x01
316
Jes Sorensen26d10912006-02-13 05:35:01 -0500317#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
Mark Mauleff512242005-11-11 11:52:43 -0600318static void
319sn_scan_pcdp(void)
320{
321 u8 *bp;
322 struct pcdp *pcdp;
323 struct pcdp_device_desc device;
324 struct pcdp_interface_pci if_pci;
325 extern struct efi efi;
326
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800327 if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
Mark Mauleff512242005-11-11 11:52:43 -0600328 return; /* no hcdp/pcdp table */
329
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800330 pcdp = __va(efi.hcdp);
331
Mark Mauleff512242005-11-11 11:52:43 -0600332 if (pcdp->rev < 3)
333 return; /* only support PCDP (rev >= 3) */
334
335 for (bp = (u8 *)&pcdp->uart[pcdp->num_type0];
336 bp < (u8 *)pcdp + pcdp->length;
337 bp += device.length) {
338 memcpy(&device, bp, sizeof(device));
339 if (! (device.primary & PCDP_PRIMARY_CONSOLE))
340 continue; /* not primary console */
341
342 if (device.type != PCDP_CONSOLE_VGA)
343 continue; /* not VGA descriptor */
344
345 memcpy(&if_pci, bp+sizeof(device), sizeof(if_pci));
346 if (if_pci.type != PCDP_IF_PCI)
347 continue; /* not PCI interconnect */
348
349 if (if_pci.translation & PCDP_PCI_TRANS_IOPORT)
John Keller0bdfc192007-03-20 13:50:10 -0500350 vga_console_iobase = if_pci.ioport_tra;
Mark Mauleff512242005-11-11 11:52:43 -0600351
352 if (if_pci.translation & PCDP_PCI_TRANS_MMIO)
353 vga_console_membase =
354 if_pci.mmio_tra | __IA64_UNCACHED_OFFSET;
355
356 break; /* once we find the primary, we're done */
357 }
358}
Jes Sorensen26d10912006-02-13 05:35:01 -0500359#endif
Mark Mauleff512242005-11-11 11:52:43 -0600360
Tony Luckd6e56a22006-02-07 15:25:57 -0800361static unsigned long sn2_rtc_initial;
362
363static unsigned long long ia64_sn2_printk_clock(void)
364{
365 unsigned long rtc_now = rtc_time();
366
367 return (rtc_now - sn2_rtc_initial) *
368 (1000000000 / sn_rtc_cycles_per_second);
369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371/**
372 * sn_setup - SN platform setup routine
373 * @cmdline_p: kernel command line
374 *
375 * Handles platform setup for SN machines. This includes determining
376 * the RTC frequency (via a SAL call), initializing secondary CPUs, and
377 * setting up per-node data areas. The console is also initialized here.
378 */
379void __init sn_setup(char **cmdline_p)
380{
381 long status, ticks_per_sec, drift;
Prarit Bhargava283c7f62005-07-06 15:29:13 -0700382 u32 version = sn_sal_rev();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 extern void sn_cpu_init(void);
384
Tony Luckd6e56a22006-02-07 15:25:57 -0800385 sn2_rtc_initial = rtc_time();
Jack Steinera1cddb82005-08-31 08:05:00 -0700386 ia64_sn_plat_set_error_handling_features(); // obsolete
387 ia64_sn_set_os_feature(OSF_MCA_SLV_TO_OS_INIT_SLV);
388 ia64_sn_set_os_feature(OSF_FEAT_LOG_SBES);
John Keller8ea60912006-10-04 16:49:25 -0500389 /*
390 * Note: The calls to notify the PROM of ACPI and PCI Segment
391 * support must be done prior to acpi_load_tables(), as
392 * an ACPI capable PROM will rebuild the DSDT as result
393 * of the call.
394 */
395 ia64_sn_set_os_feature(OSF_PCISEGMENT_ENABLE);
396 ia64_sn_set_os_feature(OSF_ACPI_ENABLE);
Jack Steinera1cddb82005-08-31 08:05:00 -0700397
John Keller3fd0b2d2007-02-28 17:47:27 -0600398 /* Load the new DSDT and SSDT tables into the global table list. */
399 acpi_table_init();
Russ Anderson6872ec52005-05-16 15:30:00 -0700400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
Mark Maulea9f9de72005-04-26 08:01:00 -0700402 /*
Mark Mauleff512242005-11-11 11:52:43 -0600403 * Handle SN vga console.
404 *
405 * SN systems do not have enough ACPI table information
406 * being passed from prom to identify VGA adapters and the legacy
407 * addresses to access them. Until that is done, SN systems rely
408 * on the PCDP table to identify the primary VGA console if one
409 * exists.
410 *
411 * However, kernel PCDP support is optional, and even if it is built
412 * into the kernel, it will not be used if the boot cmdline contains
413 * console= directives.
414 *
415 * So, to work around this mess, we duplicate some of the PCDP code
416 * here so that the primary VGA console (as defined by PCDP) will
417 * work on SN systems even if a different console (e.g. serial) is
418 * selected on the boot line (or CONFIG_EFI_PCDP is off).
Mark Maulea9f9de72005-04-26 08:01:00 -0700419 */
420
Mark Mauleff512242005-11-11 11:52:43 -0600421 if (! vga_console_membase)
422 sn_scan_pcdp();
423
John Keller8ea60912006-10-04 16:49:25 -0500424 /*
425 * Setup legacy IO space.
426 * vga_console_iobase maps to PCI IO Space address 0 on the
427 * bus containing the VGA console.
428 */
429 if (vga_console_iobase) {
John Keller0bdfc192007-03-20 13:50:10 -0500430 io_space[0].mmio_base =
431 (unsigned long) ioremap(vga_console_iobase, 0);
John Keller8ea60912006-10-04 16:49:25 -0500432 io_space[0].sparse = 0;
433 }
434
Mark Maulea9f9de72005-04-26 08:01:00 -0700435 if (vga_console_membase) {
436 /* usable vga ... make tty0 the preferred default console */
Mark Mauleff512242005-11-11 11:52:43 -0600437 if (!strstr(*cmdline_p, "console="))
438 add_preferred_console("tty", 0, NULL);
Mark Maulea9f9de72005-04-26 08:01:00 -0700439 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
Mark Mauleff512242005-11-11 11:52:43 -0600441 if (!strstr(*cmdline_p, "console="))
442 add_preferred_console("ttySG", 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#ifdef CONFIG_DUMMY_CONSOLE
444 conswitchp = &dummy_con;
445#else
446 conswitchp = NULL;
447#endif /* CONFIG_DUMMY_CONSOLE */
448 }
449#endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
450
451 MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
452
Jack Steiner24ee0a62005-09-12 12:15:43 -0500453 /*
454 * Build the tables for managing cnodes.
455 */
456 build_cnode_tables();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 status =
459 ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec,
460 &drift);
461 if (status != 0 || ticks_per_sec < 100000) {
462 printk(KERN_WARNING
463 "unable to determine platform RTC clock frequency, guessing.\n");
464 /* PROM gives wrong value for clock freq. so guess */
465 sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
466 } else
467 sn_rtc_cycles_per_second = ticks_per_sec;
468
469 platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
470
Tony Luckd6e56a22006-02-07 15:25:57 -0800471 ia64_printk_clock = ia64_sn2_printk_clock;
472
Tony Luckd6e56a22006-02-07 15:25:57 -0800473 printk("SGI SAL version %x.%02x\n", version >> 8, version & 0x00FF);
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 /*
476 * we set the default root device to /dev/hda
477 * to make simulation easy
478 */
479 ROOT_DEV = Root_HDA1;
480
481 /*
482 * Create the PDAs and NODEPDAs for all the cpus.
483 */
484 sn_init_pdas(cmdline_p);
485
486 ia64_mark_idle = &snidle;
487
Jack Steiner71a5d022005-05-10 08:01:00 -0700488 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 * For the bootcpu, we do this here. All other cpus will make the
490 * call as part of cpu_init in slave cpu initialization.
491 */
492 sn_cpu_init();
493
494#ifdef CONFIG_SMP
495 init_smp_config();
496#endif
497 screen_info = sn_screen_info;
498
499 sn_timer_init();
Aaron J Youngc1298c52005-04-25 13:11:14 -0700500
501 /*
502 * set pm_power_off to a SAL call to allow
503 * sn machines to power off. The SAL call can be replaced
504 * by an ACPI interface call when ACPI is fully implemented
505 * for sn.
506 */
507 pm_power_off = ia64_sn_power_down;
Brent Casavante08e6c52006-01-26 15:55:52 -0800508 current->thread.flags |= IA64_THREAD_MIGRATION;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
511/**
512 * sn_init_pdas - setup node data areas
513 *
514 * One time setup for Node Data Area. Called by sn_setup().
515 */
516static void __init sn_init_pdas(char **cmdline_p)
517{
518 cnodeid_t cnode;
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /*
521 * Allocate & initalize the nodepda for each node.
522 */
523 for_each_online_node(cnode) {
524 nodepdaindr[cnode] =
525 alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
526 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
Jack Steiner71a5d022005-05-10 08:01:00 -0700527 memset(nodepdaindr[cnode]->phys_cpuid, -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 sizeof(nodepdaindr[cnode]->phys_cpuid));
Jack Steiner470ceb02005-08-11 10:28:00 -0700529 spin_lock_init(&nodepdaindr[cnode]->ptc_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
532 /*
533 * Allocate & initialize nodepda for TIOs. For now, put them on node 0.
534 */
Jack Steiner24ee0a62005-09-12 12:15:43 -0500535 for (cnode = num_online_nodes(); cnode < num_cnodes; cnode++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 nodepdaindr[cnode] =
537 alloc_bootmem_node(NODE_DATA(0), sizeof(nodepda_t));
538 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
539 }
540
541 /*
542 * Now copy the array of nodepda pointers to each nodepda.
543 */
Jack Steiner24ee0a62005-09-12 12:15:43 -0500544 for (cnode = 0; cnode < num_cnodes; cnode++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr,
546 sizeof(nodepdaindr));
547
548 /*
549 * Set up IO related platform-dependent nodepda fields.
550 * The following routine actually sets up the hubinfo struct
551 * in nodepda.
552 */
553 for_each_online_node(cnode) {
554 bte_init_node(nodepdaindr[cnode], cnode);
555 }
556
557 /*
Jack Steiner71a5d022005-05-10 08:01:00 -0700558 * Initialize the per node hubdev. This includes IO Nodes and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 * headless/memless nodes.
560 */
Jack Steiner24ee0a62005-09-12 12:15:43 -0500561 for (cnode = 0; cnode < num_cnodes; cnode++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 hubdev_init_node(nodepdaindr[cnode], cnode);
563 }
564}
565
566/**
567 * sn_cpu_init - initialize per-cpu data areas
568 * @cpuid: cpuid of the caller
569 *
570 * Called during cpu initialization on each cpu as it starts.
571 * Currently, initializes the per-cpu data area for SNIA.
572 * Also sets up a few fields in the nodepda. Also known as
573 * platform_cpu_init() by the ia64 machvec code.
574 */
Jack Steiner38f5745c2006-08-31 11:35:57 -0500575void __cpuinit sn_cpu_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 int cpuid;
578 int cpuphyid;
579 int nasid;
580 int subnode;
581 int slice;
582 int cnode;
583 int i;
Jay Lanadf142e2006-12-11 15:39:23 -0800584 static int wars_have_been_checked, set_cpu0_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Jack Steiner9d56d872006-04-27 20:01:05 -0500586 cpuid = smp_processor_id();
587 if (cpuid == 0 && IS_MEDUSA()) {
Jack Steiner71a5d022005-05-10 08:01:00 -0700588 if (ia64_sn_is_fake_prom())
589 sn_prom_type = 2;
590 else
591 sn_prom_type = 1;
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500592 printk(KERN_INFO "Running on medusa with %s PROM\n",
593 (sn_prom_type == 1) ? "real" : "fake");
Jack Steiner71a5d022005-05-10 08:01:00 -0700594 }
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 memset(pda, 0, sizeof(pda));
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500597 if (ia64_sn_get_sn_info(0, &sn_hub_info->shub2,
598 &sn_hub_info->nasid_bitmask,
599 &sn_hub_info->nasid_shift,
600 &sn_system_size, &sn_sharing_domain_size,
601 &sn_partition_id, &sn_coherency_id,
602 &sn_region_size))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 BUG();
604 sn_hub_info->as_shift = sn_hub_info->nasid_shift - 2;
605
606 /*
Jack Steiner9d56d872006-04-27 20:01:05 -0500607 * Don't check status. The SAL call is not supported on all PROMs
608 * but a failure is harmless.
Jay Lanadf142e2006-12-11 15:39:23 -0800609 * Architechtuallly, cpu_init is always called twice on cpu 0. We
610 * should set cpu_number on cpu 0 once.
Jack Steiner9d56d872006-04-27 20:01:05 -0500611 */
Jay Lanadf142e2006-12-11 15:39:23 -0800612 if (cpuid == 0) {
613 if (!set_cpu0_number) {
614 (void) ia64_sn_set_cpu_number(cpuid);
615 set_cpu0_number = 1;
616 }
617 } else
618 (void) ia64_sn_set_cpu_number(cpuid);
Jack Steiner9d56d872006-04-27 20:01:05 -0500619
620 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 * The boot cpu makes this call again after platform initialization is
622 * complete.
623 */
624 if (nodepdaindr[0] == NULL)
625 return;
626
Jack Steinera1cddb82005-08-31 08:05:00 -0700627 for (i = 0; i < MAX_PROM_FEATURE_SETS; i++)
628 if (ia64_sn_get_prom_feature_set(i, &sn_prom_features[i]) != 0)
629 break;
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 cpuphyid = get_sapicid();
632
633 if (ia64_sn_get_sapic_info(cpuphyid, &nasid, &subnode, &slice))
634 BUG();
635
636 for (i=0; i < MAX_NUMNODES; i++) {
637 if (nodepdaindr[i]) {
638 nodepdaindr[i]->phys_cpuid[cpuid].nasid = nasid;
639 nodepdaindr[i]->phys_cpuid[cpuid].slice = slice;
640 nodepdaindr[i]->phys_cpuid[cpuid].subnode = subnode;
641 }
642 }
643
644 cnode = nasid_to_cnodeid(nasid);
645
Dean Nelson9b48b462005-03-22 16:00:00 -0700646 sn_nodepda = nodepdaindr[cnode];
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 pda->led_address =
649 (typeof(pda->led_address)) (LED0 + (slice << LED_CPU_SHIFT));
650 pda->led_state = LED_ALWAYS_SET;
651 pda->hb_count = HZ / 2;
652 pda->hb_state = 0;
653 pda->idle_flag = 0;
654
655 if (cpuid != 0) {
Dean Nelson2e34f072005-03-21 19:41:00 -0700656 /* copy cpu 0's sn_cnodeid_to_nasid table to this cpu's */
657 memcpy(sn_cnodeid_to_nasid,
658 (&per_cpu(__sn_cnodeid_to_nasid, 0)),
659 sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661
662 /*
663 * Check for WARs.
664 * Only needs to be done once, on BSP.
Dean Nelson2e34f072005-03-21 19:41:00 -0700665 * Has to be done after loop above, because it uses this cpu's
666 * sn_cnodeid_to_nasid table which was just initialized if this
667 * isn't cpu 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 * Has to be done before assignment below.
669 */
670 if (!wars_have_been_checked) {
671 sn_check_for_wars();
672 wars_have_been_checked = 1;
673 }
674 sn_hub_info->shub_1_1_found = shub_1_1_found;
675
676 /*
677 * Set up addresses of PIO/MEM write status registers.
678 */
679 {
680 u64 pio1[] = {SH1_PIO_WRITE_STATUS_0, 0, SH1_PIO_WRITE_STATUS_1, 0};
Jack Steiner2fdbb592005-08-11 10:26:00 -0700681 u64 pio2[] = {SH2_PIO_WRITE_STATUS_0, SH2_PIO_WRITE_STATUS_2,
682 SH2_PIO_WRITE_STATUS_1, SH2_PIO_WRITE_STATUS_3};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 u64 *pio;
684 pio = is_shub1() ? pio1 : pio2;
Brent Casavante08e6c52006-01-26 15:55:52 -0800685 pda->pio_write_status_addr =
686 (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid, pio[slice]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
688 }
689
690 /*
691 * WAR addresses for SHUB 1.x.
692 */
693 if (local_node_data->active_cpu_count++ == 0 && is_shub1()) {
694 int buddy_nasid;
695 buddy_nasid =
696 cnodeid_to_nasid(numa_node_id() ==
697 num_online_nodes() - 1 ? 0 : numa_node_id() + 1);
698 pda->pio_shub_war_cam_addr =
699 (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid,
700 SH1_PI_CAM_CONTROL);
701 }
702}
703
704/*
Jack Steiner24ee0a62005-09-12 12:15:43 -0500705 * Build tables for converting between NASIDs and cnodes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 */
Jack Steiner24ee0a62005-09-12 12:15:43 -0500707static inline int __init board_needs_cnode(int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Jack Steiner24ee0a62005-09-12 12:15:43 -0500709 return (type == KLTYPE_SNIA || type == KLTYPE_TIO);
710}
711
712void __init build_cnode_tables(void)
713{
714 int nasid;
715 int node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 lboard_t *brd;
717
Jack Steiner24ee0a62005-09-12 12:15:43 -0500718 memset(physical_node_map, -1, sizeof(physical_node_map));
719 memset(sn_cnodeid_to_nasid, -1,
720 sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
721
722 /*
723 * First populate the tables with C/M bricks. This ensures that
724 * cnode == node for all C & M bricks.
725 */
726 for_each_online_node(node) {
Yasunori Goto762834e2006-06-23 02:03:19 -0700727 nasid = pxm_to_nasid(node_to_pxm(node));
Jack Steiner24ee0a62005-09-12 12:15:43 -0500728 sn_cnodeid_to_nasid[node] = nasid;
729 physical_node_map[nasid] = node;
730 }
731
732 /*
733 * num_cnodes is total number of C/M/TIO bricks. Because of the 256 node
734 * limit on the number of nodes, we can't use the generic node numbers
735 * for this. Note that num_cnodes is incremented below as TIOs or
736 * headless/memoryless nodes are discovered.
737 */
738 num_cnodes = num_online_nodes();
739
Jack Steiner71a5d022005-05-10 08:01:00 -0700740 /* fakeprom does not support klgraph */
741 if (IS_RUNNING_ON_FAKE_PROM())
742 return;
743
Jack Steiner24ee0a62005-09-12 12:15:43 -0500744 /* Find TIOs & headless/memoryless nodes and add them to the tables */
745 for_each_online_node(node) {
746 kl_config_hdr_t *klgraph_header;
747 nasid = cnodeid_to_nasid(node);
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500748 klgraph_header = ia64_sn_get_klconfig_addr(nasid);
749 if (klgraph_header == NULL)
Jack Steiner24ee0a62005-09-12 12:15:43 -0500750 BUG();
751 brd = NODE_OFFSET_TO_LBOARD(nasid, klgraph_header->ch_board_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 while (brd) {
Jack Steiner24ee0a62005-09-12 12:15:43 -0500753 if (board_needs_cnode(brd->brd_type) && physical_node_map[brd->brd_nasid] < 0) {
754 sn_cnodeid_to_nasid[num_cnodes] = brd->brd_nasid;
755 physical_node_map[brd->brd_nasid] = num_cnodes++;
756 }
757 brd = find_lboard_next(brd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762int
763nasid_slice_to_cpuid(int nasid, int slice)
764{
765 long cpu;
Jack Steiner71a5d022005-05-10 08:01:00 -0700766
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500767 for (cpu = 0; cpu < NR_CPUS; cpu++)
Dean Nelson9b48b462005-03-22 16:00:00 -0700768 if (cpuid_to_nasid(cpu) == nasid &&
769 cpuid_to_slice(cpu) == slice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 return cpu;
771
772 return -1;
773}
Jack Steinera1cddb82005-08-31 08:05:00 -0700774
775int sn_prom_feature_available(int id)
776{
777 if (id >= BITS_PER_LONG * MAX_PROM_FEATURE_SETS)
778 return 0;
779 return test_bit(id, sn_prom_features);
780}
Zou Nan haia7956112006-12-07 09:51:35 -0800781
782void
783sn_kernel_launch_event(void)
784{
785 /* ignore status until we understand possible failure, if any*/
786 if (ia64_sn_kernel_launch_event())
787 printk(KERN_ERR "KEXEC is not supported in this PROM, Please update the PROM.\n");
788}
Jack Steinera1cddb82005-08-31 08:05:00 -0700789EXPORT_SYMBOL(sn_prom_feature_available);
790