1 /*
2  * pSeries_lpar.c
3  * Copyright (C) 2001 Todd Inglett, IBM Corporation
4  *
5  * pSeries LPAR support.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  */
21 
22 /* Enables debugging of low-level hash table routines - careful! */
23 #undef DEBUG
24 
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/console.h>
28 #include <linux/export.h>
29 #include <asm/processor.h>
30 #include <asm/mmu.h>
31 #include <asm/page.h>
32 #include <asm/pgtable.h>
33 #include <asm/machdep.h>
34 #include <asm/abs_addr.h>
35 #include <asm/mmu_context.h>
36 #include <asm/iommu.h>
37 #include <asm/tlbflush.h>
38 #include <asm/tlb.h>
39 #include <asm/prom.h>
40 #include <asm/cputable.h>
41 #include <asm/udbg.h>
42 #include <asm/smp.h>
43 #include <asm/trace.h>
44 #include <asm/firmware.h>
45 
46 #include "plpar_wrappers.h"
47 #include "pseries.h"
48 
49 
50 /* in hvCall.S */
51 EXPORT_SYMBOL(plpar_hcall);
52 EXPORT_SYMBOL(plpar_hcall9);
53 EXPORT_SYMBOL(plpar_hcall_norets);
54 
55 extern void pSeries_find_serial_port(void);
56 
vpa_init(int cpu)57 void vpa_init(int cpu)
58 {
59 	int hwcpu = get_hard_smp_processor_id(cpu);
60 	unsigned long addr;
61 	long ret;
62 	struct paca_struct *pp;
63 	struct dtl_entry *dtl;
64 
65 	if (cpu_has_feature(CPU_FTR_ALTIVEC))
66 		lppaca_of(cpu).vmxregs_in_use = 1;
67 
68 	addr = __pa(&lppaca_of(cpu));
69 	ret = register_vpa(hwcpu, addr);
70 
71 	if (ret) {
72 		pr_err("WARNING: VPA registration for cpu %d (hw %d) of area "
73 		       "%lx failed with %ld\n", cpu, hwcpu, addr, ret);
74 		return;
75 	}
76 	/*
77 	 * PAPR says this feature is SLB-Buffer but firmware never
78 	 * reports that.  All SPLPAR support SLB shadow buffer.
79 	 */
80 	addr = __pa(&slb_shadow[cpu]);
81 	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
82 		ret = register_slb_shadow(hwcpu, addr);
83 		if (ret)
84 			pr_err("WARNING: SLB shadow buffer registration for "
85 			       "cpu %d (hw %d) of area %lx failed with %ld\n",
86 			       cpu, hwcpu, addr, ret);
87 	}
88 
89 	/*
90 	 * Register dispatch trace log, if one has been allocated.
91 	 */
92 	pp = &paca[cpu];
93 	dtl = pp->dispatch_log;
94 	if (dtl) {
95 		pp->dtl_ridx = 0;
96 		pp->dtl_curr = dtl;
97 		lppaca_of(cpu).dtl_idx = 0;
98 
99 		/* hypervisor reads buffer length from this field */
100 		dtl->enqueue_to_dispatch_time = DISPATCH_LOG_BYTES;
101 		ret = register_dtl(hwcpu, __pa(dtl));
102 		if (ret)
103 			pr_err("WARNING: DTL registration of cpu %d (hw %d) "
104 			       "failed with %ld\n", smp_processor_id(),
105 			       hwcpu, ret);
106 		lppaca_of(cpu).dtl_enable_mask = 2;
107 	}
108 }
109 
pSeries_lpar_hpte_insert(unsigned long hpte_group,unsigned long va,unsigned long pa,unsigned long rflags,unsigned long vflags,int psize,int ssize)110 static long pSeries_lpar_hpte_insert(unsigned long hpte_group,
111  			      unsigned long va, unsigned long pa,
112  			      unsigned long rflags, unsigned long vflags,
113 			      int psize, int ssize)
114 {
115 	unsigned long lpar_rc;
116 	unsigned long flags;
117 	unsigned long slot;
118 	unsigned long hpte_v, hpte_r;
119 
120 	if (!(vflags & HPTE_V_BOLTED))
121 		pr_devel("hpte_insert(group=%lx, va=%016lx, pa=%016lx, "
122 			 "rflags=%lx, vflags=%lx, psize=%d)\n",
123 			 hpte_group, va, pa, rflags, vflags, psize);
124 
125 	hpte_v = hpte_encode_v(va, psize, ssize) | vflags | HPTE_V_VALID;
126 	hpte_r = hpte_encode_r(pa, psize) | rflags;
127 
128 	if (!(vflags & HPTE_V_BOLTED))
129 		pr_devel(" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);
130 
131 	/* Now fill in the actual HPTE */
132 	/* Set CEC cookie to 0         */
133 	/* Zero page = 0               */
134 	/* I-cache Invalidate = 0      */
135 	/* I-cache synchronize = 0     */
136 	/* Exact = 0                   */
137 	flags = 0;
138 
139 	/* Make pHyp happy */
140 	if ((rflags & _PAGE_NO_CACHE) & !(rflags & _PAGE_WRITETHRU))
141 		hpte_r &= ~_PAGE_COHERENT;
142 	if (firmware_has_feature(FW_FEATURE_XCMO) && !(hpte_r & HPTE_R_N))
143 		flags |= H_COALESCE_CAND;
144 
145 	lpar_rc = plpar_pte_enter(flags, hpte_group, hpte_v, hpte_r, &slot);
146 	if (unlikely(lpar_rc == H_PTEG_FULL)) {
147 		if (!(vflags & HPTE_V_BOLTED))
148 			pr_devel(" full\n");
149 		return -1;
150 	}
151 
152 	/*
153 	 * Since we try and ioremap PHBs we don't own, the pte insert
154 	 * will fail. However we must catch the failure in hash_page
155 	 * or we will loop forever, so return -2 in this case.
156 	 */
157 	if (unlikely(lpar_rc != H_SUCCESS)) {
158 		if (!(vflags & HPTE_V_BOLTED))
159 			pr_devel(" lpar err %lu\n", lpar_rc);
160 		return -2;
161 	}
162 	if (!(vflags & HPTE_V_BOLTED))
163 		pr_devel(" -> slot: %lu\n", slot & 7);
164 
165 	/* Because of iSeries, we have to pass down the secondary
166 	 * bucket bit here as well
167 	 */
168 	return (slot & 7) | (!!(vflags & HPTE_V_SECONDARY) << 3);
169 }
170 
171 static DEFINE_SPINLOCK(pSeries_lpar_tlbie_lock);
172 
pSeries_lpar_hpte_remove(unsigned long hpte_group)173 static long pSeries_lpar_hpte_remove(unsigned long hpte_group)
174 {
175 	unsigned long slot_offset;
176 	unsigned long lpar_rc;
177 	int i;
178 	unsigned long dummy1, dummy2;
179 
180 	/* pick a random slot to start at */
181 	slot_offset = mftb() & 0x7;
182 
183 	for (i = 0; i < HPTES_PER_GROUP; i++) {
184 
185 		/* don't remove a bolted entry */
186 		lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset,
187 					   (0x1UL << 4), &dummy1, &dummy2);
188 		if (lpar_rc == H_SUCCESS)
189 			return i;
190 
191 		/*
192 		 * The test for adjunct partition is performed before the
193 		 * ANDCOND test.  H_RESOURCE may be returned, so we need to
194 		 * check for that as well.
195 		 */
196 		BUG_ON(lpar_rc != H_NOT_FOUND && lpar_rc != H_RESOURCE);
197 
198 		slot_offset++;
199 		slot_offset &= 0x7;
200 	}
201 
202 	return -1;
203 }
204 
pSeries_lpar_hptab_clear(void)205 static void pSeries_lpar_hptab_clear(void)
206 {
207 	unsigned long size_bytes = 1UL << ppc64_pft_size;
208 	unsigned long hpte_count = size_bytes >> 4;
209 	struct {
210 		unsigned long pteh;
211 		unsigned long ptel;
212 	} ptes[4];
213 	long lpar_rc;
214 	unsigned long i, j;
215 
216 	/* Read in batches of 4,
217 	 * invalidate only valid entries not in the VRMA
218 	 * hpte_count will be a multiple of 4
219          */
220 	for (i = 0; i < hpte_count; i += 4) {
221 		lpar_rc = plpar_pte_read_4_raw(0, i, (void *)ptes);
222 		if (lpar_rc != H_SUCCESS)
223 			continue;
224 		for (j = 0; j < 4; j++){
225 			if ((ptes[j].pteh & HPTE_V_VRMA_MASK) ==
226 				HPTE_V_VRMA_MASK)
227 				continue;
228 			if (ptes[j].pteh & HPTE_V_VALID)
229 				plpar_pte_remove_raw(0, i + j, 0,
230 					&(ptes[j].pteh), &(ptes[j].ptel));
231 		}
232 	}
233 }
234 
235 /*
236  * This computes the AVPN and B fields of the first dword of a HPTE,
237  * for use when we want to match an existing PTE.  The bottom 7 bits
238  * of the returned value are zero.
239  */
hpte_encode_avpn(unsigned long va,int psize,int ssize)240 static inline unsigned long hpte_encode_avpn(unsigned long va, int psize,
241 					     int ssize)
242 {
243 	unsigned long v;
244 
245 	v = (va >> 23) & ~(mmu_psize_defs[psize].avpnm);
246 	v <<= HPTE_V_AVPN_SHIFT;
247 	v |= ((unsigned long) ssize) << HPTE_V_SSIZE_SHIFT;
248 	return v;
249 }
250 
251 /*
252  * NOTE: for updatepp ops we are fortunate that the linux "newpp" bits and
253  * the low 3 bits of flags happen to line up.  So no transform is needed.
254  * We can probably optimize here and assume the high bits of newpp are
255  * already zero.  For now I am paranoid.
256  */
pSeries_lpar_hpte_updatepp(unsigned long slot,unsigned long newpp,unsigned long va,int psize,int ssize,int local)257 static long pSeries_lpar_hpte_updatepp(unsigned long slot,
258 				       unsigned long newpp,
259 				       unsigned long va,
260 				       int psize, int ssize, int local)
261 {
262 	unsigned long lpar_rc;
263 	unsigned long flags = (newpp & 7) | H_AVPN;
264 	unsigned long want_v;
265 
266 	want_v = hpte_encode_avpn(va, psize, ssize);
267 
268 	pr_devel("    update: avpnv=%016lx, hash=%016lx, f=%lx, psize: %d ...",
269 		 want_v, slot, flags, psize);
270 
271 	lpar_rc = plpar_pte_protect(flags, slot, want_v);
272 
273 	if (lpar_rc == H_NOT_FOUND) {
274 		pr_devel("not found !\n");
275 		return -1;
276 	}
277 
278 	pr_devel("ok\n");
279 
280 	BUG_ON(lpar_rc != H_SUCCESS);
281 
282 	return 0;
283 }
284 
pSeries_lpar_hpte_getword0(unsigned long slot)285 static unsigned long pSeries_lpar_hpte_getword0(unsigned long slot)
286 {
287 	unsigned long dword0;
288 	unsigned long lpar_rc;
289 	unsigned long dummy_word1;
290 	unsigned long flags;
291 
292 	/* Read 1 pte at a time                        */
293 	/* Do not need RPN to logical page translation */
294 	/* No cross CEC PFT access                     */
295 	flags = 0;
296 
297 	lpar_rc = plpar_pte_read(flags, slot, &dword0, &dummy_word1);
298 
299 	BUG_ON(lpar_rc != H_SUCCESS);
300 
301 	return dword0;
302 }
303 
pSeries_lpar_hpte_find(unsigned long va,int psize,int ssize)304 static long pSeries_lpar_hpte_find(unsigned long va, int psize, int ssize)
305 {
306 	unsigned long hash;
307 	unsigned long i;
308 	long slot;
309 	unsigned long want_v, hpte_v;
310 
311 	hash = hpt_hash(va, mmu_psize_defs[psize].shift, ssize);
312 	want_v = hpte_encode_avpn(va, psize, ssize);
313 
314 	/* Bolted entries are always in the primary group */
315 	slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
316 	for (i = 0; i < HPTES_PER_GROUP; i++) {
317 		hpte_v = pSeries_lpar_hpte_getword0(slot);
318 
319 		if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID))
320 			/* HPTE matches */
321 			return slot;
322 		++slot;
323 	}
324 
325 	return -1;
326 }
327 
pSeries_lpar_hpte_updateboltedpp(unsigned long newpp,unsigned long ea,int psize,int ssize)328 static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp,
329 					     unsigned long ea,
330 					     int psize, int ssize)
331 {
332 	unsigned long lpar_rc, slot, vsid, va, flags;
333 
334 	vsid = get_kernel_vsid(ea, ssize);
335 	va = hpt_va(ea, vsid, ssize);
336 
337 	slot = pSeries_lpar_hpte_find(va, psize, ssize);
338 	BUG_ON(slot == -1);
339 
340 	flags = newpp & 7;
341 	lpar_rc = plpar_pte_protect(flags, slot, 0);
342 
343 	BUG_ON(lpar_rc != H_SUCCESS);
344 }
345 
pSeries_lpar_hpte_invalidate(unsigned long slot,unsigned long va,int psize,int ssize,int local)346 static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long va,
347 					 int psize, int ssize, int local)
348 {
349 	unsigned long want_v;
350 	unsigned long lpar_rc;
351 	unsigned long dummy1, dummy2;
352 
353 	pr_devel("    inval : slot=%lx, va=%016lx, psize: %d, local: %d\n",
354 		 slot, va, psize, local);
355 
356 	want_v = hpte_encode_avpn(va, psize, ssize);
357 	lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v, &dummy1, &dummy2);
358 	if (lpar_rc == H_NOT_FOUND)
359 		return;
360 
361 	BUG_ON(lpar_rc != H_SUCCESS);
362 }
363 
pSeries_lpar_hpte_removebolted(unsigned long ea,int psize,int ssize)364 static void pSeries_lpar_hpte_removebolted(unsigned long ea,
365 					   int psize, int ssize)
366 {
367 	unsigned long slot, vsid, va;
368 
369 	vsid = get_kernel_vsid(ea, ssize);
370 	va = hpt_va(ea, vsid, ssize);
371 
372 	slot = pSeries_lpar_hpte_find(va, psize, ssize);
373 	BUG_ON(slot == -1);
374 
375 	pSeries_lpar_hpte_invalidate(slot, va, psize, ssize, 0);
376 }
377 
378 /* Flag bits for H_BULK_REMOVE */
379 #define HBR_REQUEST	0x4000000000000000UL
380 #define HBR_RESPONSE	0x8000000000000000UL
381 #define HBR_END		0xc000000000000000UL
382 #define HBR_AVPN	0x0200000000000000UL
383 #define HBR_ANDCOND	0x0100000000000000UL
384 
385 /*
386  * Take a spinlock around flushes to avoid bouncing the hypervisor tlbie
387  * lock.
388  */
pSeries_lpar_flush_hash_range(unsigned long number,int local)389 static void pSeries_lpar_flush_hash_range(unsigned long number, int local)
390 {
391 	unsigned long i, pix, rc;
392 	unsigned long flags = 0;
393 	struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
394 	int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
395 	unsigned long param[9];
396 	unsigned long va;
397 	unsigned long hash, index, shift, hidx, slot;
398 	real_pte_t pte;
399 	int psize, ssize;
400 
401 	if (lock_tlbie)
402 		spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags);
403 
404 	psize = batch->psize;
405 	ssize = batch->ssize;
406 	pix = 0;
407 	for (i = 0; i < number; i++) {
408 		va = batch->vaddr[i];
409 		pte = batch->pte[i];
410 		pte_iterate_hashed_subpages(pte, psize, va, index, shift) {
411 			hash = hpt_hash(va, shift, ssize);
412 			hidx = __rpte_to_hidx(pte, index);
413 			if (hidx & _PTEIDX_SECONDARY)
414 				hash = ~hash;
415 			slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
416 			slot += hidx & _PTEIDX_GROUP_IX;
417 			if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {
418 				pSeries_lpar_hpte_invalidate(slot, va, psize,
419 							     ssize, local);
420 			} else {
421 				param[pix] = HBR_REQUEST | HBR_AVPN | slot;
422 				param[pix+1] = hpte_encode_avpn(va, psize,
423 								ssize);
424 				pix += 2;
425 				if (pix == 8) {
426 					rc = plpar_hcall9(H_BULK_REMOVE, param,
427 						param[0], param[1], param[2],
428 						param[3], param[4], param[5],
429 						param[6], param[7]);
430 					BUG_ON(rc != H_SUCCESS);
431 					pix = 0;
432 				}
433 			}
434 		} pte_iterate_hashed_end();
435 	}
436 	if (pix) {
437 		param[pix] = HBR_END;
438 		rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1],
439 				  param[2], param[3], param[4], param[5],
440 				  param[6], param[7]);
441 		BUG_ON(rc != H_SUCCESS);
442 	}
443 
444 	if (lock_tlbie)
445 		spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags);
446 }
447 
disable_bulk_remove(char * str)448 static int __init disable_bulk_remove(char *str)
449 {
450 	if (strcmp(str, "off") == 0 &&
451 	    firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {
452 			printk(KERN_INFO "Disabling BULK_REMOVE firmware feature");
453 			powerpc_firmware_features &= ~FW_FEATURE_BULK_REMOVE;
454 	}
455 	return 1;
456 }
457 
458 __setup("bulk_remove=", disable_bulk_remove);
459 
hpte_init_lpar(void)460 void __init hpte_init_lpar(void)
461 {
462 	ppc_md.hpte_invalidate	= pSeries_lpar_hpte_invalidate;
463 	ppc_md.hpte_updatepp	= pSeries_lpar_hpte_updatepp;
464 	ppc_md.hpte_updateboltedpp = pSeries_lpar_hpte_updateboltedpp;
465 	ppc_md.hpte_insert	= pSeries_lpar_hpte_insert;
466 	ppc_md.hpte_remove	= pSeries_lpar_hpte_remove;
467 	ppc_md.hpte_removebolted = pSeries_lpar_hpte_removebolted;
468 	ppc_md.flush_hash_range	= pSeries_lpar_flush_hash_range;
469 	ppc_md.hpte_clear_all   = pSeries_lpar_hptab_clear;
470 }
471 
472 #ifdef CONFIG_PPC_SMLPAR
473 #define CMO_FREE_HINT_DEFAULT 1
474 static int cmo_free_hint_flag = CMO_FREE_HINT_DEFAULT;
475 
cmo_free_hint(char * str)476 static int __init cmo_free_hint(char *str)
477 {
478 	char *parm;
479 	parm = strstrip(str);
480 
481 	if (strcasecmp(parm, "no") == 0 || strcasecmp(parm, "off") == 0) {
482 		printk(KERN_INFO "cmo_free_hint: CMO free page hinting is not active.\n");
483 		cmo_free_hint_flag = 0;
484 		return 1;
485 	}
486 
487 	cmo_free_hint_flag = 1;
488 	printk(KERN_INFO "cmo_free_hint: CMO free page hinting is active.\n");
489 
490 	if (strcasecmp(parm, "yes") == 0 || strcasecmp(parm, "on") == 0)
491 		return 1;
492 
493 	return 0;
494 }
495 
496 __setup("cmo_free_hint=", cmo_free_hint);
497 
pSeries_set_page_state(struct page * page,int order,unsigned long state)498 static void pSeries_set_page_state(struct page *page, int order,
499 				   unsigned long state)
500 {
501 	int i, j;
502 	unsigned long cmo_page_sz, addr;
503 
504 	cmo_page_sz = cmo_get_page_size();
505 	addr = __pa((unsigned long)page_address(page));
506 
507 	for (i = 0; i < (1 << order); i++, addr += PAGE_SIZE) {
508 		for (j = 0; j < PAGE_SIZE; j += cmo_page_sz)
509 			plpar_hcall_norets(H_PAGE_INIT, state, addr + j, 0);
510 	}
511 }
512 
arch_free_page(struct page * page,int order)513 void arch_free_page(struct page *page, int order)
514 {
515 	if (!cmo_free_hint_flag || !firmware_has_feature(FW_FEATURE_CMO))
516 		return;
517 
518 	pSeries_set_page_state(page, order, H_PAGE_SET_UNUSED);
519 }
520 EXPORT_SYMBOL(arch_free_page);
521 
522 #endif
523 
524 #ifdef CONFIG_TRACEPOINTS
525 /*
526  * We optimise our hcall path by placing hcall_tracepoint_refcount
527  * directly in the TOC so we can check if the hcall tracepoints are
528  * enabled via a single load.
529  */
530 
531 /* NB: reg/unreg are called while guarded with the tracepoints_mutex */
532 extern long hcall_tracepoint_refcount;
533 
534 /*
535  * Since the tracing code might execute hcalls we need to guard against
536  * recursion. One example of this are spinlocks calling H_YIELD on
537  * shared processor partitions.
538  */
539 static DEFINE_PER_CPU(unsigned int, hcall_trace_depth);
540 
hcall_tracepoint_regfunc(void)541 void hcall_tracepoint_regfunc(void)
542 {
543 	hcall_tracepoint_refcount++;
544 }
545 
hcall_tracepoint_unregfunc(void)546 void hcall_tracepoint_unregfunc(void)
547 {
548 	hcall_tracepoint_refcount--;
549 }
550 
__trace_hcall_entry(unsigned long opcode,unsigned long * args)551 void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
552 {
553 	unsigned long flags;
554 	unsigned int *depth;
555 
556 	/*
557 	 * We cannot call tracepoints inside RCU idle regions which
558 	 * means we must not trace H_CEDE.
559 	 */
560 	if (opcode == H_CEDE)
561 		return;
562 
563 	local_irq_save(flags);
564 
565 	depth = &__get_cpu_var(hcall_trace_depth);
566 
567 	if (*depth)
568 		goto out;
569 
570 	(*depth)++;
571 	preempt_disable();
572 	trace_hcall_entry(opcode, args);
573 	(*depth)--;
574 
575 out:
576 	local_irq_restore(flags);
577 }
578 
__trace_hcall_exit(long opcode,unsigned long retval,unsigned long * retbuf)579 void __trace_hcall_exit(long opcode, unsigned long retval,
580 			unsigned long *retbuf)
581 {
582 	unsigned long flags;
583 	unsigned int *depth;
584 
585 	if (opcode == H_CEDE)
586 		return;
587 
588 	local_irq_save(flags);
589 
590 	depth = &__get_cpu_var(hcall_trace_depth);
591 
592 	if (*depth)
593 		goto out;
594 
595 	(*depth)++;
596 	trace_hcall_exit(opcode, retval, retbuf);
597 	preempt_enable();
598 	(*depth)--;
599 
600 out:
601 	local_irq_restore(flags);
602 }
603 #endif
604 
605 /**
606  * h_get_mpp
607  * H_GET_MPP hcall returns info in 7 parms
608  */
h_get_mpp(struct hvcall_mpp_data * mpp_data)609 int h_get_mpp(struct hvcall_mpp_data *mpp_data)
610 {
611 	int rc;
612 	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
613 
614 	rc = plpar_hcall9(H_GET_MPP, retbuf);
615 
616 	mpp_data->entitled_mem = retbuf[0];
617 	mpp_data->mapped_mem = retbuf[1];
618 
619 	mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
620 	mpp_data->pool_num = retbuf[2] & 0xffff;
621 
622 	mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff;
623 	mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff;
624 	mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffff;
625 
626 	mpp_data->pool_size = retbuf[4];
627 	mpp_data->loan_request = retbuf[5];
628 	mpp_data->backing_mem = retbuf[6];
629 
630 	return rc;
631 }
632 EXPORT_SYMBOL(h_get_mpp);
633 
h_get_mpp_x(struct hvcall_mpp_x_data * mpp_x_data)634 int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data)
635 {
636 	int rc;
637 	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE] = { 0 };
638 
639 	rc = plpar_hcall9(H_GET_MPP_X, retbuf);
640 
641 	mpp_x_data->coalesced_bytes = retbuf[0];
642 	mpp_x_data->pool_coalesced_bytes = retbuf[1];
643 	mpp_x_data->pool_purr_cycles = retbuf[2];
644 	mpp_x_data->pool_spurr_cycles = retbuf[3];
645 
646 	return rc;
647 }
648