Lines Matching +full:ata +full:- +full:generic

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
33 #include <sys/ata.h>
50 #include <dev/ata/ata-all.h>
51 #include <dev/ata/ata-pci.h>
54 MALLOC_DEFINE(M_ATAPCI, "ata_pci", "ATA driver PCI");
60 * generic PCI ATA device probe
71 /* is this an IDE/ATA type device ? */ in ata_pci_probe()
75 device_set_descf(dev, "%s ATA controller", ata_pcivendor2str(dev)); in ata_pci_probe()
76 ctlr->chipinit = ata_generic_chipinit; in ata_pci_probe()
91 ctlr->legacy = ata_legacy(dev); in ata_pci_attach()
92 if (ctlr->legacy || pci_read_config(dev, PCIR_BAR(2), 4) & IOMASK) in ata_pci_attach()
93 ctlr->channels = 2; in ata_pci_attach()
95 ctlr->channels = 1; in ata_pci_attach()
96 ctlr->ichannels = -1; in ata_pci_attach()
97 ctlr->ch_attach = ata_pci_ch_attach; in ata_pci_attach()
98 ctlr->ch_detach = ata_pci_ch_detach; in ata_pci_attach()
99 ctlr->dev = dev; in ata_pci_attach()
107 ctlr->r_type1 = SYS_RES_IOPORT; in ata_pci_attach()
108 ctlr->r_rid1 = ATA_BMADDR_RID; in ata_pci_attach()
109 ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1, &ctlr->r_rid1, in ata_pci_attach()
113 if (ctlr->chipinit(dev)) { in ata_pci_attach()
114 if (ctlr->r_res1) in ata_pci_attach()
115 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, in ata_pci_attach()
116 ctlr->r_res1); in ata_pci_attach()
121 for (unit = 0; unit < ctlr->channels; unit++) { in ata_pci_attach()
122 if ((ctlr->ichannels & (1 << unit)) == 0) in ata_pci_attach()
124 child = device_add_child(dev, "ata", in ata_pci_attach()
125 ((unit == 0 || unit == 1) && ctlr->legacy) ? in ata_pci_attach()
128 device_printf(dev, "failed to add ata child device\n"); in ata_pci_attach()
147 if (ctlr->r_irq) { in ata_pci_detach()
148 bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle); in ata_pci_detach()
149 bus_release_resource(dev, SYS_RES_IRQ, ctlr->r_irq_rid, ctlr->r_irq); in ata_pci_detach()
150 if (ctlr->r_irq_rid != ATA_IRQ_RID) in ata_pci_detach()
153 if (ctlr->chipdeinit != NULL) in ata_pci_detach()
154 ctlr->chipdeinit(dev); in ata_pci_detach()
155 if (ctlr->r_res2) { in ata_pci_detach()
156 bus_release_resource(dev, ctlr->r_type2, ctlr->r_rid2, ctlr->r_res2); in ata_pci_detach()
158 if (ctlr->r_res1) { in ata_pci_detach()
159 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, ctlr->r_res1); in ata_pci_detach()
172 if (ctlr->suspend) in ata_pci_suspend()
173 error = ctlr->suspend(dev); in ata_pci_suspend()
183 if (ctlr->resume) in ata_pci_resume()
184 error = ctlr->resume(dev); in ata_pci_resume()
227 int unit = ((struct ata_channel *)device_get_softc(child))->unit; in ata_pci_alloc_resource()
233 if (controller->legacy) { in ata_pci_alloc_resource()
236 end = start + count - 1; in ata_pci_alloc_resource()
244 if (controller->legacy) { in ata_pci_alloc_resource()
248 end = start + count - 1; in ata_pci_alloc_resource()
258 if (controller->legacy) { in ata_pci_alloc_resource()
264 res = controller->r_irq; in ata_pci_alloc_resource()
270 res = controller->r_irq; in ata_pci_alloc_resource()
301 if (controller->legacy) { in ata_pci_release_resource()
327 if (controller->legacy) { in ata_pci_setup_intr()
335 printf("ata-pci.c: we cannot use a filter here\n"); in ata_pci_setup_intr()
339 unit = ((struct ata_channel *)device_get_softc(child))->unit; in ata_pci_setup_intr()
341 unit = ATA_PCI_MAX_CH - 1; in ata_pci_setup_intr()
342 controller->interrupt[unit].function = function; in ata_pci_setup_intr()
343 controller->interrupt[unit].argument = argument; in ata_pci_setup_intr()
355 if (controller->legacy) { in ata_pci_teardown_intr()
362 unit = ((struct ata_channel *)device_get_softc(child))->unit; in ata_pci_teardown_intr()
364 unit = ATA_PCI_MAX_CH - 1; in ata_pci_teardown_intr()
365 controller->interrupt[unit].function = NULL; in ata_pci_teardown_intr()
366 controller->interrupt[unit].argument = NULL; in ata_pci_teardown_intr()
385 ctlr->setmode = ata_generic_setmode; in ata_generic_chipinit()
410 ch->r_io[i].res = io; in ata_pci_ch_attach()
411 ch->r_io[i].offset = i; in ata_pci_ch_attach()
413 ch->r_io[ATA_CONTROL].res = ctlio; in ata_pci_ch_attach()
414 ch->r_io[ATA_CONTROL].offset = ctlr->legacy ? 0 : 2; in ata_pci_ch_attach()
415 ch->r_io[ATA_IDX_ADDR].res = io; in ata_pci_ch_attach()
417 if (ctlr->r_res1) { in ata_pci_ch_attach()
419 ch->r_io[i].res = ctlr->r_res1; in ata_pci_ch_attach()
420 ch->r_io[i].offset = (i - ATA_BMCMD_PORT) + (ch->unit*ATA_BMIOSIZE); in ata_pci_ch_attach()
436 ch->r_io[ATA_CONTROL].res); in ata_pci_ch_detach()
438 ch->r_io[ATA_IDX_ADDR].res); in ata_pci_ch_detach()
450 if ((dumping || !controller->legacy) && in ata_pci_status()
451 ((ch->flags & ATA_ALWAYS_DMASTAT) || in ata_pci_status()
452 (ch->dma.flags & ATA_DMA_ACTIVE))) { in ata_pci_status()
474 ch->hw.status = ata_pci_status; in ata_pci_hw()
480 struct ata_channel *ch = device_get_softc(request->parent); in ata_pci_dmastart()
486 ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, request->dma->sg_bus); in ata_pci_dmastart()
487 ch->dma.flags |= ATA_DMA_ACTIVE; in ata_pci_dmastart()
490 ((request->flags & ATA_R_READ) ? ATA_BMCMD_WRITE_READ : 0)| in ata_pci_dmastart()
498 struct ata_channel *ch = device_get_softc(request->parent); in ata_pci_dmastop()
505 ch->dma.flags &= ~ATA_DMA_ACTIVE; in ata_pci_dmastop()
519 ch->dma.flags &= ~ATA_DMA_ACTIVE; in ata_pci_dmareset()
521 if ((request = ch->running)) { in ata_pci_dmareset()
523 ch->dma.unload(request); in ata_pci_dmareset()
533 ch->dma.start = ata_pci_dmastart; in ata_pci_dmainit()
534 ch->dma.stop = ata_pci_dmastop; in ata_pci_dmainit()
535 ch->dma.reset = ata_pci_dmareset; in ata_pci_dmainit()
609 MODULE_DEPEND(atapci, ata, 1, 1, 1);
617 device_set_desc(dev, "ATA channel"); in ata_pcichannel_probe()
629 if (ch->attached) in ata_pcichannel_attach()
631 ch->attached = 1; in ata_pcichannel_attach()
633 ch->dev = dev; in ata_pcichannel_attach()
634 ch->unit = (intptr_t)device_get_ivars(dev); in ata_pcichannel_attach()
637 device_get_unit(dev), "pm_level", &ch->pm_level); in ata_pcichannel_attach()
639 if ((error = ctlr->ch_attach(dev))) in ata_pcichannel_attach()
652 if (!ch->attached) in ata_pcichannel_detach()
654 ch->attached = 0; in ata_pcichannel_detach()
659 if (ctlr->ch_detach) in ata_pcichannel_detach()
660 return (ctlr->ch_detach(dev)); in ata_pcichannel_detach()
671 if (!ch->attached) in ata_pcichannel_suspend()
677 if (ctlr->ch_suspend != NULL && (error = ctlr->ch_suspend(dev))) in ata_pcichannel_suspend()
690 if (!ch->attached) in ata_pcichannel_resume()
693 if (ctlr->ch_resume != NULL && (error = ctlr->ch_resume(dev))) in ata_pcichannel_resume()
706 if (ch->dma.reset) in ata_pcichannel_reset()
707 ch->dma.reset(dev); in ata_pcichannel_reset()
710 if (ctlr->reset) in ata_pcichannel_reset()
711 ctlr->reset(dev); in ata_pcichannel_reset()
721 if (ctlr->setmode) in ata_pcichannel_setmode()
722 return (ctlr->setmode(dev, target, mode)); in ata_pcichannel_setmode()
733 if (ch->flags & ATA_SATA) { in ata_pcichannel_getrev()
734 if (ctlr->getrev) in ata_pcichannel_getrev()
735 return (ctlr->getrev(dev, target)); in ata_pcichannel_getrev()
751 /* ATA methods */
760 "ata",
765 DRIVER_MODULE(ata, atapci, ata_pcichannel_driver, NULL, NULL);
793 if ((ch = ctlr->interrupt[unit].argument)) in ata_generic_intr()
794 ctlr->interrupt[unit].function(ch); in ata_generic_intr()
804 if (!ctlr->legacy) { in ata_setup_interrupt()
809 ctlr->r_irq_rid = 0x1; in ata_setup_interrupt()
812 ctlr->r_irq_rid = ATA_IRQ_RID; in ata_setup_interrupt()
814 if (!(ctlr->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, in ata_setup_interrupt()
815 &ctlr->r_irq_rid, RF_SHAREABLE | RF_ACTIVE))) { in ata_setup_interrupt()
821 if ((bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL, in ata_setup_interrupt()
822 intr_func, ctlr, &ctlr->handle))) { in ata_setup_interrupt()
825 SYS_RES_IRQ, ctlr->r_irq_rid, ctlr->r_irq); in ata_setup_interrupt()
840 ata_pcivendor2str(dev), ctlr->chip->text, in ata_set_desc()
841 ata_mode2str(ctlr->chip->max_dma)); in ata_set_desc()
852 while (index->chipid != 0) { in ata_match_chip()
853 if (devid == index->chipid && revid >= index->chiprev) in ata_match_chip()
873 if ((slot >= 0 && s == slot) || (slot < 0 && s <= -slot)) { in ata_find_chip()
912 default: return "Generic"; in ata_pcivendor2str()
923 return (mode & ATA_MODE_MASK) - ATA_PIO0; in ata_mode2idx()