2 * Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/endian.h>
41 #include <sys/malloc.h>
42 #include <sys/mutex.h>
43 #include <sys/sysctl.h>
44 #include <sys/taskqueue.h>
45 #include <machine/stdarg.h>
46 #include <machine/resource.h>
47 #include <machine/bus.h>
50 #include <machine/md_var.h>
52 #include <geom/geom_disk.h>
53 #include <dev/ata/ata-all.h>
54 #include <dev/ata/ata-disk.h>
55 #include <dev/ata/ata-raid.h>
57 /* device structures */
58 static d_ioctl_t ata_ioctl;
59 static struct cdevsw ata_cdevsw = {
68 static void ata_shutdown(void *arg, int howto);
69 static int ata_getparam(struct ata_device *atadev, u_int8_t command);
70 static void ata_identify_devices(struct ata_channel *ch);
71 static void ata_boot_attach(void);
72 static void bswap(int8_t *buf, int len);
73 static void btrim(int8_t *buf, int len);
74 static void bpack(int8_t *src, int8_t *dst, int len);
75 static void ata_init(void);
78 SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters");
79 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
80 TUNABLE_INT("hw.ata.wc", &ata_wc);
81 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
87 struct intr_config_hook *ata_delayed_attach = NULL;
88 devclass_t ata_devclass;
91 static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer");
94 * newbus device interface related functions
97 ata_probe(device_t dev)
99 struct ata_channel *ch;
101 if (!dev || !(ch = device_get_softc(dev)))
107 /* initialize the softc basics */
109 ch->device[MASTER].channel = ch;
110 ch->device[MASTER].unit = ATA_MASTER;
111 ch->device[MASTER].mode = ATA_PIO;
112 ch->device[SLAVE].channel = ch;
113 ch->device[SLAVE].unit = ATA_SLAVE;
114 ch->device[SLAVE].mode = ATA_PIO;
116 ch->state = ATA_IDLE;
117 bzero(&ch->queue_mtx, sizeof(struct mtx));
118 mtx_init(&ch->queue_mtx, "ATA queue lock", MTX_DEF, 0);
119 TAILQ_INIT(&ch->ata_queue);
121 /* initialise device(s) on this channel */
122 ch->locking(ch, ATA_LF_LOCK);
124 ch->locking(ch, ATA_LF_UNLOCK);
129 ata_attach(device_t dev)
131 struct ata_channel *ch;
134 if (!dev || !(ch = device_get_softc(dev)))
138 ch->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
139 RF_SHAREABLE | RF_ACTIVE);
141 ata_printf(ch, -1, "unable to allocate interrupt\n");
144 if ((error = bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS,
145 ch->hw.interrupt, ch, &ch->ih))) {
146 ata_printf(ch, -1, "unable to setup interrupt\n");
153 /* do not attach devices if we are in early boot */
154 if (ata_delayed_attach)
157 ata_identify_devices(ch);
159 if (ch->device[MASTER].attach)
160 ch->device[MASTER].attach(&ch->device[MASTER]);
161 if (ch->device[SLAVE].attach)
162 ch->device[SLAVE].attach(&ch->device[SLAVE]);
164 atapi_cam_attach_bus(ch);
170 ata_detach(device_t dev)
172 struct ata_channel *ch;
173 struct ata_request *request;
175 if (!dev || !(ch = device_get_softc(dev)) || !ch->r_irq)
178 /* detach devices on this channel */
179 if (ch->device[MASTER].detach)
180 ch->device[MASTER].detach(&ch->device[MASTER]);
181 if (ch->device[SLAVE].detach)
182 ch->device[SLAVE].detach(&ch->device[SLAVE]);
184 atapi_cam_detach_bus(ch);
187 /* fail outstanding requests on this channel */
188 mtx_lock(&ch->queue_mtx);
189 while ((request = TAILQ_FIRST(&ch->ata_queue))) {
190 TAILQ_REMOVE(&ch->ata_queue, request, chain);
191 request->status = ATA_S_ERROR;
192 mtx_unlock(&ch->queue_mtx);
194 mtx_lock(&ch->queue_mtx);
196 mtx_unlock(&ch->queue_mtx);
198 if (ch->device[MASTER].param) {
199 ata_controlcmd(&ch->device[MASTER], ATA_FLUSHCACHE, 0, 0, 0);
200 free(ch->device[MASTER].param, M_ATA);
201 ch->device[MASTER].param = NULL;
203 if (ch->device[SLAVE].param) {
204 ata_controlcmd(&ch->device[SLAVE], ATA_FLUSHCACHE, 0, 0, 0);
205 free(ch->device[SLAVE].param, M_ATA);
206 ch->device[SLAVE].param = NULL;
208 ch->device[MASTER].mode = ATA_PIO;
209 ch->device[SLAVE].mode = ATA_PIO;
215 bus_teardown_intr(dev, ch->r_irq, ch->ih);
216 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
222 ata_reinit(struct ata_channel *ch)
224 int devices, misdev, newdev;
230 ata_printf(ch, -1, "resetting devices ..\n");
231 ATA_FORCELOCK_CH(ch, ATA_CONTROL);
233 devices = ch->devices;
237 /* detach what left the channel during reset */
238 if ((misdev = devices & ~ch->devices)) {
239 if ((misdev & (ATA_ATA_MASTER | ATA_ATAPI_MASTER)) &&
240 ch->device[MASTER].detach)
241 ch->device[MASTER].detach(&ch->device[MASTER]);
242 if ((misdev & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE)) &&
243 ch->device[SLAVE].detach)
244 ch->device[SLAVE].detach(&ch->device[SLAVE]);
247 /* identify whats present on this channel now */
248 ata_identify_devices(ch);
250 /* attach new devices that appeared during reset */
251 if ((newdev = ~devices & ch->devices)) {
252 if ((newdev & (ATA_ATA_MASTER | ATA_ATAPI_MASTER)) &&
253 ch->device[MASTER].attach)
254 ch->device[MASTER].attach(&ch->device[MASTER]);
255 if ((newdev & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE)) &&
256 ch->device[SLAVE].attach)
257 ch->device[SLAVE].attach(&ch->device[SLAVE]);
260 atapi_cam_reinit_bus(ch);
268 ata_suspend(device_t dev)
270 struct ata_channel *ch;
272 if (!dev || !(ch = device_get_softc(dev)))
275 ch->locking(ch, ATA_LF_LOCK);
276 ATA_SLEEPLOCK_CH(ch, ATA_CONTROL);
281 ata_resume(device_t dev)
283 struct ata_channel *ch;
286 if (!dev || !(ch = device_get_softc(dev)))
289 ch->locking(ch, ATA_LF_LOCK);
290 error = ata_reinit(ch);
291 ch->locking(ch, ATA_LF_UNLOCK);
297 ata_shutdown(void *arg, int howto)
299 struct ata_channel *ch;
302 /* flush cache on all devices */
303 for (ctlr = 0; ctlr < devclass_get_maxunit(ata_devclass); ctlr++) {
304 if (!(ch = devclass_get_softc(ata_devclass, ctlr)))
306 if (ch->device[MASTER].param)
307 ata_controlcmd(&ch->device[MASTER], ATA_FLUSHCACHE, 0, 0, 0);
308 if (ch->device[SLAVE].param)
309 ata_controlcmd(&ch->device[SLAVE], ATA_FLUSHCACHE, 0, 0, 0);
314 * device related interfaces
317 ata_ioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td)
319 struct ata_cmd *iocmd = (struct ata_cmd *)addr;
320 device_t device = devclass_get_device(ata_devclass, iocmd->channel);
321 struct ata_channel *ch;
322 struct ata_device *atadev;
323 struct ata_request *request;
328 switch (iocmd->cmd) {
330 iocmd->u.maxchan = devclass_get_maxunit(ata_devclass);
335 if (!device || !(ch = device_get_softc(device))) {
339 iocmd->u.param.type[MASTER] =
340 ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER);
341 iocmd->u.param.type[SLAVE] =
342 ch->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE);
343 if (ch->device[MASTER].name)
344 strcpy(iocmd->u.param.name[MASTER], ch->device[MASTER].name);
345 if (ch->device[SLAVE].name)
346 strcpy(iocmd->u.param.name[SLAVE], ch->device[SLAVE].name);
347 if (ch->device[MASTER].param)
348 bcopy(ch->device[MASTER].param, &iocmd->u.param.params[MASTER],
349 sizeof(struct ata_params));
350 if (ch->device[SLAVE].param)
351 bcopy(ch->device[SLAVE].param, &iocmd->u.param.params[SLAVE],
352 sizeof(struct ata_params));
357 if (!device || !(ch = device_get_softc(device))) {
361 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode;
362 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode;
367 if (!device || !(ch = device_get_softc(device))) {
371 if (iocmd->u.mode.mode[MASTER] >= 0 && ch->device[MASTER].param)
372 ch->device[MASTER].setmode(&ch->device[MASTER],
373 iocmd->u.mode.mode[MASTER]);
374 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode;
375 if (iocmd->u.mode.mode[SLAVE] >= 0 && ch->device[SLAVE].param)
376 ch->device[SLAVE].setmode(&ch->device[SLAVE],
377 iocmd->u.mode.mode[SLAVE]);
378 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode;
383 if (!device || !(ch = device_get_softc(device))) {
387 if (!(atadev = &ch->device[iocmd->device])) {
391 if (!(buf = malloc(iocmd->u.request.count, M_ATA, M_NOWAIT))) {
395 if (!(request = ata_alloc_request())) {
400 if (iocmd->u.request.flags & ATA_CMD_WRITE) {
401 error = copyin(iocmd->u.request.data, buf, iocmd->u.request.count);
404 ata_free_request(request);
409 request->device = atadev;
411 if (iocmd->u.request.flags & ATA_CMD_ATAPI) {
412 request->flags = ATA_R_ATAPI;
413 bcopy(iocmd->u.request.u.atapi.ccb, request->u.atapi.ccb, 16);
416 request->u.ata.command = iocmd->u.request.u.ata.command;
417 request->u.ata.feature = iocmd->u.request.u.ata.feature;
418 request->u.ata.lba = iocmd->u.request.u.ata.lba;
419 request->u.ata.count = iocmd->u.request.u.ata.count;
422 request->timeout = iocmd->u.request.timeout;
424 request->bytecount = iocmd->u.request.count;
425 request->transfersize = request->bytecount;
427 if (iocmd->u.request.flags & ATA_CMD_CONTROL)
428 request->flags |= ATA_R_CONTROL;
429 if (iocmd->u.request.flags & ATA_CMD_READ)
430 request->flags |= ATA_R_READ;
431 if (iocmd->u.request.flags & ATA_CMD_WRITE)
432 request->flags |= ATA_R_WRITE;
434 ata_queue_request(request);
437 iocmd->u.request.error = request->error;
439 if (iocmd->u.request.flags & ATA_CMD_READ)
441 iocmd->u.request.data, iocmd->u.request.count);
446 ata_free_request(request);
450 if (!device || !(ch = device_get_softc(device)))
452 error = ata_reinit(ch);
461 /* SOS should enable channel HW on controller XXX */
462 error = ata_probe(device);
464 error = ata_attach(device);
472 error = ata_detach(device);
473 /* SOS should disable channel HW on controller XXX */
479 error = ata_raid_create(&iocmd->u.raid_setup);
483 error = ata_raid_delete(iocmd->channel);
487 error = ata_raid_status(iocmd->channel, &iocmd->u.raid_status);
490 case ATARAIDADDSPARE:
491 error = ata_raid_addspare(iocmd->channel, iocmd->u.raid_spare.disk);
495 error = ata_raid_rebuild(iocmd->channel);
504 * device probe functions
507 ata_getparam(struct ata_device *atadev, u_int8_t command)
509 struct ata_params *atacap;
510 struct ata_request *request;
514 atacap = atadev->param;
516 atacap = malloc(sizeof(struct ata_params), M_ATA, M_NOWAIT);
518 request = ata_alloc_request();
520 request->device = atadev;
521 request->u.ata.command = command;
522 request->flags = ATA_R_READ;
523 request->data = (caddr_t)atacap;
524 request->timeout = 2;
525 request->retries = 2;
526 request->bytecount = sizeof(struct ata_params);
527 request->transfersize = DEV_BSIZE;
528 ata_queue_request(request);
529 error = request->result;
530 ata_free_request(request);
533 atadev->param = NULL;
537 #if BYTE_ORDER == BIG_ENDIAN
540 for (ptr = (int16_t *)atacap;
541 ptr < (int16_t *)atacap + sizeof(struct ata_params)/2; ptr++) {
542 *ptr = bswap16(*ptr);
545 if (!((atacap->model[0] == 'N' && atacap->model[1] == 'E') ||
546 (atacap->model[0] == 'F' && atacap->model[1] == 'X') ||
547 (atacap->model[0] == 'P' && atacap->model[1] == 'i')))
548 bswap(atacap->model, sizeof(atacap->model));
549 btrim(atacap->model, sizeof(atacap->model));
550 bpack(atacap->model, atacap->model, sizeof(atacap->model));
551 bswap(atacap->revision, sizeof(atacap->revision));
552 btrim(atacap->revision, sizeof(atacap->revision));
553 bpack(atacap->revision, atacap->revision, sizeof(atacap->revision));
554 bswap(atacap->serial, sizeof(atacap->serial));
555 btrim(atacap->serial, sizeof(atacap->serial));
556 bpack(atacap->serial, atacap->serial, sizeof(atacap->serial));
557 atadev->param = atacap;
560 "pio=0x%02x wdma=0x%02x udma=0x%02x cable=%spin\n",
561 ata_pmode(atacap), ata_wmode(atacap),
563 (atacap->hwres & ATA_CABLE_ID) ? "80":"40");
570 ata_identify_devices(struct ata_channel *ch)
572 if (ch->devices & ATA_ATA_SLAVE) {
573 if (ata_getparam(&ch->device[SLAVE], ATA_ATA_IDENTIFY))
574 ch->devices &= ~ATA_ATA_SLAVE;
577 ch->device[SLAVE].attach = ad_attach;
580 if (ch->devices & ATA_ATAPI_SLAVE) {
581 if (ata_getparam(&ch->device[SLAVE], ATA_ATAPI_IDENTIFY))
582 ch->devices &= ~ATA_ATAPI_SLAVE;
584 switch (ch->device[SLAVE].param->config & ATA_ATAPI_TYPE_MASK) {
586 case ATA_ATAPI_TYPE_CDROM:
587 ch->device[SLAVE].attach = acd_attach;
591 case ATA_ATAPI_TYPE_DIRECT:
592 ch->device[SLAVE].attach = afd_attach;
596 case ATA_ATAPI_TYPE_TAPE:
597 ch->device[SLAVE].attach = ast_attach;
603 if (ch->devices & ATA_ATA_MASTER) {
604 if (ata_getparam(&ch->device[MASTER], ATA_ATA_IDENTIFY))
605 ch->devices &= ~ATA_ATA_MASTER;
608 ch->device[MASTER].attach = ad_attach;
611 if (ch->devices & ATA_ATAPI_MASTER) {
612 if (ata_getparam(&ch->device[MASTER], ATA_ATAPI_IDENTIFY))
613 ch->devices &= ~ATA_ATAPI_MASTER;
615 switch (ch->device[MASTER].param->config & ATA_ATAPI_TYPE_MASK) {
617 case ATA_ATAPI_TYPE_CDROM:
618 ch->device[MASTER].attach = acd_attach;
622 case ATA_ATAPI_TYPE_DIRECT:
623 ch->device[MASTER].attach = afd_attach;
627 case ATA_ATAPI_TYPE_TAPE:
628 ch->device[MASTER].attach = ast_attach;
637 ata_boot_attach(void)
639 struct ata_channel *ch;
643 * run through all ata devices and look for real ATA & ATAPI devices
644 * using the hints we found in the early probe, this avoids some of
645 * the delays probing of non-exsistent devices can cause.
647 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
648 if (!(ch = devclass_get_softc(ata_devclass, ctlr)))
650 ata_identify_devices(ch);
651 if (ch->device[MASTER].attach)
652 ch->device[MASTER].attach(&ch->device[MASTER]);
653 if (ch->device[SLAVE].attach)
654 ch->device[SLAVE].attach(&ch->device[SLAVE]);
656 atapi_cam_attach_bus(ch);
662 if (ata_delayed_attach) {
663 config_intrhook_disestablish(ata_delayed_attach);
664 free(ata_delayed_attach, M_TEMP);
665 ata_delayed_attach = NULL;
670 * misc support functions
673 bswap(int8_t *buf, int len)
675 u_int16_t *ptr = (u_int16_t*)(buf + len);
677 while (--ptr >= (u_int16_t*)buf)
682 btrim(int8_t *buf, int len)
686 for (ptr = buf; ptr < buf+len; ++ptr)
689 for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
694 bpack(int8_t *src, int8_t *dst, int len)
698 for (i = j = blank = 0 ; i < len; i++) {
699 if (blank && src[i] == ' ') continue;
700 if (blank && src[i] != ' ') {
717 ata_printf(struct ata_channel *ch, int device, const char * fmt, ...)
723 ret = printf("ata%d: ", device_get_unit(ch->dev));
725 if (ch->device[ATA_DEV(device)].name)
726 ret = printf("%s: ", ch->device[ATA_DEV(device)].name);
728 ret = printf("ata%d-%s: ", device_get_unit(ch->dev),
729 (device == ATA_MASTER) ? "master" : "slave");
732 ret += vprintf(fmt, ap);
738 ata_prtdev(struct ata_device *atadev, const char * fmt, ...)
744 ret = printf("%s: ", atadev->name);
746 ret = printf("ata%d-%s: ", device_get_unit(atadev->channel->dev),
747 (atadev->unit == ATA_MASTER) ? "master" : "slave");
749 ret += vprintf(fmt, ap);
755 ata_set_name(struct ata_device *atadev, char *name, int lun)
757 atadev->name = malloc(strlen(name) + 4, M_ATA, M_NOWAIT);
759 sprintf(atadev->name, "%s%d", name, lun);
763 ata_free_name(struct ata_device *atadev)
766 free(atadev->name, M_ATA);
771 ata_get_lun(u_int32_t *map)
773 int lun = ffs(~*map) - 1;
780 ata_test_lun(u_int32_t *map, int lun)
782 return (*map & (1 << lun));
786 ata_free_lun(u_int32_t *map, int lun)
792 ata_mode2str(int mode)
795 case ATA_PIO: return "BIOSPIO";
796 case ATA_PIO0: return "PIO0";
797 case ATA_PIO1: return "PIO1";
798 case ATA_PIO2: return "PIO2";
799 case ATA_PIO3: return "PIO3";
800 case ATA_PIO4: return "PIO4";
801 case ATA_DMA: return "BIOSDMA";
802 case ATA_WDMA0: return "WDMA0";
803 case ATA_WDMA1: return "WDMA1";
804 case ATA_WDMA2: return "WDMA2";
805 case ATA_UDMA0: return "UDMA16";
806 case ATA_UDMA1: return "UDMA25";
807 case ATA_UDMA2: return "UDMA33";
808 case ATA_UDMA3: return "UDMA40";
809 case ATA_UDMA4: return "UDMA66";
810 case ATA_UDMA5: return "UDMA100";
811 case ATA_UDMA6: return "UDMA133";
812 case ATA_SA150: return "SATA150";
813 default: return "???";
818 ata_pmode(struct ata_params *ap)
820 if (ap->atavalid & ATA_FLAG_64_70) {
821 if (ap->apiomodes & 0x02)
823 if (ap->apiomodes & 0x01)
826 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 2)
828 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 1)
830 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0)
832 if (ap->capabilities1 & ATA_SUPPORT_DMA)
838 ata_wmode(struct ata_params *ap)
840 if (ap->mwdmamodes & 0x04)
842 if (ap->mwdmamodes & 0x02)
844 if (ap->mwdmamodes & 0x01)
846 if (ap->capabilities1 & ATA_SUPPORT_DMA)
852 ata_umode(struct ata_params *ap)
854 if (ap->atavalid & ATA_FLAG_88) {
855 if (ap->udmamodes & 0x40)
857 if (ap->udmamodes & 0x20)
859 if (ap->udmamodes & 0x10)
861 if (ap->udmamodes & 0x08)
863 if (ap->udmamodes & 0x04)
865 if (ap->udmamodes & 0x02)
867 if (ap->udmamodes & 0x01)
874 ata_limit_mode(struct ata_device *atadev, int mode, int maxmode)
876 if (maxmode && mode > maxmode)
879 if (mode >= ATA_UDMA0 && ata_umode(atadev->param) > 0)
880 return min(mode, ata_umode(atadev->param));
882 if (mode >= ATA_WDMA0 && ata_wmode(atadev->param) > 0)
883 return min(mode, ata_wmode(atadev->param));
885 if (mode > ata_pmode(atadev->param))
886 return min(mode, ata_pmode(atadev->param));
894 /* register controlling device */
895 make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata");
897 /* register boot attach to be run when interrupts are enabled */
898 if (!(ata_delayed_attach = (struct intr_config_hook *)
899 malloc(sizeof(struct intr_config_hook),
900 M_TEMP, M_NOWAIT | M_ZERO))) {
901 printf("ata: malloc of delayed attach hook failed\n");
905 ata_delayed_attach->ich_func = (void*)ata_boot_attach;
906 if (config_intrhook_establish(ata_delayed_attach) != 0) {
907 printf("ata: config_intrhook_establish failed\n");
908 free(ata_delayed_attach, M_TEMP);
910 /* Register a handler to flush write caches on shutdown */
911 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, ata_shutdown,
912 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
913 printf("ata: shutdown event registration failed!\n");
916 SYSINIT(atadev, SI_SUB_DRIVERS, SI_ORDER_SECOND, ata_init, NULL)