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 <mem/memory_incremental.h> 25 26 #include "dataspace_server.h" 27 #include "ipc.h" 28 #include "simple_pager.h" 29 30 31 32 SimplePager::SimplePager(Memory *memory) 33 { 34 if (memory == NULL) 35 _memory = new MemoryIncremental(); 36 else 37 _memory = memory; 38 39 _region = _memory->region(); 40 } 41 42 void SimplePager::close() 43 { 44 if (_region != NULL) 45 { 46 _memory->release(_region); 47 _region = NULL; 48 } 49 } 50 51 /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' 52 (flexpage offset). */ 53 54 long SimplePager::map(offset_t offset, address_t hot_spot, flags_t flags, l4_snd_fpage_t *region) 55 { 56 Flexpage flexpage(_region); 57 58 flexpage.reset(offset); 59 flexpage.upgrade(flags); 60 61 /* Send the flexpage explicitly. */ 62 63 long err = ipc_prepare_flexpage(&flexpage, offset, _region->size(), 64 hot_spot, flags, region); 65 66 if (err) 67 return err; 68 69 err = complete_Dataspace_map(*region); 70 71 if (err) 72 return err; 73 74 return IPC_MESSAGE_SENT; 75 } 76 77 long SimplePager::info(offset_t *size, flags_t *flags) 78 { 79 *size = _region->size(); 80 *flags = L4_FPAGE_RW; 81 82 return L4_EOK; 83 } 84 85 // vim: tabstop=4 expandtab shiftwidth=4