xref: /titanic_41/usr/src/uts/sun4u/starfire/os/cpu_sgnblk.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  *	Following is STARFIRE specific code
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/mman.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/vm.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/starfire.h>
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include <vm/seg.h>
46*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
47*7c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/cpu_sgn.h>
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * SIGBCPU represents the cpu maintaining the primary
53*7c478bd9Sstevel@tonic-gate  * sigblock (bbsram).  This bbsram is used for CVC
54*7c478bd9Sstevel@tonic-gate  * and maintains the post2obp structure.  It starts
55*7c478bd9Sstevel@tonic-gate  * out as the bootproc (cpu0).
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate struct cpu	*SIGBCPU = &cpu0;
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate cpu_sgnblk_t *cpu_sgnblkp[NCPU];
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Mapin the the cpu's signature block.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate void
cpu_sgn_mapin(int cpuid)65*7c478bd9Sstevel@tonic-gate cpu_sgn_mapin(int cpuid)
66*7c478bd9Sstevel@tonic-gate {
67*7c478bd9Sstevel@tonic-gate 	uint64_t bbsram_physaddr;
68*7c478bd9Sstevel@tonic-gate 	uint64_t cpu_sgnblk_physaddr;
69*7c478bd9Sstevel@tonic-gate 	uint32_t cpu_sgnblk_offset;
70*7c478bd9Sstevel@tonic-gate 	caddr_t	cvaddr;
71*7c478bd9Sstevel@tonic-gate 	pgcnt_t	num_pages;
72*7c478bd9Sstevel@tonic-gate 	pfn_t	pfn;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	ASSERT(cpu_sgnblkp[cpuid] == NULL);
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	/*
77*7c478bd9Sstevel@tonic-gate 	 * Construct the physical base address of the bbsram
78*7c478bd9Sstevel@tonic-gate 	 * in PSI space associated with this cpu in question.
79*7c478bd9Sstevel@tonic-gate 	 */
80*7c478bd9Sstevel@tonic-gate 	cpu_sgnblk_physaddr = bbsram_physaddr =
81*7c478bd9Sstevel@tonic-gate 				STARFIRE_UPAID2UPS(cpuid) | STARFIRE_PSI_BASE;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	/*
84*7c478bd9Sstevel@tonic-gate 	 * The cpu_sgnblk pointer offsets are stored in the
85*7c478bd9Sstevel@tonic-gate 	 * undefined hardware trap slot 0x7f which is located
86*7c478bd9Sstevel@tonic-gate 	 * at offset 0xfe0. There are 2 of them since the
87*7c478bd9Sstevel@tonic-gate 	 * bbsram is shared among the 2 cpus residing on the
88*7c478bd9Sstevel@tonic-gate 	 * a PC. We need to determine the CPU in question whether
89*7c478bd9Sstevel@tonic-gate 	 * it is in port 0 or 1. CPU on port 0 has its
90*7c478bd9Sstevel@tonic-gate 	 * signature blkptr stored in 0xfe0 while the cpu_sgnblk
91*7c478bd9Sstevel@tonic-gate 	 * ptr of local port 1's CPU is in offset 0xfe8.
92*7c478bd9Sstevel@tonic-gate 	 */
93*7c478bd9Sstevel@tonic-gate 	if (cpuid & 0x1) {
94*7c478bd9Sstevel@tonic-gate 		/* CPU is in local port 1 */
95*7c478bd9Sstevel@tonic-gate 		bbsram_physaddr |= 0xfe8ULL;
96*7c478bd9Sstevel@tonic-gate 	} else {
97*7c478bd9Sstevel@tonic-gate 		/* CPU is in local port 0 */
98*7c478bd9Sstevel@tonic-gate 		bbsram_physaddr |= 0xfe0ULL;
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	/*
102*7c478bd9Sstevel@tonic-gate 	 * Read in the cpu_sgnblk pointer offset. Add it to the bbsram
103*7c478bd9Sstevel@tonic-gate 	 * base address to get the base address of the cpu_sgnblk.
104*7c478bd9Sstevel@tonic-gate 	 */
105*7c478bd9Sstevel@tonic-gate 	cpu_sgnblk_offset = ldphysio(bbsram_physaddr);
106*7c478bd9Sstevel@tonic-gate 	cpu_sgnblk_physaddr += cpu_sgnblk_offset;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	pfn = (pfn_t)(cpu_sgnblk_physaddr >> MMU_PAGESHIFT);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	num_pages = mmu_btopr(((cpu_sgnblk_physaddr &
111*7c478bd9Sstevel@tonic-gate 				MMU_PAGEOFFSET) + sizeof (cpu_sgnblk_t)));
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	/*
114*7c478bd9Sstevel@tonic-gate 	 * Map in the cpu_sgnblk
115*7c478bd9Sstevel@tonic-gate 	 */
116*7c478bd9Sstevel@tonic-gate 	cvaddr = vmem_alloc(heap_arena, ptob(num_pages), VM_SLEEP);
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	hat_devload(kas.a_hat, cvaddr, ptob(num_pages),
119*7c478bd9Sstevel@tonic-gate 	    pfn, PROT_READ | PROT_WRITE, HAT_LOAD_LOCK);
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	cpu_sgnblkp[cpuid] = ((cpu_sgnblk_t *)(cvaddr +
122*7c478bd9Sstevel@tonic-gate 	    (uint32_t)(cpu_sgnblk_offset & MMU_PAGEOFFSET)));
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate void
cpu_sgn_mapout(int cpuid)126*7c478bd9Sstevel@tonic-gate cpu_sgn_mapout(int cpuid)
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate 	ulong_t cvaddr, num_pages;
129*7c478bd9Sstevel@tonic-gate 	uint32_t cpu_sgnblk_offset;
130*7c478bd9Sstevel@tonic-gate 	uint64_t cpu_sgnblk_physaddr;
131*7c478bd9Sstevel@tonic-gate 	uint64_t bbsram_physaddr;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	if ((cvaddr = (ulong_t)cpu_sgnblkp[cpuid]) == NULL) {
134*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "cpu_sgn_mapout: ERROR: "
135*7c478bd9Sstevel@tonic-gate 			"cpu_sgnblkp[%d] = NULL\n", cpuid);
136*7c478bd9Sstevel@tonic-gate 	} else {
137*7c478bd9Sstevel@tonic-gate 		cvaddr &= ~MMU_PAGEOFFSET;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 		/*
140*7c478bd9Sstevel@tonic-gate 		 * Construct the physical base address of the bbsram
141*7c478bd9Sstevel@tonic-gate 		 * in PSI space associated with this cpu in question.
142*7c478bd9Sstevel@tonic-gate 		 */
143*7c478bd9Sstevel@tonic-gate 		bbsram_physaddr = STARFIRE_UPAID2UPS(cpuid) |
144*7c478bd9Sstevel@tonic-gate 					STARFIRE_PSI_BASE;
145*7c478bd9Sstevel@tonic-gate 		cpu_sgnblk_physaddr = bbsram_physaddr;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 		/*
148*7c478bd9Sstevel@tonic-gate 		 * The cpu_sgnblk pointer offsets are stored in the
149*7c478bd9Sstevel@tonic-gate 		 * undefined hardware trap slot 0x7f which is located
150*7c478bd9Sstevel@tonic-gate 		 * at offset 0xfe0. There are 2 of them since the
151*7c478bd9Sstevel@tonic-gate 		 * bbsram is shared among the 2 cpus residing on the
152*7c478bd9Sstevel@tonic-gate 		 * a PC. We need to determine the CPU in question whether
153*7c478bd9Sstevel@tonic-gate 		 * it is in port 0 or 1. CPU on port 0 has its
154*7c478bd9Sstevel@tonic-gate 		 * signature blkptr stored in 0xfe0 while the cpu_sgnblk
155*7c478bd9Sstevel@tonic-gate 		 * ptr of local port 1's CPU is in offset 0xfe8.
156*7c478bd9Sstevel@tonic-gate 		 */
157*7c478bd9Sstevel@tonic-gate 		if (cpuid & 0x1) {
158*7c478bd9Sstevel@tonic-gate 			/* CPU is in local port 1 */
159*7c478bd9Sstevel@tonic-gate 			bbsram_physaddr |= 0xfe8ULL;
160*7c478bd9Sstevel@tonic-gate 		} else {
161*7c478bd9Sstevel@tonic-gate 			/* CPU is in local port 0 */
162*7c478bd9Sstevel@tonic-gate 			bbsram_physaddr |= 0xfe0ULL;
163*7c478bd9Sstevel@tonic-gate 		}
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 		/*
166*7c478bd9Sstevel@tonic-gate 		 * Read in the cpu_sgnblk pointer offset. Add it to the bbsram
167*7c478bd9Sstevel@tonic-gate 		 * base address to get the base address of the cpu_sgnblk.
168*7c478bd9Sstevel@tonic-gate 		 */
169*7c478bd9Sstevel@tonic-gate 		cpu_sgnblk_offset = ldphysio(bbsram_physaddr);
170*7c478bd9Sstevel@tonic-gate 		cpu_sgnblk_physaddr += cpu_sgnblk_offset;
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 		num_pages = mmu_btopr(((uint_t)(cpu_sgnblk_physaddr &
173*7c478bd9Sstevel@tonic-gate 				MMU_PAGEOFFSET) + sizeof (cpu_sgnblk_t)));
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 		hat_unload(kas.a_hat, (caddr_t)cvaddr, ptob(num_pages),
176*7c478bd9Sstevel@tonic-gate 		    HAT_UNLOAD_UNLOCK);
177*7c478bd9Sstevel@tonic-gate 		vmem_free(heap_arena, (caddr_t)cvaddr, ptob(num_pages));
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 		cpu_sgnblkp[cpuid] = NULL;
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate }
182