52fb9faad819e4ec445afffd61b0ff219b7d23c4
4 * Copyright (C) 2007 OpenMoko, Inc.
5 * Author: Chia-I Wu <olv@openmoko.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <stdlib.h> /* for exit() */
28 #define GLAMO_REG_WIDTH sizeof(GLAMO_REG_TYPE)
31 * some engines only support MMIO mode; while
32 * some engines only support CMDQ mode
39 enum glamo_dma_wait_type
{
45 struct glamo_dma_manager
{
46 enum glamo_dma_mode mode
;
52 volatile GLAMO_REG_TYPE
*cmdq
;
58 struct glamo_dma_manager
*glamo_dma_new(enum glamo_dma_mode t
);
59 void glamo_dma_destroy(struct glamo_dma_manager
*dma
);
60 void glamo_dma_flush(struct glamo_dma_manager
*dma
);
61 void glamo_dma_wait(struct glamo_dma_manager
*dma
, enum glamo_dma_wait_type t
);
62 void glamo_dma_dump(struct glamo_dma_manager
*dma
);
64 #define GLAMO_DMA_VARS \
65 GLAMO_REG_TYPE *__p; int __count, __total
67 #define GLAMO_DMA_BEGIN(dma, n) \
69 if (dma->llen + n * GLAMO_REG_WIDTH > dma->lsize) \
70 glamo_dma_flush(dma); \
71 __p = (GLAMO_REG_TYPE *) (dma->lbuf + dma->llen); \
72 __count = 0; __total = n; \
75 #define GLAMO_DMA_OUT(dma, v1, v2) \
77 __p[__count++] = v1; \
78 __p[__count++] = v2; \
81 #define GLAMO_DMA_END(dma) \
83 if (__count != __total) \
85 fprintf(stderr, "count != total (%d != %d) " \
86 "at %s:%d\n", __count, __total, \
87 __FILE__, __LINE__); \
90 dma->llen += __count * GLAMO_REG_WIDTH; \
93 #define GLAMO_DMA_BURST(dma, reg, n) \
94 GLAMO_DMA_OUT(dma, (1 << 15) | reg, n)