Synchronize with trunk r58528.
[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 /* PnP Interfaces don't get Initialized */
39 ASSERTMSG(FALSE, "PCI routeintrf_Initializer, unexpected call.");
40 return STATUS_UNSUCCESSFUL;
41 }
42
43 NTSTATUS
44 NTAPI
45 routeintrf_Constructor(IN PVOID DeviceExtension,
46 IN PVOID Instance,
47 IN PVOID InterfaceData,
48 IN USHORT Version,
49 IN USHORT Size,
50 IN PINTERFACE Interface)
51 {
52 /* Only version 1 is supported */
53 if (Version != PCI_INT_ROUTE_INTRF_STANDARD_VER) return STATUS_NOINTERFACE;
54
55 /* Not yet implemented */
56 UNIMPLEMENTED_DBGBREAK();
57 return STATUS_NOT_IMPLEMENTED;
58 }
59
60 NTSTATUS
61 NTAPI
62 PciCacheLegacyDeviceRouting(IN PDEVICE_OBJECT DeviceObject,
63 IN ULONG BusNumber,
64 IN ULONG SlotNumber,
65 IN UCHAR InterruptLine,
66 IN UCHAR InterruptPin,
67 IN UCHAR BaseClass,
68 IN UCHAR SubClass,
69 IN PDEVICE_OBJECT PhysicalDeviceObject,
70 IN PPCI_PDO_EXTENSION PdoExtension,
71 OUT PDEVICE_OBJECT *pFoundDeviceObject)
72 {
73 PPCI_LEGACY_DEVICE *Link;
74 PPCI_LEGACY_DEVICE LegacyDevice;
75 PDEVICE_OBJECT FoundDeviceObject;
76 PAGED_CODE();
77
78 /* Scan current registered devices */
79 LegacyDevice = PciLegacyDeviceHead;
80 Link = &PciLegacyDeviceHead;
81 while (LegacyDevice)
82 {
83 /* Find a match */
84 if ((BusNumber == LegacyDevice->BusNumber) &&
85 (SlotNumber == LegacyDevice->SlotNumber))
86 {
87 /* We already know about this routing */
88 break;
89 }
90
91 /* We know about device already, but for a different location */
92 if (LegacyDevice->DeviceObject == DeviceObject)
93 {
94 /* Free the existing structure, move to the next one */
95 *Link = LegacyDevice->Next;
96 ExFreePoolWithTag(LegacyDevice, 0);
97 LegacyDevice = *Link;
98 }
99 else
100 {
101 /* Keep going */
102 Link = &LegacyDevice->Next;
103 LegacyDevice = LegacyDevice->Next;
104 }
105 }
106
107 /* Did we find a match? */
108 if (!LegacyDevice)
109 {
110 /* Allocate a new cache structure */
111 LegacyDevice = ExAllocatePoolWithTag(PagedPool,
112 sizeof(PCI_LEGACY_DEVICE),
113 'PciR');
114 if (!LegacyDevice) return STATUS_INSUFFICIENT_RESOURCES;
115
116 /* Save all the data in it */
117 RtlZeroMemory(LegacyDevice, sizeof(PCI_LEGACY_DEVICE));
118 LegacyDevice->BusNumber = BusNumber;
119 LegacyDevice->SlotNumber = SlotNumber;
120 LegacyDevice->InterruptLine = InterruptLine;
121 LegacyDevice->InterruptPin = InterruptPin;
122 LegacyDevice->BaseClass = BaseClass;
123 LegacyDevice->SubClass = SubClass;
124 LegacyDevice->PhysicalDeviceObject = PhysicalDeviceObject;
125 LegacyDevice->DeviceObject = DeviceObject;
126 LegacyDevice->PdoExtension = PdoExtension;
127
128 /* Link it in the list */
129 LegacyDevice->Next = PciLegacyDeviceHead;
130 PciLegacyDeviceHead = LegacyDevice;
131 }
132
133 /* Check if we found, or created, a matching caching structure */
134 FoundDeviceObject = LegacyDevice->DeviceObject;
135 if (FoundDeviceObject == DeviceObject)
136 {
137 /* Return the device object and success */
138 if (pFoundDeviceObject) *pFoundDeviceObject = DeviceObject;
139 return STATUS_SUCCESS;
140 }
141
142 /* Otherwise, this is a new device object for this location */
143 LegacyDevice->DeviceObject = DeviceObject;
144 if (pFoundDeviceObject) *pFoundDeviceObject = FoundDeviceObject;
145 return STATUS_SUCCESS;
146 }
147
148 /* EOF */