|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2000 Thomas Petazzoni 002 Copyright (C) 2004 David Decotigny 003 004 This program is free software; you can redistribute it and/or 005 modify it under the terms of the GNU General Public License 006 as published by the Free Software Foundation; either version 2 007 of the License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 017 USA. 018 */ 019 #ifndef _SOS_KMEM_VMM_H_ 020 #define _SOS_KMEM_VMM_H_ 021 022 /** 023 * @file kmem_vmm.h 024 * 025 * Kernel Memory Allocator for multiple-page-sized objects residing in 026 * the kernel (virtual memory) space. Relies on the slab cache 027 * allocator to allocate its (internal) "range" data structure. 028 */ 029 030 #include <hwcore/paging.h> 031 032 /* The base and top virtual addresses covered by the kernel allocator */ 033 #define SOS_KMEM_VMM_BASE 0x4000 /* 16kB */ 034 #define SOS_KMEM_VMM_TOP SOS_PAGING_MIRROR_VADDR /* 1GB - 4MB */ 035 036 /** Opaque structure used internally and declared here for physmem.h */ 037 struct sos_kmem_range; 038 039 #include <sos/kmem_slab.h> 040 041 /** 042 * Mark the areas belonging to SOS_KMEM_VMM_BASE and SOS_KMEM_VMM_TOP 043 * are either used or free. Those that are already mapped are marked 044 * as "used", and the 0..SOS_KMEM_VMM_BASE virtual addresses as marked 045 * as "used" too (to detect incorrect pointer dereferences). 046 */ 047 sos_ret_t 048 sos_kmem_vmm_subsystem_setup(sos_vaddr_t kernel_core_base_vaddr, 049 sos_vaddr_t kernel_core_top_vaddr, 050 sos_vaddr_t bootstrap_stack_bottom_vaddr, 051 sos_vaddr_t bootstrap_stack_top_vaddr); 052 053 054 /* 055 * Flags for kmem_vmm_new_range and kmem_vmm_alloc 056 */ 057 /** Physical pages should be immediately mapped */ 058 #define SOS_KMEM_VMM_MAP (1<<0) 059 /** Allocation should either success or fail, without blocking */ 060 #define SOS_KMEM_VMM_ATOMIC (1<<1) 061 062 /** 063 * Allocate a new kernel area spanning one or multiple pages. 064 * 065 * @param range_base_vaddr If not NULL, the start address of the range 066 * is stored in this location 067 * @eturn a new range structure 068 */ 069 struct sos_kmem_range *sos_kmem_vmm_new_range(sos_size_t nb_pages, 070 sos_ui32_t flags, 071 sos_vaddr_t *range_base_vaddr); 072 sos_ret_t sos_kmem_vmm_del_range(struct sos_kmem_range *range); 073 074 075 /** 076 * Straighforward variant of sos_kmem_vmm_new_range() returning the 077 * range's start address instead of the range structure 078 */ 079 sos_vaddr_t sos_kmem_vmm_alloc(sos_size_t nb_pages, 080 sos_ui32_t flags); 081 082 /** 083 * @note you are perfectly allowed to give the address of the 084 * kernel image, or the address of the bios area here, it will work: 085 * the kernel/bios WILL be "deallocated". But if you really want to do 086 * this, well..., do expect some "surprises" ;) 087 */ 088 sos_ret_t sos_kmem_vmm_free(sos_vaddr_t vaddr); 089 090 091 /** 092 * @return TRUE when vaddr is covered by any (used) kernel range 093 */ 094 sos_bool_t sos_kmem_vmm_is_valid_vaddr(sos_vaddr_t vaddr); 095 096 097 /* ***************************** 098 * Reserved to kmem_slab.c ONLY. 099 */ 100 /** 101 * Associate the range with the given slab. 102 */ 103 sos_ret_t sos_kmem_vmm_set_slab(struct sos_kmem_range *range, 104 struct sos_kslab *slab); 105 106 /** 107 * Retrieve the (used) slab associated with the range covering vaddr. 108 * 109 * @return NULL if the range is not associated with a KMEM range 110 */ 111 struct sos_kslab *sos_kmem_vmm_resolve_slab(sos_vaddr_t vaddr); 112 113 #endif /* _SOS_KMEM_VMM_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |