Change the ata_* methods to use a channel device instead of a

controller device. This helps when there is no controller parent
to a channel (PPC port).
This commit is contained in:
Søren Schmidt 2005-03-31 15:05:40 +00:00
parent f9bd71b713
commit 5a5b148dd8
11 changed files with 154 additions and 155 deletions

View File

@ -123,10 +123,10 @@ ata_attach(device_t dev)
TAILQ_INIT(&ch->ata_queue);
/* initialise device(s) on this channel */
while (ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_LOCK) != ch->unit)
while (ATA_LOCKING(dev, ATA_LF_LOCK) != ch->unit)
tsleep(&error, PRIBIO, "ataatch", 1);
ch->hw.reset(ch);
ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_UNLOCK);
ATA_LOCKING(dev, ATA_LF_UNLOCK);
/* setup interrupt delivery */
rid = ATA_IRQ_RID;
@ -197,7 +197,7 @@ ata_reinit(device_t dev)
device_printf(dev, "reiniting channel ..\n");
/* poll for locking the channel */
while (ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_LOCK) != ch->unit)
while (ATA_LOCKING(dev, ATA_LF_LOCK) != ch->unit)
tsleep(&dev, PRIBIO, "atarini", 1);
/* grap the channel lock */
@ -234,7 +234,7 @@ ata_reinit(device_t dev)
mtx_lock(&ch->state_mtx);
ch->state = ATA_IDLE;
mtx_unlock(&ch->state_mtx);
ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_UNLOCK);
ATA_LOCKING(dev, ATA_LF_UNLOCK);
if (bootverbose)
device_printf(dev, "reinit done ..\n");
@ -263,7 +263,7 @@ ata_suspend(device_t dev)
mtx_unlock(&ch->state_mtx);
tsleep(ch, PRIBIO, "atasusp", hz/10);
}
ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_UNLOCK);
ATA_LOCKING(dev, ATA_LF_UNLOCK);
return 0;
}
@ -324,7 +324,7 @@ ata_interrupt(void *data)
if (ch->state == ATA_ACTIVE)
ch->state = ATA_IDLE;
mtx_unlock(&ch->state_mtx);
ATA_LOCKING(device_get_parent(ch->dev), ch->dev, ATA_LF_UNLOCK);
ATA_LOCKING(ch->dev, ATA_LF_UNLOCK);
ata_finish(request);
return;
}
@ -426,12 +426,12 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
if (atadev->unit == ATA_MASTER) {
atadev->mode = iocmd->u.mode.mode[0];
ATA_SETMODE(device_get_parent(device), children[i]);
ATA_SETMODE(device, children[i]);
iocmd->u.mode.mode[0] = atadev->mode;
}
if (atadev->unit == ATA_SLAVE) {
atadev->mode = iocmd->u.mode.mode[1];
ATA_SETMODE(device_get_parent(device), children[i]);
ATA_SETMODE(device, children[i]);
iocmd->u.mode.mode[1] = atadev->mode;
}
}
@ -622,7 +622,7 @@ ata_identify(driver_t *driver, device_t parent, int type, const char *name)
slave->unit = ATA_SLAVE;
/* wait for the channel to be IDLE then grab it before touching HW */
while (ATA_LOCKING(device_get_parent(parent),parent,ATA_LF_LOCK)!=ch->unit)
while (ATA_LOCKING(parent, ATA_LF_LOCK) != ch->unit)
tsleep(ch, PRIBIO, "ataidnt2", 1);
while (1) {
mtx_lock(&ch->state_mtx);
@ -665,7 +665,7 @@ ata_identify(driver_t *driver, device_t parent, int type, const char *name)
mtx_lock(&ch->state_mtx);
ch->state = ATA_IDLE;
mtx_unlock(&ch->state_mtx);
ATA_LOCKING(device_get_parent(parent), parent, ATA_LF_UNLOCK);
ATA_LOCKING(parent, ATA_LF_UNLOCK);
}
void

View File

@ -67,7 +67,7 @@ struct ata_cbus_controller {
/* local prototypes */
static void ata_cbus_intr(void *);
static int ata_cbus_banking(device_t parent, device_t dev, int flags);
static int ata_cbuschannel_banking(device_t dev, int flags);
static int
ata_cbus_probe(device_t dev)
@ -229,16 +229,69 @@ ata_cbus_intr(void *data)
for (unit = 0; unit < 2; unit++) {
if (!(ch = ctlr->interrupt[unit].argument))
continue;
if (ata_cbus_banking(device_get_parent(ch->dev), ch->dev,
ATA_LF_WHICH) == unit)
if (ata_cbuschannel_banking(ch->dev, ATA_LF_WHICH) == unit)
ctlr->interrupt[unit].function(ch);
}
}
static device_method_t ata_cbus_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ata_cbus_probe),
DEVMETHOD(device_attach, ata_cbus_attach),
// DEVMETHOD(device_detach, ata_cbus_detach),
/* bus methods */
DEVMETHOD(bus_alloc_resource, ata_cbus_alloc_resource),
DEVMETHOD(bus_setup_intr, ata_cbus_setup_intr),
DEVMETHOD(bus_print_child, ata_cbus_print_child),
{ 0, 0 }
};
static driver_t ata_cbus_driver = {
"atacbus",
ata_cbus_methods,
sizeof(struct ata_cbus_controller),
};
static devclass_t ata_cbus_devclass;
DRIVER_MODULE(atacbus, isa, ata_cbus_driver, ata_cbus_devclass, 0, 0);
static int
ata_cbus_banking(device_t parent, device_t dev, int flags)
ata_cbuschannel_probe(device_t dev)
{
struct ata_cbus_controller *ctlr = device_get_softc(parent);
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_STATUS; i ++) {
ch->r_io[i].res = ctlr->io;
ch->r_io[i].offset = i << 1;
}
ch->r_io[ATA_ALTSTAT].res = ctlr->altio;
ch->r_io[ATA_ALTSTAT].offset = 0;
/* initialize softc for this channel */
ch->flags |= ATA_USE_16BIT;
ata_generic_hw(ch);
return ata_probe(dev);
}
static int
ata_cbuschannel_banking(device_t dev, int flags)
{
struct ata_cbus_controller *ctlr = device_get_softc(device_get_parent(dev));
struct ata_channel *ch = device_get_softc(dev);
int res;
@ -277,77 +330,25 @@ ata_cbus_banking(device_t parent, device_t dev, int flags)
return res;
}
static device_method_t ata_cbus_methods[] = {
static device_method_t ata_cbuschannel_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ata_cbus_probe),
DEVMETHOD(device_attach, ata_cbus_attach),
// DEVMETHOD(device_detach, ata_cbus_detach),
/* bus methods */
DEVMETHOD(bus_alloc_resource, ata_cbus_alloc_resource),
DEVMETHOD(bus_setup_intr, ata_cbus_setup_intr),
DEVMETHOD(bus_print_child, ata_cbus_print_child),
/* ATA methods */
DEVMETHOD(ata_locking, ata_cbus_banking),
{ 0, 0 }
};
static driver_t ata_cbus_driver = {
"atacbus",
ata_cbus_methods,
sizeof(struct ata_cbus_controller),
};
static devclass_t ata_cbus_devclass;
DRIVER_MODULE(atacbus, isa, ata_cbus_driver, ata_cbus_devclass, 0, 0);
static int
ata_cbussub_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_STATUS; i ++) {
ch->r_io[i].res = ctlr->io;
ch->r_io[i].offset = i << 1;
}
ch->r_io[ATA_ALTSTAT].res = ctlr->altio;
ch->r_io[ATA_ALTSTAT].offset = 0;
/* initialize softc for this channel */
ch->flags |= ATA_USE_16BIT;
ata_generic_hw(ch);
return ata_probe(dev);
}
static device_method_t ata_cbussub_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ata_cbussub_probe),
DEVMETHOD(device_probe, ata_cbuschannel_probe),
DEVMETHOD(device_attach, ata_attach),
DEVMETHOD(device_detach, ata_detach),
DEVMETHOD(device_suspend, ata_suspend),
DEVMETHOD(device_resume, ata_resume),
/* ATA methods */
DEVMETHOD(ata_locking, ata_cbuschannel_banking),
{ 0, 0 }
};
static driver_t ata_cbussub_driver = {
static driver_t ata_cbuschannel_driver = {
"ata",
ata_cbussub_methods,
ata_cbuschannel_methods,
sizeof(struct ata_channel),
};
DRIVER_MODULE(ata, atacbus, ata_cbussub_driver, ata_devclass, 0, 0);
DRIVER_MODULE(ata, atacbus, ata_cbuschannel_driver, ata_devclass, 0, 0);
MODULE_DEPEND(ata, ata, 1, 1, 1);

View File

@ -305,8 +305,7 @@ ata_acard_intr(void *data)
if (!(ch = ctlr->interrupt[unit].argument))
continue;
if (ctlr->chip->cfg1 == ATPOLD &&
ATA_LOCKING(device_get_parent(ch->dev),
ch->dev, ATA_LF_WHICH) != unit)
ATA_LOCKING(ch->dev, ATA_LF_WHICH) != unit)
continue;
if (ch->dma && (ch->dma->flags & ATA_DMA_ACTIVE)) {
int bmstat = ATA_IDX_INB(ch, ATA_BMSTAT_PORT) & ATA_BMSTAT_MASK;

View File

@ -337,7 +337,7 @@ ad_init(device_t dev)
{
struct ata_device *atadev = device_get_softc(dev);
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
/* enable read caching */
ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_ENAB_RCACHE, 0, 0);
@ -434,7 +434,7 @@ static device_method_t ad_methods[] = {
static driver_t ad_driver = {
"ad",
ad_methods,
sizeof(struct ad_softc)
0,
};
devclass_t ad_devclass;

View File

@ -619,7 +619,7 @@ ata_generic_reset(struct ata_channel *ch)
}
/* reset host end of channel (if supported) */
ATA_RESET(device_get_parent(ch->dev), ch->dev);
ATA_RESET(ch->dev);
/* do we have any signs of ATA/ATAPI HW being present ? */
ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_D_LBA | ATA_MASTER);

View File

@ -391,14 +391,12 @@ ata_pci_allocate(device_t dev, struct ata_channel *ch)
int i, rid;
rid = ATA_IOADDR_RID;
io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, ATA_IOSIZE, RF_ACTIVE);
io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
if (!io)
return ENXIO;
rid = ATA_ALTADDR_RID;
altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0, ~0, ATA_ALTIOSIZE, RF_ACTIVE);
altio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
if (!altio) {
bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
return ENXIO;
@ -424,40 +422,6 @@ ata_pci_allocate(device_t dev, struct ata_channel *ch)
return 0;
}
static void
ata_pci_setmode(device_t parent, device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(parent);
struct ata_device *atadev = device_get_softc(dev);
int mode = atadev->mode;
ctlr->setmode(atadev, ATA_PIO_MAX);
if (mode >= ATA_DMA)
ctlr->setmode(atadev, mode);
}
static int
ata_pci_locking(device_t parent, device_t dev, int mode)
{
struct ata_pci_controller *ctlr = device_get_softc(parent);
struct ata_channel *ch = device_get_softc(dev);
if (ctlr->locking)
return ctlr->locking(ch, mode);
else
return ch->unit;
}
static void
ata_pci_reset(device_t parent, device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(parent);
struct ata_channel *ch = device_get_softc(dev);
if (ctlr->reset)
ctlr->reset(ch);
}
static int
ata_pci_dmastart(struct ata_channel *ch)
{
@ -512,10 +476,6 @@ static device_method_t ata_pci_methods[] = {
DEVMETHOD(bus_setup_intr, ata_pci_setup_intr),
DEVMETHOD(bus_teardown_intr, ata_pci_teardown_intr),
/* ATA methods */
DEVMETHOD(ata_setmode, ata_pci_setmode),
DEVMETHOD(ata_locking, ata_pci_locking),
DEVMETHOD(ata_reset, ata_pci_reset),
{ 0, 0 }
};
@ -532,7 +492,7 @@ MODULE_VERSION(atapci, 1);
MODULE_DEPEND(atapci, ata, 1, 1, 1);
static int
ata_channel_probe(device_t dev)
ata_pcichannel_probe(device_t dev)
{
struct ata_channel *ch = device_get_softc(dev);
device_t *children;
@ -557,7 +517,7 @@ ata_channel_probe(device_t dev)
}
static int
ata_channel_attach(device_t dev)
ata_pcichannel_attach(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
struct ata_channel *ch = device_get_softc(dev);
@ -575,7 +535,7 @@ ata_channel_attach(device_t dev)
}
static int
ata_channel_detach(device_t dev)
ata_pcichannel_detach(device_t dev)
{
struct ata_channel *ch = device_get_softc(dev);
int error;
@ -589,21 +549,61 @@ ata_channel_detach(device_t dev)
return 0;
}
static device_method_t ata_channel_methods[] = {
static int
ata_pcichannel_locking(device_t dev, int mode)
{
struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
struct ata_channel *ch = device_get_softc(dev);
if (ctlr->locking)
return ctlr->locking(ch, mode);
else
return ch->unit;
}
static void
ata_pcichannel_reset(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
struct ata_channel *ch = device_get_softc(dev);
if (ctlr->reset)
ctlr->reset(ch);
}
static void
ata_pcichannel_setmode(device_t parent, device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev));
struct ata_device *atadev = device_get_softc(dev);
int mode = atadev->mode;
ctlr->setmode(atadev, ATA_PIO_MAX);
if (mode >= ATA_DMA)
ctlr->setmode(atadev, mode);
}
static device_method_t ata_pcichannel_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ata_channel_probe),
DEVMETHOD(device_attach, ata_channel_attach),
DEVMETHOD(device_detach, ata_channel_detach),
DEVMETHOD(device_probe, ata_pcichannel_probe),
DEVMETHOD(device_attach, ata_pcichannel_attach),
DEVMETHOD(device_detach, ata_pcichannel_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
/* ATA methods */
DEVMETHOD(ata_setmode, ata_pcichannel_setmode),
DEVMETHOD(ata_locking, ata_pcichannel_locking),
DEVMETHOD(ata_reset, ata_pcichannel_reset),
{ 0, 0 }
};
driver_t ata_channel_driver = {
driver_t ata_pcichannel_driver = {
"ata",
ata_channel_methods,
ata_pcichannel_methods,
sizeof(struct ata_channel),
};
DRIVER_MODULE(ata, atapci, ata_channel_driver, ata_devclass, 0, 0);
DRIVER_MODULE(ata, atapci, ata_pcichannel_driver, ata_devclass, 0, 0);

View File

@ -172,7 +172,7 @@ ata_start(device_t dev)
if ((request = TAILQ_FIRST(&ch->ata_queue))) {
/* we need the locking function to get the lock for this channel */
if (ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_LOCK) == ch->unit) {
if (ATA_LOCKING(dev, ATA_LF_LOCK) == ch->unit) {
/* check for composite dependencies */
if ((cptr = request->composite)) {
@ -211,7 +211,7 @@ ata_start(device_t dev)
ch->state = ATA_IDLE;
mtx_unlock(&ch->state_mtx);
mtx_unlock(&ch->queue_mtx);
ATA_LOCKING(device_get_parent(dev), dev, ATA_LF_UNLOCK);
ATA_LOCKING(dev, ATA_LF_UNLOCK);
ata_finish(request);
return;
}
@ -492,7 +492,7 @@ ata_timeout(struct ata_request *request)
ch->hw.end_transaction(request);
ch->state |= ATA_TIMEOUT;
mtx_unlock(&ch->state_mtx);
ATA_LOCKING(device_get_parent(ch->dev), ch->dev, ATA_LF_UNLOCK);
ATA_LOCKING(ch->dev, ATA_LF_UNLOCK);
ata_finish(request);
}
else {

View File

@ -41,24 +41,17 @@
INTERFACE ata;
CODE {
static int ata_null_locking(device_t parent, device_t dev, int mode)
static int ata_null_locking(device_t dev, int mode)
{
struct ata_channel *ch = device_get_softc(dev);
return ch->unit;
}
};
METHOD void setmode {
device_t parent;
device_t dev;
};
METHOD int locking {
device_t parent;
device_t dev;
device_t channel;
int mode;
} DEFAULT ata_null_locking;
HEADER {
#define ATA_LF_LOCK 0x0001
#define ATA_LF_UNLOCK 0x0002
@ -66,10 +59,16 @@ HEADER {
};
METHOD void reset {
device_t parent;
device_t channel;
};
METHOD void setmode {
device_t channel;
device_t dev;
};
METHOD int reinit {
device_t dev;
};

View File

@ -130,7 +130,7 @@ acd_attach(device_t dev)
}
cdp->block_size = 2048;
device_set_ivars(dev, cdp);
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
acd_get_cap(dev);
g_post_event(acd_geom_attach, dev, M_WAITOK, NULL);
@ -168,7 +168,7 @@ acd_reinit(device_t dev)
free(cdp, M_ACD);
return 1;
}
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
return 0;
}
@ -1935,7 +1935,7 @@ static device_method_t acd_methods[] = {
static driver_t acd_driver = {
"acd",
acd_methods,
sizeof(struct acd_softc)
0,
};
static devclass_t acd_devclass;

View File

@ -88,7 +88,7 @@ afd_attach(device_t dev)
return ENOMEM;
}
device_set_ivars(dev, fdp);
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
if (afd_sense(dev)) {
device_set_ivars(dev, NULL);
@ -161,7 +161,7 @@ afd_reinit(device_t dev)
free(fdp, M_AFD);
return 1;
}
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
return 0;
}
@ -415,7 +415,7 @@ static device_method_t afd_methods[] = {
static driver_t afd_driver = {
"afd",
afd_methods,
sizeof(struct afd_softc)
0,
};
static devclass_t afd_devclass;

View File

@ -115,7 +115,7 @@ ast_attach(device_t dev)
return ENOMEM;
}
device_set_ivars(dev, stp);
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
if (ast_sense(dev)) {
device_set_ivars(dev, NULL);
@ -213,7 +213,7 @@ ast_reinit(device_t dev)
free(stp, M_AST);
return 1;
}
ATA_SETMODE(GRANDPARENT(dev), dev);
ATA_SETMODE(device_get_parent(dev), dev);
return 0;
}
@ -767,7 +767,7 @@ static device_method_t ast_methods[] = {
static driver_t ast_driver = {
"ast",
ast_methods,
sizeof(struct ast_softc)
0,
};
static devclass_t ast_devclass;