Wed Sep 30 00:00:50 2009 UTC ()
Pull up following revision(s) (requested by bouyer in ticket #1040):
	sys/dev/isa/if_lc_isa.c: revision 1.30
	sys/dev/pci/pccbb.c: revision 1.183
Fix bus_addr_t/bus_size_t confusion


(snj)
diff -r1.180 -r1.180.4.1 src/sys/dev/pci/pccbb.c

cvs diff -r1.180 -r1.180.4.1 src/sys/dev/pci/pccbb.c (switch to unified diff)

--- src/sys/dev/pci/pccbb.c 2008/10/25 18:46:38 1.180
+++ src/sys/dev/pci/pccbb.c 2009/09/30 00:00:49 1.180.4.1
@@ -1,1152 +1,1152 @@ @@ -1,1152 +1,1152 @@
1/* $NetBSD: pccbb.c,v 1.180 2008/10/25 18:46:38 christos Exp $ */ 1/* $NetBSD: pccbb.c,v 1.180.4.1 2009/09/30 00:00:49 snj Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 1999 and 2000 4 * Copyright (c) 1998, 1999 and 2000
5 * HAYAKAWA Koichi. All rights reserved. 5 * HAYAKAWA Koichi. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by HAYAKAWA Koichi. 17 * This product includes software developed by HAYAKAWA Koichi.
18 * 4. The name of the author may not be used to endorse or promote products 18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission. 19 * derived from this software without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.180 2008/10/25 18:46:38 christos Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.180.4.1 2009/09/30 00:00:49 snj Exp $");
35 35
36/* 36/*
37#define CBB_DEBUG 37#define CBB_DEBUG
38#define SHOW_REGS 38#define SHOW_REGS
39*/ 39*/
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/errno.h> 44#include <sys/errno.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/reboot.h> /* for bootverbose */ 46#include <sys/reboot.h> /* for bootverbose */
47#include <sys/syslog.h> 47#include <sys/syslog.h>
48#include <sys/device.h> 48#include <sys/device.h>
49#include <sys/malloc.h> 49#include <sys/malloc.h>
50#include <sys/proc.h> 50#include <sys/proc.h>
51 51
52#include <sys/intr.h> 52#include <sys/intr.h>
53#include <sys/bus.h> 53#include <sys/bus.h>
54 54
55#include <dev/pci/pcivar.h> 55#include <dev/pci/pcivar.h>
56#include <dev/pci/pcireg.h> 56#include <dev/pci/pcireg.h>
57#include <dev/pci/pcidevs.h> 57#include <dev/pci/pcidevs.h>
58 58
59#include <dev/pci/pccbbreg.h> 59#include <dev/pci/pccbbreg.h>
60 60
61#include <dev/cardbus/cardslotvar.h> 61#include <dev/cardbus/cardslotvar.h>
62 62
63#include <dev/cardbus/cardbusvar.h> 63#include <dev/cardbus/cardbusvar.h>
64 64
65#include <dev/pcmcia/pcmciareg.h> 65#include <dev/pcmcia/pcmciareg.h>
66#include <dev/pcmcia/pcmciavar.h> 66#include <dev/pcmcia/pcmciavar.h>
67 67
68#include <dev/ic/i82365reg.h> 68#include <dev/ic/i82365reg.h>
69#include <dev/pci/pccbbvar.h> 69#include <dev/pci/pccbbvar.h>
70 70
71#ifndef __NetBSD_Version__ 71#ifndef __NetBSD_Version__
72struct cfdriver cbb_cd = { 72struct cfdriver cbb_cd = {
73 NULL, "cbb", DV_DULL 73 NULL, "cbb", DV_DULL
74}; 74};
75#endif 75#endif
76 76
77#ifdef CBB_DEBUG 77#ifdef CBB_DEBUG
78#define DPRINTF(x) printf x 78#define DPRINTF(x) printf x
79#define STATIC 79#define STATIC
80#else 80#else
81#define DPRINTF(x) 81#define DPRINTF(x)
82#define STATIC static 82#define STATIC static
83#endif 83#endif
84 84
85int pccbb_burstup = 1; 85int pccbb_burstup = 1;
86 86
87/* 87/*
88 * delay_ms() is wait in milliseconds. It should be used instead 88 * delay_ms() is wait in milliseconds. It should be used instead
89 * of delay() if you want to wait more than 1 ms. 89 * of delay() if you want to wait more than 1 ms.
90 */ 90 */
91static inline void 91static inline void
92delay_ms(int millis, void *param) 92delay_ms(int millis, void *param)
93{ 93{
94 if (cold) 94 if (cold)
95 delay(millis * 1000); 95 delay(millis * 1000);
96 else 96 else
97 tsleep(param, PWAIT, "pccbb", MAX(2, hz * millis / 1000)); 97 tsleep(param, PWAIT, "pccbb", MAX(2, hz * millis / 1000));
98} 98}
99 99
100int pcicbbmatch(device_t, struct cfdata *, void *); 100int pcicbbmatch(device_t, struct cfdata *, void *);
101void pccbbattach(device_t, device_t, void *); 101void pccbbattach(device_t, device_t, void *);
102int pccbbdetach(device_t, int); 102int pccbbdetach(device_t, int);
103int pccbbintr(void *); 103int pccbbintr(void *);
104static void pci113x_insert(void *); 104static void pci113x_insert(void *);
105static int pccbbintr_function(struct pccbb_softc *); 105static int pccbbintr_function(struct pccbb_softc *);
106 106
107static int pccbb_detect_card(struct pccbb_softc *); 107static int pccbb_detect_card(struct pccbb_softc *);
108 108
109static void pccbb_pcmcia_write(struct pccbb_softc *, int, u_int8_t); 109static void pccbb_pcmcia_write(struct pccbb_softc *, int, u_int8_t);
110static u_int8_t pccbb_pcmcia_read(struct pccbb_softc *, int); 110static u_int8_t pccbb_pcmcia_read(struct pccbb_softc *, int);
111#define Pcic_read(sc, reg) pccbb_pcmcia_read((sc), (reg)) 111#define Pcic_read(sc, reg) pccbb_pcmcia_read((sc), (reg))
112#define Pcic_write(sc, reg, val) pccbb_pcmcia_write((sc), (reg), (val)) 112#define Pcic_write(sc, reg, val) pccbb_pcmcia_write((sc), (reg), (val))
113 113
114STATIC int cb_reset(struct pccbb_softc *); 114STATIC int cb_reset(struct pccbb_softc *);
115STATIC int cb_detect_voltage(struct pccbb_softc *); 115STATIC int cb_detect_voltage(struct pccbb_softc *);
116STATIC int cbbprint(void *, const char *); 116STATIC int cbbprint(void *, const char *);
117 117
118static int cb_chipset(u_int32_t, int *); 118static int cb_chipset(u_int32_t, int *);
119STATIC void pccbb_pcmcia_attach_setup(struct pccbb_softc *, 119STATIC void pccbb_pcmcia_attach_setup(struct pccbb_softc *,
120 struct pcmciabus_attach_args *); 120 struct pcmciabus_attach_args *);
121 121
122STATIC int pccbb_ctrl(cardbus_chipset_tag_t, int); 122STATIC int pccbb_ctrl(cardbus_chipset_tag_t, int);
123STATIC int pccbb_power(struct pccbb_softc *sc, int); 123STATIC int pccbb_power(struct pccbb_softc *sc, int);
124STATIC int pccbb_power_ct(cardbus_chipset_tag_t, int); 124STATIC int pccbb_power_ct(cardbus_chipset_tag_t, int);
125STATIC int pccbb_cardenable(struct pccbb_softc * sc, int function); 125STATIC int pccbb_cardenable(struct pccbb_softc * sc, int function);
126#if !rbus 126#if !rbus
127static int pccbb_io_open(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t); 127static int pccbb_io_open(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t);
128static int pccbb_io_close(cardbus_chipset_tag_t, int); 128static int pccbb_io_close(cardbus_chipset_tag_t, int);
129static int pccbb_mem_open(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t); 129static int pccbb_mem_open(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t);
130static int pccbb_mem_close(cardbus_chipset_tag_t, int); 130static int pccbb_mem_close(cardbus_chipset_tag_t, int);
131#endif /* !rbus */ 131#endif /* !rbus */
132static void *pccbb_intr_establish(struct pccbb_softc *, 132static void *pccbb_intr_establish(struct pccbb_softc *,
133 cardbus_intr_line_t irq, int level, int (*ih) (void *), void *sc); 133 cardbus_intr_line_t irq, int level, int (*ih) (void *), void *sc);
134static void pccbb_intr_disestablish(struct pccbb_softc *, void *ih); 134static void pccbb_intr_disestablish(struct pccbb_softc *, void *ih);
135 135
136static void *pccbb_cb_intr_establish(cardbus_chipset_tag_t, 136static void *pccbb_cb_intr_establish(cardbus_chipset_tag_t,
137 cardbus_intr_line_t irq, int level, int (*ih) (void *), void *sc); 137 cardbus_intr_line_t irq, int level, int (*ih) (void *), void *sc);
138static void pccbb_cb_intr_disestablish(cardbus_chipset_tag_t ct, void *ih); 138static void pccbb_cb_intr_disestablish(cardbus_chipset_tag_t ct, void *ih);
139 139
140static cardbustag_t pccbb_make_tag(cardbus_chipset_tag_t, int, int); 140static cardbustag_t pccbb_make_tag(cardbus_chipset_tag_t, int, int);
141static void pccbb_free_tag(cardbus_chipset_tag_t, cardbustag_t); 141static void pccbb_free_tag(cardbus_chipset_tag_t, cardbustag_t);
142static cardbusreg_t pccbb_conf_read(cardbus_chipset_tag_t, cardbustag_t, int); 142static cardbusreg_t pccbb_conf_read(cardbus_chipset_tag_t, cardbustag_t, int);
143static void pccbb_conf_write(cardbus_chipset_tag_t, cardbustag_t, int, 143static void pccbb_conf_write(cardbus_chipset_tag_t, cardbustag_t, int,
144 cardbusreg_t); 144 cardbusreg_t);
145static void pccbb_chipinit(struct pccbb_softc *); 145static void pccbb_chipinit(struct pccbb_softc *);
146static void pccbb_intrinit(struct pccbb_softc *); 146static void pccbb_intrinit(struct pccbb_softc *);
147 147
148STATIC int pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t, bus_size_t, 148STATIC int pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
149 struct pcmcia_mem_handle *); 149 struct pcmcia_mem_handle *);
150STATIC void pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t, 150STATIC void pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t,
151 struct pcmcia_mem_handle *); 151 struct pcmcia_mem_handle *);
152STATIC int pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, 152STATIC int pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
153 bus_size_t, struct pcmcia_mem_handle *, bus_addr_t *, int *); 153 bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
154STATIC void pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t, int); 154STATIC void pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t, int);
155STATIC int pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, 155STATIC int pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
156 bus_size_t, bus_size_t, struct pcmcia_io_handle *); 156 bus_size_t, bus_size_t, struct pcmcia_io_handle *);
157STATIC void pccbb_pcmcia_io_free(pcmcia_chipset_handle_t, 157STATIC void pccbb_pcmcia_io_free(pcmcia_chipset_handle_t,
158 struct pcmcia_io_handle *); 158 struct pcmcia_io_handle *);
159STATIC int pccbb_pcmcia_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, 159STATIC int pccbb_pcmcia_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
160 bus_size_t, struct pcmcia_io_handle *, int *); 160 bus_size_t, struct pcmcia_io_handle *, int *);
161STATIC void pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t, int); 161STATIC void pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t, int);
162STATIC void *pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t, 162STATIC void *pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t,
163 struct pcmcia_function *, int, int (*)(void *), void *); 163 struct pcmcia_function *, int, int (*)(void *), void *);
164STATIC void pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t, void *); 164STATIC void pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t, void *);
165STATIC void pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t); 165STATIC void pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t);
166STATIC void pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t); 166STATIC void pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t);
167STATIC void pccbb_pcmcia_socket_settype(pcmcia_chipset_handle_t, int); 167STATIC void pccbb_pcmcia_socket_settype(pcmcia_chipset_handle_t, int);
168STATIC int pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t pch); 168STATIC int pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t pch);
169 169
170static int pccbb_pcmcia_wait_ready(struct pccbb_softc *); 170static int pccbb_pcmcia_wait_ready(struct pccbb_softc *);
171static void pccbb_pcmcia_delay(struct pccbb_softc *, int, const char *); 171static void pccbb_pcmcia_delay(struct pccbb_softc *, int, const char *);
172 172
173static void pccbb_pcmcia_do_io_map(struct pccbb_softc *, int); 173static void pccbb_pcmcia_do_io_map(struct pccbb_softc *, int);
174static void pccbb_pcmcia_do_mem_map(struct pccbb_softc *, int); 174static void pccbb_pcmcia_do_mem_map(struct pccbb_softc *, int);
175 175
176/* bus-space allocation and deallocation functions */ 176/* bus-space allocation and deallocation functions */
177#if rbus 177#if rbus
178 178
179static int pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t, rbus_tag_t, 179static int pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t, rbus_tag_t,
180 bus_addr_t addr, bus_size_t size, bus_addr_t mask, bus_size_t align, 180 bus_addr_t addr, bus_size_t size, bus_addr_t mask, bus_size_t align,
181 int flags, bus_addr_t * addrp, bus_space_handle_t * bshp); 181 int flags, bus_addr_t * addrp, bus_space_handle_t * bshp);
182static int pccbb_rbus_cb_space_free(cardbus_chipset_tag_t, rbus_tag_t, 182static int pccbb_rbus_cb_space_free(cardbus_chipset_tag_t, rbus_tag_t,
183 bus_space_handle_t, bus_size_t); 183 bus_space_handle_t, bus_size_t);
184 184
185#endif /* rbus */ 185#endif /* rbus */
186 186
187#if rbus 187#if rbus
188 188
189static int pccbb_open_win(struct pccbb_softc *, bus_space_tag_t, 189static int pccbb_open_win(struct pccbb_softc *, bus_space_tag_t,
190 bus_addr_t, bus_size_t, bus_space_handle_t, int flags); 190 bus_addr_t, bus_size_t, bus_space_handle_t, int flags);
191static int pccbb_close_win(struct pccbb_softc *, bus_space_tag_t, 191static int pccbb_close_win(struct pccbb_softc *, bus_space_tag_t,
192 bus_space_handle_t, bus_size_t); 192 bus_space_handle_t, bus_size_t);
193static int pccbb_winlist_insert(struct pccbb_win_chain_head *, bus_addr_t, 193static int pccbb_winlist_insert(struct pccbb_win_chain_head *, bus_addr_t,
194 bus_size_t, bus_space_handle_t, int); 194 bus_size_t, bus_space_handle_t, int);
195static int pccbb_winlist_delete(struct pccbb_win_chain_head *, 195static int pccbb_winlist_delete(struct pccbb_win_chain_head *,
196 bus_space_handle_t, bus_size_t); 196 bus_space_handle_t, bus_size_t);
197static void pccbb_winset(bus_addr_t align, struct pccbb_softc *, 197static void pccbb_winset(bus_addr_t align, struct pccbb_softc *,
198 bus_space_tag_t); 198 bus_space_tag_t);
199void pccbb_winlist_show(struct pccbb_win_chain *); 199void pccbb_winlist_show(struct pccbb_win_chain *);
200 200
201#endif /* rbus */ 201#endif /* rbus */
202 202
203/* for config_defer */ 203/* for config_defer */
204static void pccbb_pci_callback(device_t); 204static void pccbb_pci_callback(device_t);
205 205
206static bool pccbb_suspend(device_t PMF_FN_PROTO); 206static bool pccbb_suspend(device_t PMF_FN_PROTO);
207static bool pccbb_resume(device_t PMF_FN_PROTO); 207static bool pccbb_resume(device_t PMF_FN_PROTO);
208 208
209#if defined SHOW_REGS 209#if defined SHOW_REGS
210static void cb_show_regs(pci_chipset_tag_t pc, pcitag_t tag, 210static void cb_show_regs(pci_chipset_tag_t pc, pcitag_t tag,
211 bus_space_tag_t memt, bus_space_handle_t memh); 211 bus_space_tag_t memt, bus_space_handle_t memh);
212#endif 212#endif
213 213
214CFATTACH_DECL_NEW(cbb_pci, sizeof(struct pccbb_softc), 214CFATTACH_DECL_NEW(cbb_pci, sizeof(struct pccbb_softc),
215 pcicbbmatch, pccbbattach, pccbbdetach, NULL); 215 pcicbbmatch, pccbbattach, pccbbdetach, NULL);
216 216
217static const struct pcmcia_chip_functions pccbb_pcmcia_funcs = { 217static const struct pcmcia_chip_functions pccbb_pcmcia_funcs = {
218 pccbb_pcmcia_mem_alloc, 218 pccbb_pcmcia_mem_alloc,
219 pccbb_pcmcia_mem_free, 219 pccbb_pcmcia_mem_free,
220 pccbb_pcmcia_mem_map, 220 pccbb_pcmcia_mem_map,
221 pccbb_pcmcia_mem_unmap, 221 pccbb_pcmcia_mem_unmap,
222 pccbb_pcmcia_io_alloc, 222 pccbb_pcmcia_io_alloc,
223 pccbb_pcmcia_io_free, 223 pccbb_pcmcia_io_free,
224 pccbb_pcmcia_io_map, 224 pccbb_pcmcia_io_map,
225 pccbb_pcmcia_io_unmap, 225 pccbb_pcmcia_io_unmap,
226 pccbb_pcmcia_intr_establish, 226 pccbb_pcmcia_intr_establish,
227 pccbb_pcmcia_intr_disestablish, 227 pccbb_pcmcia_intr_disestablish,
228 pccbb_pcmcia_socket_enable, 228 pccbb_pcmcia_socket_enable,
229 pccbb_pcmcia_socket_disable, 229 pccbb_pcmcia_socket_disable,
230 pccbb_pcmcia_socket_settype, 230 pccbb_pcmcia_socket_settype,
231 pccbb_pcmcia_card_detect 231 pccbb_pcmcia_card_detect
232}; 232};
233 233
234#if rbus 234#if rbus
235static const struct cardbus_functions pccbb_funcs = { 235static const struct cardbus_functions pccbb_funcs = {
236 pccbb_rbus_cb_space_alloc, 236 pccbb_rbus_cb_space_alloc,
237 pccbb_rbus_cb_space_free, 237 pccbb_rbus_cb_space_free,
238 pccbb_cb_intr_establish, 238 pccbb_cb_intr_establish,
239 pccbb_cb_intr_disestablish, 239 pccbb_cb_intr_disestablish,
240 pccbb_ctrl, 240 pccbb_ctrl,
241 pccbb_power_ct, 241 pccbb_power_ct,
242 pccbb_make_tag, 242 pccbb_make_tag,
243 pccbb_free_tag, 243 pccbb_free_tag,
244 pccbb_conf_read, 244 pccbb_conf_read,
245 pccbb_conf_write, 245 pccbb_conf_write,
246}; 246};
247#else 247#else
248static const struct cardbus_functions pccbb_funcs = { 248static const struct cardbus_functions pccbb_funcs = {
249 pccbb_ctrl, 249 pccbb_ctrl,
250 pccbb_power_ct, 250 pccbb_power_ct,
251 pccbb_mem_open, 251 pccbb_mem_open,
252 pccbb_mem_close, 252 pccbb_mem_close,
253 pccbb_io_open, 253 pccbb_io_open,
254 pccbb_io_close, 254 pccbb_io_close,
255 pccbb_cb_intr_establish, 255 pccbb_cb_intr_establish,
256 pccbb_cb_intr_disestablish, 256 pccbb_cb_intr_disestablish,
257 pccbb_make_tag, 257 pccbb_make_tag,
258 pccbb_conf_read, 258 pccbb_conf_read,
259 pccbb_conf_write, 259 pccbb_conf_write,
260}; 260};
261#endif 261#endif
262 262
263int 263int
264pcicbbmatch(device_t parent, struct cfdata *match, void *aux) 264pcicbbmatch(device_t parent, struct cfdata *match, void *aux)
265{ 265{
266 struct pci_attach_args *pa = (struct pci_attach_args *)aux; 266 struct pci_attach_args *pa = (struct pci_attach_args *)aux;
267 267
268 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && 268 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
269 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_CARDBUS && 269 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_CARDBUS &&
270 PCI_INTERFACE(pa->pa_class) == 0) { 270 PCI_INTERFACE(pa->pa_class) == 0) {
271 return 1; 271 return 1;
272 } 272 }
273 273
274 return 0; 274 return 0;
275} 275}
276 276
277#define MAKEID(vendor, prod) (((vendor) << PCI_VENDOR_SHIFT) \ 277#define MAKEID(vendor, prod) (((vendor) << PCI_VENDOR_SHIFT) \
278 | ((prod) << PCI_PRODUCT_SHIFT)) 278 | ((prod) << PCI_PRODUCT_SHIFT))
279 279
280const struct yenta_chipinfo { 280const struct yenta_chipinfo {
281 pcireg_t yc_id; /* vendor tag | product tag */ 281 pcireg_t yc_id; /* vendor tag | product tag */
282 int yc_chiptype; 282 int yc_chiptype;
283 int yc_flags; 283 int yc_flags;
284} yc_chipsets[] = { 284} yc_chipsets[] = {
285 /* Texas Instruments chips */ 285 /* Texas Instruments chips */
286 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1130), CB_TI113X, 286 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1130), CB_TI113X,
287 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 287 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
288 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1131), CB_TI113X, 288 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1131), CB_TI113X,
289 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 289 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
290 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1250), CB_TI125X, 290 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1250), CB_TI125X,
291 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 291 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
292 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1220), CB_TI12XX, 292 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1220), CB_TI12XX,
293 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 293 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
294 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1221), CB_TI12XX, 294 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1221), CB_TI12XX,
295 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 295 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
296 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1225), CB_TI12XX, 296 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1225), CB_TI12XX,
297 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 297 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
298 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1251), CB_TI125X, 298 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1251), CB_TI125X,
299 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 299 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
300 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1251B), CB_TI125X, 300 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1251B), CB_TI125X,
301 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 301 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
302 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1211), CB_TI12XX, 302 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1211), CB_TI12XX,
303 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 303 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
304 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1410), CB_TI12XX, 304 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1410), CB_TI12XX,
305 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 305 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
306 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1420), CB_TI1420, 306 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1420), CB_TI1420,
307 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 307 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
308 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1450), CB_TI125X, 308 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1450), CB_TI125X,
309 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 309 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
310 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1451), CB_TI12XX, 310 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1451), CB_TI12XX,
311 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 311 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
312 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1520), CB_TI12XX, 312 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI1520), CB_TI12XX,
313 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 313 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
314 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI4410YENTA), CB_TI12XX, 314 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI4410YENTA), CB_TI12XX,
315 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 315 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
316 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI4520YENTA), CB_TI12XX, 316 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI4520YENTA), CB_TI12XX,
317 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 317 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
318 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI7420YENTA), CB_TI12XX, 318 { MAKEID(PCI_VENDOR_TI, PCI_PRODUCT_TI_PCI7420YENTA), CB_TI12XX,
319 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32}, 319 PCCBB_PCMCIA_IO_RELOC | PCCBB_PCMCIA_MEM_32},
320 320
321 /* Ricoh chips */ 321 /* Ricoh chips */
322 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C475), CB_RX5C47X, 322 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C475), CB_RX5C47X,
323 PCCBB_PCMCIA_MEM_32}, 323 PCCBB_PCMCIA_MEM_32},
324 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_RL5C476), CB_RX5C47X, 324 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_RL5C476), CB_RX5C47X,
325 PCCBB_PCMCIA_MEM_32}, 325 PCCBB_PCMCIA_MEM_32},
326 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C477), CB_RX5C47X, 326 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C477), CB_RX5C47X,
327 PCCBB_PCMCIA_MEM_32}, 327 PCCBB_PCMCIA_MEM_32},
328 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C478), CB_RX5C47X, 328 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C478), CB_RX5C47X,
329 PCCBB_PCMCIA_MEM_32}, 329 PCCBB_PCMCIA_MEM_32},
330 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C465), CB_RX5C46X, 330 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C465), CB_RX5C46X,
331 PCCBB_PCMCIA_MEM_32}, 331 PCCBB_PCMCIA_MEM_32},
332 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C466), CB_RX5C46X, 332 { MAKEID(PCI_VENDOR_RICOH, PCI_PRODUCT_RICOH_Rx5C466), CB_RX5C46X,
333 PCCBB_PCMCIA_MEM_32}, 333 PCCBB_PCMCIA_MEM_32},
334 334
335 /* Toshiba products */ 335 /* Toshiba products */
336 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC95), 336 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC95),
337 CB_TOPIC95, PCCBB_PCMCIA_MEM_32}, 337 CB_TOPIC95, PCCBB_PCMCIA_MEM_32},
338 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC95B), 338 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC95B),
339 CB_TOPIC95B, PCCBB_PCMCIA_MEM_32}, 339 CB_TOPIC95B, PCCBB_PCMCIA_MEM_32},
340 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC97), 340 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC97),
341 CB_TOPIC97, PCCBB_PCMCIA_MEM_32}, 341 CB_TOPIC97, PCCBB_PCMCIA_MEM_32},
342 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC100), 342 { MAKEID(PCI_VENDOR_TOSHIBA2, PCI_PRODUCT_TOSHIBA2_ToPIC100),
343 CB_TOPIC97, PCCBB_PCMCIA_MEM_32}, 343 CB_TOPIC97, PCCBB_PCMCIA_MEM_32},
344 344
345 /* Cirrus Logic products */ 345 /* Cirrus Logic products */
346 { MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6832), 346 { MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6832),
347 CB_CIRRUS, PCCBB_PCMCIA_MEM_32}, 347 CB_CIRRUS, PCCBB_PCMCIA_MEM_32},
348 { MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6833), 348 { MAKEID(PCI_VENDOR_CIRRUS, PCI_PRODUCT_CIRRUS_CL_PD6833),
349 CB_CIRRUS, PCCBB_PCMCIA_MEM_32}, 349 CB_CIRRUS, PCCBB_PCMCIA_MEM_32},
350 350
351 /* O2 Micro products */ 351 /* O2 Micro products */
352 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6729), 352 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6729),
353 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 353 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
354 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6730), 354 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6730),
355 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 355 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
356 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6832), 356 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6832),
357 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 357 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
358 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6836), 358 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6836),
359 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 359 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
360 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6872), 360 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6872),
361 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 361 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
362 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6922), 362 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6922),
363 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 363 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
364 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6933), 364 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6933),
365 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 365 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
366 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6972), 366 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_OZ6972),
367 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 367 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
368 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_7223), 368 { MAKEID(PCI_VENDOR_O2MICRO, PCI_PRODUCT_O2MICRO_7223),
369 CB_O2MICRO, PCCBB_PCMCIA_MEM_32}, 369 CB_O2MICRO, PCCBB_PCMCIA_MEM_32},
370 370
371 /* sentinel, or Generic chip */ 371 /* sentinel, or Generic chip */
372 { 0 /* null id */ , CB_UNKNOWN, PCCBB_PCMCIA_MEM_32}, 372 { 0 /* null id */ , CB_UNKNOWN, PCCBB_PCMCIA_MEM_32},
373}; 373};
374 374
375static int 375static int
376cb_chipset(u_int32_t pci_id, int *flagp) 376cb_chipset(u_int32_t pci_id, int *flagp)
377{ 377{
378 const struct yenta_chipinfo *yc; 378 const struct yenta_chipinfo *yc;
379 379
380 /* Loop over except the last default entry. */ 380 /* Loop over except the last default entry. */
381 for (yc = yc_chipsets; yc < yc_chipsets + 381 for (yc = yc_chipsets; yc < yc_chipsets +
382 __arraycount(yc_chipsets) - 1; yc++) 382 __arraycount(yc_chipsets) - 1; yc++)
383 if (pci_id == yc->yc_id) 383 if (pci_id == yc->yc_id)
384 break; 384 break;
385 385
386 if (flagp != NULL) 386 if (flagp != NULL)
387 *flagp = yc->yc_flags; 387 *flagp = yc->yc_flags;
388 388
389 return (yc->yc_chiptype); 389 return (yc->yc_chiptype);
390} 390}
391 391
392void 392void
393pccbbattach(device_t parent, device_t self, void *aux) 393pccbbattach(device_t parent, device_t self, void *aux)
394{ 394{
395 struct pccbb_softc *sc = device_private(self); 395 struct pccbb_softc *sc = device_private(self);
396 struct pci_attach_args *pa = aux; 396 struct pci_attach_args *pa = aux;
397 pci_chipset_tag_t pc = pa->pa_pc; 397 pci_chipset_tag_t pc = pa->pa_pc;
398 pcireg_t busreg, reg, sock_base; 398 pcireg_t busreg, reg, sock_base;
399 bus_addr_t sockbase; 399 bus_addr_t sockbase;
400 char devinfo[256]; 400 char devinfo[256];
401 int flags; 401 int flags;
402 402
403#ifdef __HAVE_PCCBB_ATTACH_HOOK 403#ifdef __HAVE_PCCBB_ATTACH_HOOK
404 pccbb_attach_hook(parent, self, pa); 404 pccbb_attach_hook(parent, self, pa);
405#endif 405#endif
406 406
407 sc->sc_dev = self; 407 sc->sc_dev = self;
408 408
409 callout_init(&sc->sc_insert_ch, 0); 409 callout_init(&sc->sc_insert_ch, 0);
410 callout_setfunc(&sc->sc_insert_ch, pci113x_insert, sc); 410 callout_setfunc(&sc->sc_insert_ch, pci113x_insert, sc);
411 411
412 sc->sc_chipset = cb_chipset(pa->pa_id, &flags); 412 sc->sc_chipset = cb_chipset(pa->pa_id, &flags);
413 413
414 aprint_naive("\n"); 414 aprint_naive("\n");
415 415
416 pci_devinfo(pa->pa_id, 0, 0, devinfo, sizeof(devinfo)); 416 pci_devinfo(pa->pa_id, 0, 0, devinfo, sizeof(devinfo));
417 aprint_normal(": %s (rev. 0x%02x)", devinfo, 417 aprint_normal(": %s (rev. 0x%02x)", devinfo,
418 PCI_REVISION(pa->pa_class)); 418 PCI_REVISION(pa->pa_class));
419 DPRINTF((" (chipflags %x)", flags)); 419 DPRINTF((" (chipflags %x)", flags));
420 aprint_normal("\n"); 420 aprint_normal("\n");
421 421
422 TAILQ_INIT(&sc->sc_memwindow); 422 TAILQ_INIT(&sc->sc_memwindow);
423 TAILQ_INIT(&sc->sc_iowindow); 423 TAILQ_INIT(&sc->sc_iowindow);
424 424
425#if rbus 425#if rbus
426 sc->sc_rbus_iot = rbus_pccbb_parent_io(pa); 426 sc->sc_rbus_iot = rbus_pccbb_parent_io(pa);
427 sc->sc_rbus_memt = rbus_pccbb_parent_mem(pa); 427 sc->sc_rbus_memt = rbus_pccbb_parent_mem(pa);
428 428
429#if 0 429#if 0
430 printf("pa->pa_memt: %08x vs rbus_mem->rb_bt: %08x\n", 430 printf("pa->pa_memt: %08x vs rbus_mem->rb_bt: %08x\n",
431 pa->pa_memt, sc->sc_rbus_memt->rb_bt); 431 pa->pa_memt, sc->sc_rbus_memt->rb_bt);
432#endif 432#endif
433#endif /* rbus */ 433#endif /* rbus */
434 434
435 sc->sc_flags &= ~CBB_MEMHMAPPED; 435 sc->sc_flags &= ~CBB_MEMHMAPPED;
436 436
437 /* 437 /*
438 * MAP socket registers and ExCA registers on memory-space 438 * MAP socket registers and ExCA registers on memory-space
439 * When no valid address is set on socket base registers (on pci 439 * When no valid address is set on socket base registers (on pci
440 * config space), get it not polite way. 440 * config space), get it not polite way.
441 */ 441 */
442 sock_base = pci_conf_read(pc, pa->pa_tag, PCI_SOCKBASE); 442 sock_base = pci_conf_read(pc, pa->pa_tag, PCI_SOCKBASE);
443 443
444 if (PCI_MAPREG_MEM_ADDR(sock_base) >= 0x100000 && 444 if (PCI_MAPREG_MEM_ADDR(sock_base) >= 0x100000 &&
445 PCI_MAPREG_MEM_ADDR(sock_base) != 0xfffffff0) { 445 PCI_MAPREG_MEM_ADDR(sock_base) != 0xfffffff0) {
446 /* The address must be valid. */ 446 /* The address must be valid. */
447 if (pci_mapreg_map(pa, PCI_SOCKBASE, PCI_MAPREG_TYPE_MEM, 0, 447 if (pci_mapreg_map(pa, PCI_SOCKBASE, PCI_MAPREG_TYPE_MEM, 0,
448 &sc->sc_base_memt, &sc->sc_base_memh, &sockbase, &sc->sc_base_size)) { 448 &sc->sc_base_memt, &sc->sc_base_memh, &sockbase, &sc->sc_base_size)) {
449 aprint_error_dev(self, 449 aprint_error_dev(self,
450 "can't map socket base address 0x%lx\n", 450 "can't map socket base address 0x%lx\n",
451 (unsigned long)sock_base); 451 (unsigned long)sock_base);
452 /* 452 /*
453 * I think it's funny: socket base registers must be 453 * I think it's funny: socket base registers must be
454 * mapped on memory space, but ... 454 * mapped on memory space, but ...
455 */ 455 */
456 if (pci_mapreg_map(pa, PCI_SOCKBASE, PCI_MAPREG_TYPE_IO, 456 if (pci_mapreg_map(pa, PCI_SOCKBASE, PCI_MAPREG_TYPE_IO,
457 0, &sc->sc_base_memt, &sc->sc_base_memh, &sockbase, 457 0, &sc->sc_base_memt, &sc->sc_base_memh, &sockbase,
458 &sc->sc_base_size)) { 458 &sc->sc_base_size)) {
459 aprint_error_dev(self, 459 aprint_error_dev(self,
460 "can't map socket base address" 460 "can't map socket base address"
461 " 0x%lx: io mode\n",  461 " 0x%lx: io mode\n",
462 (unsigned long)sockbase); 462 (unsigned long)sockbase);
463 /* give up... allocate reg space via rbus. */ 463 /* give up... allocate reg space via rbus. */
464 pci_conf_write(pc, pa->pa_tag, PCI_SOCKBASE, 0); 464 pci_conf_write(pc, pa->pa_tag, PCI_SOCKBASE, 0);
465 } else 465 } else
466 sc->sc_flags |= CBB_MEMHMAPPED; 466 sc->sc_flags |= CBB_MEMHMAPPED;
467 } else { 467 } else {
468 DPRINTF(("%s: socket base address 0x%lx\n", 468 DPRINTF(("%s: socket base address 0x%lx\n",
469 device_xname(self), 469 device_xname(self),
470 (unsigned long)sockbase)); 470 (unsigned long)sockbase));
471 sc->sc_flags |= CBB_MEMHMAPPED; 471 sc->sc_flags |= CBB_MEMHMAPPED;
472 } 472 }
473 } 473 }
474 474
475 sc->sc_mem_start = 0; /* XXX */ 475 sc->sc_mem_start = 0; /* XXX */
476 sc->sc_mem_end = 0xffffffff; /* XXX */ 476 sc->sc_mem_end = 0xffffffff; /* XXX */
477 477
478 busreg = pci_conf_read(pc, pa->pa_tag, PCI_BUSNUM); 478 busreg = pci_conf_read(pc, pa->pa_tag, PCI_BUSNUM);
479 479
480 /* pccbb_machdep.c end */ 480 /* pccbb_machdep.c end */
481 481
482#if defined CBB_DEBUG 482#if defined CBB_DEBUG
483 { 483 {
484 static const char *intrname[] = { "NON", "A", "B", "C", "D" }; 484 static const char *intrname[] = { "NON", "A", "B", "C", "D" };
485 aprint_debug_dev(self, "intrpin %s, intrtag %d\n", 485 aprint_debug_dev(self, "intrpin %s, intrtag %d\n",
486 intrname[pa->pa_intrpin], pa->pa_intrline); 486 intrname[pa->pa_intrpin], pa->pa_intrline);
487 } 487 }
488#endif 488#endif
489 489
490 /* setup softc */ 490 /* setup softc */
491 sc->sc_pc = pc; 491 sc->sc_pc = pc;
492 sc->sc_iot = pa->pa_iot; 492 sc->sc_iot = pa->pa_iot;
493 sc->sc_memt = pa->pa_memt; 493 sc->sc_memt = pa->pa_memt;
494 sc->sc_dmat = pa->pa_dmat; 494 sc->sc_dmat = pa->pa_dmat;
495 sc->sc_tag = pa->pa_tag; 495 sc->sc_tag = pa->pa_tag;
496 496
497 memcpy(&sc->sc_pa, pa, sizeof(*pa)); 497 memcpy(&sc->sc_pa, pa, sizeof(*pa));
498 498
499 sc->sc_pcmcia_flags = flags; /* set PCMCIA facility */ 499 sc->sc_pcmcia_flags = flags; /* set PCMCIA facility */
500 500
501 /* Disable legacy register mapping. */ 501 /* Disable legacy register mapping. */
502 switch (sc->sc_chipset) { 502 switch (sc->sc_chipset) {
503 case CB_RX5C46X: /* fallthrough */ 503 case CB_RX5C46X: /* fallthrough */
504#if 0 504#if 0
505 /* The RX5C47X-series requires writes to the PCI_LEGACY register. */ 505 /* The RX5C47X-series requires writes to the PCI_LEGACY register. */
506 case CB_RX5C47X: 506 case CB_RX5C47X:
507#endif 507#endif
508 /* 508 /*
509 * The legacy pcic io-port on Ricoh RX5C46X CardBus bridges 509 * The legacy pcic io-port on Ricoh RX5C46X CardBus bridges
510 * cannot be disabled by substituting 0 into PCI_LEGACY 510 * cannot be disabled by substituting 0 into PCI_LEGACY
511 * register. Ricoh CardBus bridges have special bits on Bridge 511 * register. Ricoh CardBus bridges have special bits on Bridge
512 * control reg (addr 0x3e on PCI config space). 512 * control reg (addr 0x3e on PCI config space).
513 */ 513 */
514 reg = pci_conf_read(pc, pa->pa_tag, PCI_BRIDGE_CONTROL_REG); 514 reg = pci_conf_read(pc, pa->pa_tag, PCI_BRIDGE_CONTROL_REG);
515 reg &= ~(CB_BCRI_RL_3E0_ENA | CB_BCRI_RL_3E2_ENA); 515 reg &= ~(CB_BCRI_RL_3E0_ENA | CB_BCRI_RL_3E2_ENA);
516 pci_conf_write(pc, pa->pa_tag, PCI_BRIDGE_CONTROL_REG, reg); 516 pci_conf_write(pc, pa->pa_tag, PCI_BRIDGE_CONTROL_REG, reg);
517 break; 517 break;
518 518
519 default: 519 default:
520 /* XXX I don't know proper way to kill legacy I/O. */ 520 /* XXX I don't know proper way to kill legacy I/O. */
521 pci_conf_write(pc, pa->pa_tag, PCI_LEGACY, 0x0); 521 pci_conf_write(pc, pa->pa_tag, PCI_LEGACY, 0x0);
522 break; 522 break;
523 } 523 }
524 524
525 if (!pmf_device_register(self, pccbb_suspend, pccbb_resume)) 525 if (!pmf_device_register(self, pccbb_suspend, pccbb_resume))
526 aprint_error_dev(self, "couldn't establish power handler\n"); 526 aprint_error_dev(self, "couldn't establish power handler\n");
527 527
528 config_defer(self, pccbb_pci_callback); 528 config_defer(self, pccbb_pci_callback);
529} 529}
530 530
531int 531int
532pccbbdetach(device_t self, int flags) 532pccbbdetach(device_t self, int flags)
533{ 533{
534 struct pccbb_softc *sc = device_private(self); 534 struct pccbb_softc *sc = device_private(self);
535 pci_chipset_tag_t pc = sc->sc_pa.pa_pc; 535 pci_chipset_tag_t pc = sc->sc_pa.pa_pc;
536 bus_space_tag_t bmt = sc->sc_base_memt; 536 bus_space_tag_t bmt = sc->sc_base_memt;
537 bus_space_handle_t bmh = sc->sc_base_memh; 537 bus_space_handle_t bmh = sc->sc_base_memh;
538 uint32_t sockmask; 538 uint32_t sockmask;
539 int rc; 539 int rc;
540 540
541 if ((rc = config_detach_children(self, flags)) != 0) 541 if ((rc = config_detach_children(self, flags)) != 0)
542 return rc; 542 return rc;
543 543
544 if (!LIST_EMPTY(&sc->sc_pil)) { 544 if (!LIST_EMPTY(&sc->sc_pil)) {
545 panic("%s: interrupt handlers still registered", 545 panic("%s: interrupt handlers still registered",
546 device_xname(self)); 546 device_xname(self));
547 return EBUSY; 547 return EBUSY;
548 } 548 }
549 549
550 if (sc->sc_ih != NULL) { 550 if (sc->sc_ih != NULL) {
551 pci_intr_disestablish(pc, sc->sc_ih); 551 pci_intr_disestablish(pc, sc->sc_ih);
552 sc->sc_ih = NULL; 552 sc->sc_ih = NULL;
553 } 553 }
554 554
555 /* CSC Interrupt: turn off card detect and power cycle interrupts */ 555 /* CSC Interrupt: turn off card detect and power cycle interrupts */
556 sockmask = bus_space_read_4(bmt, bmh, CB_SOCKET_MASK); 556 sockmask = bus_space_read_4(bmt, bmh, CB_SOCKET_MASK);
557 sockmask &= ~(CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | 557 sockmask &= ~(CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD |
558 CB_SOCKET_MASK_POWER); 558 CB_SOCKET_MASK_POWER);
559 bus_space_write_4(bmt, bmh, CB_SOCKET_MASK, sockmask); 559 bus_space_write_4(bmt, bmh, CB_SOCKET_MASK, sockmask);
560 /* reset interrupt */ 560 /* reset interrupt */
561 bus_space_write_4(bmt, bmh, CB_SOCKET_EVENT, 561 bus_space_write_4(bmt, bmh, CB_SOCKET_EVENT,
562 bus_space_read_4(bmt, bmh, CB_SOCKET_EVENT)); 562 bus_space_read_4(bmt, bmh, CB_SOCKET_EVENT));
563 563
564 switch (sc->sc_flags & (CBB_MEMHMAPPED|CBB_SPECMAPPED)) { 564 switch (sc->sc_flags & (CBB_MEMHMAPPED|CBB_SPECMAPPED)) {
565 case CBB_MEMHMAPPED: 565 case CBB_MEMHMAPPED:
566 bus_space_unmap(bmt, bmh, sc->sc_base_size); 566 bus_space_unmap(bmt, bmh, sc->sc_base_size);
567 break; 567 break;
568 case CBB_MEMHMAPPED|CBB_SPECMAPPED: 568 case CBB_MEMHMAPPED|CBB_SPECMAPPED:
569#if rbus 569#if rbus
570 { 570 {
571 pcireg_t sockbase; 571 pcireg_t sockbase;
572 572
573 sockbase = pci_conf_read(pc, sc->sc_tag, PCI_SOCKBASE); 573 sockbase = pci_conf_read(pc, sc->sc_tag, PCI_SOCKBASE);
574 rbus_space_free(sc->sc_rbus_memt, bmh, 0x1000, 574 rbus_space_free(sc->sc_rbus_memt, bmh, 0x1000,
575 NULL); 575 NULL);
576 } 576 }
577#else 577#else
578 bus_space_free(bmt, bmh, 0x1000); 578 bus_space_free(bmt, bmh, 0x1000);
579#endif 579#endif
580 } 580 }
581 sc->sc_flags &= ~(CBB_MEMHMAPPED|CBB_SPECMAPPED); 581 sc->sc_flags &= ~(CBB_MEMHMAPPED|CBB_SPECMAPPED);
582 582
583 if (!TAILQ_EMPTY(&sc->sc_iowindow)) 583 if (!TAILQ_EMPTY(&sc->sc_iowindow))
584 aprint_error_dev(self, "i/o windows not empty"); 584 aprint_error_dev(self, "i/o windows not empty");
585 if (!TAILQ_EMPTY(&sc->sc_memwindow)) 585 if (!TAILQ_EMPTY(&sc->sc_memwindow))
586 aprint_error_dev(self, "memory windows not empty"); 586 aprint_error_dev(self, "memory windows not empty");
587 587
588 callout_stop(&sc->sc_insert_ch); 588 callout_stop(&sc->sc_insert_ch);
589 callout_destroy(&sc->sc_insert_ch); 589 callout_destroy(&sc->sc_insert_ch);
590 return 0; 590 return 0;
591} 591}
592 592
593/* 593/*
594 * static void pccbb_pci_callback(device_t self) 594 * static void pccbb_pci_callback(device_t self)
595 * 595 *
596 * The actual attach routine: get memory space for YENTA register 596 * The actual attach routine: get memory space for YENTA register
597 * space, setup YENTA register and route interrupt. 597 * space, setup YENTA register and route interrupt.
598 * 598 *
599 * This function should be deferred because this device may obtain 599 * This function should be deferred because this device may obtain
600 * memory space dynamically. This function must avoid obtaining 600 * memory space dynamically. This function must avoid obtaining
601 * memory area which has already kept for another device. 601 * memory area which has already kept for another device.
602 */ 602 */
603static void 603static void
604pccbb_pci_callback(device_t self) 604pccbb_pci_callback(device_t self)
605{ 605{
606 struct pccbb_softc *sc = device_private(self); 606 struct pccbb_softc *sc = device_private(self);
607 pci_chipset_tag_t pc = sc->sc_pc; 607 pci_chipset_tag_t pc = sc->sc_pc;
608 bus_addr_t sockbase; 608 bus_addr_t sockbase;
609 struct cbslot_attach_args cba; 609 struct cbslot_attach_args cba;
610 struct pcmciabus_attach_args paa; 610 struct pcmciabus_attach_args paa;
611 struct cardslot_attach_args caa; 611 struct cardslot_attach_args caa;
612 device_t csc; 612 device_t csc;
613 613
614 if (!(sc->sc_flags & CBB_MEMHMAPPED)) { 614 if (!(sc->sc_flags & CBB_MEMHMAPPED)) {
615 /* The socket registers aren't mapped correctly. */ 615 /* The socket registers aren't mapped correctly. */
616#if rbus 616#if rbus
617 if (rbus_space_alloc(sc->sc_rbus_memt, 0, 0x1000, 0x0fff, 617 if (rbus_space_alloc(sc->sc_rbus_memt, 0, 0x1000, 0x0fff,
618 (sc->sc_chipset == CB_RX5C47X 618 (sc->sc_chipset == CB_RX5C47X
619 || sc->sc_chipset == CB_TI113X) ? 0x10000 : 0x1000, 619 || sc->sc_chipset == CB_TI113X) ? 0x10000 : 0x1000,
620 0, &sockbase, &sc->sc_base_memh)) { 620 0, &sockbase, &sc->sc_base_memh)) {
621 return; 621 return;
622 } 622 }
623 sc->sc_base_memt = sc->sc_memt; 623 sc->sc_base_memt = sc->sc_memt;
624 pci_conf_write(pc, sc->sc_tag, PCI_SOCKBASE, sockbase); 624 pci_conf_write(pc, sc->sc_tag, PCI_SOCKBASE, sockbase);
625 DPRINTF(("%s: CardBus register address 0x%lx -> 0x%lx\n", 625 DPRINTF(("%s: CardBus register address 0x%lx -> 0x%lx\n",
626 device_xname(self), (unsigned long)sockbase, 626 device_xname(self), (unsigned long)sockbase,
627 (unsigned long)pci_conf_read(pc, sc->sc_tag, 627 (unsigned long)pci_conf_read(pc, sc->sc_tag,
628 PCI_SOCKBASE))); 628 PCI_SOCKBASE)));
629#else 629#else
630 sc->sc_base_memt = sc->sc_memt; 630 sc->sc_base_memt = sc->sc_memt;
631#if !defined CBB_PCI_BASE 631#if !defined CBB_PCI_BASE
632#define CBB_PCI_BASE 0x20000000 632#define CBB_PCI_BASE 0x20000000
633#endif 633#endif
634 if (bus_space_alloc(sc->sc_base_memt, CBB_PCI_BASE, 0xffffffff, 634 if (bus_space_alloc(sc->sc_base_memt, CBB_PCI_BASE, 0xffffffff,
635 0x1000, 0x1000, 0, 0, &sockbase, &sc->sc_base_memh)) { 635 0x1000, 0x1000, 0, 0, &sockbase, &sc->sc_base_memh)) {
636 /* cannot allocate memory space */ 636 /* cannot allocate memory space */
637 return; 637 return;
638 } 638 }
639 pci_conf_write(pc, sc->sc_tag, PCI_SOCKBASE, sockbase); 639 pci_conf_write(pc, sc->sc_tag, PCI_SOCKBASE, sockbase);
640 DPRINTF(("%s: CardBus register address 0x%lx -> 0x%lx\n", 640 DPRINTF(("%s: CardBus register address 0x%lx -> 0x%lx\n",
641 device_xname(self), (unsigned long)sock_base, 641 device_xname(self), (unsigned long)sock_base,
642 (unsigned long)pci_conf_read(pc, 642 (unsigned long)pci_conf_read(pc,
643 sc->sc_tag, PCI_SOCKBASE))); 643 sc->sc_tag, PCI_SOCKBASE)));
644#endif 644#endif
645 sc->sc_flags |= CBB_MEMHMAPPED; 645 sc->sc_flags |= CBB_MEMHMAPPED;
646 } 646 }
647 647
648 /* clear data structure for child device interrupt handlers */ 648 /* clear data structure for child device interrupt handlers */
649 LIST_INIT(&sc->sc_pil); 649 LIST_INIT(&sc->sc_pil);
650 650
651 /* bus bridge initialization */ 651 /* bus bridge initialization */
652 pccbb_chipinit(sc); 652 pccbb_chipinit(sc);
653 653
654 sc->sc_pil_intr_enable = 1; 654 sc->sc_pil_intr_enable = 1;
655 655
656 { 656 {
657 u_int32_t sockstat; 657 u_int32_t sockstat;
658 658
659 sockstat = bus_space_read_4(sc->sc_base_memt, 659 sockstat = bus_space_read_4(sc->sc_base_memt,
660 sc->sc_base_memh, CB_SOCKET_STAT); 660 sc->sc_base_memh, CB_SOCKET_STAT);
661 if (0 == (sockstat & CB_SOCKET_STAT_CD)) { 661 if (0 == (sockstat & CB_SOCKET_STAT_CD)) {
662 sc->sc_flags |= CBB_CARDEXIST; 662 sc->sc_flags |= CBB_CARDEXIST;
663 } 663 }
664 } 664 }
665 665
666 /* 666 /*
667 * attach cardbus 667 * attach cardbus
668 */ 668 */
669 { 669 {
670 pcireg_t busreg = pci_conf_read(pc, sc->sc_tag, PCI_BUSNUM); 670 pcireg_t busreg = pci_conf_read(pc, sc->sc_tag, PCI_BUSNUM);
671 pcireg_t bhlc = pci_conf_read(pc, sc->sc_tag, PCI_BHLC_REG); 671 pcireg_t bhlc = pci_conf_read(pc, sc->sc_tag, PCI_BHLC_REG);
672 672
673 /* initialize cbslot_attach */ 673 /* initialize cbslot_attach */
674 cba.cba_iot = sc->sc_iot; 674 cba.cba_iot = sc->sc_iot;
675 cba.cba_memt = sc->sc_memt; 675 cba.cba_memt = sc->sc_memt;
676 cba.cba_dmat = sc->sc_dmat; 676 cba.cba_dmat = sc->sc_dmat;
677 cba.cba_bus = (busreg >> 8) & 0x0ff; 677 cba.cba_bus = (busreg >> 8) & 0x0ff;
678 cba.cba_cc = (void *)sc; 678 cba.cba_cc = (void *)sc;
679 cba.cba_cf = &pccbb_funcs; 679 cba.cba_cf = &pccbb_funcs;
680 cba.cba_intrline = 0; /* XXX dummy */ 680 cba.cba_intrline = 0; /* XXX dummy */
681 681
682#if rbus 682#if rbus
683 cba.cba_rbus_iot = sc->sc_rbus_iot; 683 cba.cba_rbus_iot = sc->sc_rbus_iot;
684 cba.cba_rbus_memt = sc->sc_rbus_memt; 684 cba.cba_rbus_memt = sc->sc_rbus_memt;
685#endif 685#endif
686 686
687 cba.cba_cacheline = PCI_CACHELINE(bhlc); 687 cba.cba_cacheline = PCI_CACHELINE(bhlc);
688 cba.cba_max_lattimer = PCI_LATTIMER(bhlc); 688 cba.cba_max_lattimer = PCI_LATTIMER(bhlc);
689 689
690 aprint_verbose_dev(self, 690 aprint_verbose_dev(self,
691 "cacheline 0x%x lattimer 0x%x\n", 691 "cacheline 0x%x lattimer 0x%x\n",
692 cba.cba_cacheline, 692 cba.cba_cacheline,
693 cba.cba_max_lattimer); 693 cba.cba_max_lattimer);
694 aprint_verbose_dev(self, "bhlc 0x%x\n", bhlc); 694 aprint_verbose_dev(self, "bhlc 0x%x\n", bhlc);
695#if defined SHOW_REGS 695#if defined SHOW_REGS
696 cb_show_regs(sc->sc_pc, sc->sc_tag, sc->sc_base_memt, 696 cb_show_regs(sc->sc_pc, sc->sc_tag, sc->sc_base_memt,
697 sc->sc_base_memh); 697 sc->sc_base_memh);
698#endif 698#endif
699 } 699 }
700 700
701 pccbb_pcmcia_attach_setup(sc, &paa); 701 pccbb_pcmcia_attach_setup(sc, &paa);
702 caa.caa_cb_attach = NULL; 702 caa.caa_cb_attach = NULL;
703 if (cba.cba_bus == 0) 703 if (cba.cba_bus == 0)
704 aprint_error_dev(self, 704 aprint_error_dev(self,
705 "secondary bus number uninitialized; try PCI_BUS_FIXUP\n"); 705 "secondary bus number uninitialized; try PCI_BUS_FIXUP\n");
706 else 706 else
707 caa.caa_cb_attach = &cba; 707 caa.caa_cb_attach = &cba;
708 caa.caa_16_attach = &paa; 708 caa.caa_16_attach = &paa;
709 709
710 pccbb_intrinit(sc); 710 pccbb_intrinit(sc);
711 711
712 if (NULL != (csc = config_found_ia(self, "pcmciaslot", &caa, 712 if (NULL != (csc = config_found_ia(self, "pcmciaslot", &caa,
713 cbbprint))) { 713 cbbprint))) {
714 DPRINTF(("%s: found cardslot\n", __func__)); 714 DPRINTF(("%s: found cardslot\n", __func__));
715 sc->sc_csc = device_private(csc); 715 sc->sc_csc = device_private(csc);
716 } 716 }
717 717
718 return; 718 return;
719} 719}
720 720
721 721
722 722
723 723
724 724
725/* 725/*
726 * static void pccbb_chipinit(struct pccbb_softc *sc) 726 * static void pccbb_chipinit(struct pccbb_softc *sc)
727 * 727 *
728 * This function initialize YENTA chip registers listed below: 728 * This function initialize YENTA chip registers listed below:
729 * 1) PCI command reg, 729 * 1) PCI command reg,
730 * 2) PCI and CardBus latency timer, 730 * 2) PCI and CardBus latency timer,
731 * 3) route PCI interrupt, 731 * 3) route PCI interrupt,
732 * 4) close all memory and io windows. 732 * 4) close all memory and io windows.
733 * 5) turn off bus power. 733 * 5) turn off bus power.
734 * 6) card detect and power cycle interrupts on. 734 * 6) card detect and power cycle interrupts on.
735 * 7) clear interrupt 735 * 7) clear interrupt
736 */ 736 */
737static void 737static void
738pccbb_chipinit(struct pccbb_softc *sc) 738pccbb_chipinit(struct pccbb_softc *sc)
739{ 739{
740 pci_chipset_tag_t pc = sc->sc_pc; 740 pci_chipset_tag_t pc = sc->sc_pc;
741 pcitag_t tag = sc->sc_tag; 741 pcitag_t tag = sc->sc_tag;
742 bus_space_tag_t bmt = sc->sc_base_memt; 742 bus_space_tag_t bmt = sc->sc_base_memt;
743 bus_space_handle_t bmh = sc->sc_base_memh; 743 bus_space_handle_t bmh = sc->sc_base_memh;
744 pcireg_t bcr, bhlc, cbctl, csr, lscp, mfunc, mrburst, slotctl, sockctl, 744 pcireg_t bcr, bhlc, cbctl, csr, lscp, mfunc, mrburst, slotctl, sockctl,
745 sysctrl; 745 sysctrl;
746 746
747 /* 747 /*
748 * Set PCI command reg. 748 * Set PCI command reg.
749 * Some laptop's BIOSes (i.e. TICO) do not enable CardBus chip. 749 * Some laptop's BIOSes (i.e. TICO) do not enable CardBus chip.
750 */ 750 */
751 csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); 751 csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
752 /* I believe it is harmless. */ 752 /* I believe it is harmless. */
753 csr |= (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | 753 csr |= (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
754 PCI_COMMAND_MASTER_ENABLE); 754 PCI_COMMAND_MASTER_ENABLE);
755 755
756 /* All O2 Micro chips have broken parity-error reporting 756 /* All O2 Micro chips have broken parity-error reporting
757 * until proven otherwise. The OZ6933 PCI-CardBus Bridge 757 * until proven otherwise. The OZ6933 PCI-CardBus Bridge
758 * is known to have the defect---see PR kern/38698. 758 * is known to have the defect---see PR kern/38698.
759 */ 759 */
760 if (sc->sc_chipset != CB_O2MICRO) 760 if (sc->sc_chipset != CB_O2MICRO)
761 csr |= PCI_COMMAND_PARITY_ENABLE; 761 csr |= PCI_COMMAND_PARITY_ENABLE;
762 762
763 csr |= PCI_COMMAND_SERR_ENABLE; 763 csr |= PCI_COMMAND_SERR_ENABLE;
764 pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr); 764 pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
765 765
766 /* 766 /*
767 * Set CardBus latency timer. 767 * Set CardBus latency timer.
768 */ 768 */
769 lscp = pci_conf_read(pc, tag, PCI_CB_LSCP_REG); 769 lscp = pci_conf_read(pc, tag, PCI_CB_LSCP_REG);
770 if (PCI_CB_LATENCY(lscp) < 0x20) { 770 if (PCI_CB_LATENCY(lscp) < 0x20) {
771 lscp &= ~(PCI_CB_LATENCY_MASK << PCI_CB_LATENCY_SHIFT); 771 lscp &= ~(PCI_CB_LATENCY_MASK << PCI_CB_LATENCY_SHIFT);
772 lscp |= (0x20 << PCI_CB_LATENCY_SHIFT); 772 lscp |= (0x20 << PCI_CB_LATENCY_SHIFT);
773 pci_conf_write(pc, tag, PCI_CB_LSCP_REG, lscp); 773 pci_conf_write(pc, tag, PCI_CB_LSCP_REG, lscp);
774 } 774 }
775 DPRINTF(("CardBus latency timer 0x%x (%x)\n", 775 DPRINTF(("CardBus latency timer 0x%x (%x)\n",
776 PCI_CB_LATENCY(lscp), pci_conf_read(pc, tag, PCI_CB_LSCP_REG))); 776 PCI_CB_LATENCY(lscp), pci_conf_read(pc, tag, PCI_CB_LSCP_REG)));
777 777
778 /* 778 /*
779 * Set PCI latency timer. 779 * Set PCI latency timer.
780 */ 780 */
781 bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG); 781 bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG);
782 if (PCI_LATTIMER(bhlc) < 0x10) { 782 if (PCI_LATTIMER(bhlc) < 0x10) {
783 bhlc &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT); 783 bhlc &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
784 bhlc |= (0x10 << PCI_LATTIMER_SHIFT); 784 bhlc |= (0x10 << PCI_LATTIMER_SHIFT);
785 pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc); 785 pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
786 } 786 }
787 DPRINTF(("PCI latency timer 0x%x (%x)\n", 787 DPRINTF(("PCI latency timer 0x%x (%x)\n",
788 PCI_LATTIMER(bhlc), pci_conf_read(pc, tag, PCI_BHLC_REG))); 788 PCI_LATTIMER(bhlc), pci_conf_read(pc, tag, PCI_BHLC_REG)));
789 789
790 790
791 /* Route functional interrupts to PCI. */ 791 /* Route functional interrupts to PCI. */
792 bcr = pci_conf_read(pc, tag, PCI_BRIDGE_CONTROL_REG); 792 bcr = pci_conf_read(pc, tag, PCI_BRIDGE_CONTROL_REG);
793 bcr |= CB_BCR_INTR_IREQ_ENABLE; /* disable PCI Intr */ 793 bcr |= CB_BCR_INTR_IREQ_ENABLE; /* disable PCI Intr */
794 bcr |= CB_BCR_WRITE_POST_ENABLE; /* enable write post */ 794 bcr |= CB_BCR_WRITE_POST_ENABLE; /* enable write post */
795 /* assert reset */ 795 /* assert reset */
796 bcr |= PCI_BRIDGE_CONTROL_SECBR << PCI_BRIDGE_CONTROL_SHIFT; 796 bcr |= PCI_BRIDGE_CONTROL_SECBR << PCI_BRIDGE_CONTROL_SHIFT;
797 /* Set master abort mode to 1, forward SERR# from secondary 797 /* Set master abort mode to 1, forward SERR# from secondary
798 * to primary, and detect parity errors on secondary. 798 * to primary, and detect parity errors on secondary.
799 */ 799 */
800 bcr |= PCI_BRIDGE_CONTROL_MABRT << PCI_BRIDGE_CONTROL_SHIFT; 800 bcr |= PCI_BRIDGE_CONTROL_MABRT << PCI_BRIDGE_CONTROL_SHIFT;
801 bcr |= PCI_BRIDGE_CONTROL_SERR << PCI_BRIDGE_CONTROL_SHIFT; 801 bcr |= PCI_BRIDGE_CONTROL_SERR << PCI_BRIDGE_CONTROL_SHIFT;
802 bcr |= PCI_BRIDGE_CONTROL_PERE << PCI_BRIDGE_CONTROL_SHIFT; 802 bcr |= PCI_BRIDGE_CONTROL_PERE << PCI_BRIDGE_CONTROL_SHIFT;
803 pci_conf_write(pc, tag, PCI_BRIDGE_CONTROL_REG, bcr); 803 pci_conf_write(pc, tag, PCI_BRIDGE_CONTROL_REG, bcr);
804 804
805 switch (sc->sc_chipset) { 805 switch (sc->sc_chipset) {
806 case CB_TI113X: 806 case CB_TI113X:
807 cbctl = pci_conf_read(pc, tag, PCI_CBCTRL); 807 cbctl = pci_conf_read(pc, tag, PCI_CBCTRL);
808 /* This bit is shared, but may read as 0 on some chips, so set 808 /* This bit is shared, but may read as 0 on some chips, so set
809 it explicitly on both functions. */ 809 it explicitly on both functions. */
810 cbctl |= PCI113X_CBCTRL_PCI_IRQ_ENA; 810 cbctl |= PCI113X_CBCTRL_PCI_IRQ_ENA;
811 /* CSC intr enable */ 811 /* CSC intr enable */
812 cbctl |= PCI113X_CBCTRL_PCI_CSC; 812 cbctl |= PCI113X_CBCTRL_PCI_CSC;
813 /* functional intr prohibit | prohibit ISA routing */ 813 /* functional intr prohibit | prohibit ISA routing */
814 cbctl &= ~(PCI113X_CBCTRL_PCI_INTR | PCI113X_CBCTRL_INT_MASK); 814 cbctl &= ~(PCI113X_CBCTRL_PCI_INTR | PCI113X_CBCTRL_INT_MASK);
815 pci_conf_write(pc, tag, PCI_CBCTRL, cbctl); 815 pci_conf_write(pc, tag, PCI_CBCTRL, cbctl);
816 break; 816 break;
817 817
818 case CB_TI1420: 818 case CB_TI1420:
819 sysctrl = pci_conf_read(pc, tag, PCI_SYSCTRL); 819 sysctrl = pci_conf_read(pc, tag, PCI_SYSCTRL);
820 mrburst = pccbb_burstup 820 mrburst = pccbb_burstup
821 ? PCI1420_SYSCTRL_MRBURST : PCI1420_SYSCTRL_MRBURSTDN; 821 ? PCI1420_SYSCTRL_MRBURST : PCI1420_SYSCTRL_MRBURSTDN;
822 if ((sysctrl & PCI1420_SYSCTRL_MRBURST) == mrburst) { 822 if ((sysctrl & PCI1420_SYSCTRL_MRBURST) == mrburst) {
823 printf("%s: %swrite bursts enabled\n", 823 printf("%s: %swrite bursts enabled\n",
824 device_xname(sc->sc_dev), 824 device_xname(sc->sc_dev),
825 pccbb_burstup ? "read/" : ""); 825 pccbb_burstup ? "read/" : "");
826 } else if (pccbb_burstup) { 826 } else if (pccbb_burstup) {
827 printf("%s: enabling read/write bursts\n", 827 printf("%s: enabling read/write bursts\n",
828 device_xname(sc->sc_dev)); 828 device_xname(sc->sc_dev));
829 sysctrl |= PCI1420_SYSCTRL_MRBURST; 829 sysctrl |= PCI1420_SYSCTRL_MRBURST;
830 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl); 830 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl);
831 } else { 831 } else {
832 printf("%s: disabling read bursts, " 832 printf("%s: disabling read bursts, "
833 "enabling write bursts\n", 833 "enabling write bursts\n",
834 device_xname(sc->sc_dev)); 834 device_xname(sc->sc_dev));
835 sysctrl |= PCI1420_SYSCTRL_MRBURSTDN; 835 sysctrl |= PCI1420_SYSCTRL_MRBURSTDN;
836 sysctrl &= ~PCI1420_SYSCTRL_MRBURSTUP; 836 sysctrl &= ~PCI1420_SYSCTRL_MRBURSTUP;
837 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl); 837 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl);
838 } 838 }
839 /*FALLTHROUGH*/ 839 /*FALLTHROUGH*/
840 case CB_TI12XX: 840 case CB_TI12XX:
841 /* 841 /*
842 * Some TI 12xx (and [14][45]xx) based pci cards 842 * Some TI 12xx (and [14][45]xx) based pci cards
843 * sometimes have issues with the MFUNC register not 843 * sometimes have issues with the MFUNC register not
844 * being initialized due to a bad EEPROM on board. 844 * being initialized due to a bad EEPROM on board.
845 * Laptops that this matters on have this register 845 * Laptops that this matters on have this register
846 * properly initialized. 846 * properly initialized.
847 * 847 *
848 * The TI125X parts have a different register. 848 * The TI125X parts have a different register.
849 */ 849 */
850 mfunc = pci_conf_read(pc, tag, PCI12XX_MFUNC); 850 mfunc = pci_conf_read(pc, tag, PCI12XX_MFUNC);
851 if (mfunc == 0) { 851 if (mfunc == 0) {
852 mfunc &= ~PCI12XX_MFUNC_PIN0; 852 mfunc &= ~PCI12XX_MFUNC_PIN0;
853 mfunc |= PCI12XX_MFUNC_PIN0_INTA; 853 mfunc |= PCI12XX_MFUNC_PIN0_INTA;
854 if ((pci_conf_read(pc, tag, PCI_SYSCTRL) & 854 if ((pci_conf_read(pc, tag, PCI_SYSCTRL) &
855 PCI12XX_SYSCTRL_INTRTIE) == 0) { 855 PCI12XX_SYSCTRL_INTRTIE) == 0) {
856 mfunc &= ~PCI12XX_MFUNC_PIN1; 856 mfunc &= ~PCI12XX_MFUNC_PIN1;
857 mfunc |= PCI12XX_MFUNC_PIN1_INTB; 857 mfunc |= PCI12XX_MFUNC_PIN1_INTB;
858 } 858 }
859 pci_conf_write(pc, tag, PCI12XX_MFUNC, mfunc); 859 pci_conf_write(pc, tag, PCI12XX_MFUNC, mfunc);
860 } 860 }
861 /* fallthrough */ 861 /* fallthrough */
862 862
863 case CB_TI125X: 863 case CB_TI125X:
864 /* 864 /*
865 * Disable zoom video. Some machines initialize this 865 * Disable zoom video. Some machines initialize this
866 * improperly and experience has shown that this helps 866 * improperly and experience has shown that this helps
867 * prevent strange behavior. 867 * prevent strange behavior.
868 */ 868 */
869 pci_conf_write(pc, tag, PCI12XX_MMCTRL, 0); 869 pci_conf_write(pc, tag, PCI12XX_MMCTRL, 0);
870 870
871 sysctrl = pci_conf_read(pc, tag, PCI_SYSCTRL); 871 sysctrl = pci_conf_read(pc, tag, PCI_SYSCTRL);
872 sysctrl |= PCI12XX_SYSCTRL_VCCPROT; 872 sysctrl |= PCI12XX_SYSCTRL_VCCPROT;
873 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl); 873 pci_conf_write(pc, tag, PCI_SYSCTRL, sysctrl);
874 cbctl = pci_conf_read(pc, tag, PCI_CBCTRL); 874 cbctl = pci_conf_read(pc, tag, PCI_CBCTRL);
875 cbctl |= PCI12XX_CBCTRL_CSC; 875 cbctl |= PCI12XX_CBCTRL_CSC;
876 pci_conf_write(pc, tag, PCI_CBCTRL, cbctl); 876 pci_conf_write(pc, tag, PCI_CBCTRL, cbctl);
877 break; 877 break;
878 878
879 case CB_TOPIC95B: 879 case CB_TOPIC95B:
880 sockctl = pci_conf_read(pc, tag, TOPIC_SOCKET_CTRL); 880 sockctl = pci_conf_read(pc, tag, TOPIC_SOCKET_CTRL);
881 sockctl |= TOPIC_SOCKET_CTRL_SCR_IRQSEL; 881 sockctl |= TOPIC_SOCKET_CTRL_SCR_IRQSEL;
882 pci_conf_write(pc, tag, TOPIC_SOCKET_CTRL, sockctl); 882 pci_conf_write(pc, tag, TOPIC_SOCKET_CTRL, sockctl);
883 slotctl = pci_conf_read(pc, tag, TOPIC_SLOT_CTRL); 883 slotctl = pci_conf_read(pc, tag, TOPIC_SLOT_CTRL);
884 DPRINTF(("%s: topic slot ctrl reg 0x%x -> ", 884 DPRINTF(("%s: topic slot ctrl reg 0x%x -> ",
885 device_xname(sc->sc_dev), slotctl)); 885 device_xname(sc->sc_dev), slotctl));
886 slotctl |= (TOPIC_SLOT_CTRL_SLOTON | TOPIC_SLOT_CTRL_SLOTEN | 886 slotctl |= (TOPIC_SLOT_CTRL_SLOTON | TOPIC_SLOT_CTRL_SLOTEN |
887 TOPIC_SLOT_CTRL_ID_LOCK | TOPIC_SLOT_CTRL_CARDBUS); 887 TOPIC_SLOT_CTRL_ID_LOCK | TOPIC_SLOT_CTRL_CARDBUS);
888 slotctl &= ~TOPIC_SLOT_CTRL_SWDETECT; 888 slotctl &= ~TOPIC_SLOT_CTRL_SWDETECT;
889 DPRINTF(("0x%x\n", slotctl)); 889 DPRINTF(("0x%x\n", slotctl));
890 pci_conf_write(pc, tag, TOPIC_SLOT_CTRL, slotctl); 890 pci_conf_write(pc, tag, TOPIC_SLOT_CTRL, slotctl);
891 break; 891 break;
892 892
893 case CB_TOPIC97: 893 case CB_TOPIC97:
894 slotctl = pci_conf_read(pc, tag, TOPIC_SLOT_CTRL); 894 slotctl = pci_conf_read(pc, tag, TOPIC_SLOT_CTRL);
895 DPRINTF(("%s: topic slot ctrl reg 0x%x -> ", 895 DPRINTF(("%s: topic slot ctrl reg 0x%x -> ",
896 device_xname(sc->sc_dev), slotctl)); 896 device_xname(sc->sc_dev), slotctl));
897 slotctl |= (TOPIC_SLOT_CTRL_SLOTON | TOPIC_SLOT_CTRL_SLOTEN | 897 slotctl |= (TOPIC_SLOT_CTRL_SLOTON | TOPIC_SLOT_CTRL_SLOTEN |
898 TOPIC_SLOT_CTRL_ID_LOCK | TOPIC_SLOT_CTRL_CARDBUS); 898 TOPIC_SLOT_CTRL_ID_LOCK | TOPIC_SLOT_CTRL_CARDBUS);
899 slotctl &= ~TOPIC_SLOT_CTRL_SWDETECT; 899 slotctl &= ~TOPIC_SLOT_CTRL_SWDETECT;
900 slotctl |= TOPIC97_SLOT_CTRL_PCIINT; 900 slotctl |= TOPIC97_SLOT_CTRL_PCIINT;
901 slotctl &= ~(TOPIC97_SLOT_CTRL_STSIRQP | TOPIC97_SLOT_CTRL_IRQP); 901 slotctl &= ~(TOPIC97_SLOT_CTRL_STSIRQP | TOPIC97_SLOT_CTRL_IRQP);
902 DPRINTF(("0x%x\n", slotctl)); 902 DPRINTF(("0x%x\n", slotctl));
903 pci_conf_write(pc, tag, TOPIC_SLOT_CTRL, slotctl); 903 pci_conf_write(pc, tag, TOPIC_SLOT_CTRL, slotctl);
904 /* make sure to assert LV card support bits */ 904 /* make sure to assert LV card support bits */
905 bus_space_write_1(sc->sc_base_memt, sc->sc_base_memh, 905 bus_space_write_1(sc->sc_base_memt, sc->sc_base_memh,
906 0x800 + 0x3e, 906 0x800 + 0x3e,
907 bus_space_read_1(sc->sc_base_memt, sc->sc_base_memh, 907 bus_space_read_1(sc->sc_base_memt, sc->sc_base_memh,
908 0x800 + 0x3e) | 0x03); 908 0x800 + 0x3e) | 0x03);
909 break; 909 break;
910 } 910 }
911 911
912 /* Close all memory and I/O windows. */ 912 /* Close all memory and I/O windows. */
913 pci_conf_write(pc, tag, PCI_CB_MEMBASE0, 0xffffffff); 913 pci_conf_write(pc, tag, PCI_CB_MEMBASE0, 0xffffffff);
914 pci_conf_write(pc, tag, PCI_CB_MEMLIMIT0, 0); 914 pci_conf_write(pc, tag, PCI_CB_MEMLIMIT0, 0);
915 pci_conf_write(pc, tag, PCI_CB_MEMBASE1, 0xffffffff); 915 pci_conf_write(pc, tag, PCI_CB_MEMBASE1, 0xffffffff);
916 pci_conf_write(pc, tag, PCI_CB_MEMLIMIT1, 0); 916 pci_conf_write(pc, tag, PCI_CB_MEMLIMIT1, 0);
917 pci_conf_write(pc, tag, PCI_CB_IOBASE0, 0xffffffff); 917 pci_conf_write(pc, tag, PCI_CB_IOBASE0, 0xffffffff);
918 pci_conf_write(pc, tag, PCI_CB_IOLIMIT0, 0); 918 pci_conf_write(pc, tag, PCI_CB_IOLIMIT0, 0);
919 pci_conf_write(pc, tag, PCI_CB_IOBASE1, 0xffffffff); 919 pci_conf_write(pc, tag, PCI_CB_IOBASE1, 0xffffffff);
920 pci_conf_write(pc, tag, PCI_CB_IOLIMIT1, 0); 920 pci_conf_write(pc, tag, PCI_CB_IOLIMIT1, 0);
921 921
922 /* reset 16-bit pcmcia bus */ 922 /* reset 16-bit pcmcia bus */
923 bus_space_write_1(bmt, bmh, 0x800 + PCIC_INTR, 923 bus_space_write_1(bmt, bmh, 0x800 + PCIC_INTR,
924 bus_space_read_1(bmt, bmh, 0x800 + PCIC_INTR) & ~PCIC_INTR_RESET); 924 bus_space_read_1(bmt, bmh, 0x800 + PCIC_INTR) & ~PCIC_INTR_RESET);
925 925
926 /* turn off power */ 926 /* turn off power */
927 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V); 927 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V);
928} 928}
929 929
930static void 930static void
931pccbb_intrinit(struct pccbb_softc *sc) 931pccbb_intrinit(struct pccbb_softc *sc)
932{ 932{
933 pcireg_t sockmask; 933 pcireg_t sockmask;
934 const char *intrstr = NULL; 934 const char *intrstr = NULL;
935 pci_intr_handle_t ih; 935 pci_intr_handle_t ih;
936 pci_chipset_tag_t pc = sc->sc_pc; 936 pci_chipset_tag_t pc = sc->sc_pc;
937 bus_space_tag_t bmt = sc->sc_base_memt; 937 bus_space_tag_t bmt = sc->sc_base_memt;
938 bus_space_handle_t bmh = sc->sc_base_memh; 938 bus_space_handle_t bmh = sc->sc_base_memh;
939 939
940 /* Map and establish the interrupt. */ 940 /* Map and establish the interrupt. */
941 if (pci_intr_map(&sc->sc_pa, &ih)) { 941 if (pci_intr_map(&sc->sc_pa, &ih)) {
942 aprint_error_dev(sc->sc_dev, "couldn't map interrupt\n"); 942 aprint_error_dev(sc->sc_dev, "couldn't map interrupt\n");
943 return; 943 return;
944 } 944 }
945 intrstr = pci_intr_string(pc, ih); 945 intrstr = pci_intr_string(pc, ih);
946 946
947 /* 947 /*
948 * XXX pccbbintr should be called under the priority lower 948 * XXX pccbbintr should be called under the priority lower
949 * than any other hard interupts. 949 * than any other hard interupts.
950 */ 950 */
951 KASSERT(sc->sc_ih == NULL); 951 KASSERT(sc->sc_ih == NULL);
952 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, pccbbintr, sc); 952 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, pccbbintr, sc);
953 953
954 if (sc->sc_ih == NULL) { 954 if (sc->sc_ih == NULL) {
955 aprint_error_dev(sc->sc_dev, "couldn't establish interrupt"); 955 aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
956 if (intrstr != NULL) 956 if (intrstr != NULL)
957 aprint_error(" at %s\n", intrstr); 957 aprint_error(" at %s\n", intrstr);
958 else 958 else
959 aprint_error("\n"); 959 aprint_error("\n");
960 return; 960 return;
961 } 961 }
962 962
963 aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr); 963 aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
964 964
965 /* CSC Interrupt: Card detect and power cycle interrupts on */ 965 /* CSC Interrupt: Card detect and power cycle interrupts on */
966 sockmask = bus_space_read_4(bmt, bmh, CB_SOCKET_MASK); 966 sockmask = bus_space_read_4(bmt, bmh, CB_SOCKET_MASK);
967 sockmask |= CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | 967 sockmask |= CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD |
968 CB_SOCKET_MASK_POWER; 968 CB_SOCKET_MASK_POWER;
969 bus_space_write_4(bmt, bmh, CB_SOCKET_MASK, sockmask); 969 bus_space_write_4(bmt, bmh, CB_SOCKET_MASK, sockmask);
970 /* reset interrupt */ 970 /* reset interrupt */
971 bus_space_write_4(bmt, bmh, CB_SOCKET_EVENT, 971 bus_space_write_4(bmt, bmh, CB_SOCKET_EVENT,
972 bus_space_read_4(bmt, bmh, CB_SOCKET_EVENT)); 972 bus_space_read_4(bmt, bmh, CB_SOCKET_EVENT));
973} 973}
974 974
975/* 975/*
976 * STATIC void pccbb_pcmcia_attach_setup(struct pccbb_softc *sc, 976 * STATIC void pccbb_pcmcia_attach_setup(struct pccbb_softc *sc,
977 * struct pcmciabus_attach_args *paa) 977 * struct pcmciabus_attach_args *paa)
978 * 978 *
979 * This function attaches 16-bit PCcard bus. 979 * This function attaches 16-bit PCcard bus.
980 */ 980 */
981STATIC void 981STATIC void
982pccbb_pcmcia_attach_setup(struct pccbb_softc *sc, 982pccbb_pcmcia_attach_setup(struct pccbb_softc *sc,
983 struct pcmciabus_attach_args *paa) 983 struct pcmciabus_attach_args *paa)
984{ 984{
985#if rbus 985#if rbus
986 rbus_tag_t rb; 986 rbus_tag_t rb;
987#endif 987#endif
988 /* 988 /*
989 * We need to do a few things here: 989 * We need to do a few things here:
990 * 1) Disable routing of CSC and functional interrupts to ISA IRQs by 990 * 1) Disable routing of CSC and functional interrupts to ISA IRQs by
991 * setting the IRQ numbers to 0. 991 * setting the IRQ numbers to 0.
992 * 2) Set bit 4 of PCIC_INTR, which is needed on some chips to enable 992 * 2) Set bit 4 of PCIC_INTR, which is needed on some chips to enable
993 * routing of CSC interrupts (e.g. card removal) to PCI while in 993 * routing of CSC interrupts (e.g. card removal) to PCI while in
994 * PCMCIA mode. We just leave this set all the time. 994 * PCMCIA mode. We just leave this set all the time.
995 * 3) Enable card insertion/removal interrupts in case the chip also 995 * 3) Enable card insertion/removal interrupts in case the chip also
996 * needs that while in PCMCIA mode. 996 * needs that while in PCMCIA mode.
997 * 4) Clear any pending CSC interrupt. 997 * 4) Clear any pending CSC interrupt.
998 */ 998 */
999 Pcic_write(sc, PCIC_INTR, PCIC_INTR_ENABLE); 999 Pcic_write(sc, PCIC_INTR, PCIC_INTR_ENABLE);
1000 if (sc->sc_chipset == CB_TI113X) { 1000 if (sc->sc_chipset == CB_TI113X) {
1001 Pcic_write(sc, PCIC_CSC_INTR, 0); 1001 Pcic_write(sc, PCIC_CSC_INTR, 0);
1002 } else { 1002 } else {
1003 Pcic_write(sc, PCIC_CSC_INTR, PCIC_CSC_INTR_CD_ENABLE); 1003 Pcic_write(sc, PCIC_CSC_INTR, PCIC_CSC_INTR_CD_ENABLE);
1004 Pcic_read(sc, PCIC_CSC); 1004 Pcic_read(sc, PCIC_CSC);
1005 } 1005 }
1006 1006
1007 /* initialize pcmcia bus attachment */ 1007 /* initialize pcmcia bus attachment */
1008 paa->paa_busname = "pcmcia"; 1008 paa->paa_busname = "pcmcia";
1009 paa->pct = &pccbb_pcmcia_funcs; 1009 paa->pct = &pccbb_pcmcia_funcs;
1010 paa->pch = sc; 1010 paa->pch = sc;
1011 paa->iobase = 0; /* I don't use them */ 1011 paa->iobase = 0; /* I don't use them */
1012 paa->iosize = 0; 1012 paa->iosize = 0;
1013#if rbus 1013#if rbus
1014 rb = sc->sc_rbus_iot; 1014 rb = sc->sc_rbus_iot;
1015 paa->iobase = rb->rb_start + rb->rb_offset; 1015 paa->iobase = rb->rb_start + rb->rb_offset;
1016 paa->iosize = rb->rb_end - rb->rb_start; 1016 paa->iosize = rb->rb_end - rb->rb_start;
1017#endif 1017#endif
1018 1018
1019 return; 1019 return;
1020} 1020}
1021 1021
1022/* 1022/*
1023 * int pccbbintr(arg) 1023 * int pccbbintr(arg)
1024 * void *arg; 1024 * void *arg;
1025 * This routine handles the interrupt from Yenta PCI-CardBus bridge 1025 * This routine handles the interrupt from Yenta PCI-CardBus bridge
1026 * itself. 1026 * itself.
1027 */ 1027 */
1028int 1028int
1029pccbbintr(void *arg) 1029pccbbintr(void *arg)
1030{ 1030{
1031 struct pccbb_softc *sc = (struct pccbb_softc *)arg; 1031 struct pccbb_softc *sc = (struct pccbb_softc *)arg;
1032 u_int32_t sockevent, sockstate; 1032 u_int32_t sockevent, sockstate;
1033 bus_space_tag_t memt = sc->sc_base_memt; 1033 bus_space_tag_t memt = sc->sc_base_memt;
1034 bus_space_handle_t memh = sc->sc_base_memh; 1034 bus_space_handle_t memh = sc->sc_base_memh;
1035 1035
1036 if (!device_has_power(sc->sc_dev)) 1036 if (!device_has_power(sc->sc_dev))
1037 return 0; 1037 return 0;
1038 1038
1039 sockevent = bus_space_read_4(memt, memh, CB_SOCKET_EVENT); 1039 sockevent = bus_space_read_4(memt, memh, CB_SOCKET_EVENT);
1040 bus_space_write_4(memt, memh, CB_SOCKET_EVENT, sockevent); 1040 bus_space_write_4(memt, memh, CB_SOCKET_EVENT, sockevent);
1041 Pcic_read(sc, PCIC_CSC); 1041 Pcic_read(sc, PCIC_CSC);
1042 1042
1043 if (sockevent != 0) { 1043 if (sockevent != 0) {
1044 aprint_debug("%s: enter sockevent %" PRIx32 "\n", __func__, 1044 aprint_debug("%s: enter sockevent %" PRIx32 "\n", __func__,
1045 sockevent); 1045 sockevent);
1046 } 1046 }
1047 1047
1048 /* Sometimes a change of CSTSCHG# accompanies the first 1048 /* Sometimes a change of CSTSCHG# accompanies the first
1049 * interrupt from an Atheros WLAN. That generates a 1049 * interrupt from an Atheros WLAN. That generates a
1050 * CB_SOCKET_EVENT_CSTS event on the bridge. The event 1050 * CB_SOCKET_EVENT_CSTS event on the bridge. The event
1051 * isn't interesting to pccbb(4), so we used to ignore the 1051 * isn't interesting to pccbb(4), so we used to ignore the
1052 * interrupt. Now, let the child devices try to handle 1052 * interrupt. Now, let the child devices try to handle
1053 * the interrupt, instead. The Atheros NIC produces 1053 * the interrupt, instead. The Atheros NIC produces
1054 * interrupts more reliably, now: used to be that it would 1054 * interrupts more reliably, now: used to be that it would
1055 * only interrupt if the driver avoided powering down the 1055 * only interrupt if the driver avoided powering down the
1056 * NIC's cardslot, and then the NIC would only work after 1056 * NIC's cardslot, and then the NIC would only work after
1057 * it was reset a second time. 1057 * it was reset a second time.
1058 */ 1058 */
1059 if (sockevent == 0 || 1059 if (sockevent == 0 ||
1060 (sockevent & ~(CB_SOCKET_EVENT_POWER|CB_SOCKET_EVENT_CD)) != 0) { 1060 (sockevent & ~(CB_SOCKET_EVENT_POWER|CB_SOCKET_EVENT_CD)) != 0) {
1061 /* This intr is not for me: it may be for my child devices. */ 1061 /* This intr is not for me: it may be for my child devices. */
1062 if (sc->sc_pil_intr_enable) { 1062 if (sc->sc_pil_intr_enable) {
1063 return pccbbintr_function(sc); 1063 return pccbbintr_function(sc);
1064 } else { 1064 } else {
1065 return 0; 1065 return 0;
1066 } 1066 }
1067 } 1067 }
1068 1068
1069 if (sockevent & CB_SOCKET_EVENT_CD) { 1069 if (sockevent & CB_SOCKET_EVENT_CD) {
1070 sockstate = bus_space_read_4(memt, memh, CB_SOCKET_STAT); 1070 sockstate = bus_space_read_4(memt, memh, CB_SOCKET_STAT);
1071 if (0x00 != (sockstate & CB_SOCKET_STAT_CD)) { 1071 if (0x00 != (sockstate & CB_SOCKET_STAT_CD)) {
1072 /* A card should be removed. */ 1072 /* A card should be removed. */
1073 if (sc->sc_flags & CBB_CARDEXIST) { 1073 if (sc->sc_flags & CBB_CARDEXIST) {
1074 DPRINTF(("%s: 0x%08x", 1074 DPRINTF(("%s: 0x%08x",
1075 device_xname(sc->sc_dev), sockevent)); 1075 device_xname(sc->sc_dev), sockevent));
1076 DPRINTF((" card removed, 0x%08x\n", sockstate)); 1076 DPRINTF((" card removed, 0x%08x\n", sockstate));
1077 sc->sc_flags &= ~CBB_CARDEXIST; 1077 sc->sc_flags &= ~CBB_CARDEXIST;
1078 if (sc->sc_csc->sc_status & 1078 if (sc->sc_csc->sc_status &
1079 CARDSLOT_STATUS_CARD_16) { 1079 CARDSLOT_STATUS_CARD_16) {
1080 cardslot_event_throw(sc->sc_csc, 1080 cardslot_event_throw(sc->sc_csc,
1081 CARDSLOT_EVENT_REMOVAL_16); 1081 CARDSLOT_EVENT_REMOVAL_16);
1082 } else if (sc->sc_csc->sc_status & 1082 } else if (sc->sc_csc->sc_status &
1083 CARDSLOT_STATUS_CARD_CB) { 1083 CARDSLOT_STATUS_CARD_CB) {
1084 /* Cardbus intr removed */ 1084 /* Cardbus intr removed */
1085 cardslot_event_throw(sc->sc_csc, 1085 cardslot_event_throw(sc->sc_csc,
1086 CARDSLOT_EVENT_REMOVAL_CB); 1086 CARDSLOT_EVENT_REMOVAL_CB);
1087 } 1087 }
1088 } else if (sc->sc_flags & CBB_INSERTING) { 1088 } else if (sc->sc_flags & CBB_INSERTING) {
1089 sc->sc_flags &= ~CBB_INSERTING; 1089 sc->sc_flags &= ~CBB_INSERTING;
1090 callout_stop(&sc->sc_insert_ch); 1090 callout_stop(&sc->sc_insert_ch);
1091 } 1091 }
1092 } else if (0x00 == (sockstate & CB_SOCKET_STAT_CD) && 1092 } else if (0x00 == (sockstate & CB_SOCKET_STAT_CD) &&
1093 /* 1093 /*
1094 * The pccbbintr may called from powerdown hook when 1094 * The pccbbintr may called from powerdown hook when
1095 * the system resumed, to detect the card 1095 * the system resumed, to detect the card
1096 * insertion/removal during suspension. 1096 * insertion/removal during suspension.
1097 */ 1097 */
1098 (sc->sc_flags & CBB_CARDEXIST) == 0) { 1098 (sc->sc_flags & CBB_CARDEXIST) == 0) {
1099 if (sc->sc_flags & CBB_INSERTING) { 1099 if (sc->sc_flags & CBB_INSERTING) {
1100 callout_stop(&sc->sc_insert_ch); 1100 callout_stop(&sc->sc_insert_ch);
1101 } 1101 }
1102 callout_schedule(&sc->sc_insert_ch, hz / 5); 1102 callout_schedule(&sc->sc_insert_ch, hz / 5);
1103 sc->sc_flags |= CBB_INSERTING; 1103 sc->sc_flags |= CBB_INSERTING;
1104 } 1104 }
1105 } 1105 }
1106 1106
1107 /* XXX sockevent == 9 does occur in the wild. handle it. */ 1107 /* XXX sockevent == 9 does occur in the wild. handle it. */
1108 if (sockevent & CB_SOCKET_EVENT_POWER) { 1108 if (sockevent & CB_SOCKET_EVENT_POWER) {
1109 DPRINTF(("Powercycling because of socket event\n")); 1109 DPRINTF(("Powercycling because of socket event\n"));
1110 /* XXX: Does not happen when attaching a 16-bit card */ 1110 /* XXX: Does not happen when attaching a 16-bit card */
1111 sc->sc_pwrcycle++; 1111 sc->sc_pwrcycle++;
1112 wakeup(&sc->sc_pwrcycle); 1112 wakeup(&sc->sc_pwrcycle);
1113 } 1113 }
1114 1114
1115 return (1); 1115 return (1);
1116} 1116}
1117 1117
1118/* 1118/*
1119 * static int pccbbintr_function(struct pccbb_softc *sc) 1119 * static int pccbbintr_function(struct pccbb_softc *sc)
1120 * 1120 *
1121 * This function calls each interrupt handler registered at the 1121 * This function calls each interrupt handler registered at the
1122 * bridge. The interrupt handlers are called in registered order. 1122 * bridge. The interrupt handlers are called in registered order.
1123 */ 1123 */
1124static int 1124static int
1125pccbbintr_function(struct pccbb_softc *sc) 1125pccbbintr_function(struct pccbb_softc *sc)
1126{ 1126{
1127 int retval = 0, val; 1127 int retval = 0, val;
1128 struct pccbb_intrhand_list *pil; 1128 struct pccbb_intrhand_list *pil;
1129 int s; 1129 int s;
1130 1130
1131 LIST_FOREACH(pil, &sc->sc_pil, pil_next) { 1131 LIST_FOREACH(pil, &sc->sc_pil, pil_next) {
1132 s = splraiseipl(pil->pil_icookie); 1132 s = splraiseipl(pil->pil_icookie);
1133 val = (*pil->pil_func)(pil->pil_arg); 1133 val = (*pil->pil_func)(pil->pil_arg);
1134 splx(s); 1134 splx(s);
1135 1135
1136 retval = retval == 1 ? 1 : 1136 retval = retval == 1 ? 1 :
1137 retval == 0 ? val : val != 0 ? val : retval; 1137 retval == 0 ? val : val != 0 ? val : retval;
1138 } 1138 }
1139 1139
1140 return retval; 1140 return retval;
1141} 1141}
1142 1142
1143static void 1143static void
1144pci113x_insert(void *arg) 1144pci113x_insert(void *arg)
1145{ 1145{
1146 struct pccbb_softc *sc = arg; 1146 struct pccbb_softc *sc = arg;
1147 u_int32_t sockevent, sockstate; 1147 u_int32_t sockevent, sockstate;
1148 1148
1149 if (!(sc->sc_flags & CBB_INSERTING)) { 1149 if (!(sc->sc_flags & CBB_INSERTING)) {
1150 /* We add a card only under inserting state. */ 1150 /* We add a card only under inserting state. */
1151 return; 1151 return;
1152 } 1152 }
@@ -1687,1535 +1687,1535 @@ static void @@ -1687,1535 +1687,1535 @@ static void
1687pccbb_cb_intr_disestablish(cardbus_chipset_tag_t ct, void *ih) 1687pccbb_cb_intr_disestablish(cardbus_chipset_tag_t ct, void *ih)
1688{ 1688{
1689 struct pccbb_softc *sc = (struct pccbb_softc *)ct; 1689 struct pccbb_softc *sc = (struct pccbb_softc *)ct;
1690 1690
1691 pccbb_intr_disestablish(sc, ih); 1691 pccbb_intr_disestablish(sc, ih);
1692} 1692}
1693 1693
1694 1694
1695void 1695void
1696pccbb_intr_route(struct pccbb_softc *sc) 1696pccbb_intr_route(struct pccbb_softc *sc)
1697{ 1697{
1698 pcireg_t bcr, cbctrl; 1698 pcireg_t bcr, cbctrl;
1699 1699
1700 /* initialize bridge intr routing */ 1700 /* initialize bridge intr routing */
1701 bcr = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG); 1701 bcr = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG);
1702 bcr &= ~CB_BCR_INTR_IREQ_ENABLE; 1702 bcr &= ~CB_BCR_INTR_IREQ_ENABLE;
1703 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG, bcr); 1703 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG, bcr);
1704 1704
1705 switch (sc->sc_chipset) { 1705 switch (sc->sc_chipset) {
1706 case CB_TI113X: 1706 case CB_TI113X:
1707 cbctrl = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CBCTRL); 1707 cbctrl = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CBCTRL);
1708 /* functional intr enabled */ 1708 /* functional intr enabled */
1709 cbctrl |= PCI113X_CBCTRL_PCI_INTR; 1709 cbctrl |= PCI113X_CBCTRL_PCI_INTR;
1710 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_CBCTRL, cbctrl); 1710 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_CBCTRL, cbctrl);
1711 break; 1711 break;
1712 default: 1712 default:
1713 break; 1713 break;
1714 } 1714 }
1715} 1715}
1716 1716
1717/* 1717/*
1718 * static void *pccbb_intr_establish(struct pccbb_softc *sc, 1718 * static void *pccbb_intr_establish(struct pccbb_softc *sc,
1719 * int irq, 1719 * int irq,
1720 * int level, 1720 * int level,
1721 * int (* func)(void *), 1721 * int (* func)(void *),
1722 * void *arg) 1722 * void *arg)
1723 * 1723 *
1724 * This function registers an interrupt handler at the bridge, in 1724 * This function registers an interrupt handler at the bridge, in
1725 * order not to call the interrupt handlers of child devices when 1725 * order not to call the interrupt handlers of child devices when
1726 * a card-deletion interrupt occurs. 1726 * a card-deletion interrupt occurs.
1727 * 1727 *
1728 * The arguments irq is not used because pccbb selects intr vector. 1728 * The arguments irq is not used because pccbb selects intr vector.
1729 */ 1729 */
1730static void * 1730static void *
1731pccbb_intr_establish(struct pccbb_softc *sc, cardbus_intr_line_t irq, 1731pccbb_intr_establish(struct pccbb_softc *sc, cardbus_intr_line_t irq,
1732 int level, int (*func)(void *), void *arg) 1732 int level, int (*func)(void *), void *arg)
1733{ 1733{
1734 struct pccbb_intrhand_list *pil, *newpil; 1734 struct pccbb_intrhand_list *pil, *newpil;
1735 1735
1736 DPRINTF(("pccbb_intr_establish start. %p\n", LIST_FIRST(&sc->sc_pil))); 1736 DPRINTF(("pccbb_intr_establish start. %p\n", LIST_FIRST(&sc->sc_pil)));
1737 1737
1738 if (LIST_EMPTY(&sc->sc_pil)) { 1738 if (LIST_EMPTY(&sc->sc_pil)) {
1739 pccbb_intr_route(sc); 1739 pccbb_intr_route(sc);
1740 } 1740 }
1741 1741
1742 /* 1742 /*
1743 * Allocate a room for interrupt handler structure. 1743 * Allocate a room for interrupt handler structure.
1744 */ 1744 */
1745 if (NULL == (newpil = 1745 if (NULL == (newpil =
1746 (struct pccbb_intrhand_list *)malloc(sizeof(struct 1746 (struct pccbb_intrhand_list *)malloc(sizeof(struct
1747 pccbb_intrhand_list), M_DEVBUF, M_WAITOK))) { 1747 pccbb_intrhand_list), M_DEVBUF, M_WAITOK))) {
1748 return NULL; 1748 return NULL;
1749 } 1749 }
1750 1750
1751 newpil->pil_func = func; 1751 newpil->pil_func = func;
1752 newpil->pil_arg = arg; 1752 newpil->pil_arg = arg;
1753 newpil->pil_icookie = makeiplcookie(level); 1753 newpil->pil_icookie = makeiplcookie(level);
1754 1754
1755 if (LIST_EMPTY(&sc->sc_pil)) { 1755 if (LIST_EMPTY(&sc->sc_pil)) {
1756 LIST_INSERT_HEAD(&sc->sc_pil, newpil, pil_next); 1756 LIST_INSERT_HEAD(&sc->sc_pil, newpil, pil_next);
1757 } else { 1757 } else {
1758 for (pil = LIST_FIRST(&sc->sc_pil); 1758 for (pil = LIST_FIRST(&sc->sc_pil);
1759 LIST_NEXT(pil, pil_next) != NULL; 1759 LIST_NEXT(pil, pil_next) != NULL;
1760 pil = LIST_NEXT(pil, pil_next)); 1760 pil = LIST_NEXT(pil, pil_next));
1761 LIST_INSERT_AFTER(pil, newpil, pil_next); 1761 LIST_INSERT_AFTER(pil, newpil, pil_next);
1762 } 1762 }
1763 1763
1764 DPRINTF(("pccbb_intr_establish add pil. %p\n", 1764 DPRINTF(("pccbb_intr_establish add pil. %p\n",
1765 LIST_FIRST(&sc->sc_pil))); 1765 LIST_FIRST(&sc->sc_pil)));
1766 1766
1767 return newpil; 1767 return newpil;
1768} 1768}
1769 1769
1770/* 1770/*
1771 * static void *pccbb_intr_disestablish(struct pccbb_softc *sc, 1771 * static void *pccbb_intr_disestablish(struct pccbb_softc *sc,
1772 * void *ih) 1772 * void *ih)
1773 * 1773 *
1774 * This function removes an interrupt handler pointed by ih. ih 1774 * This function removes an interrupt handler pointed by ih. ih
1775 * should be the value returned by cardbus_intr_establish() or 1775 * should be the value returned by cardbus_intr_establish() or
1776 * NULL. 1776 * NULL.
1777 * 1777 *
1778 * When ih is NULL, this function will do nothing. 1778 * When ih is NULL, this function will do nothing.
1779 */ 1779 */
1780static void 1780static void
1781pccbb_intr_disestablish(struct pccbb_softc *sc, void *ih) 1781pccbb_intr_disestablish(struct pccbb_softc *sc, void *ih)
1782{ 1782{
1783 struct pccbb_intrhand_list *pil; 1783 struct pccbb_intrhand_list *pil;
1784 pcireg_t reg; 1784 pcireg_t reg;
1785 1785
1786 DPRINTF(("pccbb_intr_disestablish start. %p\n", 1786 DPRINTF(("pccbb_intr_disestablish start. %p\n",
1787 LIST_FIRST(&sc->sc_pil))); 1787 LIST_FIRST(&sc->sc_pil)));
1788 1788
1789 if (ih == NULL) { 1789 if (ih == NULL) {
1790 /* intr handler is not set */ 1790 /* intr handler is not set */
1791 DPRINTF(("pccbb_intr_disestablish: no ih\n")); 1791 DPRINTF(("pccbb_intr_disestablish: no ih\n"));
1792 return; 1792 return;
1793 } 1793 }
1794 1794
1795#ifdef DIAGNOSTIC 1795#ifdef DIAGNOSTIC
1796 LIST_FOREACH(pil, &sc->sc_pil, pil_next) { 1796 LIST_FOREACH(pil, &sc->sc_pil, pil_next) {
1797 DPRINTF(("pccbb_intr_disestablish: pil %p\n", pil)); 1797 DPRINTF(("pccbb_intr_disestablish: pil %p\n", pil));
1798 if (pil == ih) { 1798 if (pil == ih) {
1799 DPRINTF(("pccbb_intr_disestablish frees one pil\n")); 1799 DPRINTF(("pccbb_intr_disestablish frees one pil\n"));
1800 break; 1800 break;
1801 } 1801 }
1802 } 1802 }
1803 if (pil == NULL) { 1803 if (pil == NULL) {
1804 panic("pccbb_intr_disestablish: %s cannot find pil %p", 1804 panic("pccbb_intr_disestablish: %s cannot find pil %p",
1805 device_xname(sc->sc_dev), ih); 1805 device_xname(sc->sc_dev), ih);
1806 } 1806 }
1807#endif 1807#endif
1808 1808
1809 pil = (struct pccbb_intrhand_list *)ih; 1809 pil = (struct pccbb_intrhand_list *)ih;
1810 LIST_REMOVE(pil, pil_next); 1810 LIST_REMOVE(pil, pil_next);
1811 free(pil, M_DEVBUF); 1811 free(pil, M_DEVBUF);
1812 DPRINTF(("pccbb_intr_disestablish frees one pil\n")); 1812 DPRINTF(("pccbb_intr_disestablish frees one pil\n"));
1813 1813
1814 if (LIST_EMPTY(&sc->sc_pil)) { 1814 if (LIST_EMPTY(&sc->sc_pil)) {
1815 /* No interrupt handlers */ 1815 /* No interrupt handlers */
1816 1816
1817 DPRINTF(("pccbb_intr_disestablish: no interrupt handler\n")); 1817 DPRINTF(("pccbb_intr_disestablish: no interrupt handler\n"));
1818 1818
1819 /* stop routing PCI intr */ 1819 /* stop routing PCI intr */
1820 reg = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG); 1820 reg = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG);
1821 reg |= CB_BCR_INTR_IREQ_ENABLE; 1821 reg |= CB_BCR_INTR_IREQ_ENABLE;
1822 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG, reg); 1822 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_BRIDGE_CONTROL_REG, reg);
1823 1823
1824 switch (sc->sc_chipset) { 1824 switch (sc->sc_chipset) {
1825 case CB_TI113X: 1825 case CB_TI113X:
1826 reg = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CBCTRL); 1826 reg = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CBCTRL);
1827 /* functional intr disabled */ 1827 /* functional intr disabled */
1828 reg &= ~PCI113X_CBCTRL_PCI_INTR; 1828 reg &= ~PCI113X_CBCTRL_PCI_INTR;
1829 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_CBCTRL, reg); 1829 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_CBCTRL, reg);
1830 break; 1830 break;
1831 default: 1831 default:
1832 break; 1832 break;
1833 } 1833 }
1834 } 1834 }
1835} 1835}
1836 1836
1837#if defined SHOW_REGS 1837#if defined SHOW_REGS
1838static void 1838static void
1839cb_show_regs(pci_chipset_tag_t pc, pcitag_t tag, bus_space_tag_t memt, 1839cb_show_regs(pci_chipset_tag_t pc, pcitag_t tag, bus_space_tag_t memt,
1840 bus_space_handle_t memh) 1840 bus_space_handle_t memh)
1841{ 1841{
1842 int i; 1842 int i;
1843 printf("PCI config regs:"); 1843 printf("PCI config regs:");
1844 for (i = 0; i < 0x50; i += 4) { 1844 for (i = 0; i < 0x50; i += 4) {
1845 if (i % 16 == 0) 1845 if (i % 16 == 0)
1846 printf("\n 0x%02x:", i); 1846 printf("\n 0x%02x:", i);
1847 printf(" %08x", pci_conf_read(pc, tag, i)); 1847 printf(" %08x", pci_conf_read(pc, tag, i));
1848 } 1848 }
1849 for (i = 0x80; i < 0xb0; i += 4) { 1849 for (i = 0x80; i < 0xb0; i += 4) {
1850 if (i % 16 == 0) 1850 if (i % 16 == 0)
1851 printf("\n 0x%02x:", i); 1851 printf("\n 0x%02x:", i);
1852 printf(" %08x", pci_conf_read(pc, tag, i)); 1852 printf(" %08x", pci_conf_read(pc, tag, i));
1853 } 1853 }
1854 1854
1855 if (memh == 0) { 1855 if (memh == 0) {
1856 printf("\n"); 1856 printf("\n");
1857 return; 1857 return;
1858 } 1858 }
1859 1859
1860 printf("\nsocket regs:"); 1860 printf("\nsocket regs:");
1861 for (i = 0; i <= 0x10; i += 0x04) 1861 for (i = 0; i <= 0x10; i += 0x04)
1862 printf(" %08x", bus_space_read_4(memt, memh, i)); 1862 printf(" %08x", bus_space_read_4(memt, memh, i));
1863 printf("\nExCA regs:"); 1863 printf("\nExCA regs:");
1864 for (i = 0; i < 0x08; ++i) 1864 for (i = 0; i < 0x08; ++i)
1865 printf(" %02x", bus_space_read_1(memt, memh, 0x800 + i)); 1865 printf(" %02x", bus_space_read_1(memt, memh, 0x800 + i));
1866 printf("\n"); 1866 printf("\n");
1867 return; 1867 return;
1868} 1868}
1869#endif 1869#endif
1870 1870
1871/* 1871/*
1872 * static cardbustag_t pccbb_make_tag(cardbus_chipset_tag_t cc, 1872 * static cardbustag_t pccbb_make_tag(cardbus_chipset_tag_t cc,
1873 * int busno, int function) 1873 * int busno, int function)
1874 * This is the function to make a tag to access config space of 1874 * This is the function to make a tag to access config space of
1875 * a CardBus Card. It works same as pci_conf_read. 1875 * a CardBus Card. It works same as pci_conf_read.
1876 */ 1876 */
1877static cardbustag_t 1877static cardbustag_t
1878pccbb_make_tag(cardbus_chipset_tag_t cc, int busno, int function) 1878pccbb_make_tag(cardbus_chipset_tag_t cc, int busno, int function)
1879{ 1879{
1880 struct pccbb_softc *sc = (struct pccbb_softc *)cc; 1880 struct pccbb_softc *sc = (struct pccbb_softc *)cc;
1881 1881
1882 return pci_make_tag(sc->sc_pc, busno, 0, function); 1882 return pci_make_tag(sc->sc_pc, busno, 0, function);
1883} 1883}
1884 1884
1885static void 1885static void
1886pccbb_free_tag(cardbus_chipset_tag_t cc, cardbustag_t tag) 1886pccbb_free_tag(cardbus_chipset_tag_t cc, cardbustag_t tag)
1887{ 1887{
1888} 1888}
1889 1889
1890/* 1890/*
1891 * pccbb_conf_read 1891 * pccbb_conf_read
1892 * 1892 *
1893 * This is the function to read the config space of a CardBus card. 1893 * This is the function to read the config space of a CardBus card.
1894 * It works the same as pci_conf_read(9). 1894 * It works the same as pci_conf_read(9).
1895 */ 1895 */
1896static cardbusreg_t 1896static cardbusreg_t
1897pccbb_conf_read(cardbus_chipset_tag_t cc, cardbustag_t tag, int offset) 1897pccbb_conf_read(cardbus_chipset_tag_t cc, cardbustag_t tag, int offset)
1898{ 1898{
1899 struct pccbb_softc *sc = (struct pccbb_softc *)cc; 1899 struct pccbb_softc *sc = (struct pccbb_softc *)cc;
1900 pcitag_t brtag = sc->sc_tag; 1900 pcitag_t brtag = sc->sc_tag;
1901 cardbusreg_t reg; 1901 cardbusreg_t reg;
1902 1902
1903 /* 1903 /*
1904 * clear cardbus master abort status; it is OK to write without 1904 * clear cardbus master abort status; it is OK to write without
1905 * reading before because all bits are r/o or w1tc 1905 * reading before because all bits are r/o or w1tc
1906 */ 1906 */
1907 pci_conf_write(sc->sc_pc, brtag, PCI_CBB_SECSTATUS, 1907 pci_conf_write(sc->sc_pc, brtag, PCI_CBB_SECSTATUS,
1908 CBB_SECSTATUS_CBMABORT); 1908 CBB_SECSTATUS_CBMABORT);
1909 reg = pci_conf_read(sc->sc_pc, tag, offset); 1909 reg = pci_conf_read(sc->sc_pc, tag, offset);
1910 /* check cardbus master abort status */ 1910 /* check cardbus master abort status */
1911 if (pci_conf_read(sc->sc_pc, brtag, PCI_CBB_SECSTATUS) 1911 if (pci_conf_read(sc->sc_pc, brtag, PCI_CBB_SECSTATUS)
1912 & CBB_SECSTATUS_CBMABORT) 1912 & CBB_SECSTATUS_CBMABORT)
1913 return (0xffffffff); 1913 return (0xffffffff);
1914 return reg; 1914 return reg;
1915} 1915}
1916 1916
1917/* 1917/*
1918 * pccbb_conf_write 1918 * pccbb_conf_write
1919 * 1919 *
1920 * This is the function to write the config space of a CardBus 1920 * This is the function to write the config space of a CardBus
1921 * card. It works the same as pci_conf_write(9). 1921 * card. It works the same as pci_conf_write(9).
1922 */ 1922 */
1923static void 1923static void
1924pccbb_conf_write(cardbus_chipset_tag_t cc, cardbustag_t tag, int reg, 1924pccbb_conf_write(cardbus_chipset_tag_t cc, cardbustag_t tag, int reg,
1925 cardbusreg_t val) 1925 cardbusreg_t val)
1926{ 1926{
1927 struct pccbb_softc *sc = (struct pccbb_softc *)cc; 1927 struct pccbb_softc *sc = (struct pccbb_softc *)cc;
1928 1928
1929 pci_conf_write(sc->sc_pc, tag, reg, val); 1929 pci_conf_write(sc->sc_pc, tag, reg, val);
1930} 1930}
1931 1931
1932#if 0 1932#if 0
1933STATIC int 1933STATIC int
1934pccbb_new_pcmcia_io_alloc(pcmcia_chipset_handle_t pch, 1934pccbb_new_pcmcia_io_alloc(pcmcia_chipset_handle_t pch,
1935 bus_addr_t start, bus_size_t size, bus_size_t align, bus_addr_t mask, 1935 bus_addr_t start, bus_size_t size, bus_size_t align, bus_addr_t mask,
1936 int speed, int flags, 1936 int speed, int flags,
1937 bus_space_handle_t * iohp) 1937 bus_space_handle_t * iohp)
1938#endif 1938#endif
1939/* 1939/*
1940 * STATIC int pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t pch, 1940 * STATIC int pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t pch,
1941 * bus_addr_t start, bus_size_t size, 1941 * bus_addr_t start, bus_size_t size,
1942 * bus_size_t align, 1942 * bus_size_t align,
1943 * struct pcmcia_io_handle *pcihp 1943 * struct pcmcia_io_handle *pcihp
1944 * 1944 *
1945 * This function only allocates I/O region for pccard. This function 1945 * This function only allocates I/O region for pccard. This function
1946 * never maps the allocated region to pccard I/O area. 1946 * never maps the allocated region to pccard I/O area.
1947 * 1947 *
1948 * XXX: The interface of this function is not very good, I believe. 1948 * XXX: The interface of this function is not very good, I believe.
1949 */ 1949 */
1950STATIC int 1950STATIC int
1951pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, 1951pccbb_pcmcia_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start,
1952 bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp) 1952 bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp)
1953{ 1953{
1954 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 1954 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
1955 bus_addr_t ioaddr; 1955 bus_addr_t ioaddr;
1956 int flags = 0; 1956 int flags = 0;
1957 bus_space_tag_t iot; 1957 bus_space_tag_t iot;
1958 bus_space_handle_t ioh; 1958 bus_space_handle_t ioh;
1959 bus_addr_t mask; 1959 bus_addr_t mask;
1960#if rbus 1960#if rbus
1961 rbus_tag_t rb; 1961 rbus_tag_t rb;
1962#endif 1962#endif
1963 if (align == 0) { 1963 if (align == 0) {
1964 align = size; /* XXX: funny??? */ 1964 align = size; /* XXX: funny??? */
1965 } 1965 }
1966 1966
1967 if (start != 0) { 1967 if (start != 0) {
1968 /* XXX: assume all card decode lower 10 bits by its hardware */ 1968 /* XXX: assume all card decode lower 10 bits by its hardware */
1969 mask = 0x3ff; 1969 mask = 0x3ff;
1970 /* enforce to use only masked address */ 1970 /* enforce to use only masked address */
1971 start &= mask; 1971 start &= mask;
1972 } else { 1972 } else {
1973 /* 1973 /*
1974 * calculate mask: 1974 * calculate mask:
1975 * 1. get the most significant bit of size (call it msb). 1975 * 1. get the most significant bit of size (call it msb).
1976 * 2. compare msb with the value of size. 1976 * 2. compare msb with the value of size.
1977 * 3. if size is larger, shift msb left once. 1977 * 3. if size is larger, shift msb left once.
1978 * 4. obtain mask value to decrement msb. 1978 * 4. obtain mask value to decrement msb.
1979 */ 1979 */
1980 bus_size_t size_tmp = size; 1980 bus_size_t size_tmp = size;
1981 int shifts = 0; 1981 int shifts = 0;
1982 1982
1983 mask = 1; 1983 mask = 1;
1984 while (size_tmp) { 1984 while (size_tmp) {
1985 ++shifts; 1985 ++shifts;
1986 size_tmp >>= 1; 1986 size_tmp >>= 1;
1987 } 1987 }
1988 mask = (1 << shifts); 1988 mask = (1 << shifts);
1989 if (mask < size) { 1989 if (mask < size) {
1990 mask <<= 1; 1990 mask <<= 1;
1991 } 1991 }
1992 --mask; 1992 --mask;
1993 } 1993 }
1994 1994
1995 /* 1995 /*
1996 * Allocate some arbitrary I/O space. 1996 * Allocate some arbitrary I/O space.
1997 */ 1997 */
1998 1998
1999 iot = sc->sc_iot; 1999 iot = sc->sc_iot;
2000 2000
2001#if rbus 2001#if rbus
2002 rb = sc->sc_rbus_iot; 2002 rb = sc->sc_rbus_iot;
2003 if (rbus_space_alloc(rb, start, size, mask, align, 0, &ioaddr, &ioh)) { 2003 if (rbus_space_alloc(rb, start, size, mask, align, 0, &ioaddr, &ioh)) {
2004 return 1; 2004 return 1;
2005 } 2005 }
2006 DPRINTF(("pccbb_pcmcia_io_alloc alloc port 0x%lx+0x%lx\n", 2006 DPRINTF(("pccbb_pcmcia_io_alloc alloc port 0x%lx+0x%lx\n",
2007 (u_long) ioaddr, (u_long) size)); 2007 (u_long) ioaddr, (u_long) size));
2008#else 2008#else
2009 if (start) { 2009 if (start) {
2010 ioaddr = start; 2010 ioaddr = start;
2011 if (bus_space_map(iot, start, size, 0, &ioh)) { 2011 if (bus_space_map(iot, start, size, 0, &ioh)) {
2012 return 1; 2012 return 1;
2013 } 2013 }
2014 DPRINTF(("pccbb_pcmcia_io_alloc map port 0x%lx+0x%lx\n", 2014 DPRINTF(("pccbb_pcmcia_io_alloc map port 0x%lx+0x%lx\n",
2015 (u_long) ioaddr, (u_long) size)); 2015 (u_long) ioaddr, (u_long) size));
2016 } else { 2016 } else {
2017 flags |= PCMCIA_IO_ALLOCATED; 2017 flags |= PCMCIA_IO_ALLOCATED;
2018 if (bus_space_alloc(iot, 0x700 /* ph->sc->sc_iobase */ , 2018 if (bus_space_alloc(iot, 0x700 /* ph->sc->sc_iobase */ ,
2019 0x800, /* ph->sc->sc_iobase + ph->sc->sc_iosize */ 2019 0x800, /* ph->sc->sc_iobase + ph->sc->sc_iosize */
2020 size, align, 0, 0, &ioaddr, &ioh)) { 2020 size, align, 0, 0, &ioaddr, &ioh)) {
2021 /* No room be able to be get. */ 2021 /* No room be able to be get. */
2022 return 1; 2022 return 1;
2023 } 2023 }
2024 DPRINTF(("pccbb_pcmmcia_io_alloc alloc port 0x%lx+0x%lx\n", 2024 DPRINTF(("pccbb_pcmmcia_io_alloc alloc port 0x%lx+0x%lx\n",
2025 (u_long) ioaddr, (u_long) size)); 2025 (u_long) ioaddr, (u_long) size));
2026 } 2026 }
2027#endif 2027#endif
2028 2028
2029 pcihp->iot = iot; 2029 pcihp->iot = iot;
2030 pcihp->ioh = ioh; 2030 pcihp->ioh = ioh;
2031 pcihp->addr = ioaddr; 2031 pcihp->addr = ioaddr;
2032 pcihp->size = size; 2032 pcihp->size = size;
2033 pcihp->flags = flags; 2033 pcihp->flags = flags;
2034 2034
2035 return 0; 2035 return 0;
2036} 2036}
2037 2037
2038/* 2038/*
2039 * STATIC int pccbb_pcmcia_io_free(pcmcia_chipset_handle_t pch, 2039 * STATIC int pccbb_pcmcia_io_free(pcmcia_chipset_handle_t pch,
2040 * struct pcmcia_io_handle *pcihp) 2040 * struct pcmcia_io_handle *pcihp)
2041 * 2041 *
2042 * This function only frees I/O region for pccard. 2042 * This function only frees I/O region for pccard.
2043 * 2043 *
2044 * XXX: The interface of this function is not very good, I believe. 2044 * XXX: The interface of this function is not very good, I believe.
2045 */ 2045 */
2046void 2046void
2047pccbb_pcmcia_io_free(pcmcia_chipset_handle_t pch, 2047pccbb_pcmcia_io_free(pcmcia_chipset_handle_t pch,
2048 struct pcmcia_io_handle *pcihp) 2048 struct pcmcia_io_handle *pcihp)
2049{ 2049{
2050 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2050 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2051#if !rbus 2051#if !rbus
2052 bus_space_tag_t iot = pcihp->iot; 2052 bus_space_tag_t iot = pcihp->iot;
2053#endif 2053#endif
2054 bus_space_handle_t ioh = pcihp->ioh; 2054 bus_space_handle_t ioh = pcihp->ioh;
2055 bus_size_t size = pcihp->size; 2055 bus_size_t size = pcihp->size;
2056 2056
2057#if rbus 2057#if rbus
2058 rbus_tag_t rb = sc->sc_rbus_iot; 2058 rbus_tag_t rb = sc->sc_rbus_iot;
2059 2059
2060 rbus_space_free(rb, ioh, size, NULL); 2060 rbus_space_free(rb, ioh, size, NULL);
2061#else 2061#else
2062 if (pcihp->flags & PCMCIA_IO_ALLOCATED) 2062 if (pcihp->flags & PCMCIA_IO_ALLOCATED)
2063 bus_space_free(iot, ioh, size); 2063 bus_space_free(iot, ioh, size);
2064 else 2064 else
2065 bus_space_unmap(iot, ioh, size); 2065 bus_space_unmap(iot, ioh, size);
2066#endif 2066#endif
2067} 2067}
2068 2068
2069/* 2069/*
2070 * STATIC int pccbb_pcmcia_io_map(pcmcia_chipset_handle_t pch, int width, 2070 * STATIC int pccbb_pcmcia_io_map(pcmcia_chipset_handle_t pch, int width,
2071 * bus_addr_t offset, bus_size_t size, 2071 * bus_addr_t offset, bus_size_t size,
2072 * struct pcmcia_io_handle *pcihp, 2072 * struct pcmcia_io_handle *pcihp,
2073 * int *windowp) 2073 * int *windowp)
2074 * 2074 *
2075 * This function maps the allocated I/O region to pccard. This function 2075 * This function maps the allocated I/O region to pccard. This function
2076 * never allocates any I/O region for pccard I/O area. I don't 2076 * never allocates any I/O region for pccard I/O area. I don't
2077 * understand why the original authors of pcmciabus separated alloc and 2077 * understand why the original authors of pcmciabus separated alloc and
2078 * map. I believe the two must be unite. 2078 * map. I believe the two must be unite.
2079 * 2079 *
2080 * XXX: no wait timing control? 2080 * XXX: no wait timing control?
2081 */ 2081 */
2082int 2082int
2083pccbb_pcmcia_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset, 2083pccbb_pcmcia_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
2084 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp) 2084 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
2085{ 2085{
2086 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2086 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2087 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2087 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2088 bus_addr_t ioaddr = pcihp->addr + offset; 2088 bus_addr_t ioaddr = pcihp->addr + offset;
2089 int i, win; 2089 int i, win;
2090#if defined CBB_DEBUG 2090#if defined CBB_DEBUG
2091 static const char *width_names[] = { "dynamic", "io8", "io16" }; 2091 static const char *width_names[] = { "dynamic", "io8", "io16" };
2092#endif 2092#endif
2093 2093
2094 /* Sanity check I/O handle. */ 2094 /* Sanity check I/O handle. */
2095 2095
2096 if (sc->sc_iot != pcihp->iot) { 2096 if (sc->sc_iot != pcihp->iot) {
2097 panic("pccbb_pcmcia_io_map iot is bogus"); 2097 panic("pccbb_pcmcia_io_map iot is bogus");
2098 } 2098 }
2099 2099
2100 /* XXX Sanity check offset/size. */ 2100 /* XXX Sanity check offset/size. */
2101 2101
2102 win = -1; 2102 win = -1;
2103 for (i = 0; i < PCIC_IO_WINS; i++) { 2103 for (i = 0; i < PCIC_IO_WINS; i++) {
2104 if ((ph->ioalloc & (1 << i)) == 0) { 2104 if ((ph->ioalloc & (1 << i)) == 0) {
2105 win = i; 2105 win = i;
2106 ph->ioalloc |= (1 << i); 2106 ph->ioalloc |= (1 << i);
2107 break; 2107 break;
2108 } 2108 }
2109 } 2109 }
2110 2110
2111 if (win == -1) { 2111 if (win == -1) {
2112 return 1; 2112 return 1;
2113 } 2113 }
2114 2114
2115 *windowp = win; 2115 *windowp = win;
2116 2116
2117 /* XXX this is pretty gross */ 2117 /* XXX this is pretty gross */
2118 2118
2119 DPRINTF(("pccbb_pcmcia_io_map window %d %s port %lx+%lx\n", 2119 DPRINTF(("pccbb_pcmcia_io_map window %d %s port %lx+%lx\n",
2120 win, width_names[width], (u_long) ioaddr, (u_long) size)); 2120 win, width_names[width], (u_long) ioaddr, (u_long) size));
2121 2121
2122 /* XXX wtf is this doing here? */ 2122 /* XXX wtf is this doing here? */
2123 2123
2124#if 0 2124#if 0
2125 printf(" port 0x%lx", (u_long) ioaddr); 2125 printf(" port 0x%lx", (u_long) ioaddr);
2126 if (size > 1) { 2126 if (size > 1) {
2127 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1); 2127 printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1);
2128 } 2128 }
2129#endif 2129#endif
2130 2130
2131 ph->io[win].addr = ioaddr; 2131 ph->io[win].addr = ioaddr;
2132 ph->io[win].size = size; 2132 ph->io[win].size = size;
2133 ph->io[win].width = width; 2133 ph->io[win].width = width;
2134 2134
2135 /* actual dirty register-value changing in the function below. */ 2135 /* actual dirty register-value changing in the function below. */
2136 pccbb_pcmcia_do_io_map(sc, win); 2136 pccbb_pcmcia_do_io_map(sc, win);
2137 2137
2138 return 0; 2138 return 0;
2139} 2139}
2140 2140
2141/* 2141/*
2142 * STATIC void pccbb_pcmcia_do_io_map(struct pcic_handle *h, int win) 2142 * STATIC void pccbb_pcmcia_do_io_map(struct pcic_handle *h, int win)
2143 * 2143 *
2144 * This function changes register-value to map I/O region for pccard. 2144 * This function changes register-value to map I/O region for pccard.
2145 */ 2145 */
2146static void 2146static void
2147pccbb_pcmcia_do_io_map(struct pccbb_softc *sc, int win) 2147pccbb_pcmcia_do_io_map(struct pccbb_softc *sc, int win)
2148{ 2148{
2149 static u_int8_t pcic_iowidth[3] = { 2149 static u_int8_t pcic_iowidth[3] = {
2150 PCIC_IOCTL_IO0_IOCS16SRC_CARD, 2150 PCIC_IOCTL_IO0_IOCS16SRC_CARD,
2151 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | 2151 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE |
2152 PCIC_IOCTL_IO0_DATASIZE_8BIT, 2152 PCIC_IOCTL_IO0_DATASIZE_8BIT,
2153 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | 2153 PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE |
2154 PCIC_IOCTL_IO0_DATASIZE_16BIT, 2154 PCIC_IOCTL_IO0_DATASIZE_16BIT,
2155 }; 2155 };
2156 2156
2157#define PCIC_SIA_START_LOW 0 2157#define PCIC_SIA_START_LOW 0
2158#define PCIC_SIA_START_HIGH 1 2158#define PCIC_SIA_START_HIGH 1
2159#define PCIC_SIA_STOP_LOW 2 2159#define PCIC_SIA_STOP_LOW 2
2160#define PCIC_SIA_STOP_HIGH 3 2160#define PCIC_SIA_STOP_HIGH 3
2161 2161
2162 int regbase_win = 0x8 + win * 0x04; 2162 int regbase_win = 0x8 + win * 0x04;
2163 u_int8_t ioctl, enable; 2163 u_int8_t ioctl, enable;
2164 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2164 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2165 2165
2166 DPRINTF(("pccbb_pcmcia_do_io_map win %d addr 0x%lx size 0x%lx " 2166 DPRINTF(("pccbb_pcmcia_do_io_map win %d addr 0x%lx size 0x%lx "
2167 "width %d\n", win, (unsigned long)ph->io[win].addr, 2167 "width %d\n", win, (unsigned long)ph->io[win].addr,
2168 (unsigned long)ph->io[win].size, ph->io[win].width * 8)); 2168 (unsigned long)ph->io[win].size, ph->io[win].width * 8));
2169 2169
2170 Pcic_write(sc, regbase_win + PCIC_SIA_START_LOW, 2170 Pcic_write(sc, regbase_win + PCIC_SIA_START_LOW,
2171 ph->io[win].addr & 0xff); 2171 ph->io[win].addr & 0xff);
2172 Pcic_write(sc, regbase_win + PCIC_SIA_START_HIGH, 2172 Pcic_write(sc, regbase_win + PCIC_SIA_START_HIGH,
2173 (ph->io[win].addr >> 8) & 0xff); 2173 (ph->io[win].addr >> 8) & 0xff);
2174 2174
2175 Pcic_write(sc, regbase_win + PCIC_SIA_STOP_LOW, 2175 Pcic_write(sc, regbase_win + PCIC_SIA_STOP_LOW,
2176 (ph->io[win].addr + ph->io[win].size - 1) & 0xff); 2176 (ph->io[win].addr + ph->io[win].size - 1) & 0xff);
2177 Pcic_write(sc, regbase_win + PCIC_SIA_STOP_HIGH, 2177 Pcic_write(sc, regbase_win + PCIC_SIA_STOP_HIGH,
2178 ((ph->io[win].addr + ph->io[win].size - 1) >> 8) & 0xff); 2178 ((ph->io[win].addr + ph->io[win].size - 1) >> 8) & 0xff);
2179 2179
2180 ioctl = Pcic_read(sc, PCIC_IOCTL); 2180 ioctl = Pcic_read(sc, PCIC_IOCTL);
2181 enable = Pcic_read(sc, PCIC_ADDRWIN_ENABLE); 2181 enable = Pcic_read(sc, PCIC_ADDRWIN_ENABLE);
2182 switch (win) { 2182 switch (win) {
2183 case 0: 2183 case 0:
2184 ioctl &= ~(PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT | 2184 ioctl &= ~(PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT |
2185 PCIC_IOCTL_IO0_IOCS16SRC_MASK | 2185 PCIC_IOCTL_IO0_IOCS16SRC_MASK |
2186 PCIC_IOCTL_IO0_DATASIZE_MASK); 2186 PCIC_IOCTL_IO0_DATASIZE_MASK);
2187 ioctl |= pcic_iowidth[ph->io[win].width]; 2187 ioctl |= pcic_iowidth[ph->io[win].width];
2188 enable |= PCIC_ADDRWIN_ENABLE_IO0; 2188 enable |= PCIC_ADDRWIN_ENABLE_IO0;
2189 break; 2189 break;
2190 case 1: 2190 case 1:
2191 ioctl &= ~(PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT | 2191 ioctl &= ~(PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT |
2192 PCIC_IOCTL_IO1_IOCS16SRC_MASK | 2192 PCIC_IOCTL_IO1_IOCS16SRC_MASK |
2193 PCIC_IOCTL_IO1_DATASIZE_MASK); 2193 PCIC_IOCTL_IO1_DATASIZE_MASK);
2194 ioctl |= (pcic_iowidth[ph->io[win].width] << 4); 2194 ioctl |= (pcic_iowidth[ph->io[win].width] << 4);
2195 enable |= PCIC_ADDRWIN_ENABLE_IO1; 2195 enable |= PCIC_ADDRWIN_ENABLE_IO1;
2196 break; 2196 break;
2197 } 2197 }
2198 Pcic_write(sc, PCIC_IOCTL, ioctl); 2198 Pcic_write(sc, PCIC_IOCTL, ioctl);
2199 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, enable); 2199 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, enable);
2200#if defined(CBB_DEBUG) 2200#if defined(CBB_DEBUG)
2201 { 2201 {
2202 u_int8_t start_low = 2202 u_int8_t start_low =
2203 Pcic_read(sc, regbase_win + PCIC_SIA_START_LOW); 2203 Pcic_read(sc, regbase_win + PCIC_SIA_START_LOW);
2204 u_int8_t start_high = 2204 u_int8_t start_high =
2205 Pcic_read(sc, regbase_win + PCIC_SIA_START_HIGH); 2205 Pcic_read(sc, regbase_win + PCIC_SIA_START_HIGH);
2206 u_int8_t stop_low = 2206 u_int8_t stop_low =
2207 Pcic_read(sc, regbase_win + PCIC_SIA_STOP_LOW); 2207 Pcic_read(sc, regbase_win + PCIC_SIA_STOP_LOW);
2208 u_int8_t stop_high = 2208 u_int8_t stop_high =
2209 Pcic_read(sc, regbase_win + PCIC_SIA_STOP_HIGH); 2209 Pcic_read(sc, regbase_win + PCIC_SIA_STOP_HIGH);
2210 printf("pccbb_pcmcia_do_io_map start %02x %02x, " 2210 printf("pccbb_pcmcia_do_io_map start %02x %02x, "
2211 "stop %02x %02x, ioctl %02x enable %02x\n", 2211 "stop %02x %02x, ioctl %02x enable %02x\n",
2212 start_low, start_high, stop_low, stop_high, ioctl, enable); 2212 start_low, start_high, stop_low, stop_high, ioctl, enable);
2213 } 2213 }
2214#endif 2214#endif
2215} 2215}
2216 2216
2217/* 2217/*
2218 * STATIC void pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t *h, int win) 2218 * STATIC void pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t *h, int win)
2219 * 2219 *
2220 * This function unmaps I/O region. No return value. 2220 * This function unmaps I/O region. No return value.
2221 */ 2221 */
2222STATIC void 2222STATIC void
2223pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t pch, int win) 2223pccbb_pcmcia_io_unmap(pcmcia_chipset_handle_t pch, int win)
2224{ 2224{
2225 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2225 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2226 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2226 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2227 int reg; 2227 int reg;
2228 2228
2229 if (win >= PCIC_IO_WINS || win < 0) { 2229 if (win >= PCIC_IO_WINS || win < 0) {
2230 panic("pccbb_pcmcia_io_unmap: window out of range"); 2230 panic("pccbb_pcmcia_io_unmap: window out of range");
2231 } 2231 }
2232 2232
2233 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE); 2233 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE);
2234 switch (win) { 2234 switch (win) {
2235 case 0: 2235 case 0:
2236 reg &= ~PCIC_ADDRWIN_ENABLE_IO0; 2236 reg &= ~PCIC_ADDRWIN_ENABLE_IO0;
2237 break; 2237 break;
2238 case 1: 2238 case 1:
2239 reg &= ~PCIC_ADDRWIN_ENABLE_IO1; 2239 reg &= ~PCIC_ADDRWIN_ENABLE_IO1;
2240 break; 2240 break;
2241 } 2241 }
2242 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg); 2242 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg);
2243 2243
2244 ph->ioalloc &= ~(1 << win); 2244 ph->ioalloc &= ~(1 << win);
2245} 2245}
2246 2246
2247static int 2247static int
2248pccbb_pcmcia_wait_ready(struct pccbb_softc *sc) 2248pccbb_pcmcia_wait_ready(struct pccbb_softc *sc)
2249{ 2249{
2250 u_int8_t stat; 2250 u_int8_t stat;
2251 int i; 2251 int i;
2252 2252
2253 /* wait an initial 10ms for quick cards */ 2253 /* wait an initial 10ms for quick cards */
2254 stat = Pcic_read(sc, PCIC_IF_STATUS); 2254 stat = Pcic_read(sc, PCIC_IF_STATUS);
2255 if (stat & PCIC_IF_STATUS_READY) 2255 if (stat & PCIC_IF_STATUS_READY)
2256 return (0); 2256 return (0);
2257 pccbb_pcmcia_delay(sc, 10, "pccwr0"); 2257 pccbb_pcmcia_delay(sc, 10, "pccwr0");
2258 for (i = 0; i < 50; i++) { 2258 for (i = 0; i < 50; i++) {
2259 stat = Pcic_read(sc, PCIC_IF_STATUS); 2259 stat = Pcic_read(sc, PCIC_IF_STATUS);
2260 if (stat & PCIC_IF_STATUS_READY) 2260 if (stat & PCIC_IF_STATUS_READY)
2261 return (0); 2261 return (0);
2262 if ((stat & PCIC_IF_STATUS_CARDDETECT_MASK) != 2262 if ((stat & PCIC_IF_STATUS_CARDDETECT_MASK) !=
2263 PCIC_IF_STATUS_CARDDETECT_PRESENT) 2263 PCIC_IF_STATUS_CARDDETECT_PRESENT)
2264 return (ENXIO); 2264 return (ENXIO);
2265 /* wait .1s (100ms) each iteration now */ 2265 /* wait .1s (100ms) each iteration now */
2266 pccbb_pcmcia_delay(sc, 100, "pccwr1"); 2266 pccbb_pcmcia_delay(sc, 100, "pccwr1");
2267 } 2267 }
2268 2268
2269 printf("pccbb_pcmcia_wait_ready: ready never happened, status=%02x\n", stat); 2269 printf("pccbb_pcmcia_wait_ready: ready never happened, status=%02x\n", stat);
2270 return (EWOULDBLOCK); 2270 return (EWOULDBLOCK);
2271} 2271}
2272 2272
2273/* 2273/*
2274 * Perform long (msec order) delay. timo is in milliseconds. 2274 * Perform long (msec order) delay. timo is in milliseconds.
2275 */ 2275 */
2276static void 2276static void
2277pccbb_pcmcia_delay(struct pccbb_softc *sc, int timo, const char *wmesg) 2277pccbb_pcmcia_delay(struct pccbb_softc *sc, int timo, const char *wmesg)
2278{ 2278{
2279#ifdef DIAGNOSTIC 2279#ifdef DIAGNOSTIC
2280 if (timo <= 0) 2280 if (timo <= 0)
2281 panic("pccbb_pcmcia_delay: called with timeout %d", timo); 2281 panic("pccbb_pcmcia_delay: called with timeout %d", timo);
2282 if (!curlwp) 2282 if (!curlwp)
2283 panic("pccbb_pcmcia_delay: called in interrupt context"); 2283 panic("pccbb_pcmcia_delay: called in interrupt context");
2284#endif 2284#endif
2285 DPRINTF(("pccbb_pcmcia_delay: \"%s\", sleep %d ms\n", wmesg, timo)); 2285 DPRINTF(("pccbb_pcmcia_delay: \"%s\", sleep %d ms\n", wmesg, timo));
2286 tsleep(pccbb_pcmcia_delay, PWAIT, wmesg, roundup(timo * hz, 1000) / 1000); 2286 tsleep(pccbb_pcmcia_delay, PWAIT, wmesg, roundup(timo * hz, 1000) / 1000);
2287} 2287}
2288 2288
2289/* 2289/*
2290 * STATIC void pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t pch) 2290 * STATIC void pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t pch)
2291 * 2291 *
2292 * This function enables the card. All information is stored in 2292 * This function enables the card. All information is stored in
2293 * the first argument, pcmcia_chipset_handle_t. 2293 * the first argument, pcmcia_chipset_handle_t.
2294 */ 2294 */
2295STATIC void 2295STATIC void
2296pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t pch) 2296pccbb_pcmcia_socket_enable(pcmcia_chipset_handle_t pch)
2297{ 2297{
2298 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2298 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2299 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2299 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2300 pcireg_t spsr; 2300 pcireg_t spsr;
2301 int voltage; 2301 int voltage;
2302 int win; 2302 int win;
2303 u_int8_t power, intr; 2303 u_int8_t power, intr;
2304#ifdef DIAGNOSTIC 2304#ifdef DIAGNOSTIC
2305 int reg; 2305 int reg;
2306#endif 2306#endif
2307 2307
2308 /* this bit is mostly stolen from pcic_attach_card */ 2308 /* this bit is mostly stolen from pcic_attach_card */
2309 2309
2310 DPRINTF(("pccbb_pcmcia_socket_enable: ")); 2310 DPRINTF(("pccbb_pcmcia_socket_enable: "));
2311 2311
2312 /* get card Vcc info */ 2312 /* get card Vcc info */
2313 spsr = 2313 spsr =
2314 bus_space_read_4(sc->sc_base_memt, sc->sc_base_memh, 2314 bus_space_read_4(sc->sc_base_memt, sc->sc_base_memh,
2315 CB_SOCKET_STAT); 2315 CB_SOCKET_STAT);
2316 if (spsr & CB_SOCKET_STAT_5VCARD) { 2316 if (spsr & CB_SOCKET_STAT_5VCARD) {
2317 DPRINTF(("5V card\n")); 2317 DPRINTF(("5V card\n"));
2318 voltage = CARDBUS_VCC_5V | CARDBUS_VPP_VCC; 2318 voltage = CARDBUS_VCC_5V | CARDBUS_VPP_VCC;
2319 } else if (spsr & CB_SOCKET_STAT_3VCARD) { 2319 } else if (spsr & CB_SOCKET_STAT_3VCARD) {
2320 DPRINTF(("3V card\n")); 2320 DPRINTF(("3V card\n"));
2321 voltage = CARDBUS_VCC_3V | CARDBUS_VPP_VCC; 2321 voltage = CARDBUS_VCC_3V | CARDBUS_VPP_VCC;
2322 } else { 2322 } else {
2323 DPRINTF(("?V card, 0x%x\n", spsr)); /* XXX */ 2323 DPRINTF(("?V card, 0x%x\n", spsr)); /* XXX */
2324 return; 2324 return;
2325 } 2325 }
2326 2326
2327 /* disable interrupts; assert RESET */ 2327 /* disable interrupts; assert RESET */
2328 intr = Pcic_read(sc, PCIC_INTR); 2328 intr = Pcic_read(sc, PCIC_INTR);
2329 intr &= PCIC_INTR_ENABLE; 2329 intr &= PCIC_INTR_ENABLE;
2330 Pcic_write(sc, PCIC_INTR, intr); 2330 Pcic_write(sc, PCIC_INTR, intr);
2331 2331
2332 /* zero out the address windows */ 2332 /* zero out the address windows */
2333 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, 0); 2333 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, 0);
2334 2334
2335 /* power down the socket to reset it, clear the card reset pin */ 2335 /* power down the socket to reset it, clear the card reset pin */
2336 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V); 2336 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V);
2337 2337
2338 /* power off; assert output enable bit */ 2338 /* power off; assert output enable bit */
2339 power = PCIC_PWRCTL_OE; 2339 power = PCIC_PWRCTL_OE;
2340 Pcic_write(sc, PCIC_PWRCTL, power); 2340 Pcic_write(sc, PCIC_PWRCTL, power);
2341 2341
2342 /* power up the socket */ 2342 /* power up the socket */
2343 if (pccbb_power(sc, voltage) == 0) 2343 if (pccbb_power(sc, voltage) == 0)
2344 return; 2344 return;
2345 2345
2346 /* 2346 /*
2347 * Table 4-18 and figure 4-6 of the PC Card specifiction say: 2347 * Table 4-18 and figure 4-6 of the PC Card specifiction say:
2348 * Vcc Rising Time (Tpr) = 100ms (handled in pccbb_power() above) 2348 * Vcc Rising Time (Tpr) = 100ms (handled in pccbb_power() above)
2349 * RESET Width (Th (Hi-z RESET)) = 1ms 2349 * RESET Width (Th (Hi-z RESET)) = 1ms
2350 * RESET Width (Tw (RESET)) = 10us 2350 * RESET Width (Tw (RESET)) = 10us
2351 *  2351 *
2352 * some machines require some more time to be settled 2352 * some machines require some more time to be settled
2353 * for example old toshiba topic bridges! 2353 * for example old toshiba topic bridges!
2354 * (100ms is added here). 2354 * (100ms is added here).
2355 */  2355 */
2356 pccbb_pcmcia_delay(sc, 200 + 1, "pccen1"); 2356 pccbb_pcmcia_delay(sc, 200 + 1, "pccen1");
2357 2357
2358 /* negate RESET */ 2358 /* negate RESET */
2359 intr |= PCIC_INTR_RESET; 2359 intr |= PCIC_INTR_RESET;
2360 Pcic_write(sc, PCIC_INTR, intr); 2360 Pcic_write(sc, PCIC_INTR, intr);
2361 2361
2362 /* 2362 /*
2363 * RESET Setup Time (Tsu (RESET)) = 20ms 2363 * RESET Setup Time (Tsu (RESET)) = 20ms
2364 */ 2364 */
2365 pccbb_pcmcia_delay(sc, 20, "pccen2"); 2365 pccbb_pcmcia_delay(sc, 20, "pccen2");
2366 2366
2367#ifdef DIAGNOSTIC 2367#ifdef DIAGNOSTIC
2368 reg = Pcic_read(sc, PCIC_IF_STATUS); 2368 reg = Pcic_read(sc, PCIC_IF_STATUS);
2369 if ((reg & PCIC_IF_STATUS_POWERACTIVE) == 0) 2369 if ((reg & PCIC_IF_STATUS_POWERACTIVE) == 0)
2370 printf("pccbb_pcmcia_socket_enable: no power, status=%x\n", reg); 2370 printf("pccbb_pcmcia_socket_enable: no power, status=%x\n", reg);
2371#endif 2371#endif
2372 2372
2373 /* wait for the chip to finish initializing */ 2373 /* wait for the chip to finish initializing */
2374 if (pccbb_pcmcia_wait_ready(sc)) { 2374 if (pccbb_pcmcia_wait_ready(sc)) {
2375#ifdef DIAGNOSTIC 2375#ifdef DIAGNOSTIC
2376 printf("pccbb_pcmcia_socket_enable: never became ready\n"); 2376 printf("pccbb_pcmcia_socket_enable: never became ready\n");
2377#endif 2377#endif
2378 /* XXX return a failure status?? */ 2378 /* XXX return a failure status?? */
2379 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V); 2379 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V);
2380 Pcic_write(sc, PCIC_PWRCTL, 0); 2380 Pcic_write(sc, PCIC_PWRCTL, 0);
2381 return; 2381 return;
2382 } 2382 }
2383 2383
2384 /* reinstall all the memory and io mappings */ 2384 /* reinstall all the memory and io mappings */
2385 for (win = 0; win < PCIC_MEM_WINS; ++win) 2385 for (win = 0; win < PCIC_MEM_WINS; ++win)
2386 if (ph->memalloc & (1 << win)) 2386 if (ph->memalloc & (1 << win))
2387 pccbb_pcmcia_do_mem_map(sc, win); 2387 pccbb_pcmcia_do_mem_map(sc, win);
2388 for (win = 0; win < PCIC_IO_WINS; ++win) 2388 for (win = 0; win < PCIC_IO_WINS; ++win)
2389 if (ph->ioalloc & (1 << win)) 2389 if (ph->ioalloc & (1 << win))
2390 pccbb_pcmcia_do_io_map(sc, win); 2390 pccbb_pcmcia_do_io_map(sc, win);
2391} 2391}
2392 2392
2393/* 2393/*
2394 * STATIC void pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t *ph) 2394 * STATIC void pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t *ph)
2395 * 2395 *
2396 * This function disables the card. All information is stored in 2396 * This function disables the card. All information is stored in
2397 * the first argument, pcmcia_chipset_handle_t. 2397 * the first argument, pcmcia_chipset_handle_t.
2398 */ 2398 */
2399STATIC void 2399STATIC void
2400pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t pch) 2400pccbb_pcmcia_socket_disable(pcmcia_chipset_handle_t pch)
2401{ 2401{
2402 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2402 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2403 u_int8_t intr; 2403 u_int8_t intr;
2404 2404
2405 DPRINTF(("pccbb_pcmcia_socket_disable\n")); 2405 DPRINTF(("pccbb_pcmcia_socket_disable\n"));
2406 2406
2407 /* disable interrupts; assert RESET */ 2407 /* disable interrupts; assert RESET */
2408 intr = Pcic_read(sc, PCIC_INTR); 2408 intr = Pcic_read(sc, PCIC_INTR);
2409 intr &= PCIC_INTR_ENABLE; 2409 intr &= PCIC_INTR_ENABLE;
2410 Pcic_write(sc, PCIC_INTR, intr); 2410 Pcic_write(sc, PCIC_INTR, intr);
2411 2411
2412 /* zero out the address windows */ 2412 /* zero out the address windows */
2413 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, 0); 2413 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, 0);
2414 2414
2415 /* power down the socket to reset it, clear the card reset pin */ 2415 /* power down the socket to reset it, clear the card reset pin */
2416 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V); 2416 pccbb_power(sc, CARDBUS_VCC_0V | CARDBUS_VPP_0V);
2417 2417
2418 /* disable socket: negate output enable bit and power off */ 2418 /* disable socket: negate output enable bit and power off */
2419 Pcic_write(sc, PCIC_PWRCTL, 0); 2419 Pcic_write(sc, PCIC_PWRCTL, 0);
2420 2420
2421 /* 2421 /*
2422 * Vcc Falling Time (Tpf) = 300ms 2422 * Vcc Falling Time (Tpf) = 300ms
2423 */ 2423 */
2424 pccbb_pcmcia_delay(sc, 300, "pccwr1"); 2424 pccbb_pcmcia_delay(sc, 300, "pccwr1");
2425} 2425}
2426 2426
2427STATIC void 2427STATIC void
2428pccbb_pcmcia_socket_settype(pcmcia_chipset_handle_t pch, int type) 2428pccbb_pcmcia_socket_settype(pcmcia_chipset_handle_t pch, int type)
2429{ 2429{
2430 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2430 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2431 u_int8_t intr; 2431 u_int8_t intr;
2432 2432
2433 /* set the card type */ 2433 /* set the card type */
2434 2434
2435 intr = Pcic_read(sc, PCIC_INTR); 2435 intr = Pcic_read(sc, PCIC_INTR);
2436 intr &= ~(PCIC_INTR_IRQ_MASK | PCIC_INTR_CARDTYPE_MASK); 2436 intr &= ~(PCIC_INTR_IRQ_MASK | PCIC_INTR_CARDTYPE_MASK);
2437 if (type == PCMCIA_IFTYPE_IO) 2437 if (type == PCMCIA_IFTYPE_IO)
2438 intr |= PCIC_INTR_CARDTYPE_IO; 2438 intr |= PCIC_INTR_CARDTYPE_IO;
2439 else 2439 else
2440 intr |= PCIC_INTR_CARDTYPE_MEM; 2440 intr |= PCIC_INTR_CARDTYPE_MEM;
2441 Pcic_write(sc, PCIC_INTR, intr); 2441 Pcic_write(sc, PCIC_INTR, intr);
2442 2442
2443 DPRINTF(("%s: pccbb_pcmcia_socket_settype type %s %02x\n", 2443 DPRINTF(("%s: pccbb_pcmcia_socket_settype type %s %02x\n",
2444 device_xname(sc->sc_dev), 2444 device_xname(sc->sc_dev),
2445 ((type == PCMCIA_IFTYPE_IO) ? "io" : "mem"), intr)); 2445 ((type == PCMCIA_IFTYPE_IO) ? "io" : "mem"), intr));
2446} 2446}
2447 2447
2448/* 2448/*
2449 * STATIC int pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t *ph) 2449 * STATIC int pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t *ph)
2450 * 2450 *
2451 * This function detects whether a card is in the slot or not. 2451 * This function detects whether a card is in the slot or not.
2452 * If a card is inserted, return 1. Otherwise, return 0. 2452 * If a card is inserted, return 1. Otherwise, return 0.
2453 */ 2453 */
2454STATIC int 2454STATIC int
2455pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t pch) 2455pccbb_pcmcia_card_detect(pcmcia_chipset_handle_t pch)
2456{ 2456{
2457 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2457 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2458 2458
2459 DPRINTF(("pccbb_pcmcia_card_detect\n")); 2459 DPRINTF(("pccbb_pcmcia_card_detect\n"));
2460 return pccbb_detect_card(sc) == 1 ? 1 : 0; 2460 return pccbb_detect_card(sc) == 1 ? 1 : 0;
2461} 2461}
2462 2462
2463#if 0 2463#if 0
2464STATIC int 2464STATIC int
2465pccbb_new_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch, 2465pccbb_new_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch,
2466 bus_addr_t start, bus_size_t size, bus_size_t align, int speed, int flags, 2466 bus_addr_t start, bus_size_t size, bus_size_t align, int speed, int flags,
2467 bus_space_tag_t * memtp bus_space_handle_t * memhp) 2467 bus_space_tag_t * memtp bus_space_handle_t * memhp)
2468#endif 2468#endif
2469/* 2469/*
2470 * STATIC int pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch, 2470 * STATIC int pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch,
2471 * bus_size_t size, 2471 * bus_size_t size,
2472 * struct pcmcia_mem_handle *pcmhp) 2472 * struct pcmcia_mem_handle *pcmhp)
2473 * 2473 *
2474 * This function only allocates memory region for pccard. This 2474 * This function only allocates memory region for pccard. This
2475 * function never maps the allocated region to pccard memory area. 2475 * function never maps the allocated region to pccard memory area.
2476 * 2476 *
2477 * XXX: Why the argument of start address is not in? 2477 * XXX: Why the argument of start address is not in?
2478 */ 2478 */
2479STATIC int 2479STATIC int
2480pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size, 2480pccbb_pcmcia_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
2481 struct pcmcia_mem_handle *pcmhp) 2481 struct pcmcia_mem_handle *pcmhp)
2482{ 2482{
2483 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2483 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2484 bus_space_handle_t memh; 2484 bus_space_handle_t memh;
2485 bus_addr_t addr; 2485 bus_addr_t addr;
2486 bus_size_t sizepg; 2486 bus_size_t sizepg;
2487#if rbus 2487#if rbus
2488 rbus_tag_t rb; 2488 rbus_tag_t rb;
2489#endif 2489#endif
2490 2490
2491 /* Check that the card is still there. */ 2491 /* Check that the card is still there. */
2492 if ((Pcic_read(sc, PCIC_IF_STATUS) & PCIC_IF_STATUS_CARDDETECT_MASK) != 2492 if ((Pcic_read(sc, PCIC_IF_STATUS) & PCIC_IF_STATUS_CARDDETECT_MASK) !=
2493 PCIC_IF_STATUS_CARDDETECT_PRESENT) 2493 PCIC_IF_STATUS_CARDDETECT_PRESENT)
2494 return 1; 2494 return 1;
2495 2495
2496 /* out of sc->memh, allocate as many pages as necessary */ 2496 /* out of sc->memh, allocate as many pages as necessary */
2497 2497
2498 /* convert size to PCIC pages */ 2498 /* convert size to PCIC pages */
2499 /* 2499 /*
2500 * This is not enough; when the requested region is on the page 2500 * This is not enough; when the requested region is on the page
2501 * boundaries, this may calculate wrong result. 2501 * boundaries, this may calculate wrong result.
2502 */ 2502 */
2503 sizepg = (size + (PCIC_MEM_PAGESIZE - 1)) / PCIC_MEM_PAGESIZE; 2503 sizepg = (size + (PCIC_MEM_PAGESIZE - 1)) / PCIC_MEM_PAGESIZE;
2504#if 0 2504#if 0
2505 if (sizepg > PCIC_MAX_MEM_PAGES) { 2505 if (sizepg > PCIC_MAX_MEM_PAGES) {
2506 return 1; 2506 return 1;
2507 } 2507 }
2508#endif 2508#endif
2509 2509
2510 if (!(sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32)) { 2510 if (!(sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32)) {
2511 return 1; 2511 return 1;
2512 } 2512 }
2513 2513
2514 addr = 0; /* XXX gcc -Wuninitialized */ 2514 addr = 0; /* XXX gcc -Wuninitialized */
2515 2515
2516#if rbus 2516#if rbus
2517 rb = sc->sc_rbus_memt; 2517 rb = sc->sc_rbus_memt;
2518 if (rbus_space_alloc(rb, 0, sizepg * PCIC_MEM_PAGESIZE, 2518 if (rbus_space_alloc(rb, 0, sizepg * PCIC_MEM_PAGESIZE,
2519 sizepg * PCIC_MEM_PAGESIZE - 1, PCIC_MEM_PAGESIZE, 0, 2519 sizepg * PCIC_MEM_PAGESIZE - 1, PCIC_MEM_PAGESIZE, 0,
2520 &addr, &memh)) { 2520 &addr, &memh)) {
2521 return 1; 2521 return 1;
2522 } 2522 }
2523#else 2523#else
2524 if (bus_space_alloc(sc->sc_memt, sc->sc_mem_start, sc->sc_mem_end, 2524 if (bus_space_alloc(sc->sc_memt, sc->sc_mem_start, sc->sc_mem_end,
2525 sizepg * PCIC_MEM_PAGESIZE, PCIC_MEM_PAGESIZE, 2525 sizepg * PCIC_MEM_PAGESIZE, PCIC_MEM_PAGESIZE,
2526 0, /* boundary */ 2526 0, /* boundary */
2527 0, /* flags */ 2527 0, /* flags */
2528 &addr, &memh)) { 2528 &addr, &memh)) {
2529 return 1; 2529 return 1;
2530 } 2530 }
2531#endif 2531#endif
2532 2532
2533 DPRINTF(("pccbb_pcmcia_alloc_mem: addr 0x%lx size 0x%lx, " 2533 DPRINTF(("pccbb_pcmcia_alloc_mem: addr 0x%lx size 0x%lx, "
2534 "realsize 0x%lx\n", (unsigned long)addr, (unsigned long)size, 2534 "realsize 0x%lx\n", (unsigned long)addr, (unsigned long)size,
2535 (unsigned long)sizepg * PCIC_MEM_PAGESIZE)); 2535 (unsigned long)sizepg * PCIC_MEM_PAGESIZE));
2536 2536
2537 pcmhp->memt = sc->sc_memt; 2537 pcmhp->memt = sc->sc_memt;
2538 pcmhp->memh = memh; 2538 pcmhp->memh = memh;
2539 pcmhp->addr = addr; 2539 pcmhp->addr = addr;
2540 pcmhp->size = size; 2540 pcmhp->size = size;
2541 pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE; 2541 pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE;
2542 /* What is mhandle? I feel it is very dirty and it must go trush. */ 2542 /* What is mhandle? I feel it is very dirty and it must go trush. */
2543 pcmhp->mhandle = 0; 2543 pcmhp->mhandle = 0;
2544 /* No offset??? Funny. */ 2544 /* No offset??? Funny. */
2545 2545
2546 return 0; 2546 return 0;
2547} 2547}
2548 2548
2549/* 2549/*
2550 * STATIC void pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t pch, 2550 * STATIC void pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t pch,
2551 * struct pcmcia_mem_handle *pcmhp) 2551 * struct pcmcia_mem_handle *pcmhp)
2552 * 2552 *
2553 * This function release the memory space allocated by the function 2553 * This function release the memory space allocated by the function
2554 * pccbb_pcmcia_mem_alloc(). 2554 * pccbb_pcmcia_mem_alloc().
2555 */ 2555 */
2556STATIC void 2556STATIC void
2557pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t pch, 2557pccbb_pcmcia_mem_free(pcmcia_chipset_handle_t pch,
2558 struct pcmcia_mem_handle *pcmhp) 2558 struct pcmcia_mem_handle *pcmhp)
2559{ 2559{
2560#if rbus 2560#if rbus
2561 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2561 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2562 2562
2563 rbus_space_free(sc->sc_rbus_memt, pcmhp->memh, pcmhp->realsize, NULL); 2563 rbus_space_free(sc->sc_rbus_memt, pcmhp->memh, pcmhp->realsize, NULL);
2564#else 2564#else
2565 bus_space_free(pcmhp->memt, pcmhp->memh, pcmhp->realsize); 2565 bus_space_free(pcmhp->memt, pcmhp->memh, pcmhp->realsize);
2566#endif 2566#endif
2567} 2567}
2568 2568
2569/* 2569/*
2570 * STATIC void pccbb_pcmcia_do_mem_map(struct pcic_handle *ph, int win) 2570 * STATIC void pccbb_pcmcia_do_mem_map(struct pcic_handle *ph, int win)
2571 * 2571 *
2572 * This function release the memory space allocated by the function 2572 * This function release the memory space allocated by the function
2573 * pccbb_pcmcia_mem_alloc(). 2573 * pccbb_pcmcia_mem_alloc().
2574 */ 2574 */
2575STATIC void 2575STATIC void
2576pccbb_pcmcia_do_mem_map(struct pccbb_softc *sc, int win) 2576pccbb_pcmcia_do_mem_map(struct pccbb_softc *sc, int win)
2577{ 2577{
2578 int regbase_win; 2578 int regbase_win;
2579 bus_addr_t phys_addr; 2579 bus_addr_t phys_addr;
2580 bus_addr_t phys_end; 2580 bus_addr_t phys_end;
2581 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2581 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2582 2582
2583#define PCIC_SMM_START_LOW 0 2583#define PCIC_SMM_START_LOW 0
2584#define PCIC_SMM_START_HIGH 1 2584#define PCIC_SMM_START_HIGH 1
2585#define PCIC_SMM_STOP_LOW 2 2585#define PCIC_SMM_STOP_LOW 2
2586#define PCIC_SMM_STOP_HIGH 3 2586#define PCIC_SMM_STOP_HIGH 3
2587#define PCIC_CMA_LOW 4 2587#define PCIC_CMA_LOW 4
2588#define PCIC_CMA_HIGH 5 2588#define PCIC_CMA_HIGH 5
2589 2589
2590 u_int8_t start_low, start_high = 0; 2590 u_int8_t start_low, start_high = 0;
2591 u_int8_t stop_low, stop_high; 2591 u_int8_t stop_low, stop_high;
2592 u_int8_t off_low, off_high; 2592 u_int8_t off_low, off_high;
2593 u_int8_t mem_window; 2593 u_int8_t mem_window;
2594 int reg; 2594 int reg;
2595 2595
2596 int kind = ph->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK; 2596 int kind = ph->mem[win].kind & ~PCMCIA_WIDTH_MEM_MASK;
2597 int mem8 = 2597 int mem8 =
2598 (ph->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8 2598 (ph->mem[win].kind & PCMCIA_WIDTH_MEM_MASK) == PCMCIA_WIDTH_MEM8
2599 || (kind == PCMCIA_MEM_ATTR); 2599 || (kind == PCMCIA_MEM_ATTR);
2600 2600
2601 regbase_win = 0x10 + win * 0x08; 2601 regbase_win = 0x10 + win * 0x08;
2602 2602
2603 phys_addr = ph->mem[win].addr; 2603 phys_addr = ph->mem[win].addr;
2604 phys_end = phys_addr + ph->mem[win].size; 2604 phys_end = phys_addr + ph->mem[win].size;
2605 2605
2606 DPRINTF(("pccbb_pcmcia_do_mem_map: start 0x%lx end 0x%lx off 0x%lx\n", 2606 DPRINTF(("pccbb_pcmcia_do_mem_map: start 0x%lx end 0x%lx off 0x%lx\n",
2607 (unsigned long)phys_addr, (unsigned long)phys_end, 2607 (unsigned long)phys_addr, (unsigned long)phys_end,
2608 (unsigned long)ph->mem[win].offset)); 2608 (unsigned long)ph->mem[win].offset));
2609 2609
2610#define PCIC_MEMREG_LSB_SHIFT PCIC_SYSMEM_ADDRX_SHIFT 2610#define PCIC_MEMREG_LSB_SHIFT PCIC_SYSMEM_ADDRX_SHIFT
2611#define PCIC_MEMREG_MSB_SHIFT (PCIC_SYSMEM_ADDRX_SHIFT + 8) 2611#define PCIC_MEMREG_MSB_SHIFT (PCIC_SYSMEM_ADDRX_SHIFT + 8)
2612#define PCIC_MEMREG_WIN_SHIFT (PCIC_SYSMEM_ADDRX_SHIFT + 12) 2612#define PCIC_MEMREG_WIN_SHIFT (PCIC_SYSMEM_ADDRX_SHIFT + 12)
2613 2613
2614 /* bit 19:12 */ 2614 /* bit 19:12 */
2615 start_low = (phys_addr >> PCIC_MEMREG_LSB_SHIFT) & 0xff; 2615 start_low = (phys_addr >> PCIC_MEMREG_LSB_SHIFT) & 0xff;
2616 /* bit 23:20 and bit 7 on */ 2616 /* bit 23:20 and bit 7 on */
2617 start_high = ((phys_addr >> PCIC_MEMREG_MSB_SHIFT) & 0x0f) 2617 start_high = ((phys_addr >> PCIC_MEMREG_MSB_SHIFT) & 0x0f)
2618 |(mem8 ? 0 : PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT); 2618 |(mem8 ? 0 : PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT);
2619 /* bit 31:24, for 32-bit address */ 2619 /* bit 31:24, for 32-bit address */
2620 mem_window = (phys_addr >> PCIC_MEMREG_WIN_SHIFT) & 0xff; 2620 mem_window = (phys_addr >> PCIC_MEMREG_WIN_SHIFT) & 0xff;
2621 2621
2622 Pcic_write(sc, regbase_win + PCIC_SMM_START_LOW, start_low); 2622 Pcic_write(sc, regbase_win + PCIC_SMM_START_LOW, start_low);
2623 Pcic_write(sc, regbase_win + PCIC_SMM_START_HIGH, start_high); 2623 Pcic_write(sc, regbase_win + PCIC_SMM_START_HIGH, start_high);
2624 2624
2625 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) { 2625 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) {
2626 Pcic_write(sc, 0x40 + win, mem_window); 2626 Pcic_write(sc, 0x40 + win, mem_window);
2627 } 2627 }
2628 2628
2629 stop_low = (phys_end >> PCIC_MEMREG_LSB_SHIFT) & 0xff; 2629 stop_low = (phys_end >> PCIC_MEMREG_LSB_SHIFT) & 0xff;
2630 stop_high = ((phys_end >> PCIC_MEMREG_MSB_SHIFT) & 0x0f) 2630 stop_high = ((phys_end >> PCIC_MEMREG_MSB_SHIFT) & 0x0f)
2631 | PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2; /* wait 2 cycles */ 2631 | PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2; /* wait 2 cycles */
2632 /* XXX Geee, WAIT2!! Crazy!! I must rewrite this routine. */ 2632 /* XXX Geee, WAIT2!! Crazy!! I must rewrite this routine. */
2633 2633
2634 Pcic_write(sc, regbase_win + PCIC_SMM_STOP_LOW, stop_low); 2634 Pcic_write(sc, regbase_win + PCIC_SMM_STOP_LOW, stop_low);
2635 Pcic_write(sc, regbase_win + PCIC_SMM_STOP_HIGH, stop_high); 2635 Pcic_write(sc, regbase_win + PCIC_SMM_STOP_HIGH, stop_high);
2636 2636
2637 off_low = (ph->mem[win].offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff; 2637 off_low = (ph->mem[win].offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff;
2638 off_high = ((ph->mem[win].offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8)) 2638 off_high = ((ph->mem[win].offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8))
2639 & PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK) 2639 & PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK)
2640 | ((kind == PCMCIA_MEM_ATTR) ? 2640 | ((kind == PCMCIA_MEM_ATTR) ?
2641 PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0); 2641 PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0);
2642 2642
2643 Pcic_write(sc, regbase_win + PCIC_CMA_LOW, off_low); 2643 Pcic_write(sc, regbase_win + PCIC_CMA_LOW, off_low);
2644 Pcic_write(sc, regbase_win + PCIC_CMA_HIGH, off_high); 2644 Pcic_write(sc, regbase_win + PCIC_CMA_HIGH, off_high);
2645 2645
2646 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE); 2646 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE);
2647 reg |= ((1 << win) | PCIC_ADDRWIN_ENABLE_MEMCS16); 2647 reg |= ((1 << win) | PCIC_ADDRWIN_ENABLE_MEMCS16);
2648 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg); 2648 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg);
2649 2649
2650#if defined(CBB_DEBUG) 2650#if defined(CBB_DEBUG)
2651 { 2651 {
2652 int r1, r2, r3, r4, r5, r6, r7 = 0; 2652 int r1, r2, r3, r4, r5, r6, r7 = 0;
2653 2653
2654 r1 = Pcic_read(sc, regbase_win + PCIC_SMM_START_LOW); 2654 r1 = Pcic_read(sc, regbase_win + PCIC_SMM_START_LOW);
2655 r2 = Pcic_read(sc, regbase_win + PCIC_SMM_START_HIGH); 2655 r2 = Pcic_read(sc, regbase_win + PCIC_SMM_START_HIGH);
2656 r3 = Pcic_read(sc, regbase_win + PCIC_SMM_STOP_LOW); 2656 r3 = Pcic_read(sc, regbase_win + PCIC_SMM_STOP_LOW);
2657 r4 = Pcic_read(sc, regbase_win + PCIC_SMM_STOP_HIGH); 2657 r4 = Pcic_read(sc, regbase_win + PCIC_SMM_STOP_HIGH);
2658 r5 = Pcic_read(sc, regbase_win + PCIC_CMA_LOW); 2658 r5 = Pcic_read(sc, regbase_win + PCIC_CMA_LOW);
2659 r6 = Pcic_read(sc, regbase_win + PCIC_CMA_HIGH); 2659 r6 = Pcic_read(sc, regbase_win + PCIC_CMA_HIGH);
2660 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) { 2660 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) {
2661 r7 = Pcic_read(sc, 0x40 + win); 2661 r7 = Pcic_read(sc, 0x40 + win);
2662 } 2662 }
2663 2663
2664 printf("pccbb_pcmcia_do_mem_map window %d: %02x%02x %02x%02x " 2664 printf("pccbb_pcmcia_do_mem_map window %d: %02x%02x %02x%02x "
2665 "%02x%02x", win, r1, r2, r3, r4, r5, r6); 2665 "%02x%02x", win, r1, r2, r3, r4, r5, r6);
2666 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) { 2666 if (sc->sc_pcmcia_flags & PCCBB_PCMCIA_MEM_32) {
2667 printf(" %02x", r7); 2667 printf(" %02x", r7);
2668 } 2668 }
2669 printf("\n"); 2669 printf("\n");
2670 } 2670 }
2671#endif 2671#endif
2672} 2672}
2673 2673
2674/* 2674/*
2675 * STATIC int pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t pch, int kind, 2675 * STATIC int pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t pch, int kind,
2676 * bus_addr_t card_addr, bus_size_t size, 2676 * bus_addr_t card_addr, bus_size_t size,
2677 * struct pcmcia_mem_handle *pcmhp, 2677 * struct pcmcia_mem_handle *pcmhp,
2678 * bus_addr_t *offsetp, int *windowp) 2678 * bus_addr_t *offsetp, int *windowp)
2679 * 2679 *
2680 * This function maps memory space allocated by the function 2680 * This function maps memory space allocated by the function
2681 * pccbb_pcmcia_mem_alloc(). 2681 * pccbb_pcmcia_mem_alloc().
2682 */ 2682 */
2683STATIC int 2683STATIC int
2684pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t pch, int kind, 2684pccbb_pcmcia_mem_map(pcmcia_chipset_handle_t pch, int kind,
2685 bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pcmhp, 2685 bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pcmhp,
2686 bus_addr_t *offsetp, int *windowp) 2686 bus_size_t *offsetp, int *windowp)
2687{ 2687{
2688 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2688 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2689 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2689 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2690 bus_addr_t busaddr; 2690 bus_addr_t busaddr;
2691 long card_offset; 2691 long card_offset;
2692 int win; 2692 int win;
2693 2693
2694 /* Check that the card is still there. */ 2694 /* Check that the card is still there. */
2695 if ((Pcic_read(sc, PCIC_IF_STATUS) & PCIC_IF_STATUS_CARDDETECT_MASK) != 2695 if ((Pcic_read(sc, PCIC_IF_STATUS) & PCIC_IF_STATUS_CARDDETECT_MASK) !=
2696 PCIC_IF_STATUS_CARDDETECT_PRESENT) 2696 PCIC_IF_STATUS_CARDDETECT_PRESENT)
2697 return 1; 2697 return 1;
2698 2698
2699 for (win = 0; win < PCIC_MEM_WINS; ++win) { 2699 for (win = 0; win < PCIC_MEM_WINS; ++win) {
2700 if ((ph->memalloc & (1 << win)) == 0) { 2700 if ((ph->memalloc & (1 << win)) == 0) {
2701 ph->memalloc |= (1 << win); 2701 ph->memalloc |= (1 << win);
2702 break; 2702 break;
2703 } 2703 }
2704 } 2704 }
2705 2705
2706 if (win == PCIC_MEM_WINS) { 2706 if (win == PCIC_MEM_WINS) {
2707 return 1; 2707 return 1;
2708 } 2708 }
2709 2709
2710 *windowp = win; 2710 *windowp = win;
2711 2711
2712 /* XXX this is pretty gross */ 2712 /* XXX this is pretty gross */
2713 2713
2714 if (sc->sc_memt != pcmhp->memt) { 2714 if (sc->sc_memt != pcmhp->memt) {
2715 panic("pccbb_pcmcia_mem_map memt is bogus"); 2715 panic("pccbb_pcmcia_mem_map memt is bogus");
2716 } 2716 }
2717 2717
2718 busaddr = pcmhp->addr; 2718 busaddr = pcmhp->addr;
2719 2719
2720 /* 2720 /*
2721 * compute the address offset to the pcmcia address space for the 2721 * compute the address offset to the pcmcia address space for the
2722 * pcic. this is intentionally signed. The masks and shifts below 2722 * pcic. this is intentionally signed. The masks and shifts below
2723 * will cause TRT to happen in the pcic registers. Deal with making 2723 * will cause TRT to happen in the pcic registers. Deal with making
2724 * sure the address is aligned, and return the alignment offset. 2724 * sure the address is aligned, and return the alignment offset.
2725 */ 2725 */
2726 2726
2727 *offsetp = card_addr % PCIC_MEM_PAGESIZE; 2727 *offsetp = card_addr % PCIC_MEM_PAGESIZE;
2728 card_addr -= *offsetp; 2728 card_addr -= *offsetp;
2729 2729
2730 DPRINTF(("pccbb_pcmcia_mem_map window %d bus %lx+%lx+%lx at card addr " 2730 DPRINTF(("pccbb_pcmcia_mem_map window %d bus %lx+%lx+%lx at card addr "
2731 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size, 2731 "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size,
2732 (u_long) card_addr)); 2732 (u_long) card_addr));
2733 2733
2734 /* 2734 /*
2735 * include the offset in the size, and decrement size by one, since 2735 * include the offset in the size, and decrement size by one, since
2736 * the hw wants start/stop 2736 * the hw wants start/stop
2737 */ 2737 */
2738 size += *offsetp - 1; 2738 size += *offsetp - 1;
2739 2739
2740 card_offset = (((long)card_addr) - ((long)busaddr)); 2740 card_offset = (((long)card_addr) - ((long)busaddr));
2741 2741
2742 ph->mem[win].addr = busaddr; 2742 ph->mem[win].addr = busaddr;
2743 ph->mem[win].size = size; 2743 ph->mem[win].size = size;
2744 ph->mem[win].offset = card_offset; 2744 ph->mem[win].offset = card_offset;
2745 ph->mem[win].kind = kind; 2745 ph->mem[win].kind = kind;
2746 2746
2747 pccbb_pcmcia_do_mem_map(sc, win); 2747 pccbb_pcmcia_do_mem_map(sc, win);
2748 2748
2749 return 0; 2749 return 0;
2750} 2750}
2751 2751
2752/* 2752/*
2753 * STATIC int pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t pch, 2753 * STATIC int pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t pch,
2754 * int window) 2754 * int window)
2755 * 2755 *
2756 * This function unmaps memory space which mapped by the function 2756 * This function unmaps memory space which mapped by the function
2757 * pccbb_pcmcia_mem_map(). 2757 * pccbb_pcmcia_mem_map().
2758 */ 2758 */
2759STATIC void 2759STATIC void
2760pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t pch, int window) 2760pccbb_pcmcia_mem_unmap(pcmcia_chipset_handle_t pch, int window)
2761{ 2761{
2762 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2762 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2763 struct pcic_handle *ph = &sc->sc_pcmcia_h; 2763 struct pcic_handle *ph = &sc->sc_pcmcia_h;
2764 int reg; 2764 int reg;
2765 2765
2766 if (window >= PCIC_MEM_WINS) { 2766 if (window >= PCIC_MEM_WINS) {
2767 panic("pccbb_pcmcia_mem_unmap: window out of range"); 2767 panic("pccbb_pcmcia_mem_unmap: window out of range");
2768 } 2768 }
2769 2769
2770 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE); 2770 reg = Pcic_read(sc, PCIC_ADDRWIN_ENABLE);
2771 reg &= ~(1 << window); 2771 reg &= ~(1 << window);
2772 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg); 2772 Pcic_write(sc, PCIC_ADDRWIN_ENABLE, reg);
2773 2773
2774 ph->memalloc &= ~(1 << window); 2774 ph->memalloc &= ~(1 << window);
2775} 2775}
2776 2776
2777/* 2777/*
2778 * STATIC void *pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t pch, 2778 * STATIC void *pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t pch,
2779 * struct pcmcia_function *pf, 2779 * struct pcmcia_function *pf,
2780 * int ipl, 2780 * int ipl,
2781 * int (*func)(void *), 2781 * int (*func)(void *),
2782 * void *arg); 2782 * void *arg);
2783 * 2783 *
2784 * This function enables PC-Card interrupt. PCCBB uses PCI interrupt line. 2784 * This function enables PC-Card interrupt. PCCBB uses PCI interrupt line.
2785 */ 2785 */
2786STATIC void * 2786STATIC void *
2787pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t pch, 2787pccbb_pcmcia_intr_establish(pcmcia_chipset_handle_t pch,
2788 struct pcmcia_function *pf, int ipl, int (*func)(void *), void *arg) 2788 struct pcmcia_function *pf, int ipl, int (*func)(void *), void *arg)
2789{ 2789{
2790 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2790 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2791 2791
2792 if (!(pf->cfe->flags & PCMCIA_CFE_IRQLEVEL)) { 2792 if (!(pf->cfe->flags & PCMCIA_CFE_IRQLEVEL)) {
2793 /* what should I do? */ 2793 /* what should I do? */
2794 if ((pf->cfe->flags & PCMCIA_CFE_IRQLEVEL)) { 2794 if ((pf->cfe->flags & PCMCIA_CFE_IRQLEVEL)) {
2795 DPRINTF(("%s does not provide edge nor pulse " 2795 DPRINTF(("%s does not provide edge nor pulse "
2796 "interrupt\n", device_xname(sc->sc_dev))); 2796 "interrupt\n", device_xname(sc->sc_dev)));
2797 return NULL; 2797 return NULL;
2798 } 2798 }
2799 /* 2799 /*
2800 * XXX Noooooo! The interrupt flag must set properly!! 2800 * XXX Noooooo! The interrupt flag must set properly!!
2801 * dumb pcmcia driver!! 2801 * dumb pcmcia driver!!
2802 */ 2802 */
2803 } 2803 }
2804 2804
2805 return pccbb_intr_establish(sc, 0, ipl, func, arg); 2805 return pccbb_intr_establish(sc, 0, ipl, func, arg);
2806} 2806}
2807 2807
2808/* 2808/*
2809 * STATIC void pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t pch, 2809 * STATIC void pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t pch,
2810 * void *ih) 2810 * void *ih)
2811 * 2811 *
2812 * This function disables PC-Card interrupt. 2812 * This function disables PC-Card interrupt.
2813 */ 2813 */
2814STATIC void 2814STATIC void
2815pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih) 2815pccbb_pcmcia_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
2816{ 2816{
2817 struct pccbb_softc *sc = (struct pccbb_softc *)pch; 2817 struct pccbb_softc *sc = (struct pccbb_softc *)pch;
2818 2818
2819 pccbb_intr_disestablish(sc, ih); 2819 pccbb_intr_disestablish(sc, ih);
2820} 2820}
2821 2821
2822#if rbus 2822#if rbus
2823/* 2823/*
2824 * static int 2824 * static int
2825 * pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t ct, rbus_tag_t rb, 2825 * pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t ct, rbus_tag_t rb,
2826 * bus_addr_t addr, bus_size_t size, 2826 * bus_addr_t addr, bus_size_t size,
2827 * bus_addr_t mask, bus_size_t align, 2827 * bus_addr_t mask, bus_size_t align,
2828 * int flags, bus_addr_t *addrp; 2828 * int flags, bus_addr_t *addrp;
2829 * bus_space_handle_t *bshp) 2829 * bus_space_handle_t *bshp)
2830 * 2830 *
2831 * This function allocates a portion of memory or io space for 2831 * This function allocates a portion of memory or io space for
2832 * clients. This function is called from CardBus card drivers. 2832 * clients. This function is called from CardBus card drivers.
2833 */ 2833 */
2834static int 2834static int
2835pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t ct, rbus_tag_t rb, 2835pccbb_rbus_cb_space_alloc(cardbus_chipset_tag_t ct, rbus_tag_t rb,
2836 bus_addr_t addr, bus_size_t size, bus_addr_t mask, bus_size_t align, 2836 bus_addr_t addr, bus_size_t size, bus_addr_t mask, bus_size_t align,
2837 int flags, bus_addr_t *addrp, bus_space_handle_t *bshp) 2837 int flags, bus_addr_t *addrp, bus_space_handle_t *bshp)
2838{ 2838{
2839 struct pccbb_softc *sc = (struct pccbb_softc *)ct; 2839 struct pccbb_softc *sc = (struct pccbb_softc *)ct;
2840 2840
2841 DPRINTF(("pccbb_rbus_cb_space_alloc: addr 0x%lx, size 0x%lx, " 2841 DPRINTF(("pccbb_rbus_cb_space_alloc: addr 0x%lx, size 0x%lx, "
2842 "mask 0x%lx, align 0x%lx\n", (unsigned long)addr, 2842 "mask 0x%lx, align 0x%lx\n", (unsigned long)addr,
2843 (unsigned long)size, (unsigned long)mask, (unsigned long)align)); 2843 (unsigned long)size, (unsigned long)mask, (unsigned long)align));
2844 2844
2845 if (align == 0) { 2845 if (align == 0) {
2846 align = size; 2846 align = size;
2847 } 2847 }
2848 2848
2849 if (rb->rb_bt == sc->sc_memt) { 2849 if (rb->rb_bt == sc->sc_memt) {
2850 if (align < 16) { 2850 if (align < 16) {
2851 return 1; 2851 return 1;
2852 } 2852 }
2853 /* 2853 /*
2854 * XXX: align more than 0x1000 to avoid overwrapping 2854 * XXX: align more than 0x1000 to avoid overwrapping
2855 * memory windows for two or more devices. 0x1000 2855 * memory windows for two or more devices. 0x1000
2856 * means memory window's granularity. 2856 * means memory window's granularity.
2857 * 2857 *
2858 * Two or more devices should be able to share same 2858 * Two or more devices should be able to share same
2859 * memory window region. However, overrapping memory 2859 * memory window region. However, overrapping memory
2860 * window is not good because some devices, such as 2860 * window is not good because some devices, such as
2861 * 3Com 3C575[BC], have a broken address decoder and 2861 * 3Com 3C575[BC], have a broken address decoder and
2862 * intrude other's memory region. 2862 * intrude other's memory region.
2863 */ 2863 */
2864 if (align < 0x1000) { 2864 if (align < 0x1000) {
2865 align = 0x1000; 2865 align = 0x1000;
2866 } 2866 }
2867 } else if (rb->rb_bt == sc->sc_iot) { 2867 } else if (rb->rb_bt == sc->sc_iot) {
2868 if (align < 4) { 2868 if (align < 4) {
2869 return 1; 2869 return 1;
2870 } 2870 }
2871 /* XXX: hack for avoiding ISA image */ 2871 /* XXX: hack for avoiding ISA image */
2872 if (mask < 0x0100) { 2872 if (mask < 0x0100) {
2873 mask = 0x3ff; 2873 mask = 0x3ff;
2874 addr = 0x300; 2874 addr = 0x300;
2875 } 2875 }
2876 2876
2877 } else { 2877 } else {
2878 DPRINTF(("pccbb_rbus_cb_space_alloc: Bus space tag 0x%lx is " 2878 DPRINTF(("pccbb_rbus_cb_space_alloc: Bus space tag 0x%lx is "
2879 "NOT used. io: 0x%lx, mem: 0x%lx\n", 2879 "NOT used. io: 0x%lx, mem: 0x%lx\n",
2880 (unsigned long)rb->rb_bt, (unsigned long)sc->sc_iot, 2880 (unsigned long)rb->rb_bt, (unsigned long)sc->sc_iot,
2881 (unsigned long)sc->sc_memt)); 2881 (unsigned long)sc->sc_memt));
2882 return 1; 2882 return 1;
2883 /* XXX: panic here? */ 2883 /* XXX: panic here? */
2884 } 2884 }
2885 2885
2886 if (rbus_space_alloc(rb, addr, size, mask, align, flags, addrp, bshp)) { 2886 if (rbus_space_alloc(rb, addr, size, mask, align, flags, addrp, bshp)) {
2887 aprint_normal_dev(sc->sc_dev, "<rbus> no bus space\n"); 2887 aprint_normal_dev(sc->sc_dev, "<rbus> no bus space\n");
2888 return 1; 2888 return 1;
2889 } 2889 }
2890 2890
2891 pccbb_open_win(sc, rb->rb_bt, *addrp, size, *bshp, 0); 2891 pccbb_open_win(sc, rb->rb_bt, *addrp, size, *bshp, 0);
2892 2892
2893 return 0; 2893 return 0;
2894} 2894}
2895 2895
2896/* 2896/*
2897 * static int 2897 * static int
2898 * pccbb_rbus_cb_space_free(cardbus_chipset_tag_t *ct, rbus_tag_t rb, 2898 * pccbb_rbus_cb_space_free(cardbus_chipset_tag_t *ct, rbus_tag_t rb,
2899 * bus_space_handle_t *bshp, bus_size_t size); 2899 * bus_space_handle_t *bshp, bus_size_t size);
2900 * 2900 *
2901 * This function is called from CardBus card drivers. 2901 * This function is called from CardBus card drivers.
2902 */ 2902 */
2903static int 2903static int
2904pccbb_rbus_cb_space_free(cardbus_chipset_tag_t ct, rbus_tag_t rb, 2904pccbb_rbus_cb_space_free(cardbus_chipset_tag_t ct, rbus_tag_t rb,
2905 bus_space_handle_t bsh, bus_size_t size) 2905 bus_space_handle_t bsh, bus_size_t size)
2906{ 2906{
2907 struct pccbb_softc *sc = (struct pccbb_softc *)ct; 2907 struct pccbb_softc *sc = (struct pccbb_softc *)ct;
2908 bus_space_tag_t bt = rb->rb_bt; 2908 bus_space_tag_t bt = rb->rb_bt;
2909 2909
2910 pccbb_close_win(sc, bt, bsh, size); 2910 pccbb_close_win(sc, bt, bsh, size);
2911 2911
2912 if (bt == sc->sc_memt) { 2912 if (bt == sc->sc_memt) {
2913 } else if (bt == sc->sc_iot) { 2913 } else if (bt == sc->sc_iot) {
2914 } else { 2914 } else {
2915 return 1; 2915 return 1;
2916 /* XXX: panic here? */ 2916 /* XXX: panic here? */
2917 } 2917 }
2918 2918
2919 return rbus_space_free(rb, bsh, size, NULL); 2919 return rbus_space_free(rb, bsh, size, NULL);
2920} 2920}
2921#endif /* rbus */ 2921#endif /* rbus */
2922 2922
2923#if rbus 2923#if rbus
2924 2924
2925static int 2925static int
2926pccbb_open_win(struct pccbb_softc *sc, bus_space_tag_t bst, bus_addr_t addr, 2926pccbb_open_win(struct pccbb_softc *sc, bus_space_tag_t bst, bus_addr_t addr,
2927 bus_size_t size, bus_space_handle_t bsh, int flags) 2927 bus_size_t size, bus_space_handle_t bsh, int flags)
2928{ 2928{
2929 struct pccbb_win_chain_head *head; 2929 struct pccbb_win_chain_head *head;
2930 bus_addr_t align; 2930 bus_addr_t align;
2931 2931
2932 head = &sc->sc_iowindow; 2932 head = &sc->sc_iowindow;
2933 align = 0x04; 2933 align = 0x04;
2934 if (sc->sc_memt == bst) { 2934 if (sc->sc_memt == bst) {
2935 head = &sc->sc_memwindow; 2935 head = &sc->sc_memwindow;
2936 align = 0x1000; 2936 align = 0x1000;
2937 DPRINTF(("using memory window, 0x%lx 0x%lx 0x%lx\n\n", 2937 DPRINTF(("using memory window, 0x%lx 0x%lx 0x%lx\n\n",
2938 (unsigned long)sc->sc_iot, (unsigned long)sc->sc_memt, 2938 (unsigned long)sc->sc_iot, (unsigned long)sc->sc_memt,
2939 (unsigned long)bst)); 2939 (unsigned long)bst));
2940 } 2940 }
2941 2941
2942 if (pccbb_winlist_insert(head, addr, size, bsh, flags)) { 2942 if (pccbb_winlist_insert(head, addr, size, bsh, flags)) {
2943 aprint_error_dev(sc->sc_dev, 2943 aprint_error_dev(sc->sc_dev,
2944 "pccbb_open_win: %s winlist insert failed\n", 2944 "pccbb_open_win: %s winlist insert failed\n",
2945 (head == &sc->sc_memwindow) ? "mem" : "io"); 2945 (head == &sc->sc_memwindow) ? "mem" : "io");
2946 } 2946 }
2947 pccbb_winset(align, sc, bst); 2947 pccbb_winset(align, sc, bst);
2948 2948
2949 return 0; 2949 return 0;
2950} 2950}
2951 2951
2952static int 2952static int
2953pccbb_close_win(struct pccbb_softc *sc, bus_space_tag_t bst, 2953pccbb_close_win(struct pccbb_softc *sc, bus_space_tag_t bst,
2954 bus_space_handle_t bsh, bus_size_t size) 2954 bus_space_handle_t bsh, bus_size_t size)
2955{ 2955{
2956 struct pccbb_win_chain_head *head; 2956 struct pccbb_win_chain_head *head;
2957 bus_addr_t align; 2957 bus_addr_t align;
2958 2958
2959 head = &sc->sc_iowindow; 2959 head = &sc->sc_iowindow;
2960 align = 0x04; 2960 align = 0x04;
2961 if (sc->sc_memt == bst) { 2961 if (sc->sc_memt == bst) {
2962 head = &sc->sc_memwindow; 2962 head = &sc->sc_memwindow;
2963 align = 0x1000; 2963 align = 0x1000;
2964 } 2964 }
2965 2965
2966 if (pccbb_winlist_delete(head, bsh, size)) { 2966 if (pccbb_winlist_delete(head, bsh, size)) {
2967 aprint_error_dev(sc->sc_dev, 2967 aprint_error_dev(sc->sc_dev,
2968 "pccbb_close_win: %s winlist delete failed\n", 2968 "pccbb_close_win: %s winlist delete failed\n",
2969 (head == &sc->sc_memwindow) ? "mem" : "io"); 2969 (head == &sc->sc_memwindow) ? "mem" : "io");
2970 } 2970 }
2971 pccbb_winset(align, sc, bst); 2971 pccbb_winset(align, sc, bst);
2972 2972
2973 return 0; 2973 return 0;
2974} 2974}
2975 2975
2976static int 2976static int
2977pccbb_winlist_insert(struct pccbb_win_chain_head *head, bus_addr_t start, 2977pccbb_winlist_insert(struct pccbb_win_chain_head *head, bus_addr_t start,
2978 bus_size_t size, bus_space_handle_t bsh, int flags) 2978 bus_size_t size, bus_space_handle_t bsh, int flags)
2979{ 2979{
2980 struct pccbb_win_chain *chainp, *elem; 2980 struct pccbb_win_chain *chainp, *elem;
2981 2981
2982 if ((elem = malloc(sizeof(struct pccbb_win_chain), M_DEVBUF, 2982 if ((elem = malloc(sizeof(struct pccbb_win_chain), M_DEVBUF,
2983 M_NOWAIT)) == NULL) 2983 M_NOWAIT)) == NULL)
2984 return (1); /* fail */ 2984 return (1); /* fail */
2985 2985
2986 elem->wc_start = start; 2986 elem->wc_start = start;
2987 elem->wc_end = start + (size - 1); 2987 elem->wc_end = start + (size - 1);
2988 elem->wc_handle = bsh; 2988 elem->wc_handle = bsh;
2989 elem->wc_flags = flags; 2989 elem->wc_flags = flags;
2990 2990
2991 TAILQ_FOREACH(chainp, head, wc_list) { 2991 TAILQ_FOREACH(chainp, head, wc_list) {
2992 if (chainp->wc_end >= start) 2992 if (chainp->wc_end >= start)
2993 break; 2993 break;
2994 } 2994 }
2995 if (chainp != NULL) 2995 if (chainp != NULL)
2996 TAILQ_INSERT_AFTER(head, chainp, elem, wc_list); 2996 TAILQ_INSERT_AFTER(head, chainp, elem, wc_list);
2997 else 2997 else
2998 TAILQ_INSERT_TAIL(head, elem, wc_list); 2998 TAILQ_INSERT_TAIL(head, elem, wc_list);
2999 return (0); 2999 return (0);
3000} 3000}
3001 3001
3002static int 3002static int
3003pccbb_winlist_delete(struct pccbb_win_chain_head *head, bus_space_handle_t bsh, 3003pccbb_winlist_delete(struct pccbb_win_chain_head *head, bus_space_handle_t bsh,
3004 bus_size_t size) 3004 bus_size_t size)
3005{ 3005{
3006 struct pccbb_win_chain *chainp; 3006 struct pccbb_win_chain *chainp;
3007 3007
3008 TAILQ_FOREACH(chainp, head, wc_list) { 3008 TAILQ_FOREACH(chainp, head, wc_list) {
3009 if (memcmp(&chainp->wc_handle, &bsh, sizeof(bsh)) == 0) 3009 if (memcmp(&chainp->wc_handle, &bsh, sizeof(bsh)) == 0)
3010 break; 3010 break;
3011 } 3011 }
3012 if (chainp == NULL) 3012 if (chainp == NULL)
3013 return 1; /* fail: no candidate to remove */ 3013 return 1; /* fail: no candidate to remove */
3014 3014
3015 if ((chainp->wc_end - chainp->wc_start) != (size - 1)) { 3015 if ((chainp->wc_end - chainp->wc_start) != (size - 1)) {
3016 printf("pccbb_winlist_delete: window 0x%lx size " 3016 printf("pccbb_winlist_delete: window 0x%lx size "
3017 "inconsistent: 0x%lx, 0x%lx\n", 3017 "inconsistent: 0x%lx, 0x%lx\n",
3018 (unsigned long)chainp->wc_start, 3018 (unsigned long)chainp->wc_start,
3019 (unsigned long)(chainp->wc_end - chainp->wc_start), 3019 (unsigned long)(chainp->wc_end - chainp->wc_start),
3020 (unsigned long)(size - 1)); 3020 (unsigned long)(size - 1));
3021 return 1; 3021 return 1;
3022 } 3022 }
3023 3023
3024 TAILQ_REMOVE(head, chainp, wc_list); 3024 TAILQ_REMOVE(head, chainp, wc_list);
3025 free(chainp, M_DEVBUF); 3025 free(chainp, M_DEVBUF);
3026 3026
3027 return 0; 3027 return 0;
3028} 3028}
3029 3029
3030static void 3030static void
3031pccbb_winset(bus_addr_t align, struct pccbb_softc *sc, bus_space_tag_t bst) 3031pccbb_winset(bus_addr_t align, struct pccbb_softc *sc, bus_space_tag_t bst)
3032{ 3032{
3033 pci_chipset_tag_t pc; 3033 pci_chipset_tag_t pc;
3034 pcitag_t tag; 3034 pcitag_t tag;
3035 bus_addr_t mask = ~(align - 1); 3035 bus_addr_t mask = ~(align - 1);
3036 struct { 3036 struct {
3037 cardbusreg_t win_start; 3037 cardbusreg_t win_start;
3038 cardbusreg_t win_limit; 3038 cardbusreg_t win_limit;
3039 int win_flags; 3039 int win_flags;
3040 } win[2]; 3040 } win[2];
3041 struct pccbb_win_chain *chainp; 3041 struct pccbb_win_chain *chainp;
3042 int offs; 3042 int offs;
3043 3043
3044 win[0].win_start = win[1].win_start = 0xffffffff; 3044 win[0].win_start = win[1].win_start = 0xffffffff;
3045 win[0].win_limit = win[1].win_limit = 0; 3045 win[0].win_limit = win[1].win_limit = 0;
3046 win[0].win_flags = win[1].win_flags = 0; 3046 win[0].win_flags = win[1].win_flags = 0;
3047 3047
3048 chainp = TAILQ_FIRST(&sc->sc_iowindow); 3048 chainp = TAILQ_FIRST(&sc->sc_iowindow);
3049 offs = PCI_CB_IOBASE0; 3049 offs = PCI_CB_IOBASE0;
3050 if (sc->sc_memt == bst) { 3050 if (sc->sc_memt == bst) {
3051 chainp = TAILQ_FIRST(&sc->sc_memwindow); 3051 chainp = TAILQ_FIRST(&sc->sc_memwindow);
3052 offs = PCI_CB_MEMBASE0; 3052 offs = PCI_CB_MEMBASE0;
3053 } 3053 }
3054 3054
3055 if (chainp != NULL) { 3055 if (chainp != NULL) {
3056 win[0].win_start = chainp->wc_start & mask; 3056 win[0].win_start = chainp->wc_start & mask;
3057 win[0].win_limit = chainp->wc_end & mask; 3057 win[0].win_limit = chainp->wc_end & mask;
3058 win[0].win_flags = chainp->wc_flags; 3058 win[0].win_flags = chainp->wc_flags;
3059 chainp = TAILQ_NEXT(chainp, wc_list); 3059 chainp = TAILQ_NEXT(chainp, wc_list);
3060 } 3060 }
3061 3061
3062 for (; chainp != NULL; chainp = TAILQ_NEXT(chainp, wc_list)) { 3062 for (; chainp != NULL; chainp = TAILQ_NEXT(chainp, wc_list)) {
3063 if (win[1].win_start == 0xffffffff) { 3063 if (win[1].win_start == 0xffffffff) {
3064 /* window 1 is not used */ 3064 /* window 1 is not used */
3065 if ((win[0].win_flags == chainp->wc_flags) && 3065 if ((win[0].win_flags == chainp->wc_flags) &&
3066 (win[0].win_limit + align >= 3066 (win[0].win_limit + align >=
3067 (chainp->wc_start & mask))) { 3067 (chainp->wc_start & mask))) {
3068 /* concatenate */ 3068 /* concatenate */
3069 win[0].win_limit = chainp->wc_end & mask; 3069 win[0].win_limit = chainp->wc_end & mask;
3070 } else { 3070 } else {
3071 /* make new window */ 3071 /* make new window */
3072 win[1].win_start = chainp->wc_start & mask; 3072 win[1].win_start = chainp->wc_start & mask;
3073 win[1].win_limit = chainp->wc_end & mask; 3073 win[1].win_limit = chainp->wc_end & mask;
3074 win[1].win_flags = chainp->wc_flags; 3074 win[1].win_flags = chainp->wc_flags;
3075 } 3075 }
3076 continue; 3076 continue;
3077 } 3077 }
3078 3078
3079 /* Both windows are engaged. */ 3079 /* Both windows are engaged. */
3080 if (win[0].win_flags == win[1].win_flags) { 3080 if (win[0].win_flags == win[1].win_flags) {
3081 /* same flags */ 3081 /* same flags */
3082 if (win[0].win_flags == chainp->wc_flags) { 3082 if (win[0].win_flags == chainp->wc_flags) {
3083 if (win[1].win_start - (win[0].win_limit + 3083 if (win[1].win_start - (win[0].win_limit +
3084 align) < 3084 align) <
3085 (chainp->wc_start & mask) - 3085 (chainp->wc_start & mask) -
3086 ((chainp->wc_end & mask) + align)) { 3086 ((chainp->wc_end & mask) + align)) {
3087 /* 3087 /*
3088 * merge window 0 and 1, and set win1 3088 * merge window 0 and 1, and set win1
3089 * to chainp 3089 * to chainp
3090 */ 3090 */
3091 win[0].win_limit = win[1].win_limit; 3091 win[0].win_limit = win[1].win_limit;
3092 win[1].win_start = 3092 win[1].win_start =
3093 chainp->wc_start & mask; 3093 chainp->wc_start & mask;
3094 win[1].win_limit = 3094 win[1].win_limit =
3095 chainp->wc_end & mask; 3095 chainp->wc_end & mask;
3096 } else { 3096 } else {
3097 win[1].win_limit = 3097 win[1].win_limit =
3098 chainp->wc_end & mask; 3098 chainp->wc_end & mask;
3099 } 3099 }
3100 } else { 3100 } else {
3101 /* different flags */ 3101 /* different flags */
3102 3102
3103 /* concatenate win0 and win1 */ 3103 /* concatenate win0 and win1 */
3104 win[0].win_limit = win[1].win_limit; 3104 win[0].win_limit = win[1].win_limit;
3105 /* allocate win[1] to new space */ 3105 /* allocate win[1] to new space */
3106 win[1].win_start = chainp->wc_start & mask; 3106 win[1].win_start = chainp->wc_start & mask;
3107 win[1].win_limit = chainp->wc_end & mask; 3107 win[1].win_limit = chainp->wc_end & mask;
3108 win[1].win_flags = chainp->wc_flags; 3108 win[1].win_flags = chainp->wc_flags;
3109 } 3109 }
3110 } else { 3110 } else {
3111 /* the flags of win[0] and win[1] is different */ 3111 /* the flags of win[0] and win[1] is different */
3112 if (win[0].win_flags == chainp->wc_flags) { 3112 if (win[0].win_flags == chainp->wc_flags) {
3113 win[0].win_limit = chainp->wc_end & mask; 3113 win[0].win_limit = chainp->wc_end & mask;
3114 /* 3114 /*
3115 * XXX this creates overlapping windows, so 3115 * XXX this creates overlapping windows, so
3116 * what should the poor bridge do if one is 3116 * what should the poor bridge do if one is
3117 * cachable, and the other is not? 3117 * cachable, and the other is not?
3118 */ 3118 */
3119 aprint_error_dev(sc->sc_dev, 3119 aprint_error_dev(sc->sc_dev,
3120 "overlapping windows\n"); 3120 "overlapping windows\n");
3121 } else { 3121 } else {
3122 win[1].win_limit = chainp->wc_end & mask; 3122 win[1].win_limit = chainp->wc_end & mask;
3123 } 3123 }
3124 } 3124 }
3125 } 3125 }
3126 3126
3127 pc = sc->sc_pc; 3127 pc = sc->sc_pc;
3128 tag = sc->sc_tag; 3128 tag = sc->sc_tag;
3129 pci_conf_write(pc, tag, offs, win[0].win_start); 3129 pci_conf_write(pc, tag, offs, win[0].win_start);
3130 pci_conf_write(pc, tag, offs + 4, win[0].win_limit); 3130 pci_conf_write(pc, tag, offs + 4, win[0].win_limit);
3131 pci_conf_write(pc, tag, offs + 8, win[1].win_start); 3131 pci_conf_write(pc, tag, offs + 8, win[1].win_start);
3132 pci_conf_write(pc, tag, offs + 12, win[1].win_limit); 3132 pci_conf_write(pc, tag, offs + 12, win[1].win_limit);
3133 DPRINTF(("--pccbb_winset: win0 [0x%lx, 0x%lx), win1 [0x%lx, 0x%lx)\n", 3133 DPRINTF(("--pccbb_winset: win0 [0x%lx, 0x%lx), win1 [0x%lx, 0x%lx)\n",
3134 (unsigned long)pci_conf_read(pc, tag, offs), 3134 (unsigned long)pci_conf_read(pc, tag, offs),
3135 (unsigned long)pci_conf_read(pc, tag, offs + 4) + align, 3135 (unsigned long)pci_conf_read(pc, tag, offs + 4) + align,
3136 (unsigned long)pci_conf_read(pc, tag, offs + 8), 3136 (unsigned long)pci_conf_read(pc, tag, offs + 8),
3137 (unsigned long)pci_conf_read(pc, tag, offs + 12) + align)); 3137 (unsigned long)pci_conf_read(pc, tag, offs + 12) + align));
3138 3138
3139 if (bst == sc->sc_memt) { 3139 if (bst == sc->sc_memt) {
3140 pcireg_t bcr = pci_conf_read(pc, tag, PCI_BRIDGE_CONTROL_REG); 3140 pcireg_t bcr = pci_conf_read(pc, tag, PCI_BRIDGE_CONTROL_REG);
3141 3141
3142 bcr &= ~(CB_BCR_PREFETCH_MEMWIN0 | CB_BCR_PREFETCH_MEMWIN1); 3142 bcr &= ~(CB_BCR_PREFETCH_MEMWIN0 | CB_BCR_PREFETCH_MEMWIN1);
3143 if (win[0].win_flags & PCCBB_MEM_CACHABLE) 3143 if (win[0].win_flags & PCCBB_MEM_CACHABLE)
3144 bcr |= CB_BCR_PREFETCH_MEMWIN0; 3144 bcr |= CB_BCR_PREFETCH_MEMWIN0;
3145 if (win[1].win_flags & PCCBB_MEM_CACHABLE) 3145 if (win[1].win_flags & PCCBB_MEM_CACHABLE)
3146 bcr |= CB_BCR_PREFETCH_MEMWIN1; 3146 bcr |= CB_BCR_PREFETCH_MEMWIN1;
3147 pci_conf_write(pc, tag, PCI_BRIDGE_CONTROL_REG, bcr); 3147 pci_conf_write(pc, tag, PCI_BRIDGE_CONTROL_REG, bcr);
3148 } 3148 }
3149} 3149}
3150 3150
3151#endif /* rbus */ 3151#endif /* rbus */
3152 3152
3153static bool 3153static bool
3154pccbb_suspend(device_t dv PMF_FN_ARGS) 3154pccbb_suspend(device_t dv PMF_FN_ARGS)
3155{ 3155{
3156 struct pccbb_softc *sc = device_private(dv); 3156 struct pccbb_softc *sc = device_private(dv);
3157 bus_space_tag_t base_memt = sc->sc_base_memt; /* socket regs memory */ 3157 bus_space_tag_t base_memt = sc->sc_base_memt; /* socket regs memory */
3158 bus_space_handle_t base_memh = sc->sc_base_memh; 3158 bus_space_handle_t base_memh = sc->sc_base_memh;
3159 pcireg_t reg; 3159 pcireg_t reg;
3160 3160
3161 if (sc->sc_pil_intr_enable) 3161 if (sc->sc_pil_intr_enable)
3162 (void)pccbbintr_function(sc); 3162 (void)pccbbintr_function(sc);
3163 sc->sc_pil_intr_enable = 0; 3163 sc->sc_pil_intr_enable = 0;
3164 3164
3165 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_MASK); 3165 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_MASK);
3166 /* Disable interrupts. */ 3166 /* Disable interrupts. */
3167 reg &= ~(CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | CB_SOCKET_MASK_POWER); 3167 reg &= ~(CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | CB_SOCKET_MASK_POWER);
3168 bus_space_write_4(base_memt, base_memh, CB_SOCKET_MASK, reg); 3168 bus_space_write_4(base_memt, base_memh, CB_SOCKET_MASK, reg);
3169 /* XXX joerg Disable power to the socket? */ 3169 /* XXX joerg Disable power to the socket? */
3170 3170
3171 /* XXX flush PCI write */ 3171 /* XXX flush PCI write */
3172 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT); 3172 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT);
3173 3173
3174 /* reset interrupt */ 3174 /* reset interrupt */
3175 bus_space_write_4(base_memt, base_memh, CB_SOCKET_EVENT, 3175 bus_space_write_4(base_memt, base_memh, CB_SOCKET_EVENT,
3176 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT)); 3176 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT));
3177 /* XXX flush PCI write */ 3177 /* XXX flush PCI write */
3178 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT); 3178 bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT);
3179 3179
3180 if (sc->sc_ih != NULL) { 3180 if (sc->sc_ih != NULL) {
3181 pci_intr_disestablish(sc->sc_pc, sc->sc_ih); 3181 pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
3182 sc->sc_ih = NULL; 3182 sc->sc_ih = NULL;
3183 } 3183 }
3184 3184
3185 return true; 3185 return true;
3186} 3186}
3187 3187
3188static bool 3188static bool
3189pccbb_resume(device_t dv PMF_FN_ARGS) 3189pccbb_resume(device_t dv PMF_FN_ARGS)
3190{ 3190{
3191 struct pccbb_softc *sc = device_private(dv); 3191 struct pccbb_softc *sc = device_private(dv);
3192 bus_space_tag_t base_memt = sc->sc_base_memt; /* socket regs memory */ 3192 bus_space_tag_t base_memt = sc->sc_base_memt; /* socket regs memory */
3193 bus_space_handle_t base_memh = sc->sc_base_memh; 3193 bus_space_handle_t base_memh = sc->sc_base_memh;
3194 pcireg_t reg; 3194 pcireg_t reg;
3195 3195
3196 pccbb_chipinit(sc); 3196 pccbb_chipinit(sc);
3197 pccbb_intrinit(sc); 3197 pccbb_intrinit(sc);
3198 /* setup memory and io space window for CB */ 3198 /* setup memory and io space window for CB */
3199 pccbb_winset(0x1000, sc, sc->sc_memt); 3199 pccbb_winset(0x1000, sc, sc->sc_memt);
3200 pccbb_winset(0x04, sc, sc->sc_iot); 3200 pccbb_winset(0x04, sc, sc->sc_iot);
3201 3201
3202 /* CSC Interrupt: Card detect interrupt on */ 3202 /* CSC Interrupt: Card detect interrupt on */
3203 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_MASK); 3203 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_MASK);
3204 /* Card detect intr is turned on. */ 3204 /* Card detect intr is turned on. */
3205 reg |= CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | CB_SOCKET_MASK_POWER; 3205 reg |= CB_SOCKET_MASK_CSTS | CB_SOCKET_MASK_CD | CB_SOCKET_MASK_POWER;
3206 bus_space_write_4(base_memt, base_memh, CB_SOCKET_MASK, reg); 3206 bus_space_write_4(base_memt, base_memh, CB_SOCKET_MASK, reg);
3207 /* reset interrupt */ 3207 /* reset interrupt */
3208 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT); 3208 reg = bus_space_read_4(base_memt, base_memh, CB_SOCKET_EVENT);
3209 bus_space_write_4(base_memt, base_memh, CB_SOCKET_EVENT, reg); 3209 bus_space_write_4(base_memt, base_memh, CB_SOCKET_EVENT, reg);
3210 3210
3211 /* 3211 /*
3212 * check for card insertion or removal during suspend period. 3212 * check for card insertion or removal during suspend period.
3213 * XXX: the code can't cope with card swap (remove then 3213 * XXX: the code can't cope with card swap (remove then
3214 * insert). how can we detect such situation? 3214 * insert). how can we detect such situation?
3215 */ 3215 */
3216 (void)pccbbintr(sc); 3216 (void)pccbbintr(sc);
3217 3217
3218 sc->sc_pil_intr_enable = 1; 3218 sc->sc_pil_intr_enable = 1;
3219 3219
3220 return true; 3220 return true;
3221} 3221}