1 /* $NetBSD: openbios.c,v 1.7 2021/03/30 01:50:13 rin 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.7 2021/03/30 01:50:13 rin Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/cpu.h>
39
40 #include <powerpc/ibm4xx/cpu.h>
41 #include <powerpc/ibm4xx/openbios.h>
42
43 /*
44 * Board configuration structure from the OpenBIOS.
45 *
46 * Supported (XXX):
47 * IBM/AMCC Walnut PowerPC 405GP Evaluation Board
48 * 405GPr 1.2 ROM Monitor (5/25/02)
49 */
50 struct board_bios_data {
51 unsigned char usr_config_ver[4];
52 unsigned char rom_sw_ver[30];
53 unsigned int mem_size;
54 unsigned char mac_address_local[6];
55 unsigned char mac_address_pci[6];
56 unsigned int processor_speed;
57 unsigned int plb_speed;
58 unsigned int pci_speed;
59 };
60
61 static struct board_bios_data board_bios;
62
63 void
openbios_board_init(void * info_block)64 openbios_board_init(void *info_block)
65 {
66
67 /* Initialize cache info for memcpy, etc. */
68 cpu_probe_cache();
69
70 /* Save info block */
71 memcpy(&board_bios, info_block, sizeof(board_bios));
72 }
73
74 unsigned int
openbios_board_memsize_get(void)75 openbios_board_memsize_get(void)
76 {
77
78 return board_bios.mem_size;
79 }
80
81 void
openbios_board_info_set(void)82 openbios_board_info_set(void)
83 {
84 prop_number_t pn;
85 prop_string_t ps;
86 prop_data_t pd;
87
88 /* Initialize board properties database */
89 board_info_init();
90
91 ps = prop_string_create_cstring_nocopy(board_bios.usr_config_ver);
92 KASSERT(ps != NULL);
93 if (prop_dictionary_set(board_properties, "user-config-version",
94 ps) == false)
95 panic("setting user-config-version");
96 prop_object_release(ps);
97
98 ps = prop_string_create_cstring_nocopy(board_bios.rom_sw_ver);
99 KASSERT(ps != NULL);
100 if (prop_dictionary_set(board_properties, "rom-software-version",
101 ps) == false)
102 panic("setting rom-software-version");
103 prop_object_release(ps);
104
105 pn = prop_number_create_integer(board_bios.mem_size);
106 KASSERT(pn != NULL);
107 if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
108 panic("setting mem-size");
109 prop_object_release(pn);
110
111 pd = prop_data_create_data_nocopy(board_bios.mac_address_local,
112 sizeof(board_bios.mac_address_local));
113 KASSERT(pd != NULL);
114 if (prop_dictionary_set(board_properties, "emac0-mac-addr",
115 pd) == false)
116 panic("setting emac0-mac-addr");
117 prop_object_release(pd);
118
119 pd = prop_data_create_data_nocopy(board_bios.mac_address_pci,
120 sizeof(board_bios.mac_address_pci));
121 KASSERT(pd != NULL);
122 if (prop_dictionary_set(board_properties, "sip0-mac-addr",
123 pd) == false)
124 panic("setting sip0-mac-addr");
125 prop_object_release(pd);
126
127 pn = prop_number_create_integer(board_bios.processor_speed);
128 KASSERT(pn != NULL);
129 if (prop_dictionary_set(board_properties, "processor-frequency",
130 pn) == false)
131 panic("setting processor-frequency");
132 prop_object_release(pn);
133
134 pn = prop_number_create_integer(board_bios.plb_speed);
135 KASSERT(pn != NULL);
136 if (prop_dictionary_set(board_properties, "plb-frequency", pn) == false)
137 panic("setting plb-frequency");
138 prop_object_release(pn);
139
140 pn = prop_number_create_integer(board_bios.pci_speed);
141 KASSERT(pn != NULL);
142 if (prop_dictionary_set(board_properties, "pci-frequency", pn) == false)
143 panic("setting pci-frequency");
144 prop_object_release(pn);
145 }
146
147 void
openbios_board_print(void)148 openbios_board_print(void)
149 {
150
151 printf("Board config data:\n");
152 printf(" usr_config_ver = %s\n", board_bios.usr_config_ver);
153 printf(" rom_sw_ver = %s\n", board_bios.rom_sw_ver);
154 printf(" mem_size = %u\n", board_bios.mem_size);
155 printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
156 board_bios.mac_address_local[0], board_bios.mac_address_local[1],
157 board_bios.mac_address_local[2], board_bios.mac_address_local[3],
158 board_bios.mac_address_local[4], board_bios.mac_address_local[5]);
159 printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
160 board_bios.mac_address_pci[0], board_bios.mac_address_pci[1],
161 board_bios.mac_address_pci[2], board_bios.mac_address_pci[3],
162 board_bios.mac_address_pci[4], board_bios.mac_address_pci[5]);
163 printf(" processor_speed = %u\n", board_bios.processor_speed);
164 printf(" plb_speed = %u\n", board_bios.plb_speed);
165 printf(" pci_speed = %u\n", board_bios.pci_speed);
166 }
167