diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-04-06 16:10:20 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-05-07 15:31:47 -0400 |
commit | 96dc08b35c4af8cb5810450602590706f2593a5f (patch) | |
tree | 3619f83ebce8919fb61d1c8dcc1f9def570936ab /arch/x86/xen/setup.c | |
parent | 2e2fb75475c2fc74c98100f1468c8195fee49f3b (diff) |
xen/setup: Combine the two hypercall functions - since they are quite similar.
They use the same set of arguments, so it is just the matter
of using the proper hypercall.
Acked-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'arch/x86/xen/setup.c')
-rw-r--r-- | arch/x86/xen/setup.c | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 710af36e6dfb..30ac05a8d28f 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c | |||
@@ -83,8 +83,8 @@ static void __init xen_add_extra_mem(u64 start, u64 size) | |||
83 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); | 83 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
84 | } | 84 | } |
85 | 85 | ||
86 | static unsigned long __init xen_release_chunk(unsigned long start, | 86 | static unsigned long __init xen_do_chunk(unsigned long start, |
87 | unsigned long end) | 87 | unsigned long end, bool release) |
88 | { | 88 | { |
89 | struct xen_memory_reservation reservation = { | 89 | struct xen_memory_reservation reservation = { |
90 | .address_bits = 0, | 90 | .address_bits = 0, |
@@ -95,60 +95,36 @@ static unsigned long __init xen_release_chunk(unsigned long start, | |||
95 | unsigned long pfn; | 95 | unsigned long pfn; |
96 | int ret; | 96 | int ret; |
97 | 97 | ||
98 | for(pfn = start; pfn < end; pfn++) { | ||
99 | unsigned long mfn = pfn_to_mfn(pfn); | ||
100 | |||
101 | /* Make sure pfn exists to start with */ | ||
102 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) | ||
103 | continue; | ||
104 | |||
105 | set_xen_guest_handle(reservation.extent_start, &mfn); | ||
106 | reservation.nr_extents = 1; | ||
107 | |||
108 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, | ||
109 | &reservation); | ||
110 | WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret); | ||
111 | if (ret == 1) { | ||
112 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); | ||
113 | len++; | ||
114 | } | ||
115 | } | ||
116 | if (len) | ||
117 | printk(KERN_INFO "Freeing %lx-%lx pfn range: %lu pages freed\n", | ||
118 | start, end, len); | ||
119 | |||
120 | return len; | ||
121 | } | ||
122 | static unsigned long __init xen_populate_physmap(unsigned long start, | ||
123 | unsigned long end) | ||
124 | { | ||
125 | struct xen_memory_reservation reservation = { | ||
126 | .address_bits = 0, | ||
127 | .extent_order = 0, | ||
128 | .domid = DOMID_SELF | ||
129 | }; | ||
130 | unsigned long len = 0; | ||
131 | int ret; | ||
132 | |||
133 | for (pfn = start; pfn < end; pfn++) { | 98 | for (pfn = start; pfn < end; pfn++) { |
134 | unsigned long frame; | 99 | unsigned long frame; |
100 | unsigned long mfn = pfn_to_mfn(pfn); | ||
135 | 101 | ||
136 | /* Make sure pfn does not exists to start with */ | 102 | if (release) { |
137 | if (pfn_to_mfn(pfn) != INVALID_P2M_ENTRY) | 103 | /* Make sure pfn exists to start with */ |
138 | continue; | 104 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) |
139 | 105 | continue; | |
140 | frame = pfn; | 106 | frame = mfn; |
107 | } else { | ||
108 | if (mfn != INVALID_P2M_ENTRY) | ||
109 | continue; | ||
110 | frame = pfn; | ||
111 | } | ||
141 | set_xen_guest_handle(reservation.extent_start, &frame); | 112 | set_xen_guest_handle(reservation.extent_start, &frame); |
142 | reservation.nr_extents = 1; | 113 | reservation.nr_extents = 1; |
143 | 114 | ||
144 | ret = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation); | 115 | ret = HYPERVISOR_memory_op(release ? XENMEM_decrease_reservation : XENMEM_populate_physmap, |
145 | WARN(ret != 1, "Failed to populate pfn %lx err=%d\n", pfn, ret); | 116 | &reservation); |
117 | WARN(ret != 1, "Failed to %s pfn %lx err=%d\n", | ||
118 | release ? "release" : "populate", pfn, ret); | ||
119 | |||
146 | if (ret == 1) { | 120 | if (ret == 1) { |
147 | if (!early_set_phys_to_machine(pfn, frame)) { | 121 | if (!early_set_phys_to_machine(pfn, release ? INVALID_P2M_ENTRY : frame)) { |
122 | if (release) | ||
123 | break; | ||
148 | set_xen_guest_handle(reservation.extent_start, &frame); | 124 | set_xen_guest_handle(reservation.extent_start, &frame); |
149 | reservation.nr_extents = 1; | 125 | reservation.nr_extents = 1; |
150 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, | 126 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, |
151 | &reservation); | 127 | &reservation); |
152 | break; | 128 | break; |
153 | } | 129 | } |
154 | len++; | 130 | len++; |
@@ -156,8 +132,11 @@ static unsigned long __init xen_populate_physmap(unsigned long start, | |||
156 | break; | 132 | break; |
157 | } | 133 | } |
158 | if (len) | 134 | if (len) |
159 | printk(KERN_INFO "Populated %lx-%lx pfn range: %lu pages added\n", | 135 | printk(KERN_INFO "%s %lx-%lx pfn range: %lu pages %s\n", |
160 | start, end, len); | 136 | release ? "Freeing" : "Populating", |
137 | start, end, len, | ||
138 | release ? "freed" : "added"); | ||
139 | |||
161 | return len; | 140 | return len; |
162 | } | 141 | } |
163 | static unsigned long __init xen_populate_chunk( | 142 | static unsigned long __init xen_populate_chunk( |
@@ -211,7 +190,7 @@ static unsigned long __init xen_populate_chunk( | |||
211 | if (credits > capacity) | 190 | if (credits > capacity) |
212 | credits = capacity; | 191 | credits = capacity; |
213 | 192 | ||
214 | pfns = xen_populate_physmap(dest_pfn, dest_pfn + credits); | 193 | pfns = xen_do_chunk(dest_pfn, dest_pfn + credits, false); |
215 | done += pfns; | 194 | done += pfns; |
216 | credits_left -= pfns; | 195 | credits_left -= pfns; |
217 | *last_pfn = (dest_pfn + pfns); | 196 | *last_pfn = (dest_pfn + pfns); |
@@ -249,8 +228,8 @@ static unsigned long __init xen_set_identity_and_release( | |||
249 | 228 | ||
250 | if (start_pfn < end_pfn) { | 229 | if (start_pfn < end_pfn) { |
251 | if (start_pfn < nr_pages) | 230 | if (start_pfn < nr_pages) |
252 | released += xen_release_chunk( | 231 | released += xen_do_chunk( |
253 | start_pfn, min(end_pfn, nr_pages)); | 232 | start_pfn, min(end_pfn, nr_pages), true); |
254 | 233 | ||
255 | identity += set_phys_range_identity( | 234 | identity += set_phys_range_identity( |
256 | start_pfn, end_pfn); | 235 | start_pfn, end_pfn); |