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
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 PPCI_LEGACY_DEVICE PciLegacyDeviceHead
;
19 PCI_INTERFACE PciRoutingInterface
=
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
,
27 PciInterface_IntRouteHandler
,
28 routeintrf_Constructor
,
29 routeintrf_Initializer
32 /* FUNCTIONS ******************************************************************/
36 routeintrf_Initializer(IN PVOID Instance
)
38 /* PnP Interfaces don't get Initialized */
39 ASSERTMSG(FALSE
, "PCI routeintrf_Initializer, unexpected call.");
40 return STATUS_UNSUCCESSFUL
;
45 routeintrf_Constructor(IN PVOID DeviceExtension
,
47 IN PVOID InterfaceData
,
50 IN PINTERFACE Interface
)
52 /* Only version 1 is supported */
53 if (Version
!= PCI_INT_ROUTE_INTRF_STANDARD_VER
) return STATUS_NOINTERFACE
;
55 /* Not yet implemented */
62 PciCacheLegacyDeviceRouting(IN PDEVICE_OBJECT DeviceObject
,
65 IN UCHAR InterruptLine
,
66 IN UCHAR InterruptPin
,
69 IN PDEVICE_OBJECT PhysicalDeviceObject
,
70 IN PPCI_PDO_EXTENSION PdoExtension
,
71 OUT PDEVICE_OBJECT
*pFoundDeviceObject
)
73 PPCI_LEGACY_DEVICE
*Link
;
74 PPCI_LEGACY_DEVICE LegacyDevice
;
75 PDEVICE_OBJECT FoundDeviceObject
;
78 /* Scan current registered devices */
79 LegacyDevice
= PciLegacyDeviceHead
;
80 Link
= &PciLegacyDeviceHead
;
84 if ((BusNumber
== LegacyDevice
->BusNumber
) &&
85 (SlotNumber
== LegacyDevice
->SlotNumber
))
87 /* We already know about this routing */
91 /* We know about device already, but for a different location */
92 if (LegacyDevice
->DeviceObject
== DeviceObject
)
94 /* Free the existing structure, move to the next one */
95 *Link
= LegacyDevice
->Next
;
96 ExFreePoolWithTag(LegacyDevice
, 0);
102 Link
= &LegacyDevice
->Next
;
103 LegacyDevice
= LegacyDevice
->Next
;
107 /* Did we find a match? */
110 /* Allocate a new cache structure */
111 LegacyDevice
= ExAllocatePoolWithTag(PagedPool
,
112 sizeof(PCI_LEGACY_DEVICE
),
114 if (!LegacyDevice
) return STATUS_INSUFFICIENT_RESOURCES
;
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
;
128 /* Link it in the list */
129 LegacyDevice
->Next
= PciLegacyDeviceHead
;
130 PciLegacyDeviceHead
= LegacyDevice
;
133 /* Check if we found, or created, a matching caching structure */
134 FoundDeviceObject
= LegacyDevice
->DeviceObject
;
135 if (FoundDeviceObject
== DeviceObject
)
137 /* Return the device object and success */
138 if (pFoundDeviceObject
) *pFoundDeviceObject
= DeviceObject
;
139 return STATUS_SUCCESS
;
142 /* Otherwise, this is a new device object for this location */
143 LegacyDevice
->DeviceObject
= DeviceObject
;
144 if (pFoundDeviceObject
) *pFoundDeviceObject
= FoundDeviceObject
;
145 return STATUS_SUCCESS
;