1 /* 2 * A flexpage abstraction. 3 * 4 * Copyright (C) 2021, 2022 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 #pragma once 23 24 #include <list> 25 26 #include <mem/memory_utils.h> 27 #include <mem/region.h> 28 #include <mem/send_flexpage.h> 29 30 31 32 /* Work around API change. */ 33 34 #define L4RE_DS_MAP_FLAG_RO L4RE_DS_F_R 35 #define L4RE_DS_MAP_FLAG_RW L4RE_DS_F_RW 36 37 38 39 /* Forward declaration. */ 40 41 class Flexpage; 42 43 /* Employed data types. */ 44 45 typedef std::list<Flexpage *> DerivedFlexpages; 46 47 48 49 /* A flexpage abstraction. */ 50 51 class Flexpage 52 { 53 protected: 54 unsigned int _counter; 55 map_flags_t _flags; 56 57 public: 58 Region *region; 59 60 /* Flexpage relationships to support masked regions. */ 61 62 DerivedFlexpages derived; 63 64 /* General flexpage characteristics. */ 65 66 offset_t base_addr, size; 67 offset_t base_offset; 68 69 /* Transient debugging information. */ 70 71 offset_t page_addr, page_offset; 72 73 /* Associate a flexpage with a memory 'region'. */ 74 75 explicit Flexpage(Region *region = NULL) 76 : region(region) 77 { 78 } 79 80 void set_region(Region *region); 81 82 void reset(offset_t offset); 83 84 bool decrement(); 85 86 void increment(); 87 88 void invalidate(); 89 90 bool valid(); 91 92 bool supports_position(offset_t position); 93 94 void upgrade(map_flags_t flags); 95 96 bool modified(); 97 98 SendFlexpage to_send(offset_t offset, offset_t hot_spot, map_flags_t flags, 99 offset_t max_offset=0); 100 101 SendFlexpage to_unmap(); 102 103 /* Associate other flexpages with this flexpage. */ 104 105 void associate(Flexpage *flexpage); 106 107 void disassociate(); 108 }; 109 110 // vim: tabstop=4 expandtab shiftwidth=4