Home | History | Annotate | Line # | Download | only in cardbus
      1  1.60   thorpej /*	$NetBSD: cardslot.c,v 1.60 2021/08/07 16:19:10 thorpej Exp $	*/
      2   1.5      haya 
      3   1.1      haya /*
      4   1.7      haya  * Copyright (c) 1999 and 2000
      5   1.1      haya  *       HAYAKAWA Koichi.  All rights reserved.
      6   1.1      haya  *
      7   1.1      haya  * Redistribution and use in source and binary forms, with or without
      8   1.1      haya  * modification, are permitted provided that the following conditions
      9   1.1      haya  * are met:
     10   1.1      haya  * 1. Redistributions of source code must retain the above copyright
     11   1.1      haya  *    notice, this list of conditions and the following disclaimer.
     12   1.1      haya  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      haya  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      haya  *    documentation and/or other materials provided with the distribution.
     15   1.1      haya  *
     16   1.1      haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1      haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18   1.1      haya  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19   1.1      haya  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20   1.1      haya  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21   1.1      haya  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22   1.1      haya  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23   1.1      haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24   1.1      haya  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25   1.1      haya  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1      haya  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1      haya  */
     28  1.15     lukem 
     29  1.15     lukem #include <sys/cdefs.h>
     30  1.60   thorpej __KERNEL_RCSID(0, "$NetBSD: cardslot.c,v 1.60 2021/08/07 16:19:10 thorpej Exp $");
     31   1.1      haya 
     32   1.3      haya #include "opt_cardslot.h"
     33   1.1      haya 
     34   1.1      haya #include <sys/param.h>
     35   1.1      haya #include <sys/systm.h>
     36   1.1      haya #include <sys/device.h>
     37   1.1      haya #include <sys/malloc.h>
     38   1.1      haya #include <sys/kernel.h>
     39   1.1      haya #include <sys/syslog.h>
     40   1.1      haya #include <sys/kthread.h>
     41   1.1      haya 
     42  1.36        ad #include <sys/bus.h>
     43   1.1      haya 
     44   1.1      haya #include <dev/cardbus/cardslotvar.h>
     45   1.1      haya #include <dev/cardbus/cardbusvar.h>
     46   1.1      haya #include <dev/pcmcia/pcmciavar.h>
     47   1.1      haya #include <dev/pcmcia/pcmciachip.h>
     48   1.1      haya 
     49  1.25  drochner #include "locators.h"
     50   1.1      haya 
     51   1.1      haya #if defined CARDSLOT_DEBUG
     52   1.1      haya #define STATIC
     53   1.1      haya #define DPRINTF(a) printf a
     54   1.1      haya #else
     55   1.1      haya #define STATIC static
     56   1.1      haya #define DPRINTF(a)
     57   1.1      haya #endif
     58   1.1      haya 
     59  1.56       mrg int pcmcia_error(device_t);
     60  1.56       mrg int
     61  1.56       mrg pcmcia_error(device_t dev)
     62  1.56       mrg {
     63  1.56       mrg 
     64  1.56       mrg 	return 1;
     65  1.56       mrg }
     66  1.56       mrg __weak_alias(pcmcia_card_attach, pcmcia_error);
     67  1.56       mrg __weak_alias(pcmcia_card_deactivate, pcmcia_error);
     68  1.56       mrg __weak_alias(pcmcia_card_detach, pcmcia_error);
     69   1.1      haya 
     70   1.1      haya 
     71  1.50    dyoung STATIC void cardslotchilddet(device_t, device_t);
     72  1.49    cegger STATIC void cardslotattach(device_t, device_t, void *);
     73  1.39    dyoung STATIC int cardslotdetach(device_t, int);
     74   1.1      haya 
     75  1.49    cegger STATIC int cardslotmatch(device_t, cfdata_t, void *);
     76  1.26     perry static void cardslot_event_thread(void *arg);
     77  1.26     perry 
     78  1.26     perry STATIC int cardslot_cb_print(void *aux, const char *pcic);
     79  1.26     perry static int cardslot_16_print(void *, const char *);
     80  1.54       chs static int cardslot_16_submatch(device_t, cfdata_t, const int *, void *);
     81   1.1      haya 
     82  1.47    dyoung CFATTACH_DECL3_NEW(cardslot, sizeof(struct cardslot_softc),
     83  1.50    dyoung     cardslotmatch, cardslotattach, cardslotdetach, NULL, NULL, cardslotchilddet,
     84  1.47    dyoung     DVF_DETACH_SHUTDOWN);
     85   1.1      haya 
     86   1.1      haya STATIC int
     87  1.49    cegger cardslotmatch(device_t parent, cfdata_t cf,
     88  1.32  christos     void *aux)
     89   1.1      haya {
     90  1.14      haya 	struct cardslot_attach_args *caa = aux;
     91   1.1      haya 
     92  1.14      haya 	if (caa->caa_cb_attach == NULL && caa->caa_16_attach == NULL) {
     93  1.14      haya 		/* Neither CardBus nor 16-bit PCMCIA are defined. */
     94  1.14      haya 		return 0;
     95  1.14      haya 	}
     96   1.1      haya 
     97  1.14      haya 	return 1;
     98   1.1      haya }
     99   1.1      haya 
    100  1.50    dyoung STATIC void
    101  1.50    dyoung cardslotchilddet(device_t self, device_t child)
    102  1.50    dyoung {
    103  1.50    dyoung 	struct cardslot_softc *sc = device_private(self);
    104   1.1      haya 
    105  1.50    dyoung 	KASSERT(sc->sc_cb_softc == device_private(child) ||
    106  1.50    dyoung 	    sc->sc_16_softc == child);
    107  1.50    dyoung 
    108  1.50    dyoung 	if (sc->sc_cb_softc == device_private(child))
    109  1.50    dyoung 		sc->sc_cb_softc = NULL;
    110  1.50    dyoung 	else if (sc->sc_16_softc == child)
    111  1.50    dyoung 		sc->sc_16_softc = NULL;
    112  1.50    dyoung }
    113   1.1      haya 
    114   1.1      haya STATIC void
    115  1.54       chs cardslotattach(device_t parent, device_t self, void *aux)
    116   1.1      haya {
    117  1.31   thorpej 	struct cardslot_softc *sc = device_private(self);
    118  1.14      haya 	struct cardslot_attach_args *caa = aux;
    119  1.14      haya 
    120  1.14      haya 	struct cbslot_attach_args *cba = caa->caa_cb_attach;
    121  1.14      haya 	struct pcmciabus_attach_args *pa = caa->caa_16_attach;
    122  1.14      haya 
    123  1.23  christos 	struct cardbus_softc *csc = NULL;
    124  1.23  christos 	struct pcmcia_softc *psc = NULL;
    125   1.1      haya 
    126  1.42  drochner 	sc->sc_dev = self;
    127  1.42  drochner 
    128  1.14      haya 	sc->sc_cb_softc = NULL;
    129  1.14      haya 	sc->sc_16_softc = NULL;
    130  1.14      haya 	SIMPLEQ_INIT(&sc->sc_events);
    131  1.14      haya 	sc->sc_th_enable = 0;
    132  1.58       mrg 	mutex_init(&sc->sc_event_lock, MUTEX_DEFAULT, IPL_TTY);
    133  1.58       mrg 	cv_init(&sc->sc_event_cv, "evexit");
    134  1.14      haya 
    135  1.37  jmcneill 	aprint_naive("\n");
    136  1.41  drochner 	aprint_normal("\n");
    137  1.14      haya 
    138  1.42  drochner 	DPRINTF(("%s attaching CardBus bus...\n", device_xname(self)));
    139  1.14      haya 	if (cba != NULL) {
    140  1.59   thorpej 		csc = device_private(config_found(self, cba, cardslot_cb_print,
    141  1.60   thorpej 		    CFARGS(.iattr = "cbbus")));
    142  1.25  drochner 		if (csc) {
    143  1.14      haya 			/* cardbus found */
    144  1.34    dyoung 			DPRINTF(("%s: found cardbus on %s\n", __func__,
    145  1.42  drochner 				 device_xname(self)));
    146  1.14      haya 			sc->sc_cb_softc = csc;
    147  1.14      haya 		}
    148  1.14      haya 	}
    149  1.14      haya 
    150  1.14      haya 	if (pa != NULL) {
    151  1.59   thorpej 		sc->sc_16_softc = config_found(self, pa, cardslot_16_print,
    152  1.60   thorpej 		    CFARGS(.submatch = cardslot_16_submatch,
    153  1.60   thorpej 			   .iattr = "pcmciabus"));
    154  1.45  drochner 		if (sc->sc_16_softc) {
    155  1.14      haya 			/* pcmcia 16-bit bus found */
    156  1.34    dyoung 			DPRINTF(("%s: found 16-bit pcmcia bus\n", __func__));
    157  1.45  drochner 			psc = device_private(sc->sc_16_softc);
    158  1.14      haya 		}
    159  1.14      haya 	}
    160   1.1      haya 
    161  1.14      haya 	if (csc != NULL || psc != NULL) {
    162  1.57       nat 		sc->sc_th_enable = 1;
    163  1.55  christos 		config_pending_incr(self);
    164  1.35        ad 		if (kthread_create(PRI_NONE, 0, NULL, cardslot_event_thread,
    165  1.41  drochner 		    sc, &sc->sc_event_thread, "%s", device_xname(self))) {
    166  1.42  drochner 			aprint_error_dev(sc->sc_dev,
    167  1.41  drochner 					 "unable to create thread\n");
    168  1.35        ad 			panic("cardslotattach");
    169  1.35        ad 		}
    170  1.14      haya 	}
    171   1.1      haya 
    172  1.14      haya 	if (csc && (csc->sc_cf->cardbus_ctrl)(csc->sc_cc, CARDBUS_CD)) {
    173  1.34    dyoung 		DPRINTF(("%s: CardBus card found\n", __func__));
    174  1.14      haya 		/* attach deferred */
    175  1.14      haya 		cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_CB);
    176  1.14      haya 	}
    177   1.1      haya 
    178  1.14      haya 	if (psc && (psc->pct->card_detect)(psc->pch)) {
    179  1.34    dyoung 		DPRINTF(("%s: 16-bit card found\n", __func__));
    180  1.14      haya 		/* attach deferred */
    181  1.14      haya 		cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_16);
    182  1.14      haya 	}
    183  1.38  jmcneill 
    184  1.38  jmcneill 	if (!pmf_device_register(self, NULL, NULL))
    185  1.38  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    186   1.1      haya }
    187   1.1      haya 
    188  1.39    dyoung STATIC int
    189  1.39    dyoung cardslotdetach(device_t self, int flags)
    190  1.39    dyoung {
    191  1.39    dyoung 	int rc;
    192  1.39    dyoung 	struct cardslot_softc *sc = device_private(self);
    193  1.39    dyoung 
    194  1.39    dyoung 	if ((rc = config_detach_children(self, flags)) != 0)
    195  1.39    dyoung 		return rc;
    196  1.39    dyoung 
    197  1.58       mrg 	mutex_enter(&sc->sc_event_lock);
    198  1.58       mrg 
    199  1.58       mrg 	if (sc->sc_event_thread != NULL) {
    200  1.58       mrg 		sc->sc_th_enable = 0;
    201  1.58       mrg 		cv_signal(&sc->sc_event_cv);
    202  1.58       mrg 		while (sc->sc_event_thread != NULL) {
    203  1.58       mrg 			cv_wait(&sc->sc_event_cv, &sc->sc_event_lock);
    204  1.58       mrg 		}
    205  1.58       mrg 	}
    206  1.39    dyoung 
    207  1.39    dyoung 	if (!SIMPLEQ_EMPTY(&sc->sc_events))
    208  1.39    dyoung 		aprint_error_dev(self, "events outstanding");
    209   1.1      haya 
    210  1.58       mrg 	mutex_exit(&sc->sc_event_lock);
    211  1.58       mrg 
    212  1.58       mrg 	mutex_destroy(&sc->sc_event_lock);
    213  1.58       mrg 	cv_destroy(&sc->sc_event_cv);
    214  1.58       mrg 
    215  1.39    dyoung 	pmf_device_deregister(self);
    216  1.39    dyoung 	return 0;
    217  1.39    dyoung }
    218   1.1      haya 
    219   1.1      haya STATIC int
    220  1.34    dyoung cardslot_cb_print(void *aux, const char *pnp)
    221   1.1      haya {
    222   1.9      haya 	struct cbslot_attach_args *cba = aux;
    223   1.4      haya 
    224  1.34    dyoung 	if (pnp != NULL) {
    225  1.22   thorpej 		aprint_normal("cardbus at %s subordinate bus %d",
    226  1.22   thorpej 		    pnp, cba->cba_bus);
    227   1.9      haya 	}
    228   1.4      haya 
    229   1.9      haya 	return UNCONF;
    230   1.1      haya }
    231   1.1      haya 
    232   1.1      haya 
    233   1.1      haya static int
    234  1.49    cegger cardslot_16_submatch(device_t parent, cfdata_t cf,
    235  1.33  christos     const int *ldesc, void *aux)
    236   1.1      haya {
    237   1.1      haya 
    238  1.14      haya 	if (cf->cf_loc[PCMCIABUSCF_CONTROLLER] != PCMCIABUSCF_CONTROLLER_DEFAULT
    239  1.14      haya 	    && cf->cf_loc[PCMCIABUSCF_CONTROLLER] != 0) {
    240  1.14      haya 		return 0;
    241  1.14      haya 	}
    242  1.14      haya 
    243  1.53     joerg 	if (cf->cf_loc[PCMCIABUSCF_CONTROLLER] == PCMCIABUSCF_CONTROLLER_DEFAULT) {
    244  1.18   thorpej 		return (config_match(parent, cf, aux));
    245  1.14      haya 	}
    246  1.14      haya 
    247  1.14      haya 	return 0;
    248   1.1      haya }
    249   1.1      haya 
    250   1.1      haya 
    251   1.1      haya 
    252   1.1      haya static int
    253  1.33  christos cardslot_16_print(void *arg, const char *pnp)
    254   1.1      haya {
    255   1.4      haya 
    256  1.34    dyoung 	if (pnp != NULL) {
    257  1.22   thorpej 		aprint_normal("pcmciabus at %s", pnp);
    258  1.14      haya 	}
    259   1.1      haya 
    260  1.14      haya 	return UNCONF;
    261   1.1      haya }
    262   1.1      haya 
    263   1.1      haya 
    264   1.1      haya /*
    265   1.1      haya  * void cardslot_event_throw(struct cardslot_softc *sc, int ev)
    266   1.1      haya  *
    267   1.1      haya  *   This function throws an event to the event handler.  If the state
    268   1.1      haya  *   of a slot is changed, it should be noticed using this function.
    269   1.1      haya  */
    270   1.1      haya void
    271  1.34    dyoung cardslot_event_throw(struct cardslot_softc *sc, int ev)
    272   1.1      haya {
    273  1.14      haya 	struct cardslot_event *ce;
    274   1.1      haya 
    275  1.14      haya 	DPRINTF(("cardslot_event_throw: an event %s comes\n",
    276  1.14      haya 	    ev == CARDSLOT_EVENT_INSERTION_CB ? "CardBus Card inserted" :
    277  1.14      haya 	    ev == CARDSLOT_EVENT_INSERTION_16 ? "16-bit Card inserted" :
    278  1.14      haya 	    ev == CARDSLOT_EVENT_REMOVAL_CB ? "CardBus Card removed" :
    279  1.14      haya 	    ev == CARDSLOT_EVENT_REMOVAL_16 ? "16-bit Card removed" : "???"));
    280   1.1      haya 
    281  1.14      haya 	if (NULL == (ce = (struct cardslot_event *)malloc(sizeof (struct cardslot_event), M_TEMP, M_NOWAIT))) {
    282  1.14      haya 		panic("cardslot_enevt");
    283  1.14      haya 	}
    284   1.1      haya 
    285  1.14      haya 	ce->ce_type = ev;
    286   1.1      haya 
    287  1.58       mrg 	mutex_enter(&sc->sc_event_lock);
    288  1.58       mrg 	SIMPLEQ_INSERT_TAIL(&sc->sc_events, ce, ce_q);
    289  1.58       mrg 	mutex_exit(&sc->sc_event_lock);
    290   1.1      haya 
    291  1.58       mrg 	cv_signal(&sc->sc_event_cv);
    292   1.1      haya 
    293  1.14      haya 	return;
    294   1.1      haya }
    295   1.1      haya 
    296   1.1      haya 
    297   1.1      haya /*
    298   1.1      haya  * static void cardslot_event_thread(void *arg)
    299   1.1      haya  *
    300   1.1      haya  *   This function is the main routine handing cardslot events such as
    301   1.1      haya  *   insertions and removals.
    302   1.1      haya  *
    303   1.1      haya  */
    304   1.1      haya static void
    305  1.46       dsl cardslot_event_thread(void *arg)
    306   1.1      haya {
    307  1.14      haya 	struct cardslot_softc *sc = arg;
    308  1.14      haya 	struct cardslot_event *ce;
    309  1.58       mrg 	int first = 1;
    310  1.14      haya 	static int antonym_ev[4] = {
    311  1.14      haya 		CARDSLOT_EVENT_REMOVAL_16, CARDSLOT_EVENT_INSERTION_16,
    312  1.14      haya 		CARDSLOT_EVENT_REMOVAL_CB, CARDSLOT_EVENT_INSERTION_CB
    313  1.14      haya 	};
    314  1.14      haya 
    315  1.58       mrg 	mutex_enter(&sc->sc_event_lock);
    316  1.14      haya 	while (sc->sc_th_enable) {
    317  1.14      haya 		if ((ce = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    318  1.14      haya 			if (first) {
    319  1.14      haya 				first = 0;
    320  1.58       mrg 				mutex_exit(&sc->sc_event_lock);
    321  1.55  christos 				config_pending_decr(sc->sc_dev);
    322  1.58       mrg 				mutex_enter(&sc->sc_event_lock);
    323  1.14      haya 			}
    324  1.58       mrg 			cv_wait(&sc->sc_event_cv, &sc->sc_event_lock);
    325  1.14      haya 			continue;
    326  1.14      haya 		}
    327  1.17     lukem 		SIMPLEQ_REMOVE_HEAD(&sc->sc_events, ce_q);
    328  1.14      haya 
    329  1.14      haya 		if (IS_CARDSLOT_INSERT_REMOVE_EV(ce->ce_type)) {
    330  1.24       wiz 			/* Chattering suppression */
    331  1.14      haya 			while (1) {
    332  1.14      haya 				struct cardslot_event *ce1, *ce2;
    333  1.14      haya 
    334  1.14      haya 				if ((ce1 = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    335  1.14      haya 					break;
    336  1.14      haya 				}
    337  1.14      haya 				if (ce1->ce_type != antonym_ev[ce->ce_type]) {
    338  1.14      haya 					break;
    339  1.14      haya 				}
    340  1.14      haya 				if ((ce2 = SIMPLEQ_NEXT(ce1, ce_q)) == NULL) {
    341  1.14      haya 					break;
    342  1.14      haya 				}
    343  1.14      haya 				if (ce2->ce_type == ce->ce_type) {
    344  1.17     lukem 					SIMPLEQ_REMOVE_HEAD(&sc->sc_events,
    345  1.17     lukem 					    ce_q);
    346  1.14      haya 					free(ce1, M_TEMP);
    347  1.17     lukem 					SIMPLEQ_REMOVE_HEAD(&sc->sc_events,
    348  1.17     lukem 					    ce_q);
    349  1.14      haya 					free(ce2, M_TEMP);
    350  1.14      haya 				}
    351  1.14      haya 			}
    352  1.14      haya 		}
    353  1.58       mrg 		mutex_exit(&sc->sc_event_lock);
    354  1.14      haya 
    355  1.14      haya 		switch (ce->ce_type) {
    356  1.14      haya 		case CARDSLOT_EVENT_INSERTION_CB:
    357  1.14      haya 			if ((CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB)
    358  1.14      haya 			    || (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_16)) {
    359  1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    360  1.14      haya 					/*
    361  1.14      haya 					 * A card has already been
    362  1.14      haya 					 * inserted and works.
    363  1.14      haya 					 */
    364  1.14      haya 					break;
    365  1.14      haya 				}
    366  1.14      haya 			}
    367  1.14      haya 
    368  1.14      haya 			if (sc->sc_cb_softc) {
    369  1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    370  1.14      haya 				    CARDSLOT_STATUS_CARD_CB);
    371  1.14      haya 				if (cardbus_attach_card(sc->sc_cb_softc) > 0) {
    372  1.14      haya 					/* at least one function works */
    373  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status, CARDSLOT_STATUS_WORKING);
    374  1.14      haya 				} else {
    375  1.14      haya 					/*
    376  1.14      haya 					 * no functions work or this
    377  1.14      haya 					 * card is not known
    378  1.14      haya 					 */
    379  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    380  1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    381  1.14      haya 				}
    382  1.14      haya 			} else {
    383  1.58       mrg 				printf("%s: no cardbus on %s\n", __func__,
    384  1.42  drochner 				      device_xname(sc->sc_dev));
    385  1.58       mrg 				CARDSLOT_SET_WORK(sc->sc_status,
    386  1.58       mrg 				    CARDSLOT_STATUS_NOTWORK);
    387  1.14      haya 			}
    388  1.14      haya 
    389  1.14      haya 			break;
    390  1.14      haya 
    391  1.14      haya 		case CARDSLOT_EVENT_INSERTION_16:
    392  1.14      haya 			if ((CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB)
    393  1.14      haya 			    || (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_16)) {
    394  1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    395  1.14      haya 					/*
    396  1.14      haya 					 * A card has already been
    397  1.14      haya 					 * inserted and work.
    398  1.14      haya 					 */
    399  1.14      haya 					break;
    400  1.14      haya 				}
    401  1.14      haya 			}
    402  1.14      haya 			if (sc->sc_16_softc) {
    403  1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_16);
    404  1.52    dyoung 				if (pcmcia_card_attach(sc->sc_16_softc)) {
    405  1.14      haya 					/* Do not attach */
    406  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    407  1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    408  1.14      haya 				} else {
    409  1.14      haya 					/* working */
    410  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    411  1.14      haya 					    CARDSLOT_STATUS_WORKING);
    412  1.14      haya 				}
    413  1.14      haya 			} else {
    414  1.58       mrg 				printf("%s: no 16-bit pcmcia on %s\n", __func__,
    415  1.42  drochner 				      device_xname(sc->sc_dev));
    416  1.58       mrg 				CARDSLOT_SET_WORK(sc->sc_status,
    417  1.58       mrg 				    CARDSLOT_STATUS_NOTWORK);
    418  1.14      haya 			}
    419  1.14      haya 
    420  1.14      haya 			break;
    421  1.14      haya 
    422  1.14      haya 		case CARDSLOT_EVENT_REMOVAL_CB:
    423  1.14      haya 			if (CARDSLOT_CARDTYPE(sc->sc_status) == CARDSLOT_STATUS_CARD_CB) {
    424  1.14      haya 				/* CardBus card has not been inserted. */
    425  1.14      haya 				if (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING) {
    426  1.14      haya 					cardbus_detach_card(sc->sc_cb_softc);
    427  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    428  1.14      haya 					    CARDSLOT_STATUS_NOTWORK);
    429  1.14      haya 					CARDSLOT_SET_WORK(sc->sc_status,
    430  1.14      haya 					    CARDSLOT_STATUS_CARD_NONE);
    431  1.14      haya 				}
    432  1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    433  1.14      haya 				    CARDSLOT_STATUS_CARD_NONE);
    434  1.14      haya 			} else if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_16) {
    435  1.14      haya 				/* Unknown card... */
    436  1.14      haya 				CARDSLOT_SET_CARDTYPE(sc->sc_status,
    437  1.14      haya 				    CARDSLOT_STATUS_CARD_NONE);
    438  1.14      haya 			}
    439  1.14      haya 			CARDSLOT_SET_WORK(sc->sc_status,
    440  1.14      haya 			    CARDSLOT_STATUS_NOTWORK);
    441  1.14      haya 			break;
    442  1.14      haya 
    443  1.14      haya 		case CARDSLOT_EVENT_REMOVAL_16:
    444  1.44    dogcow 			DPRINTF(("%s: removal event\n", device_xname(sc->sc_dev)));
    445  1.14      haya 			if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_16) {
    446  1.14      haya 				/* 16-bit card has not been inserted. */
    447  1.14      haya 				break;
    448  1.14      haya 			}
    449  1.14      haya 			if ((sc->sc_16_softc != NULL)
    450  1.14      haya 			    && (CARDSLOT_WORK(sc->sc_status) == CARDSLOT_STATUS_WORKING)) {
    451  1.45  drochner 				struct pcmcia_softc *psc =
    452  1.45  drochner 					device_private(sc->sc_16_softc);
    453  1.14      haya 
    454  1.45  drochner 				pcmcia_card_deactivate(sc->sc_16_softc);
    455  1.14      haya 				pcmcia_chip_socket_disable(psc->pct, psc->pch);
    456  1.45  drochner 				pcmcia_card_detach(sc->sc_16_softc,
    457  1.45  drochner 						   DETACH_FORCE);
    458  1.14      haya 			}
    459  1.14      haya 			CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_NONE);
    460  1.14      haya 			CARDSLOT_SET_WORK(sc->sc_status, CARDSLOT_STATUS_NOTWORK);
    461  1.14      haya 			break;
    462  1.14      haya 
    463  1.14      haya 		default:
    464  1.14      haya 			panic("cardslot_event_thread: unknown event %d", ce->ce_type);
    465  1.14      haya 		}
    466  1.14      haya 		free(ce, M_TEMP);
    467  1.58       mrg 		mutex_enter(&sc->sc_event_lock);
    468  1.14      haya 	}
    469   1.1      haya 
    470  1.58       mrg 	/* The parent device is waiting for us to exit. */
    471  1.14      haya 	sc->sc_event_thread = NULL;
    472   1.1      haya 
    473  1.58       mrg 	cv_signal(&sc->sc_event_cv);
    474  1.58       mrg 	mutex_exit(&sc->sc_event_lock);
    475   1.1      haya 
    476  1.14      haya 	kthread_exit(0);
    477   1.1      haya }
    478