diff --git a/sys/dev/ata/ata.c b/sys/dev/ata/ata.c index ef05b90f1c8c..3cda4e85e850 100644 --- a/sys/dev/ata/ata.c +++ b/sys/dev/ata/ata.c @@ -1,4 +1,4 @@ -/* $NetBSD: ata.c,v 1.114 2011/04/18 01:47:28 rmind Exp $ */ +/* $NetBSD: ata.c,v 1.115 2011/04/30 00:34:03 jakllsch Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -25,7 +25,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.114 2011/04/18 01:47:28 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.115 2011/04/30 00:34:03 jakllsch Exp $"); #include "opt_ata.h" @@ -105,6 +105,7 @@ const struct cdevsw atabus_cdevsw = { extern struct cfdriver atabus_cd; static void atabus_childdetached(device_t, device_t); +static int atabus_rescan(device_t, const char *, const int *); static bool atabus_resume(device_t, const pmf_qual_t *); static bool atabus_suspend(device_t, const pmf_qual_t *); static void atabusconfig_thread(void *); @@ -396,6 +397,10 @@ atabus_thread(void *arg) if (chp->ch_flags & ATACH_SHUTDOWN) { break; } + if (chp->ch_flags & ATACH_TH_RESCAN) { + atabusconfig(sc); + chp->ch_flags &= ~ATACH_TH_RESCAN; + } if (chp->ch_flags & ATACH_TH_RESET) { /* * ata_reset_channel() will freeze 2 times, so @@ -585,7 +590,7 @@ atabus_childdetached(device_t self, device_t child) } CFATTACH_DECL3_NEW(atabus, sizeof(struct atabus_softc), - atabus_match, atabus_attach, atabus_detach, NULL, NULL, + atabus_match, atabus_attach, atabus_detach, NULL, atabus_rescan, atabus_childdetached, DVF_DETACH_SHUTDOWN); /***************************************************************************** @@ -1560,3 +1565,39 @@ atabus_resume(device_t dv, const pmf_qual_t *qual) return true; } + +static int +atabus_rescan(device_t self, const char *ifattr, const int *locators) +{ + struct atabus_softc *sc = device_private(self); + struct ata_channel *chp = sc->sc_chan; + struct atabus_initq *initq; + int i; + int s; + + if (chp->atapibus != NULL) { + return EBUSY; + } + + for (i = 0; i < ATA_MAXDRIVES; i++) { + if (chp->ata_drives[i] != NULL) { + return EBUSY; + } + } + + s = splbio(); + for (i = 0; i < ATA_MAXDRIVES; i++) { + chp->ch_drive[i].drive_flags = 0; + } + splx(s); + + initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK); + initq->atabus_sc = sc; + TAILQ_INSERT_TAIL(&atabus_initq_head, initq, atabus_initq); + config_pending_incr(); + + chp->ch_flags |= ATACH_TH_RESCAN; + wakeup(&chp->ch_thread); + + return 0; +} diff --git a/sys/dev/ata/atavar.h b/sys/dev/ata/atavar.h index f0779c68e7e2..412738ceec01 100644 --- a/sys/dev/ata/atavar.h +++ b/sys/dev/ata/atavar.h @@ -1,4 +1,4 @@ -/* $NetBSD: atavar.h,v 1.81 2011/04/18 01:47:28 rmind Exp $ */ +/* $NetBSD: atavar.h,v 1.82 2011/04/30 00:34:03 jakllsch Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. @@ -331,6 +331,7 @@ struct ata_channel { #define ATACH_DISABLED 0x80 /* channel is disabled */ #define ATACH_TH_RUN 0x100 /* the kernel thread is working */ #define ATACH_TH_RESET 0x200 /* someone ask the thread to reset */ +#define ATACH_TH_RESCAN 0x400 /* rescan requested */ u_int8_t ch_status; /* copy of status register */ u_int8_t ch_error; /* copy of error register */