1 /* $NetBSD: arcbios.c,v 1.11 2005/12/11 12:21:14 christos Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: arcbios.c,v 1.11 2005/12/11 12:21:14 christos Exp $");
35 #include <sys/param.h>
37 #include <sys/systm.h>
41 #include <dev/arcbios/arcbios.h>
42 #include <dev/arcbios/arcbiosvar.h>
44 const struct arcbios_spb
*ARCBIOS_SPB
;
45 const struct arcbios_fv
*ARCBIOS
;
47 char arcbios_sysid_vendor
[ARCBIOS_SYSID_FIELDLEN
+ 1];
48 char arcbios_sysid_product
[ARCBIOS_SYSID_FIELDLEN
+ 1];
50 char arcbios_system_identifier
[64 + 1];
52 int arcbios_cngetc(dev_t
);
53 void arcbios_cnputc(dev_t
, int);
55 void arcbios_fetch_system_identifier(struct arcbios_component
*,
56 struct arcbios_treewalk_context
*);
58 struct consdev arcbios_cn
= {
59 NULL
, NULL
, arcbios_cngetc
, arcbios_cnputc
, nullcnpollc
,
60 NULL
, NULL
, NULL
, NODEV
, CN_NORMAL
,
63 extern const struct cdevsw arcbios_cdevsw
;
68 * Initialize the ARC BIOS.
71 arcbios_init(vaddr_t pblkva
)
74 struct arcbios_sysid
*sid
;
76 ARCBIOS_SPB
= (struct arcbios_spb
*) pblkva
;
78 switch (ARCBIOS_SPB
->SPBSignature
) {
79 case ARCBIOS_SPB_SIGNATURE
:
80 case ARCBIOS_SPB_SIGNATURE_1
:
85 /* Don't know what this is. */
89 /* Initialize our pointer to the firmware vector. */
90 ARCBIOS
= ARCBIOS_SPB
->FirmwareVector
;
92 /* Find the ARC BIOS console device major (needed by cnopen) */
93 maj
= cdevsw_lookup_major(&arcbios_cdevsw
);
95 arcbios_cn
.cn_dev
= makedev(maj
, 0);
97 /* Initialize the bootstrap console. */
101 * Fetch the system ID.
103 sid
= (*ARCBIOS
->GetSystemId
)();
105 memcpy(arcbios_sysid_vendor
, sid
->VendorId
,
106 sizeof(sid
->VendorId
));
107 arcbios_sysid_vendor
[sizeof(sid
->VendorId
)] = '\0';
109 memcpy(arcbios_sysid_product
, sid
->ProductId
,
110 sizeof(sid
->ProductId
));
111 arcbios_sysid_product
[sizeof(sid
->ProductId
)] = '\0';
115 * Fetch the identifier string from the `system' component.
116 * Machdep code will use this to initialize the system type.
118 arcbios_tree_walk(arcbios_fetch_system_identifier
, NULL
);
124 arcbios_fetch_system_identifier(struct arcbios_component
*node
,
125 struct arcbios_treewalk_context
*atc
)
128 switch (node
->Class
) {
129 case COMPONENT_CLASS_SystemClass
:
130 arcbios_component_id_copy(node
,
131 arcbios_system_identifier
,
132 sizeof(arcbios_system_identifier
));
133 atc
->atc_terminate
= 1;
141 /****************************************************************************
142 * ARC component tree walking routines.
143 ****************************************************************************/
146 arcbios_subtree_walk(struct arcbios_component
*node
,
147 void (*func
)(struct arcbios_component
*, struct arcbios_treewalk_context
*),
148 struct arcbios_treewalk_context
*atc
)
151 for (node
= (*ARCBIOS
->GetChild
)(node
);
152 node
!= NULL
&& atc
->atc_terminate
== 0;
153 node
= (*ARCBIOS
->GetPeer
)(node
)) {
155 if (atc
->atc_terminate
)
157 arcbios_subtree_walk(node
, func
, atc
);
162 arcbios_tree_walk(void (*func
)(struct arcbios_component
*,
163 struct arcbios_treewalk_context
*), void *cookie
)
165 struct arcbios_treewalk_context atc
;
167 atc
.atc_cookie
= cookie
;
168 atc
.atc_terminate
= 0;
170 arcbios_subtree_walk(NULL
, func
, &atc
);
174 arcbios_component_id_copy(struct arcbios_component
*node
,
175 char *dst
, size_t dstsize
)
179 if (dstsize
> node
->IdentifierLength
)
180 dstsize
= node
->IdentifierLength
;
181 memcpy(dst
, node
->Identifier
, dstsize
);
185 /****************************************************************************
186 * Bootstrap console routines.
187 ****************************************************************************/
190 arcbios_cngetc(dev_t dev
)
195 (*ARCBIOS
->Read
)(ARCBIOS_STDIN
, &c
, 1, &count
);
200 arcbios_cnputc(dev_t dev
, int c
)
205 (*ARCBIOS
->Write
)(ARCBIOS_STDOUT
, &ch
, 1, &count
);