18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2000 Silicon Graphics, Inc.
78c2ecf20Sopenharmony_ci * Copyright (C) 2005 Ralf Baechle <ralf@linux-mips.org>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __ASM_MACH_IP27_KERNEL_ENTRY_H
108c2ecf20Sopenharmony_ci#define __ASM_MACH_IP27_KERNEL_ENTRY_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <asm/sn/addrs.h>
138c2ecf20Sopenharmony_ci#include <asm/sn/agent.h>
148c2ecf20Sopenharmony_ci#include <asm/sn/klkernvars.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * TLB bits
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci#define PAGE_GLOBAL		(1 << 6)
208c2ecf20Sopenharmony_ci#define PAGE_VALID		(1 << 7)
218c2ecf20Sopenharmony_ci#define PAGE_DIRTY		(1 << 8)
228c2ecf20Sopenharmony_ci#define CACHE_CACHABLE_COW	(5 << 9)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci	/*
258c2ecf20Sopenharmony_ci	 * inputs are the text nasid in t1, data nasid in t2.
268c2ecf20Sopenharmony_ci	 */
278c2ecf20Sopenharmony_ci	.macro MAPPED_KERNEL_SETUP_TLB
288c2ecf20Sopenharmony_ci#ifdef CONFIG_MAPPED_KERNEL
298c2ecf20Sopenharmony_ci	/*
308c2ecf20Sopenharmony_ci	 * This needs to read the nasid - assume 0 for now.
318c2ecf20Sopenharmony_ci	 * Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,
328c2ecf20Sopenharmony_ci	 * 0+DVG in tlblo_1.
338c2ecf20Sopenharmony_ci	 */
348c2ecf20Sopenharmony_ci	dli	t0, 0xffffffffc0000000
358c2ecf20Sopenharmony_ci	dmtc0	t0, CP0_ENTRYHI
368c2ecf20Sopenharmony_ci	li	t0, 0x1c000		# Offset of text into node memory
378c2ecf20Sopenharmony_ci	dsll	t1, NASID_SHFT		# Shift text nasid into place
388c2ecf20Sopenharmony_ci	dsll	t2, NASID_SHFT		# Same for data nasid
398c2ecf20Sopenharmony_ci	or	t1, t1, t0		# Physical load address of kernel text
408c2ecf20Sopenharmony_ci	or	t2, t2, t0		# Physical load address of kernel data
418c2ecf20Sopenharmony_ci	dsrl	t1, 12			# 4K pfn
428c2ecf20Sopenharmony_ci	dsrl	t2, 12			# 4K pfn
438c2ecf20Sopenharmony_ci	dsll	t1, 6			# Get pfn into place
448c2ecf20Sopenharmony_ci	dsll	t2, 6			# Get pfn into place
458c2ecf20Sopenharmony_ci	li	t0, ((PAGE_GLOBAL | PAGE_VALID | CACHE_CACHABLE_COW) >> 6)
468c2ecf20Sopenharmony_ci	or	t0, t0, t1
478c2ecf20Sopenharmony_ci	mtc0	t0, CP0_ENTRYLO0	# physaddr, VG, cach exlwr
488c2ecf20Sopenharmony_ci	li	t0, ((PAGE_GLOBAL | PAGE_VALID |  PAGE_DIRTY | CACHE_CACHABLE_COW) >> 6)
498c2ecf20Sopenharmony_ci	or	t0, t0, t2
508c2ecf20Sopenharmony_ci	mtc0	t0, CP0_ENTRYLO1	# physaddr, DVG, cach exlwr
518c2ecf20Sopenharmony_ci	li	t0, 0x1ffe000		# MAPPED_KERN_TLBMASK, TLBPGMASK_16M
528c2ecf20Sopenharmony_ci	mtc0	t0, CP0_PAGEMASK
538c2ecf20Sopenharmony_ci	li	t0, 0			# KMAP_INX
548c2ecf20Sopenharmony_ci	mtc0	t0, CP0_INDEX
558c2ecf20Sopenharmony_ci	li	t0, 1
568c2ecf20Sopenharmony_ci	mtc0	t0, CP0_WIRED
578c2ecf20Sopenharmony_ci	tlbwi
588c2ecf20Sopenharmony_ci#else
598c2ecf20Sopenharmony_ci	mtc0	zero, CP0_WIRED
608c2ecf20Sopenharmony_ci#endif
618c2ecf20Sopenharmony_ci	.endm
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/*
648c2ecf20Sopenharmony_ci * Intentionally empty macro, used in head.S. Override in
658c2ecf20Sopenharmony_ci * arch/mips/mach-xxx/kernel-entry-init.h when necessary.
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_ci	.macro	kernel_entry_setup
688c2ecf20Sopenharmony_ci	GET_NASID_ASM	t1
698c2ecf20Sopenharmony_ci	move		t2, t1			# text and data are here
708c2ecf20Sopenharmony_ci	MAPPED_KERNEL_SETUP_TLB
718c2ecf20Sopenharmony_ci	.endm
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*
748c2ecf20Sopenharmony_ci * Do SMP slave processor setup necessary before we can safely execute C code.
758c2ecf20Sopenharmony_ci */
768c2ecf20Sopenharmony_ci	.macro	smp_slave_setup
778c2ecf20Sopenharmony_ci	GET_NASID_ASM	t1
788c2ecf20Sopenharmony_ci	dli	t0, KLDIR_OFFSET + (KLI_KERN_VARS * KLDIR_ENT_SIZE) + \
798c2ecf20Sopenharmony_ci		    KLDIR_OFF_POINTER + CAC_BASE
808c2ecf20Sopenharmony_ci	dsll	t1, NASID_SHFT
818c2ecf20Sopenharmony_ci	or	t0, t0, t1
828c2ecf20Sopenharmony_ci	ld	t0, 0(t0)			# t0 points to kern_vars struct
838c2ecf20Sopenharmony_ci	lh	t1, KV_RO_NASID_OFFSET(t0)
848c2ecf20Sopenharmony_ci	lh	t2, KV_RW_NASID_OFFSET(t0)
858c2ecf20Sopenharmony_ci	MAPPED_KERNEL_SETUP_TLB
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/*
888c2ecf20Sopenharmony_ci	 * We might not get launched at the address the kernel is linked to,
898c2ecf20Sopenharmony_ci	 * so we jump there.
908c2ecf20Sopenharmony_ci	 */
918c2ecf20Sopenharmony_ci	PTR_LA	t0, 0f
928c2ecf20Sopenharmony_ci	jr	t0
938c2ecf20Sopenharmony_ci0:
948c2ecf20Sopenharmony_ci	.endm
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#endif /* __ASM_MACH_IP27_KERNEL_ENTRY_H */
97