1 | /* |
---|
2 | * mapper.c - Map memory, file or device in process virtual address space. |
---|
3 | * |
---|
4 | * Authors Mohamed Lamine Karaoui (2015) |
---|
5 | * Alain Greiner (2016) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH. |
---|
10 | * |
---|
11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #include <kernel_config.h> |
---|
26 | #include <hal_types.h> |
---|
27 | #include <hal_special.h> |
---|
28 | #include <grdxt.h> |
---|
29 | #include <rwlock.h> |
---|
30 | #include <printk.h> |
---|
31 | #include <thread.h> |
---|
32 | #include <core.h> |
---|
33 | #include <process.h> |
---|
34 | #include <kmem.h> |
---|
35 | #include <kcm.h> |
---|
36 | #include <page.h> |
---|
37 | #include <cluster.h> |
---|
38 | #include <vfs.h> |
---|
39 | #include <mapper.h> |
---|
40 | |
---|
41 | ////////////////////////// |
---|
42 | mapper_t * mapper_create() |
---|
43 | { |
---|
44 | mapper_t * mapper; |
---|
45 | kmem_req_t req; |
---|
46 | error_t error; |
---|
47 | |
---|
48 | // allocate memory for associated mapper |
---|
49 | req.type = KMEM_MAPPER; |
---|
50 | req.size = sizeof(mapper_t); |
---|
51 | req.flags = AF_KERNEL | AF_ZERO; |
---|
52 | mapper = (mapper_t *)kmem_alloc( &req ); |
---|
53 | |
---|
54 | if( mapper == NULL ) |
---|
55 | { |
---|
56 | printk("\n[ERROR] in %s : no memory for mapper descriptor\n", __FUNCTION__ ); |
---|
57 | return NULL; |
---|
58 | } |
---|
59 | |
---|
60 | // initialize refcount & inode |
---|
61 | mapper->refcount = 0; |
---|
62 | mapper->inode = NULL; |
---|
63 | |
---|
64 | // initialize radix tree |
---|
65 | error = grdxt_init( &mapper->radix, |
---|
66 | CONFIG_VMM_GRDXT_W1, |
---|
67 | CONFIG_VMM_GRDXT_W2, |
---|
68 | CONFIG_VMM_GRDXT_W3 ); |
---|
69 | |
---|
70 | if( error ) |
---|
71 | { |
---|
72 | printk("\n[ERROR] in %s : cannot initialize radix tree\n", __FUNCTION__ ); |
---|
73 | req.type = KMEM_MAPPER; |
---|
74 | req.ptr = mapper; |
---|
75 | kmem_free( &req ); |
---|
76 | return NULL; |
---|
77 | } |
---|
78 | |
---|
79 | // initialize mapper lock |
---|
80 | rwlock_init( &mapper->lock ); |
---|
81 | |
---|
82 | // initialize waiting threads xlist (empty) |
---|
83 | xlist_root_init( XPTR( local_cxy , &mapper->wait_root ) ); |
---|
84 | |
---|
85 | // initialize vsegs xlist (empty) |
---|
86 | xlist_root_init( XPTR( local_cxy , &mapper->vsegs_root ) ); |
---|
87 | |
---|
88 | return mapper; |
---|
89 | |
---|
90 | } // end mapper_create() |
---|
91 | |
---|
92 | /////////////////////////////////////////// |
---|
93 | error_t mapper_destroy( mapper_t * mapper ) |
---|
94 | { |
---|
95 | page_t * page; |
---|
96 | uint32_t found_index = 0; |
---|
97 | uint32_t start_index = 0; |
---|
98 | kmem_req_t req; |
---|
99 | error_t error; |
---|
100 | |
---|
101 | // scan radix three and release all registered pages to PPM |
---|
102 | do |
---|
103 | { |
---|
104 | // get page from radix tree |
---|
105 | page = (page_t *)grdxt_get_first( &mapper->radix , start_index , &found_index ); |
---|
106 | |
---|
107 | if( page != NULL ) |
---|
108 | { |
---|
109 | // remove page from mapper and release to PPM |
---|
110 | error = mapper_release_page( mapper , found_index , page ); |
---|
111 | |
---|
112 | if ( error ) return error; |
---|
113 | |
---|
114 | // update start_key value for next page |
---|
115 | start_index = found_index; |
---|
116 | } |
---|
117 | } |
---|
118 | while( page != NULL ); |
---|
119 | |
---|
120 | // release the memory allocated to radix-tree itself |
---|
121 | grdxt_destroy( &mapper->radix ); |
---|
122 | |
---|
123 | // release memory for mapper descriptor |
---|
124 | req.type = KMEM_MAPPER; |
---|
125 | req.ptr = mapper; |
---|
126 | kmem_free( &req ); |
---|
127 | |
---|
128 | return 0; |
---|
129 | |
---|
130 | } // end mapper_destroy() |
---|
131 | |
---|
132 | |
---|
133 | //////////////////////////////////////////// |
---|
134 | page_t * mapper_get_page( mapper_t * mapper, |
---|
135 | uint32_t index ) |
---|
136 | { |
---|
137 | kmem_req_t req; |
---|
138 | page_t * page; |
---|
139 | error_t error; |
---|
140 | |
---|
141 | thread_t * this = CURRENT_THREAD; |
---|
142 | |
---|
143 | // take mapper lock in READ_MODE |
---|
144 | rwlock_rd_lock( &mapper->lock ); |
---|
145 | |
---|
146 | // search page in radix tree |
---|
147 | page = (page_t *)grdxt_lookup( &mapper->radix , index ); |
---|
148 | |
---|
149 | // test if page available in mapper |
---|
150 | if( ( page == NULL) || page_is_flag( page , PG_INLOAD ) ) // page not available / |
---|
151 | { |
---|
152 | // release the lock in READ_MODE and take it in WRITE_MODE |
---|
153 | rwlock_rd_unlock( &mapper->lock ); |
---|
154 | rwlock_wr_lock( &mapper->lock ); |
---|
155 | |
---|
156 | // second test on missing page because the page status can have been modified |
---|
157 | // by another thread, when passing from READ_MODE to WRITE_MODE. |
---|
158 | // from this point there is no concurrent accesses to mapper. |
---|
159 | |
---|
160 | page = grdxt_lookup( &mapper->radix , index ); |
---|
161 | |
---|
162 | if ( page == NULL ) // missing page => load it from file system |
---|
163 | { |
---|
164 | // allocate one page from PPM |
---|
165 | req.type = KMEM_PAGE; |
---|
166 | req.size = 0; |
---|
167 | req.flags = AF_NONE; |
---|
168 | page = kmem_alloc( &req ); |
---|
169 | |
---|
170 | if( page == NULL ) |
---|
171 | { |
---|
172 | printk("\n[ERROR] in %s : thread %x cannot allocate a page in cluster %x\n", |
---|
173 | __FUNCTION__ , this->trdid , local_cxy ); |
---|
174 | rwlock_wr_unlock( &mapper->lock ); |
---|
175 | return NULL; |
---|
176 | } |
---|
177 | |
---|
178 | // initialize the page descriptor |
---|
179 | page_init( page ); |
---|
180 | page_set_flag( page , PG_INIT ); |
---|
181 | page_set_flag( page , PG_INLOAD ); |
---|
182 | page_refcount_up( page ); |
---|
183 | page->mapper = mapper; |
---|
184 | page->index = index; |
---|
185 | |
---|
186 | // insert page in mapper radix tree |
---|
187 | error = grdxt_insert( &mapper->radix, index , page ); |
---|
188 | |
---|
189 | // release mapper lock from WRITE_MODE |
---|
190 | rwlock_wr_unlock( &mapper->lock ); |
---|
191 | |
---|
192 | if( error ) |
---|
193 | { |
---|
194 | printk("\n[ERROR] in %s : thread %x cannot insert page in mapper\n", |
---|
195 | __FUNCTION__ , this->trdid ); |
---|
196 | mapper_release_page( mapper , index , page ); |
---|
197 | page_clear_flag( page , PG_ALL ); |
---|
198 | req.ptr = page; |
---|
199 | req.type = KMEM_PAGE; |
---|
200 | kmem_free(&req); |
---|
201 | return NULL; |
---|
202 | } |
---|
203 | |
---|
204 | // launch I/O operation to load page from file system |
---|
205 | error = mapper_updt_page( mapper , index , page ); |
---|
206 | |
---|
207 | if( error ) |
---|
208 | { |
---|
209 | printk("\n[ERROR] in %s : thread %x cannot load page from device\n", |
---|
210 | __FUNCTION__ , this->trdid ); |
---|
211 | mapper_release_page( mapper , index , page ); |
---|
212 | page_clear_flag( page , PG_ALL ); |
---|
213 | req.ptr = page; |
---|
214 | req.type = KMEM_PAGE; |
---|
215 | kmem_free( &req ); |
---|
216 | return NULL; |
---|
217 | } |
---|
218 | |
---|
219 | // update the mapper and index fields in page descriptor |
---|
220 | page->mapper = mapper; |
---|
221 | page->index = index; |
---|
222 | |
---|
223 | // reset the page INLOAD flag to make the page available to all readers |
---|
224 | page_clear_flag( page , PG_INLOAD ); |
---|
225 | |
---|
226 | } |
---|
227 | else if( page_is_flag( page , PG_INLOAD ) ) // page is loaded by another thread |
---|
228 | { |
---|
229 | // release mapper lock from WRITE_MODE |
---|
230 | rwlock_wr_unlock( &mapper->lock ); |
---|
231 | |
---|
232 | // deschedule to wait load completion |
---|
233 | while( 1 ) |
---|
234 | { |
---|
235 | // exit waiting loop when loaded |
---|
236 | if( page_is_flag( page , PG_INLOAD ) ) break; |
---|
237 | |
---|
238 | // deschedule |
---|
239 | sched_yield(); |
---|
240 | } |
---|
241 | |
---|
242 | } |
---|
243 | |
---|
244 | return page; |
---|
245 | } |
---|
246 | else |
---|
247 | { |
---|
248 | // release lock from READ_MODE |
---|
249 | rwlock_rd_unlock( &mapper->lock ); |
---|
250 | |
---|
251 | return page; |
---|
252 | } |
---|
253 | } // end mapper_get_page() |
---|
254 | |
---|
255 | /////////////////////////////////////////////// |
---|
256 | error_t mapper_release_page( mapper_t * mapper, |
---|
257 | uint32_t index, |
---|
258 | page_t * page ) |
---|
259 | { |
---|
260 | error_t error; |
---|
261 | |
---|
262 | // lauch IO operation to update page to file system |
---|
263 | error = mapper_sync_page( mapper , index , page ); |
---|
264 | |
---|
265 | if( error ) |
---|
266 | { |
---|
267 | printk("\n[ERROR] in %s : cannot update file system\n", __FUNCTION__ ); |
---|
268 | return EIO; |
---|
269 | } |
---|
270 | |
---|
271 | // take mapper lock in WRITE_MODE |
---|
272 | rwlock_wr_lock( &mapper->lock ); |
---|
273 | |
---|
274 | // remove physical page from radix tree |
---|
275 | grdxt_remove( &mapper->radix , page->index ); |
---|
276 | |
---|
277 | // release mapper lock from WRITE_MODE |
---|
278 | rwlock_wr_unlock( &mapper->lock ); |
---|
279 | |
---|
280 | // release page to PPM |
---|
281 | kmem_req_t req; |
---|
282 | req.type = KMEM_PAGE; |
---|
283 | req.ptr = page; |
---|
284 | kmem_free( &req ); |
---|
285 | |
---|
286 | return 0; |
---|
287 | |
---|
288 | } // end mapper_release_page() |
---|
289 | |
---|
290 | //////////////////////////////////////////// |
---|
291 | error_t mapper_updt_page( mapper_t * mapper, |
---|
292 | uint32_t index, |
---|
293 | page_t * page ) |
---|
294 | { |
---|
295 | uint32_t type; |
---|
296 | vfs_inode_t * inode; |
---|
297 | error_t error = 0; |
---|
298 | |
---|
299 | if( page == NULL ) |
---|
300 | { |
---|
301 | printk("\n[PANIC] in %s : page pointer is NULL\n", __FUNCTION__ ); |
---|
302 | hal_core_sleep(); |
---|
303 | } |
---|
304 | |
---|
305 | if( mapper == NULL ) |
---|
306 | { |
---|
307 | printk("\n[PANIC] in %s : no mapper for this page\n", __FUNCTION__ ); |
---|
308 | hal_core_sleep(); |
---|
309 | } |
---|
310 | |
---|
311 | // get file system type and inode pointer |
---|
312 | inode = mapper->inode; |
---|
313 | type = inode->ctx->type; |
---|
314 | |
---|
315 | // get page lock |
---|
316 | page_lock( page ); |
---|
317 | |
---|
318 | // get mapper lock in WRITE_MODE |
---|
319 | rwlock_wr_lock( &mapper->lock ); |
---|
320 | |
---|
321 | // call proper I/O operation to update file system |
---|
322 | if ( type == FS_TYPE_FATFS ) error = fatfs_read_page( page ); |
---|
323 | else if( type == FS_TYPE_RAMFS ) error = ramfs_read_page( page ); |
---|
324 | else |
---|
325 | { |
---|
326 | printk("\n[PANIC] in %s : undefined file system type\n", __FUNCTION__ ); |
---|
327 | hal_core_sleep(); |
---|
328 | } |
---|
329 | |
---|
330 | // release mapper lock from WRITE_MODE |
---|
331 | rwlock_wr_unlock( &mapper->lock ); |
---|
332 | |
---|
333 | // release page lock |
---|
334 | page_unlock( page ); |
---|
335 | |
---|
336 | if( error ) |
---|
337 | { |
---|
338 | printk("\n[PANIC] in %s : cannot access file system\n", __FUNCTION__ ); |
---|
339 | return EIO; |
---|
340 | } |
---|
341 | |
---|
342 | return 0; |
---|
343 | } // end mapper_updt_page |
---|
344 | |
---|
345 | //////////////////////////////////////////// |
---|
346 | error_t mapper_sync_page( mapper_t * mapper, |
---|
347 | uint32_t index, |
---|
348 | page_t * page ) |
---|
349 | { |
---|
350 | uint32_t type; |
---|
351 | vfs_inode_t * inode; |
---|
352 | error_t error = 0; |
---|
353 | |
---|
354 | if( page == NULL ) |
---|
355 | { |
---|
356 | printk("\n[PANIC] in %s : page pointer is NULL\n", __FUNCTION__ ); |
---|
357 | hal_core_sleep(); |
---|
358 | } |
---|
359 | |
---|
360 | if( mapper == NULL ) |
---|
361 | { |
---|
362 | printk("\n[PANIC] in %s : no mapper for this page\n", __FUNCTION__ ); |
---|
363 | hal_core_sleep(); |
---|
364 | } |
---|
365 | |
---|
366 | if( page_is_flag( page , PG_DIRTY ) ) |
---|
367 | { |
---|
368 | // get file system type and inode pointer |
---|
369 | inode = mapper->inode; |
---|
370 | type = inode->ctx->type; |
---|
371 | |
---|
372 | // get page lock |
---|
373 | page_lock( page ); |
---|
374 | |
---|
375 | // get mapper lock in READ_MODE |
---|
376 | rwlock_rd_lock( &mapper->lock ); |
---|
377 | |
---|
378 | // call proper I/O operation to update file system |
---|
379 | if ( type == FS_TYPE_FATFS ) error = fatfs_write_page( page ); |
---|
380 | else if( type == FS_TYPE_RAMFS ) error = ramfs_write_page( page ); |
---|
381 | else |
---|
382 | { |
---|
383 | printk("\n[PANIC] in %s : undefined file system type\n", __FUNCTION__ ); |
---|
384 | hal_core_sleep(); |
---|
385 | } |
---|
386 | |
---|
387 | // release mapper lock from READ_MODE |
---|
388 | rwlock_rd_unlock( &mapper->lock ); |
---|
389 | |
---|
390 | // release page lock |
---|
391 | page_unlock( page ); |
---|
392 | |
---|
393 | if( error ) |
---|
394 | { |
---|
395 | printk("\n[PANIC] in %s : cannot update file system\n", __FUNCTION__ ); |
---|
396 | return EIO; |
---|
397 | } |
---|
398 | |
---|
399 | // clear dirty bit |
---|
400 | page_undo_dirty( page ); |
---|
401 | } |
---|
402 | |
---|
403 | return 0; |
---|
404 | |
---|
405 | } // end mapper_sync_page() |
---|
406 | |
---|
407 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
408 | // This static function is called by the mapper_move fragments() function. |
---|
409 | // It moves one fragment between an user buffer and the kernel mapper. |
---|
410 | // Implementation Note: It can require access to one or two pages in mapper: |
---|
411 | // [max_page_index == min_page_index] <=> fragment fit in one mapper page |
---|
412 | // [max_page index == min_page_index + 1] <=> fragment spread on two mapper pages |
---|
413 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
414 | static error_t mapper_move_one_fragment( mapper_t * mapper, |
---|
415 | bool_t to_buffer, |
---|
416 | fragment_t * fragment ) |
---|
417 | { |
---|
418 | uint32_t size; // number of bytes in fragment |
---|
419 | cxy_t buf_cxy; // cluster identifier for user buffer |
---|
420 | uint8_t * buf_ptr; // local pointer on first byte in user buffer |
---|
421 | |
---|
422 | xptr_t xp_buf; // extended pointer on byte in user buffer |
---|
423 | xptr_t xp_map; // extended pointer on byte in kernel mapper |
---|
424 | |
---|
425 | uint32_t min_file_offset; // offset of first byte in file |
---|
426 | uint32_t max_file_offset; // offset of last byte in file |
---|
427 | |
---|
428 | uint32_t first_page_index; // index of first page in mapper |
---|
429 | uint32_t first_page_offset; // offset of first byte in first page in mapper |
---|
430 | uint32_t first_page_size; // offset of first byte in first page in mapper |
---|
431 | |
---|
432 | uint32_t second_page_index; // index of last page in mapper |
---|
433 | uint32_t second_page_offset; // offset of last byte in last page in mapper |
---|
434 | uint32_t second_page_size; // offset of last byte in last page in mapper |
---|
435 | |
---|
436 | page_t * page; // pointer on one page descriptor in mapper |
---|
437 | uint8_t * map_ptr; // local pointer on first byte in mapper |
---|
438 | |
---|
439 | // get fragment attributes in user buffer |
---|
440 | buf_cxy = fragment->buf_cxy; |
---|
441 | buf_ptr = fragment->buf_ptr; |
---|
442 | size = fragment->size; |
---|
443 | |
---|
444 | if( size > CONFIG_PPM_PAGE_SIZE ) |
---|
445 | { |
---|
446 | printk("\n[PANIC] in %s : illegal fragment size = %d\n", |
---|
447 | __FUNCTION__ , size ); |
---|
448 | return EINVAL; |
---|
449 | } |
---|
450 | |
---|
451 | // compute offsets of first and last bytes in file |
---|
452 | min_file_offset = fragment->file_offset; |
---|
453 | max_file_offset = min_file_offset + size; |
---|
454 | |
---|
455 | // compute indexes of pages for first and last byte in mapper |
---|
456 | first_page_index = min_file_offset >> CONFIG_PPM_PAGE_SHIFT; |
---|
457 | second_page_index = max_file_offset >> CONFIG_PPM_PAGE_SHIFT; |
---|
458 | |
---|
459 | if ( first_page_index == second_page_index ) // only one page in mapper |
---|
460 | { |
---|
461 | // compute offset and size for page in mapper |
---|
462 | first_page_offset = min_file_offset & (1<<CONFIG_PPM_PAGE_SHIFT); |
---|
463 | first_page_size = size; |
---|
464 | |
---|
465 | // get pointer on first page in mapper |
---|
466 | page = mapper_get_page( mapper , first_page_index ); |
---|
467 | |
---|
468 | if ( page == NULL ) return EINVAL; |
---|
469 | |
---|
470 | // compute pointer on fragment first byte in mapper |
---|
471 | map_ptr = (uint8_t *)ppm_page2base( page ) + first_page_offset; |
---|
472 | |
---|
473 | // compute extended pointers in mapper and in buffer |
---|
474 | xp_map = XPTR( local_cxy , map_ptr ); |
---|
475 | xp_buf = XPTR( buf_cxy , buf_ptr ); |
---|
476 | |
---|
477 | // move fragment |
---|
478 | if( to_buffer ) |
---|
479 | { |
---|
480 | hal_remote_memcpy( xp_buf , xp_map , first_page_size ); |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | page_do_dirty( page ); |
---|
485 | hal_remote_memcpy( xp_map , xp_buf , first_page_size ); |
---|
486 | } |
---|
487 | } |
---|
488 | else // two pages in mapper |
---|
489 | { |
---|
490 | // compute offset and size for first page in mapper |
---|
491 | first_page_offset = min_file_offset & (1<<CONFIG_PPM_PAGE_SHIFT); |
---|
492 | first_page_size = CONFIG_PPM_PAGE_SIZE - first_page_offset; |
---|
493 | |
---|
494 | // get pointer on first page descriptor in mapper |
---|
495 | page = mapper_get_page( mapper , first_page_index ); |
---|
496 | |
---|
497 | if ( page == NULL ) return EINVAL; |
---|
498 | |
---|
499 | // compute local pointer on first byte in first page in mapper |
---|
500 | map_ptr = (uint8_t *)ppm_page2base(page) + first_page_offset; |
---|
501 | |
---|
502 | // compute extended pointers |
---|
503 | xp_map = XPTR( local_cxy , map_ptr ); |
---|
504 | xp_buf = XPTR( buf_cxy , buf_ptr ); |
---|
505 | |
---|
506 | // move fragment to/from first page |
---|
507 | if( to_buffer ) |
---|
508 | { |
---|
509 | hal_remote_memcpy( xp_buf , xp_map , first_page_size ); |
---|
510 | } |
---|
511 | else |
---|
512 | { |
---|
513 | page_do_dirty( page ); |
---|
514 | hal_remote_memcpy( xp_map , xp_buf , first_page_size ); |
---|
515 | } |
---|
516 | |
---|
517 | // compute offset and size for second page in mapper |
---|
518 | second_page_offset = 0; |
---|
519 | second_page_size = size - first_page_size; |
---|
520 | |
---|
521 | // get pointer on second page in mapper |
---|
522 | page = mapper_get_page( mapper , second_page_index ); |
---|
523 | |
---|
524 | if ( page == NULL ) return EINVAL; |
---|
525 | |
---|
526 | // compute local pointer on first byte in second page in mapper |
---|
527 | map_ptr = (uint8_t *)ppm_page2base( page ) + second_page_offset; |
---|
528 | |
---|
529 | // compute extended pointers |
---|
530 | xp_map = XPTR( local_cxy , map_ptr ); |
---|
531 | xp_buf = XPTR( buf_cxy , buf_ptr + first_page_offset ); |
---|
532 | |
---|
533 | // move fragment to/from second page |
---|
534 | if( to_buffer ) |
---|
535 | { |
---|
536 | hal_remote_memcpy( xp_buf , xp_map , second_page_size ); |
---|
537 | } |
---|
538 | else |
---|
539 | { |
---|
540 | page_do_dirty( page ); |
---|
541 | hal_remote_memcpy( xp_map , xp_buf , second_page_size ); |
---|
542 | } |
---|
543 | } |
---|
544 | |
---|
545 | return 0; |
---|
546 | } // end mapper_move_one_fragment() |
---|
547 | |
---|
548 | ///////////////////////////////////////////////// |
---|
549 | error_t mapper_move_fragments( mapper_t * mapper, |
---|
550 | bool_t read, |
---|
551 | uint32_t nb_frags, |
---|
552 | xptr_t xp_frags ) |
---|
553 | { |
---|
554 | uint32_t index; |
---|
555 | error_t error; |
---|
556 | fragment_t local_frags[CONFIG_MAPPER_MAX_FRAGMENTS]; // local copy of fragments array |
---|
557 | fragment_t * frags_array; // pointer on fragments array |
---|
558 | |
---|
559 | // check nb_frags |
---|
560 | if( nb_frags > CONFIG_MAPPER_MAX_FRAGMENTS ) |
---|
561 | { |
---|
562 | printk("\n[PANIC] in %s : number of fragments cannot be larger than %d\n", |
---|
563 | __FUNCTION__ , CONFIG_MAPPER_MAX_FRAGMENTS ); |
---|
564 | return EINVAL; |
---|
565 | } |
---|
566 | |
---|
567 | // get client cluster and local pointer on fragments array |
---|
568 | cxy_t client_cxy = GET_CXY( xp_frags ); |
---|
569 | fragment_t * client_frags = (fragment_t *)GET_PTR( xp_frags ); |
---|
570 | |
---|
571 | if ( local_cxy == client_cxy ) // use the local fragments array if possible |
---|
572 | { |
---|
573 | frags_array = client_frags; |
---|
574 | } |
---|
575 | else // make a local copy of fragments array |
---|
576 | { |
---|
577 | hal_remote_memcpy( XPTR( local_cxy , local_frags ) , xp_frags , |
---|
578 | sizeof(fragment_t) * nb_frags ); |
---|
579 | frags_array = local_frags; |
---|
580 | } |
---|
581 | |
---|
582 | // loop on fragments |
---|
583 | for( index = 0 ; index < nb_frags ; index ++ ) |
---|
584 | { |
---|
585 | error = mapper_move_one_fragment( mapper , read , &frags_array[index] ); |
---|
586 | if ( error ) return error; |
---|
587 | } |
---|
588 | |
---|
589 | return 0; |
---|
590 | |
---|
591 | } // end mapper_move_fragments() |
---|
592 | |
---|
593 | |
---|