SioService.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /** @file
  2. Super I/O Interface 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. /**
  8. Provides an interface to get a list of the current resources consumed by the device in the ACPI
  9. Resource Descriptor format.
  10. GetResources() returns a list of resources currently consumed by the device. The
  11. ResourceList is a pointer to the buffer containing resource descriptors for the device. The
  12. descriptors are in the format of Small or Large ACPI resource descriptor as defined by ACPI
  13. specification (2.0 & 3.0). The buffer of resource descriptors is terminated with the 'End tag'
  14. resource descriptor.
  15. @param[in] This Indicates a pointer to the calling context.
  16. @param[out] ResourceList A pointer to an ACPI resource descriptor list that defines the current resources
  17. used by the device. Type ACPI_RESOURCE_HEADER_PTR is defined in the "Related
  18. Definitions" below.
  19. @retval EFI_SUCCESS The operation completed successfully
  20. @retval EFI_INVALID_PARAMETER ResourceList is NULL
  21. **/
  22. EFI_STATUS
  23. EFIAPI
  24. SioGetResources (
  25. IN CONST EFI_SIO_PROTOCOL *This,
  26. OUT ACPI_RESOURCE_HEADER_PTR *ResourceList
  27. )
  28. {
  29. SIO_DEV *SioDev;
  30. if (ResourceList == NULL) {
  31. return EFI_INVALID_PARAMETER;
  32. }
  33. SioDev = SIO_DEV_FROM_THIS (This);
  34. return DeviceGetResources (&SioDev->Device, ResourceList);
  35. }
  36. /**
  37. Provides a collection of resource descriptor lists. Each resource descriptor list in the collection
  38. defines a combination of resources that can potentially be used by the device.
  39. @param[in] This Indicates a pointer to the calling context.
  40. @param[out] ResourceCollection Collection of the resource descriptor lists.
  41. @retval EFI_SUCCESS The operation completed successfully
  42. @retval EFI_INVALID_PARAMETER ResourceCollection is NULL
  43. **/
  44. EFI_STATUS
  45. EFIAPI
  46. SioPossibleResources (
  47. IN CONST EFI_SIO_PROTOCOL *This,
  48. OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
  49. )
  50. {
  51. SIO_DEV *SioDev;
  52. if (ResourceCollection == NULL) {
  53. return EFI_INVALID_PARAMETER;
  54. }
  55. SioDev = SIO_DEV_FROM_THIS (This);
  56. return DevicePossibleResources (&SioDev->Device, ResourceCollection);
  57. }
  58. /**
  59. Sets the resources for the device.
  60. @param[in] This Indicates a pointer to the calling context.
  61. @param[in] ResourceList Pointer to the ACPI resource descriptor list. Type ACPI_RESOURCE_HEADER_PTR
  62. is defined in the "Related Definitions" section of
  63. EFI_SIO_PROTOCOL.GetResources().
  64. @retval EFI_SUCCESS The operation completed successfully
  65. @retval EFI_INVALID_PARAMETER ResourceList is invalid
  66. @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in use
  67. **/
  68. EFI_STATUS
  69. EFIAPI
  70. SioSetResources (
  71. IN CONST EFI_SIO_PROTOCOL *This,
  72. IN ACPI_RESOURCE_HEADER_PTR ResourceList
  73. )
  74. {
  75. SIO_DEV *SioDev;
  76. ACPI_RESOURCE_HEADER_PTR ResourcePtr;
  77. ACPI_RESOURCE_HEADER_PTR ResourceCollection;
  78. ACPI_RESOURCE_HEADER_PTR ResourcePtr2;
  79. BOOLEAN Found;
  80. ResourcePtr = ResourceList;
  81. SioDev = SIO_DEV_FROM_THIS (This);
  82. //
  83. // Check whether the resource is in the possible resource collection
  84. //
  85. DevicePossibleResources (&SioDev->Device, &ResourceCollection);
  86. while (ResourcePtr.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
  87. Found = FALSE;
  88. ResourcePtr2 = ResourceCollection;
  89. while (ResourcePtr2.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
  90. if (ResourcePtr2.SmallHeader->Bits.Type == 0) {
  91. //
  92. // Small Header
  93. //
  94. if (CompareMem (
  95. ResourcePtr2.SmallHeader,
  96. ResourcePtr.SmallHeader,
  97. ResourcePtr2.SmallHeader->Bits.Length + sizeof (*ResourcePtr2.SmallHeader)
  98. ) == 0) {
  99. Found = TRUE;
  100. break;
  101. }
  102. ResourcePtr2.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr2.SmallHeader
  103. + ResourcePtr2.SmallHeader->Bits.Length
  104. + sizeof (*ResourcePtr2.SmallHeader));
  105. } else {
  106. //
  107. // Large Header
  108. //
  109. if (CompareMem (
  110. ResourcePtr2.LargeHeader,
  111. ResourcePtr.LargeHeader,
  112. ResourcePtr2.LargeHeader->Length + sizeof (*ResourcePtr2.LargeHeader)
  113. ) == 0) {
  114. Found = TRUE;
  115. break;
  116. }
  117. ResourcePtr2.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr2.LargeHeader
  118. + ResourcePtr2.LargeHeader->Length
  119. + sizeof (*ResourcePtr2.LargeHeader));
  120. }
  121. }
  122. if (!Found) {
  123. return EFI_ACCESS_DENIED;
  124. }
  125. if (ResourcePtr.SmallHeader->Bits.Type == 0) {
  126. ResourcePtr.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.SmallHeader
  127. + ResourcePtr.SmallHeader->Bits.Length
  128. + sizeof (*ResourcePtr.SmallHeader));
  129. } else {
  130. ResourcePtr.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.LargeHeader
  131. + ResourcePtr.LargeHeader->Length
  132. + sizeof (*ResourcePtr.LargeHeader));
  133. }
  134. }
  135. //
  136. // ResourceList can be set
  137. //
  138. return DeviceSetResources (&SioDev->Device, ResourceList);
  139. }
  140. /**
  141. Provides a low level access to the registers for the Super I/O.
  142. @param[in] This Indicates a pointer to the calling context.
  143. @param[in] Write Specifies the type of the register operation. If this parameter is TRUE,
  144. Value is interpreted as an input parameter and the operation is a register write.
  145. If this parameter is FALSE, Value is interpreted as an output parameter and the
  146. operation is a register read.
  147. @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this parameter is set to TRUE, the
  148. Super I/O driver will turn off configuration mode of the Super I/O prior to returning
  149. from this function. If this parameter is set to FALSE, the Super I/O driver will
  150. leave Super I/O in the configuration mode.
  151. The Super I/O driver must track the current state of the Super I/O and enable the
  152. configuration mode of Super I/O if necessary prior to register access.
  153. @param[in] Register Register number.
  154. @param[in, out] Value If Write is TRUE, Value is a pointer to the buffer containing the byte of data to be
  155. written to the Super I/O register. If Write is FALSE, Value is a pointer to the
  156. destination buffer for the byte of data to be read from the Super I/O register.
  157. @retval EFI_SUCCESS The operation completed successfully
  158. @retval EFI_INVALID_PARAMETER The Value is NULL
  159. @retval EFI_INVALID_PARAMETER Invalid Register number
  160. **/
  161. EFI_STATUS
  162. EFIAPI
  163. SioRegisterAccess (
  164. IN CONST EFI_SIO_PROTOCOL *This,
  165. IN BOOLEAN Write,
  166. IN BOOLEAN ExitCfgMode,
  167. IN UINT8 Register,
  168. IN OUT UINT8 *Value
  169. )
  170. {
  171. if (Value == NULL) {
  172. return EFI_INVALID_PARAMETER;
  173. }
  174. return EFI_SUCCESS;
  175. }
  176. /**
  177. Provides an interface for a table based programming of the Super I/O registers.
  178. The Modify() function provides an interface for table based programming of the Super I/O
  179. registers. This function can be used to perform programming of multiple Super I/O registers with a
  180. single function call. For each table entry, the Register is read, its content is bitwise ANDed with
  181. AndMask, and then ORed with OrMask before being written back to the Register. The Super
  182. I/O driver must track the current state of the Super I/O and enable the configuration mode of Super I/
  183. O if necessary prior to table processing. Once the table is processed, the Super I/O device has to be
  184. returned to the original state.
  185. @param[in] This Indicates a pointer to the calling context.
  186. @param[in] Command A pointer to an array of NumberOfCommands EFI_SIO_REGISTER_MODIFY
  187. structures. Each structure specifies a single Super I/O register modify operation.
  188. Type EFI_SIO_REGISTER_MODIFY is defined in the "Related Definitions" below.
  189. @param[in] NumberOfCommands Number of elements in the Command array.
  190. @retval EFI_SUCCESS The operation completed successfully
  191. @retval EFI_INVALID_PARAMETER Command is NULL
  192. **/
  193. EFI_STATUS
  194. EFIAPI
  195. SioModify (
  196. IN CONST EFI_SIO_PROTOCOL *This,
  197. IN CONST EFI_SIO_REGISTER_MODIFY *Command,
  198. IN UINTN NumberOfCommands
  199. )
  200. {
  201. if (Command == NULL) {
  202. return EFI_INVALID_PARAMETER;
  203. }
  204. return EFI_SUCCESS;
  205. }