Changeset 6745592 in mainline for kernel/generic/src/mm/as.c


Ignore:
Timestamp:
2008-09-02T19:00:11Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6d37d27
Parents:
ae7f6fb
Message:

cstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/as.c

    rae7f6fb r6745592  
    112112as_t *AS_KERNEL = NULL;
    113113
    114 static int area_flags_to_page_flags(int aflags);
    115 static as_area_t *find_area_and_lock(as_t *as, uintptr_t va);
    116 static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
    117     as_area_t *avoid_area);
    118 static void sh_info_remove_reference(share_info_t *sh_info);
     114static int area_flags_to_page_flags(int);
     115static as_area_t *find_area_and_lock(as_t *, uintptr_t);
     116static bool check_area_conflicts(as_t *, uintptr_t, size_t, as_area_t *);
     117static void sh_info_remove_reference(share_info_t *);
    119118
    120119static int as_constructor(void *obj, int flags)
     
    154153/** Create address space.
    155154 *
    156  * @param flags Flags that influence way in wich the address space is created.
     155 * @param flags         Flags that influence the way in wich the address space
     156 *                      is created.
    157157 */
    158158as_t *as_create(int flags)
     
    187187 *
    188188 * We know that we don't hold any spinlock.
     189 *
     190 * @param as            Address space to be destroyed.
    189191 */
    190192void as_destroy(as_t *as)
     
    258260 * The created address space area is added to the target address space.
    259261 *
    260  * @param as Target address space.
    261  * @param flags Flags of the area memory.
    262  * @param size Size of area.
    263  * @param base Base address of area.
    264  * @param attrs Attributes of the area.
    265  * @param backend Address space area backend. NULL if no backend is used.
    266  * @param backend_data NULL or a pointer to an array holding two void *.
    267  *
    268  * @return Address space area on success or NULL on failure.
     262 * @param as            Target address space.
     263 * @param flags         Flags of the area memory.
     264 * @param size          Size of area.
     265 * @param base          Base address of area.
     266 * @param attrs         Attributes of the area.
     267 * @param backend       Address space area backend. NULL if no backend is used.
     268 * @param backend_data  NULL or a pointer to an array holding two void *.
     269 *
     270 * @return              Address space area on success or NULL on failure.
    269271 */
    270272as_area_t *
    271273as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
    272                mem_backend_t *backend, mem_backend_data_t *backend_data)
     274    mem_backend_t *backend, mem_backend_data_t *backend_data)
    273275{
    274276        ipl_t ipl;
     
    322324/** Find address space area and change it.
    323325 *
    324  * @param as Address space.
    325  * @param address Virtual address belonging to the area to be changed. Must be
    326  *     page-aligned.
    327  * @param size New size of the virtual memory block starting at address.
    328  * @param flags Flags influencing the remap operation. Currently unused.
    329  *
    330  * @return Zero on success or a value from @ref errno.h otherwise.
     326 * @param as            Address space.
     327 * @param address       Virtual address belonging to the area to be changed.
     328 *                      Must be page-aligned.
     329 * @param size          New size of the virtual memory block starting at
     330 *                      address.
     331 * @param flags         Flags influencing the remap operation. Currently unused.
     332 *
     333 * @return              Zero on success or a value from @ref errno.h otherwise.
    331334 */
    332335int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags)
     
    436439                                        cond = false;   /* we are almost done */
    437440                                        i = (start_free - b) >> PAGE_WIDTH;
    438                                         if (!used_space_remove(area, start_free, c - i))
    439                                                 panic("Could not remove used space.\n");
     441                                        if (!used_space_remove(area, start_free,
     442                                            c - i))
     443                                                panic("Could not remove used "
     444                                                    "space.\n");
    440445                                } else {
    441446                                        /*
     
    444449                                         */
    445450                                        if (!used_space_remove(area, b, c))
    446                                                 panic("Could not remove used space.\n");
     451                                                panic("Could not remove used "
     452                                                    "space.\n");
    447453                                }
    448454                       
     
    506512/** Destroy address space area.
    507513 *
    508  * @param as Address space.
    509  * @param address Address withing the area to be deleted.
    510  *
    511  * @return Zero on success or a value from @ref errno.h on failure.
     514 * @param as            Address space.
     515 * @param address       Address within the area to be deleted.
     516 *
     517 * @return              Zero on success or a value from @ref errno.h on failure.
    512518 */
    513519int as_area_destroy(as_t *as, uintptr_t address)
     
    606612 * mapping is done through the backend share function.
    607613 *
    608  * @param src_as Pointer to source address space.
    609  * @param src_base Base address of the source address space area.
    610  * @param acc_size Expected size of the source area.
    611  * @param dst_as Pointer to destination address space.
    612  * @param dst_base Target base address.
     614 * @param src_as        Pointer to source address space.
     615 * @param src_base      Base address of the source address space area.
     616 * @param acc_size      Expected size of the source area.
     617 * @param dst_as        Pointer to destination address space.
     618 * @param dst_base      Target base address.
    613619 * @param dst_flags_mask Destination address space area flags mask.
    614620 *
    615  * @return Zero on success or ENOENT if there is no such task or if there is no
    616  * such address space area, EPERM if there was a problem in accepting the area
    617  * or ENOMEM if there was a problem in allocating destination address space
    618  * area. ENOTSUP is returned if the address space area backend does not support
    619  * sharing.
     621 * @return              Zero on success or ENOENT if there is no such task or if
     622 *                      there is no such address space area, EPERM if there was
     623 *                      a problem in accepting the area or ENOMEM if there was a
     624 *                      problem in allocating destination address space area.
     625 *                      ENOTSUP is returned if the address space area backend
     626 *                      does not support sharing.
    620627 */
    621628int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
     
    736743 * The address space area must be locked prior to this call.
    737744 *
    738  * @param area Address space area.
    739  * @param access Access mode.
    740  *
    741  * @return False if access violates area's permissions, true otherwise.
     745 * @param area          Address space area.
     746 * @param access        Access mode.
     747 *
     748 * @return              False if access violates area's permissions, true
     749 *                      otherwise.
    742750 */
    743751bool as_area_check_access(as_area_t *area, pf_access_t access)
     
    755763}
    756764
    757 /** Change adress area flags.
     765/** Change adress space area flags.
    758766 *
    759767 * The idea is to have the same data, but with a different access mode.
     
    762770 * into private anonymous memory (unless it's already there).
    763771 *
    764  * @param as Address space.
    765  * @param flags Flags of the area memory.
    766  * @param address Address withing the area to be changed.
    767  *
    768  * @return Zero on success or a value from @ref errno.h on failure.
     772 * @param as            Address space.
     773 * @param flags         Flags of the area memory.
     774 * @param address       Address withing the area to be changed.
     775 *
     776 * @return              Zero on success or a value from @ref errno.h on failure.
    769777 */
    770778int as_area_change_flags(as_t *as, int flags, uintptr_t address)
     
    877885        /*
    878886         * Map pages back in with new flags. This step is kept separate
    879          * so that there's no instant when the memory area could be
    880          * accesed with both the old and the new flags at once.
     887         * so that the memory area could not be accesed with both the old and
     888         * the new flags at once.
    881889         */
    882890        frame_idx = 0;
     
    916924/** Handle page fault within the current address space.
    917925 *
    918  * This is the high-level page fault handler. It decides
    919  * whether the page fault can be resolved by any backend
    920  * and if so, it invokes the backend to resolve the page
    921  * fault.
     926 * This is the high-level page fault handler. It decides whether the page fault
     927 * can be resolved by any backend and if so, it invokes the backend to resolve
     928 * the page fault.
    922929 *
    923930 * Interrupts are assumed disabled.
    924931 *
    925  * @param page Faulting page.
    926  * @param access Access mode that caused the fault (i.e. read/write/exec).
    927  * @param istate Pointer to interrupted state.
    928  *
    929  * @return AS_PF_FAULT on page fault, AS_PF_OK on success or AS_PF_DEFER if the
    930  *         fault was caused by copy_to_uspace() or copy_from_uspace().
     932 * @param page          Faulting page.
     933 * @param access        Access mode that caused the page fault (i.e.
     934 *                      read/write/exec).
     935 * @param istate        Pointer to the interrupted state.
     936 *
     937 * @return              AS_PF_FAULT on page fault, AS_PF_OK on success or
     938 *                      AS_PF_DEFER if the fault was caused by copy_to_uspace()
     939 *                      or copy_from_uspace().
    931940 */
    932941int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate)
     
    974983       
    975984        /*
    976          * To avoid race condition between two page faults
    977          * on the same address, we need to make sure
    978          * the mapping has not been already inserted.
     985         * To avoid race condition between two page faults on the same address,
     986         * we need to make sure the mapping has not been already inserted.
    979987         */
    980988        if ((pte = page_mapping_find(AS, page))) {
     
    10301038 * When this function is enetered, no spinlocks may be held.
    10311039 *
    1032  * @param old Old address space or NULL.
    1033  * @param new New address space.
     1040 * @param old           Old address space or NULL.
     1041 * @param new           New address space.
    10341042 */
    10351043void as_switch(as_t *old_as, as_t *new_as)
     
    11021110/** Convert address space area flags to page flags.
    11031111 *
    1104  * @param aflags Flags of some address space area.
    1105  *
    1106  * @return Flags to be passed to page_mapping_insert().
     1112 * @param aflags        Flags of some address space area.
     1113 *
     1114 * @return              Flags to be passed to page_mapping_insert().
    11071115 */
    11081116int area_flags_to_page_flags(int aflags)
     
    11321140 * Interrupts must be disabled.
    11331141 *
    1134  * @param a Address space area.
    1135  *
    1136  * @return Flags to be used in page_mapping_insert().
     1142 * @param a             Address space area.
     1143 *
     1144 * @return              Flags to be used in page_mapping_insert().
    11371145 */
    11381146int as_area_get_flags(as_area_t *a)
     
    11431151/** Create page table.
    11441152 *
    1145  * Depending on architecture, create either address space
    1146  * private or global page table.
    1147  *
    1148  * @param flags Flags saying whether the page table is for kernel address space.
    1149  *
    1150  * @return First entry of the page table.
     1153 * Depending on architecture, create either address space private or global page
     1154 * table.
     1155 *
     1156 * @param flags         Flags saying whether the page table is for the kernel
     1157 *                      address space.
     1158 *
     1159 * @return              First entry of the page table.
    11511160 */
    11521161pte_t *page_table_create(int flags)
     
    11621171 * Destroy page table in architecture specific way.
    11631172 *
    1164  * @param page_table Physical address of PTL0.
     1173 * @param page_table    Physical address of PTL0.
    11651174 */
    11661175void page_table_destroy(pte_t *page_table)
     
    11811190 * call in which case the lock argument is false.
    11821191 *
    1183  * @param as Address space.
    1184  * @param lock If false, do not attempt to lock as->lock.
     1192 * @param as            Address space.
     1193 * @param lock          If false, do not attempt to lock as->lock.
    11851194 */
    11861195void page_table_lock(as_t *as, bool lock)
     
    11941203/** Unlock page table.
    11951204 *
    1196  * @param as Address space.
    1197  * @param unlock If false, do not attempt to unlock as->lock.
     1205 * @param as            Address space.
     1206 * @param unlock        If false, do not attempt to unlock as->lock.
    11981207 */
    11991208void page_table_unlock(as_t *as, bool unlock)
     
    12101219 * The address space must be locked and interrupts must be disabled.
    12111220 *
    1212  * @param as Address space.
    1213  * @param va Virtual address.
    1214  *
    1215  * @return Locked address space area containing va on success or NULL on
    1216  *     failure.
     1221 * @param as            Address space.
     1222 * @param va            Virtual address.
     1223 *
     1224 * @return              Locked address space area containing va on success or
     1225 *                      NULL on failure.
    12171226 */
    12181227as_area_t *find_area_and_lock(as_t *as, uintptr_t va)
     
    12661275 * The address space must be locked and interrupts must be disabled.
    12671276 *
    1268  * @param as Address space.
    1269  * @param va Starting virtual address of the area being tested.
    1270  * @param size Size of the area being tested.
    1271  * @param avoid_area Do not touch this area.
    1272  *
    1273  * @return True if there is no conflict, false otherwise.
    1274  */
    1275 bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
    1276                           as_area_t *avoid_area)
     1277 * @param as            Address space.
     1278 * @param va            Starting virtual address of the area being tested.
     1279 * @param size          Size of the area being tested.
     1280 * @param avoid_area    Do not touch this area.
     1281 *
     1282 * @return              True if there is no conflict, false otherwise.
     1283 */
     1284bool
     1285check_area_conflicts(as_t *as, uintptr_t va, size_t size, as_area_t *avoid_area)
    12771286{
    12781287        as_area_t *a;
     
    13631372        ipl = interrupts_disable();
    13641373        src_area = find_area_and_lock(AS, base);
    1365         if (src_area){
     1374        if (src_area) {
    13661375                size = src_area->pages * PAGE_SIZE;
    13671376                mutex_unlock(&src_area->lock);
     
    13771386 * The address space area must be already locked.
    13781387 *
    1379  * @param a Address space area.
    1380  * @param page First page to be marked.
    1381  * @param count Number of page to be marked.
    1382  *
    1383  * @return 0 on failure and 1 on success.
     1388 * @param a             Address space area.
     1389 * @param page          First page to be marked.
     1390 * @param count         Number of page to be marked.
     1391 *
     1392 * @return              Zero on failure and non-zero on success.
    13841393 */
    13851394int used_space_insert(as_area_t *a, uintptr_t page, count_t count)
     
    16511660        }
    16521661
    1653         panic("Inconsistency detected while adding %" PRIc " pages of used space at "
    1654             "%p.\n", count, page);
     1662        panic("Inconsistency detected while adding %" PRIc " pages of used "
     1663            "space at %p.\n", count, page);
    16551664}
    16561665
     
    16591668 * The address space area must be already locked.
    16601669 *
    1661  * @param a Address space area.
    1662  * @param page First page to be marked.
    1663  * @param count Number of page to be marked.
    1664  *
    1665  * @return 0 on failure and 1 on success.
     1670 * @param a             Address space area.
     1671 * @param page          First page to be marked.
     1672 * @param count         Number of page to be marked.
     1673 *
     1674 * @return              Zero on failure and non-zero on success.
    16661675 */
    16671676int used_space_remove(as_area_t *a, uintptr_t page, count_t count)
     
    18301839
    18311840error:
    1832         panic("Inconsistency detected while removing %" PRIc " pages of used space "
    1833             "from %p.\n", count, page);
     1841        panic("Inconsistency detected while removing %" PRIc " pages of used "
     1842            "space from %p.\n", count, page);
    18341843}
    18351844
     
    18381847 * If the reference count drops to 0, the sh_info is deallocated.
    18391848 *
    1840  * @param sh_info Pointer to address space area share info.
     1849 * @param sh_info       Pointer to address space area share info.
    18411850 */
    18421851void sh_info_remove_reference(share_info_t *sh_info)
     
    19071916/** Print out information about address space.
    19081917 *
    1909  * @param as Address space.
     1918 * @param as            Address space.
    19101919 */
    19111920void as_print(as_t *as)
     
    19291938               
    19301939                        mutex_lock(&area->lock);
    1931                         printf("as_area: %p, base=%p, pages=%" PRIc " (%p - %p)\n",
    1932                             area, area->base, area->pages, area->base,
    1933                             area->base + FRAMES2SIZE(area->pages));
     1940                        printf("as_area: %p, base=%p, pages=%" PRIc
     1941                            " (%p - %p)\n", area, area->base, area->pages,
     1942                            area->base, area->base + FRAMES2SIZE(area->pages));
    19341943                        mutex_unlock(&area->lock);
    19351944                }
Note: See TracChangeset for help on using the changeset viewer.