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
|
/*++
Copyright (c) 2010 WonderMedia Technologies, Inc.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details. You
should have received a copy of the GNU General Public License along with this
program. If not, see http://www.gnu.org/licenses/>.
WonderMedia Technologies, Inc.
10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
--*/
#if !defined(__UASSERT_H__)
#include "uassert.h"
#endif
#if !defined(__UPC_H__)
#include "upc.h"
#endif
#if !defined(__TMACRO_H__)
#include "tmacro.h"
#endif
#if !defined(__TPCI_H__)
#include "tpci.h"
#endif
#if !defined(__UPCIX_H__)
#include "upcix.h"
#endif
#if !defined(__TBIT_H__)
#include "tbit.h"
#endif
/*--------------------- Static Definitions -------------------------*/
/* PCI configuration space IO port */
#define PCI_INDEX 0xC0000CF8
#define PCI_DATA 0xC0000CFC
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
/*--------------------- Export Variables --------------------------*/
/*--------------------- Import Functions --------------------------*/
VOID PCIXvReadB(WORD wBusDevFunId, BYTE byRegOffset, PBYTE pbyData)
{
DWORD dwIndex;
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvInPortB(PCI_DATA + (byRegOffset % 4), pbyData);
}
VOID PCIXvReadW(WORD wBusDevFunId, BYTE byRegOffset, PWORD pwData)
{
DWORD dwIndex;
/* must word alignment */
DBG_ASSERT((byRegOffset % 2) == 0);
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvInPortW(PCI_DATA + (byRegOffset % 4), pwData);
}
VOID PCIXvReadD(WORD wBusDevFunId, BYTE byRegOffset, PDWORD pdwData)
{
DWORD dwIndex;
/* must dword alignment */
DBG_ASSERT((byRegOffset % 4) == 0);
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvInPortD(PCI_DATA, pdwData);
}
VOID PCIXvWriteB(WORD wBusDevFunId, BYTE byRegOffset, BYTE byData)
{
DWORD dwIndex;
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvOutPortB(PCI_DATA + (byRegOffset % 4), byData);
}
VOID PCIXvWriteW(WORD wBusDevFunId, BYTE byRegOffset, WORD wData)
{
DWORD dwIndex;
/* must word alignment */
DBG_ASSERT((byRegOffset % 2) == 0);
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvOutPortW(PCI_DATA + (byRegOffset % 4), wData);
}
VOID PCIXvWriteD(WORD wBusDevFunId, BYTE byRegOffset, DWORD dwData)
{
DWORD dwIndex;
/* must dword alignment */
DBG_ASSERT((byRegOffset % 4) == 0);
dwIndex = wBusDevFunId;
dwIndex = 0x80000000L | (dwIndex << 8) | (byRegOffset & 0xFC);
PCBvOutPortD(PCI_INDEX, dwIndex);
PCBvOutPortD(PCI_DATA, dwData);
}
VOID PCIXvReadManyBytes(WORD wBusDevFunId, BYTE byRegOffset, PBYTE pbyBuffer, WORD wCount)
{
WORD wIdx;
PBYTE pbyTmpBuf = pbyBuffer;
for (wIdx = 0; wIdx < wCount; wIdx++, pbyTmpBuf++)
PCIXvReadB(wBusDevFunId, (BYTE)(byRegOffset + wIdx), pbyTmpBuf);
}
BOOL PCIXbFindDeviceInfo(DWORD dwDevVenID, PBYTE pbyBusNum,
PBYTE pbySlotNum, PBYTE pbyFuncNum, PBYTE pbyRevId, PDWORD pdwIoBase,
PDWORD pdwIoSpaceRange, PBYTE pbyIrqNo)
{
DWORD dwCurrDevVenID;
BYTE byBusNum = *pbyBusNum;
BYTE bySlotNum = *pbySlotNum;
BYTE byFuncNum = *pbyFuncNum;
BOOL bMultiFunc;
BYTE byData;
int i;
for (i = byBusNum; i < MAX_PCI_BUS; i++) {
byBusNum = (BYTE)i;
for ( ; bySlotNum < MAX_PCI_DEVICE; bySlotNum++) {
PCIXvReadB(MAKE_BDF_TO_WORD(byBusNum, bySlotNum, 0), PCI_REG_HDR_TYPE, &byData);
bMultiFunc = BITbIsAllBitsOn(byData, 0x80);
for ( ; byFuncNum < ((bMultiFunc) ? 8 : 1); byFuncNum++) {
PCIXvReadD(MAKE_BDF_TO_WORD(byBusNum, bySlotNum, byFuncNum),
PCI_REG_VENDOR_ID, &dwCurrDevVenID);
/* is this our device? */
if (dwCurrDevVenID == dwDevVenID) {
PCIXvReadB(MAKE_BDF_TO_WORD(byBusNum, bySlotNum, byFuncNum),
PCI_REG_REV_ID, pbyRevId);
PCIXvReadD(MAKE_BDF_TO_WORD(byBusNum, bySlotNum, byFuncNum),
PCI_REG_BAR0, pdwIoBase);
*pdwIoBase = (*pdwIoBase) & 0xFFFFFFFEUL;
/* IO space range: */
/* 43:0x80(128B), 65:0x100(256B) */
if (*pbyRevId < 0x40)
*pdwIoSpaceRange = 0x00000080L;
else
*pdwIoSpaceRange = 0x00000100L;
PCIXvReadB(MAKE_BDF_TO_WORD(byBusNum, bySlotNum, byFuncNum),
PCI_REG_INT_LINE, pbyIrqNo);
*pbyBusNum = byBusNum;
*pbySlotNum = bySlotNum;
*pbyFuncNum = byFuncNum;
return TRUE;
}
}
byFuncNum = 0;
}
bySlotNum = 0;
}
return FALSE;
}
|