1 /* 2 * Initial setup-routines for HP 9000 based hardware. 3 * 4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds 5 * Modifications for PA-RISC (C) 1999 Helge Deller <deller@gmx.de> 6 * Modifications copyright 1999 SuSE GmbH (Philipp Rumpf) 7 * Modifications copyright 2000 Martin K. Petersen <mkp@mkp.net> 8 * Modifications copyright 2000 Philipp Rumpf <prumpf@tux.org> 9 * Modifications copyright 2001 Ryan Bradetich <rbradetich@uswest.net> 10 * 11 * Initial PA-RISC Version: 04-23-1999 by Helge Deller 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2, or (at your option) 16 * any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * 27 */ 28 29 #include <linux/kernel.h> 30 #include <linux/initrd.h> 31 #include <linux/init.h> 32 #include <linux/console.h> 33 #include <linux/seq_file.h> 34 #define PCI_DEBUG 35 #include <linux/pci.h> 36 #undef PCI_DEBUG 37 #include <linux/proc_fs.h> 38 #include <linux/export.h> 39 #include <linux/sched.h> 40 #include <linux/sched/clock.h> 41 #include <linux/start_kernel.h> 42 43 #include <asm/processor.h> 44 #include <asm/sections.h> 45 #include <asm/pdc.h> 46 #include <asm/led.h> 47 #include <asm/machdep.h> /* for pa7300lc_init() proto */ 48 #include <asm/pdc_chassis.h> 49 #include <asm/io.h> 50 #include <asm/setup.h> 51 #include <asm/unwind.h> 52 #include <asm/smp.h> 53 54 static char __initdata command_line[COMMAND_LINE_SIZE]; 55 56 /* Intended for ccio/sba/cpu statistics under /proc/bus/{runway|gsc} */ 57 struct proc_dir_entry * proc_runway_root __read_mostly = NULL; 58 struct proc_dir_entry * proc_gsc_root __read_mostly = NULL; 59 struct proc_dir_entry * proc_mckinley_root __read_mostly = NULL; 60 61 void __init setup_cmdline(char **cmdline_p) 62 { 63 extern unsigned int boot_args[]; 64 65 /* Collect stuff passed in from the boot loader */ 66 67 /* boot_args[0] is free-mem start, boot_args[1] is ptr to command line */ 68 if (boot_args[0] < 64) { 69 /* called from hpux boot loader */ 70 boot_command_line[0] = '\0'; 71 } else { 72 strlcpy(boot_command_line, (char *)__va(boot_args[1]), 73 COMMAND_LINE_SIZE); 74 75 #ifdef CONFIG_BLK_DEV_INITRD 76 if (boot_args[2] != 0) /* did palo pass us a ramdisk? */ 77 { 78 initrd_start = (unsigned long)__va(boot_args[2]); 79 initrd_end = (unsigned long)__va(boot_args[3]); 80 } 81 #endif 82 } 83 84 strcpy(command_line, boot_command_line); 85 *cmdline_p = command_line; 86 } 87 88 #ifdef CONFIG_PA11 89 void __init dma_ops_init(void) 90 { 91 switch (boot_cpu_data.cpu_type) { 92 case pcx: 93 /* 94 * We've got way too many dependencies on 1.1 semantics 95 * to support 1.0 boxes at this point. 96 */ 97 panic( "PA-RISC Linux currently only supports machines that conform to\n" 98 "the PA-RISC 1.1 or 2.0 architecture specification.\n"); 99 100 case pcxl2: 101 pa7300lc_init(); 102 case pcxl: /* falls through */ 103 case pcxs: 104 case pcxt: 105 hppa_dma_ops = &dma_direct_ops; 106 break; 107 default: 108 break; 109 } 110 } 111 #endif 112 113 extern void collect_boot_cpu_data(void); 114 115 void __init setup_arch(char **cmdline_p) 116 { 117 #ifdef CONFIG_64BIT 118 extern int parisc_narrow_firmware; 119 #endif 120 unwind_init(); 121 122 init_per_cpu(smp_processor_id()); /* Set Modes & Enable FP */ 123 124 #ifdef CONFIG_64BIT 125 printk(KERN_INFO "The 64-bit Kernel has started...\n"); 126 #else 127 printk(KERN_INFO "The 32-bit Kernel has started...\n"); 128 #endif 129 130 printk(KERN_INFO "Kernel default page size is %d KB. Huge pages ", 131 (int)(PAGE_SIZE / 1024)); 132 #ifdef CONFIG_HUGETLB_PAGE 133 printk(KERN_CONT "enabled with %d MB physical and %d MB virtual size", 134 1 << (REAL_HPAGE_SHIFT - 20), 1 << (HPAGE_SHIFT - 20)); 135 #else 136 printk(KERN_CONT "disabled"); 137 #endif 138 printk(KERN_CONT ".\n"); 139 140 /* 141 * Check if initial kernel page mappings are sufficient. 142 * panic early if not, else we may access kernel functions 143 * and variables which can't be reached. 144 */ 145 if (__pa((unsigned long) &_end) >= KERNEL_INITIAL_SIZE) 146 panic("KERNEL_INITIAL_ORDER too small!"); 147 148 pdc_console_init(); 149 150 #ifdef CONFIG_64BIT 151 if(parisc_narrow_firmware) { 152 printk(KERN_INFO "Kernel is using PDC in 32-bit mode.\n"); 153 } 154 #endif 155 setup_pdc(); 156 setup_cmdline(cmdline_p); 157 collect_boot_cpu_data(); 158 do_memory_inventory(); /* probe for physical memory */ 159 parisc_cache_init(); 160 paging_init(); 161 162 #ifdef CONFIG_CHASSIS_LCD_LED 163 /* initialize the LCD/LED after boot_cpu_data is available ! */ 164 led_init(); /* LCD/LED initialization */ 165 #endif 166 167 #ifdef CONFIG_PA11 168 dma_ops_init(); 169 #endif 170 171 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE) 172 conswitchp = &dummy_con; /* we use do_take_over_console() later ! */ 173 #endif 174 175 clear_sched_clock_stable(); 176 } 177 178 /* 179 * Display CPU info for all CPUs. 180 * for parisc this is in processor.c 181 */ 182 extern int show_cpuinfo (struct seq_file *m, void *v); 183 184 static void * 185 c_start (struct seq_file *m, loff_t *pos) 186 { 187 /* Looks like the caller will call repeatedly until we return 188 * 0, signaling EOF perhaps. This could be used to sequence 189 * through CPUs for example. Since we print all cpu info in our 190 * show_cpuinfo() disregarding 'pos' (which I assume is 'v' above) 191 * we only allow for one "position". */ 192 return ((long)*pos < 1) ? (void *)1 : NULL; 193 } 194 195 static void * 196 c_next (struct seq_file *m, void *v, loff_t *pos) 197 { 198 ++*pos; 199 return c_start(m, pos); 200 } 201 202 static void 203 c_stop (struct seq_file *m, void *v) 204 { 205 } 206 207 const struct seq_operations cpuinfo_op = { 208 .start = c_start, 209 .next = c_next, 210 .stop = c_stop, 211 .show = show_cpuinfo 212 }; 213 214 static void __init parisc_proc_mkdir(void) 215 { 216 /* 217 ** Can't call proc_mkdir() until after proc_root_init() has been 218 ** called by start_kernel(). In other words, this code can't 219 ** live in arch/.../setup.c because start_parisc() calls 220 ** start_kernel(). 221 */ 222 switch (boot_cpu_data.cpu_type) { 223 case pcxl: 224 case pcxl2: 225 if (NULL == proc_gsc_root) 226 { 227 proc_gsc_root = proc_mkdir("bus/gsc", NULL); 228 } 229 break; 230 case pcxt_: 231 case pcxu: 232 case pcxu_: 233 case pcxw: 234 case pcxw_: 235 case pcxw2: 236 if (NULL == proc_runway_root) 237 { 238 proc_runway_root = proc_mkdir("bus/runway", NULL); 239 } 240 break; 241 case mako: 242 case mako2: 243 if (NULL == proc_mckinley_root) 244 { 245 proc_mckinley_root = proc_mkdir("bus/mckinley", NULL); 246 } 247 break; 248 default: 249 /* FIXME: this was added to prevent the compiler 250 * complaining about missing pcx, pcxs and pcxt 251 * I'm assuming they have neither gsc nor runway */ 252 break; 253 } 254 } 255 256 static struct resource central_bus = { 257 .name = "Central Bus", 258 .start = F_EXTEND(0xfff80000), 259 .end = F_EXTEND(0xfffaffff), 260 .flags = IORESOURCE_MEM, 261 }; 262 263 static struct resource local_broadcast = { 264 .name = "Local Broadcast", 265 .start = F_EXTEND(0xfffb0000), 266 .end = F_EXTEND(0xfffdffff), 267 .flags = IORESOURCE_MEM, 268 }; 269 270 static struct resource global_broadcast = { 271 .name = "Global Broadcast", 272 .start = F_EXTEND(0xfffe0000), 273 .end = F_EXTEND(0xffffffff), 274 .flags = IORESOURCE_MEM, 275 }; 276 277 static int __init parisc_init_resources(void) 278 { 279 int result; 280 281 result = request_resource(&iomem_resource, ¢ral_bus); 282 if (result < 0) { 283 printk(KERN_ERR 284 "%s: failed to claim %s address space!\n", 285 __FILE__, central_bus.name); 286 return result; 287 } 288 289 result = request_resource(&iomem_resource, &local_broadcast); 290 if (result < 0) { 291 printk(KERN_ERR 292 "%s: failed to claim %saddress space!\n", 293 __FILE__, local_broadcast.name); 294 return result; 295 } 296 297 result = request_resource(&iomem_resource, &global_broadcast); 298 if (result < 0) { 299 printk(KERN_ERR 300 "%s: failed to claim %s address space!\n", 301 __FILE__, global_broadcast.name); 302 return result; 303 } 304 305 return 0; 306 } 307 308 static int no_alternatives __initdata; 309 static int __init setup_no_alternatives(char *str) 310 { 311 no_alternatives = 1; 312 return 1; 313 } 314 __setup("no-alternatives", setup_no_alternatives); 315 316 static void __init apply_alternatives_all(void) 317 { 318 struct alt_instr *entry; 319 int index = 0, applied = 0; 320 321 322 pr_info("alternatives: %spatching kernel code\n", 323 no_alternatives ? "NOT " : ""); 324 if (no_alternatives) 325 return; 326 327 set_kernel_text_rw(1); 328 329 for (entry = (struct alt_instr *) &__alt_instructions; 330 entry < (struct alt_instr *) &__alt_instructions_end; 331 entry++, index++) { 332 333 u32 *from, len, cond, replacement; 334 335 from = (u32 *)((ulong)&entry->orig_offset + entry->orig_offset); 336 len = entry->len; 337 cond = entry->cond; 338 replacement = entry->replacement; 339 340 WARN_ON(!cond); 341 pr_debug("Check %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n", 342 index, cond, len, from, replacement); 343 344 if ((cond & ALT_COND_NO_SMP) && (num_online_cpus() != 1)) 345 continue; 346 if ((cond & ALT_COND_NO_DCACHE) && (cache_info.dc_size != 0)) 347 continue; 348 if ((cond & ALT_COND_NO_ICACHE) && (cache_info.ic_size != 0)) 349 continue; 350 351 /* 352 * If the PDC_MODEL capabilities has Non-coherent IO-PDIR bit 353 * set (bit #61, big endian), we have to flush and sync every 354 * time IO-PDIR is changed in Ike/Astro. 355 */ 356 if ((cond & ALT_COND_NO_IOC_FDC) && 357 (boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC)) 358 continue; 359 360 /* Want to replace pdtlb by a pdtlb,l instruction? */ 361 if (replacement == INSN_PxTLB) { 362 replacement = *from; 363 if (boot_cpu_data.cpu_type >= pcxu) /* >= pa2.0 ? */ 364 replacement |= (1 << 10); /* set el bit */ 365 } 366 367 /* 368 * Replace instruction with NOPs? 369 * For long distance insert a branch instruction instead. 370 */ 371 if (replacement == INSN_NOP && len > 1) 372 replacement = 0xe8000002 + (len-2)*8; /* "b,n .+8" */ 373 374 pr_debug("Do %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n", 375 index, cond, len, from, replacement); 376 377 /* Replace instruction */ 378 *from = replacement; 379 applied++; 380 } 381 382 pr_info("alternatives: applied %d out of %d patches\n", applied, index); 383 384 set_kernel_text_rw(0); 385 } 386 387 388 extern void gsc_init(void); 389 extern void processor_init(void); 390 extern void ccio_init(void); 391 extern void hppb_init(void); 392 extern void dino_init(void); 393 extern void iosapic_init(void); 394 extern void lba_init(void); 395 extern void sba_init(void); 396 extern void eisa_init(void); 397 398 static int __init parisc_init(void) 399 { 400 u32 osid = (OS_ID_LINUX << 16); 401 402 parisc_proc_mkdir(); 403 parisc_init_resources(); 404 do_device_inventory(); /* probe for hardware */ 405 406 parisc_pdc_chassis_init(); 407 408 /* set up a new led state on systems shipped LED State panel */ 409 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BSTART); 410 411 /* tell PDC we're Linux. Nevermind failure. */ 412 pdc_stable_write(0x40, &osid, sizeof(osid)); 413 414 /* start with known state */ 415 flush_cache_all_local(); 416 flush_tlb_all_local(NULL); 417 418 processor_init(); 419 #ifdef CONFIG_SMP 420 pr_info("CPU(s): %d out of %d %s at %d.%06d MHz online\n", 421 num_online_cpus(), num_present_cpus(), 422 #else 423 pr_info("CPU(s): 1 x %s at %d.%06d MHz\n", 424 #endif 425 boot_cpu_data.cpu_name, 426 boot_cpu_data.cpu_hz / 1000000, 427 boot_cpu_data.cpu_hz % 1000000 ); 428 429 apply_alternatives_all(); 430 parisc_setup_cache_timing(); 431 432 /* These are in a non-obvious order, will fix when we have an iotree */ 433 #if defined(CONFIG_IOSAPIC) 434 iosapic_init(); 435 #endif 436 #if defined(CONFIG_IOMMU_SBA) 437 sba_init(); 438 #endif 439 #if defined(CONFIG_PCI_LBA) 440 lba_init(); 441 #endif 442 443 /* CCIO before any potential subdevices */ 444 #if defined(CONFIG_IOMMU_CCIO) 445 ccio_init(); 446 #endif 447 448 /* 449 * Need to register Asp & Wax before the EISA adapters for the IRQ 450 * regions. EISA must come before PCI to be sure it gets IRQ region 451 * 0. 452 */ 453 #if defined(CONFIG_GSC_LASI) || defined(CONFIG_GSC_WAX) 454 gsc_init(); 455 #endif 456 #ifdef CONFIG_EISA 457 eisa_init(); 458 #endif 459 460 #if defined(CONFIG_HPPB) 461 hppb_init(); 462 #endif 463 464 #if defined(CONFIG_GSC_DINO) 465 dino_init(); 466 #endif 467 468 #ifdef CONFIG_CHASSIS_LCD_LED 469 register_led_regions(); /* register LED port info in procfs */ 470 #endif 471 472 return 0; 473 } 474 arch_initcall(parisc_init); 475 476 void __init start_parisc(void) 477 { 478 extern void early_trap_init(void); 479 480 int ret, cpunum; 481 struct pdc_coproc_cfg coproc_cfg; 482 483 cpunum = smp_processor_id(); 484 485 init_cpu_topology(); 486 487 set_firmware_width_unlocked(); 488 489 ret = pdc_coproc_cfg_unlocked(&coproc_cfg); 490 if (ret >= 0 && coproc_cfg.ccr_functional) { 491 mtctl(coproc_cfg.ccr_functional, 10); 492 493 per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision; 494 per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model; 495 496 asm volatile ("fstd %fr0,8(%sp)"); 497 } else { 498 panic("must have an fpu to boot linux"); 499 } 500 501 early_trap_init(); /* initialize checksum of fault_vector */ 502 503 start_kernel(); 504 // not reached 505 } 506