^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * dvb_ringbuffer.h: ring buffer implementation for the dvb driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2003 Oliver Endriss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2004 Andrew de Quincey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * based on code originally found in av7110.c & dvb_ci.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 1999-2003 Ralph Metzler & Marcus Metzler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * for convergence integrated media GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * modify it under the terms of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * as published by the Free Software Foundation; either version 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * of the License, or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #ifndef _DVB_RINGBUFFER_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define _DVB_RINGBUFFER_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * struct dvb_ringbuffer - Describes a ring buffer used at DVB framework
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @data: Area were the ringbuffer data is written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @size: size of the ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * @pread: next position to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @pwrite: next position to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @error: used by ringbuffer clients to indicate that an error happened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @queue: Wait queue used by ringbuffer clients to indicate when buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * was filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * @lock: Spinlock used to protect the ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct dvb_ringbuffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ssize_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ssize_t pread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ssize_t pwrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) wait_queue_head_t queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define DVB_RINGBUFFER_PKTHDRSIZE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * dvb_ringbuffer_init - initialize ring buffer, lock and queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @data: pointer to the buffer where the data will be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @len: bytes from ring buffer into @buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern void dvb_ringbuffer_init(struct dvb_ringbuffer *rbuf, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * dvb_ringbuffer_empty - test whether buffer is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) extern int dvb_ringbuffer_empty(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * dvb_ringbuffer_free - returns the number of free bytes in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Return: number of free bytes in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) extern ssize_t dvb_ringbuffer_free(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * dvb_ringbuffer_avail - returns the number of bytes waiting in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Return: number of bytes waiting in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) extern ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * dvb_ringbuffer_reset - resets the ringbuffer to initial state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Resets the read and write pointers to zero and flush the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * This counts as a read and write operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) extern void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * read routines & macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * dvb_ringbuffer_flush - flush buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) extern void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * dvb_ringbuffer_flush_spinlock_wakeup- flush buffer protected by spinlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * and wake-up waiting task(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) extern void dvb_ringbuffer_flush_spinlock_wakeup(struct dvb_ringbuffer *rbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * DVB_RINGBUFFER_PEEK - peek at byte @offs in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @offs: offset inside the ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define DVB_RINGBUFFER_PEEK(rbuf, offs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ((rbuf)->data[((rbuf)->pread + (offs)) % (rbuf)->size])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * DVB_RINGBUFFER_SKIP - advance read ptr by @num bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @num: number of bytes to advance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define DVB_RINGBUFFER_SKIP(rbuf, num) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) (rbuf)->pread = ((rbuf)->pread + (num)) % (rbuf)->size;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * dvb_ringbuffer_read_user - Reads a buffer into a user pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * @buf: pointer to the buffer where the data will be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * @len: bytes from ring buffer into @buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * This variant assumes that the buffer is a memory at the userspace. So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * it will internally call copy_to_user().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Return: number of bytes transferred or -EFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) extern ssize_t dvb_ringbuffer_read_user(struct dvb_ringbuffer *rbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u8 __user *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * dvb_ringbuffer_read - Reads a buffer into a pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @buf: pointer to the buffer where the data will be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @len: bytes from ring buffer into @buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * This variant assumes that the buffer is a memory at the Kernel space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Return: number of bytes transferred or -EFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) extern void dvb_ringbuffer_read(struct dvb_ringbuffer *rbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u8 *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * write routines & macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * DVB_RINGBUFFER_WRITE_BYTE - write single byte to ring buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * @byte: byte to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define DVB_RINGBUFFER_WRITE_BYTE(rbuf, byte) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) { (rbuf)->data[(rbuf)->pwrite] = (byte); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) (rbuf)->pwrite = ((rbuf)->pwrite + 1) % (rbuf)->size; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * dvb_ringbuffer_write - Writes a buffer into the ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @buf: pointer to the buffer where the data will be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * @len: bytes from ring buffer into @buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * This variant assumes that the buffer is a memory at the Kernel space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * return: number of bytes transferred or -EFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) extern ssize_t dvb_ringbuffer_write(struct dvb_ringbuffer *rbuf, const u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * dvb_ringbuffer_write_user - Writes a buffer received via a user pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * @rbuf: pointer to struct dvb_ringbuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * @buf: pointer to the buffer where the data will be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * @len: bytes from ring buffer into @buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * This variant assumes that the buffer is a memory at the userspace. So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * it will internally call copy_from_user().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * Return: number of bytes transferred or -EFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) extern ssize_t dvb_ringbuffer_write_user(struct dvb_ringbuffer *rbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) const u8 __user *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * dvb_ringbuffer_pkt_write - Write a packet into the ringbuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * @rbuf: Ringbuffer to write to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * @buf: Buffer to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @len: Length of buffer (currently limited to 65535 bytes max).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Return: Number of bytes written, or -EFAULT, -ENOMEM, -EVINAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) extern ssize_t dvb_ringbuffer_pkt_write(struct dvb_ringbuffer *rbuf, u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * dvb_ringbuffer_pkt_read_user - Read from a packet in the ringbuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @rbuf: Ringbuffer concerned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @idx: Packet index as returned by dvb_ringbuffer_pkt_next().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @offset: Offset into packet to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * @buf: Destination buffer for data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * @len: Size of destination buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * Return: Number of bytes read, or -EFAULT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * unlike dvb_ringbuffer_read(), this does **NOT** update the read pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * in the ringbuffer. You must use dvb_ringbuffer_pkt_dispose() to mark a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * packet as no longer required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) extern ssize_t dvb_ringbuffer_pkt_read_user(struct dvb_ringbuffer *rbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) size_t idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int offset, u8 __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * dvb_ringbuffer_pkt_read - Read from a packet in the ringbuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Note: unlike dvb_ringbuffer_read_user(), this DOES update the read pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * in the ringbuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @rbuf: Ringbuffer concerned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @idx: Packet index as returned by dvb_ringbuffer_pkt_next().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @offset: Offset into packet to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * @buf: Destination buffer for data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * @len: Size of destination buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Return: Number of bytes read, or -EFAULT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) extern ssize_t dvb_ringbuffer_pkt_read(struct dvb_ringbuffer *rbuf, size_t idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int offset, u8 *buf, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * dvb_ringbuffer_pkt_dispose - Dispose of a packet in the ring buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * @rbuf: Ring buffer concerned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @idx: Packet index as returned by dvb_ringbuffer_pkt_next().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) extern void dvb_ringbuffer_pkt_dispose(struct dvb_ringbuffer *rbuf, size_t idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * dvb_ringbuffer_pkt_next - Get the index of the next packet in a ringbuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * @rbuf: Ringbuffer concerned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * @idx: Previous packet index, or -1 to return the first packet index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @pktlen: On success, will be updated to contain the length of the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * returns Packet index (if >=0), or -1 if no packets available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) extern ssize_t dvb_ringbuffer_pkt_next(struct dvb_ringbuffer *rbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) size_t idx, size_t *pktlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #endif /* _DVB_RINGBUFFER_H_ */