Ignore:
File:
1 edited

Legend:

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

    rb6f3e7e re394b736  
    302302         * We don't want any area to have conflicts with NULL page.
    303303         */
    304         if (overlaps(addr, P2SZ(count), (uintptr_t) NULL, PAGE_SIZE))
     304        if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
    305305                return false;
    306306       
     
    329329                        mutex_lock(&area->lock);
    330330                       
    331                         if (overlaps(addr, P2SZ(count), area->base,
    332                             P2SZ(area->pages))) {
     331                        if (overlaps(addr, count << PAGE_WIDTH,
     332                            area->base, area->pages << PAGE_WIDTH)) {
    333333                                mutex_unlock(&area->lock);
    334334                                return false;
     
    346346                        mutex_lock(&area->lock);
    347347                       
    348                         if (overlaps(addr, P2SZ(count), area->base,
    349                             P2SZ(area->pages))) {
     348                        if (overlaps(addr, count << PAGE_WIDTH,
     349                            area->base, area->pages << PAGE_WIDTH)) {
    350350                                mutex_unlock(&area->lock);
    351351                                return false;
     
    366366                mutex_lock(&area->lock);
    367367               
    368                 if (overlaps(addr, P2SZ(count), area->base,
    369                     P2SZ(area->pages))) {
     368                if (overlaps(addr, count << PAGE_WIDTH,
     369                    area->base, area->pages << PAGE_WIDTH)) {
    370370                        mutex_unlock(&area->lock);
    371371                        return false;
     
    380380         */
    381381        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    382                 return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START,
     382                return !overlaps(addr, count << PAGE_WIDTH,
     383                    KERNEL_ADDRESS_SPACE_START,
    383384                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
    384385        }
     
    473474       
    474475        btree_node_t *leaf;
    475         as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va,
    476             &leaf);
     476        as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
    477477        if (area) {
    478478                /* va is the base address of an address space area */
     
    482482       
    483483        /*
    484          * Search the leaf node and the rightmost record of its left neighbour
     484         * Search the leaf node and the righmost 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 + (P2SZ(area->pages) - 1)))
     498                    (va < area->base + (area->pages << PAGE_WIDTH)))
    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,
    509             leaf);
     508        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
    510509        if (lnode) {
    511510                area = (as_area_t *) lnode->value[lnode->keys - 1];
     
    513512                mutex_lock(&area->lock);
    514513               
    515                 if (va <= area->base + (P2SZ(area->pages) - 1))
     514                if (va < area->base + (area->pages << PAGE_WIDTH))
    516515                        return area;
    517516               
     
    578577       
    579578        if (pages < area->pages) {
    580                 uintptr_t start_free = area->base + P2SZ(pages);
     579                uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
    581580               
    582581                /*
     
    591590                 */
    592591                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    593                     area->base + P2SZ(pages), area->pages - pages);
     592                    area->base + (pages << PAGE_WIDTH), area->pages - pages);
    594593               
    595594                /*
     
    614613                                size_t i = 0;
    615614                               
    616                                 if (overlaps(ptr, P2SZ(size), area->base,
    617                                     P2SZ(pages))) {
     615                                if (overlaps(ptr, size << PAGE_WIDTH, area->base,
     616                                    pages << PAGE_WIDTH)) {
    618617                                       
    619                                         if (ptr + P2SZ(size) <= start_free) {
     618                                        if (ptr + (size << PAGE_WIDTH) <= start_free) {
    620619                                                /*
    621620                                                 * The whole interval fits
     
    648647                               
    649648                                for (; i < size; i++) {
    650                                         pte_t *pte = page_mapping_find(as,
    651                                             ptr + P2SZ(i));
     649                                        pte_t *pte = page_mapping_find(as, ptr +
     650                                            (i << PAGE_WIDTH));
    652651                                       
    653652                                        ASSERT(pte);
     
    658657                                            (area->backend->frame_free)) {
    659658                                                area->backend->frame_free(area,
    660                                                     ptr + P2SZ(i),
     659                                                    ptr + (i << PAGE_WIDTH),
    661660                                                    PTE_GET_FRAME(pte));
    662661                                        }
    663662                                       
    664                                         page_mapping_remove(as, ptr + P2SZ(i));
     663                                        page_mapping_remove(as, ptr +
     664                                            (i << PAGE_WIDTH));
    665665                                }
    666666                        }
     
    671671                 */
    672672               
    673                 tlb_invalidate_pages(as->asid, area->base + P2SZ(pages),
     673                tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
    674674                    area->pages - pages);
    675675               
     
    677677                 * Invalidate software translation caches (e.g. TSB on sparc64).
    678678                 */
    679                 as_invalidate_translation_cache(as, area->base + P2SZ(pages),
    680                     area->pages - pages);
     679                as_invalidate_translation_cache(as, area->base +
     680                    (pages << PAGE_WIDTH), area->pages - pages);
    681681                tlb_shootdown_finalize(ipl);
    682682               
     
    797797                       
    798798                        for (size = 0; size < (size_t) node->value[i]; size++) {
    799                                 pte_t *pte = page_mapping_find(as,
    800                                      ptr + P2SZ(size));
     799                                pte_t *pte =
     800                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    801801                               
    802802                                ASSERT(pte);
     
    807807                                    (area->backend->frame_free)) {
    808808                                        area->backend->frame_free(area,
    809                                             ptr + P2SZ(size),
    810                                             PTE_GET_FRAME(pte));
     809                                            ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
    811810                                }
    812811                               
    813                                 page_mapping_remove(as, ptr + P2SZ(size));
     812                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    814813                        }
    815814                }
     
    898897        }
    899898       
    900         size_t src_size = P2SZ(src_area->pages);
     899        size_t src_size = src_area->pages << PAGE_WIDTH;
    901900        unsigned int src_flags = src_area->flags;
    902901        mem_backend_t *src_backend = src_area->backend;
     
    10951094        for (cur = area->used_space.leaf_head.next;
    10961095            cur != &area->used_space.leaf_head; cur = cur->next) {
    1097                 btree_node_t *node = list_get_instance(cur, btree_node_t,
    1098                     leaf_link);
     1096                btree_node_t *node
     1097                    = list_get_instance(cur, btree_node_t, leaf_link);
    10991098                btree_key_t i;
    11001099               
     
    11041103                       
    11051104                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1106                                 pte_t *pte = page_mapping_find(as,
    1107                                     ptr + P2SZ(size));
     1105                                pte_t *pte =
     1106                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    11081107                               
    11091108                                ASSERT(pte);
     
    11141113                               
    11151114                                /* Remove old mapping */
    1116                                 page_mapping_remove(as, ptr + P2SZ(size));
     1115                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    11171116                        }
    11181117                }
     
    11601159                               
    11611160                                /* Insert the new mapping */
    1162                                 page_mapping_insert(as, ptr + P2SZ(size),
     1161                                page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
    11631162                                    old_frame[frame_idx++], page_flags);
    11641163                               
     
    14821481       
    14831482        if (src_area) {
    1484                 size = P2SZ(src_area->pages);
     1483                size = src_area->pages << PAGE_WIDTH;
    14851484                mutex_unlock(&src_area->lock);
    14861485        } else
     
    15371536                if (page >= right_pg) {
    15381537                        /* Do nothing. */
    1539                 } else if (overlaps(page, P2SZ(count), left_pg,
    1540                     P2SZ(left_cnt))) {
     1538                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1539                    left_cnt << PAGE_WIDTH)) {
    15411540                        /* The interval intersects with the left interval. */
    15421541                        return false;
    1543                 } else if (overlaps(page, P2SZ(count), right_pg,
    1544                     P2SZ(right_cnt))) {
     1542                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1543                    right_cnt << PAGE_WIDTH)) {
    15451544                        /* The interval intersects with the right interval. */
    15461545                        return false;
    1547                 } else if ((page == left_pg + P2SZ(left_cnt)) &&
    1548                     (page + P2SZ(count) == right_pg)) {
     1546                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1547                    (page + (count << PAGE_WIDTH) == right_pg)) {
    15491548                        /*
    15501549                         * The interval can be added by merging the two already
     
    15541553                        btree_remove(&area->used_space, right_pg, leaf);
    15551554                        goto success;
    1556                 } else if (page == left_pg + P2SZ(left_cnt)) {
     1555                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    15571556                        /*
    15581557                         * The interval can be added by simply growing the left
     
    15611560                        node->value[node->keys - 1] += count;
    15621561                        goto success;
    1563                 } else if (page + P2SZ(count) == right_pg) {
     1562                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    15641563                        /*
    15651564                         * The interval can be addded by simply moving base of
     
    15881587                 */
    15891588               
    1590                 if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) {
     1589                if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1590                    right_cnt << PAGE_WIDTH)) {
    15911591                        /* The interval intersects with the right interval. */
    15921592                        return false;
    1593                 } else if (page + P2SZ(count) == right_pg) {
     1593                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    15941594                        /*
    15951595                         * The interval can be added by moving the base of the
     
    16261626                if (page < left_pg) {
    16271627                        /* Do nothing. */
    1628                 } else if (overlaps(page, P2SZ(count), left_pg,
    1629                     P2SZ(left_cnt))) {
     1628                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1629                    left_cnt << PAGE_WIDTH)) {
    16301630                        /* The interval intersects with the left interval. */
    16311631                        return false;
    1632                 } else if (overlaps(page, P2SZ(count), right_pg,
    1633                     P2SZ(right_cnt))) {
     1632                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1633                    right_cnt << PAGE_WIDTH)) {
    16341634                        /* The interval intersects with the right interval. */
    16351635                        return false;
    1636                 } else if ((page == left_pg + P2SZ(left_cnt)) &&
    1637                     (page + P2SZ(count) == right_pg)) {
     1636                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1637                    (page + (count << PAGE_WIDTH) == right_pg)) {
    16381638                        /*
    16391639                         * The interval can be added by merging the two already
     
    16431643                        btree_remove(&area->used_space, right_pg, node);
    16441644                        goto success;
    1645                 } else if (page == left_pg + P2SZ(left_cnt)) {
     1645                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    16461646                        /*
    16471647                         * The interval can be added by simply growing the left
     
    16501650                        leaf->value[leaf->keys - 1] += count;
    16511651                        goto success;
    1652                 } else if (page + P2SZ(count) == right_pg) {
     1652                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    16531653                        /*
    16541654                         * The interval can be addded by simply moving base of
     
    16771677                 */
    16781678               
    1679                 if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) {
     1679                if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1680                    left_cnt << PAGE_WIDTH)) {
    16801681                        /* The interval intersects with the left interval. */
    16811682                        return false;
    1682                 } else if (left_pg + P2SZ(left_cnt) == page) {
     1683                } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
    16831684                        /*
    16841685                         * The interval can be added by growing the left
     
    17151716                         */
    17161717                       
    1717                         if (overlaps(page, P2SZ(count), left_pg,
    1718                             P2SZ(left_cnt))) {
     1718                        if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1719                            left_cnt << PAGE_WIDTH)) {
    17191720                                /*
    17201721                                 * The interval intersects with the left
     
    17221723                                 */
    17231724                                return false;
    1724                         } else if (overlaps(page, P2SZ(count), right_pg,
    1725                             P2SZ(right_cnt))) {
     1725                        } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1726                            right_cnt << PAGE_WIDTH)) {
    17261727                                /*
    17271728                                 * The interval intersects with the right
     
    17291730                                 */
    17301731                                return false;
    1731                         } else if ((page == left_pg + P2SZ(left_cnt)) &&
    1732                             (page + P2SZ(count) == right_pg)) {
     1732                        } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1733                            (page + (count << PAGE_WIDTH) == right_pg)) {
    17331734                                /*
    17341735                                 * The interval can be added by merging the two
     
    17381739                                btree_remove(&area->used_space, right_pg, leaf);
    17391740                                goto success;
    1740                         } else if (page == left_pg + P2SZ(left_cnt)) {
     1741                        } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    17411742                                /*
    17421743                                 * The interval can be added by simply growing
     
    17451746                                leaf->value[i - 1] += count;
    17461747                                goto success;
    1747                         } else if (page + P2SZ(count) == right_pg) {
     1748                        } else if (page + (count << PAGE_WIDTH) == right_pg) {
    17481749                                /*
    17491750                                 * The interval can be addded by simply moving
     
    18111812                        for (i = 0; i < leaf->keys; i++) {
    18121813                                if (leaf->key[i] == page) {
    1813                                         leaf->key[i] += P2SZ(count);
     1814                                        leaf->key[i] += count << PAGE_WIDTH;
    18141815                                        leaf->value[i] -= count;
    18151816                                        goto success;
     
    18211822        }
    18221823       
    1823         btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space,
    1824             leaf);
     1824        btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, leaf);
    18251825        if ((node) && (page < leaf->key[0])) {
    18261826                uintptr_t left_pg = node->key[node->keys - 1];
    18271827                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18281828               
    1829                 if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
    1830                         if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
     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)) {
    18311833                                /*
    18321834                                 * The interval is contained in the rightmost
     
    18371839                                node->value[node->keys - 1] -= count;
    18381840                                goto success;
    1839                         } else if (page + P2SZ(count) <
    1840                             left_pg + P2SZ(left_cnt)) {
    1841                                 size_t new_cnt;
    1842 
     1841                        } else if (page + (count << PAGE_WIDTH) <
     1842                            left_pg + (left_cnt << PAGE_WIDTH)) {
    18431843                                /*
    18441844                                 * The interval is contained in the rightmost
     
    18481848                                 * new interval.
    18491849                                 */
    1850                                 new_cnt = ((left_pg + P2SZ(left_cnt)) -
    1851                                     (page + P2SZ(count))) >> PAGE_WIDTH;
     1850                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1851                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    18521852                                node->value[node->keys - 1] -= count + new_cnt;
    18531853                                btree_insert(&area->used_space, page +
    1854                                     P2SZ(count), (void *) new_cnt, leaf);
     1854                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
    18551855                                goto success;
    18561856                        }
     
    18651865                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    18661866               
    1867                 if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
    1868                         if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
     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)) {
    18691871                                /*
    18701872                                 * The interval is contained in the rightmost
     
    18741876                                leaf->value[leaf->keys - 1] -= count;
    18751877                                goto success;
    1876                         } else if (page + P2SZ(count) < left_pg +
    1877                             P2SZ(left_cnt)) {
    1878                                 size_t new_cnt;
    1879 
     1878                        } else if (page + (count << PAGE_WIDTH) < left_pg +
     1879                            (left_cnt << PAGE_WIDTH)) {
    18801880                                /*
    18811881                                 * The interval is contained in the rightmost
     
    18851885                                 * interval.
    18861886                                 */
    1887                                 new_cnt = ((left_pg + P2SZ(left_cnt)) -
    1888                                     (page + P2SZ(count))) >> PAGE_WIDTH;
     1887                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1888                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    18891889                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    18901890                                btree_insert(&area->used_space, page +
    1891                                     P2SZ(count), (void *) new_cnt, leaf);
     1891                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
    18921892                                goto success;
    18931893                        }
     
    19111911                         * to (i - 1) and i.
    19121912                         */
    1913                         if (overlaps(left_pg, P2SZ(left_cnt), page,
    1914                             P2SZ(count))) {
    1915                                 if (page + P2SZ(count) ==
    1916                                     left_pg + P2SZ(left_cnt)) {
     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)) {
    19171917                                        /*
    19181918                                         * The interval is contained in the
     
    19231923                                        leaf->value[i - 1] -= count;
    19241924                                        goto success;
    1925                                 } else if (page + P2SZ(count) <
    1926                                     left_pg + P2SZ(left_cnt)) {
    1927                                         size_t new_cnt;
    1928 
     1925                                } else if (page + (count << PAGE_WIDTH) <
     1926                                    left_pg + (left_cnt << PAGE_WIDTH)) {
    19291927                                        /*
    19301928                                         * The interval is contained in the
     
    19341932                                         * also inserting a new interval.
    19351933                                         */
    1936                                         new_cnt = ((left_pg + P2SZ(left_cnt)) -
    1937                                             (page + P2SZ(count))) >>
     1934                                        size_t new_cnt = ((left_pg +
     1935                                            (left_cnt << PAGE_WIDTH)) -
     1936                                            (page + (count << PAGE_WIDTH))) >>
    19381937                                            PAGE_WIDTH;
    19391938                                        leaf->value[i - 1] -= count + new_cnt;
    19401939                                        btree_insert(&area->used_space, page +
    1941                                             P2SZ(count), (void *) new_cnt,
     1940                                            (count << PAGE_WIDTH), (void *) new_cnt,
    19421941                                            leaf);
    19431942                                        goto success;
     
    20352034                btree_key_t i;
    20362035                for (i = 0; (ret == 0) && (i < node->keys); i++) {
    2037                         uintptr_t addr;
    2038 
    20392036                        as_area_t *area = (as_area_t *) node->value[i];
    20402037                       
    20412038                        mutex_lock(&area->lock);
    20422039                       
    2043                         addr = ALIGN_UP(area->base + P2SZ(area->pages),
     2040                        uintptr_t addr =
     2041                            ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
    20442042                            PAGE_SIZE);
    20452043                       
     
    21002098                       
    21012099                        info[area_idx].start_addr = area->base;
    2102                         info[area_idx].size = P2SZ(area->pages);
     2100                        info[area_idx].size = FRAMES2SIZE(area->pages);
    21032101                        info[area_idx].flags = area->flags;
    21042102                        ++area_idx;
     
    21382136                            " (%p - %p)\n", area, (void *) area->base,
    21392137                            area->pages, (void *) area->base,
    2140                             (void *) (area->base + P2SZ(area->pages)));
     2138                            (void *) (area->base + FRAMES2SIZE(area->pages)));
    21412139                        mutex_unlock(&area->lock);
    21422140                }
Note: See TracChangeset for help on using the changeset viewer.