Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
66d857b0 GU |
2 | /* |
3 | * linux/arch/m68k/kernel/setup.c | |
4 | * | |
5 | * Copyright (C) 1995 Hamish Macdonald | |
6 | */ | |
7 | ||
8 | /* | |
9 | * This file handles the architecture-dependent parts of system setup | |
10 | */ | |
11 | ||
12 | #include <linux/kernel.h> | |
13 | #include <linux/mm.h> | |
14 | #include <linux/sched.h> | |
15 | #include <linux/delay.h> | |
16 | #include <linux/interrupt.h> | |
17 | #include <linux/fs.h> | |
18 | #include <linux/console.h> | |
66d857b0 GU |
19 | #include <linux/errno.h> |
20 | #include <linux/string.h> | |
21 | #include <linux/init.h> | |
1008a115 | 22 | #include <linux/memblock.h> |
66d857b0 GU |
23 | #include <linux/proc_fs.h> |
24 | #include <linux/seq_file.h> | |
25 | #include <linux/module.h> | |
d3b41b6b | 26 | #include <linux/nvram.h> |
66d857b0 GU |
27 | #include <linux/initrd.h> |
28 | ||
29 | #include <asm/bootinfo.h> | |
abe48101 | 30 | #include <asm/byteorder.h> |
66d857b0 GU |
31 | #include <asm/sections.h> |
32 | #include <asm/setup.h> | |
33 | #include <asm/fpu.h> | |
34 | #include <asm/irq.h> | |
35 | #include <asm/io.h> | |
36 | #include <asm/machdep.h> | |
37 | #ifdef CONFIG_AMIGA | |
38 | #include <asm/amigahw.h> | |
39 | #endif | |
66d857b0 | 40 | #include <asm/atarihw.h> |
d3b41b6b | 41 | #ifdef CONFIG_ATARI |
66d857b0 GU |
42 | #include <asm/atari_stram.h> |
43 | #endif | |
44 | #ifdef CONFIG_SUN3X | |
45 | #include <asm/dvma.h> | |
46 | #endif | |
d3b41b6b | 47 | #include <asm/macintosh.h> |
66d857b0 | 48 | #include <asm/natfeat.h> |
91d7b75a | 49 | #include <asm/config.h> |
66d857b0 GU |
50 | |
51 | #if !FPSTATESIZE || !NR_IRQS | |
52 | #warning No CPU/platform type selected, your kernel will not work! | |
53 | #warning Are you building an allnoconfig kernel? | |
54 | #endif | |
55 | ||
56 | unsigned long m68k_machtype; | |
57 | EXPORT_SYMBOL(m68k_machtype); | |
58 | unsigned long m68k_cputype; | |
59 | EXPORT_SYMBOL(m68k_cputype); | |
60 | unsigned long m68k_fputype; | |
61 | unsigned long m68k_mmutype; | |
62 | EXPORT_SYMBOL(m68k_mmutype); | |
63 | #ifdef CONFIG_VME | |
64 | unsigned long vme_brdtype; | |
65 | EXPORT_SYMBOL(vme_brdtype); | |
66 | #endif | |
67 | ||
68 | int m68k_is040or060; | |
69 | EXPORT_SYMBOL(m68k_is040or060); | |
70 | ||
71 | extern unsigned long availmem; | |
72 | ||
73 | int m68k_num_memory; | |
74 | EXPORT_SYMBOL(m68k_num_memory); | |
75 | int m68k_realnum_memory; | |
76 | EXPORT_SYMBOL(m68k_realnum_memory); | |
77 | unsigned long m68k_memoffset; | |
79930084 | 78 | struct m68k_mem_info m68k_memory[NUM_MEMINFO]; |
66d857b0 GU |
79 | EXPORT_SYMBOL(m68k_memory); |
80 | ||
79930084 | 81 | static struct m68k_mem_info m68k_ramdisk __initdata; |
66d857b0 | 82 | |
a4df02a2 | 83 | static char m68k_command_line[CL_SIZE] __initdata; |
66d857b0 | 84 | |
f9a01539 | 85 | void (*mach_sched_init) (void) __initdata = NULL; |
66d857b0 GU |
86 | /* machine dependent irq functions */ |
87 | void (*mach_init_IRQ) (void) __initdata = NULL; | |
88 | void (*mach_get_model) (char *model); | |
89 | void (*mach_get_hardware_list) (struct seq_file *m); | |
90 | /* machine dependent timer functions */ | |
66d857b0 GU |
91 | int (*mach_hwclk) (int, struct rtc_time*); |
92 | EXPORT_SYMBOL(mach_hwclk); | |
66d857b0 GU |
93 | unsigned int (*mach_get_ss)(void); |
94 | int (*mach_get_rtc_pll)(struct rtc_pll_info *); | |
95 | int (*mach_set_rtc_pll)(struct rtc_pll_info *); | |
96 | EXPORT_SYMBOL(mach_get_ss); | |
97 | EXPORT_SYMBOL(mach_get_rtc_pll); | |
98 | EXPORT_SYMBOL(mach_set_rtc_pll); | |
99 | void (*mach_reset)( void ); | |
100 | void (*mach_halt)( void ); | |
101 | void (*mach_power_off)( void ); | |
66d857b0 GU |
102 | #ifdef CONFIG_HEARTBEAT |
103 | void (*mach_heartbeat) (int); | |
104 | EXPORT_SYMBOL(mach_heartbeat); | |
105 | #endif | |
106 | #ifdef CONFIG_M68K_L2_CACHE | |
107 | void (*mach_l2_flush) (int); | |
108 | #endif | |
66d857b0 GU |
109 | #if defined(CONFIG_ISA) && defined(MULTI_ISA) |
110 | int isa_type; | |
111 | int isa_sex; | |
112 | EXPORT_SYMBOL(isa_type); | |
113 | EXPORT_SYMBOL(isa_sex); | |
114 | #endif | |
115 | ||
66d857b0 GU |
116 | #define MASK_256K 0xfffc0000 |
117 | ||
118 | extern void paging_init(void); | |
119 | ||
120 | static void __init m68k_parse_bootinfo(const struct bi_record *record) | |
121 | { | |
abe48101 GU |
122 | uint16_t tag; |
123 | ||
7bc1e4d8 GU |
124 | save_bootinfo(record); |
125 | ||
abe48101 | 126 | while ((tag = be16_to_cpu(record->tag)) != BI_LAST) { |
66d857b0 | 127 | int unknown = 0; |
abe48101 GU |
128 | const void *data = record->data; |
129 | uint16_t size = be16_to_cpu(record->size); | |
66d857b0 | 130 | |
abe48101 | 131 | switch (tag) { |
66d857b0 GU |
132 | case BI_MACHTYPE: |
133 | case BI_CPUTYPE: | |
134 | case BI_FPUTYPE: | |
135 | case BI_MMUTYPE: | |
136 | /* Already set up by head.S */ | |
137 | break; | |
138 | ||
139 | case BI_MEMCHUNK: | |
140 | if (m68k_num_memory < NUM_MEMINFO) { | |
abe48101 GU |
141 | const struct mem_info *m = data; |
142 | m68k_memory[m68k_num_memory].addr = | |
143 | be32_to_cpu(m->addr); | |
144 | m68k_memory[m68k_num_memory].size = | |
145 | be32_to_cpu(m->size); | |
66d857b0 GU |
146 | m68k_num_memory++; |
147 | } else | |
6074a139 GU |
148 | pr_warn("%s: too many memory chunks\n", |
149 | __func__); | |
66d857b0 GU |
150 | break; |
151 | ||
152 | case BI_RAMDISK: | |
abe48101 GU |
153 | { |
154 | const struct mem_info *m = data; | |
155 | m68k_ramdisk.addr = be32_to_cpu(m->addr); | |
156 | m68k_ramdisk.size = be32_to_cpu(m->size); | |
157 | } | |
66d857b0 GU |
158 | break; |
159 | ||
160 | case BI_COMMAND_LINE: | |
abe48101 | 161 | strlcpy(m68k_command_line, data, |
66d857b0 GU |
162 | sizeof(m68k_command_line)); |
163 | break; | |
164 | ||
165 | default: | |
166 | if (MACH_IS_AMIGA) | |
167 | unknown = amiga_parse_bootinfo(record); | |
168 | else if (MACH_IS_ATARI) | |
169 | unknown = atari_parse_bootinfo(record); | |
170 | else if (MACH_IS_MAC) | |
171 | unknown = mac_parse_bootinfo(record); | |
172 | else if (MACH_IS_Q40) | |
173 | unknown = q40_parse_bootinfo(record); | |
174 | else if (MACH_IS_BVME6000) | |
175 | unknown = bvme6000_parse_bootinfo(record); | |
176 | else if (MACH_IS_MVME16x) | |
177 | unknown = mvme16x_parse_bootinfo(record); | |
178 | else if (MACH_IS_MVME147) | |
179 | unknown = mvme147_parse_bootinfo(record); | |
180 | else if (MACH_IS_HP300) | |
181 | unknown = hp300_parse_bootinfo(record); | |
182 | else if (MACH_IS_APOLLO) | |
183 | unknown = apollo_parse_bootinfo(record); | |
05d51e42 LV |
184 | else if (MACH_IS_VIRT) |
185 | unknown = virt_parse_bootinfo(record); | |
66d857b0 GU |
186 | else |
187 | unknown = 1; | |
188 | } | |
189 | if (unknown) | |
6074a139 | 190 | pr_warn("%s: unknown tag 0x%04x ignored\n", __func__, |
abe48101 GU |
191 | tag); |
192 | record = (struct bi_record *)((unsigned long)record + size); | |
66d857b0 GU |
193 | } |
194 | ||
195 | m68k_realnum_memory = m68k_num_memory; | |
196 | #ifdef CONFIG_SINGLE_MEMORY_CHUNK | |
197 | if (m68k_num_memory > 1) { | |
6074a139 GU |
198 | pr_warn("%s: ignoring last %i chunks of physical memory\n", |
199 | __func__, (m68k_num_memory - 1)); | |
66d857b0 GU |
200 | m68k_num_memory = 1; |
201 | } | |
202 | #endif | |
203 | } | |
204 | ||
205 | void __init setup_arch(char **cmdline_p) | |
206 | { | |
29a20203 | 207 | /* The bootinfo is located right after the kernel */ |
37314540 GU |
208 | if (!CPU_IS_COLDFIRE) |
209 | m68k_parse_bootinfo((const struct bi_record *)_end); | |
66d857b0 GU |
210 | |
211 | if (CPU_IS_040) | |
212 | m68k_is040or060 = 4; | |
213 | else if (CPU_IS_060) | |
214 | m68k_is040or060 = 6; | |
215 | ||
216 | /* FIXME: m68k_fputype is passed in by Penguin booter, which can | |
217 | * be confused by software FPU emulation. BEWARE. | |
218 | * We should really do our own FPU check at startup. | |
219 | * [what do we do with buggy 68LC040s? if we have problems | |
220 | * with them, we should add a test to check_bugs() below] */ | |
6d3ec805 | 221 | #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU_ONLY) |
66d857b0 | 222 | /* clear the fpu if we have one */ |
0a2796da | 223 | if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060|FPU_COLDFIRE)) { |
66d857b0 GU |
224 | volatile int zero = 0; |
225 | asm volatile ("frestore %0" : : "m" (zero)); | |
226 | } | |
227 | #endif | |
228 | ||
229 | if (CPU_IS_060) { | |
230 | u32 pcr; | |
231 | ||
232 | asm (".chip 68060; movec %%pcr,%0; .chip 68k" | |
233 | : "=d" (pcr)); | |
234 | if (((pcr >> 8) & 0xff) <= 5) { | |
6074a139 | 235 | pr_warn("Enabling workaround for errata I14\n"); |
66d857b0 GU |
236 | asm (".chip 68060; movec %0,%%pcr; .chip 68k" |
237 | : : "d" (pcr | 0x20)); | |
238 | } | |
239 | } | |
240 | ||
ed408db1 | 241 | setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end); |
66d857b0 | 242 | |
d1db9120 GU |
243 | #if defined(CONFIG_BOOTPARAM) |
244 | strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE); | |
245 | m68k_command_line[CL_SIZE - 1] = 0; | |
246 | #endif /* CONFIG_BOOTPARAM */ | |
aa5ac789 | 247 | process_uboot_commandline(&m68k_command_line[0], CL_SIZE); |
66d857b0 GU |
248 | *cmdline_p = m68k_command_line; |
249 | memcpy(boot_command_line, *cmdline_p, CL_SIZE); | |
250 | ||
251 | parse_early_param(); | |
252 | ||
66d857b0 GU |
253 | switch (m68k_machtype) { |
254 | #ifdef CONFIG_AMIGA | |
255 | case MACH_AMIGA: | |
256 | config_amiga(); | |
257 | break; | |
258 | #endif | |
259 | #ifdef CONFIG_ATARI | |
260 | case MACH_ATARI: | |
261 | config_atari(); | |
262 | break; | |
263 | #endif | |
264 | #ifdef CONFIG_MAC | |
265 | case MACH_MAC: | |
266 | config_mac(); | |
267 | break; | |
268 | #endif | |
269 | #ifdef CONFIG_SUN3 | |
270 | case MACH_SUN3: | |
271 | config_sun3(); | |
272 | break; | |
273 | #endif | |
274 | #ifdef CONFIG_APOLLO | |
275 | case MACH_APOLLO: | |
276 | config_apollo(); | |
277 | break; | |
278 | #endif | |
279 | #ifdef CONFIG_MVME147 | |
280 | case MACH_MVME147: | |
281 | config_mvme147(); | |
282 | break; | |
283 | #endif | |
284 | #ifdef CONFIG_MVME16x | |
285 | case MACH_MVME16x: | |
286 | config_mvme16x(); | |
287 | break; | |
288 | #endif | |
289 | #ifdef CONFIG_BVME6000 | |
290 | case MACH_BVME6000: | |
291 | config_bvme6000(); | |
292 | break; | |
293 | #endif | |
294 | #ifdef CONFIG_HP300 | |
295 | case MACH_HP300: | |
296 | config_hp300(); | |
297 | break; | |
298 | #endif | |
299 | #ifdef CONFIG_Q40 | |
300 | case MACH_Q40: | |
301 | config_q40(); | |
302 | break; | |
303 | #endif | |
304 | #ifdef CONFIG_SUN3X | |
305 | case MACH_SUN3X: | |
306 | config_sun3x(); | |
307 | break; | |
37314540 GU |
308 | #endif |
309 | #ifdef CONFIG_COLDFIRE | |
310 | case MACH_M54XX: | |
81d33350 | 311 | case MACH_M5441X: |
34fa9b21 GU |
312 | cf_bootmem_alloc(); |
313 | cf_mmu_context_init(); | |
37314540 GU |
314 | config_BSP(NULL, 0); |
315 | break; | |
05d51e42 LV |
316 | #endif |
317 | #ifdef CONFIG_VIRT | |
318 | case MACH_VIRT: | |
319 | config_virt(); | |
320 | break; | |
66d857b0 GU |
321 | #endif |
322 | default: | |
323 | panic("No configuration setup"); | |
324 | } | |
325 | ||
66d857b0 GU |
326 | #ifdef CONFIG_BLK_DEV_INITRD |
327 | if (m68k_ramdisk.size) { | |
1008a115 | 328 | memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size); |
66d857b0 GU |
329 | initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr); |
330 | initrd_end = initrd_start + m68k_ramdisk.size; | |
6074a139 | 331 | pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end); |
66d857b0 GU |
332 | } |
333 | #endif | |
334 | ||
376e3fde FT |
335 | paging_init(); |
336 | ||
337 | #ifdef CONFIG_NATFEAT | |
338 | nf_init(); | |
339 | #endif | |
340 | ||
66d857b0 GU |
341 | #ifdef CONFIG_ATARI |
342 | if (MACH_IS_ATARI) | |
343 | atari_stram_reserve_pages((void *)availmem); | |
344 | #endif | |
345 | #ifdef CONFIG_SUN3X | |
346 | if (MACH_IS_SUN3X) { | |
347 | dvma_init(); | |
348 | } | |
349 | #endif | |
350 | ||
66d857b0 GU |
351 | /* set ISA defs early as possible */ |
352 | #if defined(CONFIG_ISA) && defined(MULTI_ISA) | |
353 | if (MACH_IS_Q40) { | |
354 | isa_type = ISA_TYPE_Q40; | |
355 | isa_sex = 0; | |
356 | } | |
357 | #ifdef CONFIG_AMIGA_PCMCIA | |
358 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)) { | |
359 | isa_type = ISA_TYPE_AG; | |
360 | isa_sex = 1; | |
361 | } | |
362 | #endif | |
84b16b7b MS |
363 | #ifdef CONFIG_ATARI_ROM_ISA |
364 | if (MACH_IS_ATARI) { | |
365 | isa_type = ISA_TYPE_ENEC; | |
366 | isa_sex = 0; | |
367 | } | |
368 | #endif | |
66d857b0 GU |
369 | #endif |
370 | } | |
371 | ||
372 | static int show_cpuinfo(struct seq_file *m, void *v) | |
373 | { | |
374 | const char *cpu, *mmu, *fpu; | |
375 | unsigned long clockfreq, clockfactor; | |
376 | ||
377 | #define LOOP_CYCLES_68020 (8) | |
378 | #define LOOP_CYCLES_68030 (8) | |
379 | #define LOOP_CYCLES_68040 (3) | |
380 | #define LOOP_CYCLES_68060 (1) | |
060632ad | 381 | #define LOOP_CYCLES_COLDFIRE (2) |
66d857b0 GU |
382 | |
383 | if (CPU_IS_020) { | |
384 | cpu = "68020"; | |
385 | clockfactor = LOOP_CYCLES_68020; | |
386 | } else if (CPU_IS_030) { | |
387 | cpu = "68030"; | |
388 | clockfactor = LOOP_CYCLES_68030; | |
389 | } else if (CPU_IS_040) { | |
390 | cpu = "68040"; | |
391 | clockfactor = LOOP_CYCLES_68040; | |
392 | } else if (CPU_IS_060) { | |
393 | cpu = "68060"; | |
394 | clockfactor = LOOP_CYCLES_68060; | |
060632ad GU |
395 | } else if (CPU_IS_COLDFIRE) { |
396 | cpu = "ColdFire"; | |
397 | clockfactor = LOOP_CYCLES_COLDFIRE; | |
66d857b0 GU |
398 | } else { |
399 | cpu = "680x0"; | |
400 | clockfactor = 0; | |
401 | } | |
402 | ||
403 | #ifdef CONFIG_M68KFPU_EMU_ONLY | |
404 | fpu = "none(soft float)"; | |
405 | #else | |
406 | if (m68k_fputype & FPU_68881) | |
407 | fpu = "68881"; | |
408 | else if (m68k_fputype & FPU_68882) | |
409 | fpu = "68882"; | |
410 | else if (m68k_fputype & FPU_68040) | |
411 | fpu = "68040"; | |
412 | else if (m68k_fputype & FPU_68060) | |
413 | fpu = "68060"; | |
414 | else if (m68k_fputype & FPU_SUNFPA) | |
415 | fpu = "Sun FPA"; | |
060632ad GU |
416 | else if (m68k_fputype & FPU_COLDFIRE) |
417 | fpu = "ColdFire"; | |
66d857b0 GU |
418 | else |
419 | fpu = "none"; | |
420 | #endif | |
421 | ||
422 | if (m68k_mmutype & MMU_68851) | |
423 | mmu = "68851"; | |
424 | else if (m68k_mmutype & MMU_68030) | |
425 | mmu = "68030"; | |
426 | else if (m68k_mmutype & MMU_68040) | |
427 | mmu = "68040"; | |
428 | else if (m68k_mmutype & MMU_68060) | |
429 | mmu = "68060"; | |
430 | else if (m68k_mmutype & MMU_SUN3) | |
431 | mmu = "Sun-3"; | |
432 | else if (m68k_mmutype & MMU_APOLLO) | |
433 | mmu = "Apollo"; | |
060632ad GU |
434 | else if (m68k_mmutype & MMU_COLDFIRE) |
435 | mmu = "ColdFire"; | |
66d857b0 GU |
436 | else |
437 | mmu = "unknown"; | |
438 | ||
439 | clockfreq = loops_per_jiffy * HZ * clockfactor; | |
440 | ||
441 | seq_printf(m, "CPU:\t\t%s\n" | |
442 | "MMU:\t\t%s\n" | |
443 | "FPU:\t\t%s\n" | |
444 | "Clocking:\t%lu.%1luMHz\n" | |
445 | "BogoMips:\t%lu.%02lu\n" | |
446 | "Calibration:\t%lu loops\n", | |
447 | cpu, mmu, fpu, | |
448 | clockfreq/1000000,(clockfreq/100000)%10, | |
449 | loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100, | |
450 | loops_per_jiffy); | |
451 | return 0; | |
452 | } | |
453 | ||
454 | static void *c_start(struct seq_file *m, loff_t *pos) | |
455 | { | |
456 | return *pos < 1 ? (void *)1 : NULL; | |
457 | } | |
458 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | |
459 | { | |
460 | ++*pos; | |
461 | return NULL; | |
462 | } | |
463 | static void c_stop(struct seq_file *m, void *v) | |
464 | { | |
465 | } | |
466 | const struct seq_operations cpuinfo_op = { | |
467 | .start = c_start, | |
468 | .next = c_next, | |
469 | .stop = c_stop, | |
470 | .show = show_cpuinfo, | |
471 | }; | |
472 | ||
473 | #ifdef CONFIG_PROC_HARDWARE | |
474 | static int hardware_proc_show(struct seq_file *m, void *v) | |
475 | { | |
476 | char model[80]; | |
477 | unsigned long mem; | |
478 | int i; | |
479 | ||
480 | if (mach_get_model) | |
481 | mach_get_model(model); | |
482 | else | |
483 | strcpy(model, "Unknown m68k"); | |
484 | ||
485 | seq_printf(m, "Model:\t\t%s\n", model); | |
486 | for (mem = 0, i = 0; i < m68k_num_memory; i++) | |
487 | mem += m68k_memory[i].size; | |
488 | seq_printf(m, "System Memory:\t%ldK\n", mem >> 10); | |
489 | ||
490 | if (mach_get_hardware_list) | |
491 | mach_get_hardware_list(m); | |
492 | ||
493 | return 0; | |
494 | } | |
495 | ||
66d857b0 GU |
496 | static int __init proc_hardware_init(void) |
497 | { | |
3f3942ac | 498 | proc_create_single("hardware", 0, NULL, hardware_proc_show); |
66d857b0 GU |
499 | return 0; |
500 | } | |
501 | module_init(proc_hardware_init); | |
502 | #endif | |
503 | ||
504 | void check_bugs(void) | |
505 | { | |
2a744007 | 506 | #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU) |
66d857b0 | 507 | if (m68k_fputype == 0) { |
6074a139 | 508 | pr_emerg("*** YOU DO NOT HAVE A FLOATING POINT UNIT, " |
66d857b0 | 509 | "WHICH IS REQUIRED BY LINUX/M68K ***\n"); |
6074a139 | 510 | pr_emerg("Upgrade your hardware or join the FPU " |
66d857b0 GU |
511 | "emulation project\n"); |
512 | panic("no FPU"); | |
513 | } | |
514 | #endif /* !CONFIG_M68KFPU_EMU */ | |
515 | } | |
516 | ||
517 | #ifdef CONFIG_ADB | |
518 | static int __init adb_probe_sync_enable (char *str) { | |
519 | extern int __adb_probe_sync; | |
520 | __adb_probe_sync = 1; | |
521 | return 1; | |
522 | } | |
523 | ||
524 | __setup("adb_sync", adb_probe_sync_enable); | |
525 | #endif /* CONFIG_ADB */ | |
d3b41b6b FT |
526 | |
527 | #if IS_ENABLED(CONFIG_NVRAM) | |
528 | #ifdef CONFIG_MAC | |
529 | static unsigned char m68k_nvram_read_byte(int addr) | |
530 | { | |
531 | if (MACH_IS_MAC) | |
532 | return mac_pram_read_byte(addr); | |
533 | return 0xff; | |
534 | } | |
535 | ||
536 | static void m68k_nvram_write_byte(unsigned char val, int addr) | |
537 | { | |
538 | if (MACH_IS_MAC) | |
539 | mac_pram_write_byte(val, addr); | |
540 | } | |
541 | #endif /* CONFIG_MAC */ | |
542 | ||
543 | #ifdef CONFIG_ATARI | |
544 | static ssize_t m68k_nvram_read(char *buf, size_t count, loff_t *ppos) | |
545 | { | |
546 | if (MACH_IS_ATARI) | |
547 | return atari_nvram_read(buf, count, ppos); | |
548 | else if (MACH_IS_MAC) | |
549 | return nvram_read_bytes(buf, count, ppos); | |
550 | return -EINVAL; | |
551 | } | |
552 | ||
553 | static ssize_t m68k_nvram_write(char *buf, size_t count, loff_t *ppos) | |
554 | { | |
555 | if (MACH_IS_ATARI) | |
556 | return atari_nvram_write(buf, count, ppos); | |
557 | else if (MACH_IS_MAC) | |
558 | return nvram_write_bytes(buf, count, ppos); | |
559 | return -EINVAL; | |
560 | } | |
561 | ||
562 | static long m68k_nvram_set_checksum(void) | |
563 | { | |
564 | if (MACH_IS_ATARI) | |
565 | return atari_nvram_set_checksum(); | |
566 | return -EINVAL; | |
567 | } | |
568 | ||
569 | static long m68k_nvram_initialize(void) | |
570 | { | |
571 | if (MACH_IS_ATARI) | |
572 | return atari_nvram_initialize(); | |
573 | return -EINVAL; | |
574 | } | |
575 | #endif /* CONFIG_ATARI */ | |
576 | ||
577 | static ssize_t m68k_nvram_get_size(void) | |
578 | { | |
579 | if (MACH_IS_ATARI) | |
580 | return atari_nvram_get_size(); | |
581 | else if (MACH_IS_MAC) | |
582 | return mac_pram_get_size(); | |
583 | return -ENODEV; | |
584 | } | |
585 | ||
586 | /* Atari device drivers call .read (to get checksum validation) whereas | |
587 | * Mac and PowerMac device drivers just use .read_byte. | |
588 | */ | |
589 | const struct nvram_ops arch_nvram_ops = { | |
590 | #ifdef CONFIG_MAC | |
591 | .read_byte = m68k_nvram_read_byte, | |
592 | .write_byte = m68k_nvram_write_byte, | |
593 | #endif | |
594 | #ifdef CONFIG_ATARI | |
595 | .read = m68k_nvram_read, | |
596 | .write = m68k_nvram_write, | |
597 | .set_checksum = m68k_nvram_set_checksum, | |
598 | .initialize = m68k_nvram_initialize, | |
599 | #endif | |
600 | .get_size = m68k_nvram_get_size, | |
601 | }; | |
602 | EXPORT_SYMBOL(arch_nvram_ops); | |
603 | #endif /* CONFIG_NVRAM */ |