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