Changeset c621f4aa in mainline for kernel/generic/include/mm/as.h


Ignore:
Timestamp:
2010-07-25T10:11:13Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
377cce8
Parents:
24a2517 (diff), a2da43c (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.
Message:

Merge with mainline.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/mm/as.h

    r24a2517 rc621f4aa  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3737
    3838#ifdef KERNEL
    39 #include <arch/types.h>
     39        #include <typedefs.h>
    4040#else
    41 #include <sys/types.h>
     41        #include <sys/types.h>
    4242#endif
    4343
    4444/** Address space area flags. */
    45 #define AS_AREA_READ            1
    46 #define AS_AREA_WRITE           2
    47 #define AS_AREA_EXEC            4
    48 #define AS_AREA_CACHEABLE       8
     45#define AS_AREA_READ       1
     46#define AS_AREA_WRITE      2
     47#define AS_AREA_EXEC       4
     48#define AS_AREA_CACHEABLE  8
    4949
    5050/** Address space area info exported to userspace. */
     
    5252        /** Starting address */
    5353        uintptr_t start_addr;
    54 
     54       
    5555        /** Area size */
    5656        size_t size;
    57 
     57       
    5858        /** Area flags */
    59         int flags;
     59        unsigned int flags;
    6060} as_area_info_t;
    6161
     
    6565#include <arch/mm/as.h>
    6666#include <arch/mm/asid.h>
    67 #include <arch/types.h>
     67#include <typedefs.h>
    6868#include <synch/spinlock.h>
    6969#include <synch/mutex.h>
     
    7575 * Defined to be true if user address space and kernel address space shadow each
    7676 * 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
    8687
    8788/** Kernel address space. */
    88 #define FLAG_AS_KERNEL                  (1 << 0)       
     89#define FLAG_AS_KERNEL  (1 << 0)
    8990
    9091/* Address space area attributes. */
    91 #define AS_AREA_ATTR_NONE       0
    92 #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. */
    9394
    9495/** The page fault was not resolved by as_page_fault(). */
    95 #define AS_PF_FAULT             0
     96#define AS_PF_FAULT  0
     97
    9698/** The page fault was resolved by as_page_fault(). */
    97 #define AS_PF_OK                1
     99#define AS_PF_OK  1
     100
    98101/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    99 #define AS_PF_DEFER             2
     102#define AS_PF_DEFER  2
    100103
    101104/** Address space structure.
     
    105108 * supposed to figure in the list as they are shared by all tasks and
    106109 * set up during system initialization.
     110 *
    107111 */
    108112typedef struct as {
    109113        /** Protected by asidlock. */
    110114        link_t inactive_as_with_asid_link;
     115       
    111116        /**
    112117         * Number of processors on wich is this address space active.
     
    114119         */
    115120        size_t cpu_refcount;
     121       
    116122        /**
    117123         * Address space identifier.
     
    120126         */
    121127        asid_t asid;
    122 
     128       
    123129        /** Number of references (i.e tasks that reference this as). */
    124130        atomic_t refcount;
    125 
     131       
    126132        mutex_t lock;
    127 
     133       
    128134        /** B+tree of address space areas. */
    129135        btree_t as_area_btree;
     
    131137        /** Non-generic content. */
    132138        as_genarch_t genarch;
    133 
     139       
    134140        /** Architecture specific content. */
    135141        as_arch_t arch;
     
    137143
    138144typedef 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 *);
    143150} as_operations_t;
    144151
     
    146153 * This structure contains information associated with the shared address space
    147154 * area.
     155 *
    148156 */
    149157typedef struct {
    150158        /** This lock must be acquired only when the as_area lock is held. */
    151         mutex_t lock;           
     159        mutex_t lock;
    152160        /** This structure can be deallocated if refcount drops to 0. */
    153161        size_t refcount;
     162       
    154163        /**
    155164         * B+tree containing complete map of anonymous pages of the shared area.
     
    162171        PF_ACCESS_READ,
    163172        PF_ACCESS_WRITE,
    164         PF_ACCESS_EXEC
     173        PF_ACCESS_EXEC,
     174        PF_ACCESS_UNKNOWN
    165175} pf_access_t;
    166176
     
    169179/** Backend data stored in address space area. */
    170180typedef union mem_backend_data {
    171         struct {        /**< elf_backend members */
     181        /** elf_backend members */
     182        struct {
    172183                elf_header_t *elf;
    173184                elf_segment_header_t *segment;
    174185        };
    175         struct {        /**< phys_backend members */
     186       
     187        /** phys_backend members */
     188        struct {
    176189                uintptr_t base;
    177190                size_t frames;
     
    182195 *
    183196 * Each as_area_t structure describes one contiguous area of virtual memory.
     197 *
    184198 */
    185199typedef struct {
    186200        mutex_t lock;
    187201        /** Containing address space. */
    188         as_t *as;               
     202        as_t *as;
     203       
    189204        /**
    190205         * Flags related to the memory represented by the address space area.
    191206         */
    192         int flags;
     207        unsigned int flags;
     208       
    193209        /** Attributes related to the address space area itself. */
    194         int attributes;
     210        unsigned int attributes;
    195211        /** Size of this area in multiples of PAGE_SIZE. */
    196212        size_t pages;
     
    199215        /** Map of used space. */
    200216        btree_t used_space;
    201 
     217       
    202218        /**
    203219         * If the address space area has been shared, this pointer will
     
    205221         */
    206222        share_info_t *sh_info;
    207 
     223       
    208224        /** Memory backend backing this address space area. */
    209225        struct mem_backend *backend;
    210 
     226       
    211227        /** Data to be used by the backend. */
    212228        mem_backend_data_t backend_data;
     
    215231/** Address space area backend structure. */
    216232typedef 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 *);
    220236} mem_backend_t;
    221237
     
    227243extern void as_init(void);
    228244
    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);
     245extern as_t *as_create(unsigned int);
     246extern void as_destroy(as_t *);
     247extern void as_hold(as_t *);
     248extern void as_release(as_t *);
     249extern void as_switch(as_t *, as_t *);
     250extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
     251
     252extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
     253    unsigned int, mem_backend_t *, mem_backend_data_t *);
     254extern int as_area_destroy(as_t *, uintptr_t);
     255extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
     256extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
     257    unsigned int);
     258extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
     259
     260extern unsigned int as_area_get_flags(as_area_t *);
     261extern bool as_area_check_access(as_area_t *, pf_access_t);
     262extern size_t as_area_get_size(uintptr_t);
     263extern int used_space_insert(as_area_t *, uintptr_t, size_t);
     264extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    248265
    249266
    250267/* Interface to be implemented by architectures. */
     268
    251269#ifndef as_constructor_arch
    252 extern int as_constructor_arch(as_t *as, int flags);
     270extern int as_constructor_arch(as_t *, unsigned int);
    253271#endif /* !def as_constructor_arch */
     272
    254273#ifndef as_destructor_arch
    255 extern int as_destructor_arch(as_t *as);
     274extern int as_destructor_arch(as_t *);
    256275#endif /* !def as_destructor_arch */
     276
    257277#ifndef as_create_arch
    258 extern int as_create_arch(as_t *as, int flags);
     278extern int as_create_arch(as_t *, unsigned int);
    259279#endif /* !def as_create_arch */
     280
    260281#ifndef as_install_arch
    261 extern void as_install_arch(as_t *as);
     282extern void as_install_arch(as_t *);
    262283#endif /* !def as_install_arch */
     284
    263285#ifndef as_deinstall_arch
    264 extern void as_deinstall_arch(as_t *as);
     286extern void as_deinstall_arch(as_t *);
    265287#endif /* !def as_deinstall_arch */
    266288
     
    270292extern mem_backend_t phys_backend;
    271293
    272 /** 
     294/**
    273295 * This flags is passed when running the loader, otherwise elf_load()
    274296 * 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
     302extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
    280303
    281304/* 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);
     305extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int);
     306extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
     307extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int);
     308extern unative_t sys_as_area_destroy(uintptr_t);
    286309
    287310/* 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);
     311extern void as_get_area_info(as_t *, as_area_info_t **, size_t *);
     312extern void as_print(as_t *);
    290313
    291314#endif /* KERNEL */
Note: See TracChangeset for help on using the changeset viewer.