Deleted Added
full compact
28c28
< * $FreeBSD: head/sys/dev/ata/ata-all.c 74253 2001-03-14 14:00:09Z sos $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 74302 2001-03-15 15:36:25Z sos $
34a35
> #include <sys/ata.h>
35a37
> #include <sys/conf.h>
53a56,74
> /* device structures */
> static d_ioctl_t ataioctl;
> static struct cdevsw ata_cdevsw = {
> /* open */ nullopen,
> /* close */ nullclose,
> /* read */ noread,
> /* write */ nowrite,
> /* ioctl */ ataioctl,
> /* poll */ nopoll,
> /* mmap */ nommap,
> /* strategy */ nostrategy,
> /* name */ "ata",
> /* maj */ 159,
> /* dump */ nodump,
> /* psize */ nopsize,
> /* flags */ 0,
> /* bmaj */ -1
> };
>
62a84
> static void ata_change_mode(struct ata_softc *, int, int);
69d90
< static char ata_conf[256];
245a267,270
> scp->r_io = NULL;
> scp->r_altio = NULL;
> scp->r_bmio = NULL;
> scp->r_irq = NULL;
259a285,402
> ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
> {
> int error = 0;
>
> switch (cmd) {
> case ATAATTACH: {
> device_t device = devclass_get_device(ata_devclass, *(int *)addr);
> /* should enable channel HW on controller that can SOS XXX */
> if (!device)
> error = ENXIO;
> if (!error)
> error = ata_probe(device);
> if (!error)
> error = ata_attach(device);
> break;
> }
>
> case ATADETACH: {
> device_t device = devclass_get_device(ata_devclass, *(int *)addr);
> if (!device)
> error = ENXIO;
> if (!error)
> error = ata_detach(device);
> /* should disable channel HW on controller that can SOS XXX */
> break;
> }
>
> case ATAREINIT: {
> device_t device = devclass_get_device(ata_devclass, *(int *)addr);
> struct ata_softc *scp;
> int s;
>
> if (!device)
> return ENXIO;
> scp = device_get_softc(device);
> if (!scp)
> return ENXIO;
>
> /* make sure channel is not busy SOS XXX */
> s = splbio();
> while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE))
> tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4);
> splx(s);
> error = ata_reinit(scp);
> break;
> }
>
> case ATAGMODE: {
> struct ata_modes *mode = (struct ata_modes *)addr;
> device_t device = devclass_get_device(ata_devclass, mode->channel);
> struct ata_softc *scp;
>
> if (!device)
> return ENXIO;
> scp = device_get_softc(device);
> if (!scp)
> return ENXIO;
> mode->mode[MASTER] = scp->mode[MASTER];
> mode->mode[SLAVE] = scp->mode[SLAVE];
> break;
> }
>
> case ATASMODE: {
> struct ata_modes *mode = (struct ata_modes *)addr;
> device_t device = devclass_get_device(ata_devclass, mode->channel);
> struct ata_softc *scp;
>
> if (!device)
> return ENXIO;
> scp = device_get_softc(device);
> if (!scp)
> return ENXIO;
> if (mode->mode[MASTER] >= 0)
> ata_change_mode(scp, ATA_MASTER, mode->mode[MASTER]);
> if (mode->mode[SLAVE] >= 0)
> ata_change_mode(scp, ATA_SLAVE, mode->mode[SLAVE]);
> mode->mode[MASTER] = scp->mode[MASTER];
> mode->mode[SLAVE] = scp->mode[SLAVE];
> break;
> }
>
> case ATAGPARM: {
> struct ata_param *parm = (struct ata_param *)addr;
> device_t device = devclass_get_device(ata_devclass, parm->channel);
> struct ata_softc *scp;
>
> if (!device)
> return ENXIO;
> scp = device_get_softc(device);
> if (!scp)
> return ENXIO;
>
> parm->type[MASTER] =
> scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER);
> parm->type[SLAVE] =
> scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE);
>
> if (scp->dev_name[MASTER])
> strcpy(parm->name[MASTER], scp->dev_name[MASTER]);
> if (scp->dev_name[SLAVE])
> strcpy(parm->name[SLAVE], scp->dev_name[SLAVE]);
>
> if (scp->dev_param[MASTER])
> bcopy(scp->dev_param[MASTER], &parm->params[MASTER],
> sizeof(struct ata_params));
> if (scp->dev_param[SLAVE])
> bcopy(scp->dev_param[SLAVE], &parm->params[SLAVE],
> sizeof(struct ata_params));
> break;
> }
>
> default:
> error = ENOTTY;
> }
> return error;
> }
>
> static int
614a758,759
> if (!scp->r_io || !scp->r_altio || !scp->r_irq)
> return ENXIO;
621a767,768
> if (misdev)
> printf("\n");
656,657d802
< if (newdev)
< printf("\n");
659a805,806
> if (!misdev && newdev)
> printf("\n");
836a984,998
> void
> ata_set_name(struct ata_softc *scp, int device, char *name)
> {
> scp->dev_name[ATA_DEV(device)] = malloc(strlen(name) + 1, M_ATA, M_NOWAIT);
> if (scp->dev_name[ATA_DEV(device)])
> strcpy(scp->dev_name[ATA_DEV(device)], name);
> }
>
> void
> ata_free_name(struct ata_softc *scp, int device)
> {
> if (scp->dev_name[ATA_DEV(device)])
> free(scp->dev_name[ATA_DEV(device)], M_ATA);
> }
>
866,868c1028,1034
< else
< ret = printf("ata%d-%s: ", device_get_unit(scp->dev),
< (device == ATA_MASTER) ? "master" : "slave");
---
> else {
> if (scp->dev_name[ATA_DEV(device)])
> ret = printf("%s: ", scp->dev_name[ATA_DEV(device)]);
> else
> ret = printf("ata%d-%s: ", device_get_unit(scp->dev),
> (device == ATA_MASTER) ? "master" : "slave");
> }
1031a1198
> int umode, wmode, pmode;
1037,1039c1204,1225
< ata_dmainit(scp, device, ata_pmode(ATA_PARAM(scp, device)),
< mode < ATA_DMA ? -1 : ata_wmode(ATA_PARAM(scp, device)),
< mode < ATA_DMA ? -1 : ata_umode(ATA_PARAM(scp, device)));
---
> umode = ata_umode(ATA_PARAM(scp, device));
> wmode = ata_wmode(ATA_PARAM(scp, device));
> pmode = ata_pmode(ATA_PARAM(scp, device));
>
> switch (mode & ATA_DMA_MASK) {
> case ATA_UDMA:
> if ((mode & ATA_MODE_MASK) < umode)
> umode = mode & ATA_MODE_MASK;
> break;
> case ATA_WDMA:
> if ((mode & ATA_MODE_MASK) < wmode)
> wmode = mode & ATA_MODE_MASK;
> umode = -1;
> break;
> default:
> if (((mode & ATA_MODE_MASK) - ATA_PIO0) < pmode)
> pmode = (mode & ATA_MODE_MASK) - ATA_PIO0;
> umode = -1;
> wmode = -1;
> }
> ata_dmainit(scp, device, pmode, wmode, umode);
>
1045,1094d1230
< static int
< sysctl_hw_ata(SYSCTL_HANDLER_ARGS)
< {
< struct ata_softc *scp;
< int ctlr, error, i;
<
< /* readout internal state */
< bzero(ata_conf, sizeof(ata_conf));
< for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
< if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
< continue;
< for (i = 0; i < 2; i++) {
< if (!scp->dev_softc[i])
< strcat(ata_conf, "---,");
< else if (scp->mode[i] >= ATA_DMA)
< strcat(ata_conf, "dma,");
< else
< strcat(ata_conf, "pio,");
< }
< }
< error = sysctl_handle_string(oidp, ata_conf, sizeof(ata_conf), req);
< if (error == 0 && req->newptr != NULL) {
< char *ptr = ata_conf;
<
< /* update internal state */
< i = 0;
< while (*ptr) {
< if (!strncmp(ptr, "pio", 3) || !strncmp(ptr, "PIO", 3)) {
< if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
< scp->dev_softc[i & 1] && scp->mode[i & 1] >= ATA_DMA)
< ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_PIO);
< }
< else if (!strncmp(ptr, "dma", 3) || !strncmp(ptr, "DMA", 3)) {
< if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
< scp->dev_softc[i & 1] && scp->mode[i & 1] < ATA_DMA)
< ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_DMA);
< }
< else if (strncmp(ptr, "---", 3))
< break;
< ptr+=3;
< if (*ptr++ != ',' ||
< ++i > (devclass_get_maxunit(ata_devclass) << 1))
< break;
< }
< }
< return error;
< }
< SYSCTL_PROC(_hw, OID_AUTO, atamodes, CTLTYPE_STRING | CTLFLAG_RW,
< 0, sizeof(ata_conf), sysctl_hw_ata, "A", "");
<
1097a1234,1236
> /* register controlling device */
> make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0666, "ata");
>