EFI_STATUS PL061Initialize ( VOID ) { EFI_STATUS Status; // Check if the PL061 GPIO module exists on board Status = PL061Identify(); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto EXIT; } // Do other hardware initialisation things here as required // Disable Interrupts //if (MmioRead8 (PL061_GPIO_IE_REG) != 0) { // // Ensure interrupts are disabled //} mPL061Initialized = TRUE; EXIT: return Status; }
/** Initialize the state information for the Embedded Gpio protocol. @param ImageHandle of the loaded driver @param SystemTable Pointer to the System Table @retval EFI_SUCCESS Protocol registered @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure @retval EFI_DEVICE_ERROR Hardware problems **/ EFI_STATUS EFIAPI PL061InstallProtocol ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_HANDLE Handle; GPIO_CONTROLLER *GpioController; // // Make sure the Gpio protocol has not been installed in the system yet. // ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEmbeddedGpioProtocolGuid); Status = gBS->LocateProtocol (&gPlatformGpioProtocolGuid, NULL, (VOID **)&mPL061PlatformGpio); if (EFI_ERROR (Status) && (Status == EFI_NOT_FOUND)) { // Create the mPL061PlatformGpio mPL061PlatformGpio = (PLATFORM_GPIO_CONTROLLER *)AllocateZeroPool (sizeof (PLATFORM_GPIO_CONTROLLER) + sizeof (GPIO_CONTROLLER)); if (mPL061PlatformGpio == NULL) { DEBUG ((EFI_D_ERROR, "%a: failed to allocate PLATFORM_GPIO_CONTROLLER\n", __func__)); return EFI_BAD_BUFFER_SIZE; } mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS; mPL061PlatformGpio->GpioControllerCount = 1; mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN) mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER)); GpioController = mPL061PlatformGpio->GpioController; GpioController->RegisterBase = (UINTN) PcdGet32 (PcdPL061GpioBase); GpioController->GpioIndex = 0; GpioController->InternalGpioCount = PL061_GPIO_PINS; } Status = PL061Identify(); if (EFI_ERROR(Status)) { return EFI_DEVICE_ERROR; } // Install the Embedded GPIO Protocol onto a new handle Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces( &Handle, &gEmbeddedGpioProtocolGuid, &gGpio, NULL ); if (EFI_ERROR(Status)) { Status = EFI_OUT_OF_RESOURCES; } return Status; }