Lines Matching refs:v_iter

142 static inline void inc_buf_pos(struct pcmtst_buf_iter *v_iter, size_t by, size_t bytes)  in inc_buf_pos()  argument
144 v_iter->total_bytes += by; in inc_buf_pos()
145 v_iter->buf_pos += by; in inc_buf_pos()
146 if (v_iter->buf_pos >= bytes) in inc_buf_pos()
147 v_iter->buf_pos %= bytes; in inc_buf_pos()
155 static inline size_t buf_pos_n(struct pcmtst_buf_iter *v_iter, unsigned int channels, in buf_pos_n() argument
158 return v_iter->buf_pos / channels + v_iter->chan_block * chan_num; in buf_pos_n()
171 static void check_buf_block_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in check_buf_block_i() argument
177 for (i = 0; i < v_iter->b_rw; i++) { in check_buf_block_i()
178 current_byte = runtime->dma_area[v_iter->buf_pos]; in check_buf_block_i()
181 ch_num = (v_iter->total_bytes / v_iter->sample_bytes) % runtime->channels; in check_buf_block_i()
182 if (current_byte != patt_bufs[ch_num].buf[ch_pos_i(v_iter->total_bytes, in check_buf_block_i()
184 v_iter->sample_bytes) in check_buf_block_i()
186 v_iter->is_buf_corrupted = true; in check_buf_block_i()
189 inc_buf_pos(v_iter, 1, runtime->dma_bytes); in check_buf_block_i()
192 inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes); in check_buf_block_i()
195 static void check_buf_block_ni(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in check_buf_block_ni() argument
202 for (i = 0; i < v_iter->b_rw; i++) { in check_buf_block_ni()
204 current_byte = runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)]; in check_buf_block_ni()
207 if (current_byte != patt_bufs[ch_num].buf[(v_iter->total_bytes / channels) in check_buf_block_ni()
209 v_iter->is_buf_corrupted = true; in check_buf_block_ni()
212 inc_buf_pos(v_iter, 1, runtime->dma_bytes); in check_buf_block_ni()
214 inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes); in check_buf_block_ni()
222 static void check_buf_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in check_buf_block() argument
224 if (v_iter->interleaved) in check_buf_block()
225 check_buf_block_i(v_iter, runtime); in check_buf_block()
227 check_buf_block_ni(v_iter, runtime); in check_buf_block()
238 static void fill_block_pattern_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_pattern_n() argument
244 for (i = 0; i < v_iter->b_rw; i++) { in fill_block_pattern_n()
246 runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)] = in fill_block_pattern_n()
247 patt_bufs[ch_num].buf[(v_iter->total_bytes / channels) in fill_block_pattern_n()
249 inc_buf_pos(v_iter, 1, runtime->dma_bytes); in fill_block_pattern_n()
254 static void fill_block_pattern_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_pattern_i() argument
260 pos_in_ch = ch_pos_i(v_iter->total_bytes, runtime->channels, v_iter->sample_bytes); in fill_block_pattern_i()
262 for (sample = 0; sample < v_iter->s_rw_ch; sample++) { in fill_block_pattern_i()
264 for (pos_sample = 0; pos_sample < v_iter->sample_bytes; pos_sample++) { in fill_block_pattern_i()
265 pos_pattern = (pos_in_ch + sample * v_iter->sample_bytes in fill_block_pattern_i()
267 runtime->dma_area[v_iter->buf_pos] = patt_bufs[ch].buf[pos_pattern]; in fill_block_pattern_i()
268 inc_buf_pos(v_iter, 1, runtime->dma_bytes); in fill_block_pattern_i()
274 static void fill_block_pattern(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_pattern() argument
276 if (v_iter->interleaved) in fill_block_pattern()
277 fill_block_pattern_i(v_iter, runtime); in fill_block_pattern()
279 fill_block_pattern_n(v_iter, runtime); in fill_block_pattern()
282 static void fill_block_rand_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_rand_n() argument
286 size_t bytes_remain = runtime->dma_bytes - v_iter->buf_pos; in fill_block_rand_n()
290 if (v_iter->b_rw <= bytes_remain) { in fill_block_rand_n()
292 get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i), in fill_block_rand_n()
293 v_iter->b_rw / channels); in fill_block_rand_n()
296 get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i), in fill_block_rand_n()
298 get_random_bytes(runtime->dma_area + v_iter->chan_block * i, in fill_block_rand_n()
299 (v_iter->b_rw - bytes_remain) / channels); in fill_block_rand_n()
302 inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes); in fill_block_rand_n()
305 static void fill_block_rand_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_rand_i() argument
307 size_t in_cur_block = runtime->dma_bytes - v_iter->buf_pos; in fill_block_rand_i()
309 if (v_iter->b_rw <= in_cur_block) { in fill_block_rand_i()
310 get_random_bytes(&runtime->dma_area[v_iter->buf_pos], v_iter->b_rw); in fill_block_rand_i()
312 get_random_bytes(&runtime->dma_area[v_iter->buf_pos], in_cur_block); in fill_block_rand_i()
313 get_random_bytes(runtime->dma_area, v_iter->b_rw - in_cur_block); in fill_block_rand_i()
315 inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes); in fill_block_rand_i()
318 static void fill_block_random(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block_random() argument
320 if (v_iter->interleaved) in fill_block_random()
321 fill_block_rand_i(v_iter, runtime); in fill_block_random()
323 fill_block_rand_n(v_iter, runtime); in fill_block_random()
326 static void fill_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) in fill_block() argument
330 fill_block_random(v_iter, runtime); in fill_block()
333 fill_block_pattern(v_iter, runtime); in fill_block()
345 struct pcmtst_buf_iter *v_iter; in timer_timeout() local
348 v_iter = from_timer(v_iter, data, timer_instance); in timer_timeout()
349 substream = v_iter->substream; in timer_timeout()
351 if (v_iter->suspend) in timer_timeout()
354 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !v_iter->is_buf_corrupted) in timer_timeout()
355 check_buf_block(v_iter, substream->runtime); in timer_timeout()
357 fill_block(v_iter, substream->runtime); in timer_timeout()
359 inc_buf_pos(v_iter, v_iter->b_rw, substream->runtime->dma_bytes); in timer_timeout()
361 v_iter->period_pos += v_iter->b_rw; in timer_timeout()
362 if (v_iter->period_pos >= v_iter->period_bytes) { in timer_timeout()
363 v_iter->period_pos %= v_iter->period_bytes; in timer_timeout()
367 if (!v_iter->suspend) in timer_timeout()
368 mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL + inject_delay); in timer_timeout()
374 struct pcmtst_buf_iter *v_iter; in snd_pcmtst_pcm_open() local
379 v_iter = kzalloc(sizeof(*v_iter), GFP_KERNEL); in snd_pcmtst_pcm_open()
380 if (!v_iter) in snd_pcmtst_pcm_open()
383 v_iter->substream = substream; in snd_pcmtst_pcm_open()
385 runtime->private_data = v_iter; in snd_pcmtst_pcm_open()
390 timer_setup(&v_iter->timer_instance, timer_timeout, 0); in snd_pcmtst_pcm_open()
397 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; in snd_pcmtst_pcm_close() local
399 timer_shutdown_sync(&v_iter->timer_instance); in snd_pcmtst_pcm_close()
400 v_iter->substream = NULL; in snd_pcmtst_pcm_close()
401 playback_capture_test = !v_iter->is_buf_corrupted; in snd_pcmtst_pcm_close()
402 kfree(v_iter); in snd_pcmtst_pcm_close()
406 static inline void reset_buf_iterator(struct pcmtst_buf_iter *v_iter) in reset_buf_iterator() argument
408 v_iter->buf_pos = 0; in reset_buf_iterator()
409 v_iter->is_buf_corrupted = false; in reset_buf_iterator()
410 v_iter->period_pos = 0; in reset_buf_iterator()
411 v_iter->total_bytes = 0; in reset_buf_iterator()
414 static inline void start_pcmtest_timer(struct pcmtst_buf_iter *v_iter) in start_pcmtest_timer() argument
416 v_iter->suspend = false; in start_pcmtest_timer()
417 mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL); in start_pcmtest_timer()
422 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; in snd_pcmtst_pcm_trigger() local
428 reset_buf_iterator(v_iter); in snd_pcmtst_pcm_trigger()
429 start_pcmtest_timer(v_iter); in snd_pcmtst_pcm_trigger()
432 start_pcmtest_timer(v_iter); in snd_pcmtst_pcm_trigger()
437 v_iter->suspend = true; in snd_pcmtst_pcm_trigger()
446 struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; in snd_pcmtst_pcm_pointer() local
448 return bytes_to_frames(substream->runtime, v_iter->buf_pos); in snd_pcmtst_pcm_pointer()
472 struct pcmtst_buf_iter *v_iter = runtime->private_data; in snd_pcmtst_pcm_prepare() local
477 v_iter->sample_bytes = samples_to_bytes(runtime, 1); in snd_pcmtst_pcm_prepare()
478 v_iter->period_bytes = snd_pcm_lib_period_bytes(substream); in snd_pcmtst_pcm_prepare()
479 v_iter->interleaved = true; in snd_pcmtst_pcm_prepare()
482 v_iter->chan_block = snd_pcm_lib_buffer_bytes(substream) / runtime->channels; in snd_pcmtst_pcm_prepare()
483 v_iter->interleaved = false; in snd_pcmtst_pcm_prepare()
486 v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC; in snd_pcmtst_pcm_prepare()
487 v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels; in snd_pcmtst_pcm_prepare()