xref: /netbsd-src/sys/arch/powerpc/ibm4xx/openbios/openbios.c (revision d74f1c2664fc7b700b0beed07db3b1f501d7f0f8)
1*d74f1c26Srin /*	$NetBSD: openbios.c,v 1.7 2021/03/30 01:50:13 rin Exp $	*/
20f2e5868Sshige 
30f2e5868Sshige /*
40f2e5868Sshige  * Copyright (c) 2004 Shigeyuki Fukushima.
50f2e5868Sshige  * All rights reserved.
60f2e5868Sshige  *
70f2e5868Sshige  * Redistribution and use in source and binary forms, with or without
80f2e5868Sshige  * modification, are permitted provided that the following conditions
90f2e5868Sshige  * are met:
100f2e5868Sshige  * 1. Redistributions of source code must retain the above copyright
110f2e5868Sshige  *    notice, this list of conditions and the following disclaimer.
120f2e5868Sshige  * 2. Redistributions in binary form must reproduce the above
130f2e5868Sshige  *    copyright notice, this list of conditions and the following
140f2e5868Sshige  *    disclaimer in the documentation and/or other materials provided
150f2e5868Sshige  *    with the distribution.
160f2e5868Sshige  * 3. The name of the author may not be used to endorse or promote
170f2e5868Sshige  *    products derived from this software without specific prior
180f2e5868Sshige  *    written permission.
190f2e5868Sshige  *
200f2e5868Sshige  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
210f2e5868Sshige  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
220f2e5868Sshige  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
230f2e5868Sshige  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
240f2e5868Sshige  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
250f2e5868Sshige  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
260f2e5868Sshige  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
270f2e5868Sshige  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
280f2e5868Sshige  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
290f2e5868Sshige  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
300f2e5868Sshige  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
310f2e5868Sshige  */
320f2e5868Sshige 
330f2e5868Sshige #include <sys/cdefs.h>
34*d74f1c26Srin __KERNEL_RCSID(0, "$NetBSD: openbios.c,v 1.7 2021/03/30 01:50:13 rin Exp $");
350f2e5868Sshige 
360f2e5868Sshige #include <sys/param.h>
370f2e5868Sshige #include <sys/systm.h>
381fd2c684Smatt #include <sys/cpu.h>
390f2e5868Sshige 
401fd2c684Smatt #include <powerpc/ibm4xx/cpu.h>
410f2e5868Sshige #include <powerpc/ibm4xx/openbios.h>
420f2e5868Sshige 
430f2e5868Sshige /*
440f2e5868Sshige  * Board configuration structure from the OpenBIOS.
450f2e5868Sshige  *
460f2e5868Sshige  * Supported (XXX):
47*d74f1c26Srin  *    IBM/AMCC Walnut PowerPC 405GP Evaluation Board
480f2e5868Sshige  *    405GPr 1.2 ROM Monitor (5/25/02)
490f2e5868Sshige  */
500f2e5868Sshige struct board_bios_data {
510f2e5868Sshige 	unsigned char	usr_config_ver[4];
520f2e5868Sshige 	unsigned char	rom_sw_ver[30];
530f2e5868Sshige 	unsigned int	mem_size;
540f2e5868Sshige 	unsigned char	mac_address_local[6];
550f2e5868Sshige 	unsigned char	mac_address_pci[6];
560f2e5868Sshige 	unsigned int	processor_speed;
570f2e5868Sshige 	unsigned int	plb_speed;
580f2e5868Sshige 	unsigned int	pci_speed;
590f2e5868Sshige };
600f2e5868Sshige 
610f2e5868Sshige static struct board_bios_data board_bios;
620f2e5868Sshige 
630f2e5868Sshige void
openbios_board_init(void * info_block)64ce3776b0Srin openbios_board_init(void *info_block)
650f2e5868Sshige {
660f2e5868Sshige 
670f2e5868Sshige         /* Initialize cache info for memcpy, etc. */
680f2e5868Sshige         cpu_probe_cache();
690f2e5868Sshige 
700f2e5868Sshige 	/* Save info block */
710f2e5868Sshige 	memcpy(&board_bios, info_block, sizeof(board_bios));
720f2e5868Sshige }
730f2e5868Sshige 
740f2e5868Sshige unsigned int
openbios_board_memsize_get(void)750f2e5868Sshige openbios_board_memsize_get(void)
760f2e5868Sshige {
77*d74f1c26Srin 
780f2e5868Sshige 	return board_bios.mem_size;
790f2e5868Sshige }
800f2e5868Sshige 
810f2e5868Sshige void
openbios_board_info_set(void)820f2e5868Sshige openbios_board_info_set(void)
830f2e5868Sshige {
84fb44a857Sthorpej 	prop_number_t pn;
85fb44a857Sthorpej 	prop_string_t ps;
86fb44a857Sthorpej 	prop_data_t pd;
870f2e5868Sshige 
880f2e5868Sshige 	/* Initialize board properties database */
890f2e5868Sshige 	board_info_init();
900f2e5868Sshige 
91fb44a857Sthorpej 	ps = prop_string_create_cstring_nocopy(board_bios.usr_config_ver);
92fb44a857Sthorpej 	KASSERT(ps != NULL);
93fb44a857Sthorpej 	if (prop_dictionary_set(board_properties, "user-config-version",
94c8daa94cSthorpej 				ps) == false)
950f2e5868Sshige 		panic("setting user-config-version");
96fb44a857Sthorpej 	prop_object_release(ps);
970f2e5868Sshige 
98fb44a857Sthorpej 	ps = prop_string_create_cstring_nocopy(board_bios.rom_sw_ver);
99fb44a857Sthorpej 	KASSERT(ps != NULL);
100fb44a857Sthorpej 	if (prop_dictionary_set(board_properties, "rom-software-version",
101c8daa94cSthorpej 				ps) == false)
1020f2e5868Sshige 		panic("setting rom-software-version");
103fb44a857Sthorpej 	prop_object_release(ps);
1040f2e5868Sshige 
105fb44a857Sthorpej 	pn = prop_number_create_integer(board_bios.mem_size);
106fb44a857Sthorpej 	KASSERT(pn != NULL);
107c8daa94cSthorpej 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
1080f2e5868Sshige 		panic("setting mem-size");
109fb44a857Sthorpej 	prop_object_release(pn);
1100f2e5868Sshige 
111fb44a857Sthorpej 	pd = prop_data_create_data_nocopy(board_bios.mac_address_local,
112fb44a857Sthorpej 					  sizeof(board_bios.mac_address_local));
113fb44a857Sthorpej 	KASSERT(pd != NULL);
114fb44a857Sthorpej 	if (prop_dictionary_set(board_properties, "emac0-mac-addr",
115c8daa94cSthorpej 				pd) == false)
1160f2e5868Sshige 		panic("setting emac0-mac-addr");
117fb44a857Sthorpej 	prop_object_release(pd);
1180f2e5868Sshige 
119fb44a857Sthorpej 	pd = prop_data_create_data_nocopy(board_bios.mac_address_pci,
120fb44a857Sthorpej 					  sizeof(board_bios.mac_address_pci));
121fb44a857Sthorpej 	KASSERT(pd != NULL);
122fb44a857Sthorpej 	if (prop_dictionary_set(board_properties, "sip0-mac-addr",
123c8daa94cSthorpej 				pd) == false)
1240f2e5868Sshige 		panic("setting sip0-mac-addr");
125fb44a857Sthorpej 	prop_object_release(pd);
1260f2e5868Sshige 
127fb44a857Sthorpej 	pn = prop_number_create_integer(board_bios.processor_speed);
128fb44a857Sthorpej 	KASSERT(pn != NULL);
129fb44a857Sthorpej 	if (prop_dictionary_set(board_properties, "processor-frequency",
130c8daa94cSthorpej 				pn) == false)
1310f2e5868Sshige 		panic("setting processor-frequency");
132fb44a857Sthorpej 	prop_object_release(pn);
1330f2e5868Sshige 
134fb44a857Sthorpej 	pn = prop_number_create_integer(board_bios.plb_speed);
135fb44a857Sthorpej 	KASSERT(pn != NULL);
136c8daa94cSthorpej 	if (prop_dictionary_set(board_properties, "plb-frequency", pn) == false)
1370f2e5868Sshige 		panic("setting plb-frequency");
138fb44a857Sthorpej 	prop_object_release(pn);
1390f2e5868Sshige 
140fb44a857Sthorpej 	pn = prop_number_create_integer(board_bios.pci_speed);
141fb44a857Sthorpej 	KASSERT(pn != NULL);
142c8daa94cSthorpej 	if (prop_dictionary_set(board_properties, "pci-frequency", pn) == false)
1430f2e5868Sshige 		panic("setting pci-frequency");
144fb44a857Sthorpej 	prop_object_release(pn);
1450f2e5868Sshige }
1460f2e5868Sshige 
1470f2e5868Sshige void
openbios_board_print(void)1480f2e5868Sshige openbios_board_print(void)
1490f2e5868Sshige {
1500f2e5868Sshige 
1510f2e5868Sshige 	printf("Board config data:\n");
1520f2e5868Sshige 	printf("  usr_config_ver = %s\n", board_bios.usr_config_ver);
1530f2e5868Sshige 	printf("  rom_sw_ver = %s\n", board_bios.rom_sw_ver);
1540f2e5868Sshige 	printf("  mem_size = %u\n", board_bios.mem_size);
1550f2e5868Sshige 	printf("  mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
1560f2e5868Sshige 	    board_bios.mac_address_local[0], board_bios.mac_address_local[1],
1570f2e5868Sshige 	    board_bios.mac_address_local[2], board_bios.mac_address_local[3],
1580f2e5868Sshige 	    board_bios.mac_address_local[4], board_bios.mac_address_local[5]);
1590f2e5868Sshige 	printf("  mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
1600f2e5868Sshige 	    board_bios.mac_address_pci[0], board_bios.mac_address_pci[1],
1610f2e5868Sshige 	    board_bios.mac_address_pci[2], board_bios.mac_address_pci[3],
1620f2e5868Sshige 	    board_bios.mac_address_pci[4], board_bios.mac_address_pci[5]);
1630f2e5868Sshige 	printf("  processor_speed = %u\n", board_bios.processor_speed);
1640f2e5868Sshige 	printf("  plb_speed = %u\n", board_bios.plb_speed);
1650f2e5868Sshige 	printf("  pci_speed = %u\n", board_bios.pci_speed);
1660f2e5868Sshige }
167