Changeset 544a2e4 in mainline for kernel/generic/src/mm/as.c
- Timestamp:
- 2011-05-30T21:37:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7b712b60
- Parents:
- 18ba2e4f (diff), 0743493a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/as.c
r18ba2e4f r544a2e4 80 80 #include <arch/interrupt.h> 81 81 82 #ifdef CONFIG_VIRT_IDX_DCACHE83 #include <arch/mm/cache.h>84 #endif /* CONFIG_VIRT_IDX_DCACHE */85 86 82 /** 87 83 * Each architecture decides what functions will be used to carry out … … 306 302 * We don't want any area to have conflicts with NULL page. 307 303 */ 308 if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))304 if (overlaps(addr, P2SZ(count), (uintptr_t) NULL, PAGE_SIZE)) 309 305 return false; 310 306 … … 333 329 mutex_lock(&area->lock); 334 330 335 if (overlaps(addr, count << PAGE_WIDTH,336 area->base, area->pages << PAGE_WIDTH)) {331 if (overlaps(addr, P2SZ(count), area->base, 332 P2SZ(area->pages))) { 337 333 mutex_unlock(&area->lock); 338 334 return false; … … 350 346 mutex_lock(&area->lock); 351 347 352 if (overlaps(addr, count << PAGE_WIDTH,353 area->base, area->pages << PAGE_WIDTH)) {348 if (overlaps(addr, P2SZ(count), area->base, 349 P2SZ(area->pages))) { 354 350 mutex_unlock(&area->lock); 355 351 return false; … … 370 366 mutex_lock(&area->lock); 371 367 372 if (overlaps(addr, count << PAGE_WIDTH,373 area->base, area->pages << PAGE_WIDTH)) {368 if (overlaps(addr, P2SZ(count), area->base, 369 P2SZ(area->pages))) { 374 370 mutex_unlock(&area->lock); 375 371 return false; … … 384 380 */ 385 381 if (!KERNEL_ADDRESS_SPACE_SHADOWED) { 386 return !overlaps(addr, count << PAGE_WIDTH, 387 KERNEL_ADDRESS_SPACE_START, 382 return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START, 388 383 KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START); 389 384 } … … 448 443 memsetb(&area->backend_data, sizeof(area->backend_data), 0); 449 444 445 if (area->backend && area->backend->create) { 446 if (!area->backend->create(area)) { 447 free(area); 448 mutex_unlock(&as->lock); 449 return NULL; 450 } 451 } 452 450 453 btree_create(&area->used_space); 451 454 btree_insert(&as->as_area_btree, base, (void *) area, NULL); … … 470 473 471 474 btree_node_t *leaf; 472 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); 473 477 if (area) { 474 478 /* va is the base address of an address space area */ … … 478 482 479 483 /* 480 * Search the leaf node and the righ most record of its left neighbour484 * Search the leaf node and the rightmost record of its left neighbour 481 485 * to find out whether this is a miss or va belongs to an address 482 486 * space area found there. … … 490 494 491 495 mutex_lock(&area->lock); 492 496 493 497 if ((area->base <= va) && 494 (va < area->base + (area->pages << PAGE_WIDTH)))498 (va <= area->base + (P2SZ(area->pages) - 1))) 495 499 return area; 496 500 … … 502 506 * Because of its position in the B+tree, it must have base < va. 503 507 */ 504 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); 505 510 if (lnode) { 506 511 area = (as_area_t *) lnode->value[lnode->keys - 1]; … … 508 513 mutex_lock(&area->lock); 509 514 510 if (va < area->base + (area->pages << PAGE_WIDTH))515 if (va <= area->base + (P2SZ(area->pages) - 1)) 511 516 return area; 512 517 … … 573 578 574 579 if (pages < area->pages) { 575 uintptr_t start_free = area->base + (pages << PAGE_WIDTH);580 uintptr_t start_free = area->base + P2SZ(pages); 576 581 577 582 /* … … 586 591 */ 587 592 ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, 588 area->base + (pages << PAGE_WIDTH), area->pages - pages);593 area->base + P2SZ(pages), area->pages - pages); 589 594 590 595 /* … … 609 614 size_t i = 0; 610 615 611 if (overlaps(ptr, size << PAGE_WIDTH, area->base,612 pages << PAGE_WIDTH)) {616 if (overlaps(ptr, P2SZ(size), area->base, 617 P2SZ(pages))) { 613 618 614 if (ptr + (size << PAGE_WIDTH) <= start_free) {619 if (ptr + P2SZ(size) <= start_free) { 615 620 /* 616 621 * The whole interval fits … … 643 648 644 649 for (; i < size; i++) { 645 pte_t *pte = page_mapping_find(as, ptr +646 (i << PAGE_WIDTH));650 pte_t *pte = page_mapping_find(as, 651 ptr + P2SZ(i), false); 647 652 648 653 ASSERT(pte); … … 653 658 (area->backend->frame_free)) { 654 659 area->backend->frame_free(area, 655 ptr + (i << PAGE_WIDTH),660 ptr + P2SZ(i), 656 661 PTE_GET_FRAME(pte)); 657 662 } 658 663 659 page_mapping_remove(as, ptr + 660 (i << PAGE_WIDTH)); 664 page_mapping_remove(as, ptr + P2SZ(i)); 661 665 } 662 666 } … … 667 671 */ 668 672 669 tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),673 tlb_invalidate_pages(as->asid, area->base + P2SZ(pages), 670 674 area->pages - pages); 671 675 672 676 /* 673 * Invalidate software translation caches (e.g. TSB on sparc64). 674 */ 675 as_invalidate_translation_cache(as, area->base + 676 (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); 677 682 tlb_shootdown_finalize(ipl); 678 683 … … 687 692 mutex_unlock(&as->lock); 688 693 return EADDRNOTAVAIL; 694 } 695 } 696 697 if (area->backend && area->backend->resize) { 698 if (!area->backend->resize(area, pages)) { 699 mutex_unlock(&area->lock); 700 mutex_unlock(&as->lock); 701 return ENOMEM; 689 702 } 690 703 } … … 756 769 return ENOENT; 757 770 } 771 772 if (area->backend && area->backend->destroy) 773 area->backend->destroy(area); 758 774 759 775 uintptr_t base = area->base; … … 782 798 783 799 for (size = 0; size < (size_t) node->value[i]; size++) { 784 pte_t *pte = 785 page_mapping_find(as, ptr + (size << PAGE_WIDTH));800 pte_t *pte = page_mapping_find(as, 801 ptr + P2SZ(size), false); 786 802 787 803 ASSERT(pte); … … 792 808 (area->backend->frame_free)) { 793 809 area->backend->frame_free(area, 794 ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte)); 810 ptr + P2SZ(size), 811 PTE_GET_FRAME(pte)); 795 812 } 796 813 797 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));814 page_mapping_remove(as, ptr + P2SZ(size)); 798 815 } 799 816 } … … 807 824 808 825 /* 809 * Invalidate potential software translation caches (e.g. TSB on810 * sparc64).826 * Invalidate potential software translation caches 827 * (e.g. TSB on sparc64, PHT on ppc32). 811 828 */ 812 829 as_invalidate_translation_cache(as, area->base, area->pages); … … 882 899 } 883 900 884 size_t src_size = src_area->pages << PAGE_WIDTH;901 size_t src_size = P2SZ(src_area->pages); 885 902 unsigned int src_flags = src_area->flags; 886 903 mem_backend_t *src_backend = src_area->backend; … … 1079 1096 for (cur = area->used_space.leaf_head.next; 1080 1097 cur != &area->used_space.leaf_head; cur = cur->next) { 1081 btree_node_t *node 1082 = list_get_instance(cur, btree_node_t,leaf_link);1098 btree_node_t *node = list_get_instance(cur, btree_node_t, 1099 leaf_link); 1083 1100 btree_key_t i; 1084 1101 … … 1088 1105 1089 1106 for (size = 0; size < (size_t) node->value[i]; size++) { 1090 pte_t *pte = 1091 p age_mapping_find(as, ptr + (size << PAGE_WIDTH));1107 pte_t *pte = page_mapping_find(as, 1108 ptr + P2SZ(size), false); 1092 1109 1093 1110 ASSERT(pte); … … 1098 1115 1099 1116 /* Remove old mapping */ 1100 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));1117 page_mapping_remove(as, ptr + P2SZ(size)); 1101 1118 } 1102 1119 } … … 1110 1127 1111 1128 /* 1112 * Invalidate potential software translation caches (e.g. TSB on1113 * sparc64).1129 * Invalidate potential software translation caches 1130 * (e.g. TSB on sparc64, PHT on ppc32). 1114 1131 */ 1115 1132 as_invalidate_translation_cache(as, area->base, area->pages); … … 1144 1161 1145 1162 /* Insert the new mapping */ 1146 page_mapping_insert(as, ptr + (size << PAGE_WIDTH),1163 page_mapping_insert(as, ptr + P2SZ(size), 1147 1164 old_frame[frame_idx++], page_flags); 1148 1165 … … 1225 1242 */ 1226 1243 pte_t *pte; 1227 if ((pte = page_mapping_find(AS, page ))) {1244 if ((pte = page_mapping_find(AS, page, false))) { 1228 1245 if (PTE_PRESENT(pte)) { 1229 1246 if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) || … … 1466 1483 1467 1484 if (src_area) { 1468 size = src_area->pages << PAGE_WIDTH;1485 size = P2SZ(src_area->pages); 1469 1486 mutex_unlock(&src_area->lock); 1470 1487 } else … … 1521 1538 if (page >= right_pg) { 1522 1539 /* Do nothing. */ 1523 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,1524 left_cnt << PAGE_WIDTH)) {1540 } else if (overlaps(page, P2SZ(count), left_pg, 1541 P2SZ(left_cnt))) { 1525 1542 /* The interval intersects with the left interval. */ 1526 1543 return false; 1527 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1528 right_cnt << PAGE_WIDTH)) {1544 } else if (overlaps(page, P2SZ(count), right_pg, 1545 P2SZ(right_cnt))) { 1529 1546 /* The interval intersects with the right interval. */ 1530 1547 return false; 1531 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1532 (page + (count << PAGE_WIDTH) == right_pg)) {1548 } else if ((page == left_pg + P2SZ(left_cnt)) && 1549 (page + P2SZ(count) == right_pg)) { 1533 1550 /* 1534 1551 * The interval can be added by merging the two already … … 1538 1555 btree_remove(&area->used_space, right_pg, leaf); 1539 1556 goto success; 1540 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1557 } else if (page == left_pg + P2SZ(left_cnt)) { 1541 1558 /* 1542 1559 * The interval can be added by simply growing the left … … 1545 1562 node->value[node->keys - 1] += count; 1546 1563 goto success; 1547 } else if (page + (count << PAGE_WIDTH) == right_pg) {1564 } else if (page + P2SZ(count) == right_pg) { 1548 1565 /* 1549 1566 * The interval can be addded by simply moving base of … … 1572 1589 */ 1573 1590 1574 if (overlaps(page, count << PAGE_WIDTH, right_pg, 1575 right_cnt << PAGE_WIDTH)) { 1591 if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) { 1576 1592 /* The interval intersects with the right interval. */ 1577 1593 return false; 1578 } else if (page + (count << PAGE_WIDTH) == right_pg) {1594 } else if (page + P2SZ(count) == right_pg) { 1579 1595 /* 1580 1596 * The interval can be added by moving the base of the … … 1611 1627 if (page < left_pg) { 1612 1628 /* Do nothing. */ 1613 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,1614 left_cnt << PAGE_WIDTH)) {1629 } else if (overlaps(page, P2SZ(count), left_pg, 1630 P2SZ(left_cnt))) { 1615 1631 /* The interval intersects with the left interval. */ 1616 1632 return false; 1617 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1618 right_cnt << PAGE_WIDTH)) {1633 } else if (overlaps(page, P2SZ(count), right_pg, 1634 P2SZ(right_cnt))) { 1619 1635 /* The interval intersects with the right interval. */ 1620 1636 return false; 1621 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1622 (page + (count << PAGE_WIDTH) == right_pg)) {1637 } else if ((page == left_pg + P2SZ(left_cnt)) && 1638 (page + P2SZ(count) == right_pg)) { 1623 1639 /* 1624 1640 * The interval can be added by merging the two already … … 1628 1644 btree_remove(&area->used_space, right_pg, node); 1629 1645 goto success; 1630 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1646 } else if (page == left_pg + P2SZ(left_cnt)) { 1631 1647 /* 1632 1648 * The interval can be added by simply growing the left … … 1635 1651 leaf->value[leaf->keys - 1] += count; 1636 1652 goto success; 1637 } else if (page + (count << PAGE_WIDTH) == right_pg) {1653 } else if (page + P2SZ(count) == right_pg) { 1638 1654 /* 1639 1655 * The interval can be addded by simply moving base of … … 1662 1678 */ 1663 1679 1664 if (overlaps(page, count << PAGE_WIDTH, left_pg, 1665 left_cnt << PAGE_WIDTH)) { 1680 if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) { 1666 1681 /* The interval intersects with the left interval. */ 1667 1682 return false; 1668 } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {1683 } else if (left_pg + P2SZ(left_cnt) == page) { 1669 1684 /* 1670 1685 * The interval can be added by growing the left … … 1701 1716 */ 1702 1717 1703 if (overlaps(page, count << PAGE_WIDTH, left_pg,1704 left_cnt << PAGE_WIDTH)) {1718 if (overlaps(page, P2SZ(count), left_pg, 1719 P2SZ(left_cnt))) { 1705 1720 /* 1706 1721 * The interval intersects with the left … … 1708 1723 */ 1709 1724 return false; 1710 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,1711 right_cnt << PAGE_WIDTH)) {1725 } else if (overlaps(page, P2SZ(count), right_pg, 1726 P2SZ(right_cnt))) { 1712 1727 /* 1713 1728 * The interval intersects with the right … … 1715 1730 */ 1716 1731 return false; 1717 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&1718 (page + (count << PAGE_WIDTH) == right_pg)) {1732 } else if ((page == left_pg + P2SZ(left_cnt)) && 1733 (page + P2SZ(count) == right_pg)) { 1719 1734 /* 1720 1735 * The interval can be added by merging the two … … 1724 1739 btree_remove(&area->used_space, right_pg, leaf); 1725 1740 goto success; 1726 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {1741 } else if (page == left_pg + P2SZ(left_cnt)) { 1727 1742 /* 1728 1743 * The interval can be added by simply growing … … 1731 1746 leaf->value[i - 1] += count; 1732 1747 goto success; 1733 } else if (page + (count << PAGE_WIDTH) == right_pg) {1748 } else if (page + P2SZ(count) == right_pg) { 1734 1749 /* 1735 1750 * The interval can be addded by simply moving … … 1797 1812 for (i = 0; i < leaf->keys; i++) { 1798 1813 if (leaf->key[i] == page) { 1799 leaf->key[i] += count << PAGE_WIDTH;1814 leaf->key[i] += P2SZ(count); 1800 1815 leaf->value[i] -= count; 1801 1816 goto success; … … 1807 1822 } 1808 1823 1809 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); 1810 1826 if ((node) && (page < leaf->key[0])) { 1811 1827 uintptr_t left_pg = node->key[node->keys - 1]; 1812 1828 size_t left_cnt = (size_t) node->value[node->keys - 1]; 1813 1829 1814 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page, 1815 count << PAGE_WIDTH)) { 1816 if (page + (count << PAGE_WIDTH) == 1817 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)) { 1818 1832 /* 1819 1833 * The interval is contained in the rightmost … … 1824 1838 node->value[node->keys - 1] -= count; 1825 1839 goto success; 1826 } else if (page + (count << PAGE_WIDTH) < 1827 left_pg + (left_cnt << PAGE_WIDTH)) { 1840 } else if (page + P2SZ(count) < 1841 left_pg + P2SZ(left_cnt)) { 1842 size_t new_cnt; 1843 1828 1844 /* 1829 1845 * The interval is contained in the rightmost … … 1833 1849 * new interval. 1834 1850 */ 1835 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -1836 (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;1851 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1852 (page + P2SZ(count))) >> PAGE_WIDTH; 1837 1853 node->value[node->keys - 1] -= count + new_cnt; 1838 1854 btree_insert(&area->used_space, page + 1839 (count << PAGE_WIDTH), (void *) new_cnt, leaf);1855 P2SZ(count), (void *) new_cnt, leaf); 1840 1856 goto success; 1841 1857 } … … 1850 1866 size_t left_cnt = (size_t) leaf->value[leaf->keys - 1]; 1851 1867 1852 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page, 1853 count << PAGE_WIDTH)) { 1854 if (page + (count << PAGE_WIDTH) == 1855 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)) { 1856 1870 /* 1857 1871 * The interval is contained in the rightmost … … 1861 1875 leaf->value[leaf->keys - 1] -= count; 1862 1876 goto success; 1863 } else if (page + (count << PAGE_WIDTH) < left_pg + 1864 (left_cnt << PAGE_WIDTH)) { 1877 } else if (page + P2SZ(count) < left_pg + 1878 P2SZ(left_cnt)) { 1879 size_t new_cnt; 1880 1865 1881 /* 1866 1882 * The interval is contained in the rightmost … … 1870 1886 * interval. 1871 1887 */ 1872 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -1873 (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;1888 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1889 (page + P2SZ(count))) >> PAGE_WIDTH; 1874 1890 leaf->value[leaf->keys - 1] -= count + new_cnt; 1875 1891 btree_insert(&area->used_space, page + 1876 (count << PAGE_WIDTH), (void *) new_cnt, leaf);1892 P2SZ(count), (void *) new_cnt, leaf); 1877 1893 goto success; 1878 1894 } … … 1896 1912 * to (i - 1) and i. 1897 1913 */ 1898 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,1899 count << PAGE_WIDTH)) {1900 if (page + (count << PAGE_WIDTH) ==1901 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)) { 1902 1918 /* 1903 1919 * The interval is contained in the … … 1908 1924 leaf->value[i - 1] -= count; 1909 1925 goto success; 1910 } else if (page + (count << PAGE_WIDTH) < 1911 left_pg + (left_cnt << PAGE_WIDTH)) { 1926 } else if (page + P2SZ(count) < 1927 left_pg + P2SZ(left_cnt)) { 1928 size_t new_cnt; 1929 1912 1930 /* 1913 1931 * The interval is contained in the … … 1917 1935 * also inserting a new interval. 1918 1936 */ 1919 size_t new_cnt = ((left_pg + 1920 (left_cnt << PAGE_WIDTH)) - 1921 (page + (count << PAGE_WIDTH))) >> 1937 new_cnt = ((left_pg + P2SZ(left_cnt)) - 1938 (page + P2SZ(count))) >> 1922 1939 PAGE_WIDTH; 1923 1940 leaf->value[i - 1] -= count + new_cnt; 1924 1941 btree_insert(&area->used_space, page + 1925 (count << PAGE_WIDTH), (void *) new_cnt,1942 P2SZ(count), (void *) new_cnt, 1926 1943 leaf); 1927 1944 goto success; … … 2019 2036 btree_key_t i; 2020 2037 for (i = 0; (ret == 0) && (i < node->keys); i++) { 2038 uintptr_t addr; 2039 2021 2040 as_area_t *area = (as_area_t *) node->value[i]; 2022 2041 2023 2042 mutex_lock(&area->lock); 2024 2043 2025 uintptr_t addr = 2026 ALIGN_UP(area->base + (area->pages << PAGE_WIDTH), 2044 addr = ALIGN_UP(area->base + P2SZ(area->pages), 2027 2045 PAGE_SIZE); 2028 2046 … … 2083 2101 2084 2102 info[area_idx].start_addr = area->base; 2085 info[area_idx].size = FRAMES2SIZE(area->pages);2103 info[area_idx].size = P2SZ(area->pages); 2086 2104 info[area_idx].flags = area->flags; 2087 2105 ++area_idx; … … 2121 2139 " (%p - %p)\n", area, (void *) area->base, 2122 2140 area->pages, (void *) area->base, 2123 (void *) (area->base + FRAMES2SIZE(area->pages)));2141 (void *) (area->base + P2SZ(area->pages))); 2124 2142 mutex_unlock(&area->lock); 2125 2143 }
Note:
See TracChangeset
for help on using the changeset viewer.