Lines Matching refs:dev

28 __FBSDID("$FreeBSD: releng/11.0/sys/dev/ata/ata-pci.c 294883 2016-01-27 02:23:54Z jhibbits $");
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/ata/ata-all.h>
48 #include <dev/ata/ata-pci.h>
60 ata_pci_probe(device_t dev)
62 struct ata_pci_controller *ctlr = device_get_softc(dev);
66 if (pci_get_class(dev) != PCIC_STORAGE)
70 if (pci_get_subclass(dev) != PCIS_STORAGE_IDE)
73 sprintf(buffer, "%s ATA controller", ata_pcivendor2str(dev));
74 device_set_desc_copy(dev, buffer);
82 ata_pci_attach(device_t dev)
84 struct ata_pci_controller *ctlr = device_get_softc(dev);
90 ctlr->legacy = ata_legacy(dev);
91 if (ctlr->legacy || pci_read_config(dev, PCIR_BAR(2), 4) & IOMASK)
98 ctlr->dev = dev;
101 pci_enable_busmaster(dev);
102 cmd = pci_read_config(dev, PCIR_COMMAND, 2);
108 ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1, &ctlr->r_rid1,
112 if (ctlr->chipinit(dev))
119 child = device_add_child(dev, "ata",
123 device_printf(dev, "failed to add ata child device\n");
127 bus_generic_attach(dev);
132 ata_pci_detach(device_t dev)
134 struct ata_pci_controller *ctlr = device_get_softc(dev);
137 device_delete_children(dev);
140 bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle);
141 bus_release_resource(dev, SYS_RES_IRQ, ctlr->r_irq_rid, ctlr->r_irq);
143 pci_release_msi(dev);
146 ctlr->chipdeinit(dev);
152 bus_release_resource(dev, ctlr->r_type2, ctlr->r_rid2, ctlr->r_res2);
159 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, ctlr->r_res1);
166 ata_pci_suspend(device_t dev)
168 struct ata_pci_controller *ctlr = device_get_softc(dev);
171 bus_generic_suspend(dev);
173 error = ctlr->suspend(dev);
178 ata_pci_resume(device_t dev)
180 struct ata_pci_controller *ctlr = device_get_softc(dev);
184 error = ctlr->resume(dev);
185 bus_generic_resume(dev);
190 ata_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
193 return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result));
197 ata_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
200 return (BUS_WRITE_IVAR(device_get_parent(dev), dev, which, value));
204 ata_pci_read_config(device_t dev, device_t child, int reg, int width)
207 return (pci_read_config(dev, reg, width));
211 ata_pci_write_config(device_t dev, device_t child, int reg,
215 pci_write_config(dev, reg, val, width);
219 ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
223 struct ata_pci_controller *controller = device_get_softc(dev);
239 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
251 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
261 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
272 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
280 ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
285 struct ata_pci_controller *controller = device_get_softc(dev);
291 return BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
295 return BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
306 return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
317 return (BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
325 ata_pci_setup_intr(device_t dev, device_t child, struct resource *irq,
329 struct ata_pci_controller *controller = device_get_softc(dev);
332 return BUS_SETUP_INTR(device_get_parent(dev), child, irq,
335 struct ata_pci_controller *controller = device_get_softc(dev);
354 ata_pci_teardown_intr(device_t dev, device_t child, struct resource *irq,
357 struct ata_pci_controller *controller = device_get_softc(dev);
360 return BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq, cookie);
362 struct ata_pci_controller *controller = device_get_softc(dev);
376 ata_generic_setmode(device_t dev, int target, int mode)
383 ata_generic_chipinit(device_t dev)
385 struct ata_pci_controller *ctlr = device_get_softc(dev);
387 if (ata_setup_interrupt(dev, ata_generic_intr))
394 ata_pci_ch_attach(device_t dev)
396 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
397 struct ata_channel *ch = device_get_softc(dev);
402 if (!(io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)))
406 if (!(ctlio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,RF_ACTIVE))){
407 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
411 ata_pci_dmainit(dev);
420 ata_default_registers(dev);
428 ata_pci_hw(dev);
433 ata_pci_ch_detach(device_t dev)
435 struct ata_channel *ch = device_get_softc(dev);
437 ata_pci_dmafini(dev);
439 bus_release_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID,
441 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID,
448 ata_pci_status(device_t dev)
451 device_get_softc(device_get_parent(dev));
452 struct ata_channel *ch = device_get_softc(dev);
473 ata_pci_hw(device_t dev)
475 struct ata_channel *ch = device_get_softc(dev);
477 ata_generic_hw(dev);
516 ata_pci_dmareset(device_t dev)
518 struct ata_channel *ch = device_get_softc(dev);
526 device_printf(dev, "DMA reset calling unload\n");
532 ata_pci_dmainit(device_t dev)
534 struct ata_channel *ch = device_get_softc(dev);
536 ata_dmainit(dev);
543 ata_pci_dmafini(device_t dev)
546 ata_dmafini(dev);
550 ata_pci_print_child(device_t dev, device_t child)
554 retval = bus_print_child_header(dev, child);
557 retval += bus_print_child_footer(dev, child);
563 ata_pci_child_location_str(device_t dev, device_t child, char *buf,
619 ata_pcichannel_probe(device_t dev)
622 if ((intptr_t)device_get_ivars(dev) < 0)
624 device_set_desc(dev, "ATA channel");
626 return ata_probe(dev);
630 ata_pcichannel_attach(device_t dev)
632 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
633 struct ata_channel *ch = device_get_softc(dev);
640 ch->dev = dev;
641 ch->unit = (intptr_t)device_get_ivars(dev);
643 resource_int_value(device_get_name(dev),
644 device_get_unit(dev), "pm_level", &ch->pm_level);
646 if ((error = ctlr->ch_attach(dev)))
649 return ata_attach(dev);
653 ata_pcichannel_detach(device_t dev)
655 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
656 struct ata_channel *ch = device_get_softc(dev);
663 if ((error = ata_detach(dev)))
667 return (ctlr->ch_detach(dev));
672 ata_pcichannel_suspend(device_t dev)
674 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
675 struct ata_channel *ch = device_get_softc(dev);
681 if ((error = ata_suspend(dev)))
684 if (ctlr->ch_suspend != NULL && (error = ctlr->ch_suspend(dev)))
691 ata_pcichannel_resume(device_t dev)
693 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
694 struct ata_channel *ch = device_get_softc(dev);
700 if (ctlr->ch_resume != NULL && (error = ctlr->ch_resume(dev)))
703 return ata_resume(dev);
707 ata_pcichannel_reset(device_t dev)
709 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
710 struct ata_channel *ch = device_get_softc(dev);
714 ch->dma.reset(dev);
718 ctlr->reset(dev);
720 ata_generic_reset(dev);
724 ata_pcichannel_setmode(device_t dev, int target, int mode)
726 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
729 return (ctlr->setmode(dev, target, mode));
731 return (ata_generic_setmode(dev, target, mode));
735 ata_pcichannel_getrev(device_t dev, int target)
737 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
738 struct ata_channel *ch = device_get_softc(dev);
742 return (ctlr->getrev(dev, target));
778 ata_legacy(device_t dev)
780 return (((pci_read_config(dev, PCIR_SUBCLASS, 1) == PCIS_STORAGE_IDE) &&
781 (pci_read_config(dev, PCIR_PROGIF, 1)&PCIP_STORAGE_IDE_MASTERDEV)&&
782 ((pci_read_config(dev, PCIR_PROGIF, 1) &
785 (!pci_read_config(dev, PCIR_BAR(0), 4) &&
786 !pci_read_config(dev, PCIR_BAR(1), 4) &&
787 !pci_read_config(dev, PCIR_BAR(2), 4) &&
788 !pci_read_config(dev, PCIR_BAR(3), 4) &&
789 !pci_read_config(dev, PCIR_BAR(5), 4)));
806 ata_setup_interrupt(device_t dev, void *intr_func)
808 struct ata_pci_controller *ctlr = device_get_softc(dev);
812 if (resource_int_value(device_get_name(dev),
813 device_get_unit(dev), "msi", &i) == 0 && i != 0)
815 if (msi && pci_msi_count(dev) > 0 && pci_alloc_msi(dev, &msi) == 0) {
821 if (!(ctlr->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
823 device_printf(dev, "unable to map interrupt\n");
825 pci_release_msi(dev);
828 if ((bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
830 device_printf(dev, "unable to setup interrupt\n");
831 bus_release_resource(dev,
834 pci_release_msi(dev);
842 ata_set_desc(device_t dev)
844 struct ata_pci_controller *ctlr = device_get_softc(dev);
848 ata_pcivendor2str(dev), ctlr->chip->text,
850 device_set_desc_copy(dev, buffer);
854 ata_match_chip(device_t dev, const struct ata_chip_id *index)
859 devid = pci_get_devid(dev);
860 revid = pci_get_revid(dev);
870 ata_find_chip(device_t dev, const struct ata_chip_id *index, int slot)
877 if (device_get_children(device_get_parent(dev), &children, &nchildren))
895 ata_pcivendor2str(device_t dev)
897 switch (pci_get_vendor(dev)) {