kmem.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2010-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. #ifndef VM_VM_KMEM_H
  18. #define VM_VM_KMEM_H
  19. #include <stdint.h>
  20. #include <kern/init.h>
  21. #include <machine/pmap.h>
  22. #include <machine/types.h>
  23. /*
  24. * The kernel space is required not to start at address 0, which is used to
  25. * report allocation errors.
  26. */
  27. #if PMAP_START_KMEM_ADDRESS == 0
  28. #error "kernel space must not start at address 0"
  29. #endif
  30. // Special kernel addresses.
  31. extern char _text;
  32. extern char _rodata;
  33. extern char _data;
  34. extern char _end;
  35. /*
  36. * Allocate pure virtual kernel pages.
  37. *
  38. * The caller is reponsible for taking care of the underlying physical memory.
  39. */
  40. void* vm_kmem_alloc_va (size_t size);
  41. /*
  42. * Free virtual kernel pages.
  43. *
  44. * The caller is reponsible for taking care of the underlying physical memory.
  45. */
  46. void vm_kmem_free_va (void *addr, size_t size);
  47. // Allocate kernel pages.
  48. void* vm_kmem_alloc (size_t size);
  49. // Free kernel pages.
  50. void vm_kmem_free (void *addr, size_t size);
  51. /*
  52. * Map physical memory in the kernel map.
  53. *
  54. * Return the address at which the mapped memory can be accessed. If map_vap
  55. * and/or map_sizep aren't NULL, they are updated to the address and size of
  56. * the mapping created.
  57. *
  58. * This is a convenience function for modules that must map random regions of
  59. * physical memory, and as such, it doesn't expect a page-aligned input range.
  60. *
  61. * TODO When mapping attributes are implemented, make this function disable
  62. * caching on the mapping.
  63. */
  64. void* vm_kmem_map_pa (phys_addr_t pa, size_t size,
  65. uintptr_t *map_vap, size_t *map_sizep);
  66. // Unmap physical memory from the kernel map.
  67. void vm_kmem_unmap_pa (uintptr_t map_va, size_t map_size);
  68. /*
  69. * This init operation provides :
  70. * - kernel virtual memory allocation
  71. */
  72. INIT_OP_DECLARE (vm_kmem_setup);
  73. #endif