From cab8300efb093a6b9c235bcd30eaa96024ced0c5 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Sat, 21 Dec 2013 00:07:56 +0000 Subject: [PATCH] Add suspend/resume to DBDMA and ATA on PowerMacs. This, and several subsequent commits, are suspend/resume for various PowerMac drivers, which will include a change to the global suspend/resume code eventually. --- sys/powerpc/powermac/ata_macio.c | 35 ++++++++++++++++++++++++++++++++ sys/powerpc/powermac/dbdma.c | 25 +++++++++++++++++++++++ sys/powerpc/powermac/dbdmavar.h | 1 + 3 files changed, 61 insertions(+) diff --git a/sys/powerpc/powermac/ata_macio.c b/sys/powerpc/powermac/ata_macio.c index 85056642a466..78fa60d89465 100644 --- a/sys/powerpc/powermac/ata_macio.c +++ b/sys/powerpc/powermac/ata_macio.c @@ -114,11 +114,15 @@ static int ata_macio_probe(device_t dev); static int ata_macio_setmode(device_t dev, int target, int mode); static int ata_macio_attach(device_t dev); static int ata_macio_begin_transaction(struct ata_request *request); +static int ata_macio_suspend(device_t dev); +static int ata_macio_resume(device_t dev); static device_method_t ata_macio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ata_macio_probe), DEVMETHOD(device_attach, ata_macio_attach), + DEVMETHOD(device_suspend, ata_macio_suspend), + DEVMETHOD(device_resume, ata_macio_resume), /* ATA interface */ DEVMETHOD(ata_setmode, ata_macio_setmode), @@ -336,3 +340,34 @@ ata_macio_begin_transaction(struct ata_request *request) return ata_begin_transaction(request); } + +static int +ata_macio_suspend(device_t dev) +{ + struct ata_dbdma_channel *ch = device_get_softc(dev); + int error; + + if (!ch->sc_ch.attached) + return (0); + + error = ata_suspend(dev); + dbdma_save_state(ch->dbdma); + + return (error); +} + +static int +ata_macio_resume(device_t dev) +{ + struct ata_dbdma_channel *ch = device_get_softc(dev); + int error; + + if (!ch->sc_ch.attached) + return (0); + + dbdma_restore_state(ch->dbdma); + error = ata_resume(dev); + + return (error); +} + diff --git a/sys/powerpc/powermac/dbdma.c b/sys/powerpc/powermac/dbdma.c index 6712c1a79ff4..8e8c582dc8c6 100644 --- a/sys/powerpc/powermac/dbdma.c +++ b/sys/powerpc/powermac/dbdma.c @@ -343,6 +343,31 @@ dbdma_sync_commands(dbdma_channel_t *chan, bus_dmasync_op_t op) bus_dmamap_sync(chan->sc_dmatag, chan->sc_dmamap, op); } +void +dbdma_save_state(dbdma_channel_t *chan) +{ + + chan->sc_saved_regs[0] = dbdma_read_reg(chan, CHAN_CMDPTR); + chan->sc_saved_regs[1] = dbdma_read_reg(chan, CHAN_CMDPTR_HI); + chan->sc_saved_regs[2] = dbdma_read_reg(chan, CHAN_INTR_SELECT); + chan->sc_saved_regs[3] = dbdma_read_reg(chan, CHAN_BRANCH_SELECT); + chan->sc_saved_regs[4] = dbdma_read_reg(chan, CHAN_WAIT_SELECT); + + dbdma_stop(chan); +} + +void +dbdma_restore_state(dbdma_channel_t *chan) +{ + + dbdma_wake(chan); + dbdma_write_reg(chan, CHAN_CMDPTR, chan->sc_saved_regs[0]); + dbdma_write_reg(chan, CHAN_CMDPTR_HI, chan->sc_saved_regs[1]); + dbdma_write_reg(chan, CHAN_INTR_SELECT, chan->sc_saved_regs[2]); + dbdma_write_reg(chan, CHAN_BRANCH_SELECT, chan->sc_saved_regs[3]); + dbdma_write_reg(chan, CHAN_WAIT_SELECT, chan->sc_saved_regs[4]); +} + static uint32_t dbdma_read_reg(dbdma_channel_t *chan, u_int offset) { diff --git a/sys/powerpc/powermac/dbdmavar.h b/sys/powerpc/powermac/dbdmavar.h index 2916b6a04e45..0b89618bafbf 100644 --- a/sys/powerpc/powermac/dbdmavar.h +++ b/sys/powerpc/powermac/dbdmavar.h @@ -60,6 +60,7 @@ struct dbdma_channel { bus_dma_tag_t sc_dmatag; bus_dmamap_t sc_dmamap; + uint32_t sc_saved_regs[5]; };