acafh.c revision 1.2 1 /* $NetBSD: acafh.c,v 1.2 2013/12/22 23:02:38 rkujawa Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Radoslaw Kujawa.
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: acafh.c,v 1.2 2013/12/22 23:02:38 rkujawa Exp $");
34
35 /*
36 * Individual Computers ACA500 driver.
37 */
38
39 #include <sys/param.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/systm.h>
44 #include <sys/bus.h>
45
46 #include <uvm/uvm.h>
47
48 #include <machine/cpu.h>
49
50 #include <amiga/amiga/device.h>
51 #include <amiga/amiga/isr.h>
52
53 #include <amiga/dev/zbusvar.h>
54 #include <amiga/dev/acafhvar.h>
55 #include <amiga/dev/acafhreg.h>
56
57 int acafh_match(device_t, cfdata_t , void *);
58 void acafh_attach(device_t, device_t, void *);
59 static int acafh_print(void *, const char *);
60 static uint8_t acafh_reg_read(struct acafh_softc *, uint8_t);
61 static uint8_t acafh_revision(struct acafh_softc *);
62
63 CFATTACH_DECL_NEW(acafh, sizeof(struct acafh_softc),
64 acafh_match, acafh_attach, NULL, NULL);
65
66 int
67 acafh_match(device_t parent, cfdata_t cf, void *aux)
68 {
69 if (matchname(aux, "acafh") == 0)
70 return(0);
71 return(1);
72 }
73
74 void
75 acafh_attach(device_t parent, device_t self, void *aux)
76 {
77 struct acafh_softc *sc;
78 vaddr_t aca_vbase;
79 int i;
80 struct acafhbus_attach_args aaa_wdc;
81 struct acafhbus_attach_args aaa_cp;
82
83 sc = device_private(self);
84 sc->sc_dev = self;
85
86 /* XXX: we should be sure to prepare enough kva during early init... */
87 aca_vbase = uvm_km_alloc(kernel_map,
88 ACAFH_END - ACAFH_BASE, 0, UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
89
90 if (aca_vbase == 0) {
91 aprint_error_dev(sc->sc_dev,
92 "failed allocating virtual memory\n");
93 return;
94 }
95
96 for (i = ACAFH_BASE; i < ACAFH_END; i += PAGE_SIZE)
97 pmap_enter(vm_map_pmap(kernel_map),
98 i - ACAFH_BASE + aca_vbase, i,
99 VM_PROT_READ | VM_PROT_WRITE, true);
100 pmap_update(vm_map_pmap(kernel_map));
101
102 aca_vbase += ACAFH_FIRST_REG_OFF;
103
104 sc->sc_aca_bst.base = (bus_addr_t) aca_vbase;
105 sc->sc_aca_bst.absm = &amiga_bus_stride_1;
106 /* sc->sc_aca_bst.absm = &amiga_bus_stride_0x4000; */
107 sc->sc_aca_iot = &sc->sc_aca_bst;
108
109 bus_space_map(sc->sc_aca_iot, 0, 0xF, 0, &sc->sc_aca_ioh);
110
111 #ifdef ACAFH_DEBUG
112 aprint_normal_dev(sc->sc_dev,
113 "ACA500 registers mapped to pa %x (va %x)\n",
114 kvtop((void*)sc->sc_aca_ioh), sc->sc_aca_bst.base);
115 aprint_normal_dev(sc->sc_dev, "AUX intr enable %x\n",
116 acafh_reg_read(sc, ACAFH_MEMPROBE_AUXIRQ));
117 #endif /* ACAFH_DEBUG */
118
119 aprint_normal(": Individual Computers ACA500 (rev %x)\n",
120 acafh_revision(sc));
121
122 aprint_normal_dev(sc->sc_dev, "CF cards present: ");
123 if (acafh_reg_read(sc, ACAFH_CF_DETECT_BOOT)) {
124 aprint_normal("BOOT ");
125 }
126 if (acafh_reg_read(sc, ACAFH_CF_DETECT_AUX)) {
127 aprint_normal("AUX ");
128 }
129 aprint_normal("\n");
130
131 aaa_wdc.aaa_pbase = (bus_addr_t) GAYLE_IDE_BASE + 2;
132 strcpy(aaa_wdc.aaa_name, "wdc_acafh");
133 config_found_ia(sc->sc_dev, "acafhbus", &aaa_wdc, acafh_print);
134
135 aaa_cp.aaa_pbase = (bus_addr_t) ACAFH_CLOCKPORT_BASE;
136 strcpy(aaa_cp.aaa_name, "gencp_acafh");
137 config_found_ia(sc->sc_dev, "acafhbus", &aaa_cp, acafh_print);
138 }
139
140 uint8_t
141 acafh_cf_intr_status(struct acafh_softc *sc, uint8_t slot)
142 {
143 uint8_t status;
144
145 if (slot == 0) {
146 status = acafh_reg_read(sc, ACAFH_CF_IRQ_BOOT);
147 } else {
148 status = acafh_reg_read(sc, ACAFH_CF_IRQ_AUX);
149 }
150
151 return status;
152 }
153
154 static uint8_t
155 acafh_revision(struct acafh_softc *sc)
156 {
157 uint8_t revbit0, revbit1, revbit2, revbit3;
158
159 revbit3 = acafh_reg_read(sc, ACAFH_VERSION_BIT3);
160 revbit2 = acafh_reg_read(sc, ACAFH_VERSION_BIT2);
161 revbit1 = acafh_reg_read(sc, ACAFH_VERSION_BIT1);
162 revbit0 = acafh_reg_read(sc, ACAFH_VERSION_BIT0);
163
164 return revbit0 | (revbit1 << 1) | (revbit2 << 2) | (revbit3 << 3);
165 }
166
167 static uint8_t
168 acafh_reg_read(struct acafh_softc *sc, uint8_t reg)
169 {
170 uint16_t val;
171
172 val = bus_space_read_2(sc->sc_aca_iot, sc->sc_aca_ioh, reg * 0x4000);
173 #ifdef ACAFH_DEBUG
174 aprint_normal_dev(sc->sc_dev, "read out reg %x from %lx (%x), val %x\n",
175 reg, sc->sc_aca_ioh + reg, (bus_addr_t) kvtop((void*)
176 ((unsigned) sc->sc_aca_ioh + reg * 0x4000)), val);
177 #endif /* ACAFH_DEBUG */
178
179 return (val & ACAFH_MSB_MASK) >> ACAFH_MSB_SHIFT;
180 }
181
182 static int
183 acafh_print(void *aux, const char *w)
184 {
185 if (w == NULL)
186 return 0;
187
188 return 0;
189 }
190
191