3 Copyright (C) 2016, Linaro Ltd. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
11 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "NonDiscoverablePciDeviceIo.h"
17 #include <Protocol/DriverBinding.h>
19 EFI_CPU_ARCH_PROTOCOL
*mCpu
;
22 // We only support the following device types
25 CONST EFI_GUID
* CONST
26 SupportedNonDiscoverableDevices
[] = {
27 &gEdkiiNonDiscoverableAhciDeviceGuid
,
28 &gEdkiiNonDiscoverableEhciDeviceGuid
,
29 &gEdkiiNonDiscoverableNvmeDeviceGuid
,
30 &gEdkiiNonDiscoverableOhciDeviceGuid
,
31 &gEdkiiNonDiscoverableSdhciDeviceGuid
,
32 &gEdkiiNonDiscoverableUfsDeviceGuid
,
33 &gEdkiiNonDiscoverableUhciDeviceGuid
,
34 &gEdkiiNonDiscoverableXhciDeviceGuid
,
38 // Probe, start and stop functions of this driver, called by the DXE core for
41 // The following specifications document these interfaces:
42 // - Driver Writer's Guide for UEFI 2.3.1 v1.01, 9 Driver Binding Protocol
43 // - UEFI Spec 2.3.1 + Errata C, 10.1 EFI Driver Binding Protocol
45 // The implementation follows:
46 // - Driver Writer's Guide for UEFI 2.3.1 v1.01
47 // - 5.1.3.4 OpenProtocol() and CloseProtocol()
48 // - UEFI Spec 2.3.1 + Errata C
49 // - 6.3 Protocol Handler Services
53 Supported function of Driver Binding protocol for this driver.
54 Test to see if this driver supports ControllerHandle.
56 @param This Protocol instance pointer.
57 @param DeviceHandle Handle of device to test.
58 @param RemainingDevicePath A pointer to the device path.
59 it should be ignored by device driver.
61 @retval EFI_SUCCESS This driver supports this device.
62 @retval other This driver does not support this device.
68 NonDiscoverablePciDeviceSupported (
69 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
70 IN EFI_HANDLE DeviceHandle
,
71 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
74 NON_DISCOVERABLE_DEVICE
*Device
;
76 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Desc
;
79 Status
= gBS
->OpenProtocol (DeviceHandle
,
80 &gEdkiiNonDiscoverableDeviceProtocolGuid
, (VOID
**)&Device
,
81 This
->DriverBindingHandle
, DeviceHandle
,
82 EFI_OPEN_PROTOCOL_BY_DRIVER
);
83 if (EFI_ERROR (Status
)) {
87 Status
= EFI_UNSUPPORTED
;
88 for (Idx
= 0; Idx
< ARRAY_SIZE (SupportedNonDiscoverableDevices
); Idx
++) {
89 if (CompareGuid (Device
->Type
, SupportedNonDiscoverableDevices
[Idx
])) {
95 if (EFI_ERROR (Status
)) {
100 // We only support MMIO devices, so iterate over the resources to ensure
101 // that they only describe things that we can handle
103 for (Desc
= Device
->Resources
; Desc
->Desc
!= ACPI_END_TAG_DESCRIPTOR
;
104 Desc
= (VOID
*)((UINT8
*)Desc
+ Desc
->Len
+ 3)) {
105 if (Desc
->Desc
!= ACPI_ADDRESS_SPACE_DESCRIPTOR
||
106 Desc
->ResType
!= ACPI_ADDRESS_SPACE_TYPE_MEM
) {
107 Status
= EFI_UNSUPPORTED
;
113 gBS
->CloseProtocol (DeviceHandle
, &gEdkiiNonDiscoverableDeviceProtocolGuid
,
114 This
->DriverBindingHandle
, DeviceHandle
);
120 This routine is called right after the .Supported() called and
121 Start this driver on ControllerHandle.
123 @param This Protocol instance pointer.
124 @param DeviceHandle Handle of device to bind driver to.
125 @param RemainingDevicePath A pointer to the device path.
126 it should be ignored by device driver.
128 @retval EFI_SUCCESS This driver is added to this device.
129 @retval other Some error occurs when binding this driver to this device.
135 NonDiscoverablePciDeviceStart (
136 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
137 IN EFI_HANDLE DeviceHandle
,
138 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
141 NON_DISCOVERABLE_PCI_DEVICE
*Dev
;
144 Dev
= AllocateZeroPool (sizeof *Dev
);
146 return EFI_OUT_OF_RESOURCES
;
149 Status
= gBS
->OpenProtocol (DeviceHandle
,
150 &gEdkiiNonDiscoverableDeviceProtocolGuid
,
151 (VOID
**)&Dev
->Device
, This
->DriverBindingHandle
,
152 DeviceHandle
, EFI_OPEN_PROTOCOL_BY_DRIVER
);
153 if (EFI_ERROR (Status
)) {
157 InitializePciIoProtocol (Dev
);
160 // Setup complete, attempt to export the driver instance's
161 // EFI_PCI_IO_PROTOCOL interface.
163 Dev
->Signature
= NON_DISCOVERABLE_PCI_DEVICE_SIG
;
164 Status
= gBS
->InstallProtocolInterface (&DeviceHandle
, &gEfiPciIoProtocolGuid
,
165 EFI_NATIVE_INTERFACE
, &Dev
->PciIo
);
166 if (EFI_ERROR (Status
)) {
173 gBS
->CloseProtocol (DeviceHandle
, &gEdkiiNonDiscoverableDeviceProtocolGuid
,
174 This
->DriverBindingHandle
, DeviceHandle
);
183 Stop this driver on ControllerHandle.
185 @param This Protocol instance pointer.
186 @param DeviceHandle Handle of device to stop driver on.
187 @param NumberOfChildren Not used.
188 @param ChildHandleBuffer Not used.
190 @retval EFI_SUCCESS This driver is removed from this device.
191 @retval other Some error occurs when removing this driver from this device.
197 NonDiscoverablePciDeviceStop (
198 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
199 IN EFI_HANDLE DeviceHandle
,
200 IN UINTN NumberOfChildren
,
201 IN EFI_HANDLE
*ChildHandleBuffer
205 EFI_PCI_IO_PROTOCOL
*PciIo
;
206 NON_DISCOVERABLE_PCI_DEVICE
*Dev
;
208 Status
= gBS
->OpenProtocol (DeviceHandle
, &gEfiPciIoProtocolGuid
,
209 (VOID
**)&PciIo
, This
->DriverBindingHandle
, DeviceHandle
,
210 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
211 if (EFI_ERROR (Status
)) {
215 Dev
= NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (PciIo
);
218 // Handle Stop() requests for in-use driver instances gracefully.
220 Status
= gBS
->UninstallProtocolInterface (DeviceHandle
,
221 &gEfiPciIoProtocolGuid
, &Dev
->PciIo
);
222 if (EFI_ERROR (Status
)) {
226 gBS
->CloseProtocol (DeviceHandle
, &gEdkiiNonDiscoverableDeviceProtocolGuid
,
227 This
->DriverBindingHandle
, DeviceHandle
);
236 // The static object that groups the Supported() (ie. probe), Start() and
237 // Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata
238 // C, 10.1 EFI Driver Binding Protocol.
240 STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding
= {
241 &NonDiscoverablePciDeviceSupported
,
242 &NonDiscoverablePciDeviceStart
,
243 &NonDiscoverablePciDeviceStop
,
244 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers
250 Entry point of this driver.
252 @param ImageHandle Image handle this driver.
253 @param SystemTable Pointer to the System Table.
255 @retval EFI_SUCCESS The entry point is executed successfully.
256 @retval other Some error occurred when executing this entry point.
261 NonDiscoverablePciDeviceDxeEntryPoint (
262 IN EFI_HANDLE ImageHandle
,
263 IN EFI_SYSTEM_TABLE
*SystemTable
268 Status
= gBS
->LocateProtocol (&gEfiCpuArchProtocolGuid
, NULL
, (VOID
**)&mCpu
);
269 ASSERT_EFI_ERROR(Status
);
271 return EfiLibInstallDriverBindingComponentName2 (