xref: /netbsd-src/sys/arch/ews4800mips/stand/common/boot_device.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1 /*	$NetBSD: boot_device.c,v 1.2 2008/04/28 20:23:18 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/types.h>
33 #include <machine/sbd.h>
34 #include "common.h"
35 
36 /*
37  * Get boot device and unit number. IPL sets it.
38  */
39 void __nvsram_type_a(int *, int *);
40 void __nvsram_type_b(int *, int *);
41 void __nvsram_type_c(int *, int *);
42 void __nvsram_type_d(int *, int *);
43 void __nvsram_type_e(int *, int *);
44 
45 void (*tab[])(int *, int *) = {
46 	__nvsram_type_c, /* ER */
47 	__nvsram_type_a, /* TR */
48 	__nvsram_type_a, /* SR */
49 	__nvsram_type_b, /* TR+2D */
50 	__nvsram_type_b, /* TR+3D */
51 	__nvsram_type_c, /* LR */
52 	__nvsram_type_c, /* ER2 */
53 	__nvsram_type_d, /* TR2 */
54 	__nvsram_type_c, /* ER1V */
55 	__nvsram_type_e, /* LRC */
56 	__nvsram_type_c, /* SR2 */
57 	__nvsram_type_d, /* ER+ */
58 	__nvsram_type_c, /* TR2+ */
59 	__nvsram_type_d, /* ER2A */
60 };
61 
62 void
boot_device(int * type,int * unit,int * fd_format)63 boot_device(int *type, int *unit, int *fd_format)
64 {
65 	int i;
66 
67 	*fd_format = SBD_INFO->fdd == 1 ? FD_FORMAT_2HD : FD_FORMAT_2D;
68 	i  = SBD_INFO->machine - 0x1010;
69 	if (i < sizeof tab / sizeof tab[0])
70 		return tab[i](type, unit);
71 
72 	return __nvsram_type_e(type, unit);
73 }
74 
75 void
__nvsram_type_a(int * type,int * unit)76 __nvsram_type_a(int *type, int *unit)
77 {
78 	/* TR, SR */
79 	*type = NVSRAM_BOOTDEV_HARDDISK;
80 	*unit = 0;
81 }
82 
83 void
__nvsram_type_b(int * type,int * unit)84 __nvsram_type_b(int *type, int *unit)
85 {
86 	/* TR+2D, TR+3D */
87 	*type = NVSRAM_BOOTDEV_HARDDISK;
88 	*unit = *(uint8_t *)0xba021808;
89 }
90 
91 void
__nvsram_type_c(int * type,int * unit)92 __nvsram_type_c(int *type, int *unit)
93 {
94 	/* ER, LR, ER2, ER1V, SR2, TR2+ */
95 	*type = NVSRAM_BOOTDEV_HARDDISK;
96 	*unit = *(uint8_t *)0xbb012088;
97 }
98 
99 void
__nvsram_type_d(int * type,int * unit)100 __nvsram_type_d(int *type, int *unit)
101 {
102 	/* TR2, ER+, ER2A */
103 	*type = *(uint8_t *)0xbb023030;
104 	*unit = *(uint8_t *)0xbb023034;
105 }
106 
107 void
__nvsram_type_e(int * type,int * unit)108 __nvsram_type_e(int *type, int *unit)
109 {
110 	/* LRC, TR2A, LER, LER_L, LER_H, MUS, LT, LT_L ... */
111 	*type = *(uint8_t *)0xbe493030;
112 	*unit = *(uint8_t *)0xbe493034;
113 }
114