xref: /linux/arch/mips/dec/prom/init.c (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * init.c: PROM library initialisation code.
4  *
5  * Copyright (C) 1998 Harald Koerfgen
6  * Copyright (C) 2002, 2004, 2026  Maciej W. Rozycki
7  */
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/linkage.h>
11 #include <linux/smp.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 
15 #include <asm/bootinfo.h>
16 #include <asm/cpu.h>
17 #include <asm/cpu-type.h>
18 #include <asm/processor.h>
19 
20 #include <asm/dec/prom.h>
21 
22 
23 #ifdef CONFIG_64BIT
24 unsigned long o32_stk[O32_STK_SIZE] __initdata = { 0 };
25 #endif
26 
27 int (*__rex_bootinit)(void);
28 int (*__rex_bootread)(void);
29 int (*__rex_getbitmap)(memmap *);
30 unsigned long *(*__rex_slot_address)(int);
31 void *(*__rex_gettcinfo)(void);
32 int (*__rex_getsysid)(void);
33 void (*__rex_clear_cache)(void);
34 
35 int (*__prom_getchar)(void);
36 char *(*__prom_getenv)(char *);
37 int (*__prom_printf)(char *, ...);
38 
39 int (*__pmax_open)(char*, int);
40 int (*__pmax_lseek)(int, long, int);
41 int (*__pmax_read)(int, void *, int);
42 int (*__pmax_close)(int);
43 
44 
45 /*
46  * Detect which PROM the DECSTATION has, and set the callback vectors
47  * appropriately.
48  */
49 static void __init which_prom(s32 magic, s32 *prom_vec)
50 {
51 	/*
52 	 * No sign of the REX PROM's magic number means we assume a non-REX
53 	 * machine (i.e. we're on a DS2100/3100, DS5100 or DS5000/2xx)
54 	 */
55 	if (prom_is_rex(magic)) {
56 		/*
57 		 * Set up prom abstraction structure with REX entry points.
58 		 */
59 		__rex_bootinit =
60 			(void *)(long)*(prom_vec + REX_PROM_BOOTINIT);
61 		__rex_bootread =
62 			(void *)(long)*(prom_vec + REX_PROM_BOOTREAD);
63 		__rex_getbitmap =
64 			(void *)(long)*(prom_vec + REX_PROM_GETBITMAP);
65 		__prom_getchar =
66 			(void *)(long)*(prom_vec + REX_PROM_GETCHAR);
67 		__prom_getenv =
68 			(void *)(long)*(prom_vec + REX_PROM_GETENV);
69 		__rex_getsysid =
70 			(void *)(long)*(prom_vec + REX_PROM_GETSYSID);
71 		__rex_gettcinfo =
72 			(void *)(long)*(prom_vec + REX_PROM_GETTCINFO);
73 		__prom_printf =
74 			(void *)(long)*(prom_vec + REX_PROM_PRINTF);
75 		__rex_slot_address =
76 			(void *)(long)*(prom_vec + REX_PROM_SLOTADDR);
77 		__rex_clear_cache =
78 			(void *)(long)*(prom_vec + REX_PROM_CLEARCACHE);
79 	} else {
80 		/*
81 		 * Set up prom abstraction structure with non-REX entry points.
82 		 */
83 		__prom_getchar = (void *)PMAX_PROM_GETCHAR;
84 		__prom_getenv = (void *)PMAX_PROM_GETENV;
85 		__prom_printf = (void *)PMAX_PROM_PRINTF;
86 		__pmax_open = (void *)PMAX_PROM_OPEN;
87 		__pmax_lseek = (void *)PMAX_PROM_LSEEK;
88 		__pmax_read = (void *)PMAX_PROM_READ;
89 		__pmax_close = (void *)PMAX_PROM_CLOSE;
90 	}
91 }
92 
93 void __init prom_init(void)
94 {
95 	extern void dec_machine_halt(void);
96 	static const char cpu_msg[] __initconst =
97 		"Sorry, this kernel is compiled for a wrong CPU type!\n";
98 	s32 argc = fw_arg0;
99 	s32 *argv = (void *)fw_arg1;
100 	u32 magic = fw_arg2;
101 	s32 *prom_vec = (void *)fw_arg3;
102 
103 	/*
104 	 * Determine which PROM we have
105 	 * (and therefore which machine we're on!)
106 	 */
107 	which_prom(magic, prom_vec);
108 
109 	if (prom_is_rex(magic))
110 		rex_clear_cache();
111 
112 	/* Register the early console.  */
113 	register_prom_console();
114 
115 	/* Were we compiled with the right CPU option? */
116 #if defined(CONFIG_CPU_R3000)
117 	if ((current_cpu_type() == CPU_R4000SC) ||
118 	    (current_cpu_type() == CPU_R4400SC)) {
119 		static const char r4k_msg[] __initconst =
120 			"Please recompile with \"CONFIG_CPU_R4X00 = y\".\n";
121 		printk(cpu_msg);
122 		printk(r4k_msg);
123 		dec_machine_halt();
124 	}
125 #endif
126 
127 #if defined(CONFIG_CPU_R4X00)
128 	if ((current_cpu_type() == CPU_R3000) ||
129 	    (current_cpu_type() == CPU_R3000A)) {
130 		static const char r3k_msg[] __initconst =
131 			"Please recompile with \"CONFIG_CPU_R3000 = y\".\n";
132 		printk(cpu_msg);
133 		printk(r3k_msg);
134 		dec_machine_halt();
135 	}
136 #endif
137 
138 	prom_meminit(magic);
139 	prom_identify_arch(magic);
140 	prom_init_cmdline(argc, argv, magic);
141 }
142