Get rid of the ivars entirely.

This commit is contained in:
Søren Schmidt 2000-10-13 11:21:27 +00:00
parent b656ee68ec
commit 2c483f9eb5
3 changed files with 60 additions and 46 deletions

View File

@ -130,7 +130,7 @@ ata_isa_probe(device_t dev)
ATA_ALTIOSIZE);
}
bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
scp->unit = device_get_unit(dev);
scp->channel = 0;
scp->flags |= ATA_USE_16BIT;
return ata_probe(dev);
}
@ -177,7 +177,7 @@ ata_pccard_probe(device_t dev)
rman_get_start(port) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
}
bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
scp->unit = device_get_unit(dev);
scp->channel = 0;
scp->flags |= ATA_USE_16BIT;
return ata_probe(dev);
}
@ -368,7 +368,6 @@ ata_pci_add_child(device_t dev, int unit)
if (!(child = device_add_child(dev, "ata", 2)))
return ENOMEM;
}
device_set_ivars(child, (void *)(uintptr_t) unit);
return 0;
}
@ -394,8 +393,8 @@ ata_pci_attach(device_t dev)
rid = 0x20;
sc->bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, 1, RF_ACTIVE);
device_printf(dev, "Busmastering DMA %s\n",
sc->bmio ? "enabled" : "not supported");
if (!sc->bmio)
device_printf(dev, "Busmastering DMA not supported\n");
}
/* do extra chipset specific setups */
@ -492,14 +491,13 @@ static int
ata_pci_print_child(device_t dev, device_t child)
{
struct ata_softc *scp = device_get_softc(child);
int unit = (uintptr_t) device_get_ivars(child);
int retval = 0;
retval += bus_print_child_header(dev, child);
retval += printf(": at 0x%x", scp->ioaddr);
if (ATA_MASTERDEV(dev))
retval += printf(" irq %d", 14 + unit);
retval += printf(" irq %d", 14 + scp->channel);
retval += bus_print_child_footer(dev, child);
@ -511,7 +509,7 @@ ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
{
struct ata_pci_softc *sc = device_get_softc(dev);
int unit = (intptr_t)device_get_ivars(child);
int channel = ((struct ata_softc *)device_get_softc(child))->channel;
int myrid;
if (type == SYS_RES_IOPORT) {
@ -519,29 +517,29 @@ ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
case ATA_IOADDR_RID:
if (ATA_MASTERDEV(dev)) {
myrid = 0;
start = (unit == 0 ? IO_WD1 : IO_WD2);
start = (channel == 0 ? IO_WD1 : IO_WD2);
end = start + ATA_IOSIZE - 1;
count = ATA_IOSIZE;
}
else
myrid = 0x10 + 8 * unit;
myrid = 0x10 + 8 * channel;
break;
case ATA_ALTADDR_RID:
if (ATA_MASTERDEV(dev)) {
myrid = 0;
start = (unit == 0 ? IO_WD1 : IO_WD2) + ATA_ALTOFFSET;
start = (channel == 0 ? IO_WD1 : IO_WD2) + ATA_ALTOFFSET;
end = start + ATA_ALTIOSIZE - 1;
count = ATA_ALTIOSIZE;
}
else
myrid = 0x14 + 8 * unit;
myrid = 0x14 + 8 * channel;
break;
case ATA_BMADDR_RID:
/* the busmaster resource is shared between the two channels */
if (sc->bmio) {
if (unit == 0) {
if (channel == 0) {
sc->bmio_1 = *sc->bmio;
sc->bmio_1.r_end = sc->bmio->r_start + ATA_BM_OFFSET1;
return &sc->bmio_1;
@ -576,9 +574,9 @@ ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
if (ATA_MASTERDEV(dev)) {
#ifdef __alpha__
return alpha_platform_alloc_ide_intr(unit);
return alpha_platform_alloc_ide_intr(channel);
#else
int irq = (unit == 0 ? 14 : 15);
int irq = (channel == 0 ? 14 : 15);
return BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
SYS_RES_IRQ, rid,
@ -601,7 +599,7 @@ ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
struct resource *r)
{
struct ata_pci_softc *sc = device_get_softc(dev);
int unit = (uintptr_t) device_get_ivars(child);
int channel = ((struct ata_softc *)device_get_softc(child))->channel;
int myrid = 0;
if (type == SYS_RES_IOPORT) {
@ -610,14 +608,14 @@ ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
if (ATA_MASTERDEV(dev))
myrid = 0;
else
myrid = 0x10 + 8 * unit;
myrid = 0x10 + 8 * channel;
break;
case ATA_ALTADDR_RID:
if (ATA_MASTERDEV(dev))
myrid = 0;
else
myrid = 0x14 + 8 * unit;
myrid = 0x14 + 8 * channel;
break;
case ATA_BMADDR_RID:
@ -642,7 +640,7 @@ ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
if (ATA_MASTERDEV(dev)) {
#ifdef __alpha__
return alpha_platform_release_ide_intr(unit, r);
return alpha_platform_release_ide_intr(channel, r);
#else
return BUS_RELEASE_RESOURCE(device_get_parent(dev),
child, SYS_RES_IRQ, rid, r);
@ -723,10 +721,25 @@ static int
ata_pcisub_probe(device_t dev)
{
struct ata_softc *scp = device_get_softc(dev);
device_t *list;
int count, i;
/* find channel number on this controller */
device_get_children(device_get_parent(dev), &list, &count);
for (i = 0; i < count; i++) {
if (list[i] == dev)
scp->channel = i;
}
/* kids of pci ata chipsets has their physical unit number in ivars */
scp->unit = (uintptr_t) device_get_ivars(dev);
scp->chiptype = pci_get_devid(device_get_parent(dev));
/* is this an ATA RAID setup ? */
if (((pci_get_subclass(device_get_parent(dev)) == PCIS_STORAGE_RAID) &&
(scp->chiptype == 0x4d33105a || scp->chiptype == 0x4d38105a ||
scp->chiptype == 0x4d30105a || scp->chiptype == 0x0d30105a)) ||
scp->chiptype == 0x00041103) {
scp->flags |= ATA_RAID;
}
return ata_probe(dev);
}
@ -1082,7 +1095,7 @@ ata_intr(void *data)
case 0x06481095: /* CMD 648 */
case 0x06491095: /* CMD 649 */
if (!(pci_read_config(device_get_parent(scp->dev), 0x71, 1) &
(scp->unit ? 0x08 : 0x04)))
(scp->channel ? 0x08 : 0x04)))
return;
goto out;
@ -1091,7 +1104,7 @@ ata_intr(void *data)
case 0x4d30105a: /* Promise Ultra/Fasttrak 100 */
case 0x0d30105a: /* Promise OEM ATA100 */
if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
(scp->unit ? 0x00004000 : 0x00000400)))
(scp->channel ? 0x00004000 : 0x00000400)))
return;
/* FALLTHROUGH */
out:

View File

@ -111,8 +111,8 @@
#define ATA_IOSIZE 0x08
#define ATA_OP_FINISHED 0x00
#define ATA_OP_CONTINUES 0x01
#define ATA_DEV(unit) ((unit == ATA_MASTER) ? 0 : 1)
#define ATA_PARAM(scp, unit) (scp->dev_param[ATA_DEV(unit)])
#define ATA_DEV(device) ((device == ATA_MASTER) ? 0 : 1)
#define ATA_PARAM(scp, device) (scp->dev_param[ATA_DEV(device)])
/* busmaster DMA related defines */
#define ATA_BM_OFFSET1 0x08
@ -276,7 +276,7 @@ struct ata_params {
/* structure describing an ATA device */
struct ata_softc {
struct device *dev; /* device handle */
int unit; /* unit on this controller */
int channel; /* channel on this controller */
struct resource *r_io; /* io addr resource handle */
struct resource *r_altio; /* altio addr resource handle */
struct resource *r_bmio; /* bmio addr resource handle */
@ -308,6 +308,7 @@ struct ata_softc {
#define ATA_USE_16BIT 0x04
#define ATA_ATTACHED 0x08
#define ATA_QUEUED 0x10
#define ATA_RAID 0x20
int devices; /* what is present */
#define ATA_ATA_MASTER 0x01
@ -332,7 +333,7 @@ struct ata_softc {
void *running; /* currently running request */
};
/* To convert unit numbers to devices */
/* externs */
extern devclass_t ata_devclass;
/* public prototypes */

View File

@ -78,7 +78,7 @@ ata_dmainit(struct ata_softc *scp, int device,
int apiomode, int wdmamode, int udmamode)
{
device_t parent = device_get_parent(scp->dev);
int devno = (scp->unit << 1) + ATA_DEV(device);
int devno = (scp->channel << 1) + ATA_DEV(device);
int error;
/* set our most pessimistic default mode */
@ -88,7 +88,7 @@ ata_dmainit(struct ata_softc *scp, int device,
return;
/* if simplex controller, only allow DMA on primary channel */
if (scp->unit == 1) {
if (scp->channel == 1) {
outb(scp->bmaddr + ATA_BMSTAT_PORT, inb(scp->bmaddr + ATA_BMSTAT_PORT) &
(ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
if (inb(scp->bmaddr + ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX) {
@ -203,7 +203,7 @@ ata_dmainit(struct ata_softc *scp, int device,
int32_t mask40, new40, mask44, new44;
/* if SITRE not set doit for both channels */
if (!((pci_read_config(parent, 0x40, 4)>>(scp->unit<<8))&0x4000)){
if (!((pci_read_config(parent,0x40,4)>>(scp->channel<<8))&0x4000)) {
new40 = pci_read_config(parent, 0x40, 4);
new44 = pci_read_config(parent, 0x44, 4);
if (!(new40 & 0x00004000)) {
@ -240,7 +240,7 @@ ata_dmainit(struct ata_softc *scp, int device,
mask44 = 0x0000000f;
new44 = 0x0000000b;
}
if (scp->unit) {
if (scp->channel) {
mask40 <<= 16;
new40 <<= 16;
mask44 <<= 4;
@ -264,7 +264,7 @@ ata_dmainit(struct ata_softc *scp, int device,
int32_t word40;
word40 = pci_read_config(parent, 0x40, 4);
word40 >>= scp->unit * 16;
word40 >>= scp->channel * 16;
/* Check for timing config usable for DMA on controller */
if (!((word40 & 0x3300) == 0x2300 &&
@ -452,10 +452,10 @@ ata_dmainit(struct ata_softc *scp, int device,
ata_printf(scp, device, "%s setting UDMA5 on CMD chip\n",
(error) ? "failed" : "success");
if (!error) {
umode = pci_read_config(parent, scp->unit ? 0x7b : 0x73, 1);
umode = pci_read_config(parent, scp->channel ? 0x7b : 0x73, 1);
umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
umode |= (device == ATA_MASTER ? 0x05 : 0x0a);
pci_write_config(parent, scp->unit ? 0x7b : 0x73, umode, 1);
pci_write_config(parent, scp->channel ? 0x7b : 0x73, umode, 1);
scp->mode[ATA_DEV(device)] = ATA_UDMA5;
return;
}
@ -472,10 +472,10 @@ ata_dmainit(struct ata_softc *scp, int device,
ata_printf(scp, device, "%s setting UDMA4 on CMD chip\n",
(error) ? "failed" : "success");
if (!error) {
umode = pci_read_config(parent, scp->unit ? 0x7b : 0x73, 1);
umode = pci_read_config(parent, scp->channel ? 0x7b : 0x73, 1);
umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
umode |= (device == ATA_MASTER ? 0x15 : 0x4a);
pci_write_config(parent, scp->unit ? 0x7b : 0x73, umode, 1);
pci_write_config(parent, scp->channel ? 0x7b : 0x73, umode, 1);
scp->mode[ATA_DEV(device)] = ATA_UDMA4;
return;
}
@ -489,17 +489,17 @@ ata_dmainit(struct ata_softc *scp, int device,
ata_printf(scp, device, "%s setting UDMA2 on CMD chip\n",
(error) ? "failed" : "success");
if (!error) {
umode = pci_read_config(parent, scp->unit ? 0x7b : 0x73, 1);
umode = pci_read_config(parent, scp->channel ? 0x7b : 0x73, 1);
umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
umode |= (device == ATA_MASTER ? 0x11 : 0x42);
pci_write_config(parent, scp->unit ? 0x7b : 0x73, umode, 1);
pci_write_config(parent, scp->channel ? 0x7b : 0x73, umode, 1);
scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return;
}
}
/* make sure eventual UDMA mode from the BIOS is disabled */
pci_write_config(parent, scp->unit ? 0x7b : 0x73,
pci_read_config(parent, scp->unit ? 0x7b : 0x73, 1) &
pci_write_config(parent, scp->channel ? 0x7b : 0x73,
pci_read_config(parent, scp->channel ? 0x7b : 0x73, 1) &
~(device == ATA_MASTER ? 0x35 : 0xca), 1);
/* FALLTHROUGH */
@ -530,7 +530,7 @@ ata_dmainit(struct ata_softc *scp, int device,
"%s setting WDMA2 on Cypress chip\n",
error ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, scp->unit ? 0x4e : 0x4c, 0x2020, 2);
pci_write_config(scp->dev, scp->channel ? 0x4e:0x4c, 0x2020, 2);
scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return;
}
@ -605,7 +605,7 @@ ata_dmainit(struct ata_softc *scp, int device,
"%s setting WDMA2 on ServerWorks chip\n",
(error) ? "failed" : "success");
if (!error) {
int offset = (scp->unit * 2) + (device == ATA_MASTER);
int offset = (scp->channel * 2) + (device == ATA_MASTER);
int word44 = pci_read_config(parent, 0x44, 4);
pci_write_config(parent, 0x54,
@ -632,7 +632,7 @@ ata_dmainit(struct ata_softc *scp, int device,
if (udmamode >= 5 &&
(scp->chiptype == 0x4d30105a || scp->chiptype == 0x0d30105a) &&
!(pci_read_config(parent, 0x50, 2)&(scp->unit ? 1<<11 : 1<<10))) {
!(pci_read_config(parent, 0x50, 2)&(scp->channel ? 1<<11 : 1<<10))){
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
@ -647,7 +647,7 @@ ata_dmainit(struct ata_softc *scp, int device,
}
if (udmamode >= 4 && (scp->chiptype == 0x4d38105a ||
scp->chiptype == 0x4d30105a || scp->chiptype == 0x0d30105a) &&
!(pci_read_config(parent, 0x50, 2)&(scp->unit ? 1<<11 : 1<<10))) {
!(pci_read_config(parent, 0x50, 2)&(scp->channel ? 1<<11 : 1<<10))){
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
@ -705,7 +705,7 @@ ata_dmainit(struct ata_softc *scp, int device,
break;
if (udmamode >=5 && pci_get_revid(parent) >= 0x03 &&
!(pci_read_config(parent, 0x5a, 1) & (scp->unit ? 0x01 : 0x02))) {
!(pci_read_config(parent, 0x5a, 1) & (scp->channel ? 0x01:0x02))) {
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
@ -719,7 +719,7 @@ ata_dmainit(struct ata_softc *scp, int device,
}
}
if (udmamode >=4 &&
!(pci_read_config(parent, 0x5a, 1) & (scp->unit ? 0x01 : 0x02))) {
!(pci_read_config(parent, 0x5a, 1) & (scp->channel ? 0x01:0x02))) {
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)