vm_kmem.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 /* PMAP_START_KMEM_ADDRESS == 0 */
  30. /*
  31. * Special kernel addresses.
  32. */
  33. extern char _text;
  34. extern char _rodata;
  35. extern char _data;
  36. extern char _end;
  37. /*
  38. * Allocate pure virtual kernel pages.
  39. *
  40. * The caller is reponsible for taking care of the underlying physical memory.
  41. */
  42. void * vm_kmem_alloc_va(size_t size);
  43. /*
  44. * Free virtual kernel pages.
  45. *
  46. * The caller is reponsible for taking care of the underlying physical memory.
  47. */
  48. void vm_kmem_free_va(void *addr, size_t size);
  49. /*
  50. * Allocate kernel pages.
  51. */
  52. void * vm_kmem_alloc(size_t size);
  53. /*
  54. * Free kernel pages.
  55. */
  56. void vm_kmem_free(void *addr, size_t size);
  57. /*
  58. * Map physical memory in the kernel map.
  59. *
  60. * Return the address at which the mapped memory can be accessed. If map_addrp
  61. * and/or map_sizep aren't NULL, they are updated to the address and size of
  62. * the mapping created.
  63. *
  64. * This is a convenience function for modules that must map random regions of
  65. * physical memory, and as such, it doesn't expect a page-aligned input range.
  66. *
  67. * TODO When mapping attributes are implemented, make this function disable
  68. * caching on the mapping.
  69. */
  70. void * vm_kmem_map_pa(phys_addr_t pa, size_t size,
  71. uintptr_t *map_vap, size_t *map_sizep);
  72. /*
  73. * Unmap physical memory from the kernel map.
  74. */
  75. void vm_kmem_unmap_pa(uintptr_t map_va, size_t map_size);
  76. /*
  77. * This init operation provides :
  78. * - kernel virtual memory allocation
  79. */
  80. INIT_OP_DECLARE(vm_kmem_setup);
  81. #endif /* VM_VM_KMEM_H */