SioChip.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /** @file
  2. Super I/O specific implementation.
  3. Copyright (c) 2010 - 2019 Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "SioDriver.h"
  7. #include <Library/S3IoLib.h>
  8. LOCAL_IO_WRITE8 mIoWrite8 = IoWrite8;
  9. //
  10. // System configuration (setup) information
  11. //
  12. // SYSTEM_CONFIGURATION mSystemConfiguration;
  13. //
  14. // COM 1 UART Controller
  15. //
  16. ACPI_SIO_RESOURCES_IO_IRQ mCom1Resources = {
  17. {
  18. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR },
  19. 0x3f8,
  20. 8
  21. },
  22. {
  23. { ACPI_IRQ_NOFLAG_DESCRIPTOR },
  24. BIT4 // IRQ4
  25. },
  26. {
  27. ACPI_END_TAG_DESCRIPTOR,
  28. 0
  29. }
  30. };
  31. //
  32. // PS/2 Keyboard Controller
  33. //
  34. ACPI_SIO_RESOURCES_IO_IRQ mKeyboardResources = {
  35. {
  36. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR },
  37. 0x60,
  38. 5
  39. },
  40. {
  41. { ACPI_IRQ_NOFLAG_DESCRIPTOR },
  42. BIT1
  43. },
  44. {
  45. ACPI_END_TAG_DESCRIPTOR,
  46. 0
  47. }
  48. };
  49. //
  50. // PS/2 Mouse Controller
  51. //
  52. ACPI_SIO_RESOURCES_IO_IRQ mMouseResources = {
  53. {
  54. { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR },
  55. 0x60,
  56. 5
  57. },
  58. {
  59. { ACPI_IRQ_NOFLAG_DESCRIPTOR },
  60. BIT12
  61. },
  62. {
  63. ACPI_END_TAG_DESCRIPTOR,
  64. 0
  65. }
  66. };
  67. //
  68. // Table of SIO Controllers
  69. //
  70. DEVICE_INFO mDeviceInfo[] = {
  71. {
  72. {
  73. EISA_PNP_ID(0x501),
  74. 0
  75. },
  76. 0,
  77. RESOURCE_IO | RESOURCE_IRQ,
  78. { (ACPI_SMALL_RESOURCE_HEADER *) &mCom1Resources },
  79. { (ACPI_SMALL_RESOURCE_HEADER *) &mCom1Resources }
  80. }, // COM 1 UART Controller
  81. {
  82. {
  83. EISA_PNP_ID(0x303),
  84. 0
  85. },
  86. 0,
  87. 0, // Cannot change resource
  88. { (ACPI_SMALL_RESOURCE_HEADER *) &mKeyboardResources },
  89. { (ACPI_SMALL_RESOURCE_HEADER *) &mKeyboardResources }
  90. }, // PS/2 Keyboard Controller
  91. {
  92. {
  93. EISA_PNP_ID(0xF03),
  94. 0
  95. },
  96. 0,
  97. 0, // Cannot change resource
  98. { (ACPI_SMALL_RESOURCE_HEADER *) &mMouseResources },
  99. { (ACPI_SMALL_RESOURCE_HEADER *) &mMouseResources }
  100. } // PS/2 Mouse Controller
  101. };
  102. /**
  103. Return the supported devices.
  104. @param[out] Devices Pointer to pointer of EFI_SIO_ACPI_DEVICE_ID.
  105. Caller is responsible to free the buffer.
  106. @param[out] Count Pointer to UINTN holding the device count.
  107. **/
  108. VOID
  109. DeviceGetList (
  110. OUT EFI_SIO_ACPI_DEVICE_ID **Devices,
  111. OUT UINTN *Count
  112. )
  113. {
  114. EFI_SIO_ACPI_DEVICE_ID *LocalDevices;
  115. UINTN LocalCount;
  116. UINTN DeviceCount;
  117. UINTN Index;
  118. //
  119. // Allocate enough memory for simplicity
  120. //
  121. DeviceCount = sizeof (mDeviceInfo) / sizeof (mDeviceInfo[0]);
  122. LocalDevices = AllocatePool (sizeof (EFI_SIO_ACPI_DEVICE_ID) * DeviceCount);
  123. ASSERT (LocalDevices != NULL);
  124. if (LocalDevices == NULL) {
  125. return;
  126. }
  127. LocalCount = 0;
  128. for (Index = 0; Index < DeviceCount; Index++) {
  129. CopyMem (&LocalDevices[LocalCount], &mDeviceInfo[Index].Device, sizeof (EFI_SIO_ACPI_DEVICE_ID));
  130. LocalCount++;
  131. }
  132. *Devices = LocalDevices;
  133. *Count = LocalCount;
  134. }
  135. /**
  136. Super I/O controller initialization.
  137. @retval EFI_SUCCESS The super I/O controller is found and initialized.
  138. @retval EFI_UNSUPPORTED The super I/O controller is not found.
  139. **/
  140. EFI_STATUS
  141. SioInit (
  142. VOID
  143. )
  144. {
  145. return EFI_SUCCESS;
  146. }
  147. /**
  148. Find the DEVICE_INFO for specified Device.
  149. @param[in] Device Pointer to the EFI_SIO_ACPI_DEVICE_ID.
  150. @retval DEVICE_INFO* Pointer to the DEVICE_INFO.
  151. **/
  152. DEVICE_INFO *
  153. DeviceSearch (
  154. IN EFI_SIO_ACPI_DEVICE_ID *Device
  155. )
  156. {
  157. UINTN Index;
  158. for (Index = 0; Index < sizeof (mDeviceInfo) / sizeof (mDeviceInfo[0]); Index++) {
  159. if (CompareMem (Device, &mDeviceInfo[Index].Device, sizeof (*Device)) == 0) {
  160. return &mDeviceInfo[Index];
  161. }
  162. }
  163. ASSERT (FALSE);
  164. return NULL;
  165. }
  166. /**
  167. Program the SIO chip to enable the specified device using the default resource.
  168. @param[in] Device Pointer to EFI_SIO_ACPI_DEVICE_ID.
  169. **/
  170. VOID
  171. DeviceEnable (
  172. IN EFI_SIO_ACPI_DEVICE_ID *Device
  173. )
  174. {
  175. }
  176. /**
  177. Get the ACPI resources for specified device.
  178. @param[in] Device Pointer to EFI_SIO_ACPI_DEVICE_ID.
  179. @param[out] Resources Pointer to ACPI_RESOURCE_HEADER_PTR.
  180. @retval EFI_SUCCESS The resources are returned successfully.
  181. **/
  182. EFI_STATUS
  183. DeviceGetResources (
  184. IN EFI_SIO_ACPI_DEVICE_ID *Device,
  185. OUT ACPI_RESOURCE_HEADER_PTR *Resources
  186. )
  187. {
  188. DEVICE_INFO *DeviceInfo;
  189. DeviceInfo = DeviceSearch (Device);
  190. *Resources = DeviceInfo->Resources;
  191. return EFI_SUCCESS;
  192. }
  193. /**
  194. Set the ACPI resources for specified device.
  195. The SIO chip is programmed to use the new resources and the
  196. resources setting are saved. The function assumes the resources
  197. are valid.
  198. @param[in] Device Pointer to EFI_SIO_ACPI_DEVICE_ID.
  199. @param[in] Resources ACPI_RESOURCE_HEADER_PTR.
  200. @retval EFI_UNSUPPORTED
  201. **/
  202. EFI_STATUS
  203. DeviceSetResources (
  204. IN EFI_SIO_ACPI_DEVICE_ID *Device,
  205. IN ACPI_RESOURCE_HEADER_PTR Resources
  206. )
  207. {
  208. return EFI_UNSUPPORTED;
  209. }
  210. /**
  211. Get the possible ACPI resources for specified device.
  212. @param[in] Device Pointer to EFI_SIO_ACPI_DEVICE_ID.
  213. @param[out] Resources Pointer to ACPI_RESOURCE_HEADER_PTR.
  214. @retval EFI_SUCCESS The resources are returned successfully.
  215. **/
  216. EFI_STATUS
  217. DevicePossibleResources (
  218. IN EFI_SIO_ACPI_DEVICE_ID *Device,
  219. OUT ACPI_RESOURCE_HEADER_PTR *Resources
  220. )
  221. {
  222. DEVICE_INFO *DeviceInfo;
  223. DeviceInfo = DeviceSearch (Device);
  224. *Resources = DeviceInfo->PossibleResources;
  225. return EFI_SUCCESS;
  226. }