xref: /netbsd/sys/arch/iyonix/iyonix/autoconf.c (revision 6550d01e)
1 /*	$NetBSD: autoconf.c,v 1.12 2010/01/22 08:56:05 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas <matt@3am-software.com>.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.12 2010/01/22 08:56:05 martin Exp $");
34 
35 #include "opt_md.h"
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/reboot.h>
40 #include <sys/disklabel.h>
41 #include <sys/device.h>
42 #include <sys/conf.h>
43 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 
46 #include <net/if.h>
47 #include <net/if_ether.h>
48 
49 #include <machine/autoconf.h>
50 #include <machine/intr.h>
51 
52 #include <iyonix/iyonix/iyonixvar.h>
53 
54 #include <acorn32/include/bootconfig.h>
55 
56 struct device *booted_device;
57 int booted_partition;
58 
59 extern struct bootconfig bootconfig;
60 
61 /*
62  * Set up the root device from the boot args
63  */
64 void
65 cpu_rootconf(void)
66 {
67 	aprint_normal("boot device: %s\n",
68 	    booted_device != NULL ? booted_device->dv_xname : "<unknown>");
69 	setroot(booted_device, booted_partition);
70 }
71 
72 
73 /*
74  * void cpu_configure()
75  *
76  * Configure all the root devices
77  * The root devices are expected to configure their own children
78  */
79 void
80 cpu_configure(void)
81 {
82 	struct mainbus_attach_args maa;
83 
84 	(void) splhigh();
85 	(void) splserial();	/* XXX need an splextreme() */
86 
87 	maa.ma_name = "mainbus";
88 
89 	config_rootfound("mainbus", &maa);
90 
91 	/* Time to start taking interrupts so lets open the flood gates .... */
92 	spl0();
93 }
94 
95 #define BUILTIN_ETHERNET_P(pa)	\
96 	((pa)->pa_bus == 0 && (pa)->pa_device == 4 && (pa)->pa_function == 0)
97 
98 #define SETPROP(x, y)							\
99 	do {								\
100 		if (prop_dictionary_set(device_properties(dev),		\
101 						x, y) == false) {	\
102 			printf("WARNING: unable to set " x " "		\
103 			   "property for %s\n", dev->dv_xname);		\
104 		}							\
105 		prop_object_release(y);					\
106 	} while (/*CONSTCOND*/0)
107 
108 void
109 device_register(struct device *dev, void *aux)
110 {
111 	struct device *pdev;
112 
113 	if ((pdev = device_parent(dev)) != NULL &&
114 	    device_is_a(pdev, "pci")) {
115 		struct pci_attach_args *pa = aux;
116 
117 		if (BUILTIN_ETHERNET_P(pa)) {
118 			prop_number_t cfg1, cfg2, swdpin;
119 			prop_data_t mac;
120 
121 			/*
122 			 * We set these configuration registers to 0,
123 			 * because it's the closest we have to "leave them
124 			 * alone". That and, it works.
125 			 */
126 			cfg1 = prop_number_create_integer(0);
127 			KASSERT(cfg1 != NULL);
128 			cfg2 = prop_number_create_integer(0);
129 			KASSERT(cfg2 != NULL);
130 			swdpin = prop_number_create_integer(0);
131 			KASSERT(swdpin != NULL);
132 
133 			mac = prop_data_create_data_nocopy(iyonix_macaddr,
134 							   ETHER_ADDR_LEN);
135 			KASSERT(mac != NULL);
136 
137 			SETPROP("mac-address", mac);
138 			SETPROP("i82543-cfg1", cfg1);
139 			SETPROP("i82543-cfg2", cfg2);
140 			SETPROP("i82543-swdpin", swdpin);
141 		}
142 	}
143 
144 	if (device_is_a(dev, "genfb") &&
145 	    device_is_a(device_parent(dev), "pci") ) {
146 		prop_dictionary_t dict = device_properties(dev);
147 		struct pci_attach_args *pa = aux;
148 		pcireg_t bar0, bar1;
149 		uint32_t fbaddr;
150 		bus_space_handle_t vgah;
151 
152 		bar0 = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START);
153 		bar1 = pci_conf_read(pa->pa_pc, pa->pa_tag,
154 			PCI_MAPREG_START + 0x04);
155 
156 		/*
157 		 * We need to prod the VGA card to disable interrupts, since
158 		 * RISC OS has been using them and we don't know how to
159 		 * handle them. This assumes that we have a NVidia
160 		 * GeForce 2 MX card as supplied with the Iyonix and
161 		 * as (probably) required by RISC OS in order to boot.
162 		 * If you write your own RISC OS driver for a different card,
163 		 * you're on your own.
164 		 */
165 
166 /* We're guessing at the numbers here, guys */
167 #define VGASIZE 0x1000
168 #define IRQENABLE_ADDR 0x140
169 
170 		bus_space_map(pa->pa_memt, PCI_MAPREG_MEM_ADDR(bar0),
171 			VGASIZE, 0, &vgah);
172 		bus_space_write_4(pa->pa_memt, vgah, 0x140, 0);
173 		bus_space_unmap(pa->pa_memt, vgah, 0x1000);
174 
175 		fbaddr = PCI_MAPREG_MEM_ADDR(bar1);
176 
177 		prop_dictionary_set_bool(dict, "is_console", 1);
178 		prop_dictionary_set_uint32(dict, "width",
179 			bootconfig.width + 1);
180 		prop_dictionary_set_uint32(dict, "height",
181 			bootconfig.height + 1);
182 		prop_dictionary_set_uint32(dict, "depth",
183 			1 << bootconfig.log2_bpp);
184 		prop_dictionary_set_uint32(dict, "address", fbaddr);
185 	}
186 }
187