1 /* $NetBSD: arcbios.c,v 1.3 2001/07/08 23:57:09 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 41 #include <dev/cons.h> 42 43 #include <dev/arcbios/arcbios.h> 44 #include <dev/arcbios/arcbiosvar.h> 45 46 const struct arcbios_spb *ARCBIOS_SPB; 47 const struct arcbios_fv *ARCBIOS; 48 49 char arcbios_sysid_vendor[ARCBIOS_SYSID_FIELDLEN + 1]; 50 char arcbios_sysid_product[ARCBIOS_SYSID_FIELDLEN + 1]; 51 52 char arcbios_system_identifier[64 + 1]; 53 54 int arcbios_cngetc(dev_t); 55 void arcbios_cnputc(dev_t, int); 56 57 void arcbios_fetch_system_identifier(struct arcbios_component *, 58 struct arcbios_treewalk_context *); 59 60 struct consdev arcbios_cn = { 61 NULL, NULL, arcbios_cngetc, arcbios_cnputc, nullcnpollc, NULL, 62 NODEV, CN_NORMAL, 63 }; 64 65 /* 66 * arcbios_init: 67 * 68 * Initialize the ARC BIOS. 69 */ 70 int 71 arcbios_init(vaddr_t pblkva) 72 { 73 struct arcbios_sysid *sid; 74 75 ARCBIOS_SPB = (struct arcbios_spb *) pblkva; 76 77 switch (ARCBIOS_SPB->SPBSignature) { 78 case ARCBIOS_SPB_SIGNATURE: 79 case ARCBIOS_SPB_SIGNATURE_1: 80 /* Okay. */ 81 break; 82 83 default: 84 /* Don't know what this is. */ 85 return (1); 86 } 87 88 /* Initialize our pointer to the firmware vector. */ 89 ARCBIOS = ARCBIOS_SPB->FirmwareVector; 90 91 /* Initialize the bootstrap console. */ 92 cn_tab = &arcbios_cn; 93 94 /* 95 * Fetch the system ID. 96 */ 97 sid = (*ARCBIOS->GetSystemId)(); 98 if (sid != NULL) { 99 memcpy(arcbios_sysid_vendor, sid->VendorId, 100 sizeof(sid->VendorId)); 101 arcbios_sysid_vendor[sizeof(sid->VendorId)] = '\0'; 102 103 memcpy(arcbios_sysid_product, sid->ProductId, 104 sizeof(sid->ProductId)); 105 arcbios_sysid_product[sizeof(sid->ProductId)] = '\0'; 106 } 107 108 /* 109 * Fetch the identifier string from the `system' component. 110 * Machdep code will use this to initialize the system type. 111 */ 112 arcbios_tree_walk(arcbios_fetch_system_identifier, NULL); 113 114 return (0); 115 } 116 117 void 118 arcbios_fetch_system_identifier(struct arcbios_component *node, 119 struct arcbios_treewalk_context *atc) 120 { 121 122 switch (node->Class) { 123 case COMPONENT_CLASS_SystemClass: 124 arcbios_component_id_copy(node, 125 arcbios_system_identifier, 126 sizeof(arcbios_system_identifier)); 127 atc->atc_terminate = 1; 128 break; 129 130 default: 131 break; 132 } 133 } 134 135 /**************************************************************************** 136 * ARC component tree walking routines. 137 ****************************************************************************/ 138 139 static void 140 arcbios_subtree_walk(struct arcbios_component *node, 141 void (*func)(struct arcbios_component *, struct arcbios_treewalk_context *), 142 struct arcbios_treewalk_context *atc) 143 { 144 145 for (node = (*ARCBIOS->GetChild)(node); 146 node != NULL && atc->atc_terminate == 0; 147 node = (*ARCBIOS->GetPeer)(node)) { 148 (*func)(node, atc); 149 if (atc->atc_terminate) 150 return; 151 arcbios_subtree_walk(node, func, atc); 152 } 153 } 154 155 void 156 arcbios_tree_walk(void (*func)(struct arcbios_component *, 157 struct arcbios_treewalk_context *), void *cookie) 158 { 159 struct arcbios_treewalk_context atc; 160 161 atc.atc_cookie = cookie; 162 atc.atc_terminate = 0; 163 164 arcbios_subtree_walk(NULL, func, &atc); 165 } 166 167 void 168 arcbios_component_id_copy(struct arcbios_component *node, 169 char *dst, size_t dstsize) 170 { 171 172 dstsize--; 173 if (dstsize > node->IdentifierLength) 174 dstsize = node->IdentifierLength; 175 memcpy(dst, node->Identifier, dstsize); 176 dst[dstsize] = '\0'; 177 } 178 179 /**************************************************************************** 180 * Bootstrap console routines. 181 ****************************************************************************/ 182 183 int 184 arcbios_cngetc(dev_t dev) 185 { 186 uint32_t count; 187 char c; 188 189 (*ARCBIOS->Read)(ARCBIOS_STDIN, &c, 1, &count); 190 return (c); 191 } 192 193 void 194 arcbios_cnputc(dev_t dev, int c) 195 { 196 uint32_t count; 197 char ch = c; 198 199 (*ARCBIOS->Write)(ARCBIOS_STDOUT, &ch, 1, &count); 200 } 201