Deleted Added
sdiff udiff text old ( 55325 ) new ( 55500 )
full compact
1/* $NetBSD: pcmcia.c,v 1.13 1998/12/24 04:51:59 marc Exp $ */
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 55325 2000-01-03 06:45:16Z imp $ */
3
4/*
5 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright

--- 31 unchanged lines hidden (view full) ---

42#include <machine/bus.h>
43#include <sys/rman.h>
44#include <machine/resource.h>
45
46#include <dev/pccard/pccardreg.h>
47#include <dev/pccard/pccardchip.h>
48#include <dev/pccard/pccardvar.h>
49
50#ifdef PCCARDDEBUG
51int pccard_debug = 0;
52#define DPRINTF(arg) if (pccard_debug) printf arg
53int pccardintr_debug = 0;
54/* this is done this way to avoid doing lots of conditionals
55 at interrupt level. */
56#define PCCARD_CARD_INTR (pccardintr_debug?pccard_card_intrdebug:pccard_card_intr)
57#else
58#define DPRINTF(arg)
59#define PCCARD_CARD_INTR (pccard_card_intr)
60#endif
61
62#ifdef PCCARDVERBOSE
63int pccard_verbose = 1;
64#else
65int pccard_verbose = 0;
66#endif
67
68int pccard_print(void *, const char *);
69
70static __inline void pccard_socket_enable(pccard_chipset_tag_t,
71 pccard_chipset_handle_t *);
72static __inline void pccard_socket_disable(pccard_chipset_tag_t,
73 pccard_chipset_handle_t *);
74
75int pccard_card_intr(void *);
76#ifdef PCCARDDEBUG
77int pccard_card_intrdebug(void *);
78#endif
79
80/* XXX Shouldn't be touching hardware, that's a layering violation */
81/* XXX imp */
82int

--- 19 unchanged lines hidden (view full) ---

102}
103
104int
105pccard_card_attach(device_t dev)
106{
107 struct pccard_softc *sc = (struct pccard_softc *)
108 device_get_softc(dev);
109 struct pccard_function *pf;
110 struct pccard_attach_args paa;
111 int attached;
112
113 /*
114 * this is here so that when socket_enable calls gettype, trt happens
115 */
116 STAILQ_INIT(&sc->card.pf_head);
117
118 pccard_chip_socket_enable(sc->pct, sc->pch);
119
120 pccard_read_cis(sc);
121
122 pccard_chip_socket_disable(sc->pct, sc->pch);
123
124 pccard_check_cis_quirks(dev);
125
126 /*
127 * bail now if the card has no functions, or if there was an error in
128 * the cis.
129 */
130
131 if (sc->card.error)
132 return (1);
133 if (STAILQ_EMPTY(&sc->card.pf_head))
134 return (1);
135
136 if (pccard_verbose)
137 pccard_print_cis(dev);
138
139 attached = 0;
140
141 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
142 if (STAILQ_EMPTY(&pf->cfe_head))
143 continue;
144
145#ifdef DIAGNOSTIC
146 if (pf->child != NULL) {
147 printf("%s: %s still attached to function %d!\n",
148 sc->dev.dv_xname, pf->child->dv_xname,
149 pf->number);
150 panic("pccard_card_attach");
151 }
152#endif
153 pf->sc = sc;
154 pf->child = NULL;
155 pf->cfe = NULL;
156 pf->ih_fct = NULL;
157 pf->ih_arg = NULL;
158 }
159
160 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
161 if (STAILQ_EMPTY(&pf->cfe_head))
162 continue;
163
164 paa.manufacturer = sc->card.manufacturer;
165 paa.product = sc->card.product;
166 paa.card = &sc->card;
167 paa.pf = pf;
168
169#if XXX
170 if (attach_child()) {
171 attached++;
172
173 DPRINTF(("%s: function %d CCR at %d "
174 "offset %lx: %x %x %x %x, %x %x %x %x, %x\n",
175 sc->dev.dv_xname, pf->number,
176 pf->pf_ccr_window, pf->pf_ccr_offset,
177 pccard_ccr_read(pf, 0x00),
178 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04),
179 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A),
180 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E),
181 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12)));
182 }
183#endif
184 }

--- 15 unchanged lines hidden (view full) ---

200 * We are running on either the PCCARD socket's event thread
201 * or in user context detaching a device by user request.
202 */
203 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
204 if (STAILQ_FIRST(&pf->cfe_head) == NULL)
205 continue;
206 if (pf->child == NULL)
207 continue;
208 DPRINTF(("%s: detaching %s (function %d)\n",
209 sc->dev.dv_xname, pf->child->dv_xname, pf->number));
210#if XXX
211 if ((error = config_detach(pf->child, flags)) != 0) {
212 printf("%s: error %d detaching %s (function %d)\n",
213 sc->dev.dv_xname, error, pf->child->dv_xname,
214 pf->number);
215 } else
216 pf->child = NULL;
217#endif
218 }
219}
220
221void
222pccard_card_deactivate(device_t dev)

--- 7 unchanged lines hidden (view full) ---

230 * Deactivate the child driver. The PCCARD socket's
231 * event thread will run later to finish the detach.
232 */
233 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
234 if (STAILQ_FIRST(&pf->cfe_head) == NULL)
235 continue;
236 if (pf->child == NULL)
237 continue;
238 DPRINTF(("%s: deactivating %s (function %d)\n",
239 sc->dev.dv_xname, pf->child->dv_xname, pf->number));
240#if XXX
241 config_deactivate(pf->child);
242#endif
243 }
244}
245
246int
247pccard_card_gettype(device_t dev)

--- 27 unchanged lines hidden (view full) ---

275{
276 if (pf->pf_flags & PFF_ENABLED)
277 panic("pccard_function_init: function is enabled");
278
279 /* Remember which configuration entry we are using. */
280 pf->cfe = cfe;
281}
282
283static __inline void pccard_socket_enable(pct, pch)
284 pccard_chipset_tag_t pct;
285 pccard_chipset_handle_t *pch;
286{
287 pccard_chip_socket_enable(pct, pch);
288}
289
290static __inline void pccard_socket_disable(pct, pch)
291 pccard_chipset_tag_t pct;
292 pccard_chipset_handle_t *pch;
293{
294 pccard_chip_socket_disable(pct, pch);
295}
296
297/* Enable a PCCARD function */
298int
299pccard_function_enable(pf)
300 struct pccard_function *pf;
301{
302 struct pccard_function *tmp;
303 int reg;
304
305 if (pf->cfe == NULL)
306 panic("pccard_function_enable: function not initialized");
307
308 /*
309 * Increase the reference count on the socket, enabling power, if
310 * necessary.
311 */
312 if (pf->sc->sc_enabled_count++ == 0)
313 pccard_chip_socket_enable(pf->sc->pct, pf->sc->pch);
314 DPRINTF(("%s: ++enabled_count = %d\n", pf->sc->dev.dv_xname,
315 pf->sc->sc_enabled_count));
316
317 if (pf->pf_flags & PFF_ENABLED) {
318 /*
319 * Don't do anything if we're already enabled.
320 */
321 return (0);
322 }
323

--- 74 unchanged lines hidden (view full) ---

398 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0);
399
400 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize);
401 }
402
403#ifdef PCCARDDEBUG
404 if (pccard_debug) {
405 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
406 printf("%s: function %d CCR at %d offset %lx: "
407 "%x %x %x %x, %x %x %x %x, %x\n",
408 tmp->sc->dev.dv_xname, tmp->number,
409 tmp->pf_ccr_window, tmp->pf_ccr_offset,
410 pccard_ccr_read(tmp, 0x00),
411 pccard_ccr_read(tmp, 0x02),
412 pccard_ccr_read(tmp, 0x04),
413 pccard_ccr_read(tmp, 0x06),
414
415 pccard_ccr_read(tmp, 0x0A),
416 pccard_ccr_read(tmp, 0x0C),
417 pccard_ccr_read(tmp, 0x0E),
418 pccard_ccr_read(tmp, 0x10),
419
420 pccard_ccr_read(tmp, 0x12));
421 }
422 }
423#endif
424
425 pf->pf_flags |= PFF_ENABLED;
426 return (0);
427
428 bad:
429 /*
430 * Decrement the reference count, and power down the socket, if
431 * necessary.
432 */
433 if (--pf->sc->sc_enabled_count == 0)
434 pccard_chip_socket_disable(pf->sc->pct, pf->sc->pch);
435 DPRINTF(("%s: --enabled_count = %d\n", pf->sc->dev.dv_xname,
436 pf->sc->sc_enabled_count));
437
438 return (1);
439}
440
441/* Disable PCCARD function. */
442void
443pccard_function_disable(pf)

--- 32 unchanged lines hidden (view full) ---

476 pccard_mem_free(pf, &pf->pf_pcmh);
477 }
478
479 /*
480 * Decrement the reference count, and power down the socket, if
481 * necessary.
482 */
483 if (--pf->sc->sc_enabled_count == 0)
484 pccard_chip_socket_disable(pf->sc->pct, pf->sc->pch);
485 DPRINTF(("%s: --enabled_count = %d\n", pf->sc->dev.dv_xname,
486 pf->sc->sc_enabled_count));
487}
488
489int
490pccard_io_map(pf, width, offset, size, pcihp, windowp)
491 struct pccard_function *pf;
492 int width;
493 bus_addr_t offset;
494 bus_size_t size;

--- 82 unchanged lines hidden (view full) ---

577 ihcnt = 0;
578 s = 0; /* this is only here to keep the compiler
579 happy */
580 hiipl = 0; /* this is only here to keep the compiler
581 happy */
582
583 STAILQ_FOREACH(pf2, &pf->sc->card.pf_head, pf_list) {
584 if (pf2->ih_fct) {
585 DPRINTF(("%s: function %d has ih_fct %p\n",
586 pf->sc->dev.dv_xname, pf2->number,
587 pf2->ih_fct));
588
589 if (ihcnt == 0) {
590 hiipl = pf2->ih_ipl;
591 } else {
592 if (pf2->ih_ipl > hiipl)
593 hiipl = pf2->ih_ipl;
594 }
595

--- 205 unchanged lines hidden (view full) ---

801{
802 struct pccard_softc *sc = arg;
803 struct pccard_function *pf;
804 int reg, ret, ret2;
805
806 ret = 0;
807
808 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
809 printf("%s: intr flags=%x fct=%d cor=%02x csr=%02x pin=%02x",
810 sc->dev.dv_xname, pf->pf_flags, pf->number,
811 pccard_ccr_read(pf, PCCARD_CCR_OPTION),
812 pccard_ccr_read(pf, PCCARD_CCR_STATUS),
813 pccard_ccr_read(pf, PCCARD_CCR_PIN));
814 if (pf->ih_fct != NULL &&
815 (pf->ccr_mask & (1 << (PCCARD_CCR_STATUS / 2)))) {
816 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
817 if (reg & PCCARD_CCR_STATUS_INTR) {
818 ret2 = (*pf->ih_fct)(pf->ih_arg);
819 if (ret2 != 0 && ret == 0)
820 ret = ret2;
821 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);

--- 177 unchanged lines hidden ---