paul@93 | 1 | /* |
paul@93 | 2 | * A simple pager exposing a single memory region. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@1 | 22 | #include <l4/re/c/dataspace.h> |
paul@1 | 23 | |
paul@94 | 24 | #include <mem/memory_incremental.h> |
paul@94 | 25 | |
paul@1 | 26 | #include "dataspace_server.h" |
paul@2 | 27 | #include "ipc.h" |
paul@1 | 28 | #include "simple_pager.h" |
paul@1 | 29 | |
paul@1 | 30 | |
paul@1 | 31 | |
paul@1 | 32 | SimplePager::SimplePager(Memory *memory) |
paul@1 | 33 | { |
paul@1 | 34 | if (memory == NULL) |
paul@72 | 35 | _memory = new MemoryIncremental(); |
paul@1 | 36 | else |
paul@1 | 37 | _memory = memory; |
paul@1 | 38 | |
paul@1 | 39 | _region = _memory->region(); |
paul@1 | 40 | } |
paul@1 | 41 | |
paul@1 | 42 | void SimplePager::close() |
paul@1 | 43 | { |
paul@1 | 44 | if (_region != NULL) |
paul@1 | 45 | { |
paul@1 | 46 | _memory->release(_region); |
paul@1 | 47 | _region = NULL; |
paul@1 | 48 | } |
paul@1 | 49 | } |
paul@1 | 50 | |
paul@1 | 51 | /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' |
paul@1 | 52 | (flexpage offset). */ |
paul@1 | 53 | |
paul@92 | 54 | long SimplePager::map(offset_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) |
paul@1 | 55 | { |
paul@1 | 56 | Flexpage flexpage(_region); |
paul@1 | 57 | |
paul@1 | 58 | flexpage.reset(offset); |
paul@11 | 59 | flexpage.upgrade(flags); |
paul@1 | 60 | |
paul@1 | 61 | /* Send the flexpage explicitly. */ |
paul@1 | 62 | |
paul@86 | 63 | long err = ipc_prepare_flexpage(&flexpage, offset, _region->size(), |
paul@86 | 64 | hot_spot, flags, region); |
paul@1 | 65 | |
paul@4 | 66 | if (err) |
paul@10 | 67 | return err; |
paul@4 | 68 | |
paul@4 | 69 | err = complete_Dataspace_map(*region); |
paul@1 | 70 | |
paul@1 | 71 | if (err) |
paul@10 | 72 | return err; |
paul@1 | 73 | |
paul@1 | 74 | return IPC_MESSAGE_SENT; |
paul@1 | 75 | } |
paul@1 | 76 | |
paul@54 | 77 | long SimplePager::info(offset_t *size, flags_t *flags) |
paul@10 | 78 | { |
paul@10 | 79 | *size = _region->size(); |
paul@10 | 80 | *flags = L4_FPAGE_RW; |
paul@10 | 81 | |
paul@10 | 82 | return L4_EOK; |
paul@10 | 83 | } |
paul@10 | 84 | |
paul@1 | 85 | // vim: tabstop=4 expandtab shiftwidth=4 |