SasPlatform.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /** @file
  2. *
  3. * Copyright (c) 2017, Hisilicon Limited. All rights reserved.
  4. * Copyright (c) 2017, Linaro Limited. All rights reserved.
  5. *
  6. * This program and the accompanying materials
  7. * are licensed and made available under the terms and conditions of the BSD License
  8. * which accompanies this distribution. The full text of the license may be found at
  9. * http://opensource.org/licenses/bsd-license.php
  10. *
  11. * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  13. *
  14. **/
  15. #include <PiDxe.h>
  16. #include <Uefi.h>
  17. #include <Library/BaseLib.h>
  18. #include <Library/BaseMemoryLib.h>
  19. #include <Library/DebugLib.h>
  20. #include <Library/MemoryAllocationLib.h>
  21. #include <Library/UefiBootServicesTableLib.h>
  22. #include <Library/UefiDriverEntryPoint.h>
  23. #include <Library/UefiLib.h>
  24. #include <Protocol/HisiPlatformSasProtocol.h>
  25. #define SAS0BusAddr 0xc3000000
  26. #define SAS1BusAddr 0xa2000000
  27. #define SAS2BusAddr 0xa3000000
  28. #define SAS0ResetAddr 0xc0000000
  29. #define SAS1ResetAddr 0xa0000000
  30. #define SAS2ResetAddr 0xa0000000
  31. typedef struct {
  32. UINTN Signature;
  33. EFI_HANDLE Handle;
  34. HISI_PLATFORM_SAS_PROTOCOL SasPlatformProtocol;
  35. } SAS_PLATFORM_INSTANCE;
  36. STATIC HISI_PLATFORM_SAS_PROTOCOL mSasPlatformProtocol[] = {
  37. {
  38. 0,
  39. FALSE,
  40. SAS0BusAddr,
  41. SAS0ResetAddr
  42. },
  43. {
  44. 1,
  45. TRUE,
  46. SAS1BusAddr,
  47. SAS1ResetAddr
  48. },
  49. {
  50. 2,
  51. FALSE,
  52. SAS2BusAddr,
  53. SAS2ResetAddr
  54. }
  55. };
  56. EFI_STATUS
  57. EFIAPI
  58. SasPlatformInitialize (
  59. IN EFI_HANDLE ImageHandle,
  60. IN EFI_SYSTEM_TABLE *SystemTable
  61. )
  62. {
  63. UINTN Loop;
  64. SAS_PLATFORM_INSTANCE *PrivateData;
  65. EFI_STATUS Status;
  66. for (Loop = 0; Loop < ARRAY_SIZE (mSasPlatformProtocol); Loop++) {
  67. if (mSasPlatformProtocol[Loop].Enable != TRUE) {
  68. continue;
  69. }
  70. PrivateData = AllocateZeroPool (sizeof(SAS_PLATFORM_INSTANCE));
  71. if (PrivateData == NULL) {
  72. return EFI_OUT_OF_RESOURCES;
  73. }
  74. PrivateData->SasPlatformProtocol = mSasPlatformProtocol[Loop];
  75. Status = gBS->InstallMultipleProtocolInterfaces (
  76. &PrivateData->Handle,
  77. &gHisiPlatformSasProtocolGuid,
  78. &PrivateData->SasPlatformProtocol,
  79. NULL
  80. );
  81. if (EFI_ERROR (Status)) {
  82. FreePool (PrivateData);
  83. DEBUG ((DEBUG_ERROR,
  84. "[%a]:[%dL] InstallProtocolInterface fail. %r\n",
  85. __FUNCTION__,
  86. __LINE__,
  87. Status));
  88. continue;
  89. }
  90. }
  91. DEBUG ((DEBUG_INFO, "sas platform init driver Ok!!!\n"));
  92. return EFI_SUCCESS;
  93. }