summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halfire/ppc/pxpcisup.c
blob: eecaa1e35b73937af3798345b6f7da44db0175ba (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
/*
 * Copyright (c) 1995 FirePower Systems, Inc.
 * DO NOT DISTRIBUTE without permission
 *
 * $RCSfile: pxpcisup.c $
 * $Revision: 1.18 $
 * $Date: 1996/05/14 02:35:00 $
 * $Locker:  $
 */

/*++

Copyright (c) 1990  Microsoft Corporation

Copyright (c) 1994 MOTOROLA, INC.  All Rights Reserved.  This file
contains copyrighted material.  Use of this file is restricted
by the provisions of a Motorola Software License Agreement.

Module Name:

    pxmemctl.c

Abstract:

    The module initializes any planar registers.
    This module also implements machince check parity error handling.

Author:

    Jim Wooldridge (jimw@austin.vnet.ibm.com)


Revision History:



--*/

#include "halp.h"
#include "pci.h"
#include "pcip.h"
#include "pxpcisup.h"
#include "stdio.h"
#include "fpdebug.h"
#include "phsystem.h"

extern PVOID HalpPciConfigBase;
extern UCHAR PciDevicePrimaryInts[];
extern ULONG HalpGetPciInterruptSlot( PBUS_HANDLER, PCI_SLOT_NUMBER );

#define LX_PCI_INTERRUPT_ROUTING_SLOT0 25
#define LX_PCI_INTERRUPT_ROUTING_SLOT1 22
#define LX_PCI_INTERRUPT_ROUTING_SLOT2 23
#define LX_PCI_INTERRUPT_ROUTING_SLOT3 26
#define LX_PCI_INTERRUPT_ROUTING_IDEA  21
#define LX_PCI_INTERRUPT_ROUTING_IDEB  20

#define PCI_INTERRUPT_ROUTING_SLOT0		0x16	// phys dev# 2, logical 1
#define PCI_INTERRUPT_ROUTING_SLOT1		0x17	// phys dev# 3, logical 2
#define PCI_INTERRUPT_ROUTING_SCSI		0x19	// phys dev# 1, logical 3
#define PCI_INTERRUPT_ROUTING_ETHERNET	0x1a	// phys dev# 4, logical 4
#define IRQ_INVALID						0x0		// goes with IRQ_VALID defines

ULONG HalpPciConfigSlot[] = {	0x0800,		// phys dev# 0: SIO chip
								0x1000,		// phys dev# 1: mobo scsi
								0x2000,		// phys dev# 2: peripheral plug in
								0x4000,		// phys dev# 3: peripheral plug in
								0x8000		// phys dev# 4: mobo ethernet

								,0x10000,	// IDE_IntA
								0x20000		// IDE_IntB

							};



/*++

Routine Description: ULONG HalpTranslatePciSlotNumber ()

    This routine translate a PCI slot number to a PCI device number.
    This is a sandalfoot memory map implementation.

Arguments:

    None.

Return Value:

    Returns length of data written.

--*/

ULONG
HalpTranslatePciSlotNumber (
    ULONG BusNumber,
    ULONG SlotNumber
    )
{
   //
   // Sandalfoot only has 1 PCI bus so bus number is unused
   //

   UNREFERENCED_PARAMETER(BusNumber);

   return ((ULONG) ((PUCHAR) HalpPciConfigBase + HalpPciConfigSlot[SlotNumber]));

}



/*++

Routine Description: ULONG HalpPhase0SetPciDataByOffset ()

    This routine writes to PCI configuration space prior to bus handler installation.

Arguments:

    None.

Return Value:

    Returns length of data written.

--*/

ULONG
HalpPhase0SetPciDataByOffset (
    ULONG BusNumber,
    ULONG SlotNumber,
    PUCHAR Buffer,
    ULONG Offset,
    ULONG Length
    )
{
   PUCHAR to;
   PUCHAR from;
   ULONG tmpLength;

   if (SlotNumber < MAXIMUM_PCI_SLOTS) {

      to = (PUCHAR)HalpPciConfigBase + HalpPciConfigSlot[SlotNumber];
      to += Offset;
      from = Buffer;
      tmpLength = Length;
      while (tmpLength > 0) {
         *to++ = *from++;
         tmpLength--;
      }
      return(Length);
   }
   else {
      return (0);
   }
}


/*++

Routine Description: ULONG HalpPhase0GetPciDataByOffset ()

    This routine reads PCI config space prior to bus handlder installation.

Arguments:

    None.

Return Value:

    Amount of data read.

--*/

ULONG
HalpPhase0GetPciDataByOffset (
    ULONG BusNumber,
    ULONG SlotNumber,
    PUCHAR Buffer,
    ULONG Offset,
    ULONG Length
    )
{
   PUCHAR to;
   PUCHAR from;
   ULONG tmpLength;

   if (SlotNumber < MAXIMUM_PCI_SLOTS) {

      from = (PUCHAR)HalpPciConfigBase + HalpPciConfigSlot[SlotNumber];
      from += Offset;
      to = Buffer;
      tmpLength = Length;
      while (tmpLength > 0) {
         *to++ = *from++;
         tmpLength--;
      }
      return(Length);
   }
   else {
      return (0);
   }
}

NTSTATUS
HalpGetISAFixedPCIIrq (
	IN PBUS_HANDLER		BusHandler,
	IN PBUS_HANDLER		RootHandler,
	IN PCI_SLOT_NUMBER  PciSlot,
	OUT PUCHAR			IrqTable
	)
{
	UCHAR					buffer[PCI_COMMON_HDR_LENGTH];
	PPCI_COMMON_CONFIG		PciData;
	ULONG					slot;
	ULONG					interrupt;

	PciData = (PPCI_COMMON_CONFIG) buffer;
	HalGetBusData (
		PCIConfiguration,
		BusHandler->BusNumber,
		PciSlot.u.AsULONG,
		PciData,
		PCI_COMMON_HDR_LENGTH
		);

	HDBG(DBG_INTERRUPTS,
		HalpDebugPrint("HalpGetISAFixedPCIIrq: %x, %x, %x, %x %x \n",
						PCIConfiguration,
						BusHandler->BusNumber,
						PciSlot.u.AsULONG,
						PciData,
						PCI_COMMON_HDR_LENGTH ));

	if (PciData->VendorID == PCI_INVALID_VENDORID  ||
		PCI_CONFIG_TYPE (PciData) != 0) {
		return STATUS_UNSUCCESSFUL;
	}

	// For Primary PCI slots, the interrupt corresponds to the primary
	// slot number
    if ( BusHandler->BusNumber == 0 ) {
		slot = PciSlot.u.bits.DeviceNumber;
	} 
	// For Secondary PCI slots, the interrupt corresponds to the slot
	// number of the primary parent
	else {
		slot = HalpGetPciInterruptSlot(BusHandler, PciSlot );
    }

	// Search the interrupt table for the interrupt corresponding to the slot
	if (slot < MAXIMUM_PCI_SLOTS) {
		interrupt = PciDevicePrimaryInts[slot];
		if (interrupt != INVALID_INT) {
			IrqTable[interrupt] = IRQ_VALID;
		} else {
			return STATUS_UNSUCCESSFUL;
		}
	} else {
		return STATUS_UNSUCCESSFUL;
	}

    HDBG(DBG_INTERRUPTS,
	    HalpDebugPrint("HalpGetISAFixedPCIIrq: index = 0x%x \n",
            PciSlot.u.bits.DeviceNumber););
	return STATUS_SUCCESS;
}