/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008 Nathan Whitehorn4* All rights reserved5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _MACHINE_DBDMA_H_29#define _MACHINE_DBDMA_H_3031#include <sys/param.h>32#include <machine/bus.h>3334/*35* Apple's DBDMA (Descriptor-based DMA) interface is a common DMA engine36* used by a variety of custom Apple ASICs. It is described in the CHRP37* specification and in the book Macintosh Technology in the Common38* Hardware Reference Platform, copyright 1995 Apple Computer.39*/4041/* DBDMA Command Values */4243enum {44DBDMA_OUTPUT_MORE = 0,45DBDMA_OUTPUT_LAST = 1,46DBDMA_INPUT_MORE = 2,47DBDMA_INPUT_LAST = 3,4849DBDMA_STORE_QUAD = 4,50DBDMA_LOAD_QUAD = 5,51DBDMA_NOP = 6,52DBDMA_STOP = 753};5455/* These codes are for the interrupt, branch, and wait flags */5657enum {58DBDMA_NEVER = 0,59DBDMA_COND_TRUE = 1,60DBDMA_COND_FALSE = 2,61DBDMA_ALWAYS = 362};6364/* Channel status bits */65#define DBDMA_STATUS_RUN (0x01 << 15)66#define DBDMA_STATUS_PAUSE (0x01 << 14)67#define DBDMA_STATUS_FLUSH (0x01 << 13)68#define DBDMA_STATUS_WAKE (0x01 << 12)69#define DBDMA_STATUS_DEAD (0x01 << 11)70#define DBDMA_STATUS_ACTIVE (0x01 << 10)7172/* Set by hardware if a branch was taken */73#define DBDMA_STATUS_BRANCH 87475struct dbdma_command;76typedef struct dbdma_command dbdma_command_t;77struct dbdma_channel;78typedef struct dbdma_channel dbdma_channel_t;7980int dbdma_allocate_channel(struct resource *dbdma_regs, u_int offset,81bus_dma_tag_t parent_dma, int slots, dbdma_channel_t **chan);8283int dbdma_resize_channel(dbdma_channel_t *chan, int newslots);84int dbdma_free_channel(dbdma_channel_t *chan);8586void dbdma_run(dbdma_channel_t *chan);87void dbdma_stop(dbdma_channel_t *chan);88void dbdma_reset(dbdma_channel_t *chan);89void dbdma_set_current_cmd(dbdma_channel_t *chan, int slot);9091void dbdma_pause(dbdma_channel_t *chan);92void dbdma_wake(dbdma_channel_t *chan);9394/*95* DBDMA uses a 16 bit channel control register to describe the current96* state of DMA on the channel. The high-order bits (8-15) contain information97* on the run state and are listed in the DBDMA_STATUS_* constants above. These98* are manipulated with the dbdma_run/stop/reset() routines above.99*100* The low order bits (0-7) are device dependent status bits. These can be set101* and read by both hardware and software. The mask is the set of bits to102* modify; if mask is 0x03 and value is 0, the lowest order 2 bits will be103* zeroed.104*/105106uint16_t dbdma_get_chan_status(dbdma_channel_t *chan);107108uint8_t dbdma_get_device_status(dbdma_channel_t *chan);109void dbdma_set_device_status(dbdma_channel_t *chan, uint8_t mask,110uint8_t value);111112/*113* Each DBDMA command word has the current channel status register and the114* number of residual bytes (requested - actually transferred) written to it115* at time of command completion.116*/117118uint16_t dbdma_get_cmd_status(dbdma_channel_t *chan, int slot);119uint16_t dbdma_get_residuals(dbdma_channel_t *chan, int slot);120121void dbdma_clear_cmd_status(dbdma_channel_t *chan, int slot);122123/*124* The interrupt/branch/wait selector let you specify a set of values125* of the device dependent status bits that will cause intterupt/branch/wait126* conditions to be taken if the flags for these are set to one of the127* DBDMA_COND_* values.128*129* The condition is considered true if (status & mask) == value.130*/131132void dbdma_set_interrupt_selector(dbdma_channel_t *chan, uint8_t mask,133uint8_t value);134void dbdma_set_branch_selector(dbdma_channel_t *chan, uint8_t mask,135uint8_t value);136void dbdma_set_wait_selector(dbdma_channel_t *chan, uint8_t mask,137uint8_t value);138139void dbdma_insert_command(dbdma_channel_t *chan, int slot, int command,140int stream, bus_addr_t data, size_t count, uint8_t interrupt,141uint8_t branch, uint8_t wait, uint32_t branch_slot);142143void dbdma_insert_stop(dbdma_channel_t *chan, int slot);144void dbdma_insert_nop(dbdma_channel_t *chan, int slot);145void dbdma_insert_branch(dbdma_channel_t *chan, int slot, int to_slot);146147void dbdma_sync_commands(dbdma_channel_t *chan, bus_dmasync_op_t op);148149void dbdma_save_state(dbdma_channel_t *chan);150void dbdma_restore_state(dbdma_channel_t *chan);151152#endif /* _MACHINE_DBDMA_H_ */153154155