ReactOS  0.4.13-dev-247-g0f29b3f
bus.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS HAL
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: hal/halppc/generic/bus.c
5  * PURPOSE: Bus Support Routines
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS *******************************************************************/
16 
18 
19 /* PRIVATE FUNCTIONS *********************************************************/
20 
21 VOID
22 NTAPI
24 {
25  /* Register PCI Device Functions */
28 
29  /* Register memory functions */
32 
33  /* Register ACPI stub */
35 }
36 
38 NTAPI
47 {
48  BUS_HANDLER BusHandler;
49  PAGED_CODE();
50 
51  /* Only PCI is supported */
52  if (BusType != PCIBus) return STATUS_NOT_IMPLEMENTED;
53 
54  /* Setup fake PCI Bus handler */
55  RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
56  BusHandler.BusNumber = BusNumber;
57 
58  /* Call the PCI function */
59  return HalpAssignPCISlotResources(&BusHandler,
60  &BusHandler,
65  SlotNumber,
67 }
68 
69 BOOLEAN
70 NTAPI
76 {
77  /* Translation is easy */
79  return TRUE;
80 }
81 
82 ULONG
83 NTAPI
87  OUT PKIRQL Irql,
89 {
92  *Affinity = 0xFFFFFFFF;
93  return Vector;
94 }
95 
96 BOOLEAN
97 NTAPI
102  IN BOOLEAN NextBus)
103 {
104  /* Make sure we have a context */
105  if (!Context) return FALSE;
106 
107  /* If we have data in the context, then this shouldn't be a new lookup */
108  if ((*Context != 0) && (NextBus != FALSE)) return FALSE;
109 
110  /* Return bus data */
112 
113  /* Set context value and return success */
114  *Context = 1;
115  return TRUE;
116 }
117 
118 VOID
119 NTAPI
121 {
122  /* These should be written by the PCI driver later, but we give defaults */
126 }
127 
128 /* PUBLIC FUNCTIONS **********************************************************/
129 
130 /*
131  * @implemented
132  */
133 NTSTATUS
134 NTAPI
136 {
137  /* Deprecated, return success */
138  return STATUS_SUCCESS;
139 }
140 
141 /*
142  * @implemented
143  */
144 NTSTATUS
145 NTAPI
154 {
155  /* Check the bus type */
156  if (BusType != PCIBus)
157  {
158  /* Call our internal handler */
161  DriverObject,
162  DeviceObject,
163  BusType,
164  BusNumber,
165  SlotNumber,
167  }
168  else
169  {
170  /* Call the PCI registered function */
173  DriverObject,
174  DeviceObject,
175  PCIBus,
176  BusNumber,
177  SlotNumber,
179  }
180 }
181 
182 /*
183  * @implemented
184  */
185 ULONG
186 NTAPI
190  IN PVOID Buffer,
191  IN ULONG Length)
192 {
193  /* Call the extended function */
194  return HalGetBusDataByOffset(BusDataType,
195  BusNumber,
196  SlotNumber,
197  Buffer,
198  0,
199  Length);
200 }
201 
202 /*
203  * @implemented
204  */
205 ULONG
206 NTAPI
210  IN PVOID Buffer,
211  IN ULONG Offset,
212  IN ULONG Length)
213 {
214  BUS_HANDLER BusHandler;
215 
216  /* Look as the bus type */
217  if (BusDataType == Cmos)
218  {
219  /* Call CMOS Function */
221  }
222  else if (BusDataType == EisaConfiguration)
223  {
224  /* FIXME: TODO */
225  ASSERT(FALSE);
226  }
227  else if ((BusDataType == PCIConfiguration) &&
230  {
231  /* Setup fake PCI Bus handler */
232  RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
233  BusHandler.BusNumber = BusNumber;
234 
235  /* Call PCI function */
236  return HalpGetPCIData(&BusHandler,
237  &BusHandler,
239  Buffer,
240  Offset,
241  Length);
242  }
243 
244  /* Invalid bus */
245  return 0;
246 }
247 
248 /*
249  * @implemented
250  */
251 ULONG
252 NTAPI
257  OUT PKIRQL Irql,
259 {
260  /* Call the system bus translator */
264  Irql,
265  Affinity);
266 }
267 
268 /*
269  * @implemented
270  */
271 ULONG
272 NTAPI
276  IN PVOID Buffer,
277  IN ULONG Length)
278 {
279  /* Call the extended function */
280  return HalSetBusDataByOffset(BusDataType,
281  BusNumber,
282  SlotNumber,
283  Buffer,
284  0,
285  Length);
286 }
287 
288 /*
289  * @implemented
290  */
291 ULONG
292 NTAPI
296  IN PVOID Buffer,
297  IN ULONG Offset,
298  IN ULONG Length)
299 {
300  BUS_HANDLER BusHandler;
301 
302  /* Look as the bus type */
303  if (BusDataType == Cmos)
304  {
305  /* Call CMOS Function */
307  }
308  else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized))
309  {
310  /* Setup fake PCI Bus handler */
311  RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
312  BusHandler.BusNumber = BusNumber;
313 
314  /* Call PCI function */
315  return HalpSetPCIData(&BusHandler,
316  &BusHandler,
318  Buffer,
319  Offset,
320  Length);
321  }
322 
323  /* Invalid bus */
324  return 0;
325 }
326 
327 /*
328  * @implemented
329  */
330 BOOLEAN
331 NTAPI
337 {
338  /* Look as the bus type */
339  if (InterfaceType == PCIBus)
340  {
341  /* Call the PCI registered function */
343  BusNumber,
344  BusAddress,
345  AddressSpace,
347  }
348  else
349  {
350  /* Translation is easy */
352  return TRUE;
353  }
354 }
355 
356 /* EOF */
_In_ ULONG _In_ ULONG BusInterruptLevel
Definition: halfuncs.h:170
#define IN
Definition: typedefs.h:38
#define HalPciTranslateBusAddress
Definition: halfuncs.h:41
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2268
VOID NTAPI HalpCheckPowerButton(VOID)
Definition: misc.c:20
enum _INTERFACE_TYPE INTERFACE_TYPE
BOOLEAN HalpPCIConfigInitialized
Definition: pci.c:17
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define KdUnmapVirtualAddress
Definition: halfuncs.h:53
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4640
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:156
VOID NTAPI HalpInitNonBusHandler(VOID)
Definition: bus.c:120
enum _BUS_DATA_TYPE BUS_DATA_TYPE
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
BOOLEAN NTAPI HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress, IN OUT PULONG_PTR Context, IN BOOLEAN NextBus)
Definition: bus.c:98
LONG NTSTATUS
Definition: precomp.h:26
ULONG HalpMinPciBus
Definition: pci.c:18
NTSTATUS NTAPI HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN INTERFACE_TYPE BusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
Definition: bus.c:39
_In_ ULONG _In_ ULONG _In_ ULONG BusInterruptVector
Definition: halfuncs.h:170
ULONG NTAPI HalpGetCmosData(IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: cmos.c:47
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
_Out_ PKIRQL Irql
Definition: csq.h:179
#define PAGED_CODE()
Definition: video.h:57
_In_opt_ PUNICODE_STRING DriverClassName
Definition: halfuncs.h:156
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI HalpSetupPciDeviceForDebugging(IN PVOID LoaderBlock, IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
Definition: pci.c:473
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PVOID NTAPI HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG NumberPage)
Definition: misc.c:28
KAFFINITY * PKAFFINITY
Definition: basetsd.h:197
BOOLEAN NTAPI HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:71
unsigned char BOOLEAN
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI HalAdjustResourceList(IN PIO_RESOURCE_REQUIREMENTS_LIST *ResourceList)
Definition: bus.c:26
Definition: bufpool.h:45
#define VECTOR2IRQL(vector)
Definition: halirq.h:26
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
NTSTATUS NTAPI HalAssignSlotResources(IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN INTERFACE_TYPE BusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
Definition: bus.c:38
ULONG HalpBusType
Definition: bus.c:17
ULONG BusNumber
Definition: haltypes.h:226
Definition: miniport.h:89
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
#define KdMapPhysicalMemory64
Definition: halfuncs.h:52
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
VOID NTAPI HalpUnmapVirtualAddress(IN PVOID VirtualAddress, IN ULONG NumberPages)
Definition: misc.c:39
ULONG HalpMaxPciBus
Definition: pci.c:18
#define KdSetupPciDeviceForDebugging
Definition: halfuncs.h:47
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
ULONG NTAPI HalpGetPCIData(IN PBUS_HANDLER BusHandler, IN PBUS_HANDLER RootHandler, IN PCI_SLOT_NUMBER Slot, IN PUCHAR Buffer, IN ULONG Offset, IN ULONG Length)
Definition: pci.c:338
ULONG NTAPI HalpSetPCIData(IN PBUS_HANDLER BusHandler, IN PBUS_HANDLER RootHandler, IN PCI_SLOT_NUMBER Slot, IN PUCHAR Buffer, IN ULONG Offset, IN ULONG Length)
Definition: pci.c:409
NTSTATUS NTAPI HalpReleasePciDeviceForDebugging(IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
Definition: pci.c:482
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI HalpRegisterKdSupportFunctions(VOID)
Definition: bus.c:23
ULONG NTAPI HalGetBusData(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: bus.c:57
ULONG NTAPI HalpGetSystemInterruptVector(IN ULONG BusNumber, IN ULONG BusInterruptLevel, IN ULONG BusInterruptVector, OUT PKIRQL Irql, OUT PKAFFINITY Affinity)
Definition: bus.c:84
ULONG NTAPI HalSetBusData(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: bus.c:107
#define HalFindBusAddressTranslation
Definition: halfuncs.h:44
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG Vector
Definition: iofuncs.h:798
NTSTATUS NTAPI HalpAssignPCISlotResources(IN PBUS_HANDLER BusHandler, IN PBUS_HANDLER RootHandler, IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN ULONG Slot, IN OUT PCM_RESOURCE_LIST *pAllocatedResources)
Definition: pci.c:490
ULONG NTAPI HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN ULONG BusInterruptLevel, IN ULONG BusInterruptVector, OUT PKIRQL Irql, OUT PKAFFINITY Affinity)
Definition: bus.c:90
unsigned int * PULONG
Definition: retypes.h:1
#define KdCheckPowerButton
Definition: halfuncs.h:50
#define OUT
Definition: typedefs.h:39
#define KdReleasePciDeviceforDebugging
Definition: halfuncs.h:48
unsigned int ULONG
Definition: retypes.h:1
#define HalPciAssignSlotResources
Definition: halfuncs.h:42
uint32_t * PULONG_PTR
Definition: typedefs.h:63
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
BUS_HANDLER HalpFakePciBusHandler
Definition: pci.c:91
#define IRQ2VECTOR(irq)
Definition: halirq.h:27
ULONG NTAPI HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:123
return STATUS_SUCCESS
Definition: btrfs.c:2745
ULONG NTAPI HalpSetCmosData(IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: cmos.c:99
LONGLONG QuadPart
Definition: typedefs.h:112