mm.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* include/kernel/mm.h
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __MM_H
  19. #define __MM_H
  20. #ifndef __ASSEMBLER__
  21. #include <sys/types.h>
  22. #include <arch/archinfo.h>
  23. /* a descriptor for each page to describe a page, hopely be smallest
  24. * and this is create only for the buddy memory management system. we
  25. * can't implement that without this, because we need more memory when
  26. * inserting.
  27. *
  28. * we should initiallize this as late as we can, after maps okay.
  29. * */
  30. struct page {
  31. /* for cow, the reference count. we won't free if count-- */
  32. __uint32_t count;
  33. struct page *next;
  34. };
  35. /* okay, that's may only in the x86, but... */
  36. struct zone {
  37. __uint32_t total_pages;
  38. #define ZONETYPE_RAM 1
  39. #define ZONETYPE_OTHER 0
  40. __uint32_t type;
  41. void *start_addr;
  42. struct page *pages;
  43. };
  44. /* the bucket_entry are for free objects. next_free points to next free
  45. * object. we replace the freeptr pointer in struct mempool and let that
  46. * points to old freeptr */
  47. struct bucket_entry {
  48. struct bucket_entry *next;
  49. };
  50. #define CACHE_SIZE 4096
  51. struct mempool {
  52. int size, used;
  53. void *cache;
  54. struct bucket_entry *freeptr;
  55. /* it has the same size */
  56. struct mempool *next_pool;
  57. };
  58. struct mempool_dir {
  59. int size;
  60. struct mempool *pools;
  61. };
  62. void *__mempool_alloc(struct mempool *);
  63. int __mempool_free(struct mempool *, void *);
  64. void *kmalloc(int size);
  65. int free_s(void *p, int size);
  66. int kmalloc_report(void);
  67. int dump_pool(struct mempool_dir *);
  68. #define free(p)
  69. /* sets by arch_mm_init */
  70. extern struct page *first_usable_ram;
  71. #define kmem_zones ((struct zone *) kernel_end)
  72. #define kmem_pages ((struct page *) (kmem_zones + 2))
  73. /* they're really early but fast. actually, most free() did nothing
  74. *
  75. * WARNING that you should't use align, because we didn't save old
  76. * freeptr and it will be cracked by it: not freeable */
  77. void *early_kmalloc(int nbytes, int align);
  78. int early_free(void *p, int nbytes);
  79. #endif
  80. #endif