Home | History | Annotate | Line # | Download | only in cardbus
cardslot.c revision 1.2.4.1
      1  1.2.4.1  fvdl /*	$NetBSD: cardslot.c,v 1.2.4.1 1999/11/15 00:40:19 fvdl Exp $	*/
      2      1.1  haya /*
      3      1.1  haya  * Copyright (c) 1999
      4      1.1  haya  *       HAYAKAWA Koichi.  All rights reserved.
      5      1.1  haya  *
      6      1.1  haya  * Redistribution and use in source and binary forms, with or without
      7      1.1  haya  * modification, are permitted provided that the following conditions
      8      1.1  haya  * are met:
      9      1.1  haya  * 1. Redistributions of source code must retain the above copyright
     10      1.1  haya  *    notice, this list of conditions and the following disclaimer.
     11      1.1  haya  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  haya  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  haya  *    documentation and/or other materials provided with the distribution.
     14      1.1  haya  * 3. All advertising materials mentioning features or use of this software
     15      1.1  haya  *    must display the following acknowledgement:
     16      1.1  haya  *	This product includes software developed by HAYAKAWA Koichi.
     17      1.1  haya  * 4. The name of the author may not be used to endorse or promote products
     18      1.1  haya  *    derived from this software without specific prior written permission.
     19      1.1  haya  *
     20      1.1  haya  *
     21      1.1  haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23      1.1  haya  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24      1.1  haya  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     25      1.1  haya  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     26      1.1  haya  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     27      1.1  haya  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28      1.1  haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     29      1.1  haya  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     30      1.1  haya  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31      1.1  haya  * POSSIBILITY OF SUCH DAMAGE.
     32      1.1  haya  */
     33      1.1  haya 
     34  1.2.4.1  fvdl #include "opt_cardslot.h"
     35      1.1  haya 
     36      1.1  haya #include <sys/types.h>
     37      1.1  haya #include <sys/param.h>
     38      1.1  haya #include <sys/systm.h>
     39      1.1  haya #include <sys/device.h>
     40      1.1  haya #include <sys/malloc.h>
     41      1.1  haya #include <sys/kernel.h>
     42      1.1  haya #include <sys/syslog.h>
     43      1.1  haya #include <sys/kthread.h>
     44      1.1  haya 
     45      1.1  haya #include <machine/bus.h>
     46      1.1  haya 
     47      1.1  haya #include <dev/cardbus/cardslotvar.h>
     48      1.1  haya #include <dev/cardbus/cardbusvar.h>
     49      1.1  haya #include <dev/pcmcia/pcmciavar.h>
     50      1.1  haya #include <dev/pcmcia/pcmciachip.h>
     51      1.1  haya #include <dev/ic/i82365var.h>
     52      1.1  haya 
     53      1.1  haya 
     54      1.1  haya #if defined CARDSLOT_DEBUG
     55      1.1  haya #define STATIC
     56      1.1  haya #define DPRINTF(a) printf a
     57      1.1  haya #define DDELAY(x) delay((x)*1000*1000)
     58      1.1  haya #else
     59      1.1  haya #define STATIC static
     60      1.1  haya #define DPRINTF(a)
     61      1.1  haya #endif
     62      1.1  haya 
     63      1.1  haya 
     64      1.1  haya 
     65      1.1  haya STATIC void cardslotattach __P((struct device *, struct device *, void *));
     66      1.1  haya 
     67      1.1  haya #if !defined __BROKEN_INDIRECT_CONFIG
     68      1.1  haya STATIC int cardslotmatch __P((struct device *, struct cfdata *, void *));
     69      1.1  haya #else
     70      1.1  haya STATIC int cardslotmatch __P((struct device *, void *, void *));
     71      1.1  haya #endif
     72      1.1  haya static void create_slot_manager __P((void *));
     73      1.1  haya static void cardslot_event_thread __P((void *arg));
     74      1.1  haya 
     75      1.1  haya STATIC int cardslot_cb_print __P((void *aux, const char *pcic));
     76      1.1  haya static int cardslot_16_print __P((void *, const char *));
     77      1.1  haya static int cardslot_16_submatch __P((struct device *, struct cfdata *,void *));
     78      1.1  haya 
     79      1.1  haya struct cfattach cardslot_ca = {
     80      1.1  haya 	sizeof(struct cardslot_softc), cardslotmatch, cardslotattach
     81      1.1  haya };
     82      1.1  haya 
     83      1.1  haya #ifndef __NetBSD_Version__
     84      1.1  haya struct cfdriver cardslot_cd = {
     85      1.1  haya 	NULL, "cardslot", DV_DULL
     86      1.1  haya };
     87      1.1  haya #endif
     88      1.1  haya 
     89      1.1  haya 
     90      1.1  haya STATIC int
     91      1.1  haya #if defined __BROKEN_INDIRECT_CONFIG
     92      1.1  haya cardslotmatch(parent, match, aux)
     93      1.1  haya      struct device *parent;
     94      1.1  haya      void *match;
     95      1.1  haya      void *aux;
     96      1.1  haya #else
     97      1.1  haya cardslotmatch(parent, cf, aux)
     98      1.1  haya      struct device *parent;
     99      1.1  haya      struct cfdata *cf;
    100      1.1  haya      void *aux;
    101      1.1  haya #endif
    102      1.1  haya {
    103      1.1  haya #if defined __BROKEN_INDIRECT_CONFIG
    104      1.1  haya   struct cfdata *cf = match;
    105      1.1  haya #endif
    106      1.1  haya   struct cardslot_attach_args *caa = aux;
    107      1.1  haya 
    108      1.1  haya   if (caa->caa_cb_attach == NULL && caa->caa_16_attach == NULL) {
    109      1.1  haya     /* Neither CardBus nor 16-bit PCMCIA are defined. */
    110      1.1  haya     return 0;
    111      1.1  haya   }
    112      1.1  haya 
    113      1.1  haya   return 1;
    114      1.1  haya }
    115      1.1  haya 
    116      1.1  haya 
    117      1.1  haya 
    118      1.1  haya STATIC void
    119      1.1  haya cardslotattach(parent, self, aux)
    120      1.1  haya      struct device *parent;
    121      1.1  haya      struct device *self;
    122      1.1  haya      void *aux;
    123      1.1  haya {
    124      1.1  haya   struct cardslot_softc *sc = (struct cardslot_softc *)self;
    125      1.1  haya   struct cardslot_attach_args *caa = aux;
    126      1.1  haya 
    127      1.1  haya   struct cbslot_attach_args *cba = caa->caa_cb_attach;
    128      1.1  haya   struct pcmciabus_attach_args *pa = caa->caa_16_attach;
    129      1.1  haya 
    130      1.1  haya   struct cardbus_softc *csc;
    131      1.1  haya   struct pcmcia_softc *psc;
    132      1.1  haya 
    133      1.1  haya   int card_attach_now;
    134      1.1  haya 
    135      1.1  haya   sc->sc_slot = sc->sc_dev.dv_unit;
    136      1.1  haya   sc->sc_cb_softc = NULL;
    137      1.1  haya   sc->sc_16_softc = NULL;
    138      1.1  haya   SIMPLEQ_INIT(&sc->sc_events);
    139      1.1  haya   sc->sc_th_enable = 0;
    140      1.1  haya 
    141      1.1  haya   printf(" slot %d flags %x\n", sc->sc_slot, sc->sc_dev.dv_cfdata->cf_flags);
    142      1.1  haya 
    143      1.1  haya   DPRINTF(("%s attaching CardBus bus...\n", sc->sc_dev.dv_xname));
    144      1.1  haya   if (cba != NULL) {
    145      1.1  haya     if (NULL != (csc = (void *)config_found(self, cba, cardslot_cb_print))) {
    146      1.1  haya       /* cardbus found */
    147      1.1  haya       DPRINTF(("cardslotattach: found cardbus on %s\n", sc->sc_dev.dv_xname));
    148      1.1  haya       sc->sc_cb_softc = csc;
    149      1.1  haya     }
    150      1.1  haya   }
    151      1.1  haya 
    152      1.1  haya   if (pa != NULL) {
    153      1.1  haya     if (NULL != (psc = (void *)config_found_sm(self, pa, cardslot_16_print,
    154      1.1  haya 				       cardslot_16_submatch))) {
    155      1.1  haya       /* pcmcia 16-bit bus found */
    156      1.1  haya       DPRINTF(("cardslotattach: found 16-bit pcmcia bus\n"));
    157      1.1  haya       sc->sc_16_softc = psc;
    158      1.1  haya       /* XXX: dirty.  This code should be removed to achieve MI */
    159      1.1  haya       caa->caa_ph->pcmcia = (struct device *)psc;
    160      1.1  haya     }
    161      1.1  haya   }
    162      1.1  haya 
    163      1.1  haya   if (csc != NULL || psc != NULL) {
    164      1.1  haya #if __NetBSD_Version__ > 104060000
    165      1.1  haya     kthread_create(create_slot_manager, (void *)sc);
    166      1.1  haya #else
    167      1.1  haya     kthread_create_deferred(create_slot_manager, (void *)sc);
    168      1.1  haya #endif
    169      1.1  haya   }
    170      1.1  haya 
    171      1.1  haya   card_attach_now = sc->sc_dev.dv_cfdata->cf_flags & 0x01;
    172      1.1  haya 
    173      1.1  haya   if (csc && (csc->sc_cf->cardbus_ctrl)(csc->sc_cc, CARDBUS_CD)) {
    174      1.1  haya     DPRINTF(("cardslotattach: CardBus card found\n"));
    175      1.1  haya     if (card_attach_now) {
    176      1.1  haya       /* attach now */
    177      1.1  haya       cardbus_attach_card(sc->sc_cb_softc);
    178      1.1  haya       CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_CB);
    179      1.1  haya     } else {
    180      1.1  haya       /* attach deffered */
    181      1.1  haya       cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_CB);
    182      1.1  haya     }
    183      1.1  haya   }
    184      1.1  haya 
    185      1.1  haya   if (psc && (psc->pct->card_detect)(psc->pch)) {
    186      1.1  haya     DPRINTF(("cardbusattach: 16-bit card found\n"));
    187      1.1  haya     if (card_attach_now) {
    188      1.1  haya       /* attach now */
    189      1.1  haya       pcmcia_card_attach((struct device *)sc->sc_16_softc);
    190      1.1  haya       CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_16);
    191      1.1  haya     } else {
    192      1.1  haya       /* attach deffered */
    193      1.1  haya       cardslot_event_throw(sc, CARDSLOT_EVENT_INSERTION_16);
    194      1.1  haya     }
    195      1.1  haya   }
    196      1.1  haya }
    197      1.1  haya 
    198      1.1  haya 
    199      1.1  haya 
    200      1.1  haya STATIC int
    201  1.2.4.1  fvdl cardslot_cb_print(aux, pnp)
    202      1.1  haya      void *aux;
    203  1.2.4.1  fvdl      const char *pnp;
    204      1.1  haya {
    205  1.2.4.1  fvdl   struct cbslot_attach_args *cba = aux;
    206  1.2.4.1  fvdl 
    207  1.2.4.1  fvdl   if (pnp) {
    208  1.2.4.1  fvdl     printf("cardbus at %s", pnp);
    209  1.2.4.1  fvdl     printf(" function %d subordinate bus %d", cba->cba_function, cba->cba_bus);
    210  1.2.4.1  fvdl   }
    211  1.2.4.1  fvdl 
    212      1.1  haya   return UNCONF;
    213      1.1  haya }
    214      1.1  haya 
    215      1.1  haya 
    216      1.1  haya static int
    217      1.1  haya cardslot_16_submatch(parent, cf, aux)
    218      1.1  haya      struct device *parent;
    219      1.1  haya      struct cfdata *cf;
    220      1.1  haya      void *aux;
    221      1.1  haya {
    222      1.1  haya   if (cf->cf_loc[PCMCIABUSCF_CONTROLLER] != PCMCIABUSCF_CONTROLLER_DEFAULT
    223      1.1  haya       && cf->cf_loc[PCMCIABUSCF_CONTROLLER] != 0) {
    224      1.1  haya     return 0;
    225      1.1  haya   }
    226      1.1  haya 
    227      1.1  haya   if ((cf->cf_loc[PCMCIABUSCF_CONTROLLER] == PCMCIABUSCF_CONTROLLER_DEFAULT)) {
    228      1.1  haya     return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    229      1.1  haya   }
    230      1.1  haya 
    231      1.1  haya   return 0;
    232      1.1  haya }
    233      1.1  haya 
    234      1.1  haya 
    235      1.1  haya 
    236      1.1  haya static int
    237      1.1  haya cardslot_16_print(arg, pnp)
    238      1.1  haya      void *arg;
    239      1.1  haya      const char *pnp;
    240      1.1  haya {
    241  1.2.4.1  fvdl 
    242      1.1  haya   if (pnp) {
    243  1.2.4.1  fvdl     printf("pcmciabus at %s", pnp);
    244      1.1  haya   }
    245      1.1  haya 
    246      1.1  haya   return UNCONF;
    247      1.1  haya }
    248      1.1  haya 
    249      1.1  haya 
    250      1.1  haya 
    251      1.1  haya 
    252      1.1  haya static void
    253      1.1  haya create_slot_manager(arg)
    254      1.1  haya      void *arg;
    255      1.1  haya {
    256      1.1  haya   struct cardslot_softc *sc = (struct cardslot_softc *)arg;
    257      1.1  haya 
    258      1.1  haya   sc->sc_th_enable = 1;
    259      1.1  haya 
    260      1.1  haya #if __NetBSD_Version__ > 104060000
    261      1.1  haya  if (kthread_create1(cardslot_event_thread, sc, &sc->sc_event_thread, "%s",
    262      1.1  haya 		     sc->sc_dev.dv_xname)) {
    263      1.1  haya #else
    264      1.1  haya  if (kthread_create(cardslot_event_thread, sc, &sc->sc_event_thread, "%s",
    265      1.1  haya 		     sc->sc_dev.dv_xname)) {
    266      1.1  haya #endif
    267      1.1  haya     printf("%s: unable to create event thread for slot %d\n",
    268      1.1  haya 	   sc->sc_dev.dv_xname, sc->sc_slot);
    269      1.1  haya     panic("create_slot_manager");
    270      1.1  haya   }
    271      1.1  haya }
    272      1.1  haya 
    273      1.1  haya 
    274      1.1  haya 
    275      1.1  haya 
    276      1.1  haya /*
    277      1.1  haya  * void cardslot_event_throw(struct cardslot_softc *sc, int ev)
    278      1.1  haya  *
    279      1.1  haya  *   This function throws an event to the event handler.  If the state
    280      1.1  haya  *   of a slot is changed, it should be noticed using this function.
    281      1.1  haya  */
    282      1.1  haya void
    283      1.1  haya cardslot_event_throw(sc, ev)
    284      1.1  haya      struct cardslot_softc *sc;
    285      1.1  haya      int ev;
    286      1.1  haya {
    287      1.1  haya   struct cardslot_event *ce;
    288      1.1  haya 
    289      1.1  haya   DPRINTF(("cardslot_event_throw: an event %s comes\n",
    290      1.1  haya 	   ev == CARDSLOT_EVENT_INSERTION_CB ? "CardBus Card inserted" :
    291      1.1  haya 	   ev == CARDSLOT_EVENT_INSERTION_16 ? "16-bit Card inserted" :
    292      1.1  haya 	   ev == CARDSLOT_EVENT_REMOVAL_CB ? "CardBus Card removed" :
    293      1.1  haya 	   ev == CARDSLOT_EVENT_REMOVAL_16 ? "16-bit Card removed" : "???"));
    294      1.1  haya 
    295      1.1  haya   if (NULL == (ce = (struct cardslot_event *)malloc(sizeof (struct cardslot_event), M_TEMP, M_NOWAIT))) {
    296      1.1  haya     panic("cardslot_enevt");
    297      1.1  haya   }
    298      1.1  haya 
    299      1.1  haya   ce->ce_type = ev;
    300      1.1  haya 
    301      1.1  haya   {
    302      1.1  haya     int s = spltty();
    303      1.1  haya     SIMPLEQ_INSERT_TAIL(&sc->sc_events, ce, ce_q);
    304      1.1  haya     splx(s);
    305      1.1  haya   }
    306      1.1  haya 
    307      1.1  haya   wakeup(&sc->sc_events);
    308      1.1  haya 
    309      1.1  haya   return;
    310      1.1  haya }
    311      1.1  haya 
    312      1.1  haya 
    313      1.1  haya /*
    314      1.1  haya  * static void cardslot_event_thread(void *arg)
    315      1.1  haya  *
    316      1.1  haya  *   This function is the main routine handing cardslot events such as
    317      1.1  haya  *   insertions and removals.
    318      1.1  haya  *
    319      1.1  haya  */
    320      1.1  haya static void
    321      1.1  haya cardslot_event_thread(arg)
    322      1.1  haya      void *arg;
    323      1.1  haya {
    324      1.1  haya   struct cardslot_softc *sc = arg;
    325      1.1  haya   struct cardslot_event *ce;
    326      1.1  haya   int s;
    327      1.1  haya   static int antonym_ev[4] = {
    328      1.1  haya     CARDSLOT_EVENT_REMOVAL_16, CARDSLOT_EVENT_INSERTION_16,
    329      1.1  haya     CARDSLOT_EVENT_REMOVAL_CB, CARDSLOT_EVENT_INSERTION_CB
    330      1.1  haya   };
    331      1.1  haya 
    332      1.1  haya   while (sc->sc_th_enable) {
    333      1.1  haya     s = spltty();
    334      1.1  haya     if ((ce = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    335      1.1  haya       splx(s);
    336      1.1  haya       (void) tsleep(&sc->sc_events, PWAIT, "cardslotev", 0);
    337      1.1  haya       continue;
    338      1.1  haya     }
    339      1.1  haya     SIMPLEQ_REMOVE_HEAD(&sc->sc_events, ce, ce_q);
    340      1.1  haya     splx(s);
    341      1.1  haya 
    342      1.1  haya     if (IS_CARDSLOT_INSERT_REMOVE_EV(ce->ce_type)) {
    343      1.1  haya       /* Chattering supression */
    344      1.1  haya       s = spltty();
    345      1.1  haya       while (1) {
    346      1.1  haya 	struct cardslot_event *ce1, *ce2;
    347      1.1  haya 
    348      1.1  haya 	if ((ce1 = SIMPLEQ_FIRST(&sc->sc_events)) == NULL) {
    349      1.1  haya 	  break;
    350      1.1  haya 	}
    351      1.1  haya 	if (ce1->ce_type != antonym_ev[ce->ce_type]) {
    352      1.1  haya 	  break;
    353      1.1  haya 	}
    354      1.1  haya 	if ((ce2 = SIMPLEQ_NEXT(ce1, ce_q)) == NULL) {
    355      1.1  haya 	  break;
    356      1.1  haya 	}
    357      1.1  haya 	if (ce2->ce_type == ce->ce_type) {
    358      1.1  haya 	  SIMPLEQ_REMOVE_HEAD(&sc->sc_events, ce1, ce_q);
    359      1.1  haya 	  free(ce1, M_TEMP);
    360      1.1  haya 	  SIMPLEQ_REMOVE_HEAD(&sc->sc_events, ce2, ce_q);
    361      1.1  haya 	  free(ce2, M_TEMP);
    362      1.1  haya 	}
    363      1.1  haya       }
    364      1.1  haya       splx(s);
    365      1.1  haya     }
    366      1.1  haya 
    367      1.1  haya     switch (ce->ce_type) {
    368      1.1  haya     case CARDSLOT_EVENT_INSERTION_CB:
    369      1.1  haya       if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_NONE) {
    370      1.1  haya 	/* A card has already been inserted. */
    371      1.1  haya 	break;
    372      1.1  haya       }
    373      1.1  haya       if (sc->sc_cb_softc) {
    374      1.1  haya 	cardbus_attach_card(sc->sc_cb_softc);
    375      1.1  haya 	CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_CB);
    376      1.1  haya       } else {
    377      1.1  haya 	panic("no cardbus on %s", sc->sc_dev.dv_xname);
    378      1.1  haya       }
    379      1.1  haya 
    380      1.1  haya       break;
    381      1.1  haya 
    382      1.1  haya     case CARDSLOT_EVENT_INSERTION_16:
    383      1.1  haya       if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_NONE) {
    384      1.1  haya 	/* A card has already been inserted. */
    385      1.1  haya 	break;
    386      1.1  haya       }
    387      1.1  haya       if (sc->sc_16_softc) {
    388      1.1  haya 	pcmcia_card_attach((struct device *)sc->sc_16_softc);
    389      1.1  haya 	CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_16);
    390      1.1  haya       } else {
    391      1.1  haya 	panic("no 16-bit pcmcia on %s", sc->sc_dev.dv_xname);
    392      1.1  haya       }
    393      1.1  haya 
    394      1.1  haya       break;
    395      1.1  haya 
    396      1.1  haya     case CARDSLOT_EVENT_REMOVAL_CB:
    397      1.1  haya       if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_CB) {
    398      1.1  haya 	/* CardBus card has not been inserted. */
    399      1.1  haya 	break;
    400      1.1  haya       }
    401      1.1  haya 				/* not yet */
    402      1.1  haya       CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_NONE);
    403      1.1  haya       break;
    404      1.1  haya 
    405      1.1  haya     case CARDSLOT_EVENT_REMOVAL_16:
    406      1.1  haya       DPRINTF(("%s: removal event\n", sc->sc_dev.dv_xname));
    407      1.1  haya       if (CARDSLOT_CARDTYPE(sc->sc_status) != CARDSLOT_STATUS_CARD_16) {
    408      1.1  haya 	/* 16-bit card has not been inserted. */
    409      1.1  haya 	break;
    410      1.1  haya       }
    411      1.1  haya       if (sc->sc_16_softc) {
    412      1.1  haya 	struct pcmcia_softc *psc = sc->sc_16_softc;
    413      1.1  haya 
    414      1.1  haya 	pcmcia_card_deactivate((struct device *)psc);
    415      1.1  haya 	pcmcia_chip_socket_disable(psc->pct, psc->pch);
    416      1.1  haya 	pcmcia_card_detach((struct device *)psc, DETACH_FORCE);
    417      1.1  haya 	CARDSLOT_SET_CARDTYPE(sc->sc_status, CARDSLOT_STATUS_CARD_NONE);
    418      1.1  haya       }
    419      1.1  haya       break;
    420      1.1  haya 
    421      1.1  haya     default:
    422      1.1  haya       panic("cardslot_event_thread: unknown event %d", ce->ce_type);
    423      1.1  haya     }
    424      1.1  haya     free(ce, M_TEMP);
    425      1.1  haya   }
    426      1.1  haya 
    427      1.1  haya   sc->sc_event_thread = NULL;
    428      1.1  haya 
    429      1.1  haya   /* In case parent is waiting for us to exit. */
    430      1.1  haya   wakeup(sc);
    431      1.1  haya 
    432      1.1  haya   kthread_exit(0);
    433      1.1  haya }
    434