Lines Matching refs:cp

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