xref: /netbsd/sys/arch/evbppc/obs405/dev/century_bios.c (revision 6550d01e)
1 /*	$NetBSD: century_bios.c,v 1.4 2007/02/22 05:27:47 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: century_bios.c,v 1.4 2007/02/22 05:27:47 thorpej Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 
39 #include <machine/cpu.h>
40 #include <machine/century_bios.h>
41 
42 /*
43  * OpenBlockS S/R Board configuration structure.
44  *
45  * IBM405GP Monitor (Ver. 1.8, REV-01  H/W)
46  * Century Version  (MA-300) (Oct. 30, 2001)
47  */
48 struct board_bios_data {
49 	unsigned char	mac_address_local[6];
50 	unsigned char	boot_mode;
51 	unsigned char	mem_size;		/* MB */
52 };
53 
54 static struct board_bios_data	board_bios;
55 static unsigned int		board_mem_size;
56 static unsigned int		board_cpu_speed;
57 static unsigned int		board_plb_speed;
58 static unsigned int		board_pci_speed;
59 
60 void
61 bios_board_init(void *info_block, u_int sysclk_base)
62 {
63 
64         /* Initialize cache info for memcpy, etc. */
65         cpu_probe_cache();
66 
67 	/* Save info block */
68 	memcpy(&board_bios, info_block, sizeof(board_bios));
69 	board_mem_size = board_bios.mem_size * 1024 * 1024;
70 
71 	board_cpu_speed = 0x0bebc200;
72 	board_plb_speed = 0x05f5e100;
73 	board_pci_speed = 0x01f78a40;
74 }
75 
76 unsigned int
77 bios_board_memsize_get(void)
78 {
79 	return board_mem_size;
80 }
81 
82 void
83 bios_board_info_set(void)
84 {
85 	prop_number_t pn;
86 	prop_data_t pd;
87 
88 	/* Initialize board properties dictionary */
89 	board_info_init();
90 
91 	pn = prop_number_create_integer(board_mem_size);
92 	KASSERT(pn != NULL);
93 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
94 		panic("setting mem-size");
95 	prop_object_release(pn);
96 
97 	pd = prop_data_create_data_nocopy(board_bios.mac_address_local,
98 					  sizeof(board_bios.mac_address_local));
99 	KASSERT(pd != NULL);
100 	if (prop_dictionary_set(board_properties, "emac0-mac-addr",
101 				pd) == false)
102 		panic("setting emac0-mac-addr");
103 	prop_object_release(pd);
104 
105 	pn = prop_number_create_integer(board_cpu_speed);
106 	KASSERT(pn != NULL);
107 	if (prop_dictionary_set(board_properties, "processor-frequency",
108 				pn) == false)
109 		panic("setting processor-frequency");
110 	prop_object_release(pn);
111 
112 	pn = prop_number_create_integer(board_plb_speed);
113 	KASSERT(pn != NULL);
114 	if (prop_dictionary_set(board_properties, "plb-frequency", pn) == false)
115 		panic("setting plb-frequency");
116 	prop_object_release(pn);
117 
118 	pn = prop_number_create_integer(board_pci_speed);
119 	KASSERT(pn != NULL);
120 	if (prop_dictionary_set(board_properties, "pci-frequency", pn) == false)
121 		panic("setting pci-frequency");
122 	prop_object_release(pn);
123 }
124 
125 
126 void
127 bios_board_print(void)
128 {
129 
130 	printf("Board config data:\n");
131 	printf("  mem_size = %u\n", board_mem_size);
132 	printf("  mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
133 	    board_bios.mac_address_local[0], board_bios.mac_address_local[1],
134 	    board_bios.mac_address_local[2], board_bios.mac_address_local[3],
135 	    board_bios.mac_address_local[4], board_bios.mac_address_local[5]);
136 	printf("  processor_speed = %u\n", board_cpu_speed);
137 	printf("  plb_speed = %u\n", board_plb_speed);
138 	printf("  pci_speed = %u\n", board_pci_speed);
139 }
140