xref: /titanic_52/usr/src/uts/sun4v/ml/mach_proc_init.s (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1*1ae08745Sheppo/*
2*1ae08745Sheppo * CDDL HEADER START
3*1ae08745Sheppo *
4*1ae08745Sheppo * The contents of this file are subject to the terms of the
5*1ae08745Sheppo * Common Development and Distribution License (the "License").
6*1ae08745Sheppo * You may not use this file except in compliance with the License.
7*1ae08745Sheppo *
8*1ae08745Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*1ae08745Sheppo * or http://www.opensolaris.org/os/licensing.
10*1ae08745Sheppo * See the License for the specific language governing permissions
11*1ae08745Sheppo * and limitations under the License.
12*1ae08745Sheppo *
13*1ae08745Sheppo * When distributing Covered Code, include this CDDL HEADER in each
14*1ae08745Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*1ae08745Sheppo * If applicable, add the following below this CDDL HEADER, with the
16*1ae08745Sheppo * fields enclosed by brackets "[]" replaced with your own identifying
17*1ae08745Sheppo * information: Portions Copyright [yyyy] [name of copyright owner]
18*1ae08745Sheppo *
19*1ae08745Sheppo * CDDL HEADER END
20*1ae08745Sheppo */
21*1ae08745Sheppo
22*1ae08745Sheppo/*
23*1ae08745Sheppo * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*1ae08745Sheppo * Use is subject to license terms.
25*1ae08745Sheppo */
26*1ae08745Sheppo
27*1ae08745Sheppo#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*1ae08745Sheppo
29*1ae08745Sheppo/*
30*1ae08745Sheppo * sun4v processor initialization
31*1ae08745Sheppo *
32*1ae08745Sheppo * This is the kernel entry point for CPUs that enter Solaris
33*1ae08745Sheppo * directly from the hypervisor. i.e. without going through OBP.
34*1ae08745Sheppo */
35*1ae08745Sheppo
36*1ae08745Sheppo#if !defined(lint)
37*1ae08745Sheppo#include "assym.h"
38*1ae08745Sheppo#endif /* !lint */
39*1ae08745Sheppo
40*1ae08745Sheppo#include <sys/asm_linkage.h>
41*1ae08745Sheppo#include <sys/hypervisor_api.h>
42*1ae08745Sheppo#include <sys/machasi.h>
43*1ae08745Sheppo#include <sys/machpcb.h>
44*1ae08745Sheppo#include <sys/machlock.h>
45*1ae08745Sheppo#include <sys/mmu.h>
46*1ae08745Sheppo#include <sys/lpad.h>
47*1ae08745Sheppo
48*1ae08745Sheppo#if defined(lint)
49*1ae08745Sheppo
50*1ae08745Sheppo/* ARGSUSED */
51*1ae08745Sheppovoid
52*1ae08745Sheppomach_cpu_startup(uint64_t rabase, uint64_t memsz)
53*1ae08745Sheppo{}
54*1ae08745Sheppo
55*1ae08745Sheppo#else	/* lint */
56*1ae08745Sheppo
57*1ae08745Sheppo	/*
58*1ae08745Sheppo	 * %o0 - hcall specified arg (cpuid)
59*1ae08745Sheppo	 * %i0 - real memory base
60*1ae08745Sheppo	 * %i1 - memory size
61*1ae08745Sheppo	 */
62*1ae08745Sheppo	ENTRY_NP(mach_cpu_startup)
63*1ae08745Sheppo	/*
64*1ae08745Sheppo	 * Calculate the data pointer. The landing pad
65*1ae08745Sheppo	 * data immediately follows the landing pad text.
66*1ae08745Sheppo	 */
67*1ae08745Sheppo	rd	%pc, %l0
68*1ae08745Sheppo	add	%l0, LPAD_TEXT_SIZE, %l1	! %l1 has start of data
69*1ae08745Sheppo
70*1ae08745Sheppo	/*
71*1ae08745Sheppo	 * Setup the initial state of the CPU.
72*1ae08745Sheppo	 */
73*1ae08745Sheppo	wrpr	%g0, 0, %tl
74*1ae08745Sheppo	wrpr	%g0, 0, %gl
75*1ae08745Sheppo	wrpr	%g0, MAXWIN - 2, %cansave
76*1ae08745Sheppo	wrpr	%g0, MAXWIN - 2, %cleanwin
77*1ae08745Sheppo	wrpr	%g0, 0, %canrestore
78*1ae08745Sheppo	wrpr	%g0, 0, %otherwin
79*1ae08745Sheppo	wrpr	%g0, 0, %cwp
80*1ae08745Sheppo	wrpr	%g0, 0, %wstate
81*1ae08745Sheppo	wr	%g0, %y
82*1ae08745Sheppo	wrpr	%g0, PIL_MAX, %pil
83*1ae08745Sheppo
84*1ae08745Sheppo	set	trap_table, %g1
85*1ae08745Sheppo	wrpr	%g1, %tba
86*1ae08745Sheppo
87*1ae08745Sheppo	! initialize cpuid into scratchpad register
88*1ae08745Sheppo	mov	SCRATCHPAD_CPUID, %g1
89*1ae08745Sheppo	stxa	%o0, [%g1]ASI_SCRATCHPAD
90*1ae08745Sheppo
91*1ae08745Sheppo	! sanity check the data section
92*1ae08745Sheppo	setx	LPAD_MAGIC_VAL, %g2, %g1
93*1ae08745Sheppo	ldx	[%l1 + LPAD_MAGIC], %g2
94*1ae08745Sheppo	cmp	%g1, %g2
95*1ae08745Sheppo	bne	startup_error
96*1ae08745Sheppo	  nop
97*1ae08745Sheppo
98*1ae08745Sheppo	/*
99*1ae08745Sheppo	 * Loop through the array of TTE's, installing the
100*1ae08745Sheppo	 * VA to RA mapping for each one.
101*1ae08745Sheppo	 */
102*1ae08745Sheppo	ldx	[%l1 + LPAD_NMAP], %l2		! %l2 = number of mappings
103*1ae08745Sheppo	add	%l1, LPAD_MAP, %l3		! %l3 = the current mapping
104*1ae08745Sheppo
105*1ae08745Sheppo	/*
106*1ae08745Sheppo	 * Sanity check the number of mappings.
107*1ae08745Sheppo	 */
108*1ae08745Sheppo	mulx	%l2, LPAD_MAP_SIZE, %g1
109*1ae08745Sheppo	add	%l3, %g1, %g1			! %g1 = end of the array
110*1ae08745Sheppo	add	%l1, LPAD_DATA_SIZE, %g2	! %g2 = end of data section
111*1ae08745Sheppo	sub	%g2, %g1, %g2
112*1ae08745Sheppo	brlz	%g2, startup_error
113*1ae08745Sheppo	  nop
114*1ae08745Sheppo
115*1ae08745Sheppo0:
116*1ae08745Sheppo	cmp	%l2, %g0
117*1ae08745Sheppo	be	3f
118*1ae08745Sheppo	  nop
119*1ae08745Sheppo
120*1ae08745Sheppo	ldx	[%l3 + LPAD_MAP_FLAGS], %l4	! %l4 = flags
121*1ae08745Sheppo
122*1ae08745Sheppo	/*
123*1ae08745Sheppo	 * Generate args for the HV call
124*1ae08745Sheppo	 */
125*1ae08745Sheppo	ldx	[%l3 + LPAD_MAP_VA], %o0	! %o0 = virtual address
126*1ae08745Sheppo	mov	KCONTEXT, %o1			! %o1 = context
127*1ae08745Sheppo	ldx	[%l3 + LPAD_MAP_TTE], %o2	! %o2 = TTE
128*1ae08745Sheppo	and	%l4, FLAG_MMUFLAGS_MASK, %o3	! %o3 = MMU flags
129*1ae08745Sheppo
130*1ae08745Sheppo	! check if this is a locked TTE
131*1ae08745Sheppo	and	%l4, FLAG_LOCK_MASK, %l4
132*1ae08745Sheppo	cmp	%l4, %g0
133*1ae08745Sheppo	bne	1f
134*1ae08745Sheppo	  nop
135*1ae08745Sheppo
136*1ae08745Sheppo	! install an unlocked entry
137*1ae08745Sheppo	ta	MMU_MAP_ADDR
138*1ae08745Sheppo	ba	2f
139*1ae08745Sheppo	  nop
140*1ae08745Sheppo1:
141*1ae08745Sheppo	! install a locked entry
142*1ae08745Sheppo	mov	MAP_PERM_ADDR, %o5
143*1ae08745Sheppo	ta	FAST_TRAP
144*1ae08745Sheppo
145*1ae08745Sheppo2:
146*1ae08745Sheppo	! check for errors from the hcall
147*1ae08745Sheppo	cmp	%o0, %g0
148*1ae08745Sheppo	bne	startup_error
149*1ae08745Sheppo	  nop
150*1ae08745Sheppo
151*1ae08745Sheppo	sub	%l2, 1, %l2			! decrement counter
152*1ae08745Sheppo	add	%l3, LPAD_MAP_SIZE, %l3		! increment pointer
153*1ae08745Sheppo
154*1ae08745Sheppo	ba	0b
155*1ae08745Sheppo	  nop
156*1ae08745Sheppo
157*1ae08745Sheppo3:
158*1ae08745Sheppo	/*
159*1ae08745Sheppo	 * Set the MMU fault status area
160*1ae08745Sheppo	 */
161*1ae08745Sheppo	ldx	[%l1 + LPAD_MMFSA_RA], %o0
162*1ae08745Sheppo
163*1ae08745Sheppo	mov	MMU_SET_INFOPTR, %o5
164*1ae08745Sheppo	ta	FAST_TRAP
165*1ae08745Sheppo
166*1ae08745Sheppo	! check for errors from the hcall
167*1ae08745Sheppo	cmp	%o0, %g0
168*1ae08745Sheppo	bne	startup_error
169*1ae08745Sheppo	  nop
170*1ae08745Sheppo
171*1ae08745Sheppo	/*
172*1ae08745Sheppo	 * Load remaining arguments before enabling the
173*1ae08745Sheppo	 * MMU so that the loads can be done using real
174*1ae08745Sheppo	 * addresses.
175*1ae08745Sheppo	 */
176*1ae08745Sheppo	ldx	[%l1 + LPAD_PC], %l3		! %l3 = specified entry point
177*1ae08745Sheppo	ldx	[%l1 + LPAD_ARG], %l4		! %l4 = specified argument
178*1ae08745Sheppo	ldx	[%l1 + LPAD_INUSE], %l5		! %l5 = va of inuse mailbox
179*1ae08745Sheppo
180*1ae08745Sheppo	/*
181*1ae08745Sheppo	 * Enable the MMU. On success, it returns to the
182*1ae08745Sheppo	 * global version of the landing pad text, rather
183*1ae08745Sheppo	 * than the text copied into the lpad buffer.
184*1ae08745Sheppo	 */
185*1ae08745Sheppo	mov	1, %o0				! %o0 = enable flag (1 = enable)
186*1ae08745Sheppo	set	startup_complete, %o1		! VA of return address
187*1ae08745Sheppo	mov	MMU_ENABLE, %o5
188*1ae08745Sheppo	ta	FAST_TRAP
189*1ae08745Sheppo
190*1ae08745Sheppo	/*
191*1ae08745Sheppo	 * On errors, just enter a spin loop until the
192*1ae08745Sheppo	 * CPU that initiated the start recovers the CPU.
193*1ae08745Sheppo	 */
194*1ae08745Sheppostartup_error:
195*1ae08745Sheppo	ba	startup_error
196*1ae08745Sheppo	  nop
197*1ae08745Sheppo
198*1ae08745Sheppo	/*
199*1ae08745Sheppo	 * Jump to the generic CPU initialization code.
200*1ae08745Sheppo	 */
201*1ae08745Sheppostartup_complete:
202*1ae08745Sheppo	mov	%l4, %o0
203*1ae08745Sheppo	jmpl	%l3, %g0
204*1ae08745Sheppo	  stx	%g0, [%l5]			! clear the inuse mailbox
205*1ae08745Sheppo
206*1ae08745Sheppo	SET_SIZE(mach_cpu_startup)
207*1ae08745Sheppo
208*1ae08745Sheppo	.global mach_cpu_startup_end
209*1ae08745Sheppomach_cpu_startup_end:
210*1ae08745Sheppo
211*1ae08745Sheppo#endif	/* lint */
212