The patch number 9802 was added via Andy Walls <awa...@radix.net>
to http://linuxtv.org/hg/v4l-dvb master development tree.

Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel

If anyone has any objections, please let us know by sending a message to:
        v4l-dvb-maintai...@linuxtv.org

------

From: Andy Walls  <awa...@radix.net>
cx18: Add module parameters for finer control over buffer allocations


cx18: Add module parameters for finer control over buffer allocations.
User now has the option of setting smaller buffers to get lower
latency transfers from the encoder.  User can also now set the number
of buffers used for a stream explicitly.

Priority: normal

Signed-off-by: Andy Walls <awa...@radix.net>


---

 linux/drivers/media/video/cx18/cx18-driver.c  |  154 ++++++++++++++++--
 linux/drivers/media/video/cx18/cx18-driver.h  |   12 +
 linux/drivers/media/video/cx18/cx18-dvb.c     |    4 
 linux/drivers/media/video/cx18/cx18-streams.c |   21 +-
 4 files changed, 167 insertions(+), 24 deletions(-)

diff -r d7cecea5493e -r 2c15335c16ce 
linux/drivers/media/video/cx18/cx18-driver.c
--- a/linux/drivers/media/video/cx18/cx18-driver.c      Mon Dec 08 21:02:45 
2008 -0500
+++ b/linux/drivers/media/video/cx18/cx18-driver.c      Sun Dec 07 21:30:17 
2008 -0500
@@ -83,11 +83,27 @@ static char ntsc[] = "-";
 static char ntsc[] = "-";
 
 /* Buffers */
+static int enc_ts_buffers = CX18_DEFAULT_ENC_TS_BUFFERS;
 static int enc_mpg_buffers = CX18_DEFAULT_ENC_MPG_BUFFERS;
-static int enc_ts_buffers = CX18_DEFAULT_ENC_TS_BUFFERS;
+static int enc_idx_buffers = CX18_DEFAULT_ENC_IDX_BUFFERS;
 static int enc_yuv_buffers = CX18_DEFAULT_ENC_YUV_BUFFERS;
 static int enc_vbi_buffers = CX18_DEFAULT_ENC_VBI_BUFFERS;
 static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS;
+
+static int enc_ts_bufsize = CX18_DEFAULT_ENC_TS_BUFSIZE;
+static int enc_mpg_bufsize = CX18_DEFAULT_ENC_MPG_BUFSIZE;
+static int enc_idx_bufsize = CX18_DEFAULT_ENC_IDX_BUFSIZE;
+static int enc_yuv_bufsize = CX18_DEFAULT_ENC_YUV_BUFSIZE;
+/* VBI bufsize based on standards supported by card tuner for now */
+static int enc_pcm_bufsize = CX18_DEFAULT_ENC_PCM_BUFSIZE;
+
+static int enc_ts_bufs = -1;
+static int enc_mpg_bufs = -1;
+static int enc_idx_bufs = -1;
+static int enc_yuv_bufs = -1;
+static int enc_vbi_bufs = -1;
+static int enc_pcm_bufs = -1;
+
 
 static int cx18_pci_latency = 1;
 
@@ -108,11 +124,26 @@ module_param(cx18_pci_latency, int, 0644
 module_param(cx18_pci_latency, int, 0644);
 module_param(cx18_first_minor, int, 0644);
 
+module_param(enc_ts_buffers, int, 0644);
 module_param(enc_mpg_buffers, int, 0644);
-module_param(enc_ts_buffers, int, 0644);
+module_param(enc_idx_buffers, int, 0644);
 module_param(enc_yuv_buffers, int, 0644);
 module_param(enc_vbi_buffers, int, 0644);
 module_param(enc_pcm_buffers, int, 0644);
+
+module_param(enc_ts_bufsize, int, 0644);
+module_param(enc_mpg_bufsize, int, 0644);
+module_param(enc_idx_bufsize, int, 0644);
+module_param(enc_yuv_bufsize, int, 0644);
+/* VBI bufsize based on standards supported by card tuner for now */
+module_param(enc_pcm_bufsize, int, 0644);
+
+module_param(enc_ts_bufs, int, 0644);
+module_param(enc_mpg_bufs, int, 0644);
+module_param(enc_idx_bufs, int, 0644);
+module_param(enc_yuv_bufs, int, 0644);
+module_param(enc_vbi_bufs, int, 0644);
+module_param(enc_pcm_bufs, int, 0644);
 
 MODULE_PARM_DESC(tuner, "Tuner type selection,\n"
                        "\t\t\tsee tuner.h for values");
@@ -154,21 +185,57 @@ MODULE_PARM_DESC(mmio_ndelay,
 MODULE_PARM_DESC(mmio_ndelay,
                 "(Deprecated) MMIO accesses are now never purposely delayed\n"
                 "\t\t\tEffectively: 0 ns");
+MODULE_PARM_DESC(enc_ts_buffers,
+                "Encoder TS buffer memory (MB). (enc_ts_bufs can override)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFFERS));
+MODULE_PARM_DESC(enc_ts_bufsize,
+                "Size of an encoder TS buffer (kB)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFSIZE));
+MODULE_PARM_DESC(enc_ts_bufs,
+                "Number of encoder TS buffers\n"
+                "\t\t\tDefault is computed from other enc_ts_* parameters");
 MODULE_PARM_DESC(enc_mpg_buffers,
-                "Encoder MPG Buffers (in MB)\n"
+                "Encoder MPG buffer memory (MB). (enc_mpg_bufs can override)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS));
-MODULE_PARM_DESC(enc_ts_buffers,
-                "Encoder TS Buffers (in MB)\n"
-                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFFERS));
+MODULE_PARM_DESC(enc_mpg_bufsize,
+                "Size of an encoder MPG buffer (kB)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFSIZE));
+MODULE_PARM_DESC(enc_mpg_bufs,
+                "Number of encoder MPG buffers\n"
+                "\t\t\tDefault is computed from other enc_mpg_* parameters");
+MODULE_PARM_DESC(enc_idx_buffers,
+                "Encoder IDX buffer memory (MB). (enc_idx_bufs can override)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFFERS));
+MODULE_PARM_DESC(enc_idx_bufsize,
+                "Size of an encoder IDX buffer (kB)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFSIZE));
+MODULE_PARM_DESC(enc_idx_bufs,
+                "Number of encoder IDX buffers\n"
+                "\t\t\tDefault is computed from other enc_idx_* parameters");
 MODULE_PARM_DESC(enc_yuv_buffers,
-                "Encoder YUV Buffers (in MB)\n"
+                "Encoder YUV buffer memory (MB). (enc_yuv_bufs can override)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS));
+MODULE_PARM_DESC(enc_yuv_bufsize,
+                "Size of an encoder YUV buffer (kB)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFSIZE));
+MODULE_PARM_DESC(enc_yuv_bufs,
+                "Number of encoder YUV buffers\n"
+                "\t\t\tDefault is computed from other enc_yuv_* parameters");
 MODULE_PARM_DESC(enc_vbi_buffers,
-                "Encoder VBI Buffers (in MB)\n"
+                "Encoder VBI buffer memory (MB). (enc_vbi_bufs can override)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_VBI_BUFFERS));
+MODULE_PARM_DESC(enc_vbi_bufs,
+                "Number of encoder VBI buffers\n"
+                "\t\t\tDefault is computed from enc_vbi_buffers & tuner std");
 MODULE_PARM_DESC(enc_pcm_buffers,
-                "Encoder PCM buffers (in MB)\n"
+                "Encoder PCM buffer memory (MB). (enc_pcm_bufs can override)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS));
+MODULE_PARM_DESC(enc_pcm_bufsize,
+                "Size of an encoder PCM buffer (kB)\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFSIZE));
+MODULE_PARM_DESC(enc_pcm_bufs,
+                "Number of encoder PCM buffers\n"
+                "\t\t\tDefault is computed from other enc_pcm_* parameters");
 
 MODULE_PARM_DESC(cx18_first_minor, "Set kernel number assigned to first card");
 
@@ -361,11 +428,65 @@ static void cx18_process_options(struct 
 {
        int i, j;
 
+       cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers;
        cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers;
-       cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers;
+       cx->options.megabytes[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_buffers;
        cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers;
        cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers;
        cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
+       cx->options.megabytes[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control only */
+
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufs;
+       cx->stream_buffers[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control, no data */
+
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufsize;
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize;
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize;
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize;
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = 0; /* computed later */
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize;
+       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */
+
+       /* Except for VBI ensure stream_buffers & stream_buf_size are valid */
+       for (i = 0; i < CX18_MAX_STREAMS; i++) {
+               /* User said to use 0 buffers */
+               if (cx->stream_buffers[i] == 0) {
+                       cx->options.megabytes[i] = 0;
+                       cx->stream_buf_size[i] = 0;
+                       continue;
+               }
+               /* User said to use 0 MB total */
+               if (cx->options.megabytes[i] <= 0) {
+                       cx->options.megabytes[i] = 0;
+                       cx->stream_buffers[i] = 0;
+                       cx->stream_buf_size[i] = 0;
+                       continue;
+               }
+               /* VBI is computed later or user said buffer has size 0 */
+               if (cx->stream_buf_size[i] <= 0) {
+                       if (i != CX18_ENC_STREAM_TYPE_VBI) {
+                               cx->options.megabytes[i] = 0;
+                               cx->stream_buffers[i] = 0;
+                               cx->stream_buf_size[i] = 0;
+                       }
+                       continue;
+               }
+               if (cx->stream_buffers[i] < 0) {
+                       cx->stream_buffers[i] = cx->options.megabytes[i] * 1024
+                                               / cx->stream_buf_size[i];
+               } else {
+                       /* N.B. This might round down to 0 */
+                       cx->options.megabytes[i] =
+                         cx->stream_buffers[i] * cx->stream_buf_size[i] / 1024;
+               }
+               cx->stream_buf_size[i] *= 1024; /* convert from kB to bytes */
+       }
+
        cx->options.cardtype = cardtype[cx->num];
        cx->options.tuner = tuner[cx->num];
        cx->options.radio = radio[cx->num];
@@ -773,12 +894,17 @@ static int __devinit cx18_probe(struct p
        }
        cx->params.video_gop_size = cx->is_60hz ? 15 : 12;
 
-       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = 0x08000;
-       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = 0x08000;
-       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = 0x01200;
-       cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = 0x20000;
        vbi_buf_size = cx->vbi.raw_size * (cx->is_60hz ? 24 : 36) / 2;
        cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_buf_size;
+
+       if (cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] < 0)
+               cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] =
+                  cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] * 1024 * 1024
+                  / vbi_buf_size;
+       else
+               cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] =
+                    cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] * vbi_buf_size
+                    / (1024 * 1024);
 
        if (cx->options.radio > 0)
                cx->v4l2_cap |= V4L2_CAP_RADIO;
diff -r d7cecea5493e -r 2c15335c16ce 
linux/drivers/media/video/cx18/cx18-driver.h
--- a/linux/drivers/media/video/cx18/cx18-driver.h      Mon Dec 08 21:02:45 
2008 -0500
+++ b/linux/drivers/media/video/cx18/cx18-driver.h      Sun Dec 07 21:30:17 
2008 -0500
@@ -114,6 +114,17 @@
 #define CX18_DEFAULT_ENC_YUV_BUFFERS 2
 #define CX18_DEFAULT_ENC_VBI_BUFFERS 1
 #define CX18_DEFAULT_ENC_PCM_BUFFERS 1
+
+/* Maximum firmware DMA buffers per stream */
+#define CX18_MAX_MDLS_PER_STREAM 63
+
+/* DMA buffer, default size in kB allocated */
+#define CX18_DEFAULT_ENC_TS_BUFSIZE   32
+#define CX18_DEFAULT_ENC_MPG_BUFSIZE  32
+#define CX18_DEFAULT_ENC_IDX_BUFSIZE  32
+#define CX18_DEFAULT_ENC_YUV_BUFSIZE 128
+/* Default VBI bufsize based on standards supported by card tuner for now */
+#define CX18_DEFAULT_ENC_PCM_BUFSIZE   4
 
 /* i2c stuff */
 #define I2C_CLIENTS_MAX 16
@@ -408,6 +419,7 @@ struct cx18 {
 
        struct mutex serialize_lock;    /* mutex used to serialize 
open/close/start/stop/ioctl operations */
        struct cx18_options options;    /* User options */
+       int stream_buffers[CX18_MAX_STREAMS]; /* # of buffers for each stream */
        int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */
        struct cx18_stream streams[CX18_MAX_STREAMS];   /* Stream data */
        unsigned long i_flags;  /* global cx18 flags */
diff -r d7cecea5493e -r 2c15335c16ce linux/drivers/media/video/cx18/cx18-dvb.c
--- a/linux/drivers/media/video/cx18/cx18-dvb.c Mon Dec 08 21:02:45 2008 -0500
+++ b/linux/drivers/media/video/cx18/cx18-dvb.c Sun Dec 07 21:30:17 2008 -0500
@@ -217,6 +217,10 @@ int cx18_dvb_register(struct cx18_stream
        dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
 
        CX18_INFO("DVB Frontend registered\n");
+       CX18_INFO("Registered DVB adapter%d for %s (%d x %d kB)\n",
+                 stream->dvb.dvb_adapter.num, stream->name,
+                 stream->buffers, stream->buf_size/1024);
+
        mutex_init(&dvb->feedlock);
        dvb->enabled = 1;
        return ret;
diff -r d7cecea5493e -r 2c15335c16ce 
linux/drivers/media/video/cx18/cx18-streams.c
--- a/linux/drivers/media/video/cx18/cx18-streams.c     Mon Dec 08 21:02:45 
2008 -0500
+++ b/linux/drivers/media/video/cx18/cx18-streams.c     Sun Dec 07 21:30:17 
2008 -0500
@@ -111,7 +111,6 @@ static void cx18_stream_init(struct cx18
 {
        struct cx18_stream *s = &cx->streams[type];
        struct video_device *dev = s->v4l2dev;
-       u32 max_size = cx->options.megabytes[type] * 1024 * 1024;
 
        /* we need to keep v4l2dev, so restore it afterwards */
        memset(s, 0, sizeof(*s));
@@ -124,9 +123,9 @@ static void cx18_stream_init(struct cx18
        s->handle = CX18_INVALID_TASK_HANDLE;
 
        s->dma = cx18_stream_info[type].dma;
+       s->buffers = cx->stream_buffers[type];
        s->buf_size = cx->stream_buf_size[type];
-       if (s->buf_size)
-               s->buffers = max_size / s->buf_size;
+
        mutex_init(&s->qlock);
        init_waitqueue_head(&s->waitq);
        s->id = -1;
@@ -162,7 +161,7 @@ static int cx18_prep_dev(struct cx18 *cx
        /* User explicitly selected 0 buffers for these streams, so don't
           create them. */
        if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
-           cx->options.megabytes[type] == 0) {
+           cx->stream_buffers[type] == 0) {
                CX18_INFO("Disabled %s device\n", cx18_stream_info[type].name);
                return 0;
        }
@@ -262,8 +261,9 @@ static int cx18_reg_dev(struct cx18 *cx,
 
        switch (vfl_type) {
        case VFL_TYPE_GRABBER:
-               CX18_INFO("Registered device video%d for %s (%d MB)\n",
-                       num, s->name, cx->options.megabytes[type]);
+               CX18_INFO("Registered device video%d for %s (%d x %d kB)\n",
+                         num, s->name, cx->stream_buffers[type],
+                         cx->stream_buf_size[type]/1024);
                break;
 
        case VFL_TYPE_RADIO:
@@ -272,10 +272,11 @@ static int cx18_reg_dev(struct cx18 *cx,
                break;
 
        case VFL_TYPE_VBI:
-               if (cx->options.megabytes[type])
-                       CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
-                               num,
-                               s->name, cx->options.megabytes[type]);
+               if (cx->stream_buffers[type])
+                       CX18_INFO("Registered device vbi%d for %s "
+                                 "(%d x %d bytes)\n",
+                                 num, s->name, cx->stream_buffers[type],
+                                 cx->stream_buf_size[type]);
                else
                        CX18_INFO("Registered device vbi%d for %s\n",
                                num, s->name);


---

Patch is available at: 
http://linuxtv.org/hg/v4l-dvb/rev/2c15335c16ce38ea95b717ddc806589cdea1cc41

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to