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