summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halfire/ppc/pxproc.c
blob: ca6d2e3f34913ae4d77e2b66ec86c2b0744fb6c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
 * Copyright (c) 1995 FirePower Systems, Inc.
 * DO NOT DISTRIBUTE without permission
 *
 * $RCSfile: pxproc.c $
 * $Revision: 1.21 $
 * $Date: 1996/06/25 02:46:32 $
 * $Locker:  $
 */

/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

	pxproc.c

Abstract:

	Stub functions for UP hals.

Author:

	Ken Reneris (kenr) 22-Jan-1991

Environment:

	Kernel mode only.

Revision History:

	Jim Wooldridge Ported to PowerPC

--*/

#include "fpdebug.h"
#include "halp.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "arccodes.h"
#include "fpreg.h"
#include "phsystem.h"


UCHAR   HalName[] = "Powerized HAL";

extern	VOID HalpInitializePciBus (VOID);
VOID	HalpInitOtherBuses (VOID);
ULONG	HalpProcessorCount(VOID);

#ifdef ALLOC_PRAGMA
#pragma alloc_text(INIT,HalStartNextProcessor)
#pragma alloc_text(INIT,HalAllProcessorsStarted)
#pragma alloc_text(INIT,HalReportResourceUsage)
#pragma alloc_text(INIT,HalReportResourceUsage)
#pragma alloc_text(INIT,HalpInitOtherBuses)
#endif

/*++

Routine Description:

	This function is called to start the next processor.

Arguments:

	LoaderBlock - Supplies a pointer to the loader parameter block.

	ProcessorState - Supplies a pointer to the processor state to be
		used to start the processor.

Return Value:

	If a processor is successfully started, then a value of TRUE is
	returned. Otherwise a value of FALSE is returned. If a value of
	TRUE is returned, then the logical processor number is stored
	in the processor control block specified by the loader block.

--*/
BOOLEAN
HalStartNextProcessor (
	IN PLOADER_PARAMETER_BLOCK LoaderBlock,
	IN PKPROCESSOR_STATE ProcessorState
	)
{
	PRESTART_BLOCK pRB;
	ULONG Number;
	PKPRCB Prcb;
	char buf[128];

	HDBG(DBG_INTERNAL, HalpDebugPrint("HalpStartNextProcessor: called\n"););


    //
    // Check if UNIPROCESSOR is set and ignore all other processors,
	// this is done in a free HAL so that UP/MP performance measurements
	// can be taken.
    //
    if (HalGetEnvironmentVariable("UNIPROCESSOR", sizeof(buf), buf)
        == ESUCCESS) {
        if (_stricmp(buf, "true") == 0) {
            HalpDebugPrint("HalpStartNextProcessor: UNIPROCESSOR set\n");
            return FALSE;
        }
    }

	//
	// If there is more than one restart block then this is a multi-
	// processor system.
	//
	// N.B. The first restart parameter block must be for the boot master
	//		and must represent logical processor 0.
	//
	// Scan the restart parameter blocks for a processor that is ready,
	// but not running. If a processor is found, then fill in the restart
	// processor state, set the logical processor number, and set start
	// in the boot status.
	//
	pRB = SYSTEM_BLOCK->RestartBlock;
	Number = 0;
	while (pRB != NULL) {
		if ((pRB->BootStatus.ProcessorReady == TRUE) &&
			(pRB->BootStatus.ProcessorStart == FALSE)) {
			
			//
			// Assert that we think this is an MP capable machine
			//
			if (!(SystemDescription[SystemType].Flags&SYS_MPCAPABLE) ||
			   !(ProcessorDescription[ProcessorType].Flags&PROC_MPCAPABLE)) {
				HalpDebugPrint("HalStartNextProcessor: HAL/Veneer mismatch\n");
				KeBugCheck(MISMATCHED_HAL);
			}

			RtlZeroMemory(&pRB->u.Ppc, sizeof(PPC_RESTART_STATE));

			//
			// Set processor start address.
			//
			pRB->u.Ppc.Iar = ProcessorState->ContextFrame.Iar;
			pRB->u.Ppc.Msr = ProcessorState->ContextFrame.Msr;

			//
			// PowerPC linkage conventions pass parameters in registers
			// r.3 thru r.10.  Set all of them to allow as much flexibility
			// to the kernel as possible.
			//
			pRB->u.Ppc.IntR3 = ProcessorState->ContextFrame.Gpr3;
			pRB->u.Ppc.IntR4 = ProcessorState->ContextFrame.Gpr4;
			pRB->u.Ppc.IntR5 = ProcessorState->ContextFrame.Gpr5;
			pRB->u.Ppc.IntR6 = ProcessorState->ContextFrame.Gpr6;
			pRB->u.Ppc.IntR7 = ProcessorState->ContextFrame.Gpr7;
			pRB->u.Ppc.IntR8 = ProcessorState->ContextFrame.Gpr8;
			pRB->u.Ppc.IntR9 = ProcessorState->ContextFrame.Gpr9;
			pRB->u.Ppc.IntR10 =  ProcessorState->ContextFrame.Gpr10;

			Prcb = (PKPRCB)(LoaderBlock->Prcb);
			Prcb->Number = (CCHAR)Number;
			Prcb->RestartBlock = pRB;

			//
			// ARC interface is waiting for this bit to change
			// so change it.
			//
			pRB->BootStatus.ProcessorStart = TRUE;
			HDBG(DBG_GENERAL, 
				 HalpDebugPrint("HalStartNextProcessor: started Cpu (%d)\n",
								Number););
			return TRUE;
		}
		Number++;
		pRB = pRB->NextRestartBlock;
	}
	return FALSE;
}

BOOLEAN
HalAllProcessorsStarted(VOID)
{
	PRESTART_BLOCK pRB;
	ULONG	NumCpu=0;

	HDBG(DBG_INTERNAL, HalpDebugPrint("HalAllProcessorsStarted: called\n"););

	pRB = SYSTEM_BLOCK->RestartBlock;
	while (pRB != NULL) {
		if ((pRB->BootStatus.ProcessorReady == TRUE) &&
			(pRB->BootStatus.ProcessorStart == FALSE))
			HDBG(DBG_GENERAL,HalpDebugPrint(
				"HalAllProcessorsStarted: NT disabled processor %d\n",NumCpu););
		NumCpu++;
		pRB = pRB->NextRestartBlock;
	}
	HDBG(DBG_GENERAL, 
		 HalpDebugPrint("HalAllProcessorsStarted: return TRUE\n"););
	return TRUE;
}

VOID
HalReportResourceUsage(VOID)
{
        extern VOID HalpSetUpFirePowerRegistry(VOID);
	INTERFACE_TYPE  interfacetype;
	ANSI_STRING		AHalName;
	UNICODE_STRING  UHalName;

	interfacetype = Internal;

	RtlInitAnsiString (&AHalName, HalName);
	RtlAnsiStringToUnicodeString (&UHalName, &AHalName, TRUE);
	HalpReportResourceUsage(&UHalName, interfacetype);

	interfacetype = Isa;
	HalpReportResourceUsage (&UHalName, interfacetype);
	RtlFreeUnicodeString (&UHalName);

	//
	// Registry is now intialized, see if there are any PCI buses
	//
	HalpInitializePciBus ();


        HalpSetUpFirePowerRegistry(); // in fprgstry.c
}

ULONG
HalpProcessorCount()
{
	PRESTART_BLOCK pRB;
	static ULONG Count = 0;

	if (Count)
		return(Count);

	pRB = SYSTEM_BLOCK->RestartBlock;
	while (pRB != NULL) {
		if ((pRB->BootStatus.ProcessorReady == TRUE) &&
				(pRB->BootStatus.ProcessorStart == TRUE)) 
			Count++;
		pRB = pRB->NextRestartBlock;
	}
	return Count;
}

VOID
HalpInitOtherBuses(VOID)
{
	// no other internal buses supported
}