Sun Mar 8 09:18:34 2020 UTC ()
Pull up following revision(s) (requested by is in ticket #1724):

	sys/arch/amiga/dev/gayle_pcmcia.c: revision 1.32

The Gayle interface uses swapped (little-endian) word accesses, so we
need to use the amiga_bus_stride_1swap methods for the word accesses.

Analyzed and submitted via port-amiga@ by Martin �berg.

Tested on formerly working hardware
- by Jukka Andberg	with Dlink DE-660+		(ne)
- by Frank Wille	with D-Link DFE-670TXD		(ne)

Tested on formerly not working hardware:
- by Martin		with 3Com 3c589 Etherling III	(ep)
- by Martin and Frank	with CompactFlash cards		(wdc)


(martin)
diff -r1.29.4.2 -r1.29.4.3 src/sys/arch/amiga/dev/gayle_pcmcia.c

cvs diff -r1.29.4.2 -r1.29.4.3 src/sys/arch/amiga/dev/gayle_pcmcia.c (switch to unified diff)

--- src/sys/arch/amiga/dev/gayle_pcmcia.c 2015/02/16 12:48:32 1.29.4.2
+++ src/sys/arch/amiga/dev/gayle_pcmcia.c 2020/03/08 09:18:34 1.29.4.3
@@ -1,542 +1,542 @@ @@ -1,542 +1,542 @@
1/* $NetBSD: gayle_pcmcia.c,v 1.29.4.2 2015/02/16 12:48:32 martin Exp $ */ 1/* $NetBSD: gayle_pcmcia.c,v 1.29.4.3 2020/03/08 09:18:34 martin Exp $ */
2 2
3/* public domain */ 3/* public domain */
4 4
5#include <sys/cdefs.h> 5#include <sys/cdefs.h>
6__KERNEL_RCSID(0, "$NetBSD: gayle_pcmcia.c,v 1.29.4.2 2015/02/16 12:48:32 martin Exp $"); 6__KERNEL_RCSID(0, "$NetBSD: gayle_pcmcia.c,v 1.29.4.3 2020/03/08 09:18:34 martin Exp $");
7 7
8/* PCMCIA front-end driver for A1200's and A600's. */ 8/* PCMCIA front-end driver for A1200's and A600's. */
9 9
10#include <sys/param.h> 10#include <sys/param.h>
11#include <sys/device.h> 11#include <sys/device.h>
12#include <sys/kernel.h> 12#include <sys/kernel.h>
13#include <sys/kthread.h> 13#include <sys/kthread.h>
14#include <sys/systm.h> 14#include <sys/systm.h>
15 15
16#include <uvm/uvm.h> 16#include <uvm/uvm.h>
17 17
18#include <dev/pcmcia/pcmciareg.h> 18#include <dev/pcmcia/pcmciareg.h>
19#include <dev/pcmcia/pcmciavar.h> 19#include <dev/pcmcia/pcmciavar.h>
20 20
21#include <machine/cpu.h> 21#include <machine/cpu.h>
22#include <amiga/amiga/custom.h> 22#include <amiga/amiga/custom.h>
23#include <amiga/amiga/device.h> 23#include <amiga/amiga/device.h>
24#include <amiga/amiga/gayle.h> 24#include <amiga/amiga/gayle.h>
25#include <amiga/amiga/isr.h> 25#include <amiga/amiga/isr.h>
26 26
27 27
28/* There is one of these for each slot. And yes, there is only one slot. */ 28/* There is one of these for each slot. And yes, there is only one slot. */
29struct pccard_slot { 29struct pccard_slot {
30 struct pccard_softc *sc; /* refer to `parent' */ 30 struct pccard_softc *sc; /* refer to `parent' */
31 int (*intr_func)(void *); 31 int (*intr_func)(void *);
32 void * intr_arg; 32 void * intr_arg;
33 device_t card; 33 device_t card;
34 int flags; 34 int flags;
35#define SLOT_OCCUPIED 0x01 35#define SLOT_OCCUPIED 0x01
36#define SLOT_NEW_CARD_EVENT 0x02 36#define SLOT_NEW_CARD_EVENT 0x02
37}; 37};
38 38
39struct pccard_softc { 39struct pccard_softc {
40 struct bus_space_tag io_space; 40 struct bus_space_tag io_space;
41 struct bus_space_tag attr_space; 41 struct bus_space_tag attr_space;
42 struct bus_space_tag mem_space; 42 struct bus_space_tag mem_space;
43 struct pccard_slot devs[1]; 43 struct pccard_slot devs[1];
44 struct isr intr6; 44 struct isr intr6;
45 struct isr intr2; 45 struct isr intr2;
46}; 46};
47 47
48static int pccard_probe(device_t, cfdata_t, void *); 48static int pccard_probe(device_t, cfdata_t, void *);
49static void pccard_attach(device_t, device_t, void *); 49static void pccard_attach(device_t, device_t, void *);
50static void pccard_attach_slot(struct pccard_slot *); 50static void pccard_attach_slot(struct pccard_slot *);
51static int pccard_intr6(void *); 51static int pccard_intr6(void *);
52static int pccard_intr2(void *); 52static int pccard_intr2(void *);
53static void pccard_kthread(void *); 53static void pccard_kthread(void *);
54 54
55static int pcf_mem_alloc(pcmcia_chipset_handle_t, bus_size_t, 55static int pcf_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
56 struct pcmcia_mem_handle *); 56 struct pcmcia_mem_handle *);
57static void pcf_mem_free(pcmcia_chipset_handle_t, struct pcmcia_mem_handle *); 57static void pcf_mem_free(pcmcia_chipset_handle_t, struct pcmcia_mem_handle *);
58static int pcf_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t, 58static int pcf_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
59 struct pcmcia_mem_handle *, bus_addr_t *, int *); 59 struct pcmcia_mem_handle *, bus_addr_t *, int *);
60static void pcf_mem_unmap(pcmcia_chipset_handle_t, int); 60static void pcf_mem_unmap(pcmcia_chipset_handle_t, int);
61static int pcf_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, bus_size_t, 61static int pcf_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, bus_size_t,
62 bus_size_t, struct pcmcia_io_handle *); 62 bus_size_t, struct pcmcia_io_handle *);
63static void pcf_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *); 63static void pcf_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *);
64static int pcf_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t, 64static int pcf_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
65 struct pcmcia_io_handle *, int *); 65 struct pcmcia_io_handle *, int *);
66static void pcf_io_unmap(pcmcia_chipset_handle_t, int); 66static void pcf_io_unmap(pcmcia_chipset_handle_t, int);
67static void *pcf_intr_establish(pcmcia_chipset_handle_t, 67static void *pcf_intr_establish(pcmcia_chipset_handle_t,
68 struct pcmcia_function *, int, int (*)(void *), void *); 68 struct pcmcia_function *, int, int (*)(void *), void *);
69static void pcf_intr_disestablish(pcmcia_chipset_handle_t, void *); 69static void pcf_intr_disestablish(pcmcia_chipset_handle_t, void *);
70static void pcf_socket_enable(pcmcia_chipset_handle_t); 70static void pcf_socket_enable(pcmcia_chipset_handle_t);
71static void pcf_socket_disable(pcmcia_chipset_handle_t); 71static void pcf_socket_disable(pcmcia_chipset_handle_t);
72static void pcf_socket_settype(pcmcia_chipset_handle_t, int); 72static void pcf_socket_settype(pcmcia_chipset_handle_t, int);
73 73
74static bsr(pcmio_bsr1, u_int8_t); 74static bsr(pcmio_bsr1, u_int8_t);
75static bsw(pcmio_bsw1, u_int8_t); 75static bsw(pcmio_bsw1, u_int8_t);
76static bsrm(pcmio_bsrm1, u_int8_t); 76static bsrm(pcmio_bsrm1, u_int8_t);
77static bswm(pcmio_bswm1, u_int8_t); 77static bswm(pcmio_bswm1, u_int8_t);
78static bsrm(pcmio_bsrr1, u_int8_t); 78static bsrm(pcmio_bsrr1, u_int8_t);
79static bswm(pcmio_bswr1, u_int8_t); 79static bswm(pcmio_bswr1, u_int8_t);
80static bssr(pcmio_bssr1, u_int8_t); 80static bssr(pcmio_bssr1, u_int8_t);
81static bscr(pcmio_bscr1, u_int8_t); 81static bscr(pcmio_bscr1, u_int8_t);
82 82
83CFATTACH_DECL_NEW(pccard, sizeof(struct pccard_softc), 83CFATTACH_DECL_NEW(pccard, sizeof(struct pccard_softc),
84 pccard_probe, pccard_attach, NULL, NULL); 84 pccard_probe, pccard_attach, NULL, NULL);
85 85
86static struct pcmcia_chip_functions chip_functions = { 86static struct pcmcia_chip_functions chip_functions = {
87 pcf_mem_alloc, pcf_mem_free, 87 pcf_mem_alloc, pcf_mem_free,
88 pcf_mem_map, pcf_mem_unmap, 88 pcf_mem_map, pcf_mem_unmap,
89 pcf_io_alloc, pcf_io_free, 89 pcf_io_alloc, pcf_io_free,
90 pcf_io_map, pcf_io_unmap, 90 pcf_io_map, pcf_io_unmap,
91 pcf_intr_establish, pcf_intr_disestablish, 91 pcf_intr_establish, pcf_intr_disestablish,
92 pcf_socket_enable, pcf_socket_disable, 92 pcf_socket_enable, pcf_socket_disable,
93 pcf_socket_settype 93 pcf_socket_settype
94}; 94};
95 95
96static struct amiga_bus_space_methods pcmio_bs_methods; 96static struct amiga_bus_space_methods pcmio_bs_methods;
97 97
98static u_int8_t *reset_card_reg; 98static u_int8_t *reset_card_reg;
99 99
100static int 100static int
101pccard_probe(device_t parent, cfdata_t cf, void *aux) 101pccard_probe(device_t parent, cfdata_t cf, void *aux)
102{ 102{
103 103
104 return (is_a600() || is_a1200()) && matchname(aux, "pccard"); 104 return (is_a600() || is_a1200()) && matchname(aux, "pccard");
105} 105}
106 106
107static void 107static void
108pccard_attach(device_t parent, device_t self, void *aux) 108pccard_attach(device_t parent, device_t self, void *aux)
109{ 109{
110 struct pccard_softc *sc = device_private(self); 110 struct pccard_softc *sc = device_private(self);
111 struct pcmciabus_attach_args paa; 111 struct pcmciabus_attach_args paa;
112 vaddr_t pcmcia_base; 112 vaddr_t pcmcia_base;
113 vaddr_t i; 113 vaddr_t i;
114 114
115 printf("\n"); 115 printf("\n");
116 116
117 gayle_init(); 117 gayle_init();
118 118
119 pcmcia_base = uvm_km_alloc(kernel_map, 119 pcmcia_base = uvm_km_alloc(kernel_map,
120 GAYLE_PCMCIA_END - GAYLE_PCMCIA_START, 120 GAYLE_PCMCIA_END - GAYLE_PCMCIA_START,
121 0, UVM_KMF_VAONLY | UVM_KMF_NOWAIT); 121 0, UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
122 if (pcmcia_base == 0) { 122 if (pcmcia_base == 0) {
123 printf("attach failed (no virtual memory)\n"); 123 printf("attach failed (no virtual memory)\n");
124 return; 124 return;
125 } 125 }
126 126
127 for (i = GAYLE_PCMCIA_START; i < GAYLE_PCMCIA_END; i += PAGE_SIZE) 127 for (i = GAYLE_PCMCIA_START; i < GAYLE_PCMCIA_END; i += PAGE_SIZE)
128 pmap_enter(vm_map_pmap(kernel_map), 128 pmap_enter(vm_map_pmap(kernel_map),
129 i - GAYLE_PCMCIA_START + pcmcia_base, i, 129 i - GAYLE_PCMCIA_START + pcmcia_base, i,
130 VM_PROT_READ | VM_PROT_WRITE, true); 130 VM_PROT_READ | VM_PROT_WRITE, true);
131 pmap_update(vm_map_pmap(kernel_map)); 131 pmap_update(vm_map_pmap(kernel_map));
132 132
133 /* override the one-byte access methods for I/O space */ 133 /* override the one-byte access methods for I/O space */
134 pcmio_bs_methods = amiga_bus_stride_1; 134 pcmio_bs_methods = amiga_bus_stride_1swap;
135 pcmio_bs_methods.bsr1 = pcmio_bsr1; 135 pcmio_bs_methods.bsr1 = pcmio_bsr1;
136 pcmio_bs_methods.bsw1 = pcmio_bsw1; 136 pcmio_bs_methods.bsw1 = pcmio_bsw1;
137 pcmio_bs_methods.bsrm1 = pcmio_bsrm1; 137 pcmio_bs_methods.bsrm1 = pcmio_bsrm1;
138 pcmio_bs_methods.bswm1 = pcmio_bswm1; 138 pcmio_bs_methods.bswm1 = pcmio_bswm1;
139 pcmio_bs_methods.bsrr1 = pcmio_bsrr1; 139 pcmio_bs_methods.bsrr1 = pcmio_bsrr1;
140 pcmio_bs_methods.bswr1 = pcmio_bswr1; 140 pcmio_bs_methods.bswr1 = pcmio_bswr1;
141 pcmio_bs_methods.bssr1 = pcmio_bssr1; 141 pcmio_bs_methods.bssr1 = pcmio_bssr1;
142 pcmio_bs_methods.bscr1 = pcmio_bscr1; 142 pcmio_bs_methods.bscr1 = pcmio_bscr1;
143 143
144 reset_card_reg = (u_int8_t *) pcmcia_base + 144 reset_card_reg = (u_int8_t *) pcmcia_base +
145 (GAYLE_PCMCIA_RESET - GAYLE_PCMCIA_START); 145 (GAYLE_PCMCIA_RESET - GAYLE_PCMCIA_START);
146 146
147 sc->io_space.base = (bus_addr_t) pcmcia_base + 147 sc->io_space.base = (bus_addr_t) pcmcia_base +
148 (GAYLE_PCMCIA_IO_START - GAYLE_PCMCIA_START); 148 (GAYLE_PCMCIA_IO_START - GAYLE_PCMCIA_START);
149 sc->io_space.absm = &pcmio_bs_methods; 149 sc->io_space.absm = &pcmio_bs_methods;
150 150
151 sc->attr_space.base = (bus_addr_t) pcmcia_base + 151 sc->attr_space.base = (bus_addr_t) pcmcia_base +
152 (GAYLE_PCMCIA_ATTR_START - GAYLE_PCMCIA_START); 152 (GAYLE_PCMCIA_ATTR_START - GAYLE_PCMCIA_START);
153 sc->attr_space.absm = &amiga_bus_stride_1; 153 sc->attr_space.absm = &amiga_bus_stride_1;
154 154
155 /* XXX we should check if the 4M of common memory are actually 155 /* XXX we should check if the 4M of common memory are actually
156 * RAM or PCMCIA usable. 156 * RAM or PCMCIA usable.
157 * For now, we just do as if the 4M were RAM and make common memory 157 * For now, we just do as if the 4M were RAM and make common memory
158 * point to attribute memory, which is OK for some I/O cards. 158 * point to attribute memory, which is OK for some I/O cards.
159 */ 159 */
160 sc->mem_space.base = (bus_addr_t) pcmcia_base; 160 sc->mem_space.base = (bus_addr_t) pcmcia_base;
161 sc->mem_space.absm = &amiga_bus_stride_1; 161 sc->mem_space.absm = &amiga_bus_stride_1;
162 162
163 sc->devs[0].sc = sc; 163 sc->devs[0].sc = sc;
164 sc->devs[0].intr_func = NULL; 164 sc->devs[0].intr_func = NULL;
165 sc->devs[0].intr_arg = NULL; 165 sc->devs[0].intr_arg = NULL;
166 sc->devs[0].flags = 0; 166 sc->devs[0].flags = 0;
167 167
168 gayle_pcmcia_status_write(0); 168 gayle_pcmcia_status_write(0);
169 gayle_intr_ack(0); 169 gayle_intr_ack(0);
170 gayle_pcmcia_config_write(0); 170 gayle_pcmcia_config_write(0);
171 gayle_intr_enable_set(GAYLE_INT_IDE); 171 gayle_intr_enable_set(GAYLE_INT_IDE);
172 172
173 paa.paa_busname = "pcmcia"; 173 paa.paa_busname = "pcmcia";
174 paa.pct = &chip_functions; 174 paa.pct = &chip_functions;
175 paa.pch = &sc->devs[0]; 175 paa.pch = &sc->devs[0];
176 sc->devs[0].card = config_found(self, &paa, simple_devprint); 176 sc->devs[0].card = config_found(self, &paa, simple_devprint);
177 if (sc->devs[0].card == NULL) { 177 if (sc->devs[0].card == NULL) {
178 printf("attach failed, config_found() returned NULL\n"); 178 printf("attach failed, config_found() returned NULL\n");
179 pmap_remove(kernel_map->pmap, pcmcia_base, 179 pmap_remove(kernel_map->pmap, pcmcia_base,
180 pcmcia_base + (GAYLE_PCMCIA_END - GAYLE_PCMCIA_START)); 180 pcmcia_base + (GAYLE_PCMCIA_END - GAYLE_PCMCIA_START));
181 pmap_update(kernel_map->pmap); 181 pmap_update(kernel_map->pmap);
182 uvm_deallocate(kernel_map, pcmcia_base, 182 uvm_deallocate(kernel_map, pcmcia_base,
183 GAYLE_PCMCIA_END - GAYLE_PCMCIA_START); 183 GAYLE_PCMCIA_END - GAYLE_PCMCIA_START);
184 return; 184 return;
185 } 185 }
186 186
187 sc->intr6.isr_intr = pccard_intr6; 187 sc->intr6.isr_intr = pccard_intr6;
188 sc->intr6.isr_arg = sc; 188 sc->intr6.isr_arg = sc;
189 sc->intr6.isr_ipl = 6; 189 sc->intr6.isr_ipl = 6;
190 add_isr(&sc->intr6); 190 add_isr(&sc->intr6);
191 191
192 sc->intr2.isr_intr = pccard_intr2; 192 sc->intr2.isr_intr = pccard_intr2;
193 sc->intr2.isr_arg = sc; 193 sc->intr2.isr_arg = sc;
194 sc->intr2.isr_ipl = 2; 194 sc->intr2.isr_ipl = 2;
195 add_isr(&sc->intr2); 195 add_isr(&sc->intr2);
196 196
197 if (kthread_create(PRI_NONE, 0, NULL, pccard_kthread, sc, 197 if (kthread_create(PRI_NONE, 0, NULL, pccard_kthread, sc,
198 NULL, "pccard")) { 198 NULL, "pccard")) {
199 printf("%s: can't create kernel thread\n", 199 printf("%s: can't create kernel thread\n",
200 device_xname(self)); 200 device_xname(self));
201 panic("pccard kthread_create() failed"); 201 panic("pccard kthread_create() failed");
202 } 202 }
203 203
204 gayle_intr_enable_set(GAYLE_INT_DETECT | GAYLE_INT_IREQ); 204 gayle_intr_enable_set(GAYLE_INT_DETECT | GAYLE_INT_IREQ);
205 205
206 /* reset the card if it's already there */ 206 /* reset the card if it's already there */
207 if (gayle_pcmcia_status_read() & GAYLE_CCMEM_DETECT) { 207 if (gayle_pcmcia_status_read() & GAYLE_CCMEM_DETECT) {
208 volatile u_int8_t x; 208 volatile u_int8_t x;
209 209
210 gayle_intr_ack(0xff); 210 gayle_intr_ack(0xff);
211 delay(500); 211 delay(500);
212 gayle_intr_ack(0xfc); 212 gayle_intr_ack(0xfc);
213 213
214 delay(100*1000); 214 delay(100*1000);
215 215
216 *reset_card_reg = 0x0; 216 *reset_card_reg = 0x0;
217 delay(1000); 217 delay(1000);
218 x = *reset_card_reg; 218 x = *reset_card_reg;
219 __USE(x); 219 __USE(x);
220 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR); 220 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR);
221 } 221 }
222 222
223 pccard_attach_slot(&sc->devs[0]); 223 pccard_attach_slot(&sc->devs[0]);
224} 224}
225 225
226static int 226static int
227pccard_intr6(void *arg) 227pccard_intr6(void *arg)
228{ 228{
229 struct pccard_softc *sc = arg; 229 struct pccard_softc *sc = arg;
230 230
231 if (gayle_intr_status() & GAYLE_INT_DETECT) { 231 if (gayle_intr_status() & GAYLE_INT_DETECT) {
232 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_STSCHG | 232 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_STSCHG |
233 GAYLE_INT_SPKR | GAYLE_INT_WP | GAYLE_INT_IREQ); 233 GAYLE_INT_SPKR | GAYLE_INT_WP | GAYLE_INT_IREQ);
234 sc->devs[0].flags |= SLOT_NEW_CARD_EVENT; 234 sc->devs[0].flags |= SLOT_NEW_CARD_EVENT;
235 return 1; 235 return 1;
236 } 236 }
237 return 0; 237 return 0;
238} 238}
239 239
240static int 240static int
241pccard_intr2(void *arg) 241pccard_intr2(void *arg)
242{ 242{
243 struct pccard_softc *sc = arg; 243 struct pccard_softc *sc = arg;
244 struct pccard_slot *slot = &sc->devs[0]; 244 struct pccard_slot *slot = &sc->devs[0];
245 245
246 if (slot->flags & SLOT_NEW_CARD_EVENT) { 246 if (slot->flags & SLOT_NEW_CARD_EVENT) {
247 slot->flags &= ~SLOT_NEW_CARD_EVENT; 247 slot->flags &= ~SLOT_NEW_CARD_EVENT;
248 248
249 /* reset the registers */ 249 /* reset the registers */
250 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_DETECT); 250 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_DETECT);
251 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR); 251 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR);
252 gayle_pcmcia_config_write(0); 252 gayle_pcmcia_config_write(0);
253 pccard_attach_slot(&sc->devs[0]); 253 pccard_attach_slot(&sc->devs[0]);
254 } else { 254 } else {
255 int intreq = gayle_intr_status() & 255 int intreq = gayle_intr_status() &
256 (GAYLE_INT_STSCHG | GAYLE_INT_WP | GAYLE_INT_IREQ); 256 (GAYLE_INT_STSCHG | GAYLE_INT_WP | GAYLE_INT_IREQ);
257 if (intreq) { 257 if (intreq) {
258 gayle_intr_ack((intreq ^ 0x2c) | 0xc0); 258 gayle_intr_ack((intreq ^ 0x2c) | 0xc0);
259 259
260 return slot->flags & SLOT_OCCUPIED && 260 return slot->flags & SLOT_OCCUPIED &&
261 slot->intr_func != NULL && 261 slot->intr_func != NULL &&
262 slot->intr_func(slot->intr_arg); 262 slot->intr_func(slot->intr_arg);
263 } 263 }
264 } 264 }
265 return 0; 265 return 0;
266} 266}
267 267
268static void 268static void
269pccard_kthread(void *arg) 269pccard_kthread(void *arg)
270{ 270{
271 struct pccard_softc *sc = arg; 271 struct pccard_softc *sc = arg;
272 struct pccard_slot *slot = &sc->devs[0]; 272 struct pccard_slot *slot = &sc->devs[0];
273 273
274 for (;;) { 274 for (;;) {
275 int s = spl2(); 275 int s = spl2();
276 276
277 if (slot->flags & SLOT_NEW_CARD_EVENT) { 277 if (slot->flags & SLOT_NEW_CARD_EVENT) {
278 slot->flags &= ~SLOT_NEW_CARD_EVENT; 278 slot->flags &= ~SLOT_NEW_CARD_EVENT;
279 gayle_intr_ack(0xc0); 279 gayle_intr_ack(0xc0);
280 280
281 /* reset the registers */ 281 /* reset the registers */
282 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_DETECT); 282 gayle_intr_ack(GAYLE_INT_IDE | GAYLE_INT_DETECT);
283 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR); 283 gayle_pcmcia_status_write(GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR);
284 gayle_pcmcia_config_write(0); 284 gayle_pcmcia_config_write(0);
285 pccard_attach_slot(&sc->devs[0]); 285 pccard_attach_slot(&sc->devs[0]);
286 } 286 }
287 splx(s); 287 splx(s);
288 288
289 tsleep(slot, PWAIT, "pccthread", hz); 289 tsleep(slot, PWAIT, "pccthread", hz);
290 } 290 }
291} 291}
292 292
293static void 293static void
294pccard_attach_slot(struct pccard_slot *slot) 294pccard_attach_slot(struct pccard_slot *slot)
295{ 295{
296 296
297 if (!(slot->flags & SLOT_OCCUPIED) && 297 if (!(slot->flags & SLOT_OCCUPIED) &&
298 gayle_pcmcia_status_read() & GAYLE_CCMEM_DETECT) { 298 gayle_pcmcia_status_read() & GAYLE_CCMEM_DETECT) {
299 if (pcmcia_card_attach(slot->card) == 0) 299 if (pcmcia_card_attach(slot->card) == 0)
300 slot->flags |= SLOT_OCCUPIED; 300 slot->flags |= SLOT_OCCUPIED;
301 } 301 }
302} 302}
303 303
304static int 304static int
305pcf_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t bsz, 305pcf_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t bsz,
306 struct pcmcia_mem_handle *pcmh) 306 struct pcmcia_mem_handle *pcmh)
307{ 307{
308 struct pccard_slot *slot = (struct pccard_slot *) pch; 308 struct pccard_slot *slot = (struct pccard_slot *) pch;
309 309
310 pcmh->memt = &slot->sc->attr_space; 310 pcmh->memt = &slot->sc->attr_space;
311 pcmh->memh = pcmh->memt->base; 311 pcmh->memh = pcmh->memt->base;
312 return 0; 312 return 0;
313} 313}
314 314
315static void 315static void
316pcf_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *memh) 316pcf_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *memh)
317{ 317{
318} 318}
319 319
320static int 320static int
321pcf_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t addr, 321pcf_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t addr,
322 bus_size_t size, struct pcmcia_mem_handle *pcmh, 322 bus_size_t size, struct pcmcia_mem_handle *pcmh,
323 bus_addr_t *offsetp, int *windowp) 323 bus_addr_t *offsetp, int *windowp)
324{ 324{
325 struct pccard_slot *slot = (struct pccard_slot *) pch; 325 struct pccard_slot *slot = (struct pccard_slot *) pch;
326 326
327 /* Ignore width requirements */ 327 /* Ignore width requirements */
328 kind &= ~PCMCIA_WIDTH_MEM_MASK; 328 kind &= ~PCMCIA_WIDTH_MEM_MASK;
329 329
330 switch (kind) { 330 switch (kind) {
331 case PCMCIA_MEM_ATTR: 331 case PCMCIA_MEM_ATTR:
332 pcmh->memt = &slot->sc->attr_space; 332 pcmh->memt = &slot->sc->attr_space;
333 break; 333 break;
334 case PCMCIA_MEM_COMMON: 334 case PCMCIA_MEM_COMMON:
335 pcmh->memt = &slot->sc->mem_space; 335 pcmh->memt = &slot->sc->mem_space;
336 break; 336 break;
337 default: 337 default:
338 /* This means that this code needs an update/a bugfix */ 338 /* This means that this code needs an update/a bugfix */
339 printf(__FILE__ ": unknown kind %d of PCMCIA memory\n", kind); 339 printf(__FILE__ ": unknown kind %d of PCMCIA memory\n", kind);
340 return 1; 340 return 1;
341 } 341 }
342 342
343 bus_space_map(pcmh->memt, addr, size, 0, &pcmh->memh); 343 bus_space_map(pcmh->memt, addr, size, 0, &pcmh->memh);
344 *offsetp = 0; 344 *offsetp = 0;
345 *windowp = 0; /* unused */ 345 *windowp = 0; /* unused */
346 346
347 return 0; 347 return 0;
348} 348}
349 349
350static void 350static void
351pcf_mem_unmap(pcmcia_chipset_handle_t pch, int win) 351pcf_mem_unmap(pcmcia_chipset_handle_t pch, int win)
352{ 352{
353} 353}
354 354
355static int 355static int
356pcf_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size, 356pcf_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size,
357 bus_size_t align, struct pcmcia_io_handle *pcihp) 357 bus_size_t align, struct pcmcia_io_handle *pcihp)
358{ 358{
359 struct pccard_slot *slot = (struct pccard_slot *) pch; 359 struct pccard_slot *slot = (struct pccard_slot *) pch;
360 360
361 pcihp->iot = &slot->sc->io_space; 361 pcihp->iot = &slot->sc->io_space;
362 pcihp->ioh = pcihp->iot->base; 362 pcihp->ioh = pcihp->iot->base;
363 return 0; 363 return 0;
364} 364}
365 365
366static void 366static void
367pcf_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp) 367pcf_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp)
368{ 368{
369} 369}
370 370
371static int 371static int
372pcf_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset, 372pcf_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
373 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp) 373 bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
374{ 374{
375 struct pccard_slot *slot = (struct pccard_slot *) pch; 375 struct pccard_slot *slot = (struct pccard_slot *) pch;
376 376
377 pcihp->iot = &slot->sc->io_space; 377 pcihp->iot = &slot->sc->io_space;
378 bus_space_map(pcihp->iot, offset, size, 0, &pcihp->ioh); 378 bus_space_map(pcihp->iot, offset, size, 0, &pcihp->ioh);
379 379
380 *windowp = 0; /* unused */ 380 *windowp = 0; /* unused */
381 return 0; 381 return 0;
382} 382}
383 383
384static void 384static void
385pcf_io_unmap(pcmcia_chipset_handle_t pch, int win) 385pcf_io_unmap(pcmcia_chipset_handle_t pch, int win)
386{ 386{
387} 387}
388 388
389static void * 389static void *
390pcf_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf, 390pcf_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf,
391 int ipl, int (*func)(void *), void *arg) 391 int ipl, int (*func)(void *), void *arg)
392{ 392{
393 struct pccard_slot *slot = (struct pccard_slot *) pch; 393 struct pccard_slot *slot = (struct pccard_slot *) pch;
394 int s; 394 int s;
395 395
396 s = splhigh(); 396 s = splhigh();
397 if (slot->intr_func == NULL) { 397 if (slot->intr_func == NULL) {
398 slot->intr_func = func; 398 slot->intr_func = func;
399 slot->intr_arg = arg; 399 slot->intr_arg = arg;
400 } else { 400 } else {
401 /* if we are here, we need to put intrs into a list */ 401 /* if we are here, we need to put intrs into a list */
402 printf("ARGH! see " __FILE__ "\n"); 402 printf("ARGH! see " __FILE__ "\n");
403 slot = NULL; 403 slot = NULL;
404 } 404 }
405 splx(s); 405 splx(s);
406 406
407 return slot; 407 return slot;
408} 408}
409 409
410static void 410static void
411pcf_intr_disestablish(pcmcia_chipset_handle_t pch, void *intr_handler) 411pcf_intr_disestablish(pcmcia_chipset_handle_t pch, void *intr_handler)
412{ 412{
413 struct pccard_slot *slot = (struct pccard_slot *) intr_handler; 413 struct pccard_slot *slot = (struct pccard_slot *) intr_handler;
414 414
415 if (slot != NULL) { 415 if (slot != NULL) {
416 slot->intr_func = NULL; 416 slot->intr_func = NULL;
417 slot->intr_arg = NULL; 417 slot->intr_arg = NULL;
418 } 418 }
419} 419}
420 420
421static void 421static void
422pcf_socket_enable(pcmcia_chipset_handle_t pch) 422pcf_socket_enable(pcmcia_chipset_handle_t pch)
423{ 423{
424} 424}
425 425
426static void 426static void
427pcf_socket_disable(pcmcia_chipset_handle_t pch) 427pcf_socket_disable(pcmcia_chipset_handle_t pch)
428{ 428{
429} 429}
430 430
431static void 431static void
432pcf_socket_settype(pcmcia_chipset_handle_t pch, int type) { 432pcf_socket_settype(pcmcia_chipset_handle_t pch, int type) {
433} 433}
434 434
435static u_int8_t 435static u_int8_t
436pcmio_bsr1(bus_space_handle_t h, bus_size_t o) 436pcmio_bsr1(bus_space_handle_t h, bus_size_t o)
437{ 437{
438 438
439 return *((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0)); 439 return *((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0));
440} 440}
441 441
442static void 442static void
443pcmio_bsw1(bus_space_handle_t h, bus_size_t o, unsigned v) 443pcmio_bsw1(bus_space_handle_t h, bus_size_t o, unsigned v)
444{ 444{
445 445
446 *((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0)) = v; 446 *((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0)) = v;
447} 447}
448 448
449static void 449static void
450pcmio_bsrm1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c) 450pcmio_bsrm1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c)
451{ 451{
452 volatile u_int8_t *src = (volatile u_int8_t *) 452 volatile u_int8_t *src = (volatile u_int8_t *)
453 (h + o + (o & 1 ? 0xffff : 0)); 453 (h + o + (o & 1 ? 0xffff : 0));
454 454
455 455
456 /* XXX we can (should, must) optimize this if c >= 4 */ 456 /* XXX we can (should, must) optimize this if c >= 4 */
457 for (; c > 0; c--) 457 for (; c > 0; c--)
458 *p++ = *src; 458 *p++ = *src;
459} 459}
460 460
461 461
462static void 462static void
463pcmio_bswm1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c) 463pcmio_bswm1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c)
464{ 464{
465 volatile u_int8_t *dst = (volatile u_int8_t *) 465 volatile u_int8_t *dst = (volatile u_int8_t *)
466 (h + o + (o & 1 ? 0xffff : 0)); 466 (h + o + (o & 1 ? 0xffff : 0));
467 467
468 468
469 /* XXX we can (should, must) optimize this if c >= 4 */ 469 /* XXX we can (should, must) optimize this if c >= 4 */
470 for (; c > 0; c--) 470 for (; c > 0; c--)
471 *dst = *p++; 471 *dst = *p++;
472} 472}
473 473
474static void 474static void
475pcmio_bsrr1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c) 475pcmio_bsrr1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c)
476{ 476{
477 volatile u_int8_t *cp1; 477 volatile u_int8_t *cp1;
478 volatile u_int8_t *cp2; 478 volatile u_int8_t *cp2;
479 volatile u_int8_t *temp; 479 volatile u_int8_t *temp;
480 480
481 if (o & 1) { 481 if (o & 1) {
482 cp1 = (volatile u_int8_t *) h + o + 0x10000; 482 cp1 = (volatile u_int8_t *) h + o + 0x10000;
483 cp2 = (volatile u_int8_t *) h + o; 483 cp2 = (volatile u_int8_t *) h + o;
484 } else { 484 } else {
485 cp1 = (volatile u_int8_t *) h + o; 485 cp1 = (volatile u_int8_t *) h + o;
486 cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2; 486 cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2;
487 } 487 }
488 488
489 /* XXX we can (should, must) optimize this if c >= 4 */ 489 /* XXX we can (should, must) optimize this if c >= 4 */
490 for (; c > 0; c--) { 490 for (; c > 0; c--) {
491 *p++ = *cp1; 491 *p++ = *cp1;
492 cp1 += 2; 492 cp1 += 2;
493 493
494 /* swap pointers - hope gcc generates exg for this ;) */ 494 /* swap pointers - hope gcc generates exg for this ;) */
495 temp = cp1; 495 temp = cp1;
496 cp1 = cp2; 496 cp1 = cp2;
497 cp2 = temp; 497 cp2 = temp;
498 } 498 }
499} 499}
500 500
501 501
502static void 502static void
503pcmio_bswr1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c) 503pcmio_bswr1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c)
504{ 504{
505 volatile u_int8_t *cp1; 505 volatile u_int8_t *cp1;
506 volatile u_int8_t *cp2; 506 volatile u_int8_t *cp2;
507 volatile u_int8_t *temp; 507 volatile u_int8_t *temp;
508 508
509 if (o & 1) { 509 if (o & 1) {
510 cp1 = (volatile u_int8_t *) h + o + 0x10000; 510 cp1 = (volatile u_int8_t *) h + o + 0x10000;
511 cp2 = (volatile u_int8_t *) h + o; 511 cp2 = (volatile u_int8_t *) h + o;
512 } else { 512 } else {
513 cp1 = (volatile u_int8_t *) h + o; 513 cp1 = (volatile u_int8_t *) h + o;
514 cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2; 514 cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2;
515 } 515 }
516 516
517 /* XXX we can (should, must) optimize this if c >= 4 */ 517 /* XXX we can (should, must) optimize this if c >= 4 */
518 for (; c > 0; c--) { 518 for (; c > 0; c--) {
519 *cp1 = *p++; 519 *cp1 = *p++;
520 cp1 += 2; 520 cp1 += 2;
521 521
522 /* swap pointers - hope gcc generates exg for this ;) */ 522 /* swap pointers - hope gcc generates exg for this ;) */
523 temp = cp1; 523 temp = cp1;
524 cp1 = cp2; 524 cp1 = cp2;
525 cp2 = temp; 525 cp2 = temp;
526 } 526 }
527} 527}
528 528
529void 529void
530pcmio_bssr1(bus_space_handle_t h, bus_size_t o, unsigned v, bus_size_t c) 530pcmio_bssr1(bus_space_handle_t h, bus_size_t o, unsigned v, bus_size_t c)
531{ 531{
532 532
533 panic("pcmio_bssr1 is not defined (" __FILE__ ")"); 533 panic("pcmio_bssr1 is not defined (" __FILE__ ")");
534} 534}
535 535
536void 536void
537pcmio_bscr1(bus_space_handle_t h, bus_size_t o, bus_space_handle_t g, 537pcmio_bscr1(bus_space_handle_t h, bus_size_t o, bus_space_handle_t g,
538 bus_size_t q, bus_size_t c) 538 bus_size_t q, bus_size_t c)
539{ 539{
540 540
541 panic("pcmio_bscr1 is not defined (" __FILE__ ")"); 541 panic("pcmio_bscr1 is not defined (" __FILE__ ")");
542} 542}