ReactOS  0.4.15-dev-5452-g3c95c95
hwpci.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for hwpci.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (HWDETECT)
 
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable (VOID)
 
BOOLEAN PcFindPciBios (PPCI_REGISTRY_INFO BusData)
 
static VOID DetectPciIrqRoutingTable (PCONFIGURATION_COMPONENT_DATA BusKey)
 
VOID DetectPciBios (PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 

Variables

FIND_PCI_BIOS FindPciBios = NULL
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DetectPciBios()

VOID DetectPciBios ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)

Definition at line 176 of file hwpci.c.

177 {
178  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
179  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
180  PCI_REGISTRY_INFO BusData;
182  ULONG Size;
184  ULONG i;
185 
186  /* Report the PCI BIOS */
187  if (FindPciBios(&BusData))
188  {
189  /* Set 'Configuration Data' value */
190  Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
191  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
192  if (PartialResourceList == NULL)
193  {
194  ERR("Failed to allocate resource descriptor\n");
195  return;
196  }
197 
198  /* Initialize resource descriptor */
199  RtlZeroMemory(PartialResourceList, Size);
200 
201  /* Create new bus key */
202  FldrCreateComponentKey(SystemKey,
203  AdapterClass,
204  MultiFunctionAdapter,
205  0x0,
206  0x0,
207  0xFFFFFFFF,
208  "PCI BIOS",
209  PartialResourceList,
210  Size,
211  &BiosKey);
212 
213  /* Increment bus number */
214  (*BusNumber)++;
215 
216  DetectPciIrqRoutingTable(BiosKey);
217 
218  /* Report PCI buses */
219  for (i = 0; i < (ULONG)BusData.NoBuses; i++)
220  {
221  /* Check if this is the first bus */
222  if (i == 0)
223  {
224  /* Set 'Configuration Data' value */
226  PartialDescriptors) +
228  sizeof(PCI_REGISTRY_INFO);
229  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
230  if (!PartialResourceList)
231  {
232  ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
233  i, (ULONG)BusData.NoBuses);
234  return;
235  }
236 
237  /* Initialize resource descriptor */
238  RtlZeroMemory(PartialResourceList, Size);
239  PartialResourceList->Version = 1;
240  PartialResourceList->Revision = 1;
241  PartialResourceList->Count = 1;
242  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
243  PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
244  PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
245  PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(PCI_REGISTRY_INFO);
246  memcpy(&PartialResourceList->PartialDescriptors[1],
247  &BusData,
248  sizeof(PCI_REGISTRY_INFO));
249  }
250  else
251  {
252  /* Set 'Configuration Data' value */
254  PartialDescriptors);
255  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
256  if (!PartialResourceList)
257  {
258  ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
259  i, (ULONG)BusData.NoBuses);
260  return;
261  }
262 
263  /* Initialize resource descriptor */
264  RtlZeroMemory(PartialResourceList, Size);
265  }
266 
267  /* Create the bus key */
268  FldrCreateComponentKey(SystemKey,
269  AdapterClass,
270  MultiFunctionAdapter,
271  0x0,
272  0x0,
273  0xFFFFFFFF,
274  "PCI",
275  PartialResourceList,
276  Size,
277  &BusKey);
278 
279  /* Increment bus number */
280  (*BusNumber)++;
281  }
282  }
283 }
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
GLint x0
Definition: linetemp.h:95
struct _PCI_REGISTRY_INFO PCI_REGISTRY_INFO
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
static VOID DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: hwpci.c:117
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@381::@390 DeviceSpecificData
FIND_PCI_BIOS FindPciBios
Definition: hwpci.c:26
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:174
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID NTAPI FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode, IN CONFIGURATION_CLASS Class, IN CONFIGURATION_TYPE Type, IN IDENTIFIER_FLAG Flags, IN ULONG Key, IN ULONG Affinity, IN PCHAR IdentifierString, IN PCM_PARTIAL_RESOURCE_LIST ResourceList, IN ULONG Size, OUT PCONFIGURATION_COMPONENT_DATA *ComponentKey)
Definition: archwsup.c:147
#define ERR(fmt,...)
Definition: debug.h:110
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
UCHAR NoBuses
Definition: pci.h:109
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@381 u
#define TAG_HW_RESOURCE_LIST
Definition: hardware.h:23

Referenced by Pc98HwDetect(), PcHwDetect(), and XboxHwDetect().

◆ DetectPciIrqRoutingTable()

static VOID DetectPciIrqRoutingTable ( PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 117 of file hwpci.c.

118 {
119  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
120  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
123  ULONG Size;
124 
126  if (Table != NULL)
127  {
128  TRACE("Table size: %u\n", Table->TableSize);
129 
130  /* Set 'Configuration Data' value */
131  Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
132  2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->TableSize;
133  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
134  if (PartialResourceList == NULL)
135  {
136  ERR("Failed to allocate resource descriptor\n");
137  return;
138  }
139 
140  /* Initialize resource descriptor */
141  RtlZeroMemory(PartialResourceList, Size);
142  PartialResourceList->Version = 1;
143  PartialResourceList->Revision = 1;
144  PartialResourceList->Count = 2;
145 
146  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
147  PartialDescriptor->Type = CmResourceTypeBusNumber;
149  PartialDescriptor->u.BusNumber.Start = 0;
150  PartialDescriptor->u.BusNumber.Length = 1;
151 
152  PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
153  PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
154  PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
155  PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize;
156 
157  memcpy(&PartialResourceList->PartialDescriptors[2],
158  Table,
159  Table->TableSize);
160 
161  FldrCreateComponentKey(BusKey,
163  RealModeIrqRoutingTable,
164  0x0,
165  0x0,
166  0xFFFFFFFF,
167  "PCI Real-mode IRQ Routing Table",
168  PartialResourceList,
169  Size,
170  &TableKey);
171  }
172 }
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
ASMGENDATA Table[]
Definition: genincdata.c:61
GLint x0
Definition: linetemp.h:95
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable(VOID)
Definition: hwpci.c:30
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@381::@390 DeviceSpecificData
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:174
#define TRACE(s)
Definition: solgame.cpp:4
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID NTAPI FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode, IN CONFIGURATION_CLASS Class, IN CONFIGURATION_TYPE Type, IN IDENTIFIER_FLAG Flags, IN ULONG Key, IN ULONG Affinity, IN PCHAR IdentifierString, IN PCM_PARTIAL_RESOURCE_LIST ResourceList, IN ULONG Size, OUT PCONFIGURATION_COMPONENT_DATA *ComponentKey)
Definition: archwsup.c:147
#define ERR(fmt,...)
Definition: debug.h:110
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@381::@389 BusNumber
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CmResourceTypeBusNumber
Definition: hwresource.cpp:128
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@381 u
#define TAG_HW_RESOURCE_LIST
Definition: hardware.h:23

Referenced by DetectPciBios().

◆ GetPciIrqRoutingTable()

static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable ( VOID  )
static

Definition at line 30 of file hwpci.c.

31 {
33  PUCHAR Ptr;
34  ULONG Sum;
35  ULONG i;
36 
37  Table = (PPCI_IRQ_ROUTING_TABLE)0xF0000;
38  while ((ULONG_PTR)Table < 0x100000)
39  {
40  if (Table->Signature == 'RIP$')
41  {
42  TRACE("Found signature\n");
43 
44  if (Table->TableSize < FIELD_OFFSET(PCI_IRQ_ROUTING_TABLE, Slot) ||
45  Table->TableSize % 16 != 0)
46  {
47  ERR("Invalid routing table size (%u) at 0x%p. Continue searching...\n", Table->TableSize, Table);
49  continue;
50  }
51 
52  Ptr = (PUCHAR)Table;
53  Sum = 0;
54  for (i = 0; i < Table->TableSize; i++)
55  {
56  Sum += Ptr[i];
57  }
58 
59  if ((Sum & 0xFF) != 0)
60  {
61  ERR("Invalid routing table checksum (%#lx) at 0x%p. Continue searching...\n", Sum & 0xFF, Table);
62  }
63  else
64  {
65  TRACE("Valid checksum (%#lx): found routing table at 0x%p\n", Sum & 0xFF, Table);
66  return Table;
67  }
68  }
69 
71  }
72 
73  ERR("No valid routing table found!\n");
74 
75  return NULL;
76 }
ASMGENDATA Table[]
Definition: genincdata.c:61
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define TRACE(s)
Definition: solgame.cpp:4
struct _PCI_IRQ_ROUTING_TABLE * PPCI_IRQ_ROUTING_TABLE
#define ERR(fmt,...)
Definition: debug.h:110
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by DetectPciIrqRoutingTable().

◆ PcFindPciBios()

BOOLEAN PcFindPciBios ( PPCI_REGISTRY_INFO  BusData)

Definition at line 80 of file hwpci.c.

81 {
82  REGS RegsIn;
83  REGS RegsOut;
84 
85  RegsIn.b.ah = 0xB1; /* Subfunction B1h */
86  RegsIn.b.al = 0x01; /* PCI BIOS present */
87 
88  Int386(0x1A, &RegsIn, &RegsOut);
89 
90  if (INT386_SUCCESS(RegsOut) &&
91  (RegsOut.d.edx == ' ICP') &&
92  (RegsOut.b.ah == 0))
93  {
94  TRACE("Found PCI bios\n");
95 
96  TRACE("AL: %x\n", RegsOut.b.al);
97  TRACE("BH: %x\n", RegsOut.b.bh);
98  TRACE("BL: %x\n", RegsOut.b.bl);
99  TRACE("CL: %x\n", RegsOut.b.cl);
100 
101  BusData->NoBuses = RegsOut.b.cl + 1;
102  BusData->MajorRevision = RegsOut.b.bh;
103  BusData->MinorRevision = RegsOut.b.bl;
104  BusData->HardwareMechanism = RegsOut.b.al;
105 
106  return TRUE;
107  }
108 
109  TRACE("No PCI bios found\n");
110 
111  return FALSE;
112 }
#define TRUE
Definition: types.h:120
UCHAR HardwareMechanism
Definition: pci.h:110
unsigned char ah
Definition: pcbios.h:132
UCHAR MinorRevision
Definition: pci.h:108
int __cdecl Int386(int ivec, REGS *in, REGS *out)
#define FALSE
Definition: types.h:117
UCHAR MajorRevision
Definition: pci.h:107
#define INT386_SUCCESS(regs)
Definition: pcbios.h:179
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char bl
Definition: pcbios.h:134
unsigned char cl
Definition: pcbios.h:137
BYTEREGS b
Definition: pcbios.h:163
unsigned char al
Definition: pcbios.h:131
DWORDREGS d
Definition: pcbios.h:161
unsigned char bh
Definition: pcbios.h:135
UCHAR NoBuses
Definition: pci.h:109
Definition: pcbios.h:158
unsigned long edx
Definition: pcbios.h:94

Referenced by Pc98HwDetect(), and PcHwDetect().

Variable Documentation

◆ FindPciBios

FIND_PCI_BIOS FindPciBios = NULL

Definition at line 26 of file hwpci.c.

Referenced by DetectPciBios(), Pc98HwDetect(), PcHwDetect(), and XboxHwDetect().