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