SioService.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /** @file
  2. The SioBusDxe driver is used to create child devices on the ISA bus and
  3. installs the Super I/O protocols on them.
  4. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "SioBusDxe.h"
  8. //
  9. // Super I/O Protocol interfaces
  10. //
  11. EFI_SIO_PROTOCOL mSioInterface = {
  12. SioRegisterAccess,
  13. SioGetResources,
  14. SioSetResources,
  15. SioPossibleResources,
  16. SioModify
  17. };
  18. //
  19. // COM 1 UART Controller
  20. //
  21. GLOBAL_REMOVE_IF_UNREFERENCED
  22. SIO_RESOURCES_IO mCom1Resources = {
  23. {
  24. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x3F8, 8
  25. },
  26. { ACPI_END_TAG_DESCRIPTOR, 0 }
  27. };
  28. //
  29. // COM 2 UART Controller
  30. //
  31. GLOBAL_REMOVE_IF_UNREFERENCED
  32. SIO_RESOURCES_IO mCom2Resources = {
  33. {
  34. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x2F8, 8
  35. },
  36. { ACPI_END_TAG_DESCRIPTOR, 0 }
  37. };
  38. //
  39. // PS/2 Keyboard Controller
  40. //
  41. GLOBAL_REMOVE_IF_UNREFERENCED
  42. SIO_RESOURCES_IO mPs2KeyboardDeviceResources = {
  43. {
  44. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x60, 5
  45. },
  46. { ACPI_END_TAG_DESCRIPTOR, 0 }
  47. };
  48. //
  49. // Table of SIO Controllers
  50. //
  51. GLOBAL_REMOVE_IF_UNREFERENCED
  52. SIO_DEVICE_INFO mDevicesInfo[] = {
  53. {
  54. EISA_PNP_ID (0x501),
  55. 0,
  56. { (ACPI_SMALL_RESOURCE_HEADER *)&mCom1Resources }
  57. }, // COM 1 UART Controller
  58. {
  59. EISA_PNP_ID (0x501),
  60. 1,
  61. { (ACPI_SMALL_RESOURCE_HEADER *)&mCom2Resources }
  62. }, // COM 2 UART Controller
  63. {
  64. EISA_PNP_ID (0x303),
  65. 0,
  66. { (ACPI_SMALL_RESOURCE_HEADER *)&mPs2KeyboardDeviceResources }
  67. } // PS/2 Keyboard Controller
  68. };
  69. //
  70. // ACPI Device Path Node template
  71. //
  72. GLOBAL_REMOVE_IF_UNREFERENCED
  73. ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate = {
  74. { // Header
  75. ACPI_DEVICE_PATH,
  76. ACPI_DP,
  77. {
  78. (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
  79. (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
  80. }
  81. },
  82. 0x0, // HID
  83. 0x0 // UID
  84. };
  85. /**
  86. Provides a low level access to the registers for the Super I/O.
  87. @param[in] This Indicates a pointer to the calling context.
  88. @param[in] Write Specifies the type of the register operation.
  89. If this parameter is TRUE, Value is interpreted
  90. as an input parameter and the operation is a
  91. register write. If this parameter is FALSE,
  92. Value is interpreted as an output parameter and
  93. the operation is a register read.
  94. @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this
  95. parameter is set to TRUE, the Super I/O driver
  96. will turn off configuration mode of the Super
  97. I/O prior to returning from this function. If
  98. this parameter is set to FALSE, the Super I/O
  99. driver will leave Super I/O in the
  100. configuration mode. The Super I/O driver must
  101. track the current state of the Super I/O and
  102. enable the configuration mode of Super I/O if
  103. necessary prior to register access.
  104. @param[in] Register Register number.
  105. @param[in,out] Value If Write is TRUE, Value is a pointer to the
  106. buffer containing the byte of data to be
  107. written to the Super I/O register. If Write is
  108. FALSE, Value is a pointer to the destination
  109. buffer for the byte of data to be read from the
  110. Super I/O register.
  111. @retval EFI_SUCCESS The operation completed successfully.
  112. @retval EFI_INVALID_PARAMETER The Value is NULL.
  113. @retval EFI_INVALID_PARAMETER Invalid Register number.
  114. **/
  115. EFI_STATUS
  116. EFIAPI
  117. SioRegisterAccess (
  118. IN CONST EFI_SIO_PROTOCOL *This,
  119. IN BOOLEAN Write,
  120. IN BOOLEAN ExitCfgMode,
  121. IN UINT8 Register,
  122. IN OUT UINT8 *Value
  123. )
  124. {
  125. return EFI_SUCCESS;
  126. }
  127. /**
  128. Provides an interface to get a list of the current resources consumed by the
  129. device in the ACPI Resource Descriptor format.
  130. GetResources() returns a list of resources currently consumed by the device.
  131. The ResourceList is a pointer to the buffer containing resource descriptors
  132. for the device. The descriptors are in the format of Small or Large ACPI
  133. resource descriptor as defined by ACPI specification (2.0 & 3.0). The buffer
  134. of resource descriptors is terminated with the 'End tag' resource descriptor.
  135. @param[in] This Indicates a pointer to the calling context.
  136. @param[out] ResourceList A pointer to an ACPI resource descriptor list
  137. that defines the current resources used by the
  138. device.
  139. @retval EFI_SUCCESS The operation completed successfully.
  140. @retval EFI_INVALID_PARAMETER ResourceList is NULL.
  141. **/
  142. EFI_STATUS
  143. EFIAPI
  144. SioGetResources (
  145. IN CONST EFI_SIO_PROTOCOL *This,
  146. OUT ACPI_RESOURCE_HEADER_PTR *ResourceList
  147. )
  148. {
  149. SIO_DEV *SioDevice;
  150. if (ResourceList == NULL) {
  151. return EFI_INVALID_PARAMETER;
  152. }
  153. SioDevice = SIO_DEV_FROM_SIO (This);
  154. if (SioDevice->DeviceIndex < ARRAY_SIZE (mDevicesInfo)) {
  155. *ResourceList = mDevicesInfo[SioDevice->DeviceIndex].Resources;
  156. }
  157. return EFI_SUCCESS;
  158. }
  159. /**
  160. Sets the resources for the device.
  161. @param[in] This Indicates a pointer to the calling context.
  162. @param[in] ResourceList Pointer to the ACPI resource descriptor list.
  163. @retval EFI_SUCCESS The operation completed successfully.
  164. @retval EFI_INVALID_PARAMETER ResourceList is invalid.
  165. @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in
  166. use.
  167. **/
  168. EFI_STATUS
  169. EFIAPI
  170. SioSetResources (
  171. IN CONST EFI_SIO_PROTOCOL *This,
  172. IN ACPI_RESOURCE_HEADER_PTR ResourceList
  173. )
  174. {
  175. return EFI_SUCCESS;
  176. }
  177. /**
  178. Provides a collection of resource descriptor lists. Each resource descriptor
  179. list in the collection defines a combination of resources that can
  180. potentially be used by the device.
  181. @param[in] This Indicates a pointer to the calling context.
  182. @param[out] ResourceCollection Collection of the resource descriptor
  183. lists.
  184. @retval EFI_SUCCESS The operation completed successfully.
  185. @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
  186. **/
  187. EFI_STATUS
  188. EFIAPI
  189. SioPossibleResources (
  190. IN CONST EFI_SIO_PROTOCOL *This,
  191. OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
  192. )
  193. {
  194. return EFI_SUCCESS;
  195. }
  196. /**
  197. Provides an interface for a table based programming of the Super I/O
  198. registers.
  199. The Modify() function provides an interface for table based programming of
  200. the Super I/O registers. This function can be used to perform programming of
  201. multiple Super I/O registers with a single function call. For each table
  202. entry, the Register is read, its content is bitwise ANDed with AndMask, and
  203. then ORed with OrMask before being written back to the Register. The Super
  204. I/O driver must track the current state of the Super I/O and enable the
  205. configuration mode of Super I/O if necessary prior to table processing. Once
  206. the table is processed, the Super I/O device has to be returned to the
  207. original state.
  208. @param[in] This Indicates a pointer to the calling context.
  209. @param[in] Command A pointer to an array of NumberOfCommands
  210. EFI_SIO_REGISTER_MODIFY structures. Each
  211. structure specifies a single Super I/O register
  212. modify operation.
  213. @param[in] NumberOfCommands Number of elements in the Command array.
  214. @retval EFI_SUCCESS The operation completed successfully.
  215. @retval EFI_INVALID_PARAMETER Command is NULL.
  216. **/
  217. EFI_STATUS
  218. EFIAPI
  219. SioModify (
  220. IN CONST EFI_SIO_PROTOCOL *This,
  221. IN CONST EFI_SIO_REGISTER_MODIFY *Command,
  222. IN UINTN NumberOfCommands
  223. )
  224. {
  225. return EFI_SUCCESS;
  226. }
  227. /**
  228. Create the child device with a given device index.
  229. @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
  230. @param[in] Controller The handle of ISA bus controller.
  231. @param[in] PciIo The pointer to the PCI protocol.
  232. @param[in] ParentDevicePath Device path of the ISA bus controller.
  233. @param[in] DeviceIndex Index of the device supported by this driver.
  234. @retval EFI_SUCCESS The child device has been created successfully.
  235. @retval Others Error occurred during the child device creation.
  236. **/
  237. EFI_STATUS
  238. SioCreateChildDevice (
  239. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  240. IN EFI_HANDLE Controller,
  241. IN EFI_PCI_IO_PROTOCOL *PciIo,
  242. IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
  243. IN UINT32 DeviceIndex
  244. )
  245. {
  246. EFI_STATUS Status;
  247. SIO_DEV *SioDevice;
  248. //
  249. // Initialize the SIO_DEV structure
  250. //
  251. SioDevice = AllocateZeroPool (sizeof (SIO_DEV));
  252. if (SioDevice == NULL) {
  253. return EFI_OUT_OF_RESOURCES;
  254. }
  255. SioDevice->Signature = SIO_DEV_SIGNATURE;
  256. SioDevice->Handle = NULL;
  257. SioDevice->PciIo = PciIo;
  258. //
  259. // Construct the child device path
  260. //
  261. mAcpiDeviceNodeTemplate.HID = mDevicesInfo[DeviceIndex].Hid;
  262. mAcpiDeviceNodeTemplate.UID = mDevicesInfo[DeviceIndex].Uid;
  263. SioDevice->DevicePath = AppendDevicePathNode (
  264. ParentDevicePath,
  265. (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiDeviceNodeTemplate
  266. );
  267. if (SioDevice->DevicePath == NULL) {
  268. Status = EFI_OUT_OF_RESOURCES;
  269. goto Done;
  270. }
  271. CopyMem (&SioDevice->Sio, &mSioInterface, sizeof (EFI_SIO_PROTOCOL));
  272. SioDevice->DeviceIndex = DeviceIndex;
  273. //
  274. // Create a child handle and install Device Path and Super I/O protocols
  275. //
  276. Status = gBS->InstallMultipleProtocolInterfaces (
  277. &SioDevice->Handle,
  278. &gEfiDevicePathProtocolGuid,
  279. SioDevice->DevicePath,
  280. &gEfiSioProtocolGuid,
  281. &SioDevice->Sio,
  282. NULL
  283. );
  284. if (EFI_ERROR (Status)) {
  285. goto Done;
  286. }
  287. Status = gBS->OpenProtocol (
  288. Controller,
  289. &gEfiPciIoProtocolGuid,
  290. (VOID **)&PciIo,
  291. This->DriverBindingHandle,
  292. SioDevice->Handle,
  293. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
  294. );
  295. if (EFI_ERROR (Status)) {
  296. gBS->UninstallMultipleProtocolInterfaces (
  297. SioDevice->Handle,
  298. &gEfiDevicePathProtocolGuid,
  299. SioDevice->DevicePath,
  300. &gEfiSioProtocolGuid,
  301. &SioDevice->Sio,
  302. NULL
  303. );
  304. }
  305. Done:
  306. if (EFI_ERROR (Status)) {
  307. if (SioDevice->DevicePath != NULL) {
  308. FreePool (SioDevice->DevicePath);
  309. }
  310. FreePool (SioDevice);
  311. }
  312. return Status;
  313. }
  314. /**
  315. Create all the ISA child devices on the ISA bus controller (PCI to ISA
  316. bridge).
  317. @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
  318. @param[in] Controller The handle of ISA bus controller.
  319. @param[in] PciIo The pointer to the PCI protocol.
  320. @param[in] ParentDevicePath Device path of the ISA bus controller.
  321. @retval The number of child device that is successfully created.
  322. **/
  323. UINT32
  324. SioCreateAllChildDevices (
  325. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  326. IN EFI_HANDLE Controller,
  327. IN EFI_PCI_IO_PROTOCOL *PciIo,
  328. IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath
  329. )
  330. {
  331. UINT32 Index;
  332. UINT32 ChildDeviceNumber;
  333. EFI_STATUS Status;
  334. ChildDeviceNumber = 0;
  335. for (Index = 0; Index < ARRAY_SIZE (mDevicesInfo); Index++) {
  336. Status = SioCreateChildDevice (
  337. This,
  338. Controller,
  339. PciIo,
  340. ParentDevicePath,
  341. Index
  342. );
  343. if (!EFI_ERROR (Status)) {
  344. ChildDeviceNumber++;
  345. }
  346. }
  347. return ChildDeviceNumber;
  348. }