/root/src/xen/xen/common/pdx.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * Original code extracted from arch/x86/x86_64/mm.c |
3 | | * |
4 | | * This program is free software; you can redistribute it and/or modify |
5 | | * it under the terms of the GNU General Public License as published by |
6 | | * the Free Software Foundation; either version 2 of the License, or |
7 | | * (at your option) any later version. |
8 | | * |
9 | | * This program is distributed in the hope that it will be useful, |
10 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | * GNU General Public License for more details. |
13 | | * |
14 | | * You should have received a copy of the GNU General Public License |
15 | | * along with this program; If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | |
18 | | #include <xen/init.h> |
19 | | #include <xen/mm.h> |
20 | | #include <xen/bitops.h> |
21 | | |
22 | | /* Parameters for PFN/MADDR compression. */ |
23 | | unsigned long __read_mostly max_pdx; |
24 | | unsigned long __read_mostly pfn_pdx_bottom_mask = ~0UL; |
25 | | unsigned long __read_mostly ma_va_bottom_mask = ~0UL; |
26 | | unsigned long __read_mostly pfn_top_mask = 0; |
27 | | unsigned long __read_mostly ma_top_mask = 0; |
28 | | unsigned long __read_mostly pfn_hole_mask = 0; |
29 | | unsigned int __read_mostly pfn_pdx_hole_shift = 0; |
30 | | |
31 | | unsigned long __read_mostly pdx_group_valid[BITS_TO_LONGS( |
32 | | (FRAMETABLE_NR + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT)] = { [0] = 1 }; |
33 | | |
34 | | bool __mfn_valid(unsigned long mfn) |
35 | 15.3M | { |
36 | 15.3M | return likely(mfn < max_page) && |
37 | 15.1M | likely(!(mfn & pfn_hole_mask)) && |
38 | 15.1M | likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, |
39 | 15.3M | pdx_group_valid)); |
40 | 15.3M | } |
41 | | |
42 | | /* Sets all bits from the most-significant 1-bit down to the LSB */ |
43 | | static u64 __init fill_mask(u64 mask) |
44 | 0 | { |
45 | 0 | while (mask & (mask + 1)) |
46 | 0 | mask |= mask + 1; |
47 | 0 | return mask; |
48 | 0 | } |
49 | | |
50 | | u64 __init pdx_init_mask(u64 base_addr) |
51 | 0 | { |
52 | 0 | return fill_mask(base_addr - 1); |
53 | 0 | } |
54 | | |
55 | | u64 __init pdx_region_mask(u64 base, u64 len) |
56 | 0 | { |
57 | 0 | return fill_mask(base ^ (base + len - 1)); |
58 | 0 | } |
59 | | |
60 | | void set_pdx_range(unsigned long smfn, unsigned long emfn) |
61 | 16 | { |
62 | 16 | unsigned long idx, eidx; |
63 | 16 | |
64 | 16 | idx = pfn_to_pdx(smfn) / PDX_GROUP_COUNT; |
65 | 16 | eidx = (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT; |
66 | 16 | |
67 | 102 | for ( ; idx < eidx; ++idx ) |
68 | 86 | __set_bit(idx, pdx_group_valid); |
69 | 16 | } |
70 | | |
71 | | void __init pfn_pdx_hole_setup(unsigned long mask) |
72 | 0 | { |
73 | 0 | unsigned int i, j, bottom_shift = 0, hole_shift = 0; |
74 | 0 |
|
75 | 0 | /* |
76 | 0 | * We skip the first MAX_ORDER bits, as we never want to compress them. |
77 | 0 | * This guarantees that page-pointer arithmetic remains valid within |
78 | 0 | * contiguous aligned ranges of 2^MAX_ORDER pages. Among others, our |
79 | 0 | * buddy allocator relies on this assumption. |
80 | 0 | */ |
81 | 0 | for ( j = MAX_ORDER-1; ; ) |
82 | 0 | { |
83 | 0 | i = find_next_zero_bit(&mask, BITS_PER_LONG, j); |
84 | 0 | j = find_next_bit(&mask, BITS_PER_LONG, i); |
85 | 0 | if ( j >= BITS_PER_LONG ) |
86 | 0 | break; |
87 | 0 | if ( j - i > hole_shift ) |
88 | 0 | { |
89 | 0 | hole_shift = j - i; |
90 | 0 | bottom_shift = i; |
91 | 0 | } |
92 | 0 | } |
93 | 0 | if ( !hole_shift ) |
94 | 0 | return; |
95 | 0 |
|
96 | 0 | printk(KERN_INFO "PFN compression on bits %u...%u\n", |
97 | 0 | bottom_shift, bottom_shift + hole_shift - 1); |
98 | 0 |
|
99 | 0 | pfn_pdx_hole_shift = hole_shift; |
100 | 0 | pfn_pdx_bottom_mask = (1UL << bottom_shift) - 1; |
101 | 0 | ma_va_bottom_mask = (PAGE_SIZE << bottom_shift) - 1; |
102 | 0 | pfn_hole_mask = ((1UL << hole_shift) - 1) << bottom_shift; |
103 | 0 | pfn_top_mask = ~(pfn_pdx_bottom_mask | pfn_hole_mask); |
104 | 0 | ma_top_mask = pfn_top_mask << PAGE_SHIFT; |
105 | 0 | } |
106 | | |
107 | | |
108 | | /* |
109 | | * Local variables: |
110 | | * mode: C |
111 | | * c-file-style: "BSD" |
112 | | * c-basic-offset: 4 |
113 | | * indent-tabs-mode: nil |
114 | | * End: |
115 | | */ |