ReactOS  0.4.13-dev-257-gfabbd7c
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)
 
static BOOLEAN FindPciBios (PPCI_REGISTRY_INFO BusData)
 
static VOID DetectPciIrqRoutingTable (PCONFIGURATION_COMPONENT_DATA BusKey)
 
VOID DetectPciBios (PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DetectPciBios()

VOID DetectPciBios ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)

Definition at line 175 of file hwpci.c.

176 {
177  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
178  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
179  PCI_REGISTRY_INFO BusData;
181  ULONG Size;
183  ULONG i;
184 
185  /* Report the PCI BIOS */
186  if (FindPciBios(&BusData))
187  {
188  /* Set 'Configuration Data' value */
189  Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
190  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
191  if (PartialResourceList == NULL)
192  {
193  ERR("Failed to allocate resource descriptor\n");
194  return;
195  }
196 
197  /* Initialize resource descriptor */
198  memset(PartialResourceList, 0, Size);
199 
200  /* Create new bus key */
201  FldrCreateComponentKey(SystemKey,
202  AdapterClass,
203  MultiFunctionAdapter,
204  0x0,
205  0x0,
206  0xFFFFFFFF,
207  "PCI BIOS",
208  PartialResourceList,
209  Size,
210  &BiosKey);
211 
212  /* Increment bus number */
213  (*BusNumber)++;
214 
215  DetectPciIrqRoutingTable(BiosKey);
216 
217  /* Report PCI buses */
218  for (i = 0; i < (ULONG)BusData.NoBuses; i++)
219  {
220  /* Check if this is the first bus */
221  if (i == 0)
222  {
223  /* Set 'Configuration Data' value */
225  PartialDescriptors) +
227  sizeof(PCI_REGISTRY_INFO);
228  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
229  if (!PartialResourceList)
230  {
231  ERR("Failed to allocate resource descriptor\n");
232  return;
233  }
234 
235  /* Initialize resource descriptor */
236  memset(PartialResourceList, 0, Size);
237  PartialResourceList->Version = 1;
238  PartialResourceList->Revision = 1;
239  PartialResourceList->Count = 1;
240  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
241  PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
242  PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
243  PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(PCI_REGISTRY_INFO);
244  memcpy(&PartialResourceList->PartialDescriptors[1],
245  &BusData,
246  sizeof(PCI_REGISTRY_INFO));
247  }
248  else
249  {
250  /* Set 'Configuration Data' value */
252  PartialDescriptors);
253  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
254  if (!PartialResourceList)
255  {
256  ERR("Failed to allocate resource descriptor\n");
257  return;
258  }
259 
260  /* Initialize resource descriptor */
261  memset(PartialResourceList, 0, Size);
262  }
263 
264  /* Create the bus key */
265  FldrCreateComponentKey(SystemKey,
266  AdapterClass,
267  MultiFunctionAdapter,
268  0x0,
269  0x0,
270  0xFFFFFFFF,
271  "PCI",
272  PartialResourceList,
273  Size,
274  &BusKey);
275 
276  /* Increment bus number */
277  (*BusNumber)++;
278  }
279  }
280 }
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
GLint x0
Definition: linetemp.h:95
struct _PCI_REGISTRY_INFO PCI_REGISTRY_INFO
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@369 u
static VOID DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: hwpci.c:116
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
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
smooth NULL
Definition: ftsmooth.c:416
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@369::@378 DeviceSpecificData
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:163
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
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:109
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
static BOOLEAN FindPciBios(PPCI_REGISTRY_INFO BusData)
Definition: hwpci.c:79
UCHAR NoBuses
Definition: pci.h:109
unsigned int ULONG
Definition: retypes.h:1
#define memset(x, y, z)
Definition: compat.h:39
#define TAG_HW_RESOURCE_LIST
Definition: hardware.h:26

Referenced by PcHwDetect().

◆ DetectPciIrqRoutingTable()

static VOID DetectPciIrqRoutingTable ( PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 116 of file hwpci.c.

117 {
118  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
119  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
122  ULONG Size;
123 
125  if (Table != NULL)
126  {
127  TRACE("Table size: %u\n", Table->TableSize);
128 
129  /* Set 'Configuration Data' value */
130  Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
131  2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->TableSize;
132  PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
133  if (PartialResourceList == NULL)
134  {
135  ERR("Failed to allocate resource descriptor\n");
136  return;
137  }
138 
139  /* Initialize resource descriptor */
140  memset(PartialResourceList, 0, Size);
141  PartialResourceList->Version = 1;
142  PartialResourceList->Revision = 1;
143  PartialResourceList->Count = 2;
144 
145  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
146  PartialDescriptor->Type = CmResourceTypeBusNumber;
148  PartialDescriptor->u.BusNumber.Start = 0;
149  PartialDescriptor->u.BusNumber.Length = 1;
150 
151  PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
152  PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
153  PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
154  PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize;
155 
156  memcpy(&PartialResourceList->PartialDescriptors[2],
157  Table,
158  Table->TableSize);
159 
160  FldrCreateComponentKey(BusKey,
162  RealModeIrqRoutingTable,
163  0x0,
164  0x0,
165  0xFFFFFFFF,
166  "PCI Real-mode IRQ Routing Table",
167  PartialResourceList,
168  Size,
169  &TableKey);
170  }
171 }
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
ASMGENDATA Table[]
Definition: genincdata.c:61
GLint x0
Definition: linetemp.h:95
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@369 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable(VOID)
Definition: hwpci.c:29
smooth NULL
Definition: ftsmooth.c:416
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@369::@378 DeviceSpecificData
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:163
#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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
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:109
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@369::@377 BusNumber
unsigned int ULONG
Definition: retypes.h:1
#define CmResourceTypeBusNumber
Definition: hwresource.cpp:128
#define memset(x, y, z)
Definition: compat.h:39
#define TAG_HW_RESOURCE_LIST
Definition: hardware.h:26

Referenced by DetectPciBios().

◆ FindPciBios()

static BOOLEAN FindPciBios ( PPCI_REGISTRY_INFO  BusData)
static

Definition at line 79 of file hwpci.c.

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

Referenced by DetectPciBios().

◆ GetPciIrqRoutingTable()

static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable ( VOID  )
static

Definition at line 29 of file hwpci.c.

30 {
32  PUCHAR Ptr;
33  ULONG Sum;
34  ULONG i;
35 
36  Table = (PPCI_IRQ_ROUTING_TABLE)0xF0000;
37  while ((ULONG_PTR)Table < 0x100000)
38  {
39  if (Table->Signature == 'RIP$')
40  {
41  TRACE("Found signature\n");
42 
43  if (Table->TableSize < FIELD_OFFSET(PCI_IRQ_ROUTING_TABLE, Slot) ||
44  Table->TableSize % 16 != 0)
45  {
46  ERR("Invalid routing table size (%u) at 0x%p. Continue searching...\n", Table->TableSize, Table);
48  continue;
49  }
50 
51  Ptr = (PUCHAR)Table;
52  Sum = 0;
53  for (i = 0; i < Table->TableSize; i++)
54  {
55  Sum += Ptr[i];
56  }
57 
58  if ((Sum & 0xFF) != 0)
59  {
60  ERR("Invalid routing table checksum (%#lx) at 0x%p. Continue searching...\n", Sum & 0xFF, Table);
61  }
62  else
63  {
64  TRACE("Valid checksum (%#lx): found routing table at 0x%p\n", Sum & 0xFF, Table);
65  return Table;
66  }
67  }
68 
70  }
71 
72  ERR("No valid routing table found!\n");
73 
74  return NULL;
75 }
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:63
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
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
struct _PCI_IRQ_ROUTING_TABLE * PPCI_IRQ_ROUTING_TABLE
#define ERR(fmt,...)
Definition: debug.h:109
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1

Referenced by DetectPciIrqRoutingTable().