xref: /linux-6.15/arch/parisc/kernel/setup.c (revision 06a2e499)
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 <[email protected]>
71da177e4SLinus Torvalds  *    Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)
81da177e4SLinus Torvalds  *    Modifications copyright 2000 Martin K. Petersen <[email protected]>
91da177e4SLinus Torvalds  *    Modifications copyright 2000 Philipp Rumpf <[email protected]>
101da177e4SLinus Torvalds  *    Modifications copyright 2001 Ryan Bradetich <[email protected]>
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 {
103f0514ae3SJames Bottomley 	unwind_init();
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	init_per_cpu(smp_processor_id());	/* Set Modes & Enable FP */
1061da177e4SLinus Torvalds 
107a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1081da177e4SLinus Torvalds 	printk(KERN_INFO "The 64-bit Kernel has started...\n");
1091da177e4SLinus Torvalds #else
1101da177e4SLinus Torvalds 	printk(KERN_INFO "The 32-bit Kernel has started...\n");
1111da177e4SLinus Torvalds #endif
1121da177e4SLinus Torvalds 
113736d2169SHelge Deller 	printk(KERN_INFO "Kernel default page size is %d KB. Huge pages ",
114736d2169SHelge Deller 		(int)(PAGE_SIZE / 1024));
115736d2169SHelge Deller #ifdef CONFIG_HUGETLB_PAGE
116736d2169SHelge Deller 	printk(KERN_CONT "enabled with %d MB physical and %d MB virtual size",
117736d2169SHelge Deller 		 1 << (REAL_HPAGE_SHIFT - 20), 1 << (HPAGE_SHIFT - 20));
118736d2169SHelge Deller #else
119736d2169SHelge Deller 	printk(KERN_CONT "disabled");
120736d2169SHelge Deller #endif
121736d2169SHelge Deller 	printk(KERN_CONT ".\n");
122736d2169SHelge Deller 
123690d097cSHelge Deller 	/*
124690d097cSHelge Deller 	 * Check if initial kernel page mappings are sufficient.
125690d097cSHelge Deller 	 * panic early if not, else we may access kernel functions
126690d097cSHelge Deller 	 * and variables which can't be reached.
127690d097cSHelge Deller 	 */
128690d097cSHelge Deller 	if (__pa((unsigned long) &_end) >= KERNEL_INITIAL_SIZE)
129690d097cSHelge Deller 		panic("KERNEL_INITIAL_ORDER too small!");
1306a45716aSHelge Deller 
131a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1321da177e4SLinus Torvalds 	if(parisc_narrow_firmware) {
1331da177e4SLinus Torvalds 		printk(KERN_INFO "Kernel is using PDC in 32-bit mode.\n");
1341da177e4SLinus Torvalds 	}
1351da177e4SLinus Torvalds #endif
1361da177e4SLinus Torvalds 	setup_pdc();
1371da177e4SLinus Torvalds 	setup_cmdline(cmdline_p);
1381da177e4SLinus Torvalds 	collect_boot_cpu_data();
1391da177e4SLinus Torvalds 	do_memory_inventory();  /* probe for physical memory */
1401da177e4SLinus Torvalds 	parisc_cache_init();
1411da177e4SLinus Torvalds 	paging_init();
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds #ifdef CONFIG_PA11
1441da177e4SLinus Torvalds 	dma_ops_init();
1451da177e4SLinus Torvalds #endif
1467962c089SHelge Deller 
1477962c089SHelge Deller 	clear_sched_clock_stable();
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds /*
1517022672eSSimon Arlott  * Display CPU info for all CPUs.
1521da177e4SLinus Torvalds  */
1531da177e4SLinus Torvalds static void *
c_start(struct seq_file * m,loff_t * pos)1541da177e4SLinus Torvalds c_start (struct seq_file *m, loff_t *pos)
1551da177e4SLinus Torvalds {
1561da177e4SLinus Torvalds     	/* Looks like the caller will call repeatedly until we return
1571da177e4SLinus Torvalds 	 * 0, signaling EOF perhaps.  This could be used to sequence
1581da177e4SLinus Torvalds 	 * through CPUs for example.  Since we print all cpu info in our
1591da177e4SLinus Torvalds 	 * show_cpuinfo() disregarding 'pos' (which I assume is 'v' above)
1601da177e4SLinus Torvalds 	 * we only allow for one "position".  */
1611da177e4SLinus Torvalds 	return ((long)*pos < 1) ? (void *)1 : NULL;
1621da177e4SLinus Torvalds }
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds static void *
c_next(struct seq_file * m,void * v,loff_t * pos)1651da177e4SLinus Torvalds c_next (struct seq_file *m, void *v, loff_t *pos)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds 	++*pos;
1681da177e4SLinus Torvalds 	return c_start(m, pos);
1691da177e4SLinus Torvalds }
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds static void
c_stop(struct seq_file * m,void * v)1721da177e4SLinus Torvalds c_stop (struct seq_file *m, void *v)
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds }
1751da177e4SLinus Torvalds 
17603a44825SJan Engelhardt const struct seq_operations cpuinfo_op = {
1771da177e4SLinus Torvalds 	.start	= c_start,
1781da177e4SLinus Torvalds 	.next	= c_next,
1791da177e4SLinus Torvalds 	.stop	= c_stop,
1801da177e4SLinus Torvalds 	.show	= show_cpuinfo
1811da177e4SLinus Torvalds };
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds static struct resource central_bus = {
1841da177e4SLinus Torvalds 	.name	= "Central Bus",
1851da177e4SLinus Torvalds 	.start	= F_EXTEND(0xfff80000),
1861da177e4SLinus Torvalds 	.end    = F_EXTEND(0xfffaffff),
1871da177e4SLinus Torvalds 	.flags	= IORESOURCE_MEM,
1881da177e4SLinus Torvalds };
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds static struct resource local_broadcast = {
1911da177e4SLinus Torvalds 	.name	= "Local Broadcast",
1921da177e4SLinus Torvalds 	.start	= F_EXTEND(0xfffb0000),
1931da177e4SLinus Torvalds 	.end	= F_EXTEND(0xfffdffff),
1941da177e4SLinus Torvalds 	.flags	= IORESOURCE_MEM,
1951da177e4SLinus Torvalds };
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds static struct resource global_broadcast = {
1981da177e4SLinus Torvalds 	.name	= "Global Broadcast",
1991da177e4SLinus Torvalds 	.start	= F_EXTEND(0xfffe0000),
2001da177e4SLinus Torvalds 	.end	= F_EXTEND(0xffffffff),
2011da177e4SLinus Torvalds 	.flags	= IORESOURCE_MEM,
2021da177e4SLinus Torvalds };
2031da177e4SLinus Torvalds 
parisc_init_resources(void)2041da177e4SLinus Torvalds static int __init parisc_init_resources(void)
2051da177e4SLinus Torvalds {
2061da177e4SLinus Torvalds 	int result;
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds 	result = request_resource(&iomem_resource, &central_bus);
2091da177e4SLinus Torvalds 	if (result < 0) {
2101da177e4SLinus Torvalds 		printk(KERN_ERR
2111da177e4SLinus Torvalds 		       "%s: failed to claim %s address space!\n",
2121da177e4SLinus Torvalds 		       __FILE__, central_bus.name);
2131da177e4SLinus Torvalds 		return result;
2141da177e4SLinus Torvalds 	}
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds 	result = request_resource(&iomem_resource, &local_broadcast);
2171da177e4SLinus Torvalds 	if (result < 0) {
2181da177e4SLinus Torvalds 		printk(KERN_ERR
2191da177e4SLinus Torvalds 		       "%s: failed to claim %s address space!\n",
2201da177e4SLinus Torvalds 		       __FILE__, local_broadcast.name);
2211da177e4SLinus Torvalds 		return result;
2221da177e4SLinus Torvalds 	}
2231da177e4SLinus Torvalds 
2241da177e4SLinus Torvalds 	result = request_resource(&iomem_resource, &global_broadcast);
2251da177e4SLinus Torvalds 	if (result < 0) {
2261da177e4SLinus Torvalds 		printk(KERN_ERR
2271da177e4SLinus Torvalds 		       "%s: failed to claim %s address space!\n",
2281da177e4SLinus Torvalds 		       __FILE__, global_broadcast.name);
2291da177e4SLinus Torvalds 		return result;
2301da177e4SLinus Torvalds 	}
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds 	return 0;
2331da177e4SLinus Torvalds }
2341da177e4SLinus Torvalds 
parisc_init(void)2351da177e4SLinus Torvalds static int __init parisc_init(void)
2361da177e4SLinus Torvalds {
237ec1fdc24SKyle McMartin 	u32 osid = (OS_ID_LINUX << 16);
2383f9edb53SThibaut Varene 
2391da177e4SLinus Torvalds 	parisc_init_resources();
2401da177e4SLinus Torvalds 	do_device_inventory();                  /* probe for hardware */
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds 	parisc_pdc_chassis_init();
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds 	/* set up a new led state on systems shipped LED State panel */
2451da177e4SLinus Torvalds 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BSTART);
2461da177e4SLinus Torvalds 
2473f9edb53SThibaut Varene 	/* tell PDC we're Linux. Nevermind failure. */
2483f9edb53SThibaut Varene 	pdc_stable_write(0x40, &osid, sizeof(osid));
2493f9edb53SThibaut Varene 
250741dc7bfSJohn David Anglin 	/* start with known state */
251741dc7bfSJohn David Anglin 	flush_cache_all_local();
252741dc7bfSJohn David Anglin 	flush_tlb_all_local(NULL);
253741dc7bfSJohn David Anglin 
2541da177e4SLinus Torvalds 	processor_init();
2553a7452b4SHelge Deller #ifdef CONFIG_SMP
2563a7452b4SHelge Deller 	pr_info("CPU(s): %d out of %d %s at %d.%06d MHz online\n",
2573a7452b4SHelge Deller 		num_online_cpus(), num_present_cpus(),
2583a7452b4SHelge Deller #else
2593a7452b4SHelge Deller 	pr_info("CPU(s): 1 x %s at %d.%06d MHz\n",
2603a7452b4SHelge Deller #endif
2611da177e4SLinus Torvalds 			boot_cpu_data.cpu_name,
2621da177e4SLinus Torvalds 			boot_cpu_data.cpu_hz / 1000000,
2631da177e4SLinus Torvalds 			boot_cpu_data.cpu_hz % 1000000	);
2641da177e4SLinus Torvalds 
265b37d1c18SMikulas Patocka #if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
266b37d1c18SMikulas Patocka 	/* Don't serialize TLB flushes if we run on one CPU only. */
267b37d1c18SMikulas Patocka 	if (num_online_cpus() == 1)
268b37d1c18SMikulas Patocka 		pa_serialize_tlb_flushes = 0;
269b37d1c18SMikulas Patocka #endif
270b37d1c18SMikulas Patocka 
2713847dab7SHelge Deller 	apply_alternatives_all();
2721da177e4SLinus Torvalds 	parisc_setup_cache_timing();
2731da177e4SLinus Torvalds 	return 0;
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds arch_initcall(parisc_init);
2761da177e4SLinus Torvalds 
start_parisc(void)27708b8a99bSHelge Deller void __init start_parisc(void)
278089d5528SKyle McMartin {
279089d5528SKyle McMartin 	int ret, cpunum;
280089d5528SKyle McMartin 	struct pdc_coproc_cfg coproc_cfg;
281089d5528SKyle McMartin 
282d006e95bSHelge Deller 	/* check QEMU/SeaBIOS marker in PAGE0 */
283d006e95bSHelge Deller 	running_on_qemu = (memcmp(&PAGE0->pad0, "SeaBIOS", 8) == 0);
284d006e95bSHelge Deller 
285089d5528SKyle McMartin 	cpunum = smp_processor_id();
286089d5528SKyle McMartin 
287bf7b4c1bSHelge Deller 	init_cpu_topology();
288bf7b4c1bSHelge Deller 
289089d5528SKyle McMartin 	set_firmware_width_unlocked();
290089d5528SKyle McMartin 
291089d5528SKyle McMartin 	ret = pdc_coproc_cfg_unlocked(&coproc_cfg);
292089d5528SKyle McMartin 	if (ret >= 0 && coproc_cfg.ccr_functional) {
293089d5528SKyle McMartin 		mtctl(coproc_cfg.ccr_functional, 10);
294089d5528SKyle McMartin 
295ef017bebSHelge Deller 		per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;
296ef017bebSHelge Deller 		per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;
297089d5528SKyle McMartin 
298089d5528SKyle McMartin 		asm volatile ("fstd	%fr0,8(%sp)");
299089d5528SKyle McMartin 	} else {
300089d5528SKyle McMartin 		panic("must have an fpu to boot linux");
301089d5528SKyle McMartin 	}
302089d5528SKyle McMartin 
3034182d0cdSHelge Deller 	early_trap_init(); /* initialize checksum of fault_vector */
3044182d0cdSHelge Deller 
305089d5528SKyle McMartin 	start_kernel();
306089d5528SKyle McMartin 	// not reached
307089d5528SKyle McMartin }
308