| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /* include/kernel/mm.h
- *
- * This file is part of evx.
- *
- * evx is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * evx is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with evx. If not, see <https://www.gnu.org/licenses/>
- */
- #ifndef __MM_H
- #define __MM_H
- #ifndef __ASSEMBLER__
- #include <sys/types.h>
- #include <lib/klist.h>
- #include <arch/archinfo.h>
- /* a descriptor for each page to describe a page, hopely be smallest
- * and this is create only for the buddy memory management system. we
- * can't implement that without this, because we need more memory when
- * inserting.
- *
- * we should initiallize this as late as we can, after maps okay.
- * */
- struct page {
- /* for cow, the reference count. we won't free if count-- */
- __uint32_t count;
- struct page *next;
- };
- /* okay, that's may only in the x86, but... */
- struct zone {
- __uint32_t total_pages;
- #define ZONETYPE_RAM 1
- #define ZONETYPE_OTHER 0
- __uint32_t type;
- void *start_addr;
-
- struct page *pages;
- };
- /* the bucket_entry are for free objects. next_free points to next free
- * object. we replace the freeptr pointer in struct mempool and let that
- * points to old freeptr */
- struct bucket_entry {
- struct bucket_entry *next;
- };
- #define CACHE_SIZE 4096
- struct mempool {
- int size, used;
- void *cache;
- struct bucket_entry *freeptr;
- /* it has the same size */
- struct mempool *next_pool;
- };
- struct mempool_dir {
- int size;
- struct mempool *pools;
- };
- void *__mempool_alloc(struct mempool *);
- int __mempool_free(struct mempool *, void *);
- void *kmalloc(int size);
- int free_s(void *p, int size);
- int kmalloc_report(void);
- int dump_pool(struct mempool_dir *);
- void *early_kmalloc(int nbytes, int align);
- int early_free(void *p, int nbytes);
- #define free(p) early_free(p, 0)
- #define BUDDY_LEVELS 5
- extern struct klist_node buddy_pages[BUDDY_LEVELS];
- /* nr_ram_pages is the total */
- extern int nr_ram_pages, usable_ram_pages;
- /* sets by arch_mm_init */
- extern struct page *first_usable_ram,
- *kmem_pages;
- #define kmem_zones ((struct zone *) kernel_end)
- /* they're really early but fast. actually, most free() did nothing
- *
- * WARNING that you should't use align, because we didn't save old
- * freeptr and it will be cracked by it: not freeable */
- #endif
- #endif
|