vm_object.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2017 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Virtual memory object.
  19. *
  20. * The purpose of VM objects is to track pages that are resident in
  21. * physical memory. They collectively form the page cache.
  22. */
  23. #ifndef VM_OBJECT_H
  24. #define VM_OBJECT_H
  25. #include <stdint.h>
  26. #include <kern/init.h>
  27. #include <kern/rdxtree.h>
  28. #include <vm/vm_object_types.h>
  29. #include <vm/vm_page.h>
  30. struct vm_object;
  31. static inline struct vm_object *
  32. vm_object_get_kernel_object(void)
  33. {
  34. extern struct vm_object vm_object_kernel_object;
  35. return &vm_object_kernel_object;
  36. }
  37. /*
  38. * Initialize a VM object.
  39. */
  40. void vm_object_init(struct vm_object *object, uint64_t size);
  41. /*
  42. * Insert a page into a VM object.
  43. *
  44. * The offset must be page-aligned.
  45. *
  46. * The page becomes managed, and gains a reference. If successful,
  47. * the reference is kept. Otherwise it's dropped. If the page had
  48. * no references on entry, and a failure occurs, the page is freed.
  49. */
  50. int vm_object_insert(struct vm_object *object, struct vm_page *page,
  51. uint64_t offset);
  52. /*
  53. * Remove pages from a VM object.
  54. *
  55. * The range boundaries must be page-aligned.
  56. *
  57. * Holes in the given range are silently skipped. Pages that are removed
  58. * become unmanaged and lose a reference.
  59. */
  60. void vm_object_remove(struct vm_object *object, uint64_t start, uint64_t end);
  61. /*
  62. * Look up a page in a VM object.
  63. *
  64. * The offset must be page-aligned.
  65. *
  66. * If successful, the returned page gains a reference. Note that, if a valid
  67. * page is returned, it may already have been removed from the object, or
  68. * moved at a different offset.
  69. */
  70. struct vm_page * vm_object_lookup(struct vm_object *object, uint64_t offset);
  71. /*
  72. * This init operation provides :
  73. * - module fully initialized
  74. */
  75. INIT_OP_DECLARE(vm_object_setup);
  76. #endif /* VM_OBJECT_H */