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 55500 2000-01-06 07:30:28Z 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#include "power_if.h"
51
52#define PCCARDDEBUG
53
54#ifdef PCCARDDEBUG
55int pccard_debug = 1;
56#define DPRINTF(arg) if (pccard_debug) printf arg
57#define DEVPRINTF(arg) if (pccard_debug) device_printf arg
58int pccardintr_debug = 0;
59/* this is done this way to avoid doing lots of conditionals
60 at interrupt level. */
61#define PCCARD_CARD_INTR (pccardintr_debug?pccard_card_intrdebug:pccard_card_intr)
62#else
63#define DPRINTF(arg)
64#define DEVPRINTF(arg)
65#define PCCARD_CARD_INTR (pccard_card_intr)
66#endif
67
68#ifdef PCCARDVERBOSE
69int pccard_verbose = 1;
70#else
71int pccard_verbose = 0;
72#endif
73
74int pccard_print(void *, const char *);
75
76int pccard_card_intr(void *);
77#ifdef PCCARDDEBUG
78int pccard_card_intrdebug(void *);
79#endif
80
81/* XXX Shouldn't be touching hardware, that's a layering violation */
82/* XXX imp */
83int

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

103}
104
105int
106pccard_card_attach(device_t dev)
107{
108 struct pccard_softc *sc = (struct pccard_softc *)
109 device_get_softc(dev);
110 struct pccard_function *pf;
111 int attached;
112
113 DEVPRINTF((dev, "pccard_card_attach\n"));
114 /*
115 * this is here so that when socket_enable calls gettype, trt happens
116 */
117 STAILQ_INIT(&sc->card.pf_head);
118
119 DEVPRINTF((dev, "chip_socket_enable\n"));
120 POWER_ENABLE_SOCKET(device_get_parent(dev), dev);
121
122 DEVPRINTF((dev, "read_cis\n"));
123 pccard_read_cis(sc);
124
125 DEVPRINTF((dev, "chip_socket_disable\n"));
126 POWER_DISABLE_SOCKET(device_get_parent(dev), dev);
127
128 DEVPRINTF((dev, "check_cis_quirks\n"));
129 pccard_check_cis_quirks(dev);
130
131 /*
132 * bail now if the card has no functions, or if there was an error in
133 * the cis.
134 */
135
136 if (sc->card.error)
137 return (1);
138 if (STAILQ_EMPTY(&sc->card.pf_head))
139 return (1);
140
141 if (pccard_verbose)
142 pccard_print_cis(dev);
143
144 attached = 0;
145
146 DEVPRINTF((dev, "functions scanning\n"));
147 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
148 if (STAILQ_EMPTY(&pf->cfe_head))
149 continue;
150
151#ifdef DIAGNOSTIC
152 if (pf->child != NULL) {
153 device_printf(sc->dev,
154 "%s still attached to function %d!\n",
155 device_get_name(pf->child), pf->number);
156 panic("pccard_card_attach");
157 }
158#endif
159 pf->sc = sc;
160 pf->child = NULL;
161 pf->cfe = NULL;
162 pf->ih_fct = NULL;
163 pf->ih_arg = NULL;
164 }
165
166 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
167 if (STAILQ_EMPTY(&pf->cfe_head))
168 continue;
169
170#if XXX
171 if (attach_child()) {
172 attached++;
173
174 DEVPRINTF((sc->dev, "function %d CCR at %d "
175 "offset %lx: %x %x %x %x, %x %x %x %x, %x\n",
176 pf->number, 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 DEVPRINTF((sc->dev, "detaching %s (function %d)\n",
209 device_get_name(pf->child), pf->number));
210#if XXX
211 if ((error = config_detach(pf->child, flags)) != 0) {
212 device_printf(sc->dev,
213 "error %d detaching %s (function %d)\n",
214 error, device_get_name(pf->child), 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 DEVPRINTF((sc->dev, "deactivating %s (function %d)\n",
239 device_get_name(pf->child), 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
283/* Enable a PCCARD function */
284int
285pccard_function_enable(pf)
286 struct pccard_function *pf;
287{
288 struct pccard_function *tmp;
289 int reg;
290
291 if (pf->cfe == NULL)
292 panic("pccard_function_enable: function not initialized");
293
294 /*
295 * Increase the reference count on the socket, enabling power, if
296 * necessary.
297 */
298 if (pf->sc->sc_enabled_count++ == 0)
299 POWER_ENABLE_SOCKET(device_get_parent(pf->sc->dev),
300 pf->sc->dev);
301 DEVPRINTF((pf->sc->dev, "++enabled_count = %d\n",
302 pf->sc->sc_enabled_count));
303
304 if (pf->pf_flags & PFF_ENABLED) {
305 /*
306 * Don't do anything if we're already enabled.
307 */
308 return (0);
309 }
310

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

385 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0);
386
387 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize);
388 }
389
390#ifdef PCCARDDEBUG
391 if (pccard_debug) {
392 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
393 device_printf(tmp->sc->dev,
394 "function %d CCR at %d offset %x: "
395 "%x %x %x %x, %x %x %x %x, %x\n",
396 tmp->number, tmp->pf_ccr_window,
397 tmp->pf_ccr_offset,
398 pccard_ccr_read(tmp, 0x00),
399 pccard_ccr_read(tmp, 0x02),
400 pccard_ccr_read(tmp, 0x04),
401 pccard_ccr_read(tmp, 0x06),
402 pccard_ccr_read(tmp, 0x0A),
403 pccard_ccr_read(tmp, 0x0C),
404 pccard_ccr_read(tmp, 0x0E),
405 pccard_ccr_read(tmp, 0x10),
406 pccard_ccr_read(tmp, 0x12));
407 }
408 }
409#endif
410
411 pf->pf_flags |= PFF_ENABLED;
412 return (0);
413
414 bad:
415 /*
416 * Decrement the reference count, and power down the socket, if
417 * necessary.
418 */
419 if (--pf->sc->sc_enabled_count == 0)
420 POWER_DISABLE_SOCKET(device_get_parent(pf->sc->dev),
421 pf->sc->dev);
422 DEVPRINTF((pf->sc->dev, "--enabled_count = %d\n",
423 pf->sc->sc_enabled_count));
424
425 return (1);
426}
427
428/* Disable PCCARD function. */
429void
430pccard_function_disable(pf)

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

463 pccard_mem_free(pf, &pf->pf_pcmh);
464 }
465
466 /*
467 * Decrement the reference count, and power down the socket, if
468 * necessary.
469 */
470 if (--pf->sc->sc_enabled_count == 0)
471 POWER_DISABLE_SOCKET(device_get_parent(pf->sc->dev),
472 pf->sc->dev);
473 DEVPRINTF((pf->sc->dev, "--enabled_count = %d\n",
474 pf->sc->sc_enabled_count));
475}
476
477int
478pccard_io_map(pf, width, offset, size, pcihp, windowp)
479 struct pccard_function *pf;
480 int width;
481 bus_addr_t offset;
482 bus_size_t size;

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

565 ihcnt = 0;
566 s = 0; /* this is only here to keep the compiler
567 happy */
568 hiipl = 0; /* this is only here to keep the compiler
569 happy */
570
571 STAILQ_FOREACH(pf2, &pf->sc->card.pf_head, pf_list) {
572 if (pf2->ih_fct) {
573 DEVPRINTF((pf2->sc->dev,
574 "function %d has ih_fct %p\n",
575 pf2->number, pf2->ih_fct));
576
577 if (ihcnt == 0) {
578 hiipl = pf2->ih_ipl;
579 } else {
580 if (pf2->ih_ipl > hiipl)
581 hiipl = pf2->ih_ipl;
582 }
583

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

789{
790 struct pccard_softc *sc = arg;
791 struct pccard_function *pf;
792 int reg, ret, ret2;
793
794 ret = 0;
795
796 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
797 device_printf(sc->dev,
798 "intr flags=%x fct=%d cor=%02x csr=%02x pin=%02x",
799 pf->pf_flags, pf->number,
800 pccard_ccr_read(pf, PCCARD_CCR_OPTION),
801 pccard_ccr_read(pf, PCCARD_CCR_STATUS),
802 pccard_ccr_read(pf, PCCARD_CCR_PIN));
803 if (pf->ih_fct != NULL &&
804 (pf->ccr_mask & (1 << (PCCARD_CCR_STATUS / 2)))) {
805 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
806 if (reg & PCCARD_CCR_STATUS_INTR) {
807 ret2 = (*pf->ih_fct)(pf->ih_arg);
808 if (ret2 != 0 && ret == 0)
809 ret = ret2;
810 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);

--- 177 unchanged lines hidden ---