|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * @brief Backing store on qemu_x86_tiny for testing |
| 10 | + * |
| 11 | + * This uses the "flash" memory area (in DTS) as the backing store |
| 12 | + * for demand paging. The qemu_x86_tiny.ld linker script puts |
| 13 | + * the symbols outside of boot and pinned sections into the flash |
| 14 | + * area, allowing testing of the demand paging mechanism on |
| 15 | + * code and data. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <mmu.h> |
| 19 | +#include <string.h> |
| 20 | +#include <kernel_arch_interface.h> |
| 21 | +#include <linker/linker-defs.h> |
| 22 | +#include <sys/util.h> |
| 23 | + |
| 24 | +void *location_to_flash(uintptr_t location) |
| 25 | +{ |
| 26 | + uintptr_t ptr = location; |
| 27 | + |
| 28 | + /* Offset from start of virtual address space */ |
| 29 | + ptr -= CONFIG_KERNEL_VM_BASE + CONFIG_KERNEL_VM_OFFSET; |
| 30 | + |
| 31 | + /* Translate the offset into address to flash */ |
| 32 | + ptr += CONFIG_FLASH_BASE_ADDRESS; |
| 33 | + |
| 34 | + __ASSERT_NO_MSG(ptr >= CONFIG_FLASH_BASE_ADDRESS); |
| 35 | + __ASSERT_NO_MSG(ptr < (CONFIG_FLASH_BASE_ADDRESS |
| 36 | + + KB(CONFIG_FLASH_SIZE) |
| 37 | + - CONFIG_MMU_PAGE_SIZE)); |
| 38 | + |
| 39 | + return UINT_TO_POINTER(ptr); |
| 40 | +} |
| 41 | + |
| 42 | +int k_mem_paging_backing_store_location_get(struct z_page_frame *pf, |
| 43 | + uintptr_t *location, |
| 44 | + bool page_fault) |
| 45 | +{ |
| 46 | + /* Simply returns the virtual address */ |
| 47 | + *location = POINTER_TO_UINT(pf->addr); |
| 48 | + |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +void k_mem_paging_backing_store_location_free(uintptr_t location) |
| 53 | +{ |
| 54 | + /* Nothing to do */ |
| 55 | +} |
| 56 | + |
| 57 | +void k_mem_paging_backing_store_page_out(uintptr_t location) |
| 58 | +{ |
| 59 | + (void)memcpy(location_to_flash(location), Z_SCRATCH_PAGE, |
| 60 | + CONFIG_MMU_PAGE_SIZE); |
| 61 | +} |
| 62 | + |
| 63 | +void k_mem_paging_backing_store_page_in(uintptr_t location) |
| 64 | +{ |
| 65 | + (void)memcpy(Z_SCRATCH_PAGE, location_to_flash(location), |
| 66 | + CONFIG_MMU_PAGE_SIZE); |
| 67 | +} |
| 68 | + |
| 69 | +void k_mem_paging_backing_store_page_finalize(struct z_page_frame *pf, |
| 70 | + uintptr_t location) |
| 71 | +{ |
| 72 | + /* Nothing to do */ |
| 73 | +} |
| 74 | + |
| 75 | +void k_mem_paging_backing_store_init(void) |
| 76 | +{ |
| 77 | + /* Nothing to do */ |
| 78 | +} |
0 commit comments