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


Ignore:
Timestamp:
2011-06-01T10:04:32Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
65c3794
Parents:
049a16f (diff), df29f24 (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 usb/development

File:
1 edited

Legend:

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

    r049a16f rc9f0975  
    302302         * We don't want any area to have conflicts with NULL page.
    303303         */
    304         if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
     304        if (overlaps(addr, P2SZ(count), (uintptr_t) NULL, PAGE_SIZE))
    305305                return false;
    306306       
     
    329329                        mutex_lock(&area->lock);
    330330                       
    331                         if (overlaps(addr, count << PAGE_WIDTH,
    332                             area->base, area->pages << PAGE_WIDTH)) {
     331                        if (overlaps(addr, P2SZ(count), area->base,
     332                            P2SZ(area->pages))) {
    333333                                mutex_unlock(&area->lock);
    334334                                return false;
     
    346346                        mutex_lock(&area->lock);
    347347                       
    348                         if (overlaps(addr, count << PAGE_WIDTH,
    349                             area->base, area->pages << PAGE_WIDTH)) {
     348                        if (overlaps(addr, P2SZ(count), area->base,
     349                            P2SZ(area->pages))) {
    350350                                mutex_unlock(&area->lock);
    351351                                return false;
     
    366366                mutex_lock(&area->lock);
    367367               
    368                 if (overlaps(addr, count << PAGE_WIDTH,
    369                     area->base, area->pages << PAGE_WIDTH)) {
     368                if (overlaps(addr, P2SZ(count), area->base,
     369                    P2SZ(area->pages))) {
    370370                        mutex_unlock(&area->lock);
    371371                        return false;
     
    380380         */
    381381        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    382                 return !overlaps(addr, count << PAGE_WIDTH,
    383                     KERNEL_ADDRESS_SPACE_START,
     382                return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START,
    384383                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
    385384        }
     
    474473       
    475474        btree_node_t *leaf;
    476         as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
     475        as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va,
     476            &leaf);
    477477        if (area) {
    478478                /* va is the base address of an address space area */
     
    482482       
    483483        /*
    484          * Search the leaf node and the righmost record of its left neighbour
     484         * Search the leaf node and the rightmost record of its left neighbour
    485485         * to find out whether this is a miss or va belongs to an address
    486486         * space area found there.
     
    494494               
    495495                mutex_lock(&area->lock);
    496                
     496
    497497                if ((area->base <= va) &&
    498                     (va < area->base + (area->pages << PAGE_WIDTH)))
     498                    (va <= area->base + (P2SZ(area->pages) - 1)))
    499499                        return area;
    500500               
     
    506506         * Because of its position in the B+tree, it must have base < va.
    507507         */
    508         btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     508        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree,
     509            leaf);
    509510        if (lnode) {
    510511                area = (as_area_t *) lnode->value[lnode->keys - 1];
     
    512513                mutex_lock(&area->lock);
    513514               
    514                 if (va < area->base + (area->pages << PAGE_WIDTH))
     515                if (va <= area->base + (P2SZ(area->pages) - 1))
    515516                        return area;
    516517               
     
    577578       
    578579        if (pages < area->pages) {
    579                 uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
     580                uintptr_t start_free = area->base + P2SZ(pages);
    580581               
    581582                /*
     
    590591                 */
    591592                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    592                     area->base + (pages << PAGE_WIDTH), area->pages - pages);
     593                    area->base + P2SZ(pages), area->pages - pages);
    593594               
    594595                /*
     
    613614                                size_t i = 0;
    614615                               
    615                                 if (overlaps(ptr, size << PAGE_WIDTH, area->base,
    616                                     pages << PAGE_WIDTH)) {
     616                                if (overlaps(ptr, P2SZ(size), area->base,
     617                                    P2SZ(pages))) {
    617618                                       
    618                                         if (ptr + (size << PAGE_WIDTH) <= start_free) {
     619                                        if (ptr + P2SZ(size) <= start_free) {
    619620                                                /*
    620621                                                 * The whole interval fits
     
    647648                               
    648649                                for (; i < size; i++) {
    649                                         pte_t *pte = page_mapping_find(as, ptr +
    650                                             (i << PAGE_WIDTH));
     650                                        pte_t *pte = page_mapping_find(as,
     651                                            ptr + P2SZ(i), false);
    651652                                       
    652653                                        ASSERT(pte);
     
    657658                                            (area->backend->frame_free)) {
    658659                                                area->backend->frame_free(area,
    659                                                     ptr + (i << PAGE_WIDTH),
     660                                                    ptr + P2SZ(i),
    660661                                                    PTE_GET_FRAME(pte));
    661662                                        }
    662663                                       
    663                                         page_mapping_remove(as, ptr +
    664                                             (i << PAGE_WIDTH));
     664                                        page_mapping_remove(as, ptr + P2SZ(i));
    665665                                }
    666666                        }
     
    671671                 */
    672672               
    673                 tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
     673                tlb_invalidate_pages(as->asid, area->base + P2SZ(pages),
    674674                    area->pages - pages);
    675675               
    676676                /*
    677                  * Invalidate software translation caches (e.g. TSB on sparc64).
    678                  */
    679                 as_invalidate_translation_cache(as, area->base +
    680                     (pages << PAGE_WIDTH), area->pages - pages);
     677                 * Invalidate software translation caches
     678                 * (e.g. TSB on sparc64, PHT on ppc32).
     679                 */
     680                as_invalidate_translation_cache(as, area->base + P2SZ(pages),
     681                    area->pages - pages);
    681682                tlb_shootdown_finalize(ipl);
    682683               
     
    797798                       
    798799                        for (size = 0; size < (size_t) node->value[i]; size++) {
    799                                 pte_t *pte =
    800                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     800                                pte_t *pte = page_mapping_find(as,
     801                                     ptr + P2SZ(size), false);
    801802                               
    802803                                ASSERT(pte);
     
    807808                                    (area->backend->frame_free)) {
    808809                                        area->backend->frame_free(area,
    809                                             ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
     810                                            ptr + P2SZ(size),
     811                                            PTE_GET_FRAME(pte));
    810812                                }
    811813                               
    812                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     814                                page_mapping_remove(as, ptr + P2SZ(size));
    813815                        }
    814816                }
     
    822824       
    823825        /*
    824          * Invalidate potential software translation caches (e.g. TSB on
    825          * sparc64).
     826         * Invalidate potential software translation caches
     827         * (e.g. TSB on sparc64, PHT on ppc32).
    826828         */
    827829        as_invalidate_translation_cache(as, area->base, area->pages);
     
    897899        }
    898900       
    899         size_t src_size = src_area->pages << PAGE_WIDTH;
     901        size_t src_size = P2SZ(src_area->pages);
    900902        unsigned int src_flags = src_area->flags;
    901903        mem_backend_t *src_backend = src_area->backend;
     
    10941096        for (cur = area->used_space.leaf_head.next;
    10951097            cur != &area->used_space.leaf_head; cur = cur->next) {
    1096                 btree_node_t *node
    1097                     = list_get_instance(cur, btree_node_t, leaf_link);
     1098                btree_node_t *node = list_get_instance(cur, btree_node_t,
     1099                    leaf_link);
    10981100                btree_key_t i;
    10991101               
     
    11031105                       
    11041106                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1105                                 pte_t *pte =
    1106                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     1107                                pte_t *pte = page_mapping_find(as,
     1108                                    ptr + P2SZ(size), false);
    11071109                               
    11081110                                ASSERT(pte);
     
    11131115                               
    11141116                                /* Remove old mapping */
    1115                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     1117                                page_mapping_remove(as, ptr + P2SZ(size));
    11161118                        }
    11171119                }
     
    11251127       
    11261128        /*
    1127          * Invalidate potential software translation caches (e.g. TSB on
    1128          * sparc64).
     1129         * Invalidate potential software translation caches
     1130         * (e.g. TSB on sparc64, PHT on ppc32).
    11291131         */
    11301132        as_invalidate_translation_cache(as, area->base, area->pages);
     
    11591161                               
    11601162                                /* Insert the new mapping */
    1161                                 page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
     1163                                page_mapping_insert(as, ptr + P2SZ(size),
    11621164                                    old_frame[frame_idx++], page_flags);
    11631165                               
     
    12401242         */
    12411243        pte_t *pte;
    1242         if ((pte = page_mapping_find(AS, page))) {
     1244        if ((pte = page_mapping_find(AS, page, false))) {
    12431245                if (PTE_PRESENT(pte)) {
    12441246                        if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
     
    14811483       
    14821484        if (src_area) {
    1483                 size = src_area->pages << PAGE_WIDTH;
     1485                size = P2SZ(src_area->pages);
    14841486                mutex_unlock(&src_area->lock);
    14851487        } else
     
    15361538                if (page >= right_pg) {
    15371539                        /* Do nothing. */
    1538                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1539                     left_cnt << PAGE_WIDTH)) {
     1540                } else if (overlaps(page, P2SZ(count), left_pg,
     1541                    P2SZ(left_cnt))) {
    15401542                        /* The interval intersects with the left interval. */
    15411543                        return false;
    1542                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1543                     right_cnt << PAGE_WIDTH)) {
     1544                } else if (overlaps(page, P2SZ(count), right_pg,
     1545                    P2SZ(right_cnt))) {
    15441546                        /* The interval intersects with the right interval. */
    15451547                        return false;
    1546                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1547                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1548                } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1549                    (page + P2SZ(count) == right_pg)) {
    15481550                        /*
    15491551                         * The interval can be added by merging the two already
     
    15531555                        btree_remove(&area->used_space, right_pg, leaf);
    15541556                        goto success;
    1555                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1557                } else if (page == left_pg + P2SZ(left_cnt)) {
    15561558                        /*
    15571559                         * The interval can be added by simply growing the left
     
    15601562                        node->value[node->keys - 1] += count;
    15611563                        goto success;
    1562                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1564                } else if (page + P2SZ(count) == right_pg) {
    15631565                        /*
    15641566                         * The interval can be addded by simply moving base of
     
    15871589                 */
    15881590               
    1589                 if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1590                     right_cnt << PAGE_WIDTH)) {
     1591                if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) {
    15911592                        /* The interval intersects with the right interval. */
    15921593                        return false;
    1593                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1594                } else if (page + P2SZ(count) == right_pg) {
    15941595                        /*
    15951596                         * The interval can be added by moving the base of the
     
    16261627                if (page < left_pg) {
    16271628                        /* Do nothing. */
    1628                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1629                     left_cnt << PAGE_WIDTH)) {
     1629                } else if (overlaps(page, P2SZ(count), left_pg,
     1630                    P2SZ(left_cnt))) {
    16301631                        /* The interval intersects with the left interval. */
    16311632                        return false;
    1632                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1633                     right_cnt << PAGE_WIDTH)) {
     1633                } else if (overlaps(page, P2SZ(count), right_pg,
     1634                    P2SZ(right_cnt))) {
    16341635                        /* The interval intersects with the right interval. */
    16351636                        return false;
    1636                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1637                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1637                } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1638                    (page + P2SZ(count) == right_pg)) {
    16381639                        /*
    16391640                         * The interval can be added by merging the two already
     
    16431644                        btree_remove(&area->used_space, right_pg, node);
    16441645                        goto success;
    1645                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1646                } else if (page == left_pg + P2SZ(left_cnt)) {
    16461647                        /*
    16471648                         * The interval can be added by simply growing the left
     
    16501651                        leaf->value[leaf->keys - 1] += count;
    16511652                        goto success;
    1652                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1653                } else if (page + P2SZ(count) == right_pg) {
    16531654                        /*
    16541655                         * The interval can be addded by simply moving base of
     
    16771678                 */
    16781679               
    1679                 if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1680                     left_cnt << PAGE_WIDTH)) {
     1680                if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) {
    16811681                        /* The interval intersects with the left interval. */
    16821682                        return false;
    1683                 } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
     1683                } else if (left_pg + P2SZ(left_cnt) == page) {
    16841684                        /*
    16851685                         * The interval can be added by growing the left
     
    17161716                         */
    17171717                       
    1718                         if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1719                             left_cnt << PAGE_WIDTH)) {
     1718                        if (overlaps(page, P2SZ(count), left_pg,
     1719                            P2SZ(left_cnt))) {
    17201720                                /*
    17211721                                 * The interval intersects with the left
     
    17231723                                 */
    17241724                                return false;
    1725                         } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1726                             right_cnt << PAGE_WIDTH)) {
     1725                        } else if (overlaps(page, P2SZ(count), right_pg,
     1726                            P2SZ(right_cnt))) {
    17271727                                /*
    17281728                                 * The interval intersects with the right
     
    17301730                                 */
    17311731                                return false;
    1732                         } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1733                             (page + (count << PAGE_WIDTH) == right_pg)) {
     1732                        } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1733                            (page + P2SZ(count) == right_pg)) {
    17341734                                /*
    17351735                                 * The interval can be added by merging the two
     
    17391739                                btree_remove(&area->used_space, right_pg, leaf);
    17401740                                goto success;
    1741                         } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1741                        } else if (page == left_pg + P2SZ(left_cnt)) {
    17421742                                /*
    17431743                                 * The interval can be added by simply growing
     
    17461746                                leaf->value[i - 1] += count;
    17471747                                goto success;
    1748                         } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1748                        } else if (page + P2SZ(count) == right_pg) {
    17491749                                /*
    17501750                                 * The interval can be addded by simply moving
     
    18121812                        for (i = 0; i < leaf->keys; i++) {
    18131813                                if (leaf->key[i] == page) {
    1814                                         leaf->key[i] += count << PAGE_WIDTH;
     1814                                        leaf->key[i] += P2SZ(count);
    18151815                                        leaf->value[i] -= count;
    18161816                                        goto success;
     
    18221822        }
    18231823       
    1824         btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, leaf);
     1824        btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space,
     1825            leaf);
    18251826        if ((node) && (page < leaf->key[0])) {
    18261827                uintptr_t left_pg = node->key[node->keys - 1];
    18271828                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18281829               
    1829                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1830                     count << PAGE_WIDTH)) {
    1831                         if (page + (count << PAGE_WIDTH) ==
    1832                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1830                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
     1831                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
    18331832                                /*
    18341833                                 * The interval is contained in the rightmost
     
    18391838                                node->value[node->keys - 1] -= count;
    18401839                                goto success;
    1841                         } else if (page + (count << PAGE_WIDTH) <
    1842                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1840                        } else if (page + P2SZ(count) <
     1841                            left_pg + P2SZ(left_cnt)) {
     1842                                size_t new_cnt;
     1843
    18431844                                /*
    18441845                                 * The interval is contained in the rightmost
     
    18481849                                 * new interval.
    18491850                                 */
    1850                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1851                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1851                                new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1852                                    (page + P2SZ(count))) >> PAGE_WIDTH;
    18521853                                node->value[node->keys - 1] -= count + new_cnt;
    18531854                                btree_insert(&area->used_space, page +
    1854                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1855                                    P2SZ(count), (void *) new_cnt, leaf);
    18551856                                goto success;
    18561857                        }
     
    18651866                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    18661867               
    1867                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1868                     count << PAGE_WIDTH)) {
    1869                         if (page + (count << PAGE_WIDTH) ==
    1870                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1868                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
     1869                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
    18711870                                /*
    18721871                                 * The interval is contained in the rightmost
     
    18761875                                leaf->value[leaf->keys - 1] -= count;
    18771876                                goto success;
    1878                         } else if (page + (count << PAGE_WIDTH) < left_pg +
    1879                             (left_cnt << PAGE_WIDTH)) {
     1877                        } else if (page + P2SZ(count) < left_pg +
     1878                            P2SZ(left_cnt)) {
     1879                                size_t new_cnt;
     1880
    18801881                                /*
    18811882                                 * The interval is contained in the rightmost
     
    18851886                                 * interval.
    18861887                                 */
    1887                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1888                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1888                                new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1889                                    (page + P2SZ(count))) >> PAGE_WIDTH;
    18891890                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    18901891                                btree_insert(&area->used_space, page +
    1891                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1892                                    P2SZ(count), (void *) new_cnt, leaf);
    18921893                                goto success;
    18931894                        }
     
    19111912                         * to (i - 1) and i.
    19121913                         */
    1913                         if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1914                             count << PAGE_WIDTH)) {
    1915                                 if (page + (count << PAGE_WIDTH) ==
    1916                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1914                        if (overlaps(left_pg, P2SZ(left_cnt), page,
     1915                            P2SZ(count))) {
     1916                                if (page + P2SZ(count) ==
     1917                                    left_pg + P2SZ(left_cnt)) {
    19171918                                        /*
    19181919                                         * The interval is contained in the
     
    19231924                                        leaf->value[i - 1] -= count;
    19241925                                        goto success;
    1925                                 } else if (page + (count << PAGE_WIDTH) <
    1926                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1926                                } else if (page + P2SZ(count) <
     1927                                    left_pg + P2SZ(left_cnt)) {
     1928                                        size_t new_cnt;
     1929
    19271930                                        /*
    19281931                                         * The interval is contained in the
     
    19321935                                         * also inserting a new interval.
    19331936                                         */
    1934                                         size_t new_cnt = ((left_pg +
    1935                                             (left_cnt << PAGE_WIDTH)) -
    1936                                             (page + (count << PAGE_WIDTH))) >>
     1937                                        new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1938                                            (page + P2SZ(count))) >>
    19371939                                            PAGE_WIDTH;
    19381940                                        leaf->value[i - 1] -= count + new_cnt;
    19391941                                        btree_insert(&area->used_space, page +
    1940                                             (count << PAGE_WIDTH), (void *) new_cnt,
     1942                                            P2SZ(count), (void *) new_cnt,
    19411943                                            leaf);
    19421944                                        goto success;
     
    20342036                btree_key_t i;
    20352037                for (i = 0; (ret == 0) && (i < node->keys); i++) {
     2038                        uintptr_t addr;
     2039
    20362040                        as_area_t *area = (as_area_t *) node->value[i];
    20372041                       
    20382042                        mutex_lock(&area->lock);
    20392043                       
    2040                         uintptr_t addr =
    2041                             ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
     2044                        addr = ALIGN_UP(area->base + P2SZ(area->pages),
    20422045                            PAGE_SIZE);
    20432046                       
     
    20982101                       
    20992102                        info[area_idx].start_addr = area->base;
    2100                         info[area_idx].size = FRAMES2SIZE(area->pages);
     2103                        info[area_idx].size = P2SZ(area->pages);
    21012104                        info[area_idx].flags = area->flags;
    21022105                        ++area_idx;
     
    21362139                            " (%p - %p)\n", area, (void *) area->base,
    21372140                            area->pages, (void *) area->base,
    2138                             (void *) (area->base + FRAMES2SIZE(area->pages)));
     2141                            (void *) (area->base + P2SZ(area->pages)));
    21392142                        mutex_unlock(&area->lock);
    21402143                }
Note: See TracChangeset for help on using the changeset viewer.