OvmfPkg/MptScsiDxe: Probe PCI devices and look for MptScsi
[mirror_edk2.git] / OvmfPkg / MptScsiDxe / MptScsi.c
CommitLineData
feec20b2
NL
1/** @file\r
2\r
3 This driver produces Extended SCSI Pass Thru Protocol instances for\r
4 LSI Fusion MPT SCSI devices.\r
5\r
6 Copyright (C) 2020, Oracle and/or its affiliates.\r
7\r
8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
9\r
10**/\r
11\r
f4707442
NL
12#include <IndustryStandard/FusionMptScsi.h>\r
13#include <IndustryStandard/Pci.h>\r
14#include <Library/UefiBootServicesTableLib.h>\r
ad8f2d6b 15#include <Library/UefiLib.h>\r
f4707442 16#include <Protocol/PciIo.h>\r
feec20b2
NL
17#include <Uefi/UefiSpec.h>\r
18\r
ad8f2d6b
NL
19//\r
20// Higher versions will be used before lower, 0x10-0xffffffef is the version\r
21// range for IVH (Indie Hardware Vendors)\r
22//\r
23#define MPT_SCSI_BINDING_VERSION 0x10\r
24\r
25//\r
26// Driver Binding\r
27//\r
28\r
29STATIC\r
30EFI_STATUS\r
31EFIAPI\r
32MptScsiControllerSupported (\r
33 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
34 IN EFI_HANDLE ControllerHandle,\r
35 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
36 )\r
37{\r
f4707442
NL
38 EFI_STATUS Status;\r
39 EFI_PCI_IO_PROTOCOL *PciIo;\r
40 PCI_TYPE00 Pci;\r
41\r
42 Status = gBS->OpenProtocol (\r
43 ControllerHandle,\r
44 &gEfiPciIoProtocolGuid,\r
45 (VOID **)&PciIo,\r
46 This->DriverBindingHandle,\r
47 ControllerHandle,\r
48 EFI_OPEN_PROTOCOL_BY_DRIVER\r
49 );\r
50 if (EFI_ERROR (Status)) {\r
51 return Status;\r
52 }\r
53\r
54 Status = PciIo->Pci.Read (\r
55 PciIo,\r
56 EfiPciIoWidthUint32,\r
57 0,\r
58 sizeof (Pci) / sizeof (UINT32),\r
59 &Pci\r
60 );\r
61 if (EFI_ERROR (Status)) {\r
62 goto Done;\r
63 }\r
64\r
65 if (Pci.Hdr.VendorId == LSI_LOGIC_PCI_VENDOR_ID &&\r
66 (Pci.Hdr.DeviceId == LSI_53C1030_PCI_DEVICE_ID ||\r
67 Pci.Hdr.DeviceId == LSI_SAS1068_PCI_DEVICE_ID ||\r
68 Pci.Hdr.DeviceId == LSI_SAS1068E_PCI_DEVICE_ID)) {\r
69 Status = EFI_SUCCESS;\r
70 } else {\r
71 Status = EFI_UNSUPPORTED;\r
72 }\r
73\r
74Done:\r
75 gBS->CloseProtocol (\r
76 ControllerHandle,\r
77 &gEfiPciIoProtocolGuid,\r
78 This->DriverBindingHandle,\r
79 ControllerHandle\r
80 );\r
81 return Status;\r
ad8f2d6b
NL
82}\r
83\r
84STATIC\r
85EFI_STATUS\r
86EFIAPI\r
87MptScsiControllerStart (\r
88 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
89 IN EFI_HANDLE ControllerHandle,\r
90 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
91 )\r
92{\r
93 return EFI_UNSUPPORTED;\r
94}\r
95\r
96STATIC\r
97EFI_STATUS\r
98EFIAPI\r
99MptScsiControllerStop (\r
100 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
101 IN EFI_HANDLE ControllerHandle,\r
102 IN UINTN NumberOfChildren,\r
103 IN EFI_HANDLE *ChildHandleBuffer\r
104 )\r
105{\r
106 return EFI_UNSUPPORTED;\r
107}\r
108\r
109STATIC\r
110EFI_DRIVER_BINDING_PROTOCOL mMptScsiDriverBinding = {\r
111 &MptScsiControllerSupported,\r
112 &MptScsiControllerStart,\r
113 &MptScsiControllerStop,\r
114 MPT_SCSI_BINDING_VERSION,\r
115 NULL, // ImageHandle, filled by EfiLibInstallDriverBindingComponentName2\r
116 NULL, // DriverBindingHandle, filled as well\r
117};\r
118\r
be7fcaa1
NL
119//\r
120// Component Name\r
121//\r
122\r
123STATIC\r
124EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {\r
125 { "eng;en", L"LSI Fusion MPT SCSI Driver" },\r
126 { NULL, NULL }\r
127};\r
128\r
129STATIC\r
130EFI_COMPONENT_NAME_PROTOCOL mComponentName;\r
131\r
132EFI_STATUS\r
133EFIAPI\r
134MptScsiGetDriverName (\r
135 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
136 IN CHAR8 *Language,\r
137 OUT CHAR16 **DriverName\r
138 )\r
139{\r
140 return LookupUnicodeString2 (\r
141 Language,\r
142 This->SupportedLanguages,\r
143 mDriverNameTable,\r
144 DriverName,\r
145 (BOOLEAN)(This == &mComponentName) // Iso639Language\r
146 );\r
147}\r
148\r
149EFI_STATUS\r
150EFIAPI\r
151MptScsiGetDeviceName (\r
152 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
153 IN EFI_HANDLE DeviceHandle,\r
154 IN EFI_HANDLE ChildHandle,\r
155 IN CHAR8 *Language,\r
156 OUT CHAR16 **ControllerName\r
157 )\r
158{\r
159 return EFI_UNSUPPORTED;\r
160}\r
161\r
162STATIC\r
163EFI_COMPONENT_NAME_PROTOCOL mComponentName = {\r
164 &MptScsiGetDriverName,\r
165 &MptScsiGetDeviceName,\r
166 "eng" // SupportedLanguages, ISO 639-2 language codes\r
167};\r
168\r
169STATIC\r
170EFI_COMPONENT_NAME2_PROTOCOL mComponentName2 = {\r
171 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &MptScsiGetDriverName,\r
172 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &MptScsiGetDeviceName,\r
173 "en" // SupportedLanguages, RFC 4646 language codes\r
174};\r
175\r
feec20b2
NL
176//\r
177// Entry Point\r
178//\r
179\r
180EFI_STATUS\r
181EFIAPI\r
182MptScsiEntryPoint (\r
183 IN EFI_HANDLE ImageHandle,\r
184 IN EFI_SYSTEM_TABLE *SystemTable\r
185 )\r
186{\r
ad8f2d6b
NL
187 return EfiLibInstallDriverBindingComponentName2 (\r
188 ImageHandle,\r
189 SystemTable,\r
190 &mMptScsiDriverBinding,\r
191 ImageHandle, // The handle to install onto\r
be7fcaa1
NL
192 &mComponentName,\r
193 &mComponentName2\r
ad8f2d6b 194 );\r
feec20b2 195}\r