[75b139f] | 1 | /*
|
---|
| 2 | * Copyright (c) 2016 Jakub Jermar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup genericmm
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | * @brief Backend for address space areas backed by the user pager.
|
---|
| 36 | *
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <mm/as.h>
|
---|
| 40 | #include <mm/page.h>
|
---|
| 41 | #include <synch/mutex.h>
|
---|
| 42 | #include <typedefs.h>
|
---|
| 43 | #include <align.h>
|
---|
| 44 | #include <debug.h>
|
---|
| 45 |
|
---|
| 46 | static bool user_create(as_area_t *);
|
---|
| 47 | static bool user_resize(as_area_t *, size_t);
|
---|
| 48 | static void user_share(as_area_t *);
|
---|
| 49 | static void user_destroy(as_area_t *);
|
---|
| 50 |
|
---|
| 51 | static bool user_is_resizable(as_area_t *);
|
---|
| 52 | static bool user_is_shareable(as_area_t *);
|
---|
| 53 |
|
---|
| 54 | static int user_page_fault(as_area_t *, uintptr_t, pf_access_t);
|
---|
| 55 | static void user_frame_free(as_area_t *, uintptr_t, uintptr_t);
|
---|
| 56 |
|
---|
| 57 | mem_backend_t user_backend = {
|
---|
| 58 | .create = user_create,
|
---|
| 59 | .resize = user_resize,
|
---|
| 60 | .share = user_share,
|
---|
| 61 | .destroy = user_destroy,
|
---|
| 62 |
|
---|
| 63 | .is_resizable = user_is_resizable,
|
---|
| 64 | .is_shareable = user_is_shareable,
|
---|
| 65 |
|
---|
| 66 | .page_fault = user_page_fault,
|
---|
| 67 | .frame_free = user_frame_free,
|
---|
| 68 |
|
---|
| 69 | .create_shared_data = NULL,
|
---|
| 70 | .destroy_shared_data = NULL
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | bool user_create(as_area_t *area)
|
---|
| 74 | {
|
---|
| 75 | return true;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | bool user_resize(as_area_t *area, size_t new_pages)
|
---|
| 79 | {
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /** Share the user-paged address space area.
|
---|
| 84 | *
|
---|
| 85 | * The address space and address space area must be already locked.
|
---|
| 86 | *
|
---|
| 87 | * @param area Address space area to be shared.
|
---|
| 88 | */
|
---|
| 89 | void user_share(as_area_t *area)
|
---|
| 90 | {
|
---|
| 91 | ASSERT(mutex_locked(&area->as->lock));
|
---|
| 92 | ASSERT(mutex_locked(&area->lock));
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | void user_destroy(as_area_t *area)
|
---|
| 96 | {
|
---|
| 97 | return;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | bool user_is_resizable(as_area_t *area)
|
---|
| 101 | {
|
---|
| 102 | return true;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | bool user_is_shareable(as_area_t *area)
|
---|
| 106 | {
|
---|
| 107 | return true;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | /** Service a page fault in the user-paged address space area.
|
---|
| 111 | *
|
---|
| 112 | * The address space area and page tables must be already locked.
|
---|
| 113 | *
|
---|
| 114 | * @param area Pointer to the address space area.
|
---|
| 115 | * @param upage Faulting virtual page.
|
---|
| 116 | * @param access Access mode that caused the fault (i.e. read/write/exec).
|
---|
| 117 | *
|
---|
| 118 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e.
|
---|
| 119 | * serviced).
|
---|
| 120 | */
|
---|
| 121 | int user_page_fault(as_area_t *area, uintptr_t upage, pf_access_t access)
|
---|
| 122 | {
|
---|
| 123 | ASSERT(page_table_locked(AS));
|
---|
| 124 | ASSERT(mutex_locked(&area->lock));
|
---|
| 125 | ASSERT(IS_ALIGNED(upage, PAGE_SIZE));
|
---|
| 126 |
|
---|
| 127 | return AS_PF_FAULT;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /** Free a frame that is backed by the user memory backend.
|
---|
| 131 | *
|
---|
| 132 | * The address space area and page tables must be already locked.
|
---|
| 133 | *
|
---|
| 134 | * @param area Ignored.
|
---|
| 135 | * @param page Virtual address of the page corresponding to the frame.
|
---|
| 136 | * @param frame Frame to be released.
|
---|
| 137 | */
|
---|
| 138 | void user_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
|
---|
| 139 | {
|
---|
| 140 | ASSERT(page_table_locked(area->as));
|
---|
| 141 | ASSERT(mutex_locked(&area->lock));
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /** @}
|
---|
| 145 | */
|
---|