Lines Matching refs:s
25 int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src,… in ivtv_buf_copy_from_user() argument
27 if (s->buf_size - buf->bytesused < copybytes) in ivtv_buf_copy_from_user()
28 copybytes = s->buf_size - buf->bytesused; in ivtv_buf_copy_from_user()
52 void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q) in ivtv_enqueue() argument
57 if (q == &s->q_free) { in ivtv_enqueue()
63 spin_lock_irqsave(&s->qlock, flags); in ivtv_enqueue()
66 q->length += s->buf_size; in ivtv_enqueue()
68 spin_unlock_irqrestore(&s->qlock, flags); in ivtv_enqueue()
71 struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q) in ivtv_dequeue() argument
76 spin_lock_irqsave(&s->qlock, flags); in ivtv_dequeue()
81 q->length -= s->buf_size; in ivtv_dequeue()
84 spin_unlock_irqrestore(&s->qlock, flags); in ivtv_dequeue()
88 static void ivtv_queue_move_buf(struct ivtv_stream *s, struct ivtv_queue *from, in ivtv_queue_move_buf() argument
95 from->length -= s->buf_size; in ivtv_queue_move_buf()
101 to->length += s->buf_size; in ivtv_queue_move_buf()
122 int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal, in ivtv_queue_move() argument
127 int from_free = from == &s->q_free; in ivtv_queue_move()
128 int to_free = to == &s->q_free; in ivtv_queue_move()
131 spin_lock_irqsave(&s->qlock, flags); in ivtv_queue_move()
141 spin_unlock_irqrestore(&s->qlock, flags); in ivtv_queue_move()
156 steal->length -= s->buf_size; in ivtv_queue_move()
160 from->length += s->buf_size; in ivtv_queue_move()
161 bytes_available += s->buf_size; in ivtv_queue_move()
171 ivtv_queue_move_buf(s, from, to, 1); in ivtv_queue_move()
178 ivtv_queue_move_buf(s, from, to, to_free); in ivtv_queue_move()
181 spin_unlock_irqrestore(&s->qlock, flags); in ivtv_queue_move()
185 void ivtv_flush_queues(struct ivtv_stream *s) in ivtv_flush_queues() argument
187 ivtv_queue_move(s, &s->q_io, NULL, &s->q_free, 0); in ivtv_flush_queues()
188 ivtv_queue_move(s, &s->q_full, NULL, &s->q_free, 0); in ivtv_flush_queues()
189 ivtv_queue_move(s, &s->q_dma, NULL, &s->q_free, 0); in ivtv_flush_queues()
190 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_free, 0); in ivtv_flush_queues()
193 int ivtv_stream_alloc(struct ivtv_stream *s) in ivtv_stream_alloc() argument
195 struct ivtv *itv = s->itv; in ivtv_stream_alloc()
196 int SGsize = sizeof(struct ivtv_sg_host_element) * s->buffers; in ivtv_stream_alloc()
199 if (s->buffers == 0) in ivtv_stream_alloc()
203 s->dma != PCI_DMA_NONE ? "DMA " : "", in ivtv_stream_alloc()
204 s->name, s->buffers, s->buf_size, s->buffers * s->buf_size / 1024); in ivtv_stream_alloc()
206 s->sg_pending = kzalloc(SGsize, GFP_KERNEL|__GFP_NOWARN); in ivtv_stream_alloc()
207 if (s->sg_pending == NULL) { in ivtv_stream_alloc()
208 IVTV_ERR("Could not allocate sg_pending for %s stream\n", s->name); in ivtv_stream_alloc()
211 s->sg_pending_size = 0; in ivtv_stream_alloc()
213 s->sg_processing = kzalloc(SGsize, GFP_KERNEL|__GFP_NOWARN); in ivtv_stream_alloc()
214 if (s->sg_processing == NULL) { in ivtv_stream_alloc()
215 IVTV_ERR("Could not allocate sg_processing for %s stream\n", s->name); in ivtv_stream_alloc()
216 kfree(s->sg_pending); in ivtv_stream_alloc()
217 s->sg_pending = NULL; in ivtv_stream_alloc()
220 s->sg_processing_size = 0; in ivtv_stream_alloc()
222 s->sg_dma = kzalloc(sizeof(struct ivtv_sg_element), in ivtv_stream_alloc()
224 if (s->sg_dma == NULL) { in ivtv_stream_alloc()
225 IVTV_ERR("Could not allocate sg_dma for %s stream\n", s->name); in ivtv_stream_alloc()
226 kfree(s->sg_pending); in ivtv_stream_alloc()
227 s->sg_pending = NULL; in ivtv_stream_alloc()
228 kfree(s->sg_processing); in ivtv_stream_alloc()
229 s->sg_processing = NULL; in ivtv_stream_alloc()
232 if (ivtv_might_use_dma(s)) { in ivtv_stream_alloc()
233 s->sg_handle = pci_map_single(itv->pdev, s->sg_dma, in ivtv_stream_alloc()
235 ivtv_stream_sync_for_cpu(s); in ivtv_stream_alloc()
239 for (i = 0; i < s->buffers; i++) { in ivtv_stream_alloc()
245 buf->buf = kmalloc(s->buf_size + 256, GFP_KERNEL|__GFP_NOWARN); in ivtv_stream_alloc()
251 if (ivtv_might_use_dma(s)) { in ivtv_stream_alloc()
252 buf->dma_handle = pci_map_single(s->itv->pdev, in ivtv_stream_alloc()
253 buf->buf, s->buf_size + 256, s->dma); in ivtv_stream_alloc()
254 ivtv_buf_sync_for_cpu(s, buf); in ivtv_stream_alloc()
256 ivtv_enqueue(s, buf, &s->q_free); in ivtv_stream_alloc()
258 if (i == s->buffers) in ivtv_stream_alloc()
260 IVTV_ERR("Couldn't allocate buffers for %s stream\n", s->name); in ivtv_stream_alloc()
261 ivtv_stream_free(s); in ivtv_stream_alloc()
265 void ivtv_stream_free(struct ivtv_stream *s) in ivtv_stream_free() argument
270 ivtv_flush_queues(s); in ivtv_stream_free()
273 while ((buf = ivtv_dequeue(s, &s->q_free))) { in ivtv_stream_free()
274 if (ivtv_might_use_dma(s)) in ivtv_stream_free()
275 pci_unmap_single(s->itv->pdev, buf->dma_handle, in ivtv_stream_free()
276 s->buf_size + 256, s->dma); in ivtv_stream_free()
282 if (s->sg_dma != NULL) { in ivtv_stream_free()
283 if (s->sg_handle != IVTV_DMA_UNMAPPED) { in ivtv_stream_free()
284 pci_unmap_single(s->itv->pdev, s->sg_handle, in ivtv_stream_free()
286 s->sg_handle = IVTV_DMA_UNMAPPED; in ivtv_stream_free()
288 kfree(s->sg_pending); in ivtv_stream_free()
289 kfree(s->sg_processing); in ivtv_stream_free()
290 kfree(s->sg_dma); in ivtv_stream_free()
291 s->sg_pending = NULL; in ivtv_stream_free()
292 s->sg_processing = NULL; in ivtv_stream_free()
293 s->sg_dma = NULL; in ivtv_stream_free()
294 s->sg_pending_size = 0; in ivtv_stream_free()
295 s->sg_processing_size = 0; in ivtv_stream_free()