aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/ttpci/budget-core.c
diff options
context:
space:
mode:
authorIngo Schneider <mail@ingo-schneider.de>2006-03-29 20:05:16 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-04-02 03:55:57 -0400
commitafa47abf09f148332b0e6e480972494bc2e5c8af (patch)
tree2f7222cc9de26adcbe5052f606d1f03dbdd599d0 /drivers/media/dvb/ttpci/budget-core.c
parent1864cfb1537e108c2fe7a8e178b28bffde5a5439 (diff)
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>
Diffstat (limited to 'drivers/media/dvb/ttpci/budget-core.c')
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c78
1 files changed, 63 insertions, 15 deletions
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 633e68c341c8..ea2066d461fc 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -39,9 +39,21 @@
39#include "budget.h" 39#include "budget.h"
40#include "ttpci-eeprom.h" 40#include "ttpci-eeprom.h"
41 41
42#define TS_WIDTH (2 * TS_SIZE)
43#define TS_WIDTH_ACTIVY TS_SIZE
44#define TS_HEIGHT_MASK 0xf00
45#define TS_HEIGHT_MASK_ACTIVY 0xc00
46#define TS_MIN_BUFSIZE_K 188
47#define TS_MAX_BUFSIZE_K 1410
48#define TS_MAX_BUFSIZE_K_ACTIVY 564
49#define BUFFER_WARNING_WAIT (30*HZ)
50
42int budget_debug; 51int budget_debug;
52static int dma_buffer_size = TS_MIN_BUFSIZE_K;
43module_param_named(debug, budget_debug, int, 0644); 53module_param_named(debug, budget_debug, int, 0644);
54module_param_named(bufsize, dma_buffer_size, int, 0444);
44MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off)."); 55MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
56MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
45 57
46/**************************************************************************** 58/****************************************************************************
47 * TT budget / WinTV Nova 59 * TT budget / WinTV Nova
@@ -70,11 +82,10 @@ static int start_ts_capture(struct budget *budget)
70 82
71 saa7146_write(dev, MC1, MASK_20); // DMA3 off 83 saa7146_write(dev, MC1, MASK_20); // DMA3 off
72 84
73 memset(budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH); 85 memset(budget->grabbing, 0x00, budget->buffer_size);
74 86
75 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000)); 87 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
76 88
77 budget->tsf = 0xff;
78 budget->ttbp = 0; 89 budget->ttbp = 0;
79 90
80 /* 91 /*
@@ -115,16 +126,12 @@ static int start_ts_capture(struct budget *budget)
115 126
116 saa7146_write(dev, BASE_ODD3, 0); 127 saa7146_write(dev, BASE_ODD3, 0);
117 saa7146_write(dev, BASE_EVEN3, 0); 128 saa7146_write(dev, BASE_EVEN3, 0);
118 saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT); 129 saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
119 saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90); 130 saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);
120 131
121 if (budget->card->type == BUDGET_FS_ACTIVY) { 132 saa7146_write(dev, PITCH3, budget->buffer_width);
122 saa7146_write(dev, PITCH3, TS_WIDTH / 2); 133 saa7146_write(dev, NUM_LINE_BYTE3,
123 saa7146_write(dev, NUM_LINE_BYTE3, ((TS_HEIGHT * 2) << 16) | (TS_WIDTH / 2)); 134 (budget->buffer_height << 16) | budget->buffer_width);
124 } else {
125 saa7146_write(dev, PITCH3, TS_WIDTH);
126 saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
127 }
128 135
129 saa7146_write(dev, MC2, (MASK_04 | MASK_20)); 136 saa7146_write(dev, MC2, (MASK_04 | MASK_20));
130 137
@@ -141,11 +148,12 @@ static void vpeirq(unsigned long data)
141 u8 *mem = (u8 *) (budget->grabbing); 148 u8 *mem = (u8 *) (budget->grabbing);
142 u32 olddma = budget->ttbp; 149 u32 olddma = budget->ttbp;
143 u32 newdma = saa7146_read(budget->dev, PCI_VDP3); 150 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
151 u32 count;
144 152
145 /* nearest lower position divisible by 188 */ 153 /* nearest lower position divisible by 188 */
146 newdma -= newdma % 188; 154 newdma -= newdma % 188;
147 155
148 if (newdma >= TS_BUFLEN) 156 if (newdma >= budget->buffer_size)
149 return; 157 return;
150 158
151 budget->ttbp = newdma; 159 budget->ttbp = newdma;
@@ -154,11 +162,24 @@ static void vpeirq(unsigned long data)
154 return; 162 return;
155 163
156 if (newdma > olddma) { /* no wraparound, dump olddma..newdma */ 164 if (newdma > olddma) { /* no wraparound, dump olddma..newdma */
157 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (newdma - olddma) / 188); 165 count = newdma - olddma;
166 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
158 } else { /* wraparound, dump olddma..buflen and 0..newdma */ 167 } else { /* wraparound, dump olddma..buflen and 0..newdma */
159 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (TS_BUFLEN - olddma) / 188); 168 count = budget->buffer_size - olddma;
169 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
170 count += newdma;
160 dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188); 171 dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188);
161 } 172 }
173
174 if (count > budget->buffer_warning_threshold)
175 budget->buffer_warnings++;
176
177 if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) {
178 printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n",
179 budget->dev->name, __FUNCTION__, budget->buffer_warnings, count);
180 budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT;
181 budget->buffer_warnings = 0;
182 }
162} 183}
163 184
164 185
@@ -341,9 +362,10 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
341 struct saa7146_pci_extension_data *info, 362 struct saa7146_pci_extension_data *info,
342 struct module *owner) 363 struct module *owner)
343{ 364{
344 int length = TS_WIDTH * TS_HEIGHT;
345 int ret = 0; 365 int ret = 0;
346 struct budget_info *bi = info->ext_priv; 366 struct budget_info *bi = info->ext_priv;
367 int max_bufsize;
368 int height_mask;
347 369
348 memset(budget, 0, sizeof(struct budget)); 370 memset(budget, 0, sizeof(struct budget));
349 371
@@ -352,6 +374,32 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
352 budget->card = bi; 374 budget->card = bi;
353 budget->dev = (struct saa7146_dev *) dev; 375 budget->dev = (struct saa7146_dev *) dev;
354 376
377 if (budget->card->type == BUDGET_FS_ACTIVY) {
378 budget->buffer_width = TS_WIDTH_ACTIVY;
379 max_bufsize = TS_MAX_BUFSIZE_K_ACTIVY;
380 height_mask = TS_HEIGHT_MASK_ACTIVY;
381 } else {
382 budget->buffer_width = TS_WIDTH;
383 max_bufsize = TS_MAX_BUFSIZE_K;
384 height_mask = TS_HEIGHT_MASK;
385 }
386
387 if (dma_buffer_size < TS_MIN_BUFSIZE_K)
388 dma_buffer_size = TS_MIN_BUFSIZE_K;
389 else if (dma_buffer_size > max_bufsize)
390 dma_buffer_size = max_bufsize;
391
392 budget->buffer_height = dma_buffer_size * 1024 / budget->buffer_width;
393 budget->buffer_height &= height_mask;
394 budget->buffer_size = budget->buffer_height * budget->buffer_width;
395 budget->buffer_warning_threshold = budget->buffer_size * 80/100;
396 budget->buffer_warnings = 0;
397 budget->buffer_warning_time = jiffies;
398
399 dprintk(2, "%s: width = %d, height = %d\n",
400 budget->dev->name, budget->buffer_width, budget->buffer_height);
401 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
402
355 dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner); 403 dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner);
356 404
357 /* set dd1 stream a & b */ 405 /* set dd1 stream a & b */
@@ -392,7 +440,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
392 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac); 440 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
393 441
394 if (NULL == 442 if (NULL ==
395 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, length, &budget->pt))) { 443 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt))) {
396 ret = -ENOMEM; 444 ret = -ENOMEM;
397 goto err; 445 goto err;
398 } 446 }