summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halncr/i386/ncrqic.c
blob: 197acb3bd96adbf86831217cc0b2a833a81e68d6 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*++

Copyright (c) 1992  NCR Corporation

Module Name:

    ncrqic.c

Abstract:


Author:

    Rick Ulmer

Environment:

    Kernel mode only.

Revision History:

--*/

#include "halp.h"
#include "ncr.h"
#include "ncrsus.h"
#include "stdio.h"

PQIC_IPI    IpiAddresses[NCR_MAX_NUMBER_QUAD_PROCESSORS];
PQIC_IPI    PhysicalIpiAddresses[NCR_MAX_NUMBER_QUAD_PROCESSORS];

extern PPROCESSOR_BOARD_INFO   SUSBoardInfo;
extern ULONG	NCRLogicalDyadicProcessorMask;
extern ULONG	NCRLogicalQuadProcessorMask;
extern ULONG	NCRLogicalNumberToPhysicalMask[];
extern ULONG	NCRExistingQuadProcessorMask;

extern ULONG	NCRActiveProcessorMask;

ULONG   NCRQicSpurCount = 0;


VOID
HalQicRequestIpi (
    IN KAFFINITY Mask,
    IN ULONG Level
    );

VOID
HalRequestIpi (
    IN KAFFINITY Mask
    )
/*++

Routine Description:
    Send Ipi's to processors

Arguments:
    Processors Mask;

Return Value:
    none.

--*/

{
	if (Mask & NCRLogicalDyadicProcessorMask) {
		HalVicRequestIpi(Mask & NCRLogicalDyadicProcessorMask);
	}

	if (Mask & NCRLogicalQuadProcessorMask) {
	    HalQicRequestIpi(Mask & NCRLogicalQuadProcessorMask, NCR_IPI_LEVEL_CPI);
	}
}


VOID
HalQicRequestIpi (
    IN KAFFINITY Mask,
    IN ULONG    Level
    )
/*++

Routine Description:
    Send Ipi's to processors

Arguments:
    Processors Mask;

Return Value:
    none.

--*/

{
    PKPCR   pPCR;
    ULONG   my_logical_mask;

    PQIC_IPI IpiAddress;
    ULONG   logical_mask;
    ULONG   cpu_id;


    pPCR = KeGetPcr();
    my_logical_mask = ((PProcessorPrivateData)pPCR->HalReserved)->MyLogicalMask;

    logical_mask = Mask;

    cpu_id = 0;
    
	//
	// See if we need to send the cpi two ourselves
	//

	if (my_logical_mask & logical_mask) {
		WRITE_PORT_UCHAR((PUCHAR)(0xFCC0+(0x8*Level)),0x1);
		logical_mask ^= my_logical_mask;
	}


	//
	// Now send to all other processors
	//

    while (logical_mask) {
        if (logical_mask & 0x01) {
            IpiAddress = IpiAddresses[cpu_id];
            IpiAddress->QIC_LEVEL[Level].Ipi = 1;
        }
        cpu_id++;
        logical_mask >>= 1;
    }
}



VOID
HalQicStartupIpi (
    ULONG   ProcessorNumber
    )
/*++

Routine Description:
    Send Ipi's to processors

Arguments:
    Processors Mask;

Return Value:
    none.

--*/

{
    register QIC_IPI    *IpiAddress;

    IpiAddress = PhysicalIpiAddresses[ProcessorNumber];
    IpiAddress->QIC_LEVEL[2].Ipi = 1;
}




ULONG
NCRClearQicIpi (
    IN Level
    )
/*++

Routine Description:
    Send Ipi's to processors

Arguments:
    Processors Mask;

Return Value:
    none.

--*/

{
    PKPCR   pPCR;
    ULONG   my_logical_number;
    register QIC_IPI    *IpiAddress;


    pPCR = KeGetPcr();
    my_logical_number = ((PProcessorPrivateData)pPCR->HalReserved)->MyLogicalNumber;

//
// Clear the interrupt
//

    WRITE_PORT_UCHAR((PUCHAR)0xfc8b, (UCHAR) (0x1<<Level));

// there is some window during bootup where we are hitting this code before
// IpiAddresses is filled in

    IpiAddress = IpiAddresses[my_logical_number];

    return (IpiAddress->QIC_LEVEL[Level].Ipi);
}



VOID
NCRFindIpiAddress (
    ULONG   ProcessorNumber
    )

{    
	ULONG	physical_processor_number;
	ULONG	physical_mask;
	ULONG	mask;
	ULONG	i;

	physical_mask = NCRLogicalNumberToPhysicalMask[ProcessorNumber];

	physical_processor_number = 0;

	for ( mask = 0x1; mask < (0x1 << NCR_MAX_NUMBER_PROCESSORS); mask <<= 1, physical_processor_number++) {
		if (mask & physical_mask) {
			break;
		}
	}
	IpiAddresses[ProcessorNumber] = PhysicalIpiAddresses[physical_processor_number];
}





VOID
NCRMapIpiAddresses (
    )

{
    ULONG   i;
    PQUAD_DESCRIPTION       quad_desc;
    PCHAR    cpiaddr[8] = {0};
    ULONG    cpipage[8] = {0};
    ULONG   modules;
    ULONG   slot;
    ULONG   cpu_offset;
    ULONG   proc_id;
	ULONG	physical_processor_number;
	ULONG	mask;

	if (NCRExistingQuadProcessorMask == 0) {
		return;
	}

	physical_processor_number = 0;

	for ( mask = NCRExistingQuadProcessorMask; mask != 0; mask >>= 1, physical_processor_number++) {

		if (!(mask & 1)) {
			continue;
		}

	    slot = (physical_processor_number / 4);
	    proc_id = physical_processor_number % 4;

	    DBGMSG(("NCRMapIpiAddress: Physical Proc 0x%x, slot = 0x%x, proc_id = 0x%x\n", 
	    						physical_processor_number, slot, proc_id));
    
	    modules = SUSBoardInfo->NumberOfBoards;
	    quad_desc = SUSBoardInfo->QuadData;

	    cpu_offset = proc_id * 0x100;

	    DBGMSG(("NCRMapIpiAddress: modules = %d\n",modules));

	    for ( i = 0; i < modules; quad_desc++, i++) {

	        DBGMSG(("NCRMapIpiAddress: quad_desc Type = 0x%x, slot = 0x%x\n",quad_desc->Type, quad_desc->Slot));

	        if ( quad_desc->Slot == (slot+1)) {
	            if (quad_desc->Type == QUAD ) {
	                if (cpipage[slot] == 0 ) {
	                    cpipage[slot] = (ULONG) quad_desc->IpiBaseAddress & ~POFFMASK;
	                    cpiaddr[slot] = HalpMapPhysicalMemory(cpipage[slot],1);
	                }
	                PhysicalIpiAddresses[physical_processor_number] = 
	                    cpiaddr[slot]+(cpu_offset+(quad_desc->IpiBaseAddress & POFFMASK));

	                DBGMSG(("NCRMapIpiAddress: Proc %d, Address = 0x%x\n", 
	                                            physical_processor_number,
	                                            PhysicalIpiAddresses[physical_processor_number]));

	                break;
	            } else {
	                break;
	            }
	        }
	    }
   	}
}


VOID
NCRHandleQicSpuriousInt (TrapFramePtr, ExceptionRecordPtr)
IN PKTRAP_FRAME     TrapFramePtr;
IN PVOID        ExceptionRecordPtr;
/*++

Routine Description:
    Handles the NCR Qic Spurious interrupts

Arguments:

Return Value:
    none.

--*/
{
	UCHAR	qic_irr0;
	UCHAR	qic_irr1;

	NCRQicSpurCount++;

#ifdef NEVER
	qic_irr0 = READ_PORT_UCHAR(0xfc82);
	qic_irr1 = READ_PORT_UCHAR(0xfc83);

    DBGMSG(("NCRHandleQicSpurious: Count %d, QicIrr0 = 0x%x, QicIrr1 = 0x%x\n", 
                                NCRQicSpurCount, qic_irr0, qic_irr1));
#endif
}