xref: /freebsd/sys/powerpc/include/dbdma.h (revision 95ee2897)
17d8ccad7SMarcel Moolenaar /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
47d8ccad7SMarcel Moolenaar  * Copyright (c) 2008 Nathan Whitehorn
57d8ccad7SMarcel Moolenaar  * All rights reserved
67d8ccad7SMarcel Moolenaar  *
77d8ccad7SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
87d8ccad7SMarcel Moolenaar  * modification, are permitted provided that the following conditions
97d8ccad7SMarcel Moolenaar  * are met:
107d8ccad7SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
117d8ccad7SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
127d8ccad7SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
137d8ccad7SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
147d8ccad7SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
157d8ccad7SMarcel Moolenaar  *
167d8ccad7SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177d8ccad7SMarcel Moolenaar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
187d8ccad7SMarcel Moolenaar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
197d8ccad7SMarcel Moolenaar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
207d8ccad7SMarcel Moolenaar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
217d8ccad7SMarcel Moolenaar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
227d8ccad7SMarcel Moolenaar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
237d8ccad7SMarcel Moolenaar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
247d8ccad7SMarcel Moolenaar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
257d8ccad7SMarcel Moolenaar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267d8ccad7SMarcel Moolenaar  * SUCH DAMAGE.
277d8ccad7SMarcel Moolenaar  */
287d8ccad7SMarcel Moolenaar 
297d8ccad7SMarcel Moolenaar #ifndef _MACHINE_DBDMA_H_
307d8ccad7SMarcel Moolenaar #define _MACHINE_DBDMA_H_
317d8ccad7SMarcel Moolenaar 
327d8ccad7SMarcel Moolenaar #include <sys/param.h>
337d8ccad7SMarcel Moolenaar #include <machine/bus.h>
347d8ccad7SMarcel Moolenaar 
357d8ccad7SMarcel Moolenaar /*
367d8ccad7SMarcel Moolenaar  * Apple's DBDMA (Descriptor-based DMA) interface is a common DMA engine
377d8ccad7SMarcel Moolenaar  * used by a variety of custom Apple ASICs. It is described in the CHRP
387d8ccad7SMarcel Moolenaar  * specification and in the book Macintosh Technology in the Common
397d8ccad7SMarcel Moolenaar  * Hardware Reference Platform, copyright 1995 Apple Computer.
407d8ccad7SMarcel Moolenaar  */
417d8ccad7SMarcel Moolenaar 
427d8ccad7SMarcel Moolenaar /* DBDMA Command Values */
437d8ccad7SMarcel Moolenaar 
447d8ccad7SMarcel Moolenaar enum {
457d8ccad7SMarcel Moolenaar 	DBDMA_OUTPUT_MORE	= 0,
467d8ccad7SMarcel Moolenaar 	DBDMA_OUTPUT_LAST	= 1,
477d8ccad7SMarcel Moolenaar 	DBDMA_INPUT_MORE	= 2,
487d8ccad7SMarcel Moolenaar 	DBDMA_INPUT_LAST	= 3,
497d8ccad7SMarcel Moolenaar 
507d8ccad7SMarcel Moolenaar 	DBDMA_STORE_QUAD	= 4,
517d8ccad7SMarcel Moolenaar 	DBDMA_LOAD_QUAD		= 5,
527d8ccad7SMarcel Moolenaar 	DBDMA_NOP		= 6,
537d8ccad7SMarcel Moolenaar 	DBDMA_STOP		= 7
547d8ccad7SMarcel Moolenaar };
557d8ccad7SMarcel Moolenaar 
567d8ccad7SMarcel Moolenaar /* These codes are for the interrupt, branch, and wait flags */
577d8ccad7SMarcel Moolenaar 
587d8ccad7SMarcel Moolenaar enum {
597d8ccad7SMarcel Moolenaar 	DBDMA_NEVER		= 0,
607d8ccad7SMarcel Moolenaar 	DBDMA_COND_TRUE		= 1,
617d8ccad7SMarcel Moolenaar 	DBDMA_COND_FALSE	= 2,
627d8ccad7SMarcel Moolenaar 	DBDMA_ALWAYS		= 3
637d8ccad7SMarcel Moolenaar };
647d8ccad7SMarcel Moolenaar 
657d8ccad7SMarcel Moolenaar /* Channel status bits */
667d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_RUN    (0x01 << 15)
677d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_PAUSE  (0x01 << 14)
687d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_FLUSH  (0x01 << 13)
697d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_WAKE   (0x01 << 12)
707d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_DEAD   (0x01 << 11)
717d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_ACTIVE (0x01 << 10)
727d8ccad7SMarcel Moolenaar 
737d8ccad7SMarcel Moolenaar /* Set by hardware if a branch was taken */
747d8ccad7SMarcel Moolenaar #define DBDMA_STATUS_BRANCH 8
757d8ccad7SMarcel Moolenaar 
767d8ccad7SMarcel Moolenaar struct dbdma_command;
777d8ccad7SMarcel Moolenaar typedef struct dbdma_command dbdma_command_t;
787d8ccad7SMarcel Moolenaar struct dbdma_channel;
797d8ccad7SMarcel Moolenaar typedef struct dbdma_channel dbdma_channel_t;
807d8ccad7SMarcel Moolenaar 
81f1dea04aSNathan Whitehorn int dbdma_allocate_channel(struct resource *dbdma_regs, u_int offset,
827d8ccad7SMarcel Moolenaar     bus_dma_tag_t parent_dma, int slots, dbdma_channel_t **chan);
837d8ccad7SMarcel Moolenaar 
847d8ccad7SMarcel Moolenaar int dbdma_resize_channel(dbdma_channel_t *chan, int newslots);
857d8ccad7SMarcel Moolenaar int dbdma_free_channel(dbdma_channel_t *chan);
867d8ccad7SMarcel Moolenaar 
877d8ccad7SMarcel Moolenaar void dbdma_run(dbdma_channel_t *chan);
887d8ccad7SMarcel Moolenaar void dbdma_stop(dbdma_channel_t *chan);
897d8ccad7SMarcel Moolenaar void dbdma_reset(dbdma_channel_t *chan);
907d8ccad7SMarcel Moolenaar void dbdma_set_current_cmd(dbdma_channel_t *chan, int slot);
917d8ccad7SMarcel Moolenaar 
927d8ccad7SMarcel Moolenaar void dbdma_pause(dbdma_channel_t *chan);
937d8ccad7SMarcel Moolenaar void dbdma_wake(dbdma_channel_t *chan);
947d8ccad7SMarcel Moolenaar 
95b798355bSNathan Whitehorn /*
96b798355bSNathan Whitehorn  * DBDMA uses a 16 bit channel control register to describe the current
97b798355bSNathan Whitehorn  * state of DMA on the channel. The high-order bits (8-15) contain information
98b798355bSNathan Whitehorn  * on the run state and are listed in the DBDMA_STATUS_* constants above. These
99b798355bSNathan Whitehorn  * are manipulated with the dbdma_run/stop/reset() routines above.
100b798355bSNathan Whitehorn  *
101b798355bSNathan Whitehorn  * The low order bits (0-7) are device dependent status bits. These can be set
102b798355bSNathan Whitehorn  * and read by both hardware and software. The mask is the set of bits to
103b798355bSNathan Whitehorn  * modify; if mask is 0x03 and value is 0, the lowest order 2 bits will be
104b798355bSNathan Whitehorn  * zeroed.
105b798355bSNathan Whitehorn  */
106b798355bSNathan Whitehorn 
1077d8ccad7SMarcel Moolenaar uint16_t dbdma_get_chan_status(dbdma_channel_t *chan);
108b798355bSNathan Whitehorn 
109b798355bSNathan Whitehorn uint8_t dbdma_get_device_status(dbdma_channel_t *chan);
110b798355bSNathan Whitehorn void dbdma_set_device_status(dbdma_channel_t *chan, uint8_t mask,
111b798355bSNathan Whitehorn     uint8_t value);
112b798355bSNathan Whitehorn 
113b798355bSNathan Whitehorn /*
114b798355bSNathan Whitehorn  * Each DBDMA command word has the current channel status register and the
115b798355bSNathan Whitehorn  * number of residual bytes (requested - actually transferred) written to it
116b798355bSNathan Whitehorn  * at time of command completion.
117b798355bSNathan Whitehorn  */
118b798355bSNathan Whitehorn 
119b798355bSNathan Whitehorn uint16_t dbdma_get_cmd_status(dbdma_channel_t *chan, int slot);
120b798355bSNathan Whitehorn uint16_t dbdma_get_residuals(dbdma_channel_t *chan, int slot);
121b798355bSNathan Whitehorn 
122b798355bSNathan Whitehorn void dbdma_clear_cmd_status(dbdma_channel_t *chan, int slot);
123b798355bSNathan Whitehorn 
124b798355bSNathan Whitehorn /*
125b798355bSNathan Whitehorn  * The interrupt/branch/wait selector let you specify a set of values
126b798355bSNathan Whitehorn  * of the device dependent status bits that will cause intterupt/branch/wait
127b798355bSNathan Whitehorn  * conditions to be taken if the flags for these are set to one of the
128b798355bSNathan Whitehorn  * DBDMA_COND_* values.
129b798355bSNathan Whitehorn  *
130b798355bSNathan Whitehorn  * The condition is considered true if (status & mask) == value.
131b798355bSNathan Whitehorn  */
1327d8ccad7SMarcel Moolenaar 
1337d8ccad7SMarcel Moolenaar void dbdma_set_interrupt_selector(dbdma_channel_t *chan, uint8_t mask,
1347d8ccad7SMarcel Moolenaar     uint8_t value);
1357d8ccad7SMarcel Moolenaar void dbdma_set_branch_selector(dbdma_channel_t *chan, uint8_t mask,
1367d8ccad7SMarcel Moolenaar     uint8_t value);
1377d8ccad7SMarcel Moolenaar void dbdma_set_wait_selector(dbdma_channel_t *chan, uint8_t mask,
1387d8ccad7SMarcel Moolenaar     uint8_t value);
1397d8ccad7SMarcel Moolenaar 
1407d8ccad7SMarcel Moolenaar void dbdma_insert_command(dbdma_channel_t *chan, int slot, int command,
1417d8ccad7SMarcel Moolenaar     int stream, bus_addr_t data, size_t count, uint8_t interrupt,
1427d8ccad7SMarcel Moolenaar     uint8_t branch, uint8_t wait, uint32_t branch_slot);
1437d8ccad7SMarcel Moolenaar 
1447d8ccad7SMarcel Moolenaar void dbdma_insert_stop(dbdma_channel_t *chan, int slot);
1457d8ccad7SMarcel Moolenaar void dbdma_insert_nop(dbdma_channel_t *chan, int slot);
1467d8ccad7SMarcel Moolenaar void dbdma_insert_branch(dbdma_channel_t *chan, int slot, int to_slot);
1477d8ccad7SMarcel Moolenaar 
1487d8ccad7SMarcel Moolenaar void dbdma_sync_commands(dbdma_channel_t *chan, bus_dmasync_op_t op);
1497d8ccad7SMarcel Moolenaar 
1504702d987SJustin Hibbits void dbdma_save_state(dbdma_channel_t *chan);
1514702d987SJustin Hibbits void dbdma_restore_state(dbdma_channel_t *chan);
1524702d987SJustin Hibbits 
1537d8ccad7SMarcel Moolenaar #endif /* _MACHINE_DBDMA_H_ */
154