1 /* 2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 #ifndef _KERNEL_VM_VM_PAGE_H 9 #define _KERNEL_VM_VM_PAGE_H 10 11 12 #include <vm/vm.h> 13 #include <vm/vm_types.h> 14 15 16 struct kernel_args; 17 18 extern int32 gMappedPagesCount; 19 20 21 struct vm_page_reservation { 22 uint32 count; 23 24 #if KDEBUG && defined(__cplusplus) 25 vm_page_reservation() : count(0) {} 26 ~vm_page_reservation() 27 { 28 ASSERT(count == 0); 29 } 30 #endif 31 }; 32 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 void vm_page_init_num_pages(struct kernel_args *args); 39 status_t vm_page_init(struct kernel_args *args); 40 status_t vm_page_init_post_area(struct kernel_args *args); 41 status_t vm_page_init_post_thread(struct kernel_args *args); 42 43 status_t vm_mark_page_inuse(page_num_t page); 44 status_t vm_mark_page_range_inuse(page_num_t startPage, page_num_t length); 45 void vm_page_free_etc(VMCache* cache, vm_page* page, 46 vm_page_reservation* reservation); 47 48 void vm_page_set_state(struct vm_page *page, int state); 49 void vm_page_requeue(struct vm_page *page, bool tail); 50 51 // get some data about the number of pages in the system 52 page_num_t vm_page_num_pages(void); 53 page_num_t vm_page_num_free_pages(void); 54 page_num_t vm_page_num_available_pages(void); 55 page_num_t vm_page_num_unused_pages(void); 56 void vm_page_get_stats(system_info *info); 57 phys_addr_t vm_page_max_address(); 58 59 status_t vm_page_write_modified_page_range(struct VMCache *cache, 60 uint32 firstPage, uint32 endPage); 61 status_t vm_page_write_modified_pages(struct VMCache *cache); 62 void vm_page_schedule_write_page(struct vm_page *page); 63 void vm_page_schedule_write_page_range(struct VMCache *cache, 64 uint32 firstPage, uint32 endPage); 65 66 void vm_page_unreserve_pages(vm_page_reservation* reservation); 67 void vm_page_reserve_pages(vm_page_reservation* reservation, uint32 count, 68 int priority); 69 bool vm_page_try_reserve_pages(vm_page_reservation* reservation, uint32 count, 70 int priority); 71 72 struct vm_page *vm_page_allocate_page(vm_page_reservation* reservation, 73 uint32 flags); 74 struct vm_page *vm_page_allocate_page_run(uint32 flags, page_num_t length, 75 const physical_address_restrictions* restrictions, int priority); 76 struct vm_page *vm_page_at_index(int32 index); 77 struct vm_page *vm_lookup_page(page_num_t pageNumber); 78 bool vm_page_is_dummy(struct vm_page *page); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 85 static inline void 86 vm_page_free(struct VMCache *cache, struct vm_page *page) 87 { 88 vm_page_free_etc(cache, page, NULL); 89 } 90 91 92 #endif /* _KERNEL_VM_VM_PAGE_H */ 93