⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpar.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		DBG_LOW(" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);	/* Now fill in the actual HPTE */	/* Set CEC cookie to 0         */	/* Zero page = 0               */	/* I-cache Invalidate = 0      */	/* I-cache synchronize = 0     */	/* Exact = 0                   */	flags = 0;	/* Make pHyp happy */	if (rflags & (_PAGE_GUARDED|_PAGE_NO_CACHE))		hpte_r &= ~_PAGE_COHERENT;	lpar_rc = plpar_pte_enter(flags, hpte_group, hpte_v, hpte_r, &slot);	if (unlikely(lpar_rc == H_PTEG_FULL)) {		if (!(vflags & HPTE_V_BOLTED))			DBG_LOW(" full\n");		return -1;	}	/*	 * Since we try and ioremap PHBs we don't own, the pte insert	 * will fail. However we must catch the failure in hash_page	 * or we will loop forever, so return -2 in this case.	 */	if (unlikely(lpar_rc != H_SUCCESS)) {		if (!(vflags & HPTE_V_BOLTED))			DBG_LOW(" lpar err %d\n", lpar_rc);		return -2;	}	if (!(vflags & HPTE_V_BOLTED))		DBG_LOW(" -> slot: %d\n", slot & 7);	/* Because of iSeries, we have to pass down the secondary	 * bucket bit here as well	 */	return (slot & 7) | (!!(vflags & HPTE_V_SECONDARY) << 3);}static DEFINE_SPINLOCK(pSeries_lpar_tlbie_lock);static long pSeries_lpar_hpte_remove(unsigned long hpte_group){	unsigned long slot_offset;	unsigned long lpar_rc;	int i;	unsigned long dummy1, dummy2;	/* pick a random slot to start at */	slot_offset = mftb() & 0x7;	for (i = 0; i < HPTES_PER_GROUP; i++) {		/* don't remove a bolted entry */		lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset,					   (0x1UL << 4), &dummy1, &dummy2);		if (lpar_rc == H_SUCCESS)			return i;		BUG_ON(lpar_rc != H_NOT_FOUND);		slot_offset++;		slot_offset &= 0x7;	}	return -1;}static void pSeries_lpar_hptab_clear(void){	unsigned long size_bytes = 1UL << ppc64_pft_size;	unsigned long hpte_count = size_bytes >> 4;	unsigned long dummy1, dummy2, dword0;	long lpar_rc;	int i;	/* TODO: Use bulk call */	for (i = 0; i < hpte_count; i++) {		/* dont remove HPTEs with VRMA mappings */		lpar_rc = plpar_pte_remove_raw(H_ANDCOND, i, HPTE_V_1TB_SEG,						&dummy1, &dummy2);		if (lpar_rc == H_NOT_FOUND) {			lpar_rc = plpar_pte_read_raw(0, i, &dword0, &dummy1);			if (!lpar_rc && ((dword0 & HPTE_V_VRMA_MASK)				!= HPTE_V_VRMA_MASK))				/* Can be hpte for 1TB Seg. So remove it */				plpar_pte_remove_raw(0, i, 0, &dummy1, &dummy2);		}	}}/* * This computes the AVPN and B fields of the first dword of a HPTE, * for use when we want to match an existing PTE.  The bottom 7 bits * of the returned value are zero. */static inline unsigned long hpte_encode_avpn(unsigned long va, int psize,					     int ssize){	unsigned long v;	v = (va >> 23) & ~(mmu_psize_defs[psize].avpnm);	v <<= HPTE_V_AVPN_SHIFT;	v |= ((unsigned long) ssize) << HPTE_V_SSIZE_SHIFT;	return v;}/* * NOTE: for updatepp ops we are fortunate that the linux "newpp" bits and * the low 3 bits of flags happen to line up.  So no transform is needed. * We can probably optimize here and assume the high bits of newpp are * already zero.  For now I am paranoid. */static long pSeries_lpar_hpte_updatepp(unsigned long slot,				       unsigned long newpp,				       unsigned long va,				       int psize, int ssize, int local){	unsigned long lpar_rc;	unsigned long flags = (newpp & 7) | H_AVPN;	unsigned long want_v;	want_v = hpte_encode_avpn(va, psize, ssize);	DBG_LOW("    update: avpnv=%016lx, hash=%016lx, f=%x, psize: %d ... ",		want_v, slot, flags, psize);	lpar_rc = plpar_pte_protect(flags, slot, want_v);	if (lpar_rc == H_NOT_FOUND) {		DBG_LOW("not found !\n");		return -1;	}	DBG_LOW("ok\n");	BUG_ON(lpar_rc != H_SUCCESS);	return 0;}static unsigned long pSeries_lpar_hpte_getword0(unsigned long slot){	unsigned long dword0;	unsigned long lpar_rc;	unsigned long dummy_word1;	unsigned long flags;	/* Read 1 pte at a time                        */	/* Do not need RPN to logical page translation */	/* No cross CEC PFT access                     */	flags = 0;	lpar_rc = plpar_pte_read(flags, slot, &dword0, &dummy_word1);	BUG_ON(lpar_rc != H_SUCCESS);	return dword0;}static long pSeries_lpar_hpte_find(unsigned long va, int psize, int ssize){	unsigned long hash;	unsigned long i;	long slot;	unsigned long want_v, hpte_v;	hash = hpt_hash(va, mmu_psize_defs[psize].shift, ssize);	want_v = hpte_encode_avpn(va, psize, ssize);	/* Bolted entries are always in the primary group */	slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;	for (i = 0; i < HPTES_PER_GROUP; i++) {		hpte_v = pSeries_lpar_hpte_getword0(slot);		if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID))			/* HPTE matches */			return slot;		++slot;	}	return -1;} static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp,					     unsigned long ea,					     int psize, int ssize){	unsigned long lpar_rc, slot, vsid, va, flags;	vsid = get_kernel_vsid(ea, ssize);	va = hpt_va(ea, vsid, ssize);	slot = pSeries_lpar_hpte_find(va, psize, ssize);	BUG_ON(slot == -1);	flags = newpp & 7;	lpar_rc = plpar_pte_protect(flags, slot, 0);	BUG_ON(lpar_rc != H_SUCCESS);}static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long va,					 int psize, int ssize, int local){	unsigned long want_v;	unsigned long lpar_rc;	unsigned long dummy1, dummy2;	DBG_LOW("    inval : slot=%lx, va=%016lx, psize: %d, local: %d",		slot, va, psize, local);	want_v = hpte_encode_avpn(va, psize, ssize);	lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v, &dummy1, &dummy2);	if (lpar_rc == H_NOT_FOUND)		return;	BUG_ON(lpar_rc != H_SUCCESS);}/* Flag bits for H_BULK_REMOVE */#define HBR_REQUEST	0x4000000000000000UL#define HBR_RESPONSE	0x8000000000000000UL#define HBR_END		0xc000000000000000UL#define HBR_AVPN	0x0200000000000000UL#define HBR_ANDCOND	0x0100000000000000UL/* * Take a spinlock around flushes to avoid bouncing the hypervisor tlbie * lock. */static void pSeries_lpar_flush_hash_range(unsigned long number, int local){	unsigned long i, pix, rc;	unsigned long flags = 0;	struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);	int lock_tlbie = !cpu_has_feature(CPU_FTR_LOCKLESS_TLBIE);	unsigned long param[9];	unsigned long va;	unsigned long hash, index, shift, hidx, slot;	real_pte_t pte;	int psize, ssize;	if (lock_tlbie)		spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags);	psize = batch->psize;	ssize = batch->ssize;	pix = 0;	for (i = 0; i < number; i++) {		va = batch->vaddr[i];		pte = batch->pte[i];		pte_iterate_hashed_subpages(pte, psize, va, index, shift) {			hash = hpt_hash(va, shift, ssize);			hidx = __rpte_to_hidx(pte, index);			if (hidx & _PTEIDX_SECONDARY)				hash = ~hash;			slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;			slot += hidx & _PTEIDX_GROUP_IX;			if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) {				pSeries_lpar_hpte_invalidate(slot, va, psize,							     ssize, local);			} else {				param[pix] = HBR_REQUEST | HBR_AVPN | slot;				param[pix+1] = hpte_encode_avpn(va, psize,								ssize);				pix += 2;				if (pix == 8) {					rc = plpar_hcall9(H_BULK_REMOVE, param,						param[0], param[1], param[2],						param[3], param[4], param[5],						param[6], param[7]);					BUG_ON(rc != H_SUCCESS);					pix = 0;				}			}		} pte_iterate_hashed_end();	}	if (pix) {		param[pix] = HBR_END;		rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1],				  param[2], param[3], param[4], param[5],				  param[6], param[7]);		BUG_ON(rc != H_SUCCESS);	}	if (lock_tlbie)		spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags);}void __init hpte_init_lpar(void){	ppc_md.hpte_invalidate	= pSeries_lpar_hpte_invalidate;	ppc_md.hpte_updatepp	= pSeries_lpar_hpte_updatepp;	ppc_md.hpte_updateboltedpp = pSeries_lpar_hpte_updateboltedpp;	ppc_md.hpte_insert	= pSeries_lpar_hpte_insert;	ppc_md.hpte_remove	= pSeries_lpar_hpte_remove;	ppc_md.flush_hash_range	= pSeries_lpar_flush_hash_range;	ppc_md.hpte_clear_all   = pSeries_lpar_hptab_clear;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -