LpcIsaAcpi.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /** @file
  2. Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. LpcIsaAcpi.c
  6. Abstract: IsaAcpi implementation
  7. --*/
  8. #include "LpcDriver.h"
  9. //
  10. // PS/2 Keyboard Controller
  11. //
  12. static EFI_ISA_ACPI_RESOURCE mLpcWpce791Ps2KeyboardDeviceResources[] = {
  13. {EfiIsaAcpiResourceIo, 0, 0x60, 0x64},
  14. {EfiIsaAcpiResourceInterrupt, 0, 1, 0},
  15. {EfiIsaAcpiResourceEndOfList, 0, 0, 0}
  16. };
  17. //
  18. // PS/2 Mouse Controller
  19. //
  20. static EFI_ISA_ACPI_RESOURCE mLpcWpce791Ps2MouseDeviceResources[] = {
  21. {EfiIsaAcpiResourceIo, 0, 0x60, 0x64},
  22. {EfiIsaAcpiResourceInterrupt, 0, 12, 0},
  23. {EfiIsaAcpiResourceEndOfList, 0, 0, 0}
  24. };
  25. //
  26. // COM
  27. //
  28. static EFI_ISA_ACPI_RESOURCE mLpcWpce791ComDeviceResources[] = {
  29. {EfiIsaAcpiResourceIo, 0, 0x3f8, 0x3ff},
  30. {EfiIsaAcpiResourceInterrupt, 0, 4, 0},
  31. {EfiIsaAcpiResourceEndOfList, 0, 0, 0}
  32. };
  33. //
  34. // Table of ISA Controllers
  35. //
  36. EFI_ISA_ACPI_RESOURCE_LIST mLpcWpce791DeviceList[] = {
  37. {{EISA_PNP_ID(0x303), 0}, mLpcWpce791Ps2KeyboardDeviceResources }, // PS/2 Keyboard Controller
  38. {{EISA_PNP_ID(0xF03), 0}, mLpcWpce791Ps2MouseDeviceResources }, // PS/2 Mouse Controller
  39. {{EISA_PNP_ID(0x501), 0}, mLpcWpce791ComDeviceResources }, // COM
  40. {{0, 0}, NULL } // End
  41. };
  42. static ICH_DMA_INIT mIchDmaInitTable [] = {
  43. //
  44. //Register OFFSET, Value
  45. //
  46. 0x0D8, 0x000, // Reset DMA Controller 2
  47. 0x0D0, 0x000, // Enable DMA controller 2
  48. 0x00C, 0x000, // Reset DMA Controller 1
  49. 0x008, 0x000, // Enable DMA controller 1
  50. //
  51. // Channel 4
  52. //
  53. 0x0D6, 0x0c0, // DMA contr. 2 Cascade mode, addr. increment, disable auto init.
  54. 0x0D2, 0x000, // Clear write request register
  55. 0x0d4, 0x000, // Enable DREQs for channel
  56. //
  57. // Channel 0
  58. //
  59. 0x00B, 0x040, // DMA contr. 1 single mode, addr. increment, disable auto init.
  60. 0x009, 0x000, // Clear write request register
  61. 0x00A, 0x000, // Enable DREQs for channel
  62. //
  63. // Channel 1
  64. //
  65. 0x00B, 0x041, // DMA contr. 1 single mode, addr. increment, disable auto init.
  66. 0x009, 0x001, // Clear write request register
  67. 0x00A, 0x001, // Enable DREQs for channel
  68. //
  69. // Channel 2
  70. //
  71. 0x00B, 0x042, // DMA contr. 1 single mode, addr. increment, disable auto init.
  72. 0x009, 0x002, // Clear write request register
  73. 0x00A, 0x002, // Enable DREQs for channel
  74. //
  75. // Channel 3
  76. //
  77. 0x00B, 0x043, // DMA contr. 1 single mode, addr. increment, disable auto init.
  78. 0x009, 0x003, // Clear write request register
  79. 0x00A, 0x003, // Enable DREQs for channel
  80. //
  81. // Channel 5
  82. //
  83. 0x0D6, 0x041, // DMA contr. 2 single mode, addr. increment, disable auto init.
  84. 0x0D2, 0x001, // Clear write request register
  85. 0x0D4, 0x001, // Enable DREQs for channel
  86. //
  87. // Channel 6
  88. //
  89. 0x0D6, 0x042, // DMA contr. 2 single mode, addr. increment, disable auto init.
  90. 0x0D2, 0x002, // Clear write request register
  91. 0x0D4, 0x002, // Enable DREQs for channel
  92. //
  93. // Channel 7
  94. //
  95. 0x0D6, 0x043, // DMA contr. 2 single mode, addr. increment, disable auto init.
  96. 0x0D2, 0x003, // Clear write request register
  97. 0x0D4, 0x003 // Enable DREQs for channel
  98. };
  99. //
  100. // ISA ACPI Protocol Functions
  101. //
  102. /**
  103. Enumerate the ISA devices on the ISA bus
  104. **/
  105. VOID
  106. IsaDeviceLookup (
  107. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  108. OUT EFI_ISA_ACPI_RESOURCE_LIST **IsaAcpiDevice,
  109. OUT EFI_ISA_ACPI_RESOURCE_LIST **NextIsaAcpiDevice
  110. )
  111. {
  112. UINTN Index;
  113. *IsaAcpiDevice = NULL;
  114. if (NextIsaAcpiDevice != NULL) {
  115. *NextIsaAcpiDevice = NULL;
  116. }
  117. if (Device == NULL) {
  118. Index = 0;
  119. } else {
  120. for(Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {
  121. if (Device->HID == mLpcWpce791DeviceList[Index].Device.HID &&
  122. Device->UID == mLpcWpce791DeviceList[Index].Device.UID ) {
  123. break;
  124. }
  125. }
  126. if (mLpcWpce791DeviceList[Index].Device.HID == 0) {
  127. return;
  128. }
  129. *IsaAcpiDevice = &(mLpcWpce791DeviceList[Index]);
  130. Index++;
  131. }
  132. if (NextIsaAcpiDevice != NULL && mLpcWpce791DeviceList[Index].Device.HID != 0){
  133. *NextIsaAcpiDevice = &(mLpcWpce791DeviceList[Index]);
  134. }
  135. }
  136. /**
  137. Enumerate the ISA devices on the ISA bus
  138. It is hard code now and future it will get from ACPI table
  139. **/
  140. EFI_STATUS
  141. EFIAPI
  142. IsaDeviceEnumerate (
  143. IN EFI_ISA_ACPI_PROTOCOL *This,
  144. OUT EFI_ISA_ACPI_DEVICE_ID **Device
  145. )
  146. {
  147. EFI_ISA_ACPI_RESOURCE_LIST *IsaAcpiDevice;
  148. EFI_ISA_ACPI_RESOURCE_LIST *NextIsaAcpiDevice;
  149. IsaDeviceLookup (*Device, &IsaAcpiDevice, &NextIsaAcpiDevice);
  150. if (NextIsaAcpiDevice == NULL) {
  151. return EFI_NOT_FOUND;
  152. }
  153. *Device = &(NextIsaAcpiDevice->Device);
  154. return EFI_SUCCESS;
  155. }
  156. /**
  157. Set ISA device power use sio
  158. **/
  159. EFI_STATUS
  160. EFIAPI
  161. IsaDeviceSetPower (
  162. IN EFI_ISA_ACPI_PROTOCOL *This,
  163. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  164. IN BOOLEAN OnOff
  165. )
  166. {
  167. return EFI_UNSUPPORTED;
  168. }
  169. /**
  170. Get current Resource of the specific ISA device
  171. It is hardcode now and future will get from ACPI table
  172. **/
  173. EFI_STATUS
  174. EFIAPI
  175. IsaGetCurrentResource (
  176. IN EFI_ISA_ACPI_PROTOCOL *This,
  177. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  178. OUT EFI_ISA_ACPI_RESOURCE_LIST **ResourceList
  179. )
  180. {
  181. IsaDeviceLookup (Device, ResourceList, NULL);
  182. if (*ResourceList == NULL || (*ResourceList)->ResourceItem == NULL) {
  183. return EFI_NOT_FOUND;
  184. }
  185. return EFI_SUCCESS;
  186. }
  187. EFI_STATUS
  188. EFIAPI
  189. IsaGetPossibleResource (
  190. IN EFI_ISA_ACPI_PROTOCOL *This,
  191. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  192. OUT EFI_ISA_ACPI_RESOURCE_LIST **ResourceList
  193. )
  194. {
  195. //
  196. // Not supported yet
  197. //
  198. return EFI_UNSUPPORTED;
  199. }
  200. EFI_STATUS
  201. EFIAPI
  202. IsaSetResource (
  203. IN EFI_ISA_ACPI_PROTOCOL *This,
  204. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  205. IN EFI_ISA_ACPI_RESOURCE_LIST *ResourceList
  206. )
  207. {
  208. return EFI_UNSUPPORTED;
  209. }
  210. EFI_STATUS
  211. EFIAPI
  212. IsaEnableDevice (
  213. IN EFI_ISA_ACPI_PROTOCOL *This,
  214. IN EFI_ISA_ACPI_DEVICE_ID *Device,
  215. IN BOOLEAN Enable
  216. )
  217. {
  218. return EFI_UNSUPPORTED;
  219. }
  220. /**
  221. Clear out Resource List if device is set to disable by platform policy
  222. **/
  223. VOID
  224. EmptyResourceList (
  225. IN UINT32 DeviceHid
  226. )
  227. {
  228. UINT8 Index;
  229. for (Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {
  230. if (DeviceHid == mLpcWpce791DeviceList[Index].Device.HID) {
  231. mLpcWpce791DeviceList[Index].ResourceItem = NULL;
  232. }
  233. }
  234. return;
  235. }
  236. /**
  237. Clear out Resource List if device is set to disable by platform policy
  238. **/
  239. VOID
  240. EmptyResourceListHidUid (
  241. IN UINT32 DeviceHid,
  242. IN UINT32 DeviceUid
  243. )
  244. {
  245. UINT8 Index;
  246. for (Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {
  247. if ((DeviceHid == mLpcWpce791DeviceList[Index].Device.HID) &&
  248. (DeviceUid == mLpcWpce791DeviceList[Index].Device.UID)) {
  249. mLpcWpce791DeviceList[Index].ResourceItem = NULL;
  250. }
  251. }
  252. return;
  253. }
  254. EFI_STATUS
  255. EFIAPI
  256. IsaInitDevice (
  257. IN EFI_ISA_ACPI_PROTOCOL *This,
  258. IN EFI_ISA_ACPI_DEVICE_ID *Device
  259. )
  260. {
  261. EFI_WPCE791_POLICY_PROTOCOL *LpcWpce791Policy;
  262. EFI_STATUS Status;
  263. //
  264. // Disable configuration according to platform protocol
  265. //
  266. Status = gBS->LocateProtocol (
  267. &gEfiLpcWpce791PolicyProtocolGuid,
  268. NULL,
  269. (VOID **) &LpcWpce791Policy
  270. );
  271. if (!EFI_ERROR(Status)) {
  272. if (LpcWpce791Policy->DeviceEnables.Ps2Keyboard == EFI_WPCE791_PS2_KEYBOARD_DISABLE) {
  273. EmptyResourceList(EISA_PNP_ID(0x303));
  274. DisableLogicalDevice (SIO_KEYBOARD);
  275. EmptyResourceList(EISA_PNP_ID(0xF03));
  276. DisableLogicalDevice (SIO_KEYBOARD);
  277. }
  278. if (LpcWpce791Policy->DeviceEnables.Ps2Mouse == EFI_WPCE791_PS2_MOUSE_DISABLE) {
  279. EmptyResourceList(EISA_PNP_ID(0xF03));
  280. DisableLogicalDevice (SIO_MOUSE);
  281. }
  282. }
  283. return EFI_SUCCESS;
  284. }
  285. EFI_STATUS
  286. EFIAPI
  287. LpcInterfaceInit (
  288. IN EFI_ISA_ACPI_PROTOCOL *This
  289. )
  290. {
  291. EFI_PCI_IO_PROTOCOL *PciIo;
  292. UINTN Index;
  293. PciIo = (LPC_ISA_ACPI_FROM_THIS (This))->PciIo;
  294. //
  295. // DMA controller initialize
  296. //
  297. for (Index=0; Index < (sizeof(mIchDmaInitTable)/sizeof(ICH_DMA_INIT)); Index++) {
  298. PciIo->Io.Write (
  299. PciIo,
  300. EfiPciIoWidthUint8,
  301. EFI_PCI_IO_PASS_THROUGH_BAR,
  302. mIchDmaInitTable[Index].Register,
  303. 1,
  304. &mIchDmaInitTable[Index].Value
  305. );
  306. }
  307. return EFI_SUCCESS;
  308. }