Lines Matching full:cp
39 static int pvr2_ioread_init(struct pvr2_ioread *cp) in pvr2_ioread_init() argument
43 cp->stream = NULL; in pvr2_ioread_init()
44 mutex_init(&cp->mutex); in pvr2_ioread_init()
47 cp->buffer_storage[idx] = kmalloc(BUFFER_SIZE,GFP_KERNEL); in pvr2_ioread_init()
48 if (!(cp->buffer_storage[idx])) break; in pvr2_ioread_init()
54 if (!(cp->buffer_storage[idx])) continue; in pvr2_ioread_init()
55 kfree(cp->buffer_storage[idx]); in pvr2_ioread_init()
62 static void pvr2_ioread_done(struct pvr2_ioread *cp) in pvr2_ioread_done() argument
66 pvr2_ioread_setup(cp,NULL); in pvr2_ioread_done()
68 if (!(cp->buffer_storage[idx])) continue; in pvr2_ioread_done()
69 kfree(cp->buffer_storage[idx]); in pvr2_ioread_done()
75 struct pvr2_ioread *cp; in pvr2_ioread_create() local
76 cp = kzalloc(sizeof(*cp),GFP_KERNEL); in pvr2_ioread_create()
77 if (!cp) return NULL; in pvr2_ioread_create()
78 pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_create id=%p",cp); in pvr2_ioread_create()
79 if (pvr2_ioread_init(cp) < 0) { in pvr2_ioread_create()
80 kfree(cp); in pvr2_ioread_create()
83 return cp; in pvr2_ioread_create()
86 void pvr2_ioread_destroy(struct pvr2_ioread *cp) in pvr2_ioread_destroy() argument
88 if (!cp) return; in pvr2_ioread_destroy()
89 pvr2_ioread_done(cp); in pvr2_ioread_destroy()
90 pvr2_trace(PVR2_TRACE_STRUCT,"pvr2_ioread_destroy id=%p",cp); in pvr2_ioread_destroy()
91 if (cp->sync_key_ptr) { in pvr2_ioread_destroy()
92 kfree(cp->sync_key_ptr); in pvr2_ioread_destroy()
93 cp->sync_key_ptr = NULL; in pvr2_ioread_destroy()
95 kfree(cp); in pvr2_ioread_destroy()
98 void pvr2_ioread_set_sync_key(struct pvr2_ioread *cp, in pvr2_ioread_set_sync_key() argument
102 if (!cp) return; in pvr2_ioread_set_sync_key()
105 if ((sync_key_len == cp->sync_key_len) && in pvr2_ioread_set_sync_key()
107 (!memcmp(sync_key_ptr,cp->sync_key_ptr,sync_key_len)))) return; in pvr2_ioread_set_sync_key()
109 if (sync_key_len != cp->sync_key_len) { in pvr2_ioread_set_sync_key()
110 if (cp->sync_key_ptr) { in pvr2_ioread_set_sync_key()
111 kfree(cp->sync_key_ptr); in pvr2_ioread_set_sync_key()
112 cp->sync_key_ptr = NULL; in pvr2_ioread_set_sync_key()
114 cp->sync_key_len = 0; in pvr2_ioread_set_sync_key()
116 cp->sync_key_ptr = kmalloc(sync_key_len,GFP_KERNEL); in pvr2_ioread_set_sync_key()
117 if (cp->sync_key_ptr) { in pvr2_ioread_set_sync_key()
118 cp->sync_key_len = sync_key_len; in pvr2_ioread_set_sync_key()
122 if (!cp->sync_key_len) return; in pvr2_ioread_set_sync_key()
123 memcpy(cp->sync_key_ptr,sync_key_ptr,cp->sync_key_len); in pvr2_ioread_set_sync_key()
126 static void pvr2_ioread_stop(struct pvr2_ioread *cp) in pvr2_ioread_stop() argument
128 if (!(cp->enabled)) return; in pvr2_ioread_stop()
130 "/*---TRACE_READ---*/ pvr2_ioread_stop id=%p",cp); in pvr2_ioread_stop()
131 pvr2_stream_kill(cp->stream); in pvr2_ioread_stop()
132 cp->c_buf = NULL; in pvr2_ioread_stop()
133 cp->c_data_ptr = NULL; in pvr2_ioread_stop()
134 cp->c_data_len = 0; in pvr2_ioread_stop()
135 cp->c_data_offs = 0; in pvr2_ioread_stop()
136 cp->enabled = 0; in pvr2_ioread_stop()
137 cp->stream_running = 0; in pvr2_ioread_stop()
138 cp->spigot_open = 0; in pvr2_ioread_stop()
139 if (cp->sync_state) { in pvr2_ioread_stop()
142 cp->sync_state = 0; in pvr2_ioread_stop()
146 static int pvr2_ioread_start(struct pvr2_ioread *cp) in pvr2_ioread_start() argument
150 if (cp->enabled) return 0; in pvr2_ioread_start()
151 if (!(cp->stream)) return 0; in pvr2_ioread_start()
153 "/*---TRACE_READ---*/ pvr2_ioread_start id=%p",cp); in pvr2_ioread_start()
154 while ((bp = pvr2_stream_get_idle_buffer(cp->stream)) != NULL) { in pvr2_ioread_start()
159 cp,stat); in pvr2_ioread_start()
160 pvr2_ioread_stop(cp); in pvr2_ioread_start()
164 cp->enabled = !0; in pvr2_ioread_start()
165 cp->c_buf = NULL; in pvr2_ioread_start()
166 cp->c_data_ptr = NULL; in pvr2_ioread_start()
167 cp->c_data_len = 0; in pvr2_ioread_start()
168 cp->c_data_offs = 0; in pvr2_ioread_start()
169 cp->stream_running = 0; in pvr2_ioread_start()
170 if (cp->sync_key_len) { in pvr2_ioread_start()
173 cp->sync_state = 1; in pvr2_ioread_start()
174 cp->sync_trashed_count = 0; in pvr2_ioread_start()
175 cp->sync_buf_offs = 0; in pvr2_ioread_start()
177 cp->spigot_open = 0; in pvr2_ioread_start()
181 struct pvr2_stream *pvr2_ioread_get_stream(struct pvr2_ioread *cp) in pvr2_ioread_get_stream() argument
183 return cp->stream; in pvr2_ioread_get_stream()
186 int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp) in pvr2_ioread_setup() argument
192 mutex_lock(&cp->mutex); in pvr2_ioread_setup()
194 if (cp->stream) { in pvr2_ioread_setup()
197 cp); in pvr2_ioread_setup()
198 pvr2_ioread_stop(cp); in pvr2_ioread_setup()
199 pvr2_stream_kill(cp->stream); in pvr2_ioread_setup()
200 if (pvr2_stream_get_buffer_count(cp->stream)) { in pvr2_ioread_setup()
201 pvr2_stream_set_buffer_count(cp->stream,0); in pvr2_ioread_setup()
203 cp->stream = NULL; in pvr2_ioread_setup()
208 cp); in pvr2_ioread_setup()
212 mutex_unlock(&cp->mutex); in pvr2_ioread_setup()
218 cp->buffer_storage[idx], in pvr2_ioread_setup()
221 cp->stream = sp; in pvr2_ioread_setup()
224 mutex_unlock(&cp->mutex); in pvr2_ioread_setup()
229 int pvr2_ioread_set_enabled(struct pvr2_ioread *cp,int fl) in pvr2_ioread_set_enabled() argument
232 if ((!fl) == (!(cp->enabled))) return ret; in pvr2_ioread_set_enabled()
234 mutex_lock(&cp->mutex); in pvr2_ioread_set_enabled()
237 ret = pvr2_ioread_start(cp); in pvr2_ioread_set_enabled()
239 pvr2_ioread_stop(cp); in pvr2_ioread_set_enabled()
242 mutex_unlock(&cp->mutex); in pvr2_ioread_set_enabled()
246 static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp) in pvr2_ioread_get_buffer() argument
250 while (cp->c_data_len <= cp->c_data_offs) { in pvr2_ioread_get_buffer()
251 if (cp->c_buf) { in pvr2_ioread_get_buffer()
253 stat = pvr2_buffer_queue(cp->c_buf); in pvr2_ioread_get_buffer()
258 cp,stat); in pvr2_ioread_get_buffer()
259 pvr2_ioread_stop(cp); in pvr2_ioread_get_buffer()
262 cp->c_buf = NULL; in pvr2_ioread_get_buffer()
263 cp->c_data_ptr = NULL; in pvr2_ioread_get_buffer()
264 cp->c_data_len = 0; in pvr2_ioread_get_buffer()
265 cp->c_data_offs = 0; in pvr2_ioread_get_buffer()
268 cp->c_buf = pvr2_stream_get_ready_buffer(cp->stream); in pvr2_ioread_get_buffer()
269 if (!cp->c_buf) break; // Nothing ready; done. in pvr2_ioread_get_buffer()
270 cp->c_data_len = pvr2_buffer_get_count(cp->c_buf); in pvr2_ioread_get_buffer()
271 if (!cp->c_data_len) { in pvr2_ioread_get_buffer()
273 stat = pvr2_buffer_get_status(cp->c_buf); in pvr2_ioread_get_buffer()
278 cp,stat); in pvr2_ioread_get_buffer()
279 pvr2_ioread_stop(cp); in pvr2_ioread_get_buffer()
286 cp->c_data_offs = 0; in pvr2_ioread_get_buffer()
287 cp->c_data_ptr = cp->buffer_storage[ in pvr2_ioread_get_buffer()
288 pvr2_buffer_get_id(cp->c_buf)]; in pvr2_ioread_get_buffer()
293 static void pvr2_ioread_filter(struct pvr2_ioread *cp) in pvr2_ioread_filter() argument
296 if (!cp->enabled) return; in pvr2_ioread_filter()
297 if (cp->sync_state != 1) return; in pvr2_ioread_filter()
302 mutex_lock(&cp->mutex); in pvr2_ioread_filter()
305 if (!pvr2_ioread_get_buffer(cp)) break; in pvr2_ioread_filter()
306 if (!cp->c_data_len) break; in pvr2_ioread_filter()
310 for (idx = cp->c_data_offs; idx < cp->c_data_len; idx++) { in pvr2_ioread_filter()
311 if (cp->sync_buf_offs >= cp->sync_key_len) break; in pvr2_ioread_filter()
312 if (cp->c_data_ptr[idx] == in pvr2_ioread_filter()
313 cp->sync_key_ptr[cp->sync_buf_offs]) { in pvr2_ioread_filter()
315 (cp->sync_buf_offs)++; in pvr2_ioread_filter()
318 cp->sync_buf_offs = 0; in pvr2_ioread_filter()
323 cp->c_data_offs += idx; in pvr2_ioread_filter()
324 cp->sync_trashed_count += idx; in pvr2_ioread_filter()
327 if (cp->sync_buf_offs >= cp->sync_key_len) { in pvr2_ioread_filter()
328 cp->sync_trashed_count -= cp->sync_key_len; in pvr2_ioread_filter()
331 cp->sync_trashed_count); in pvr2_ioread_filter()
332 cp->sync_state = 2; in pvr2_ioread_filter()
333 cp->sync_buf_offs = 0; in pvr2_ioread_filter()
337 if (cp->c_data_offs < cp->c_data_len) { in pvr2_ioread_filter()
341 cp->c_data_len,cp->c_data_offs); in pvr2_ioread_filter()
349 mutex_unlock(&cp->mutex); in pvr2_ioread_filter()
352 int pvr2_ioread_avail(struct pvr2_ioread *cp) in pvr2_ioread_avail() argument
355 if (!(cp->enabled)) { in pvr2_ioread_avail()
360 if (cp->sync_state == 1) { in pvr2_ioread_avail()
361 pvr2_ioread_filter(cp); in pvr2_ioread_avail()
362 if (cp->sync_state == 1) return -EAGAIN; in pvr2_ioread_avail()
366 if (cp->stream_running) { in pvr2_ioread_avail()
367 if (!pvr2_stream_get_ready_count(cp->stream)) { in pvr2_ioread_avail()
372 if (pvr2_stream_get_ready_count(cp->stream) < BUFFER_COUNT/2) { in pvr2_ioread_avail()
378 if ((!(cp->spigot_open)) != (!(ret == 0))) { in pvr2_ioread_avail()
379 cp->spigot_open = (ret == 0); in pvr2_ioread_avail()
382 cp->spigot_open ? "available" : "pending"); in pvr2_ioread_avail()
388 int pvr2_ioread_read(struct pvr2_ioread *cp,void __user *buf,unsigned int cnt) in pvr2_ioread_read() argument
400 cp); in pvr2_ioread_read()
404 stat = pvr2_ioread_avail(cp); in pvr2_ioread_read()
407 cp->stream_running = !0; in pvr2_ioread_read()
409 mutex_lock(&cp->mutex); in pvr2_ioread_read()
416 if (!pvr2_ioread_get_buffer(cp)) { in pvr2_ioread_read()
423 if (cp->sync_state == 2) { in pvr2_ioread_read()
426 src = cp->sync_key_ptr + cp->sync_buf_offs; in pvr2_ioread_read()
427 bcnt = cp->sync_key_len - cp->sync_buf_offs; in pvr2_ioread_read()
430 src = cp->c_data_ptr + cp->c_data_offs; in pvr2_ioread_read()
431 bcnt = cp->c_data_len - cp->c_data_offs; in pvr2_ioread_read()
450 if (cp->sync_state == 2) { in pvr2_ioread_read()
453 cp->sync_buf_offs += bcnt; in pvr2_ioread_read()
454 if (cp->sync_buf_offs >= cp->sync_key_len) { in pvr2_ioread_read()
459 cp->sync_state = 0; in pvr2_ioread_read()
463 cp->c_data_offs += bcnt; in pvr2_ioread_read()
468 mutex_unlock(&cp->mutex); in pvr2_ioread_read()
483 cp,req_cnt,ret); in pvr2_ioread_read()