Changeset 46c20c8 in mainline for kernel/generic/include/mm
- Timestamp:
- 2010-11-26T20:08:10Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 45df59a
- Parents:
- fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- kernel/generic/include/mm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/as.h
rfb150d78 r46c20c8 1 1 /* 2 * Copyright (c) 20 01-2004Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 37 37 38 38 #ifdef KERNEL 39 #include <arch/types.h>39 #include <typedefs.h> 40 40 #else 41 #include <sys/types.h>41 #include <sys/types.h> 42 42 #endif 43 43 44 44 /** Address space area flags. */ 45 #define AS_AREA_READ 146 #define AS_AREA_WRITE 247 #define AS_AREA_EXEC 448 #define AS_AREA_CACHEABLE 845 #define AS_AREA_READ 1 46 #define AS_AREA_WRITE 2 47 #define AS_AREA_EXEC 4 48 #define AS_AREA_CACHEABLE 8 49 49 50 50 /** Address space area info exported to userspace. */ … … 52 52 /** Starting address */ 53 53 uintptr_t start_addr; 54 54 55 55 /** Area size */ 56 56 size_t size; 57 57 58 58 /** Area flags */ 59 int flags;59 unsigned int flags; 60 60 } as_area_info_t; 61 61 … … 65 65 #include <arch/mm/as.h> 66 66 #include <arch/mm/asid.h> 67 #include < arch/types.h>67 #include <typedefs.h> 68 68 #include <synch/spinlock.h> 69 69 #include <synch/mutex.h> … … 75 75 * Defined to be true if user address space and kernel address space shadow each 76 76 * other. 77 */ 78 #define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 79 80 #define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH 81 #define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH 82 #define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH 83 #define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH 84 85 #define USTACK_ADDRESS USTACK_ADDRESS_ARCH 77 * 78 */ 79 #define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 80 81 #define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH 82 #define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH 83 #define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH 84 #define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH 85 86 #define USTACK_ADDRESS USTACK_ADDRESS_ARCH 86 87 87 88 /** Kernel address space. */ 88 #define FLAG_AS_KERNEL (1 << 0)89 #define FLAG_AS_KERNEL (1 << 0) 89 90 90 91 /* Address space area attributes. */ 91 #define AS_AREA_ATTR_NONE 092 #define AS_AREA_ATTR_PARTIAL 1/**< Not fully initialized area. */92 #define AS_AREA_ATTR_NONE 0 93 #define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ 93 94 94 95 /** The page fault was not resolved by as_page_fault(). */ 95 #define AS_PF_FAULT 0 96 #define AS_PF_FAULT 0 97 96 98 /** The page fault was resolved by as_page_fault(). */ 97 #define AS_PF_OK 1 99 #define AS_PF_OK 1 100 98 101 /** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */ 99 #define AS_PF_DEFER 2102 #define AS_PF_DEFER 2 100 103 101 104 /** Address space structure. … … 105 108 * supposed to figure in the list as they are shared by all tasks and 106 109 * set up during system initialization. 110 * 107 111 */ 108 112 typedef struct as { 109 113 /** Protected by asidlock. */ 110 114 link_t inactive_as_with_asid_link; 115 111 116 /** 112 117 * Number of processors on wich is this address space active. … … 114 119 */ 115 120 size_t cpu_refcount; 121 116 122 /** 117 123 * Address space identifier. … … 120 126 */ 121 127 asid_t asid; 122 128 123 129 /** Number of references (i.e tasks that reference this as). */ 124 130 atomic_t refcount; 125 131 126 132 mutex_t lock; 127 133 128 134 /** B+tree of address space areas. */ 129 135 btree_t as_area_btree; … … 131 137 /** Non-generic content. */ 132 138 as_genarch_t genarch; 133 139 134 140 /** Architecture specific content. */ 135 141 as_arch_t arch; … … 137 143 138 144 typedef struct { 139 pte_t *(* page_table_create)(int flags); 140 void (* page_table_destroy)(pte_t *page_table); 141 void (* page_table_lock)(as_t *as, bool lock); 142 void (* page_table_unlock)(as_t *as, bool unlock); 145 pte_t *(* page_table_create)(unsigned int); 146 void (* page_table_destroy)(pte_t *); 147 void (* page_table_lock)(as_t *, bool); 148 void (* page_table_unlock)(as_t *, bool); 149 bool (* page_table_locked)(as_t *); 143 150 } as_operations_t; 144 151 … … 146 153 * This structure contains information associated with the shared address space 147 154 * area. 155 * 148 156 */ 149 157 typedef struct { 150 158 /** This lock must be acquired only when the as_area lock is held. */ 151 mutex_t lock; 159 mutex_t lock; 152 160 /** This structure can be deallocated if refcount drops to 0. */ 153 161 size_t refcount; 162 154 163 /** 155 164 * B+tree containing complete map of anonymous pages of the shared area. … … 162 171 PF_ACCESS_READ, 163 172 PF_ACCESS_WRITE, 164 PF_ACCESS_EXEC 173 PF_ACCESS_EXEC, 174 PF_ACCESS_UNKNOWN 165 175 } pf_access_t; 166 176 … … 169 179 /** Backend data stored in address space area. */ 170 180 typedef union mem_backend_data { 171 struct { /**< elf_backend members */ 181 /** elf_backend members */ 182 struct { 172 183 elf_header_t *elf; 173 184 elf_segment_header_t *segment; 174 185 }; 175 struct { /**< phys_backend members */ 186 187 /** phys_backend members */ 188 struct { 176 189 uintptr_t base; 177 190 size_t frames; … … 182 195 * 183 196 * Each as_area_t structure describes one contiguous area of virtual memory. 197 * 184 198 */ 185 199 typedef struct { 186 200 mutex_t lock; 187 201 /** Containing address space. */ 188 as_t *as; 202 as_t *as; 203 189 204 /** 190 205 * Flags related to the memory represented by the address space area. 191 206 */ 192 int flags; 207 unsigned int flags; 208 193 209 /** Attributes related to the address space area itself. */ 194 int attributes;210 unsigned int attributes; 195 211 /** Size of this area in multiples of PAGE_SIZE. */ 196 212 size_t pages; … … 199 215 /** Map of used space. */ 200 216 btree_t used_space; 201 217 202 218 /** 203 219 * If the address space area has been shared, this pointer will … … 205 221 */ 206 222 share_info_t *sh_info; 207 223 208 224 /** Memory backend backing this address space area. */ 209 225 struct mem_backend *backend; 210 226 211 227 /** Data to be used by the backend. */ 212 228 mem_backend_data_t backend_data; … … 215 231 /** Address space area backend structure. */ 216 232 typedef struct mem_backend { 217 int (* page_fault)(as_area_t * area, uintptr_t addr, pf_access_t access);218 void (* frame_free)(as_area_t * area, uintptr_t page, uintptr_t frame);219 void (* share)(as_area_t * area);233 int (* page_fault)(as_area_t *, uintptr_t, pf_access_t); 234 void (* frame_free)(as_area_t *, uintptr_t, uintptr_t); 235 void (* share)(as_area_t *); 220 236 } mem_backend_t; 221 237 … … 227 243 extern void as_init(void); 228 244 229 extern as_t *as_create(int flags); 230 extern void as_destroy(as_t *as); 231 extern void as_switch(as_t *old_as, as_t *new_as); 232 extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate); 233 234 extern as_area_t *as_area_create(as_t *as, int flags, size_t size, 235 uintptr_t base, int attrs, mem_backend_t *backend, 236 mem_backend_data_t *backend_data); 237 extern int as_area_destroy(as_t *as, uintptr_t address); 238 extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags); 239 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size, 240 as_t *dst_as, uintptr_t dst_base, int dst_flags_mask); 241 extern int as_area_change_flags(as_t *as, int flags, uintptr_t address); 242 243 extern int as_area_get_flags(as_area_t *area); 244 extern bool as_area_check_access(as_area_t *area, pf_access_t access); 245 extern size_t as_area_get_size(uintptr_t base); 246 extern int used_space_insert(as_area_t *a, uintptr_t page, size_t count); 247 extern int used_space_remove(as_area_t *a, uintptr_t page, size_t count); 245 extern as_t *as_create(unsigned int); 246 extern void as_destroy(as_t *); 247 extern void as_hold(as_t *); 248 extern void as_release(as_t *); 249 extern void as_switch(as_t *, as_t *); 250 extern int as_page_fault(uintptr_t, pf_access_t, istate_t *); 251 252 extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t, 253 unsigned int, mem_backend_t *, mem_backend_data_t *); 254 extern int as_area_destroy(as_t *, uintptr_t); 255 extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int); 256 extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, 257 unsigned int); 258 extern int as_area_change_flags(as_t *, unsigned int, uintptr_t); 259 260 extern unsigned int as_area_get_flags(as_area_t *); 261 extern bool as_area_check_access(as_area_t *, pf_access_t); 262 extern size_t as_area_get_size(uintptr_t); 263 extern int used_space_insert(as_area_t *, uintptr_t, size_t); 264 extern int used_space_remove(as_area_t *, uintptr_t, size_t); 248 265 249 266 250 267 /* Interface to be implemented by architectures. */ 268 251 269 #ifndef as_constructor_arch 252 extern int as_constructor_arch(as_t * as, int flags);270 extern int as_constructor_arch(as_t *, unsigned int); 253 271 #endif /* !def as_constructor_arch */ 272 254 273 #ifndef as_destructor_arch 255 extern int as_destructor_arch(as_t * as);274 extern int as_destructor_arch(as_t *); 256 275 #endif /* !def as_destructor_arch */ 276 257 277 #ifndef as_create_arch 258 extern int as_create_arch(as_t * as, int flags);278 extern int as_create_arch(as_t *, unsigned int); 259 279 #endif /* !def as_create_arch */ 280 260 281 #ifndef as_install_arch 261 extern void as_install_arch(as_t * as);282 extern void as_install_arch(as_t *); 262 283 #endif /* !def as_install_arch */ 284 263 285 #ifndef as_deinstall_arch 264 extern void as_deinstall_arch(as_t * as);286 extern void as_deinstall_arch(as_t *); 265 287 #endif /* !def as_deinstall_arch */ 266 288 … … 270 292 extern mem_backend_t phys_backend; 271 293 272 /** 294 /** 273 295 * This flags is passed when running the loader, otherwise elf_load() 274 296 * would return with a EE_LOADER error code. 275 */ 276 #define ELD_F_NONE 0 277 #define ELD_F_LOADER 1 278 279 extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags); 297 * 298 */ 299 #define ELD_F_NONE 0 300 #define ELD_F_LOADER 1 301 302 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int); 280 303 281 304 /* Address space area related syscalls. */ 282 extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags);283 extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags);284 extern unative_t sys_as_area_change_flags(uintptr_t address, int flags);285 extern unative_t sys_as_area_destroy(uintptr_t address);305 extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int); 306 extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int); 307 extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int); 308 extern unative_t sys_as_area_destroy(uintptr_t); 286 309 287 310 /* Introspection functions. */ 288 extern void as_get_area_info(as_t * as, as_area_info_t **obuf, size_t *osize);289 extern void as_print(as_t * as);311 extern void as_get_area_info(as_t *, as_area_info_t **, size_t *); 312 extern void as_print(as_t *); 290 313 291 314 #endif /* KERNEL */ -
kernel/generic/include/mm/buddy.h
rfb150d78 r46c20c8 36 36 #define KERN_BUDDY_H_ 37 37 38 #include < arch/types.h>38 #include <typedefs.h> 39 39 #include <adt/list.h> 40 40 -
kernel/generic/include/mm/frame.h
rfb150d78 r46c20c8 37 37 #define KERN_FRAME_H_ 38 38 39 #include <arch/types.h> 39 #include <typedefs.h> 40 #include <trace.h> 40 41 #include <adt/list.h> 41 42 #include <mm/buddy.h> … … 81 82 82 83 typedef struct { 83 size_t refcount; /**< Tracking of shared frames */84 size_t refcount; /**< Tracking of shared frames */ 84 85 uint8_t buddy_order; /**< Buddy system block order */ 85 86 link_t buddy_link; /**< Link to the next free block inside … … 91 92 pfn_t base; /**< Frame_no of the first frame 92 93 in the frames array */ 93 size_t count; /**< Size of zone */94 size_t free_count; /**< Number of free frame_t94 size_t count; /**< Size of zone */ 95 size_t free_count; /**< Number of free frame_t 95 96 structures */ 96 size_t busy_count; /**< Number of busy frame_t97 size_t busy_count; /**< Number of busy frame_t 97 98 structures */ 98 99 zone_flags_t flags; /**< Type of the zone */ … … 108 109 */ 109 110 typedef struct { 110 SPINLOCK_DECLARE(lock);111 IRQ_SPINLOCK_DECLARE(lock); 111 112 size_t count; 112 113 zone_t info[ZONES_MAX]; … … 115 116 extern zones_t zones; 116 117 117 static inline uintptr_t PFN2ADDR(pfn_t frame)118 NO_TRACE static inline uintptr_t PFN2ADDR(pfn_t frame) 118 119 { 119 120 return (uintptr_t) (frame << FRAME_WIDTH); 120 121 } 121 122 122 static inline pfn_t ADDR2PFN(uintptr_t addr)123 NO_TRACE static inline pfn_t ADDR2PFN(uintptr_t addr) 123 124 { 124 125 return (pfn_t) (addr >> FRAME_WIDTH); 125 126 } 126 127 127 static inline size_t SIZE2FRAMES(size_t size)128 NO_TRACE static inline size_t SIZE2FRAMES(size_t size) 128 129 { 129 130 if (!size) … … 132 133 } 133 134 134 static inline size_t FRAMES2SIZE(size_t frames)135 NO_TRACE static inline size_t FRAMES2SIZE(size_t frames) 135 136 { 136 137 return (size_t) (frames << FRAME_WIDTH); 137 138 } 138 139 139 static inline bool zone_flags_available(zone_flags_t flags)140 NO_TRACE static inline bool zone_flags_available(zone_flags_t flags) 140 141 { 141 142 return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0); … … 166 167 extern void frame_set_parent(pfn_t, void *, size_t); 167 168 extern void frame_mark_unavailable(pfn_t, size_t); 168 extern uintptr_t zone_conf_size(size_t);169 extern size_t zone_conf_size(size_t); 169 170 extern bool zone_merge(size_t, size_t); 170 171 extern void zone_merge_all(void); 171 extern uint64_t zone_total_size(void); 172 extern uint64_t zones_total_size(void); 173 extern void zones_stats(uint64_t *, uint64_t *, uint64_t *, uint64_t *); 172 174 173 175 /* 174 176 * Console functions 175 177 */ 176 extern void zone _print_list(void);178 extern void zones_print_list(void); 177 179 extern void zone_print_one(size_t); 178 180 -
kernel/generic/include/mm/page.h
rfb150d78 r46c20c8 36 36 #define KERN_PAGE_H_ 37 37 38 #include < arch/types.h>38 #include <typedefs.h> 39 39 #include <mm/as.h> 40 40 #include <memstr.h> … … 42 42 /** Operations to manipulate page mappings. */ 43 43 typedef struct { 44 void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame, 45 int flags); 46 void (* mapping_remove)(as_t *as, uintptr_t page); 47 pte_t *(* mapping_find)(as_t *as, uintptr_t page); 44 void (* mapping_insert)(as_t *, uintptr_t, uintptr_t, unsigned int); 45 void (* mapping_remove)(as_t *, uintptr_t); 46 pte_t *(* mapping_find)(as_t *, uintptr_t); 48 47 } page_mapping_operations_t; 49 48 … … 51 50 52 51 extern void page_init(void); 53 extern void page_table_lock(as_t * as, bool lock);54 extern void page_table_unlock(as_t * as, bool unlock);55 extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,56 int flags);57 extern void page_mapping_remove(as_t * as, uintptr_t page);58 extern pte_t *page_mapping_find(as_t * as, uintptr_t page);59 extern pte_t *page_table_create( int flags);60 extern void page_table_destroy(pte_t * page_table);61 extern void map_structure(uintptr_t s, size_t size);52 extern void page_table_lock(as_t *, bool); 53 extern void page_table_unlock(as_t *, bool); 54 extern bool page_table_locked(as_t *); 55 extern void page_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int); 56 extern void page_mapping_remove(as_t *, uintptr_t); 57 extern pte_t *page_mapping_find(as_t *, uintptr_t); 58 extern pte_t *page_table_create(unsigned int); 59 extern void page_table_destroy(pte_t *); 60 extern void map_structure(uintptr_t, size_t); 62 61 63 extern uintptr_t hw_map(uintptr_t physaddr, size_t size);62 extern uintptr_t hw_map(uintptr_t, size_t); 64 63 65 64 #endif -
kernel/generic/include/mm/slab.h
rfb150d78 r46c20c8 84 84 } slab_mag_cache_t; 85 85 86 87 86 typedef struct { 88 c har *name;87 const char *name; 89 88 90 89 link_t link; … … 94 93 size_t size; 95 94 96 int (*constructor)(void *obj, int kmflag);97 int (*destructor)(void *obj);95 int (*constructor)(void *obj, unsigned int kmflag); 96 size_t (*destructor)(void *obj); 98 97 99 98 /** Flags changing behaviour of cache */ 100 int flags;99 unsigned int flags; 101 100 102 101 /* Computed values */ 103 uint8_t order; /**< Order of frames to be allocated */104 unsigned int objects; /**< Number of objects that fit in */102 uint8_t order; /**< Order of frames to be allocated */ 103 size_t objects; /**< Number of objects that fit in */ 105 104 106 105 /* Statistics */ … … 109 108 atomic_t cached_objs; 110 109 /** How many magazines in magazines list */ 111 atomic_t magazine_counter; 110 atomic_t magazine_counter; 112 111 113 112 /* Slabs */ … … 123 122 } slab_cache_t; 124 123 125 extern slab_cache_t *slab_cache_create(c har *, size_t, size_t,126 int (*)(void *, int), int (*)(void *),int);124 extern slab_cache_t *slab_cache_create(const char *, size_t, size_t, 125 int (*)(void *, unsigned int), size_t (*)(void *), unsigned int); 127 126 extern void slab_cache_destroy(slab_cache_t *); 128 127 129 extern void * slab_alloc(slab_cache_t *, int); 128 extern void *slab_alloc(slab_cache_t *, unsigned int) 129 __attribute__((malloc)); 130 130 extern void slab_free(slab_cache_t *, void *); 131 extern size_t slab_reclaim( int);131 extern size_t slab_reclaim(unsigned int); 132 132 133 133 /* slab subsytem initialization */ … … 139 139 140 140 /* malloc support */ 141 extern void *malloc(unsigned int, int); 142 extern void *realloc(void *, unsigned int, int); 141 extern void *malloc(size_t, unsigned int) 142 __attribute__((malloc)); 143 extern void *realloc(void *, size_t, unsigned int); 143 144 extern void free(void *); 144 145 -
kernel/generic/include/mm/tlb.h
rfb150d78 r46c20c8 37 37 38 38 #include <arch/mm/asid.h> 39 #include < arch/types.h>39 #include <typedefs.h> 40 40 41 41 /** … … 68 68 69 69 #ifdef CONFIG_SMP 70 extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,71 uintptr_t page, size_t count);72 extern void tlb_shootdown_finalize( void);70 extern ipl_t tlb_shootdown_start(tlb_invalidate_type_t, asid_t, uintptr_t, 71 size_t); 72 extern void tlb_shootdown_finalize(ipl_t); 73 73 extern void tlb_shootdown_ipi_recv(void); 74 74 #else 75 #define tlb_shootdown_start(w, x, y, z) 76 #define tlb_shootdown_finalize( )75 #define tlb_shootdown_start(w, x, y, z) (0) 76 #define tlb_shootdown_finalize(i) ((i) = (i)); 77 77 #define tlb_shootdown_ipi_recv() 78 78 #endif /* CONFIG_SMP */ … … 84 84 85 85 extern void tlb_invalidate_all(void); 86 extern void tlb_invalidate_asid(asid_t asid);87 extern void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt);86 extern void tlb_invalidate_asid(asid_t); 87 extern void tlb_invalidate_pages(asid_t, uintptr_t, size_t); 88 88 #endif 89 89
Note:
See TracChangeset
for help on using the changeset viewer.
