V4L/DVB (3669): Configurable dma buffer size for saa7146-based budget dvb cards

- Issue a warning when more than 80% of the DMA buffer is being used 
  (probably due to bad IRQ latency). Warnings are rate-limited.
- Introduce a new parameter 'bufsize' (in KByte) which increases the
  default DMA buffer of 188 KByte up to 1410 KByte (Activy: 564 KByte).

Signed-off-by: Ingo Schneider <mail@ingo-schneider.de>
Signed-off-by: Oliver Endriss <o.endriss@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
Ingo Schneider 2006-03-29 22:05:16 -03:00 коммит произвёл Mauro Carvalho Chehab
Родитель 1864cfb153
Коммит afa47abf09
3 изменённых файлов: 84 добавлений и 35 удалений

Просмотреть файл

@ -39,9 +39,21 @@
#include "budget.h" #include "budget.h"
#include "ttpci-eeprom.h" #include "ttpci-eeprom.h"
#define TS_WIDTH (2 * TS_SIZE)
#define TS_WIDTH_ACTIVY TS_SIZE
#define TS_HEIGHT_MASK 0xf00
#define TS_HEIGHT_MASK_ACTIVY 0xc00
#define TS_MIN_BUFSIZE_K 188
#define TS_MAX_BUFSIZE_K 1410
#define TS_MAX_BUFSIZE_K_ACTIVY 564
#define BUFFER_WARNING_WAIT (30*HZ)
int budget_debug; int budget_debug;
static int dma_buffer_size = TS_MIN_BUFSIZE_K;
module_param_named(debug, budget_debug, int, 0644); module_param_named(debug, budget_debug, int, 0644);
module_param_named(bufsize, dma_buffer_size, int, 0444);
MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off)."); MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
/**************************************************************************** /****************************************************************************
* TT budget / WinTV Nova * TT budget / WinTV Nova
@ -70,11 +82,10 @@ static int start_ts_capture(struct budget *budget)
saa7146_write(dev, MC1, MASK_20); // DMA3 off saa7146_write(dev, MC1, MASK_20); // DMA3 off
memset(budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH); memset(budget->grabbing, 0x00, budget->buffer_size);
saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000)); saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
budget->tsf = 0xff;
budget->ttbp = 0; budget->ttbp = 0;
/* /*
@ -115,16 +126,12 @@ static int start_ts_capture(struct budget *budget)
saa7146_write(dev, BASE_ODD3, 0); saa7146_write(dev, BASE_ODD3, 0);
saa7146_write(dev, BASE_EVEN3, 0); saa7146_write(dev, BASE_EVEN3, 0);
saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT); saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90); saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);
if (budget->card->type == BUDGET_FS_ACTIVY) { saa7146_write(dev, PITCH3, budget->buffer_width);
saa7146_write(dev, PITCH3, TS_WIDTH / 2); saa7146_write(dev, NUM_LINE_BYTE3,
saa7146_write(dev, NUM_LINE_BYTE3, ((TS_HEIGHT * 2) << 16) | (TS_WIDTH / 2)); (budget->buffer_height << 16) | budget->buffer_width);
} else {
saa7146_write(dev, PITCH3, TS_WIDTH);
saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
}
saa7146_write(dev, MC2, (MASK_04 | MASK_20)); saa7146_write(dev, MC2, (MASK_04 | MASK_20));
@ -141,11 +148,12 @@ static void vpeirq(unsigned long data)
u8 *mem = (u8 *) (budget->grabbing); u8 *mem = (u8 *) (budget->grabbing);
u32 olddma = budget->ttbp; u32 olddma = budget->ttbp;
u32 newdma = saa7146_read(budget->dev, PCI_VDP3); u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
u32 count;
/* nearest lower position divisible by 188 */ /* nearest lower position divisible by 188 */
newdma -= newdma % 188; newdma -= newdma % 188;
if (newdma >= TS_BUFLEN) if (newdma >= budget->buffer_size)
return; return;
budget->ttbp = newdma; budget->ttbp = newdma;
@ -154,11 +162,24 @@ static void vpeirq(unsigned long data)
return; return;
if (newdma > olddma) { /* no wraparound, dump olddma..newdma */ if (newdma > olddma) { /* no wraparound, dump olddma..newdma */
dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (newdma - olddma) / 188); count = newdma - olddma;
dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
} else { /* wraparound, dump olddma..buflen and 0..newdma */ } else { /* wraparound, dump olddma..buflen and 0..newdma */
dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (TS_BUFLEN - olddma) / 188); count = budget->buffer_size - olddma;
dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
count += newdma;
dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188); dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188);
} }
if (count > budget->buffer_warning_threshold)
budget->buffer_warnings++;
if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) {
printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n",
budget->dev->name, __FUNCTION__, budget->buffer_warnings, count);
budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT;
budget->buffer_warnings = 0;
}
} }
@ -341,9 +362,10 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
struct saa7146_pci_extension_data *info, struct saa7146_pci_extension_data *info,
struct module *owner) struct module *owner)
{ {
int length = TS_WIDTH * TS_HEIGHT;
int ret = 0; int ret = 0;
struct budget_info *bi = info->ext_priv; struct budget_info *bi = info->ext_priv;
int max_bufsize;
int height_mask;
memset(budget, 0, sizeof(struct budget)); memset(budget, 0, sizeof(struct budget));
@ -352,6 +374,32 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
budget->card = bi; budget->card = bi;
budget->dev = (struct saa7146_dev *) dev; budget->dev = (struct saa7146_dev *) dev;
if (budget->card->type == BUDGET_FS_ACTIVY) {
budget->buffer_width = TS_WIDTH_ACTIVY;
max_bufsize = TS_MAX_BUFSIZE_K_ACTIVY;
height_mask = TS_HEIGHT_MASK_ACTIVY;
} else {
budget->buffer_width = TS_WIDTH;
max_bufsize = TS_MAX_BUFSIZE_K;
height_mask = TS_HEIGHT_MASK;
}
if (dma_buffer_size < TS_MIN_BUFSIZE_K)
dma_buffer_size = TS_MIN_BUFSIZE_K;
else if (dma_buffer_size > max_bufsize)
dma_buffer_size = max_bufsize;
budget->buffer_height = dma_buffer_size * 1024 / budget->buffer_width;
budget->buffer_height &= height_mask;
budget->buffer_size = budget->buffer_height * budget->buffer_width;
budget->buffer_warning_threshold = budget->buffer_size * 80/100;
budget->buffer_warnings = 0;
budget->buffer_warning_time = jiffies;
dprintk(2, "%s: width = %d, height = %d\n",
budget->dev->name, budget->buffer_width, budget->buffer_height);
printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner); dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner);
/* set dd1 stream a & b */ /* set dd1 stream a & b */
@ -392,7 +440,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac); ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
if (NULL == if (NULL ==
(budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, length, &budget->pt))) { (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt))) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
} }

Просмотреть файл

@ -577,20 +577,6 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
// Set RPS1 Address register to point to RPS code (r108 p42) // Set RPS1 Address register to point to RPS code (r108 p42)
saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle); saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
// Set Source Line Counter Threshold, using BRS (rCC p43)
// It generates HS event every TS_HEIGHT lines
// this is related to TS_WIDTH set in register
// NUM_LINE_BYTE3 in budget-core.c. If NUM_LINE_BYTE
// low 16 bits are set to TS_WIDTH bytes (TS_WIDTH=2*188
//,then RPS_THRESH1
// should be set to trigger every TS_HEIGHT (512) lines.
//
saa7146_write(dev, RPS_THRESH1, (TS_HEIGHT*1) | MASK_12 );
// saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
// Enable RPS1 (rFC p33)
saa7146_write(dev, MC1, (MASK_13 | MASK_29));
if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL))) if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
return -ENOMEM; return -ENOMEM;
@ -602,6 +588,20 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
return err; return err;
} }
// Set Source Line Counter Threshold, using BRS (rCC p43)
// It generates HS event every TS_HEIGHT lines
// this is related to TS_WIDTH set in register
// NUM_LINE_BYTE3 in budget-core.c. If NUM_LINE_BYTE
// low 16 bits are set to TS_WIDTH bytes (TS_WIDTH=2*188
//,then RPS_THRESH1
// should be set to trigger every TS_HEIGHT (512) lines.
//
saa7146_write(dev, RPS_THRESH1, budget->buffer_height | MASK_12 );
// saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
// Enable RPS1 (rFC p33)
saa7146_write(dev, MC1, (MASK_13 | MASK_29));
dev->ext_priv = budget; dev->ext_priv = budget;

Просмотреть файл

@ -58,7 +58,13 @@ struct budget {
int ci_present; int ci_present;
int video_port; int video_port;
u8 tsf; u32 buffer_width;
u32 buffer_height;
u32 buffer_size;
u32 buffer_warning_threshold;
u32 buffer_warnings;
unsigned long buffer_warning_time;
u32 ttbp; u32 ttbp;
int feeding; int feeding;
@ -79,11 +85,6 @@ static struct saa7146_pci_extension_data x_var = { \
.ext_priv = &x_var ## _info, \ .ext_priv = &x_var ## _info, \
.ext = &budget_extension }; .ext = &budget_extension };
#define TS_WIDTH (376)
#define TS_HEIGHT (512)
#define TS_BUFLEN (TS_WIDTH*TS_HEIGHT)
#define TS_MAX_PACKETS (TS_BUFLEN/TS_SIZE)
#define BUDGET_TT 0 #define BUDGET_TT 0
#define BUDGET_TT_HW_DISEQC 1 #define BUDGET_TT_HW_DISEQC 1
#define BUDGET_PATCH 3 #define BUDGET_PATCH 3