2 Mantis PCI bridge driver
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/vmalloc.h>
23 #include "mantis_common.h"
25 #define RISC_WRITE (0x01 << 28)
26 #define RISC_JUMP (0x07 << 28)
27 #define RISC_IRQ (0x01 << 24)
29 #define RISC_STATUS(status) ((((~status) & 0x0f) << 20) | ((status & 0x0f) << 16))
30 #define RISC_FLUSH() mantis->risc_pos = 0
31 #define RISC_INSTR(opcode) mantis->risc_cpu[mantis->risc_pos++] = cpu_to_le32(opcode)
33 #define MANTIS_BUF_SIZE 64 * 1024
34 #define MANTIS_BLOCK_BYTES (MANTIS_BUF_SIZE >> 4)
35 #define MANTIS_BLOCK_COUNT (1 << 4)
36 #define MANTIS_RISC_SIZE PAGE_SIZE
38 int mantis_dma_exit(struct mantis_pci
*mantis
)
40 if (mantis
->buf_cpu
) {
41 dprintk(verbose
, MANTIS_ERROR
, 1,
42 "DMA=0x%lx cpu=0x%p size=%d",
43 (unsigned long) mantis
->buf_dma
,
47 pci_free_consistent(mantis
->pdev
, MANTIS_BUF_SIZE
,
48 mantis
->buf_cpu
, mantis
->buf_dma
);
50 mantis
->buf_cpu
= NULL
;
52 if (mantis
->risc_cpu
) {
53 dprintk(verbose
, MANTIS_ERROR
, 1,
54 "RISC=0x%lx cpu=0x%p size=%lx",
55 (unsigned long) mantis
->risc_dma
,
59 pci_free_consistent(mantis
->pdev
, MANTIS_RISC_SIZE
,
60 mantis
->risc_cpu
, mantis
->risc_dma
);
62 mantis
->risc_cpu
= NULL
;
68 static inline int mantis_alloc_buffers(struct mantis_pci
*mantis
)
70 if (!mantis
->buf_cpu
) {
71 mantis
->buf_cpu
= pci_alloc_consistent(mantis
->pdev
,
74 if (!mantis
->buf_cpu
) {
75 dprintk(verbose
, MANTIS_ERROR
, 1,
76 "DMA buffer allocation failed");
80 dprintk(verbose
, MANTIS_ERROR
, 1,
81 "DMA=0x%lx cpu=0x%p size=%d",
82 (unsigned long) mantis
->buf_dma
,
83 mantis
->buf_cpu
, MANTIS_BUF_SIZE
);
85 if (!mantis
->risc_cpu
) {
86 mantis
->risc_cpu
= pci_alloc_consistent(mantis
->pdev
,
90 if (!mantis
->risc_cpu
) {
91 dprintk(verbose
, MANTIS_ERROR
, 1,
92 "RISC program allocation failed");
94 mantis_dma_exit(mantis
);
98 dprintk(verbose
, MANTIS_ERROR
, 1,
99 "RISC=0x%lx cpu=0x%p size=%lx",
100 (unsigned long) mantis
->risc_dma
,
101 mantis
->risc_cpu
, MANTIS_RISC_SIZE
);
106 dprintk(verbose
, MANTIS_ERROR
, 1, "Out of memory (?) .....");
110 static inline int mantis_calc_lines(struct mantis_pci
*mantis
)
112 mantis
->line_bytes
= MANTIS_BLOCK_BYTES
;
113 mantis
->line_count
= MANTIS_BLOCK_COUNT
;
115 while (mantis
->line_bytes
> 4095) {
116 mantis
->line_bytes
>>= 1;
117 mantis
->line_count
<<= 1;
120 dprintk(verbose
, MANTIS_DEBUG
, 1,
121 "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]",
122 MANTIS_BLOCK_BYTES
, mantis
->line_bytes
, mantis
->line_count
);
124 if (mantis
->line_count
> 255) {
125 dprintk(verbose
, MANTIS_ERROR
, 1, "Buffer size error");
132 int mantis_dma_init(struct mantis_pci
*mantis
)
136 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis DMA init");
137 if (mantis_alloc_buffers(mantis
) < 0) {
138 dprintk(verbose
, MANTIS_ERROR
, 1, "Error allocating DMA buffer");
141 // mmwrite(mmread(MANTIS_DMA_CTL) & ~MANTIS_RISC_EN, MANTIS_DMA_CTL);
142 mmwrite(0, MANTIS_DMA_CTL
);
146 if ((err
= mantis_calc_lines(mantis
)) < 0) {
147 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis calc lines failed");
157 static inline void mantis_risc_program(struct mantis_pci
*mantis
)
162 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis create RISC program");
165 dprintk(verbose
, MANTIS_DEBUG
, 1, "risc len lines %u, bytes per line %u",
166 mantis
->line_count
, mantis
->line_bytes
);
168 for (line
= 0; line
< mantis
->line_count
; line
++) {
169 dprintk(verbose
, MANTIS_DEBUG
, 1, "RISC PROG line=[%d]", line
);
170 if (!(buf_pos
% MANTIS_BLOCK_BYTES
)) {
171 RISC_INSTR(RISC_WRITE
|
173 RISC_STATUS(((buf_pos
/ MANTIS_BLOCK_BYTES
) +
174 (MANTIS_BLOCK_COUNT
- 1)) %
175 MANTIS_BLOCK_COUNT
) |
178 RISC_INSTR(RISC_WRITE
| mantis
->line_bytes
);
180 RISC_INSTR(mantis
->buf_dma
+ buf_pos
);
181 buf_pos
+= mantis
->line_bytes
;
183 RISC_INSTR(RISC_JUMP
);
184 RISC_INSTR(mantis
->risc_dma
);
187 void mantis_dma_start(struct mantis_pci
*mantis
)
189 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis Start DMA engine");
191 mantis_risc_program(mantis
);
192 mmwrite(cpu_to_le32(mantis
->risc_dma
), MANTIS_RISC_START
);
193 mmwrite(mmread(MANTIS_GPIF_ADDR
) | MANTIS_GPIF_RDWRN
, MANTIS_GPIF_ADDR
);
195 mmwrite(0, MANTIS_DMA_CTL
);
196 mantis
->last_block
= mantis
->finished_block
= 0;
198 mmwrite(mmread(MANTIS_INT_MASK
) | MANTIS_INT_RISCI
, MANTIS_INT_MASK
);
200 mmwrite(MANTIS_FIFO_EN
| MANTIS_DCAP_EN
201 | MANTIS_RISC_EN
, MANTIS_DMA_CTL
);
205 void mantis_dma_stop(struct mantis_pci
*mantis
)
207 u32 stat
= 0, mask
= 0;
209 stat
= mmread(MANTIS_INT_STAT
);
210 mask
= mmread(MANTIS_INT_MASK
);
211 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis Stop DMA engine");
213 mmwrite((mmread(MANTIS_GPIF_ADDR
) & (~(MANTIS_GPIF_RDWRN
))), MANTIS_GPIF_ADDR
);
215 mmwrite((mmread(MANTIS_DMA_CTL
) & ~(MANTIS_FIFO_EN
|
217 MANTIS_RISC_EN
)), MANTIS_DMA_CTL
);
219 mmwrite(mmread(MANTIS_INT_STAT
), MANTIS_INT_STAT
);
221 mmwrite(mmread(MANTIS_INT_MASK
) & ~(MANTIS_INT_RISCI
|
222 MANTIS_INT_RISCEN
), MANTIS_INT_MASK
);
226 void mantis_dma_xfer(unsigned long data
)
228 struct mantis_pci
*mantis
= (struct mantis_pci
*) data
;
229 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
231 while (mantis
->last_block
!= mantis
->finished_block
) {
232 dprintk(verbose
, MANTIS_DEBUG
, 1, "last block=[%d] finished block=[%d]",
233 mantis
->last_block
, mantis
->finished_block
);
235 (config
->ts_size
? dvb_dmx_swfilter_204
: dvb_dmx_swfilter
)
236 (&mantis
->demux
, &mantis
->buf_cpu
[mantis
->last_block
* MANTIS_BLOCK_BYTES
], MANTIS_BLOCK_BYTES
);
237 mantis
->last_block
= (mantis
->last_block
+ 1) % MANTIS_BLOCK_COUNT
;
This page took 0.045646 seconds and 6 git commands to generate.