Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / drivers / bus / pcix / intrface / routintf.c
1 /*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/intrface/routinf.c
5 * PURPOSE: Routing Interface
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <pci.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 PPCI_LEGACY_DEVICE PciLegacyDeviceHead;
18
19 PCI_INTERFACE PciRoutingInterface =
20 {
21 &GUID_INT_ROUTE_INTERFACE_STANDARD,
22 sizeof(INT_ROUTE_INTERFACE_STANDARD),
23 PCI_INT_ROUTE_INTRF_STANDARD_VER,
24 PCI_INT_ROUTE_INTRF_STANDARD_VER,
25 PCI_INTERFACE_FDO,
26 0,
27 PciInterface_IntRouteHandler,
28 routeintrf_Constructor,
29 routeintrf_Initializer
30 };
31
32 /* FUNCTIONS ******************************************************************/
33
34 NTSTATUS
35 NTAPI
36 routeintrf_Initializer(IN PVOID Instance)
37 {
38 UNREFERENCED_PARAMETER(Instance);
39 /* PnP Interfaces don't get Initialized */
40 ASSERTMSG("PCI routeintrf_Initializer, unexpected call.", FALSE);
41 return STATUS_UNSUCCESSFUL;
42 }
43
44 NTSTATUS
45 NTAPI
46 routeintrf_Constructor(IN PVOID DeviceExtension,
47 IN PVOID Instance,
48 IN PVOID InterfaceData,
49 IN USHORT Version,
50 IN USHORT Size,
51 IN PINTERFACE Interface)
52 {
53 UNREFERENCED_PARAMETER(DeviceExtension);
54 UNREFERENCED_PARAMETER(Instance);
55 UNREFERENCED_PARAMETER(InterfaceData);
56 UNREFERENCED_PARAMETER(Size);
57 UNREFERENCED_PARAMETER(Interface);
58
59 /* Only version 1 is supported */
60 if (Version != PCI_INT_ROUTE_INTRF_STANDARD_VER) return STATUS_NOINTERFACE;
61
62 /* Not yet implemented */
63 UNIMPLEMENTED_DBGBREAK();
64 return STATUS_NOT_IMPLEMENTED;
65 }
66
67 NTSTATUS
68 NTAPI
69 PciCacheLegacyDeviceRouting(IN PDEVICE_OBJECT DeviceObject,
70 IN ULONG BusNumber,
71 IN ULONG SlotNumber,
72 IN UCHAR InterruptLine,
73 IN UCHAR InterruptPin,
74 IN UCHAR BaseClass,
75 IN UCHAR SubClass,
76 IN PDEVICE_OBJECT PhysicalDeviceObject,
77 IN PPCI_PDO_EXTENSION PdoExtension,
78 OUT PDEVICE_OBJECT *pFoundDeviceObject)
79 {
80 PPCI_LEGACY_DEVICE *Link;
81 PPCI_LEGACY_DEVICE LegacyDevice;
82 PDEVICE_OBJECT FoundDeviceObject;
83 PAGED_CODE();
84
85 /* Scan current registered devices */
86 LegacyDevice = PciLegacyDeviceHead;
87 Link = &PciLegacyDeviceHead;
88 while (LegacyDevice)
89 {
90 /* Find a match */
91 if ((BusNumber == LegacyDevice->BusNumber) &&
92 (SlotNumber == LegacyDevice->SlotNumber))
93 {
94 /* We already know about this routing */
95 break;
96 }
97
98 /* We know about device already, but for a different location */
99 if (LegacyDevice->DeviceObject == DeviceObject)
100 {
101 /* Free the existing structure, move to the next one */
102 *Link = LegacyDevice->Next;
103 ExFreePoolWithTag(LegacyDevice, 0);
104 LegacyDevice = *Link;
105 }
106 else
107 {
108 /* Keep going */
109 Link = &LegacyDevice->Next;
110 LegacyDevice = LegacyDevice->Next;
111 }
112 }
113
114 /* Did we find a match? */
115 if (!LegacyDevice)
116 {
117 /* Allocate a new cache structure */
118 LegacyDevice = ExAllocatePoolWithTag(PagedPool,
119 sizeof(PCI_LEGACY_DEVICE),
120 'PciR');
121 if (!LegacyDevice) return STATUS_INSUFFICIENT_RESOURCES;
122
123 /* Save all the data in it */
124 RtlZeroMemory(LegacyDevice, sizeof(PCI_LEGACY_DEVICE));
125 LegacyDevice->BusNumber = BusNumber;
126 LegacyDevice->SlotNumber = SlotNumber;
127 LegacyDevice->InterruptLine = InterruptLine;
128 LegacyDevice->InterruptPin = InterruptPin;
129 LegacyDevice->BaseClass = BaseClass;
130 LegacyDevice->SubClass = SubClass;
131 LegacyDevice->PhysicalDeviceObject = PhysicalDeviceObject;
132 LegacyDevice->DeviceObject = DeviceObject;
133 LegacyDevice->PdoExtension = PdoExtension;
134
135 /* Link it in the list */
136 LegacyDevice->Next = PciLegacyDeviceHead;
137 PciLegacyDeviceHead = LegacyDevice;
138 }
139
140 /* Check if we found, or created, a matching caching structure */
141 FoundDeviceObject = LegacyDevice->DeviceObject;
142 if (FoundDeviceObject == DeviceObject)
143 {
144 /* Return the device object and success */
145 if (pFoundDeviceObject) *pFoundDeviceObject = DeviceObject;
146 return STATUS_SUCCESS;
147 }
148
149 /* Otherwise, this is a new device object for this location */
150 LegacyDevice->DeviceObject = DeviceObject;
151 if (pFoundDeviceObject) *pFoundDeviceObject = FoundDeviceObject;
152 return STATUS_SUCCESS;
153 }
154
155 /* EOF */