1de6cc651SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2071327ecSAlexander Beregalov /*
31da177e4SLinus Torvalds * Initial setup-routines for HP 9000 based hardware.
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 1991, 1992, 1995 Linus Torvalds
61da177e4SLinus Torvalds * Modifications for PA-RISC (C) 1999 Helge Deller <deller@gmx.de>
71da177e4SLinus Torvalds * Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)
81da177e4SLinus Torvalds * Modifications copyright 2000 Martin K. Petersen <mkp@mkp.net>
91da177e4SLinus Torvalds * Modifications copyright 2000 Philipp Rumpf <prumpf@tux.org>
101da177e4SLinus Torvalds * Modifications copyright 2001 Ryan Bradetich <rbradetich@uswest.net>
111da177e4SLinus Torvalds *
121da177e4SLinus Torvalds * Initial PA-RISC Version: 04-23-1999 by Helge Deller
131da177e4SLinus Torvalds */
141da177e4SLinus Torvalds
151da177e4SLinus Torvalds #include <linux/kernel.h>
161da177e4SLinus Torvalds #include <linux/initrd.h>
171da177e4SLinus Torvalds #include <linux/init.h>
181da177e4SLinus Torvalds #include <linux/console.h>
191da177e4SLinus Torvalds #include <linux/seq_file.h>
201da177e4SLinus Torvalds #define PCI_DEBUG
211da177e4SLinus Torvalds #include <linux/pci.h>
221da177e4SLinus Torvalds #undef PCI_DEBUG
231da177e4SLinus Torvalds #include <linux/proc_fs.h>
24a87df54eSPaul Gortmaker #include <linux/export.h>
25acb04058SPeter Zijlstra #include <linux/sched.h>
26e6017571SIngo Molnar #include <linux/sched/clock.h>
2708b8a99bSHelge Deller #include <linux/start_kernel.h>
281da177e4SLinus Torvalds
293e803d3eSChristoph Hellwig #include <asm/cacheflush.h>
301da177e4SLinus Torvalds #include <asm/processor.h>
31690d097cSHelge Deller #include <asm/sections.h>
321da177e4SLinus Torvalds #include <asm/pdc.h>
331da177e4SLinus Torvalds #include <asm/led.h>
341da177e4SLinus Torvalds #include <asm/pdc_chassis.h>
351da177e4SLinus Torvalds #include <asm/io.h>
361da177e4SLinus Torvalds #include <asm/setup.h>
37f0514ae3SJames Bottomley #include <asm/unwind.h>
38a7e6601fSHelge Deller #include <asm/smp.h>
391da177e4SLinus Torvalds
4001da41b8SAlexey Dobriyan static char __initdata command_line[COMMAND_LINE_SIZE];
411da177e4SLinus Torvalds
setup_cmdline(char ** cmdline_p)42*f310f8ddSHelge Deller static void __init setup_cmdline(char **cmdline_p)
431da177e4SLinus Torvalds {
441da177e4SLinus Torvalds extern unsigned int boot_args[];
455f7ee6e3SHelge Deller char *p;
461da177e4SLinus Torvalds
471bc54346SHelge Deller *cmdline_p = command_line;
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds /* boot_args[0] is free-mem start, boot_args[1] is ptr to command line */
501bc54346SHelge Deller if (boot_args[0] < 64)
511bc54346SHelge Deller return; /* return if called from hpux boot loader */
521bc54346SHelge Deller
531bc54346SHelge Deller /* Collect stuff passed in from the boot loader */
54bd25c378SHelge Deller strscpy(boot_command_line, (char *)__va(boot_args[1]),
55ea99b1adSChen Gang COMMAND_LINE_SIZE);
561da177e4SLinus Torvalds
575f7ee6e3SHelge Deller /* autodetect console type (if not done by palo yet) */
585f7ee6e3SHelge Deller p = boot_command_line;
595f7ee6e3SHelge Deller if (!str_has_prefix(p, "console=") && !strstr(p, " console=")) {
605f7ee6e3SHelge Deller strlcat(p, " console=", COMMAND_LINE_SIZE);
615f7ee6e3SHelge Deller if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
625f7ee6e3SHelge Deller strlcat(p, "ttyS0", COMMAND_LINE_SIZE);
635f7ee6e3SHelge Deller else
645f7ee6e3SHelge Deller strlcat(p, "tty0", COMMAND_LINE_SIZE);
655f7ee6e3SHelge Deller }
665f7ee6e3SHelge Deller
67027c3d34SHelge Deller /* default to use early console */
68027c3d34SHelge Deller if (!strstr(p, "earlycon"))
69027c3d34SHelge Deller strlcat(p, " earlycon=pdc", COMMAND_LINE_SIZE);
70027c3d34SHelge Deller
711da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
721bc54346SHelge Deller /* did palo pass us a ramdisk? */
731bc54346SHelge Deller if (boot_args[2] != 0) {
741da177e4SLinus Torvalds initrd_start = (unsigned long)__va(boot_args[2]);
751da177e4SLinus Torvalds initrd_end = (unsigned long)__va(boot_args[3]);
761da177e4SLinus Torvalds }
771da177e4SLinus Torvalds #endif
781da177e4SLinus Torvalds
79bd25c378SHelge Deller strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds
821da177e4SLinus Torvalds #ifdef CONFIG_PA11
dma_ops_init(void)83*f310f8ddSHelge Deller static void __init dma_ops_init(void)
841da177e4SLinus Torvalds {
851da177e4SLinus Torvalds switch (boot_cpu_data.cpu_type) {
861da177e4SLinus Torvalds case pcx:
871da177e4SLinus Torvalds /*
881da177e4SLinus Torvalds * We've got way too many dependencies on 1.1 semantics
891da177e4SLinus Torvalds * to support 1.0 boxes at this point.
901da177e4SLinus Torvalds */
911da177e4SLinus Torvalds panic( "PA-RISC Linux currently only supports machines that conform to\n"
921da177e4SLinus Torvalds "the PA-RISC 1.1 or 2.0 architecture specification.\n");
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds case pcxl2:
951da177e4SLinus Torvalds default:
961da177e4SLinus Torvalds break;
971da177e4SLinus Torvalds }
981da177e4SLinus Torvalds }
991da177e4SLinus Torvalds #endif
1001da177e4SLinus Torvalds
setup_arch(char ** cmdline_p)1011da177e4SLinus Torvalds void __init setup_arch(char **cmdline_p)
1021da177e4SLinus Torvalds {
103a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1041da177e4SLinus Torvalds extern int parisc_narrow_firmware;
1051da177e4SLinus Torvalds #endif
106f0514ae3SJames Bottomley unwind_init();
1071da177e4SLinus Torvalds
1081da177e4SLinus Torvalds init_per_cpu(smp_processor_id()); /* Set Modes & Enable FP */
1091da177e4SLinus Torvalds
110a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1111da177e4SLinus Torvalds printk(KERN_INFO "The 64-bit Kernel has started...\n");
1121da177e4SLinus Torvalds #else
1131da177e4SLinus Torvalds printk(KERN_INFO "The 32-bit Kernel has started...\n");
1141da177e4SLinus Torvalds #endif
1151da177e4SLinus Torvalds
116736d2169SHelge Deller printk(KERN_INFO "Kernel default page size is %d KB. Huge pages ",
117736d2169SHelge Deller (int)(PAGE_SIZE / 1024));
118736d2169SHelge Deller #ifdef CONFIG_HUGETLB_PAGE
119736d2169SHelge Deller printk(KERN_CONT "enabled with %d MB physical and %d MB virtual size",
120736d2169SHelge Deller 1 << (REAL_HPAGE_SHIFT - 20), 1 << (HPAGE_SHIFT - 20));
121736d2169SHelge Deller #else
122736d2169SHelge Deller printk(KERN_CONT "disabled");
123736d2169SHelge Deller #endif
124736d2169SHelge Deller printk(KERN_CONT ".\n");
125736d2169SHelge Deller
126690d097cSHelge Deller /*
127690d097cSHelge Deller * Check if initial kernel page mappings are sufficient.
128690d097cSHelge Deller * panic early if not, else we may access kernel functions
129690d097cSHelge Deller * and variables which can't be reached.
130690d097cSHelge Deller */
131690d097cSHelge Deller if (__pa((unsigned long) &_end) >= KERNEL_INITIAL_SIZE)
132690d097cSHelge Deller panic("KERNEL_INITIAL_ORDER too small!");
1336a45716aSHelge Deller
134a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1351da177e4SLinus Torvalds if(parisc_narrow_firmware) {
1361da177e4SLinus Torvalds printk(KERN_INFO "Kernel is using PDC in 32-bit mode.\n");
1371da177e4SLinus Torvalds }
1381da177e4SLinus Torvalds #endif
1391da177e4SLinus Torvalds setup_pdc();
1401da177e4SLinus Torvalds setup_cmdline(cmdline_p);
1411da177e4SLinus Torvalds collect_boot_cpu_data();
1421da177e4SLinus Torvalds do_memory_inventory(); /* probe for physical memory */
1431da177e4SLinus Torvalds parisc_cache_init();
1441da177e4SLinus Torvalds paging_init();
1451da177e4SLinus Torvalds
1461da177e4SLinus Torvalds #ifdef CONFIG_PA11
1471da177e4SLinus Torvalds dma_ops_init();
1481da177e4SLinus Torvalds #endif
1497962c089SHelge Deller
1507962c089SHelge Deller clear_sched_clock_stable();
1511da177e4SLinus Torvalds }
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds /*
1547022672eSSimon Arlott * Display CPU info for all CPUs.
1551da177e4SLinus Torvalds */
1561da177e4SLinus Torvalds static void *
c_start(struct seq_file * m,loff_t * pos)1571da177e4SLinus Torvalds c_start (struct seq_file *m, loff_t *pos)
1581da177e4SLinus Torvalds {
1591da177e4SLinus Torvalds /* Looks like the caller will call repeatedly until we return
1601da177e4SLinus Torvalds * 0, signaling EOF perhaps. This could be used to sequence
1611da177e4SLinus Torvalds * through CPUs for example. Since we print all cpu info in our
1621da177e4SLinus Torvalds * show_cpuinfo() disregarding 'pos' (which I assume is 'v' above)
1631da177e4SLinus Torvalds * we only allow for one "position". */
1641da177e4SLinus Torvalds return ((long)*pos < 1) ? (void *)1 : NULL;
1651da177e4SLinus Torvalds }
1661da177e4SLinus Torvalds
1671da177e4SLinus Torvalds static void *
c_next(struct seq_file * m,void * v,loff_t * pos)1681da177e4SLinus Torvalds c_next (struct seq_file *m, void *v, loff_t *pos)
1691da177e4SLinus Torvalds {
1701da177e4SLinus Torvalds ++*pos;
1711da177e4SLinus Torvalds return c_start(m, pos);
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds static void
c_stop(struct seq_file * m,void * v)1751da177e4SLinus Torvalds c_stop (struct seq_file *m, void *v)
1761da177e4SLinus Torvalds {
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds
17903a44825SJan Engelhardt const struct seq_operations cpuinfo_op = {
1801da177e4SLinus Torvalds .start = c_start,
1811da177e4SLinus Torvalds .next = c_next,
1821da177e4SLinus Torvalds .stop = c_stop,
1831da177e4SLinus Torvalds .show = show_cpuinfo
1841da177e4SLinus Torvalds };
1851da177e4SLinus Torvalds
1861da177e4SLinus Torvalds static struct resource central_bus = {
1871da177e4SLinus Torvalds .name = "Central Bus",
1881da177e4SLinus Torvalds .start = F_EXTEND(0xfff80000),
1891da177e4SLinus Torvalds .end = F_EXTEND(0xfffaffff),
1901da177e4SLinus Torvalds .flags = IORESOURCE_MEM,
1911da177e4SLinus Torvalds };
1921da177e4SLinus Torvalds
1931da177e4SLinus Torvalds static struct resource local_broadcast = {
1941da177e4SLinus Torvalds .name = "Local Broadcast",
1951da177e4SLinus Torvalds .start = F_EXTEND(0xfffb0000),
1961da177e4SLinus Torvalds .end = F_EXTEND(0xfffdffff),
1971da177e4SLinus Torvalds .flags = IORESOURCE_MEM,
1981da177e4SLinus Torvalds };
1991da177e4SLinus Torvalds
2001da177e4SLinus Torvalds static struct resource global_broadcast = {
2011da177e4SLinus Torvalds .name = "Global Broadcast",
2021da177e4SLinus Torvalds .start = F_EXTEND(0xfffe0000),
2031da177e4SLinus Torvalds .end = F_EXTEND(0xffffffff),
2041da177e4SLinus Torvalds .flags = IORESOURCE_MEM,
2051da177e4SLinus Torvalds };
2061da177e4SLinus Torvalds
parisc_init_resources(void)2071da177e4SLinus Torvalds static int __init parisc_init_resources(void)
2081da177e4SLinus Torvalds {
2091da177e4SLinus Torvalds int result;
2101da177e4SLinus Torvalds
2111da177e4SLinus Torvalds result = request_resource(&iomem_resource, ¢ral_bus);
2121da177e4SLinus Torvalds if (result < 0) {
2131da177e4SLinus Torvalds printk(KERN_ERR
2141da177e4SLinus Torvalds "%s: failed to claim %s address space!\n",
2151da177e4SLinus Torvalds __FILE__, central_bus.name);
2161da177e4SLinus Torvalds return result;
2171da177e4SLinus Torvalds }
2181da177e4SLinus Torvalds
2191da177e4SLinus Torvalds result = request_resource(&iomem_resource, &local_broadcast);
2201da177e4SLinus Torvalds if (result < 0) {
2211da177e4SLinus Torvalds printk(KERN_ERR
2221da177e4SLinus Torvalds "%s: failed to claim %s address space!\n",
2231da177e4SLinus Torvalds __FILE__, local_broadcast.name);
2241da177e4SLinus Torvalds return result;
2251da177e4SLinus Torvalds }
2261da177e4SLinus Torvalds
2271da177e4SLinus Torvalds result = request_resource(&iomem_resource, &global_broadcast);
2281da177e4SLinus Torvalds if (result < 0) {
2291da177e4SLinus Torvalds printk(KERN_ERR
2301da177e4SLinus Torvalds "%s: failed to claim %s address space!\n",
2311da177e4SLinus Torvalds __FILE__, global_broadcast.name);
2321da177e4SLinus Torvalds return result;
2331da177e4SLinus Torvalds }
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds return 0;
2361da177e4SLinus Torvalds }
2371da177e4SLinus Torvalds
parisc_init(void)2381da177e4SLinus Torvalds static int __init parisc_init(void)
2391da177e4SLinus Torvalds {
240ec1fdc24SKyle McMartin u32 osid = (OS_ID_LINUX << 16);
2413f9edb53SThibaut Varene
2421da177e4SLinus Torvalds parisc_init_resources();
2431da177e4SLinus Torvalds do_device_inventory(); /* probe for hardware */
2441da177e4SLinus Torvalds
2451da177e4SLinus Torvalds parisc_pdc_chassis_init();
2461da177e4SLinus Torvalds
2471da177e4SLinus Torvalds /* set up a new led state on systems shipped LED State panel */
2481da177e4SLinus Torvalds pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BSTART);
2491da177e4SLinus Torvalds
2503f9edb53SThibaut Varene /* tell PDC we're Linux. Nevermind failure. */
2513f9edb53SThibaut Varene pdc_stable_write(0x40, &osid, sizeof(osid));
2523f9edb53SThibaut Varene
253741dc7bfSJohn David Anglin /* start with known state */
254741dc7bfSJohn David Anglin flush_cache_all_local();
255741dc7bfSJohn David Anglin flush_tlb_all_local(NULL);
256741dc7bfSJohn David Anglin
2571da177e4SLinus Torvalds processor_init();
2583a7452b4SHelge Deller #ifdef CONFIG_SMP
2593a7452b4SHelge Deller pr_info("CPU(s): %d out of %d %s at %d.%06d MHz online\n",
2603a7452b4SHelge Deller num_online_cpus(), num_present_cpus(),
2613a7452b4SHelge Deller #else
2623a7452b4SHelge Deller pr_info("CPU(s): 1 x %s at %d.%06d MHz\n",
2633a7452b4SHelge Deller #endif
2641da177e4SLinus Torvalds boot_cpu_data.cpu_name,
2651da177e4SLinus Torvalds boot_cpu_data.cpu_hz / 1000000,
2661da177e4SLinus Torvalds boot_cpu_data.cpu_hz % 1000000 );
2671da177e4SLinus Torvalds
268b37d1c18SMikulas Patocka #if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
269b37d1c18SMikulas Patocka /* Don't serialize TLB flushes if we run on one CPU only. */
270b37d1c18SMikulas Patocka if (num_online_cpus() == 1)
271b37d1c18SMikulas Patocka pa_serialize_tlb_flushes = 0;
272b37d1c18SMikulas Patocka #endif
273b37d1c18SMikulas Patocka
2743847dab7SHelge Deller apply_alternatives_all();
2751da177e4SLinus Torvalds parisc_setup_cache_timing();
2761da177e4SLinus Torvalds return 0;
2771da177e4SLinus Torvalds }
2781da177e4SLinus Torvalds arch_initcall(parisc_init);
2791da177e4SLinus Torvalds
start_parisc(void)28008b8a99bSHelge Deller void __init start_parisc(void)
281089d5528SKyle McMartin {
282089d5528SKyle McMartin int ret, cpunum;
283089d5528SKyle McMartin struct pdc_coproc_cfg coproc_cfg;
284089d5528SKyle McMartin
285d006e95bSHelge Deller /* check QEMU/SeaBIOS marker in PAGE0 */
286d006e95bSHelge Deller running_on_qemu = (memcmp(&PAGE0->pad0, "SeaBIOS", 8) == 0);
287d006e95bSHelge Deller
288089d5528SKyle McMartin cpunum = smp_processor_id();
289089d5528SKyle McMartin
290bf7b4c1bSHelge Deller init_cpu_topology();
291bf7b4c1bSHelge Deller
292089d5528SKyle McMartin set_firmware_width_unlocked();
293089d5528SKyle McMartin
294089d5528SKyle McMartin ret = pdc_coproc_cfg_unlocked(&coproc_cfg);
295089d5528SKyle McMartin if (ret >= 0 && coproc_cfg.ccr_functional) {
296089d5528SKyle McMartin mtctl(coproc_cfg.ccr_functional, 10);
297089d5528SKyle McMartin
298ef017bebSHelge Deller per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;
299ef017bebSHelge Deller per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;
300089d5528SKyle McMartin
301089d5528SKyle McMartin asm volatile ("fstd %fr0,8(%sp)");
302089d5528SKyle McMartin } else {
303089d5528SKyle McMartin panic("must have an fpu to boot linux");
304089d5528SKyle McMartin }
305089d5528SKyle McMartin
3064182d0cdSHelge Deller early_trap_init(); /* initialize checksum of fault_vector */
3074182d0cdSHelge Deller
308089d5528SKyle McMartin start_kernel();
309089d5528SKyle McMartin // not reached
310089d5528SKyle McMartin }
311