|
@@ -159,22 +159,16 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
159
|
159
|
size_t data_end = ( data_start + len );
|
160
|
160
|
int rc;
|
161
|
161
|
|
162
|
|
- DBGC ( buffer, "BUFFER %p [%lx,%lx) filling portion [%lx,%lx)\n",
|
163
|
|
- buffer, user_to_phys ( buffer->addr, 0 ),
|
164
|
|
- user_to_phys ( buffer->addr, buffer->len ),
|
165
|
|
- user_to_phys ( buffer->addr, data_start ),
|
166
|
|
- user_to_phys ( buffer->addr, data_end ) );
|
|
162
|
+ DBGC2 ( buffer, "BUFFER %p [%lx,%lx) filling portion [%lx,%lx)\n",
|
|
163
|
+ buffer, user_to_phys ( buffer->addr, 0 ),
|
|
164
|
+ user_to_phys ( buffer->addr, buffer->len ),
|
|
165
|
+ user_to_phys ( buffer->addr, data_start ),
|
|
166
|
+ user_to_phys ( buffer->addr, data_end ) );
|
167
|
167
|
|
168
|
168
|
/* Check that block fits within buffer, expand if necessary */
|
169
|
169
|
if ( data_end > buffer->len ) {
|
170
|
|
- if ( ( rc = expand_buffer ( buffer, data_end ) ) != 0 ) {
|
171
|
|
- DBGC ( buffer, "BUFFER %p could not expand :%s\n",
|
172
|
|
- buffer, strerror ( rc ) );
|
|
170
|
+ if ( ( rc = expand_buffer ( buffer, data_end ) ) != 0 )
|
173
|
171
|
return rc;
|
174
|
|
- }
|
175
|
|
- DBGC ( buffer, "BUFFER %p expanded to [%lx,%lx)\n", buffer,
|
176
|
|
- user_to_phys ( buffer->addr, 0 ),
|
177
|
|
- user_to_phys ( buffer->addr, buffer->len ) );
|
178
|
172
|
assert ( buffer->len >= data_end );
|
179
|
173
|
}
|
180
|
174
|
|
|
@@ -200,18 +194,18 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
200
|
194
|
/* Link 'after' block to 'before' block */
|
201
|
195
|
before.next = after.start;
|
202
|
196
|
|
203
|
|
- DBGC ( buffer, "BUFFER %p split before [%lx,%lx) after [%lx,%lx)\n",
|
204
|
|
- buffer, user_to_phys ( buffer->addr, before.start ),
|
205
|
|
- user_to_phys ( buffer->addr, before.end ),
|
206
|
|
- user_to_phys ( buffer->addr, after.start ),
|
207
|
|
- user_to_phys ( buffer->addr, after.end ) );
|
|
197
|
+ DBGC2 ( buffer, "BUFFER %p split before [%lx,%lx) after [%lx,%lx)\n",
|
|
198
|
+ buffer, user_to_phys ( buffer->addr, before.start ),
|
|
199
|
+ user_to_phys ( buffer->addr, before.end ),
|
|
200
|
+ user_to_phys ( buffer->addr, after.start ),
|
|
201
|
+ user_to_phys ( buffer->addr, after.end ) );
|
208
|
202
|
|
209
|
203
|
/* Write back 'before' block, if any */
|
210
|
204
|
if ( before.end == 0 ) {
|
211
|
205
|
/* No 'before' block: update buffer->fill */
|
212
|
206
|
buffer->fill = after.start;
|
213
|
|
- DBGC ( buffer, "BUFFER %p full up to %lx\n", buffer,
|
214
|
|
- user_to_phys ( buffer->addr, buffer->fill ) );
|
|
207
|
+ DBGC2 ( buffer, "BUFFER %p full up to %lx\n", buffer,
|
|
208
|
+ user_to_phys ( buffer->addr, buffer->fill ) );
|
215
|
209
|
} else {
|
216
|
210
|
/* Write back 'before' block */
|
217
|
211
|
store_free_block ( buffer, &before );
|
|
@@ -221,8 +215,8 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
221
|
215
|
if ( after.end == buffer->len ) {
|
222
|
216
|
/* 'After' block is the final block: update buffer->free */
|
223
|
217
|
buffer->free = after.start;
|
224
|
|
- DBGC ( buffer, "BUFFER %p free from %lx onwards\n", buffer,
|
225
|
|
- user_to_phys ( buffer->addr, buffer->free ) );
|
|
218
|
+ DBGC2 ( buffer, "BUFFER %p free from %lx onwards\n", buffer,
|
|
219
|
+ user_to_phys ( buffer->addr, buffer->free ) );
|
226
|
220
|
} else {
|
227
|
221
|
/* Write back 'after' block */
|
228
|
222
|
store_free_block ( buffer, &after );
|
|
@@ -233,3 +227,39 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
233
|
227
|
|
234
|
228
|
return 0;
|
235
|
229
|
}
|
|
230
|
+
|
|
231
|
+/** Expand data buffer
|
|
232
|
+ *
|
|
233
|
+ * @v buffer Data buffer
|
|
234
|
+ * @v new_len New length
|
|
235
|
+ * @ret rc Return status code
|
|
236
|
+ *
|
|
237
|
+ * Expand the data buffer to accommodate more data. Some buffers may
|
|
238
|
+ * not support being expanded.
|
|
239
|
+ */
|
|
240
|
+int expand_buffer ( struct buffer *buffer, size_t new_len ) {
|
|
241
|
+ int rc;
|
|
242
|
+
|
|
243
|
+ if ( new_len <= buffer->len )
|
|
244
|
+ return 0;
|
|
245
|
+
|
|
246
|
+ DBGC ( buffer, "BUFFER %p attempting to expand from length %zx to "
|
|
247
|
+ "length %zx\n", buffer, buffer->len, new_len );
|
|
248
|
+
|
|
249
|
+ if ( ! buffer->expand ) {
|
|
250
|
+ DBGC ( buffer, "BUFFER %p is not expandable\n", buffer );
|
|
251
|
+ return -ENOBUFS;
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ if ( ( rc = buffer->expand ( buffer, new_len ) ) != 0 ) {
|
|
255
|
+ DBGC ( buffer, "BUFFER %p could not expand: %s\n",
|
|
256
|
+ buffer, strerror ( rc ) );
|
|
257
|
+ return rc;
|
|
258
|
+ }
|
|
259
|
+
|
|
260
|
+ DBGC ( buffer, "BUFFER %p expanded to [%lx,%lx)\n", buffer,
|
|
261
|
+ user_to_phys ( buffer->addr, 0 ),
|
|
262
|
+ user_to_phys ( buffer->addr, buffer->len ) );
|
|
263
|
+
|
|
264
|
+ return 0;
|
|
265
|
+}
|