Changeset b6f3e7e in mainline
- Timestamp:
- 2011-05-20T22:26:02Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c263c77
- Parents:
- 712c4ba
- Location:
- kernel
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/sparc64/src/mm/sun4u/as.c
r712c4ba rb6f3e7e 47 47 #include <bitops.h> 48 48 #include <macros.h> 49 #include <memstr.h> 49 50 50 51 #endif /* CONFIG_TSB */ -
kernel/arch/sparc64/src/mm/sun4v/as.c
r712c4ba rb6f3e7e 50 50 #include <bitops.h> 51 51 #include <macros.h> 52 #include <memstr.h> 52 53 53 54 #endif /* CONFIG_TSB */ -
kernel/generic/include/mm/page.h
r712c4ba rb6f3e7e 38 38 #include <typedefs.h> 39 39 #include <mm/as.h> 40 #include <memstr.h> 40 #include <arch/mm/page.h> 41 42 #define P2SZ(pages) \ 43 ((pages) << PAGE_WIDTH) 41 44 42 45 /** Operations to manipulate page mappings. */ -
kernel/generic/src/mm/as.c
r712c4ba rb6f3e7e 302 302 * We don't want any area to have conflicts with NULL page. 303 303 */ 304 if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))304 if (overlaps(addr, P2SZ(count), (uintptr_t) NULL, PAGE_SIZE)) 305 305 return false; 306 306 … … 329 329 mutex_lock(&area->lock); 330 330 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))) { 333 333 mutex_unlock(&area->lock); 334 334 return false; … … 346 346 mutex_lock(&area->lock); 347 347 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))) { 350 350 mutex_unlock(&area->lock); 351 351 return false; … … 366 366 mutex_lock(&area->lock); 367 367 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))) { 370 370 mutex_unlock(&area->lock); 371 371 return false; … … 380 380 */ 381 381 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, 384 383 KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START); 385 384 } … … 474 473 475 474 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); 477 477 if (area) { 478 478 /* va is the base address of an address space area */ … … 495 495 mutex_lock(&area->lock); 496 496 497 size_t size = area->pages << PAGE_WIDTH;498 if ((area->base <= va) && (va <= area->base + (size- 1)))497 if ((area->base <= va) && 498 (va <= area->base + (P2SZ(area->pages) - 1))) 499 499 return area; 500 500 … … 506 506 * Because of its position in the B+tree, it must have base < va. 507 507 */ 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); 509 510 if (lnode) { 510 511 area = (as_area_t *) lnode->value[lnode->keys - 1]; … … 512 513 mutex_lock(&area->lock); 513 514 514 if (va < area->base + (area->pages << PAGE_WIDTH))515 if (va <= area->base + (P2SZ(area->pages) - 1)) 515 516 return area; 516 517 … … 577 578 578 579 if (pages < area->pages) { 579 uintptr_t start_free = area->base + (pages << PAGE_WIDTH);580 uintptr_t start_free = area->base + P2SZ(pages); 580 581 581 582 /* … … 590 591 */ 591 592 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); 593 594 594 595 /* … … 613 614 size_t i = 0; 614 615 615 if (overlaps(ptr, size << PAGE_WIDTH, area->base,616 pages << PAGE_WIDTH)) {616 if (overlaps(ptr, P2SZ(size), area->base, 617 P2SZ(pages))) { 617 618 618 if (ptr + (size << PAGE_WIDTH) <= start_free) {619 if (ptr + P2SZ(size) <= start_free) { 619 620 /* 620 621 * The whole interval fits … … 647 648 648 649 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)); 651 652 652 653 ASSERT(pte); … … 657 658 (area->backend->frame_free)) { 658 659 area->backend->frame_free(area, 659 ptr + (i << PAGE_WIDTH),660 ptr + P2SZ(i), 660 661 PTE_GET_FRAME(pte)); 661 662 } 662 663 663 page_mapping_remove(as, ptr + 664 (i << PAGE_WIDTH)); 664 page_mapping_remove(as, ptr + P2SZ(i)); 665 665 } 666 666 } … … 671 671 */ 672 672 673 tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),673 tlb_invalidate_pages(as->asid, area->base + P2SZ(pages), 674 674 area->pages - pages); 675 675 … … 677 677 * Invalidate software translation caches (e.g. TSB on sparc64). 678 678 */ 679 as_invalidate_translation_cache(as, area->base + 680 (pages << PAGE_WIDTH),area->pages - pages);679 as_invalidate_translation_cache(as, area->base + P2SZ(pages), 680 area->pages - pages); 681 681 tlb_shootdown_finalize(ipl); 682 682 … … 797 797 798 798 for (size = 0; size < (size_t) node->value[i]; size++) { 799 pte_t *pte = 800 page_mapping_find(as, ptr + (size << PAGE_WIDTH));799 pte_t *pte = page_mapping_find(as, 800 ptr + P2SZ(size)); 801 801 802 802 ASSERT(pte); … … 807 807 (area->backend->frame_free)) { 808 808 area->backend->frame_free(area, 809 ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte)); 809 ptr + P2SZ(size), 810 PTE_GET_FRAME(pte)); 810 811 } 811 812 812 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));813 page_mapping_remove(as, ptr + P2SZ(size)); 813 814 } 814 815 } … … 897 898 } 898 899 899 size_t src_size = src_area->pages << PAGE_WIDTH;900 size_t src_size = P2SZ(src_area->pages); 900 901 unsigned int src_flags = src_area->flags; 901 902 mem_backend_t *src_backend = src_area->backend; … … 1094 1095 for (cur = area->used_space.leaf_head.next; 1095 1096 cur != &area->used_space.leaf_head; cur = cur->next) { 1096 btree_node_t *node 1097 = list_get_instance(cur, btree_node_t,leaf_link);1097 btree_node_t *node = list_get_instance(cur, btree_node_t, 1098 leaf_link); 1098 1099 btree_key_t i; 1099 1100 … … 1103 1104 1104 1105 for (size = 0; size < (size_t) node->value[i]; size++) { 1105 pte_t *pte = 1106 p age_mapping_find(as, ptr + (size << PAGE_WIDTH));1106 pte_t *pte = page_mapping_find(as, 1107 ptr + P2SZ(size)); 1107 1108 1108 1109 ASSERT(pte); … … 1113 1114 1114 1115 /* Remove old mapping */ 1115 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));1116 page_mapping_remove(as, ptr + P2SZ(size)); 1116 1117 } 1117 1118 } … … 1159 1160 1160 1161 /* Insert the new mapping */ 1161 page_mapping_insert(as, ptr + (size << PAGE_WIDTH),1162 page_mapping_insert(as, ptr + P2SZ(size), 1162 1163 old_frame[frame_idx++], page_flags); 1163 1164 … … 1481 1482 1482 1483 if (src_area) { 1483 size = src_area->pages << PAGE_WIDTH;1484 size = P2SZ(src_area->pages); 1484 1485 mutex_unlock(&src_area->lock); 1485 1486 } else … … 1536 1537 if (page >= right_pg) { 1537 1538 /* Do nothing. */ 1538 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,1539 left_cnt << PAGE_WIDTH)) {1539 } else if (overlaps(page, P2SZ(count), left_pg, 1540 P2SZ(left_cnt))) { 1540 1541 /* The interval intersects with the left interval. */ 1541 1542 return false; 1542 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1543 right_cnt << PAGE_WIDTH)) {1543 } else if (overlaps(page, P2SZ(count), right_pg, 1544 P2SZ(right_cnt))) { 1544 1545 /* The interval intersects with the right interval. */ 1545 1546 return false; 1546 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1547 (page + (count << PAGE_WIDTH) == right_pg)) {1547 } else if ((page == left_pg + P2SZ(left_cnt)) && 1548 (page + P2SZ(count) == right_pg)) { 1548 1549 /* 1549 1550 * The interval can be added by merging the two already … … 1553 1554 btree_remove(&area->used_space, right_pg, leaf); 1554 1555 goto success; 1555 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1556 } else if (page == left_pg + P2SZ(left_cnt)) { 1556 1557 /* 1557 1558 * The interval can be added by simply growing the left … … 1560 1561 node->value[node->keys - 1] += count; 1561 1562 goto success; 1562 } else if (page + (count << PAGE_WIDTH) == right_pg) {1563 } else if (page + P2SZ(count) == right_pg) { 1563 1564 /* 1564 1565 * The interval can be addded by simply moving base of … … 1587 1588 */ 1588 1589 1589 if (overlaps(page, count << PAGE_WIDTH, right_pg, 1590 right_cnt << PAGE_WIDTH)) { 1590 if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) { 1591 1591 /* The interval intersects with the right interval. */ 1592 1592 return false; 1593 } else if (page + (count << PAGE_WIDTH) == right_pg) {1593 } else if (page + P2SZ(count) == right_pg) { 1594 1594 /* 1595 1595 * The interval can be added by moving the base of the … … 1626 1626 if (page < left_pg) { 1627 1627 /* Do nothing. */ 1628 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,1629 left_cnt << PAGE_WIDTH)) {1628 } else if (overlaps(page, P2SZ(count), left_pg, 1629 P2SZ(left_cnt))) { 1630 1630 /* The interval intersects with the left interval. */ 1631 1631 return false; 1632 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1633 right_cnt << PAGE_WIDTH)) {1632 } else if (overlaps(page, P2SZ(count), right_pg, 1633 P2SZ(right_cnt))) { 1634 1634 /* The interval intersects with the right interval. */ 1635 1635 return false; 1636 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1637 (page + (count << PAGE_WIDTH) == right_pg)) {1636 } else if ((page == left_pg + P2SZ(left_cnt)) && 1637 (page + P2SZ(count) == right_pg)) { 1638 1638 /* 1639 1639 * The interval can be added by merging the two already … … 1643 1643 btree_remove(&area->used_space, right_pg, node); 1644 1644 goto success; 1645 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1645 } else if (page == left_pg + P2SZ(left_cnt)) { 1646 1646 /* 1647 1647 * The interval can be added by simply growing the left … … 1650 1650 leaf->value[leaf->keys - 1] += count; 1651 1651 goto success; 1652 } else if (page + (count << PAGE_WIDTH) == right_pg) {1652 } else if (page + P2SZ(count) == right_pg) { 1653 1653 /* 1654 1654 * The interval can be addded by simply moving base of … … 1677 1677 */ 1678 1678 1679 if (overlaps(page, count << PAGE_WIDTH, left_pg, 1680 left_cnt << PAGE_WIDTH)) { 1679 if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) { 1681 1680 /* The interval intersects with the left interval. */ 1682 1681 return false; 1683 } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {1682 } else if (left_pg + P2SZ(left_cnt) == page) { 1684 1683 /* 1685 1684 * The interval can be added by growing the left … … 1716 1715 */ 1717 1716 1718 if (overlaps(page, count << PAGE_WIDTH, left_pg,1719 left_cnt << PAGE_WIDTH)) {1717 if (overlaps(page, P2SZ(count), left_pg, 1718 P2SZ(left_cnt))) { 1720 1719 /* 1721 1720 * The interval intersects with the left … … 1723 1722 */ 1724 1723 return false; 1725 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1726 right_cnt << PAGE_WIDTH)) {1724 } else if (overlaps(page, P2SZ(count), right_pg, 1725 P2SZ(right_cnt))) { 1727 1726 /* 1728 1727 * The interval intersects with the right … … 1730 1729 */ 1731 1730 return false; 1732 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1733 (page + (count << PAGE_WIDTH) == right_pg)) {1731 } else if ((page == left_pg + P2SZ(left_cnt)) && 1732 (page + P2SZ(count) == right_pg)) { 1734 1733 /* 1735 1734 * The interval can be added by merging the two … … 1739 1738 btree_remove(&area->used_space, right_pg, leaf); 1740 1739 goto success; 1741 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1740 } else if (page == left_pg + P2SZ(left_cnt)) { 1742 1741 /* 1743 1742 * The interval can be added by simply growing … … 1746 1745 leaf->value[i - 1] += count; 1747 1746 goto success; 1748 } else if (page + (count << PAGE_WIDTH) == right_pg) {1747 } else if (page + P2SZ(count) == right_pg) { 1749 1748 /* 1750 1749 * The interval can be addded by simply moving … … 1812 1811 for (i = 0; i < leaf->keys; i++) { 1813 1812 if (leaf->key[i] == page) { 1814 leaf->key[i] += count << PAGE_WIDTH;1813 leaf->key[i] += P2SZ(count); 1815 1814 leaf->value[i] -= count; 1816 1815 goto success; … … 1822 1821 } 1823 1822 1824 btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, leaf); 1823 btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, 1824 leaf); 1825 1825 if ((node) && (page < leaf->key[0])) { 1826 1826 uintptr_t left_pg = node->key[node->keys - 1]; 1827 1827 size_t left_cnt = (size_t) node->value[node->keys - 1]; 1828 1828 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)) { 1829 if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) { 1830 if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) { 1833 1831 /* 1834 1832 * The interval is contained in the rightmost … … 1839 1837 node->value[node->keys - 1] -= count; 1840 1838 goto success; 1841 } else if (page + (count << PAGE_WIDTH) < 1842 left_pg + (left_cnt << PAGE_WIDTH)) { 1839 } else if (page + P2SZ(count) < 1840 left_pg + P2SZ(left_cnt)) { 1841 size_t new_cnt; 1842 1843 1843 /* 1844 1844 * The interval is contained in the rightmost … … 1848 1848 * new interval. 1849 1849 */ 1850 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -1851 (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;1850 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1851 (page + P2SZ(count))) >> PAGE_WIDTH; 1852 1852 node->value[node->keys - 1] -= count + new_cnt; 1853 1853 btree_insert(&area->used_space, page + 1854 (count << PAGE_WIDTH), (void *) new_cnt, leaf);1854 P2SZ(count), (void *) new_cnt, leaf); 1855 1855 goto success; 1856 1856 } … … 1865 1865 size_t left_cnt = (size_t) leaf->value[leaf->keys - 1]; 1866 1866 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)) { 1867 if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) { 1868 if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) { 1871 1869 /* 1872 1870 * The interval is contained in the rightmost … … 1876 1874 leaf->value[leaf->keys - 1] -= count; 1877 1875 goto success; 1878 } else if (page + (count << PAGE_WIDTH) < left_pg + 1879 (left_cnt << PAGE_WIDTH)) { 1876 } else if (page + P2SZ(count) < left_pg + 1877 P2SZ(left_cnt)) { 1878 size_t new_cnt; 1879 1880 1880 /* 1881 1881 * The interval is contained in the rightmost … … 1885 1885 * interval. 1886 1886 */ 1887 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -1888 (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;1887 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1888 (page + P2SZ(count))) >> PAGE_WIDTH; 1889 1889 leaf->value[leaf->keys - 1] -= count + new_cnt; 1890 1890 btree_insert(&area->used_space, page + 1891 (count << PAGE_WIDTH), (void *) new_cnt, leaf);1891 P2SZ(count), (void *) new_cnt, leaf); 1892 1892 goto success; 1893 1893 } … … 1911 1911 * to (i - 1) and i. 1912 1912 */ 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)) {1913 if (overlaps(left_pg, P2SZ(left_cnt), page, 1914 P2SZ(count))) { 1915 if (page + P2SZ(count) == 1916 left_pg + P2SZ(left_cnt)) { 1917 1917 /* 1918 1918 * The interval is contained in the … … 1923 1923 leaf->value[i - 1] -= count; 1924 1924 goto success; 1925 } else if (page + (count << PAGE_WIDTH) < 1926 left_pg + (left_cnt << PAGE_WIDTH)) { 1925 } else if (page + P2SZ(count) < 1926 left_pg + P2SZ(left_cnt)) { 1927 size_t new_cnt; 1928 1927 1929 /* 1928 1930 * The interval is contained in the … … 1932 1934 * also inserting a new interval. 1933 1935 */ 1934 size_t new_cnt = ((left_pg + 1935 (left_cnt << PAGE_WIDTH)) - 1936 (page + (count << PAGE_WIDTH))) >> 1936 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1937 (page + P2SZ(count))) >> 1937 1938 PAGE_WIDTH; 1938 1939 leaf->value[i - 1] -= count + new_cnt; 1939 1940 btree_insert(&area->used_space, page + 1940 (count << PAGE_WIDTH), (void *) new_cnt,1941 P2SZ(count), (void *) new_cnt, 1941 1942 leaf); 1942 1943 goto success; … … 2034 2035 btree_key_t i; 2035 2036 for (i = 0; (ret == 0) && (i < node->keys); i++) { 2037 uintptr_t addr; 2038 2036 2039 as_area_t *area = (as_area_t *) node->value[i]; 2037 2040 2038 2041 mutex_lock(&area->lock); 2039 2042 2040 uintptr_t addr = 2041 ALIGN_UP(area->base + (area->pages << PAGE_WIDTH), 2043 addr = ALIGN_UP(area->base + P2SZ(area->pages), 2042 2044 PAGE_SIZE); 2043 2045 … … 2098 2100 2099 2101 info[area_idx].start_addr = area->base; 2100 info[area_idx].size = FRAMES2SIZE(area->pages);2102 info[area_idx].size = P2SZ(area->pages); 2101 2103 info[area_idx].flags = area->flags; 2102 2104 ++area_idx; … … 2136 2138 " (%p - %p)\n", area, (void *) area->base, 2137 2139 area->pages, (void *) area->base, 2138 (void *) (area->base + FRAMES2SIZE(area->pages)));2140 (void *) (area->base + P2SZ(area->pages))); 2139 2141 mutex_unlock(&area->lock); 2140 2142 } -
kernel/generic/src/mm/backend_anon.c
r712c4ba rb6f3e7e 50 50 #include <typedefs.h> 51 51 #include <align.h> 52 #include <memstr.h> 52 53 #include <arch.h> 53 54
Note:
See TracChangeset
for help on using the changeset viewer.