static int ata_macio_probe(device_t dev) { const char *type = ofw_bus_get_type(dev); const char *name = ofw_bus_get_name(dev); struct ata_macio_softc *sc; if (strcmp(type, "ata") != 0 && strcmp(type, "ide") != 0) return (ENXIO); sc = device_get_softc(dev); bzero(sc, sizeof(struct ata_macio_softc)); if (strcmp(name,"ata-4") == 0) { device_set_desc(dev,"Apple MacIO Ultra ATA Controller"); sc->rev = 4; sc->max_mode = ATA_UDMA4; } else { device_set_desc(dev,"Apple MacIO ATA Controller"); sc->rev = 3; sc->max_mode = ATA_WDMA2; } return (ata_probe(dev)); }
static int ata_cbuschannel_probe(device_t dev) { struct ata_cbus_controller *ctlr = device_get_softc(device_get_parent(dev)); struct ata_channel *ch = device_get_softc(dev); device_t *children; int count, i; /* find channel number on this controller */ device_get_children(device_get_parent(dev), &children, &count); for (i = 0; i < count; i++) { if (children[i] == dev) ch->unit = i; } free(children, M_TEMP); /* setup the resource vectors */ for (i = ATA_DATA; i <= ATA_COMMAND; i ++) { ch->r_io[i].res = ctlr->io; ch->r_io[i].offset = i << 1; } ch->r_io[ATA_CONTROL].res = ctlr->ctlio; ch->r_io[ATA_CONTROL].offset = 0; ch->r_io[ATA_IDX_ADDR].res = ctlr->io; ata_default_registers(dev); /* initialize softc for this channel */ ch->flags |= ATA_USE_16BIT; ata_generic_hw(dev); return ata_probe(dev); }
static int ata_pccard_attach(device_t dev) { struct ata_channel *ch = device_get_softc(dev); struct resource *io, *ctlio; int i, rid, err; uint16_t funce; if (ch->attached) return (0); ch->attached = 1; /* allocate the io range to get start and length */ rid = ATA_IOADDR_RID; if (!(io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_IOSIZE, RF_ACTIVE))) return (ENXIO); /* setup the resource vectors */ for (i = ATA_DATA; i <= ATA_COMMAND; i++) { ch->r_io[i].res = io; ch->r_io[i].offset = i; } ch->r_io[ATA_IDX_ADDR].res = io; /* * if we got more than the default ATA_IOSIZE ports, this is a device * where ctlio is located at offset 14 into "normal" io space. */ if (rman_get_size(io) > ATA_IOSIZE) { ch->r_io[ATA_CONTROL].res = io; ch->r_io[ATA_CONTROL].offset = 14; } else { rid = ATA_CTLADDR_RID; if (!(ctlio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_CTLIOSIZE, RF_ACTIVE))) { bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); for (i = ATA_DATA; i < ATA_MAX_RES; i++) ch->r_io[i].res = NULL; return (ENXIO); } ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = 0; } ata_default_registers(dev); /* initialize softc for this channel */ ch->unit = 0; ch->flags |= ATA_USE_16BIT; funce = 0; /* Default to sane setting of FUNCE */ pccard_get_funce_disk(dev, &funce); if (!(funce & PFD_I_D)) ch-> flags |= ATA_NO_SLAVE; ata_generic_hw(dev); err = ata_probe(dev); if (err) return (err); return (ata_attach(dev)); }
static int sata_channel_probe(device_t dev) { device_set_desc(dev, "Marvell Integrated SATA Channel"); return (ata_probe(dev)); }
static int ata_isa_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); struct resource *io; u_long tmp; int rid; /* check isapnp ids */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO) return ENXIO; /* allocate the io port range to get the start address */ rid = ATA_IOADDR_RID; io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_IOSIZE, RF_ACTIVE); if (!io) return ENOMEM; /* set the altport range */ if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) { bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, rman_get_start(io) + ATA_ALTOFFSET, ATA_ALTIOSIZE); } bus_release_resource(dev, SYS_RES_IOPORT, rid, io); ch->unit = 0; ch->flags |= ATA_USE_16BIT; return ata_probe(dev); }
static int ata_macio_sub_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); ch->unit = 0; ch->flags = ATA_USE_16BIT; return ata_probe(dev); }
static int ata_cbuschannel_probe(device_t dev) { char buffer[32]; sprintf(buffer, "ATA channel %d", (int)(intptr_t)device_get_ivars(dev)); device_set_desc_copy(dev, buffer); return ata_probe(dev); }
static int ata_pcichannel_probe(device_t dev) { if ((intptr_t)device_get_ivars(dev) < 0) return (ENXIO); device_set_desc(dev, "ATA channel"); return ata_probe(dev); }
static int at91_channel_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); ch->unit = 0; ch->flags |= ATA_USE_16BIT | ATA_NO_SLAVE; device_set_desc_copy(dev, "ATA channel 0"); return (ata_probe(dev)); }
static int xlr_pcmcia_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); ch->unit = 0; ch->flags |= ATA_USE_16BIT | ATA_NO_SLAVE ; device_set_desc(dev, "PCMCIA ATA controller"); return (ata_probe(dev)); }
int main (void) { ipc_structure_type ipc_structure; ata_drive_type *ata_drive; unsigned int drive_number; /* Set the name of the server. */ system_process_name_set (PACKAGE_NAME); system_thread_name_set ("Initialising"); log_init (&log_structure, PACKAGE_NAME, &empty_tag); for ( drive_number = 0 ; drive_number < number_of_probe ; drive_number++ ) { if (!register_ports (ata_probe_drives[drive_number])) { continue; } ata_drive = ata_probe (ata_probe_drives[drive_number]); if (ata_drive != NULL) { switch (ata_drive->type) { case ATA_HARD_DRIVE : { create_hard_drive_service (ata_drive); break; } case ATA_CDROM : { create_cdrom_service (ata_drive); break; } /* FIXME: what we must do there ? */ default : { } } ata_drivers[number_of_drives] = ata_drive; number_of_drives++; } else { unregister_ports (ata_probe_drives[drive_number]); } } system_call_process_parent_unblock (); return 0; }
static int ata_iobus_sub_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); /* Only a single unit per controller thus far */ ch->unit = 0; ch->flags = (ATA_USE_16BIT|ATA_NO_SLAVE); ata_generic_hw(dev); return ata_probe(dev); }
static int ata_macio_probe(device_t dev) { const char *type = ofw_bus_get_type(dev); const char *name = ofw_bus_get_name(dev); struct ata_macio_softc *sc; struct ata_channel *ch; int rid, i; if (strcmp(type, "ata") != 0 && strcmp(type, "ide") != 0) return (ENXIO); sc = device_get_softc(dev); bzero(sc, sizeof(struct ata_macio_softc)); ch = &sc->sc_ch.sc_ch; if (strcmp(name,"ata-4") == 0) { device_set_desc(dev,"Apple MacIO Ultra ATA Controller"); sc->rev = 4; sc->max_mode = ATA_UDMA4; } else { device_set_desc(dev,"Apple MacIO ATA Controller"); sc->rev = 3; sc->max_mode = ATA_WDMA2; } rid = 0; sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_mem == NULL) { device_printf(dev, "could not allocate memory\n"); return (ENXIO); } /* * Set up the resource vectors */ for (i = ATA_DATA; i <= ATA_COMMAND; i++) { ch->r_io[i].res = sc->sc_mem; ch->r_io[i].offset = i * ATA_MACIO_REGGAP; } ch->r_io[ATA_CONTROL].res = sc->sc_mem; ch->r_io[ATA_CONTROL].offset = ATA_MACIO_ALTOFFSET; ata_default_registers(dev); ch->unit = 0; ch->flags |= ATA_USE_16BIT | ATA_NO_ATAPI_DMA; ata_generic_hw(dev); return (ata_probe(dev)); }
static int ata_isa_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); struct resource *io = NULL, *ctlio = NULL; u_long tmp; int i, rid; /* check isapnp ids */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO) return ENXIO; /* allocate the io port range */ rid = ATA_IOADDR_RID; if (!(io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_IOSIZE, RF_ACTIVE))) return ENXIO; /* set the altport range */ if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID, &tmp, &tmp)) { bus_set_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID, rman_get_start(io) + ATA_CTLOFFSET, ATA_CTLIOSIZE, -1); } /* allocate the altport range */ rid = ATA_CTLADDR_RID; if (!(ctlio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_CTLIOSIZE, RF_ACTIVE))) { bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); return ENXIO; } /* setup the resource vectors */ for (i = ATA_DATA; i <= ATA_COMMAND; i++) { ch->r_io[i].res = io; ch->r_io[i].offset = i; } ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = 0; ch->r_io[ATA_IDX_ADDR].res = io; ata_default_registers(dev); /* initialize softc for this channel */ ch->unit = 0; ch->flags |= ATA_USE_16BIT; ata_generic_hw(dev); return ata_probe(dev); }
static int ata_pccard_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); struct resource *io; int rid, len, start, end; u_long tmp; /* allocate the io range to get start and length */ rid = ATA_IOADDR_RID; len = bus_get_resource_count(dev, SYS_RES_IOPORT, rid); io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_IOSIZE, RF_ACTIVE); if (!io) return ENOMEM; /* reallocate the io address to only cover the io ports */ start = rman_get_start(io); end = start + ATA_IOSIZE - 1; bus_release_resource(dev, SYS_RES_IOPORT, rid, io); io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, start, end, ATA_IOSIZE, RF_ACTIVE); bus_release_resource(dev, SYS_RES_IOPORT, rid, io); /* * if we got more than the default ATA_IOSIZE ports, this is likely * a pccard system where the altio ports are located at offset 14 * otherwise its the normal altio offset */ if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) { if (len > ATA_IOSIZE) { bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE); } else { bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, start + ATA_ALTOFFSET, ATA_ALTIOSIZE); } } else return ENOMEM; ch->unit = 0; ch->flags |= (ATA_USE_16BIT | ATA_NO_SLAVE); return ata_probe(dev); }
static int ata_isa_probe(device_t dev) { struct resource *io = NULL, *ctlio = NULL; u_long tmp; int rid; /* check isapnp ids */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO) return ENXIO; /* allocate the io port range */ rid = ATA_IOADDR_RID; if (!(io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_IOSIZE, RF_ACTIVE))) return ENXIO; /* set the altport range */ if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID, &tmp, &tmp)) { bus_set_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID, rman_get_start(io) + ATA_CTLOFFSET, ATA_CTLIOSIZE); } /* allocate the altport range */ rid = ATA_CTLADDR_RID; if (!(ctlio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, ATA_CTLIOSIZE, RF_ACTIVE))) { bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); return ENXIO; } /* Release resources to reallocate on attach. */ bus_release_resource(dev, SYS_RES_IOPORT, ATA_CTLADDR_RID, ctlio); bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); device_set_desc(dev, "ATA channel"); return (ata_probe(dev)); }
static int ata_pcichannel_probe(device_t dev) { struct ata_channel *ch = device_get_softc(dev); device_t *children; int count, i; char buffer[32]; /* take care of green memory */ bzero(ch, sizeof(struct ata_channel)); /* find channel number on this controller */ device_get_children(device_get_parent(dev), &children, &count); for (i = 0; i < count; i++) { if (children[i] == dev) ch->unit = i; } kfree(children, M_TEMP); ksprintf(buffer, "ATA channel %d", ch->unit); device_set_desc_copy(dev, buffer); return ata_probe(dev); }
static int ata_kauai_probe(device_t dev) { struct ata_channel *ch; struct ata_kauai_softc *sc; u_int32_t devid; phandle_t node; const char *compatstring = NULL; int i, found, rid; found = 0; devid = pci_get_devid(dev); for (i = 0; kauai_pci_devlist[i].kpd_desc != NULL; i++) { if (devid == kauai_pci_devlist[i].kpd_devid) { found = 1; device_set_desc(dev, kauai_pci_devlist[i].kpd_desc); } } if (!found) return (ENXIO); node = ofw_bus_get_node(dev); sc = device_get_softc(dev); bzero(sc, sizeof(struct ata_kauai_softc)); ch = &sc->sc_ch.sc_ch; compatstring = ofw_bus_get_compat(dev); if (compatstring != NULL && strcmp(compatstring,"shasta-ata") == 0) sc->shasta = 1; /* Pre-K2 controllers apparently need this hack */ if (!sc->shasta && (compatstring == NULL || strcmp(compatstring, "K2-UATA") != 0)) bus_set_resource(dev, SYS_RES_IRQ, 0, 39, 1); rid = PCIR_BARS; sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_memr == NULL) { device_printf(dev, "could not allocate memory\n"); return (ENXIO); } /* * Set up the resource vectors */ for (i = ATA_DATA; i <= ATA_COMMAND; i++) { ch->r_io[i].res = sc->sc_memr; ch->r_io[i].offset = i*ATA_KAUAI_REGGAP + ATA_KAUAI_REGOFFSET; } ch->r_io[ATA_CONTROL].res = sc->sc_memr; ch->r_io[ATA_CONTROL].offset = ATA_KAUAI_ALTOFFSET; ata_default_registers(dev); ch->unit = 0; ch->flags |= ATA_USE_16BIT; /* XXX: ATAPI DMA is unreliable. We should find out why. */ ch->flags |= ATA_NO_ATAPI_DMA; ata_generic_hw(dev); return (ata_probe(dev)); }
static int ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p) { struct ata_cmd *iocmd = (struct ata_cmd *)addr; struct ata_channel *ch; device_t device = devclass_get_device(ata_devclass, iocmd->channel); int error; if (cmd != IOCATA) return ENOTTY; if (iocmd->channel < -1 || iocmd->device < -1 || iocmd->device > SLAVE) return ENXIO; switch (iocmd->cmd) { case ATAATTACH: /* should enable channel HW on controller that can SOS XXX */ error = ata_probe(device); if (!error) error = ata_attach(device); return error; case ATADETACH: error = ata_detach(device); /* should disable channel HW on controller that can SOS XXX */ return error; case ATAREINIT: if (!device || !(ch = device_get_softc(device))) return ENXIO; ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE); if ((error = ata_reinit(ch))) ATA_UNLOCK_CH(ch); return error; case ATAGMODE: if (!device || !(ch = device_get_softc(device))) return ENXIO; if ((iocmd->device == MASTER || iocmd->device == -1) && ch->device[MASTER].driver) iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; else iocmd->u.mode.mode[MASTER] = -1; if ((iocmd->device == SLAVE || iocmd->device == -1) && ch->device[SLAVE].param) iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; else iocmd->u.mode.mode[SLAVE] = -1; return 0; case ATASMODE: if (!device || !(ch = device_get_softc(device))) return ENXIO; if ((iocmd->device == MASTER || iocmd->device == -1) && iocmd->u.mode.mode[MASTER] >= 0 && ch->device[MASTER].param) { ata_change_mode(&ch->device[MASTER],iocmd->u.mode.mode[MASTER]); iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; } else iocmd->u.mode.mode[MASTER] = -1; if ((iocmd->device == SLAVE || iocmd->device == -1) && iocmd->u.mode.mode[SLAVE] >= 0 && ch->device[SLAVE].param) { ata_change_mode(&ch->device[SLAVE], iocmd->u.mode.mode[SLAVE]); iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; } else iocmd->u.mode.mode[SLAVE] = -1; return 0; case ATAGPARM: if (!device || !(ch = device_get_softc(device))) return ENXIO; iocmd->u.param.type[MASTER] = ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER); iocmd->u.param.type[SLAVE] = ch->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE); if (ch->device[MASTER].name) strcpy(iocmd->u.param.name[MASTER], ch->device[MASTER].name); if (ch->device[SLAVE].name) strcpy(iocmd->u.param.name[SLAVE], ch->device[SLAVE].name); if (ch->device[MASTER].param) bcopy(ch->device[MASTER].param, &iocmd->u.param.params[MASTER], sizeof(struct ata_params)); if (ch->device[SLAVE].param) bcopy(ch->device[SLAVE].param, &iocmd->u.param.params[SLAVE], sizeof(struct ata_params)); return 0; case ATAENCSTAT: { struct ata_device *atadev; if (!device || !(ch = device_get_softc(device))) return ENXIO; if (iocmd->device == SLAVE) atadev = &ch->device[SLAVE]; else atadev = &ch->device[MASTER]; return ata_enclosure_status(atadev, &iocmd->u.enclosure.fan, &iocmd->u.enclosure.temp, &iocmd->u.enclosure.v05, &iocmd->u.enclosure.v12); } #if NATADISK > 0 case ATARAIDREBUILD: return ata_raid_rebuild(iocmd->channel); case ATARAIDCREATE: return ata_raid_create(&iocmd->u.raid_setup); case ATARAIDDELETE: return ata_raid_delete(iocmd->channel); case ATARAIDSTATUS: return ata_raid_status(iocmd->channel, &iocmd->u.raid_status); #endif #if DEV_ATAPIALL case ATAPICMD: { struct ata_device *atadev; caddr_t buf; if (!device || !(ch = device_get_softc(device))) return ENXIO; if (!(atadev = &ch->device[iocmd->device]) || !(ch->devices & (iocmd->device == MASTER ? ATA_ATAPI_MASTER : ATA_ATAPI_SLAVE))) return ENODEV; if (!(buf = malloc(iocmd->u.atapi.count, M_ATA, M_NOWAIT))) return ENOMEM; if (iocmd->u.atapi.flags & ATAPI_CMD_WRITE) { error = copyin(iocmd->u.atapi.data, buf, iocmd->u.atapi.count); if (error) return error; } error = atapi_queue_cmd(atadev, iocmd->u.atapi.ccb, buf, iocmd->u.atapi.count, (iocmd->u.atapi.flags == ATAPI_CMD_READ ? ATPR_F_READ : 0) | ATPR_F_QUIET, iocmd->u.atapi.timeout, NULL, NULL); if (error) { iocmd->u.atapi.error = error; bcopy(&atadev->result, iocmd->u.atapi.sense_data, sizeof(struct atapi_reqsense)); error = 0; } else if (iocmd->u.atapi.flags & ATAPI_CMD_READ) error = copyout(buf, iocmd->u.atapi.data, iocmd->u.atapi.count); free(buf, M_ATA); return error; } #endif default: break; } return ENOTTY; }
static int ata_zbbus_probe(device_t dev) { return (ata_probe(dev)); }