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