paul@93 | 1 | /* |
paul@93 | 2 | * Generic pager functionality. |
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@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@30 | 24 | #include <systypes/base.h> |
paul@30 | 25 | |
paul@94 | 26 | #include <fsserver/page_mapper.h> |
paul@94 | 27 | #include <fsserver/resource.h> |
paul@332 | 28 | #include <mem/memory_incremental.h> |
paul@6 | 29 | |
paul@6 | 30 | |
paul@6 | 31 | |
paul@6 | 32 | /* A pager exposing a dataspace. */ |
paul@6 | 33 | |
paul@7 | 34 | class Pager : public Resource |
paul@6 | 35 | { |
paul@6 | 36 | protected: |
paul@6 | 37 | offset_t _start, _size; |
paul@6 | 38 | PageMapper *_mapper; |
paul@121 | 39 | map_flags_t _flags; |
paul@6 | 40 | |
paul@340 | 41 | /* Support for masked regions and replicated flexpages. */ |
paul@340 | 42 | |
paul@340 | 43 | MemoryIncremental _memory; |
paul@340 | 44 | |
paul@332 | 45 | /* Masked region support. */ |
paul@332 | 46 | |
paul@332 | 47 | bool _is_masked; |
paul@332 | 48 | offset_t _start_visible, _end_visible; |
paul@332 | 49 | Flexpage _start_flexpage, _end_flexpage, _zero_flexpage; |
paul@332 | 50 | |
paul@332 | 51 | Flexpage *get_masked_flexpage(Flexpage *flexpage); |
paul@332 | 52 | |
paul@332 | 53 | void allocate_region(Flexpage *flexpage, Flexpage &masked); |
paul@332 | 54 | |
paul@332 | 55 | void populate_region(Flexpage *flexpage, Flexpage &masked, |
paul@332 | 56 | bool has_start, bool has_end); |
paul@332 | 57 | |
paul@340 | 58 | /* Replicated flexpage support. */ |
paul@340 | 59 | |
paul@340 | 60 | AccessMap _map; |
paul@340 | 61 | Flexpage *get_replicated_flexpage(Flexpage *flexpage, map_flags_t flags); |
paul@340 | 62 | |
paul@6 | 63 | public: |
paul@121 | 64 | explicit Pager(PageMapper *mapper, map_flags_t flags); |
paul@6 | 65 | |
paul@24 | 66 | virtual void close(); |
paul@6 | 67 | |
paul@6 | 68 | /* Paging methods. */ |
paul@6 | 69 | |
paul@121 | 70 | virtual long map(offset_t offset, address_t hot_spot, map_flags_t flags, |
paul@90 | 71 | l4_snd_fpage_t *region); |
paul@6 | 72 | |
paul@6 | 73 | /* Limit methods. */ |
paul@6 | 74 | |
paul@6 | 75 | offset_t get_data_size(); |
paul@6 | 76 | |
paul@53 | 77 | /* File methods. */ |
paul@53 | 78 | |
paul@53 | 79 | virtual long flush(offset_t populated_size, offset_t *size); |
paul@53 | 80 | |
paul@55 | 81 | virtual long resize(offset_t *size); |
paul@55 | 82 | |
paul@7 | 83 | /* Mapped file methods. */ |
paul@7 | 84 | |
paul@339 | 85 | virtual long mmap(offset_t position, offset_t length, |
paul@339 | 86 | offset_t start_visible, offset_t end_visible, |
paul@332 | 87 | offset_t *start_pos, offset_t *end_pos, offset_t *size); |
paul@6 | 88 | }; |
paul@6 | 89 | |
paul@6 | 90 | // vim: tabstop=4 expandtab shiftwidth=4 |