industrialio-buffer.c (527c465a3c8716d93201ae34b7fc52679610596d) | industrialio-buffer.c (0123635a77f72e0787f6f8b3ac796a40f796fcc4) |
---|---|
1/* The industrial I/O core 2 * 3 * Copyright (c) 2008 Jonathan Cameron 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 as published by 7 * the Free Software Foundation. 8 * --- 57 unchanged lines hidden (view full) --- 66 to_wait = min_t(size_t, to_wait, 1); 67 to_flush = 0; 68 } 69 70 avail = iio_buffer_data_available(buf); 71 72 if (avail >= to_wait) { 73 /* force a flush for non-blocking reads */ | 1/* The industrial I/O core 2 * 3 * Copyright (c) 2008 Jonathan Cameron 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 as published by 7 * the Free Software Foundation. 8 * --- 57 unchanged lines hidden (view full) --- 66 to_wait = min_t(size_t, to_wait, 1); 67 to_flush = 0; 68 } 69 70 avail = iio_buffer_data_available(buf); 71 72 if (avail >= to_wait) { 73 /* force a flush for non-blocking reads */ |
74 if (!to_wait && !avail && to_flush) 75 iio_buffer_flush_hwfifo(indio_dev, buf, to_flush); | 74 if (!to_wait && avail < to_flush) 75 iio_buffer_flush_hwfifo(indio_dev, buf, 76 to_flush - avail); |
76 return true; 77 } 78 79 if (to_flush) 80 flushed = iio_buffer_flush_hwfifo(indio_dev, buf, 81 to_wait - avail); 82 if (flushed <= 0) 83 return false; 84 85 if (avail + flushed >= to_wait) 86 return true; 87 88 return false; 89} 90 91/** 92 * iio_buffer_read_first_n_outer() - chrdev read for buffer access | 77 return true; 78 } 79 80 if (to_flush) 81 flushed = iio_buffer_flush_hwfifo(indio_dev, buf, 82 to_wait - avail); 83 if (flushed <= 0) 84 return false; 85 86 if (avail + flushed >= to_wait) 87 return true; 88 89 return false; 90} 91 92/** 93 * iio_buffer_read_first_n_outer() - chrdev read for buffer access |
94 * @filp: File structure pointer for the char device 95 * @buf: Destination buffer for iio buffer read 96 * @n: First n bytes to read 97 * @f_ps: Long offset provided by the user as a seek position |
|
93 * 94 * This function relies on all buffer implementations having an 95 * iio_buffer as their first element. | 98 * 99 * This function relies on all buffer implementations having an 100 * iio_buffer as their first element. |
101 * 102 * Return: negative values corresponding to error codes or ret != 0 103 * for ending the reading activity |
|
96 **/ 97ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf, 98 size_t n, loff_t *f_ps) 99{ 100 struct iio_dev *indio_dev = filp->private_data; 101 struct iio_buffer *rb = indio_dev->buffer; 102 size_t datum_size; | 104 **/ 105ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf, 106 size_t n, loff_t *f_ps) 107{ 108 struct iio_dev *indio_dev = filp->private_data; 109 struct iio_buffer *rb = indio_dev->buffer; 110 size_t datum_size; |
103 size_t to_wait = 0; 104 size_t to_read; | 111 size_t to_wait; |
105 int ret; 106 107 if (!indio_dev->info) 108 return -ENODEV; 109 110 if (!rb || !rb->access->read_first_n) 111 return -EINVAL; 112 113 datum_size = rb->bytes_per_datum; 114 115 /* 116 * If datum_size is 0 there will never be anything to read from the 117 * buffer, so signal end of file now. 118 */ 119 if (!datum_size) 120 return 0; 121 | 112 int ret; 113 114 if (!indio_dev->info) 115 return -ENODEV; 116 117 if (!rb || !rb->access->read_first_n) 118 return -EINVAL; 119 120 datum_size = rb->bytes_per_datum; 121 122 /* 123 * If datum_size is 0 there will never be anything to read from the 124 * buffer, so signal end of file now. 125 */ 126 if (!datum_size) 127 return 0; 128 |
122 to_read = min_t(size_t, n / datum_size, rb->watermark); | 129 if (filp->f_flags & O_NONBLOCK) 130 to_wait = 0; 131 else 132 to_wait = min_t(size_t, n / datum_size, rb->watermark); |
123 | 133 |
124 if (!(filp->f_flags & O_NONBLOCK)) 125 to_wait = to_read; 126 | |
127 do { 128 ret = wait_event_interruptible(rb->pollq, | 134 do { 135 ret = wait_event_interruptible(rb->pollq, |
129 iio_buffer_ready(indio_dev, rb, to_wait, to_read)); | 136 iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size)); |
130 if (ret) 131 return ret; 132 133 if (!indio_dev->info) 134 return -ENODEV; 135 136 ret = rb->access->read_first_n(rb, n, buf); 137 if (ret == 0 && (filp->f_flags & O_NONBLOCK)) 138 ret = -EAGAIN; 139 } while (ret == 0); 140 141 return ret; 142} 143 144/** 145 * iio_buffer_poll() - poll the buffer to find out if it has data | 137 if (ret) 138 return ret; 139 140 if (!indio_dev->info) 141 return -ENODEV; 142 143 ret = rb->access->read_first_n(rb, n, buf); 144 if (ret == 0 && (filp->f_flags & O_NONBLOCK)) 145 ret = -EAGAIN; 146 } while (ret == 0); 147 148 return ret; 149} 150 151/** 152 * iio_buffer_poll() - poll the buffer to find out if it has data |
153 * @filp: File structure pointer for device access 154 * @wait: Poll table structure pointer for which the driver adds 155 * a wait queue 156 * 157 * Return: (POLLIN | POLLRDNORM) if data is available for reading 158 * or 0 for other cases |
|
146 */ 147unsigned int iio_buffer_poll(struct file *filp, 148 struct poll_table_struct *wait) 149{ 150 struct iio_dev *indio_dev = filp->private_data; 151 struct iio_buffer *rb = indio_dev->buffer; 152 153 if (!indio_dev->info) --- 977 unchanged lines hidden (view full) --- 1131 return 0; 1132 1133 /* Ensure return value is 0 or 1. */ 1134 return !!test_bit(bit, buffer->scan_mask); 1135}; 1136EXPORT_SYMBOL_GPL(iio_scan_mask_query); 1137 1138/** | 159 */ 160unsigned int iio_buffer_poll(struct file *filp, 161 struct poll_table_struct *wait) 162{ 163 struct iio_dev *indio_dev = filp->private_data; 164 struct iio_buffer *rb = indio_dev->buffer; 165 166 if (!indio_dev->info) --- 977 unchanged lines hidden (view full) --- 1144 return 0; 1145 1146 /* Ensure return value is 0 or 1. */ 1147 return !!test_bit(bit, buffer->scan_mask); 1148}; 1149EXPORT_SYMBOL_GPL(iio_scan_mask_query); 1150 1151/** |
1139 * struct iio_demux_table() - table describing demux memcpy ops | 1152 * struct iio_demux_table - table describing demux memcpy ops |
1140 * @from: index to copy from 1141 * @to: index to copy to 1142 * @length: how many bytes to copy 1143 * @l: list head used for management 1144 */ 1145struct iio_demux_table { 1146 unsigned from; 1147 unsigned to; --- 225 unchanged lines hidden --- | 1153 * @from: index to copy from 1154 * @to: index to copy to 1155 * @length: how many bytes to copy 1156 * @l: list head used for management 1157 */ 1158struct iio_demux_table { 1159 unsigned from; 1160 unsigned to; --- 225 unchanged lines hidden --- |