diff -r 9652f85e688a linux/drivers/media/dvb/mantis/mantis_dma.c --- a/linux/drivers/media/dvb/mantis/mantis_dma.c Thu May 27 02:02:09 2010 -0300 +++ b/linux/drivers/media/dvb/mantis/mantis_dma.c Sat Jun 19 13:04:49 2010 +0300 @@ -46,11 +46,15 @@ #define RISC_FLUSH() (mantis->risc_pos = 0) #define RISC_INSTR(opcode) (mantis->risc_cpu[mantis->risc_pos++] = cpu_to_le32(opcode)) -#define MANTIS_BUF_SIZE (64 * 1024) -#define MANTIS_BLOCK_BYTES (MANTIS_BUF_SIZE >> 4) -#define MANTIS_BLOCK_COUNT (1 << 4) +/* (16 * 188) = 3008. (16 * 204) = 3264. x % 64 == 0, x <= 4095 */ +#define RISC_DMA_TR_UNIT(m) (((m->hwconfig->ts_size == MANTIS_TS_204)? 204:188) * 16) +#define DMA_TRANSFERS_PER_BLOCK (5) +#define MANTIS_BLOCK_BYTES(m) (RISC_DMA_TR_UNIT(m) * DMA_TRANSFERS_PER_BLOCK) +#define MANTIS_BLOCK_COUNT (4) #define MANTIS_RISC_SIZE PAGE_SIZE +#define MANTIS_DMA_BUFSZ(m) (m->line_bytes * m->line_count) + int mantis_dma_exit(struct mantis_pci *mantis) { if (mantis->buf_cpu) { @@ -58,9 +62,9 @@ "DMA=0x%lx cpu=0x%p size=%d", (unsigned long) mantis->buf_dma, mantis->buf_cpu, - MANTIS_BUF_SIZE); + MANTIS_DMA_BUFSZ(mantis)); - pci_free_consistent(mantis->pdev, MANTIS_BUF_SIZE, + pci_free_consistent(mantis->pdev, MANTIS_DMA_BUFSZ(mantis), mantis->buf_cpu, mantis->buf_dma); mantis->buf_cpu = NULL; @@ -86,7 +90,7 @@ { if (!mantis->buf_cpu) { mantis->buf_cpu = pci_alloc_consistent(mantis->pdev, - MANTIS_BUF_SIZE, + MANTIS_DMA_BUFSZ(mantis), &mantis->buf_dma); if (!mantis->buf_cpu) { dprintk(MANTIS_ERROR, 1, @@ -97,7 +101,8 @@ dprintk(MANTIS_ERROR, 1, "DMA=0x%lx cpu=0x%p size=%d", (unsigned long) mantis->buf_dma, - mantis->buf_cpu, MANTIS_BUF_SIZE); + mantis->buf_cpu, + MANTIS_DMA_BUFSZ(mantis)); } if (!mantis->risc_cpu) { mantis->risc_cpu = pci_alloc_consistent(mantis->pdev, @@ -126,18 +131,13 @@ static inline int mantis_calc_lines(struct mantis_pci *mantis) { - mantis->line_bytes = MANTIS_BLOCK_BYTES; + mantis->line_bytes = MANTIS_BLOCK_BYTES(mantis); mantis->line_count = MANTIS_BLOCK_COUNT; - while (mantis->line_bytes > 4095) { - mantis->line_bytes >>= 1; - mantis->line_count <<= 1; - } + dprintk(MANTIS_DEBUG, 1, "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]", + RISC_DMA_TR_UNIT(mantis), mantis->line_bytes, mantis->line_count); - dprintk(MANTIS_DEBUG, 1, "Mantis RISC block bytes=[%d], line bytes=[%d], line count=[%d]", - MANTIS_BLOCK_BYTES, mantis->line_bytes, mantis->line_count); - - if (mantis->line_count > 255) { + if (DMA_TRANSFERS_PER_BLOCK * mantis->line_count > 255) { dprintk(MANTIS_ERROR, 1, "Buffer size error"); return -EINVAL; } @@ -150,6 +150,14 @@ int err = 0; dprintk(MANTIS_DEBUG, 1, "Mantis DMA init"); + + err = mantis_calc_lines(mantis); + if (err < 0) { + dprintk(MANTIS_ERROR, 1, "Mantis calc lines failed"); + + goto err; + } + if (mantis_alloc_buffers(mantis) < 0) { dprintk(MANTIS_ERROR, 1, "Error allocating DMA buffer"); @@ -158,12 +166,6 @@ goto err; } - err = mantis_calc_lines(mantis); - if (err < 0) { - dprintk(MANTIS_ERROR, 1, "Mantis calc lines failed"); - - goto err; - } return 0; err: @@ -175,7 +177,9 @@ { u32 buf_pos = 0; u32 line; + u32 step_bytes; + step_bytes = RISC_DMA_TR_UNIT(mantis); dprintk(MANTIS_DEBUG, 1, "Mantis create RISC program"); RISC_FLUSH(); @@ -183,19 +187,18 @@ mantis->line_count, mantis->line_bytes); for (line = 0; line < mantis->line_count; line++) { - dprintk(MANTIS_DEBUG, 1, "RISC PROG line=[%d]", line); - if (!(buf_pos % MANTIS_BLOCK_BYTES)) { - RISC_INSTR(RISC_WRITE | - RISC_IRQ | - RISC_STATUS(((buf_pos / MANTIS_BLOCK_BYTES) + - (MANTIS_BLOCK_COUNT - 1)) % - MANTIS_BLOCK_COUNT) | - mantis->line_bytes); - } else { - RISC_INSTR(RISC_WRITE | mantis->line_bytes); + int risc_step; + + for (risc_step = 0; risc_step < DMA_TRANSFERS_PER_BLOCK; risc_step++) { + u32 en_irq = (risc_step == 1); + dprintk(MANTIS_DEBUG, 1, "RISC PROG line=[%d] risc_step=[%d] en_irq=[%d]", line, risc_step, en_irq); + /* Last risc_step: eject IRQ about block completion. */ + RISC_INSTR(RISC_WRITE | + (en_irq ? (RISC_IRQ | RISC_STATUS(line)) : 0) | + step_bytes); + RISC_INSTR(mantis->buf_dma + buf_pos); + buf_pos += step_bytes; } - RISC_INSTR(mantis->buf_dma + buf_pos); - buf_pos += mantis->line_bytes; } RISC_INSTR(RISC_JUMP); RISC_INSTR(mantis->risc_dma); @@ -205,23 +208,25 @@ { dprintk(MANTIS_DEBUG, 1, "Mantis Start DMA engine"); + memset(mantis->buf_cpu, 0, MANTIS_DMA_BUFSZ(mantis)); + mantis->last_block = mantis->finished_block = 0; mantis_risc_program(mantis); mmwrite(mantis->risc_dma, MANTIS_RISC_START); mmwrite(mmread(MANTIS_GPIF_ADDR) | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR); mmwrite(0, MANTIS_DMA_CTL); - mantis->last_block = mantis->finished_block = 0; mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_RISCI, MANTIS_INT_MASK); mmwrite(MANTIS_FIFO_EN | MANTIS_DCAP_EN | MANTIS_RISC_EN, MANTIS_DMA_CTL); - + // tasklet_enable(&mantis->tasklet); } void mantis_dma_stop(struct mantis_pci *mantis) { u32 stat = 0, mask = 0; + //tasklet_disable(&mantis->tasklet); stat = mmread(MANTIS_INT_STAT); mask = mmread(MANTIS_INT_MASK); @@ -246,11 +251,12 @@ struct mantis_hwconfig *config = mantis->hwconfig; while (mantis->last_block != mantis->finished_block) { + dprintk(MANTIS_DEBUG, 1, "last block=[%d] finished block=[%d]", mantis->last_block, mantis->finished_block); (config->ts_size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter) - (&mantis->demux, &mantis->buf_cpu[mantis->last_block * MANTIS_BLOCK_BYTES], MANTIS_BLOCK_BYTES); - mantis->last_block = (mantis->last_block + 1) % MANTIS_BLOCK_COUNT; + (&mantis->demux, &mantis->buf_cpu[mantis->last_block * mantis->line_bytes], mantis->line_bytes); + mantis->last_block = (mantis->last_block + 1) % mantis->line_count; } }