PcuSio.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /** @file
  2. Produces the SIO Protocols for ISA devices integrated in the Platform
  3. Controller Unit (PCU).
  4. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __PCU_SIO_H__
  8. #define __PCU_SIO_H__
  9. #include <Uefi.h>
  10. #include <Protocol/DriverBinding.h>
  11. #include <Protocol/PciIo.h>
  12. #include <Protocol/DevicePath.h>
  13. #include <Protocol/SuperIo.h>
  14. #include <Library/UefiBootServicesTableLib.h>
  15. #include <Library/DebugLib.h>
  16. #include <Library/ReportStatusCodeLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. #include <Library/MemoryAllocationLib.h>
  19. #include <Library/DevicePathLib.h>
  20. #include <Library/UefiLib.h>
  21. #include <IndustryStandard/Pci.h>
  22. #pragma pack(1)
  23. typedef struct {
  24. EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR Io;
  25. EFI_ACPI_END_TAG_DESCRIPTOR End;
  26. } SIO_RESOURCES_IO;
  27. #pragma pack()
  28. typedef struct {
  29. UINT32 Hid;
  30. UINT32 Uid;
  31. ACPI_RESOURCE_HEADER_PTR Resources;
  32. } SIO_DEVICE_INFO;
  33. //
  34. // SIO Bus driver private data structure
  35. //
  36. typedef struct {
  37. EFI_PCI_IO_PROTOCOL *PciIo;
  38. UINT64 OriginalAttributes;
  39. } SIO_BUS_DRIVER_PRIVATE_DATA;
  40. //
  41. // SIO device private data structure
  42. //
  43. typedef struct {
  44. UINT32 Signature;
  45. EFI_HANDLE Handle;
  46. EFI_PCI_IO_PROTOCOL *PciIo;
  47. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  48. EFI_SIO_PROTOCOL Sio;
  49. UINT32 DeviceIndex;
  50. } SIO_DEV;
  51. #define SIO_DEV_SIGNATURE SIGNATURE_32 ('S', 'I', 'O', 'D')
  52. #define SIO_DEV_FROM_SIO(a) CR (a, SIO_DEV, Sio, SIO_DEV_SIGNATURE)
  53. /**
  54. Tests to see if this driver supports a given controller. If a child device is
  55. provided, it further tests to see if this driver supports creating a handle
  56. for the specified child device.
  57. This function checks to see if the driver specified by This supports the
  58. device specified by ControllerHandle. Drivers will typically use the device
  59. path attached to ControllerHandle and/or the services from the bus I/O
  60. abstraction attached to ControllerHandle to determine if the driver supports
  61. ControllerHandle. This function may be called many times during platform
  62. initialization. In order to reduce boot times, the tests performed by this
  63. function must be very small, and take as little time as possible to execute.
  64. This function must not change the state of any hardware devices, and this
  65. function must be aware that the device specified by ControllerHandle may
  66. already be managed by the same driver or a different driver. This function
  67. must match its calls to AllocatePages() with FreePages(), AllocatePool() with
  68. FreePool(), and OpenProtocol() with CloseProtocol(). Since ControllerHandle
  69. may have been previously started by the same driver, if a protocol is already
  70. in the opened state, then it must not be closed with CloseProtocol(). This is
  71. required to guarantee the state of ControllerHandle is not modified by this
  72. function.
  73. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL
  74. instance.
  75. @param[in] ControllerHandle The handle of the controller to test. This
  76. handle must support a protocol interface
  77. that supplies an I/O abstraction to the
  78. driver.
  79. @param[in] RemainingDevicePath A pointer to the remaining portion of a
  80. device path. This parameter is ignored by
  81. device drivers, and is optional for bus
  82. drivers. For bus drivers, if this parameter
  83. is not NULL, then the bus driver must
  84. determine if the bus controller specified by
  85. ControllerHandle and the child controller
  86. specified by RemainingDevicePath are both
  87. supported by this bus driver.
  88. @retval EFI_SUCCESS The device specified by ControllerHandle and
  89. RemainingDevicePath is supported by the
  90. driver specified by This.
  91. @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
  92. RemainingDevicePath is already being managed
  93. by the driver specified by This.
  94. @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
  95. RemainingDevicePath is already being managed
  96. by a different driver or an application that
  97. requires exclusive access.
  98. @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
  99. RemainingDevicePath is not supported by the
  100. driver specified by This.
  101. **/
  102. EFI_STATUS
  103. EFIAPI
  104. PcuSioDriverBindingSupported (
  105. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  106. IN EFI_HANDLE Controller,
  107. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  108. );
  109. /**
  110. Starts a device controller or a bus controller.
  111. The Start() function is designed to be invoked from the EFI boot service
  112. ConnectController(). As a result, much of the error checking on the
  113. parameters to Start() has been moved into this common boot service. It is
  114. legal to call Start() from other locations, but the following calling
  115. restrictions must be followed or the system behavior will not be
  116. deterministic.
  117. 1. ControllerHandle must be a valid EFI_HANDLE.
  118. 2. If RemainingDevicePath is not NULL, then it must be a pointer to a
  119. naturally aligned EFI_DEVICE_PATH_PROTOCOL.
  120. 3. Prior to calling Start(), the Supported() function for the driver
  121. specified by This must have been called with the same calling parameters,
  122. and Supported() must have returned EFI_SUCCESS.
  123. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL
  124. instance.
  125. @param[in] ControllerHandle The handle of the controller to start. This
  126. handle must support a protocol interface
  127. that supplies an I/O abstraction to the
  128. driver.
  129. @param[in] RemainingDevicePath A pointer to the remaining portion of a
  130. device path. This parameter is ignored by
  131. device drivers, and is optional for bus
  132. drivers. For a bus driver, if this parameter
  133. is NULL, then handles for all the children
  134. of Controller are created by this driver. If
  135. this parameter is not NULL and the first
  136. Device Path Node is not the End of Device
  137. Path Node, then only the handle for the
  138. child device specified by the first Device
  139. Path Node of RemainingDevicePath is created
  140. by this driver. If the first Device Path
  141. Node of RemainingDevicePath is the End of
  142. Device Path Node, no child handle is created
  143. by this driver.
  144. @retval EFI_SUCCESS The device was started.
  145. @retval EFI_DEVICE_ERROR The device could not be started due to a
  146. device error.
  147. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
  148. lack of resources.
  149. @retval Others The driver failded to start the device.
  150. **/
  151. EFI_STATUS
  152. EFIAPI
  153. PcuSioDriverBindingStart (
  154. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  155. IN EFI_HANDLE Controller,
  156. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  157. );
  158. /**
  159. Stops a device controller or a bus controller.
  160. The Stop() function is designed to be invoked from the EFI boot service
  161. DisconnectController(). As a result, much of the error checking on the
  162. parameters to Stop() has been moved into this common boot service. It is
  163. legal to call Stop() from other locations, but the following calling
  164. restrictions must be followed or the system behavior will not be
  165. deterministic.
  166. 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous
  167. call to this same driver's Start() function.
  168. 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a
  169. valid EFI_HANDLE. In addition, all of these handles must have been created
  170. in this driver's Start() function, and the Start() function must have
  171. called OpenProtocol() on ControllerHandle with an Attribute of
  172. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
  173. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL
  174. instance.
  175. @param[in] ControllerHandle A handle to the device being stopped. The
  176. handle must support a bus specific I/O
  177. protocol for the driver to use to stop the
  178. device.
  179. @param[in] NumberOfChildren The number of child device handles in
  180. ChildHandleBuffer.
  181. @param[in] ChildHandleBuffer An array of child handles to be freed. May be
  182. NULL if NumberOfChildren is 0.
  183. @retval EFI_SUCCESS The device was stopped.
  184. @retval EFI_DEVICE_ERROR The device could not be stopped due to a
  185. device error.
  186. **/
  187. EFI_STATUS
  188. EFIAPI
  189. PcuSioDriverBindingStop (
  190. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  191. IN EFI_HANDLE Controller,
  192. IN UINTN NumberOfChildren,
  193. IN EFI_HANDLE *ChildHandleBuffer
  194. );
  195. /**
  196. Provides a low level access to the registers for the Super I/O.
  197. @param[in] This Indicates a pointer to the calling context.
  198. @param[in] Write Specifies the type of the register operation.
  199. If this parameter is TRUE, Value is interpreted
  200. as an input parameter and the operation is a
  201. register write. If this parameter is FALSE,
  202. Value is interpreted as an output parameter and
  203. the operation is a register read.
  204. @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this
  205. parameter is set to TRUE, the Super I/O driver
  206. will turn off configuration mode of the Super
  207. I/O prior to returning from this function. If
  208. this parameter is set to FALSE, the Super I/O
  209. driver will leave Super I/O in the
  210. configuration mode. The Super I/O driver must
  211. track the current state of the Super I/O and
  212. enable the configuration mode of Super I/O if
  213. necessary prior to register access.
  214. @param[in] Register Register number.
  215. @param[in,out] Value If Write is TRUE, Value is a pointer to the
  216. buffer containing the byte of data to be
  217. written to the Super I/O register. If Write is
  218. FALSE, Value is a pointer to the destination
  219. buffer for the byte of data to be read from the
  220. Super I/O register.
  221. @retval EFI_SUCCESS The operation completed successfully.
  222. @retval EFI_INVALID_PARAMETER The Value is NULL.
  223. @retval EFI_INVALID_PARAMETER Invalid Register number.
  224. **/
  225. EFI_STATUS
  226. EFIAPI
  227. SioRegisterAccess (
  228. IN CONST EFI_SIO_PROTOCOL *This,
  229. IN BOOLEAN Write,
  230. IN BOOLEAN ExitCfgMode,
  231. IN UINT8 Register,
  232. IN OUT UINT8 *Value
  233. );
  234. /**
  235. Provides an interface to get a list of the current resources consumed by the
  236. device in the ACPI Resource Descriptor format.
  237. GetResources() returns a list of resources currently consumed by the device.
  238. The ResourceList is a pointer to the buffer containing resource descriptors
  239. for the device. The descriptors are in the format of Small or Large ACPI
  240. resource descriptor as defined by ACPI specification (2.0 & 3.0). The buffer
  241. of resource descriptors is terminated with the 'End tag' resource descriptor.
  242. @param[in] This Indicates a pointer to the calling context.
  243. @param[out] ResourceList A pointer to an ACPI resource descriptor list
  244. that defines the current resources used by the
  245. device.
  246. @retval EFI_SUCCESS The operation completed successfully.
  247. @retval EFI_INVALID_PARAMETER ResourceList is NULL.
  248. **/
  249. EFI_STATUS
  250. EFIAPI
  251. SioGetResources (
  252. IN CONST EFI_SIO_PROTOCOL *This,
  253. OUT ACPI_RESOURCE_HEADER_PTR *ResourceList
  254. );
  255. /**
  256. Sets the resources for the device.
  257. @param[in] This Indicates a pointer to the calling context.
  258. @param[in] ResourceList Pointer to the ACPI resource descriptor list.
  259. @retval EFI_SUCCESS The operation completed successfully.
  260. @retval EFI_INVALID_PARAMETER ResourceList is invalid.
  261. @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in
  262. use.
  263. **/
  264. EFI_STATUS
  265. EFIAPI
  266. SioSetResources (
  267. IN CONST EFI_SIO_PROTOCOL *This,
  268. IN ACPI_RESOURCE_HEADER_PTR ResourceList
  269. );
  270. /**
  271. Provides a collection of resource descriptor lists. Each resource descriptor
  272. list in the collection defines a combination of resources that can
  273. potentially be used by the device.
  274. @param[in] This Indicates a pointer to the calling context.
  275. @param[out] ResourceCollection Collection of the resource descriptor
  276. lists.
  277. @retval EFI_SUCCESS The operation completed successfully.
  278. @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
  279. **/
  280. EFI_STATUS
  281. EFIAPI
  282. SioPossibleResources (
  283. IN CONST EFI_SIO_PROTOCOL *This,
  284. OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
  285. );
  286. /**
  287. Provides an interface for a table based programming of the Super I/O
  288. registers.
  289. The Modify() function provides an interface for table based programming of
  290. the Super I/O registers. This function can be used to perform programming of
  291. multiple Super I/O registers with a single function call. For each table
  292. entry, the Register is read, its content is bitwise ANDed with AndMask, and
  293. then ORed with OrMask before being written back to the Register. The Super
  294. I/O driver must track the current state of the Super I/O and enable the
  295. configuration mode of Super I/O if necessary prior to table processing. Once
  296. the table is processed, the Super I/O device has to be returned to the
  297. original state.
  298. @param[in] This Indicates a pointer to the calling context.
  299. @param[in] Command A pointer to an array of NumberOfCommands
  300. EFI_SIO_REGISTER_MODIFY structures. Each
  301. structure specifies a single Super I/O register
  302. modify operation.
  303. @param[in] NumberOfCommands Number of elements in the Command array.
  304. @retval EFI_SUCCESS The operation completed successfully.
  305. @retval EFI_INVALID_PARAMETER Command is NULL.
  306. **/
  307. EFI_STATUS
  308. EFIAPI
  309. SioModify (
  310. IN CONST EFI_SIO_PROTOCOL *This,
  311. IN CONST EFI_SIO_REGISTER_MODIFY *Command,
  312. IN UINTN NumberOfCommands
  313. );
  314. #endif