Lines Matching defs:dev

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);
65 if (pci_get_class(dev) != PCIC_STORAGE)
69 if (pci_get_subclass(dev) != PCIS_STORAGE_IDE)
72 device_set_descf(dev, "%s ATA controller", ata_pcivendor2str(dev));
80 ata_pci_attach(device_t dev)
82 struct ata_pci_controller *ctlr = device_get_softc(dev);
88 ctlr->legacy = ata_legacy(dev);
89 if (ctlr->legacy || pci_read_config(dev, PCIR_BAR(2), 4) & IOMASK)
96 ctlr->dev = dev;
99 pci_enable_busmaster(dev);
100 cmd = pci_read_config(dev, PCIR_COMMAND, 2);
106 ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1, &ctlr->r_rid1,
110 if (ctlr->chipinit(dev)) {
112 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1,
121 child = device_add_child(dev, "ata",
125 device_printf(dev, "failed to add ata child device\n");
129 bus_attach_children(dev);
134 ata_pci_detach(device_t dev)
136 struct ata_pci_controller *ctlr = device_get_softc(dev);
140 error = bus_generic_detach(dev);
145 bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle);
146 bus_release_resource(dev, SYS_RES_IRQ, ctlr->r_irq_rid, ctlr->r_irq);
148 pci_release_msi(dev);
151 ctlr->chipdeinit(dev);
153 bus_release_resource(dev, ctlr->r_type2, ctlr->r_rid2, ctlr->r_res2);
156 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, ctlr->r_res1);
163 ata_pci_suspend(device_t dev)
165 struct ata_pci_controller *ctlr = device_get_softc(dev);
168 bus_generic_suspend(dev);
170 error = ctlr->suspend(dev);
175 ata_pci_resume(device_t dev)
177 struct ata_pci_controller *ctlr = device_get_softc(dev);
181 error = ctlr->resume(dev);
182 bus_generic_resume(dev);
187 ata_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
190 return (BUS_READ_IVAR(device_get_parent(dev), dev, which, result));
194 ata_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
197 return (BUS_WRITE_IVAR(device_get_parent(dev), dev, which, value));
201 ata_pci_read_config(device_t dev, device_t child, int reg, int width)
204 return (pci_read_config(dev, reg, width));
208 ata_pci_write_config(device_t dev, device_t child, int reg,
212 pci_write_config(dev, reg, val, width);
216 ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
220 struct ata_pci_controller *controller = device_get_softc(dev);
236 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
248 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
258 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
269 res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
277 ata_pci_release_resource(device_t dev, device_t child, struct resource *r)
283 struct ata_pci_controller *controller = device_get_softc(dev);
289 return BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
299 return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
310 return (BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
318 ata_pci_setup_intr(device_t dev, device_t child, struct resource *irq,
322 struct ata_pci_controller *controller = device_get_softc(dev);
325 return BUS_SETUP_INTR(device_get_parent(dev), child, irq,
328 struct ata_pci_controller *controller = device_get_softc(dev);
347 ata_pci_teardown_intr(device_t dev, device_t child, struct resource *irq,
350 struct ata_pci_controller *controller = device_get_softc(dev);
353 return BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq, cookie);
355 struct ata_pci_controller *controller = device_get_softc(dev);
369 ata_generic_setmode(device_t dev, int target, int mode)
376 ata_generic_chipinit(device_t dev)
378 struct ata_pci_controller *ctlr = device_get_softc(dev);
380 if (ata_setup_interrupt(dev, ata_generic_intr))
387 ata_pci_ch_attach(device_t dev)
389 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
390 struct ata_channel *ch = device_get_softc(dev);
395 if (!(io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)))
399 if (!(ctlio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,RF_ACTIVE))){
400 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
404 ata_pci_dmainit(dev);
413 ata_default_registers(dev);
421 ata_pci_hw(dev);
426 ata_pci_ch_detach(device_t dev)
428 struct ata_channel *ch = device_get_softc(dev);
430 ata_pci_dmafini(dev);
432 bus_release_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID,
434 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID,
441 ata_pci_status(device_t dev)
444 device_get_softc(device_get_parent(dev));
445 struct ata_channel *ch = device_get_softc(dev);
466 ata_pci_hw(device_t dev)
468 struct ata_channel *ch = device_get_softc(dev);
470 ata_generic_hw(dev);
509 ata_pci_dmareset(device_t dev)
511 struct ata_channel *ch = device_get_softc(dev);
519 device_printf(dev, "DMA reset calling unload\n");
525 ata_pci_dmainit(device_t dev)
527 struct ata_channel *ch = device_get_softc(dev);
529 ata_dmainit(dev);
536 ata_pci_dmafini(device_t dev)
539 ata_dmafini(dev);
543 ata_pci_print_child(device_t dev, device_t child)
547 retval = bus_print_child_header(dev, child);
550 retval += bus_print_child_footer(dev, child);
556 ata_pci_child_location(device_t dev, device_t child, struct sbuf *sb)
609 ata_pcichannel_probe(device_t dev)
612 if ((intptr_t)device_get_ivars(dev) < 0)
614 device_set_desc(dev, "ATA channel");
616 return ata_probe(dev);
620 ata_pcichannel_attach(device_t dev)
622 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
623 struct ata_channel *ch = device_get_softc(dev);
630 ch->dev = dev;
631 ch->unit = (intptr_t)device_get_ivars(dev);
633 resource_int_value(device_get_name(dev),
634 device_get_unit(dev), "pm_level", &ch->pm_level);
636 if ((error = ctlr->ch_attach(dev)))
639 return ata_attach(dev);
643 ata_pcichannel_detach(device_t dev)
645 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
646 struct ata_channel *ch = device_get_softc(dev);
653 if ((error = ata_detach(dev)))
657 return (ctlr->ch_detach(dev));
662 ata_pcichannel_suspend(device_t dev)
664 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
665 struct ata_channel *ch = device_get_softc(dev);
671 if ((error = ata_suspend(dev)))
674 if (ctlr->ch_suspend != NULL && (error = ctlr->ch_suspend(dev)))
681 ata_pcichannel_resume(device_t dev)
683 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
684 struct ata_channel *ch = device_get_softc(dev);
690 if (ctlr->ch_resume != NULL && (error = ctlr->ch_resume(dev)))
693 return ata_resume(dev);
697 ata_pcichannel_reset(device_t dev)
699 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
700 struct ata_channel *ch = device_get_softc(dev);
704 ch->dma.reset(dev);
708 ctlr->reset(dev);
710 ata_generic_reset(dev);
714 ata_pcichannel_setmode(device_t dev, int target, int mode)
716 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
719 return (ctlr->setmode(dev, target, mode));
721 return (ata_generic_setmode(dev, target, mode));
725 ata_pcichannel_getrev(device_t dev, int target)
727 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
728 struct ata_channel *ch = device_get_softc(dev);
732 return (ctlr->getrev(dev, target));
768 ata_legacy(device_t dev)
770 return (((pci_read_config(dev, PCIR_SUBCLASS, 1) == PCIS_STORAGE_IDE) &&
771 (pci_read_config(dev, PCIR_PROGIF, 1)&PCIP_STORAGE_IDE_MASTERDEV)&&
772 ((pci_read_config(dev, PCIR_PROGIF, 1) &
775 (!pci_read_config(dev, PCIR_BAR(0), 4) &&
776 !pci_read_config(dev, PCIR_BAR(1), 4) &&
777 !pci_read_config(dev, PCIR_BAR(2), 4) &&
778 !pci_read_config(dev, PCIR_BAR(3), 4) &&
779 !pci_read_config(dev, PCIR_BAR(5), 4)));
796 ata_setup_interrupt(device_t dev, void *intr_func)
798 struct ata_pci_controller *ctlr = device_get_softc(dev);
802 if (resource_int_value(device_get_name(dev),
803 device_get_unit(dev), "msi", &i) == 0 && i != 0)
805 if (msi && pci_msi_count(dev) > 0 && pci_alloc_msi(dev, &msi) == 0) {
811 if (!(ctlr->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
813 device_printf(dev, "unable to map interrupt\n");
815 pci_release_msi(dev);
818 if ((bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
820 device_printf(dev, "unable to setup interrupt\n");
821 bus_release_resource(dev,
824 pci_release_msi(dev);
832 ata_set_desc(device_t dev)
834 struct ata_pci_controller *ctlr = device_get_softc(dev);
836 device_set_descf(dev, "%s %s %s controller",
837 ata_pcivendor2str(dev), ctlr->chip->text,
842 ata_match_chip(device_t dev, const struct ata_chip_id *index)
847 devid = pci_get_devid(dev);
848 revid = pci_get_revid(dev);
858 ata_find_chip(device_t dev, const struct ata_chip_id *index, int slot)
865 if (device_get_children(device_get_parent(dev), &children, &nchildren))
883 ata_pcivendor2str(device_t dev)
885 switch (pci_get_vendor(dev)) {