1 // Copyright 2016 The Fuchsia Authors 2 // Copyright (c) 2014 Travis Geiselbrecht 3 // 4 // Use of this source code is governed by a MIT-style 5 // license that can be found in the LICENSE file or at 6 // https://opensource.org/licenses/MIT 7 8 #pragma once 9 10 #include <fbl/algorithm.h> 11 #include <list.h> 12 #include <stdint.h> 13 #include <sys/types.h> 14 #include <zircon/compiler.h> 15 16 enum vm_page_state { 17 VM_PAGE_STATE_FREE, 18 VM_PAGE_STATE_ALLOC, 19 VM_PAGE_STATE_OBJECT, 20 VM_PAGE_STATE_WIRED, 21 VM_PAGE_STATE_HEAP, 22 VM_PAGE_STATE_MMU, // allocated to serve arch-specific mmu purposes 23 VM_PAGE_STATE_IOMMU, // allocated for platform-specific iommu structures 24 VM_PAGE_STATE_IPC, 25 26 VM_PAGE_STATE_COUNT_ 27 }; 28 29 #define VM_PAGE_STATE_BITS 3 30 static_assert((1u << VM_PAGE_STATE_BITS) >= VM_PAGE_STATE_COUNT_, ""); 31 32 // core per page structure allocated at pmm arena creation time 33 typedef struct vm_page { 34 struct list_node queue_node; 35 paddr_t paddr_priv; // use paddr() accessor 36 // offset 0x18 37 38 struct { 39 uint32_t flags : 8; 40 uint32_t state : VM_PAGE_STATE_BITS; 41 }; 42 // offset: 0x1c 43 44 union { 45 struct { 46 #define VM_PAGE_OBJECT_PIN_COUNT_BITS 5 47 #define VM_PAGE_OBJECT_MAX_PIN_COUNT ((1ul << VM_PAGE_OBJECT_PIN_COUNT_BITS) - 1) 48 49 uint8_t pin_count : VM_PAGE_OBJECT_PIN_COUNT_BITS; 50 } object; // attached to a vm object 51 }; 52 53 // helper routines is_freevm_page54 bool is_free() const { 55 return state == VM_PAGE_STATE_FREE; 56 } 57 58 void dump() const; 59 60 // return the physical address 61 // future plan to store in a compressed form paddrvm_page62 paddr_t paddr() const { return paddr_priv; } 63 } vm_page_t; 64 65 // assert that the page structure isn't growing uncontrollably 66 static_assert(sizeof(vm_page) == 0x20, ""); 67 68 // helpers 69 const char* page_state_to_string(unsigned int state); 70