paul@65 | 1 | #include "pipe_pager.h" |
paul@65 | 2 | #include "pipe_object_server.h" |
paul@65 | 3 | |
paul@72 | 4 | |
paul@72 | 5 | |
paul@65 | 6 | /* Initialise a pager for a pipe with a shared page mapper for moderating |
paul@65 | 7 | access to loaded pages. At first, no mapper will be configured: this must be |
paul@65 | 8 | done by requesting a region. */ |
paul@65 | 9 | |
paul@66 | 10 | PipePager::PipePager(PipePaging *paging, bool writing) |
paul@87 | 11 | : Pager(NULL, writing ? L4RE_DS_MAP_FLAG_RW : L4RE_DS_MAP_FLAG_RO), |
paul@66 | 12 | _paging(paging), _writing(writing) |
paul@65 | 13 | { |
paul@66 | 14 | /* Initialise the size of the paged region. */ |
paul@65 | 15 | |
paul@66 | 16 | _size = _paging->region_size(); |
paul@65 | 17 | } |
paul@65 | 18 | |
paul@65 | 19 | int PipePager::expected_items() |
paul@65 | 20 | { |
paul@65 | 21 | return PipeObject_expected_items; |
paul@65 | 22 | } |
paul@65 | 23 | |
paul@65 | 24 | ipc_server_handler_type PipePager::handler() |
paul@65 | 25 | { |
paul@65 | 26 | return (ipc_server_handler_type) handle_PipeObject; |
paul@65 | 27 | } |
paul@65 | 28 | |
paul@65 | 29 | |
paul@65 | 30 | |
paul@67 | 31 | /* Close the pager, releasing the paging coordinator for the pipe. This will |
paul@67 | 32 | release all active page mappers. */ |
paul@67 | 33 | |
paul@67 | 34 | void PipePager::close() |
paul@67 | 35 | { |
paul@67 | 36 | _paging->detach(); |
paul@67 | 37 | } |
paul@67 | 38 | |
paul@65 | 39 | /* Support paging. */ |
paul@65 | 40 | |
paul@65 | 41 | long PipePager::map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region) |
paul@65 | 42 | { |
paul@65 | 43 | return Pager::map(offset, hot_spot, flags, region); |
paul@65 | 44 | } |
paul@65 | 45 | |
paul@65 | 46 | |
paul@65 | 47 | |
paul@65 | 48 | /* Return details of the current region. */ |
paul@65 | 49 | |
paul@65 | 50 | long PipePager::current_region(offset_t *populated_size, offset_t *size) |
paul@65 | 51 | { |
paul@65 | 52 | if (_mapper != NULL) |
paul@65 | 53 | { |
paul@65 | 54 | *populated_size = _mapper->get_data_size(); |
paul@65 | 55 | *size = _size; |
paul@65 | 56 | return L4_EOK; |
paul@65 | 57 | } |
paul@65 | 58 | else |
paul@65 | 59 | return -L4_EIO; |
paul@65 | 60 | } |
paul@65 | 61 | |
paul@65 | 62 | /* Obtain the next region and its details. */ |
paul@65 | 63 | |
paul@65 | 64 | long PipePager::next_region(offset_t *populated_size, offset_t *size) |
paul@65 | 65 | { |
paul@65 | 66 | /* Obtain a new region if writing. */ |
paul@65 | 67 | |
paul@66 | 68 | if (_writing) |
paul@65 | 69 | return next_region_for_writer(populated_size, size); |
paul@65 | 70 | else |
paul@65 | 71 | return next_region_for_reader(populated_size, size); |
paul@65 | 72 | } |
paul@65 | 73 | |
paul@65 | 74 | long PipePager::next_region_for_reader(offset_t *populated_size, offset_t *size) |
paul@65 | 75 | { |
paul@72 | 76 | PageMapper *mapper = _paging->next_region(); |
paul@65 | 77 | |
paul@72 | 78 | if (mapper == NULL) |
paul@72 | 79 | return -L4_EIO; |
paul@65 | 80 | |
paul@72 | 81 | _mapper = mapper; |
paul@65 | 82 | |
paul@65 | 83 | return current_region(populated_size, size); |
paul@65 | 84 | } |
paul@65 | 85 | |
paul@65 | 86 | long PipePager::next_region_for_writer(offset_t *populated_size, offset_t *size) |
paul@65 | 87 | { |
paul@65 | 88 | /* Set the populated size before moving on. */ |
paul@65 | 89 | |
paul@65 | 90 | if (_mapper != NULL) |
paul@65 | 91 | _mapper->set_data_size(*populated_size); |
paul@65 | 92 | |
paul@72 | 93 | /* Obtain the page mapper for the region. */ |
paul@66 | 94 | |
paul@72 | 95 | PageMapper *mapper = _paging->add_region(); |
paul@65 | 96 | |
paul@72 | 97 | if (mapper == NULL) |
paul@72 | 98 | return -L4_EIO; |
paul@65 | 99 | |
paul@72 | 100 | _mapper = mapper; |
paul@65 | 101 | |
paul@72 | 102 | return current_region(populated_size, size); |
paul@65 | 103 | } |
paul@65 | 104 | |
paul@65 | 105 | // vim: tabstop=4 expandtab shiftwidth=4 |