paul@6 | 1 | #include "dataspace_server.h" |
paul@6 | 2 | #include "ipc.h" |
paul@6 | 3 | #include "pager.h" |
paul@6 | 4 | |
paul@6 | 5 | |
paul@6 | 6 | |
paul@54 | 7 | Pager::Pager(PageMapper *mapper, flags_t flags) |
paul@48 | 8 | : _start(0), _size(0), _mapper(mapper), _flags(flags) |
paul@6 | 9 | { |
paul@65 | 10 | /* Some pagers may not be initialised with a mapper. */ |
paul@65 | 11 | |
paul@65 | 12 | if (_mapper != NULL) |
paul@65 | 13 | _mapper->attach(); |
paul@6 | 14 | } |
paul@6 | 15 | |
paul@79 | 16 | /* Close the pager. */ |
paul@79 | 17 | |
paul@6 | 18 | void Pager::close() |
paul@6 | 19 | { |
paul@65 | 20 | if (_mapper != NULL) |
paul@65 | 21 | _mapper->detach(); |
paul@6 | 22 | } |
paul@6 | 23 | |
paul@53 | 24 | /* Flush data to the file. */ |
paul@53 | 25 | |
paul@53 | 26 | long Pager::flush(offset_t populated_size, offset_t *size) |
paul@53 | 27 | { |
paul@55 | 28 | _mapper->flush_all(_start, populated_size); |
paul@53 | 29 | |
paul@55 | 30 | *size = _mapper->get_data_size(); |
paul@55 | 31 | return L4_EOK; |
paul@55 | 32 | } |
paul@53 | 33 | |
paul@55 | 34 | /* Resize the underlying file. */ |
paul@53 | 35 | |
paul@55 | 36 | long Pager::resize(offset_t *size) |
paul@55 | 37 | { |
paul@55 | 38 | _mapper->set_data_size(*size); |
paul@55 | 39 | |
paul@55 | 40 | *size = _mapper->get_data_size(); |
paul@53 | 41 | return L4_EOK; |
paul@53 | 42 | } |
paul@53 | 43 | |
paul@7 | 44 | /* Expose a region of the file. */ |
paul@7 | 45 | |
paul@30 | 46 | long Pager::mmap(offset_t position, offset_t length, offset_t *start_pos, offset_t *end_pos, offset_t *data_end) |
paul@6 | 47 | { |
paul@7 | 48 | _start = trunc(position, PAGE_SIZE); |
paul@7 | 49 | _size = round(position + length, PAGE_SIZE) - _start; |
paul@6 | 50 | |
paul@7 | 51 | *start_pos = _start; |
paul@7 | 52 | *end_pos = _start + _size; |
paul@7 | 53 | *data_end = 0; |
paul@7 | 54 | |
paul@7 | 55 | return L4_EOK; |
paul@6 | 56 | } |
paul@6 | 57 | |
paul@6 | 58 | /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' |
paul@6 | 59 | (flexpage offset). */ |
paul@6 | 60 | |
paul@54 | 61 | long Pager::map(offset_t offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region) |
paul@6 | 62 | { |
paul@6 | 63 | offset_t file_offset = _start + offset; |
paul@6 | 64 | offset_t max_offset = _start + _size; |
paul@11 | 65 | Flexpage *flexpage = _mapper->get(file_offset, flags); |
paul@6 | 66 | |
paul@6 | 67 | /* Issue the flexpage via the IPC system. */ |
paul@6 | 68 | |
paul@11 | 69 | long err = ipc_prepare_flexpage(flexpage, file_offset, max_offset, hot_spot, region); |
paul@6 | 70 | |
paul@37 | 71 | if (!err) |
paul@37 | 72 | err = complete_Dataspace_map(*region); |
paul@6 | 73 | |
paul@6 | 74 | /* After the flexpage is issued, it is queued for future reuse. */ |
paul@6 | 75 | |
paul@6 | 76 | _mapper->queue(flexpage); |
paul@6 | 77 | |
paul@37 | 78 | if (err) |
paul@37 | 79 | return err; |
paul@37 | 80 | |
paul@6 | 81 | return IPC_MESSAGE_SENT; |
paul@6 | 82 | } |
paul@6 | 83 | |
paul@6 | 84 | /* Return the total size of the data. */ |
paul@6 | 85 | |
paul@6 | 86 | offset_t Pager::get_data_size() |
paul@6 | 87 | { |
paul@6 | 88 | return _mapper->get_data_size(); |
paul@6 | 89 | } |
paul@6 | 90 | |
paul@6 | 91 | // vim: tabstop=4 expandtab shiftwidth=4 |