1 /* $NetBSD: openbios.c,v 1.4 2007/02/22 16:57:57 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Shigeyuki Fukushima. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 3. The name of the author may not be used to endorse or promote 17 * products derived from this software without specific prior 18 * written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: openbios.c,v 1.4 2007/02/22 16:57:57 thorpej Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 39 #include <machine/cpu.h> 40 41 #include <powerpc/ibm4xx/openbios.h> 42 43 /* 44 * Board configuration structure from the OpenBIOS. 45 * 46 * Supported (XXX): 47 * 405GPr 1.2 ROM Monitor (5/25/02) 48 */ 49 struct board_bios_data { 50 unsigned char usr_config_ver[4]; 51 unsigned char rom_sw_ver[30]; 52 unsigned int mem_size; 53 unsigned char mac_address_local[6]; 54 unsigned char mac_address_pci[6]; 55 unsigned int processor_speed; 56 unsigned int plb_speed; 57 unsigned int pci_speed; 58 }; 59 60 static struct board_bios_data board_bios; 61 62 void 63 openbios_board_init(void *info_block, u_int startkernel) 64 { 65 66 /* Initialize cache info for memcpy, etc. */ 67 cpu_probe_cache(); 68 69 /* Save info block */ 70 memcpy(&board_bios, info_block, sizeof(board_bios)); 71 } 72 73 unsigned int 74 openbios_board_memsize_get(void) 75 { 76 return board_bios.mem_size; 77 } 78 79 void 80 openbios_board_info_set(void) 81 { 82 prop_number_t pn; 83 prop_string_t ps; 84 prop_data_t pd; 85 86 /* Initialize board properties database */ 87 board_info_init(); 88 89 ps = prop_string_create_cstring_nocopy(board_bios.usr_config_ver); 90 KASSERT(ps != NULL); 91 if (prop_dictionary_set(board_properties, "user-config-version", 92 ps) == false) 93 panic("setting user-config-version"); 94 prop_object_release(ps); 95 96 ps = prop_string_create_cstring_nocopy(board_bios.rom_sw_ver); 97 KASSERT(ps != NULL); 98 if (prop_dictionary_set(board_properties, "rom-software-version", 99 ps) == false) 100 panic("setting rom-software-version"); 101 prop_object_release(ps); 102 103 pn = prop_number_create_integer(board_bios.mem_size); 104 KASSERT(pn != NULL); 105 if (prop_dictionary_set(board_properties, "mem-size", pn) == false) 106 panic("setting mem-size"); 107 prop_object_release(pn); 108 109 pd = prop_data_create_data_nocopy(board_bios.mac_address_local, 110 sizeof(board_bios.mac_address_local)); 111 KASSERT(pd != NULL); 112 if (prop_dictionary_set(board_properties, "emac0-mac-addr", 113 pd) == false) 114 panic("setting emac0-mac-addr"); 115 prop_object_release(pd); 116 117 pd = prop_data_create_data_nocopy(board_bios.mac_address_pci, 118 sizeof(board_bios.mac_address_pci)); 119 KASSERT(pd != NULL); 120 if (prop_dictionary_set(board_properties, "sip0-mac-addr", 121 pd) == false) 122 panic("setting sip0-mac-addr"); 123 prop_object_release(pd); 124 125 pn = prop_number_create_integer(board_bios.processor_speed); 126 KASSERT(pn != NULL); 127 if (prop_dictionary_set(board_properties, "processor-frequency", 128 pn) == false) 129 panic("setting processor-frequency"); 130 prop_object_release(pn); 131 132 pn = prop_number_create_integer(board_bios.plb_speed); 133 KASSERT(pn != NULL); 134 if (prop_dictionary_set(board_properties, "plb-frequency", pn) == false) 135 panic("setting plb-frequency"); 136 prop_object_release(pn); 137 138 pn = prop_number_create_integer(board_bios.pci_speed); 139 KASSERT(pn != NULL); 140 if (prop_dictionary_set(board_properties, "pci-frequency", pn) == false) 141 panic("setting pci-frequency"); 142 prop_object_release(pn); 143 } 144 145 146 void 147 openbios_board_print(void) 148 { 149 150 printf("Board config data:\n"); 151 printf(" usr_config_ver = %s\n", board_bios.usr_config_ver); 152 printf(" rom_sw_ver = %s\n", board_bios.rom_sw_ver); 153 printf(" mem_size = %u\n", board_bios.mem_size); 154 printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n", 155 board_bios.mac_address_local[0], board_bios.mac_address_local[1], 156 board_bios.mac_address_local[2], board_bios.mac_address_local[3], 157 board_bios.mac_address_local[4], board_bios.mac_address_local[5]); 158 printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n", 159 board_bios.mac_address_pci[0], board_bios.mac_address_pci[1], 160 board_bios.mac_address_pci[2], board_bios.mac_address_pci[3], 161 board_bios.mac_address_pci[4], board_bios.mac_address_pci[5]); 162 printf(" processor_speed = %u\n", board_bios.processor_speed); 163 printf(" plb_speed = %u\n", board_bios.plb_speed); 164 printf(" pci_speed = %u\n", board_bios.pci_speed); 165 } 166