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