EFI_STATUS EFIAPI PlatformDriverOverrideEntry ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Platform Driver Override driver entry point, install the Platform Driver Override Protocol Arguments: (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) Returns: EFI_STATUS --*/ { DxeInitializeDriverLib (ImageHandle, SystemTable); mEnvironmentVariableRead = FALSE; mCallerImageHandle = ImageHandle; InitializeListHead (&mMappingDataBase); return LibInstallPlatformDriverOverrideProtocol (&gPlatformDriverOverride); }
/********************************************************************************* * Name: FchAcpiCsInit * * Description * Entry point of the AMD FCH ACPI driver * * Input * ImageHandle : EFI Image Handle for the DXE driver * SystemTable : pointer to the EFI system table * * Output * EFI_SUCCESS : Module initialized successfully * EFI_ERROR : Initialization failed (see error for more details) * *********************************************************************************/ EFI_STATUS EFIAPI FchAcpiCsInit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { VOID *Registration; EFI_STATUS Status; EFI_EVENT Event; DxeInitializeDriverLib (ImageHandle, SystemTable); Status = LibFchDxeInitialization (SystemTable); // Allocate memory for the private data Status = gBS->AllocatePool ( EfiReservedMemoryType, sizeof (AMD_FCH_COMMON_DATA), &mFchCommonData ); ASSERT_EFI_ERROR (Status); // Initialize the Config table with default value Status = FchInitDefaultConfigDxe (mFchCommonData); //Register event to do FCH ACPI Initialization at Ready-to-Boot Status = EfiCreateEventReadyToBoot ( EFI_TPL_CALLBACK, FchAcpiReadyToBootInit, NULL, &Event ); // // Register event for FchAcpiInstallNotify // EfiLibCreateProtocolNotifyEvent ( &gEfiAcpiSdtProtocolGuid, EFI_TPL_CALLBACK, FchAcpiInstallNotify, NULL, &Registration ); // // Register event for FchAcpiInstallNotify // EfiLibCreateProtocolNotifyEvent ( &gEfiPciIoProtocolGuid, EFI_TPL_CALLBACK, FchAcpiInstall2Notify, NULL, &Registration ); return Status; }
// // Implementation // EFI_STATUS InitializePciHostBridge ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Entry point of this driver Arguments: ImageHandle - SystemTable - Returns: --*/ // TODO: EFI_DEVICE_ERROR - add return value to function comment // TODO: EFI_DEVICE_ERROR - add return value to function comment // TODO: EFI_SUCCESS - add return value to function comment { EFI_STATUS Status; UINTN Loop1; UINTN Loop2; PCI_HOST_BRIDGE_INSTANCE *HostBridge; PCI_ROOT_BRIDGE_INSTANCE *PrivateData; DxeInitializeDriverLib (ImageHandle, SystemTable); mDriverImageHandle = ImageHandle; // // Support one Host Bridge (one Root Bridge in this Host Bridge) // // // Create Host Bridge Device Handle // for (Loop1 = 0; Loop1 < HOST_BRIDGE_NUMBER; Loop1++) { Status = gBS->AllocatePool ( EfiBootServicesData, sizeof (PCI_HOST_BRIDGE_INSTANCE), &HostBridge ); ASSERT (!EFI_ERROR (Status)); HostBridge->Signature = PCI_HOST_BRIDGE_SIGNATURE; HostBridge->RootBridgeNumber = mRootBridgeNumber[Loop1]; HostBridge->ResourceSubmited = FALSE; HostBridge->CanRestarted = TRUE; HostBridge->ResAlloc.NotifyPhase = NotifyPhase; HostBridge->ResAlloc.GetNextRootBridge = GetNextRootBridge; HostBridge->ResAlloc.GetAllocAttributes = GetAttributes; HostBridge->ResAlloc.StartBusEnumeration = StartBusEnumeration; HostBridge->ResAlloc.SetBusNumbers = SetBusNumbers; HostBridge->ResAlloc.SubmitResources = SubmitResources; HostBridge->ResAlloc.GetProposedResources = GetProposedResources; HostBridge->ResAlloc.PreprocessController = PreprocessController; HostBridge->HostBridgeHandle = NULL; Status = gBS->InstallProtocolInterface ( &HostBridge->HostBridgeHandle, &gEfiPciHostBridgeResourceAllocationProtocolGuid, EFI_NATIVE_INTERFACE, &HostBridge->ResAlloc ); if (EFI_ERROR (Status)) { gBS->FreePool (HostBridge); return EFI_DEVICE_ERROR; } // // Create Root Bridge Device Handle in this Host Bridge // InitializeListHead (&HostBridge->Head); for (Loop2 = 0; Loop2 < HostBridge->RootBridgeNumber; Loop2++) { Status = gBS->AllocatePool ( EfiBootServicesData, sizeof (PCI_ROOT_BRIDGE_INSTANCE), &PrivateData ); ASSERT (!EFI_ERROR (Status)); PrivateData->Signature = PCI_ROOT_BRIDGE_SIGNATURE; PrivateData->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &mEfiPciRootBridgeDevicePath[Loop1][Loop2]; RootBridgeConstructor ( &PrivateData->Io, HostBridge->HostBridgeHandle, mRootBridgeAttribute[Loop1][Loop2], mResAppeture[Loop1][Loop2] ); PrivateData->Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces ( &PrivateData->Handle, &gEfiDevicePathProtocolGuid, PrivateData->DevicePath, &gEfiPciRootBridgeIoProtocolGuid, &PrivateData->Io, NULL ); if (EFI_ERROR (Status)) { gBS->FreePool (PrivateData); return EFI_DEVICE_ERROR; } // // Install DeviceIo // Status = DeviceIoConstructor ( PrivateData->Handle, &PrivateData->Io, PrivateData->DevicePath ); InsertTailList (&HostBridge->Head, &PrivateData->Link); } // // end for // } // // end for // Status = gDS->AddIoSpace ( EfiGcdIoTypeIo, RES_IO_BASE, RES_IO_LIMIT - RES_IO_BASE + 1 ); Status = gDS->AddMemorySpace ( EfiGcdMemoryTypeMemoryMappedIo, RES_MEM_BASE, RES_MEM_LIMIT - RES_MEM_BASE + 1, 0 ); return EFI_SUCCESS; }
/******************************************************************************** * Name: AmdFchWheaInitEntry * * Description * AmdFchWheaInit Entrypoint * * Input * * Output * EFI_UNSUPPORTED : unsupported function * *********************************************************************************/ EFI_STATUS AmdFchWheaInitEntry ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; BOOLEAN InSmm; FCH_INIT_PROTOCOL *AmdFchInit; EFI_SMM_BASE_PROTOCOL *SmmBase; FCH_SMM_SW_DISPATCH_PROTOCOL *AmdSwDispatch; FCH_SMM_SW_REGISTER_CONTEXT SwRegisterContext; EFI_HANDLE SwHandle; FCH_SMM_MISC_DISPATCH_PROTOCOL *AmdFchSmmMiscDispatch; FCH_SMM_MISC_REGISTER_CONTEXT MiscRegisterContext; EFI_HANDLE MiscHandle; EFI_SMM_SYSTEM_TABLE *mSmst; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; EFI_DEVICE_PATH_PROTOCOL *CompleteFilePath; EFI_HANDLE SmmImageHandle; EFI_EVENT InstallAmdTableEvent; EFI_HANDLE Handle; UINT8 *buffer; InSmm = FALSE; DxeInitializeDriverLib (ImageHandle, SystemTable); Status = gBS->LocateProtocol ( &gFchInitProtocolGuid, NULL, &AmdFchInit ); ASSERT_EFI_ERROR (Status); if (AmdFchInit->FchPolicy.Gpp.PcieAer == 0) { return Status; } Status = gBS->LocateProtocol ( &gEfiSmmBaseProtocolGuid, NULL, &SmmBase ); if (EFI_ERROR (Status)) { return Status; } SmmBase->GetSmstLocation ( SmmBase, &mSmst ); SmmBase->InSmm ( SmmBase, &InSmm ); if (!InSmm) { Status = EfiCreateEventReadyToBoot ( EFI_TPL_CALLBACK, AmdWheaCheckInstallTables, NULL, &InstallAmdTableEvent ); // // Allocate memory and Initialize for Data block // Status = gBS->AllocatePool ( EfiReservedMemoryType, sizeof (AMD_FCH_WHEA_EINJ_BUFFER), (VOID **)&buffer ); if (EFI_ERROR (Status)) { return Status; } EfiZeroMem (buffer, sizeof (AMD_FCH_WHEA_EINJ_BUFFER)); mEinjData = (AMD_FCH_WHEA_EINJ_BUFFER *)buffer; mEinjData->Valid = FALSE; mEinjData->PlatformEinjValid = FALSE; // // Allocate memory and Initialize for Error Data block // Status = gBS->AllocatePool ( EfiReservedMemoryType, MAX_ERROR_BLOCK_SIZE, (VOID **)&buffer ); if (EFI_ERROR (Status)) { return Status; } EfiZeroMem (buffer, MAX_ERROR_BLOCK_SIZE); mEinjData->AmdHwErrBlk = (GENERIC_ERROR_STATUS_BLOCK *)buffer; AmdErrBlkAddressUpdate (); Handle = ImageHandle; Status = gBS->InstallProtocolInterface ( &Handle, &mEfiAmdFchWheaDataGuid, EFI_NATIVE_INTERFACE, mEinjData ); if (EFI_ERROR (Status)) { return (Status); } if (ImageHandle != NULL) { Status = gBS->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, &LoadedImage ); if (EFI_ERROR (Status)) { return Status; } Status = gBS->HandleProtocol ( LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID*) &ImageDevicePath ); if (EFI_ERROR (Status)) { return Status; } CompleteFilePath = AppendDevicePath ( ImageDevicePath, LoadedImage->FilePath ); // Load the image in memory to SMRAM, this automatically triggers SMI SmmBase->Register ( SmmBase, CompleteFilePath, NULL, 0, &SmmImageHandle, FALSE ); } } else { Status = gBS->LocateProtocol ( &mEfiAmdFchWheaDataGuid, NULL, &mEinjData ); if (EFI_ERROR (Status)) { return Status; } Status = gBS->LocateProtocol ( &gFchSmmSwDispatchProtocolGuid, NULL, &AmdSwDispatch ); ASSERT_EFI_ERROR (Status); SwRegisterContext.AmdSwValue = EINJ_TRIGGER_ACTION_SWSMI; Status = AmdSwDispatch->Register ( AmdSwDispatch, AmdSmiEinjTriggerActionCallBack, &SwRegisterContext, &SwHandle ); if (EFI_ERROR (Status)) { return Status; } Status = gBS->LocateProtocol ( &gFchSmmMiscDispatchProtocolGuid, NULL, &AmdFchSmmMiscDispatch ); ASSERT_EFI_ERROR (Status); MiscRegisterContext.SmiStatusReg = FCH_SMI_REG88; MiscRegisterContext.SmiStatusBit = BIT21; MiscRegisterContext.Order = 0x80; Status = AmdFchSmmMiscDispatch->Register ( AmdFchSmmMiscDispatch, AmdMiscFchWheaHwSmiCallback, &MiscRegisterContext, &MiscHandle ); MiscRegisterContext.SmiStatusReg = FCH_SMI_REG88; MiscRegisterContext.SmiStatusBit = BIT22; MiscRegisterContext.Order = 0x80; Status = AmdFchSmmMiscDispatch->Register ( AmdFchSmmMiscDispatch, AmdMiscFchWheaHwSmiCallback, &MiscRegisterContext, &MiscHandle ); MiscRegisterContext.SmiStatusReg = FCH_SMI_REG88; MiscRegisterContext.SmiStatusBit = BIT23; MiscRegisterContext.Order = 0x80; Status = AmdFchSmmMiscDispatch->Register ( AmdFchSmmMiscDispatch, AmdMiscFchWheaHwSmiCallback, &MiscRegisterContext, &MiscHandle ); MiscRegisterContext.SmiStatusReg = FCH_SMI_REG88; MiscRegisterContext.SmiStatusBit = BIT24; MiscRegisterContext.Order = 0x80; Status = AmdFchSmmMiscDispatch->Register ( AmdFchSmmMiscDispatch, AmdMiscFchWheaHwSmiCallback, &MiscRegisterContext, &MiscHandle ); ACPIMMIO32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB4) &= ~(BIT11 + BIT13 + BIT15 + BIT17); ACPIMMIO32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB4) |= (BIT10 + BIT12 + BIT14 + BIT16); } return Status; }
EFI_STATUS EFIAPI PlatOverMngrInit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: The driver Entry Point. The funciton will export a disk device class formset and its callback function to hii database Arguments: ImageHandle - EFI_HANDLE SystemTable - EFI_SYSTEM_TABLE Returns: EFI_STATUS --*/ { EFI_STATUS Status; EFI_HII_PROTOCOL *Hii; EFI_HII_PACKAGES *PackageList; EFI_HII_HANDLE HiiHandle; EFI_HII_UPDATE_DATA *UpdateData; EFI_CALLBACK_INFO *CallbackInfo; EFI_HANDLE Handle; UINTN Index; EFI_GUID PlatOverMngrGuid = PLAT_OVER_MNGR_GUID; // // Initialize the library and our protocol. // DxeInitializeDriverLib (ImageHandle, SystemTable); // // There should only be one HII protocol // Status = gBS->LocateProtocol ( &gEfiHiiProtocolGuid, NULL, &Hii ); if (EFI_ERROR (Status)) { return Status ; } CallbackInfo = EfiLibAllocateZeroPool (sizeof (EFI_CALLBACK_INFO)); if (CallbackInfo == NULL) { return EFI_BAD_BUFFER_SIZE; } CallbackInfo->Signature = EFI_CALLBACK_INFO_SIGNATURE; CallbackInfo->Hii = Hii; // // This driver implement a NV write worker function and a callback evaluator // CallbackInfo->DriverCallback.NvRead = NULL; CallbackInfo->DriverCallback.NvWrite = PlatOverMngrNvWrite; CallbackInfo->DriverCallback.Callback = PlatOverMngrCallback; // // Install protocol interface // Handle = NULL; Status = gBS->InstallProtocolInterface ( &Handle, &gEfiFormCallbackProtocolGuid, EFI_NATIVE_INTERFACE, &CallbackInfo->DriverCallback ); ASSERT_EFI_ERROR (Status); CallbackInfo->CallbackHandle = Handle; PackageList = PreparePackages (2, &PlatOverMngrGuid, VfrBin, PlatOverMngrStrings); Status = Hii->NewPack (Hii, PackageList, &HiiHandle); gBS->FreePool (PackageList); CallbackInfo->RegisteredHandle = HiiHandle; // // Allocate space for creation of Buffer // UpdateData = EfiLibAllocateZeroPool (0x1000); ASSERT (UpdateData != NULL); // // Flag update pending in FormSet // UpdateData->FormSetUpdate = TRUE; // // Register CallbackHandle data for FormSet // UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) CallbackInfo->CallbackHandle; UpdateData->FormUpdate = FALSE; UpdateData->FormTitle = 0; UpdateData->DataCount = 0; Hii->UpdateForm (Hii, HiiHandle, (EFI_FORM_LABEL) 0x0, TRUE, UpdateData); gBS->FreePool (UpdateData); mDriverImageHandleCount = 0; mCurrentPage = 0; // // Clear all the globle variable // for (Index = 0; Index < MAX_CHOICE_NUM; Index++) { mDriverImageToken[Index] = 0; mDriverImageFilePathToken[Index] = 0; mControllerToken[Index] = 0; mDriverImageProtocol[Index] = NULL; } return EFI_SUCCESS; }
EFI_STATUS EFIAPI CpuIoInitialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Initialize the state information for the CPU I/O Protocol Arguments: ImageHandle of the loaded driver Pointer to the System Table Returns: Status EFI_SUCCESS - Protocol successfully installed EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure --*/ // TODO: SystemTable - add argument and description to function comment { EFI_STATUS Status; UINTN NumHandles; EFI_HANDLE *HandleBuffer; UINTN Index; EFI_CPU_IO_PROTOCOL *OldCpuIoProtocol; // // Initialize the library // DxeInitializeDriverLib (ImageHandle, SystemTable); mCpuIoProtocol.Mem.Read = CpuMemoryServiceRead; mCpuIoProtocol.Mem.Write = CpuMemoryServiceWrite; mCpuIoProtocol.Io.Read = CpuIoServiceRead; mCpuIoProtocol.Io.Write = CpuIoServiceWrite; Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiCpuIoProtocolGuid, NULL, &NumHandles, &HandleBuffer ); if (Status == EFI_SUCCESS) { for (Index = 0; Index < NumHandles; Index++) { Status = gBS->HandleProtocol ( HandleBuffer[Index], &gEfiCpuIoProtocolGuid, (VOID **) &OldCpuIoProtocol ); if (Status == EFI_SUCCESS) { gBS->ReinstallProtocolInterface ( HandleBuffer[Index], &gEfiCpuIoProtocolGuid, OldCpuIoProtocol, &mCpuIoProtocol ); } } } ASSERT_EFI_ERROR (Status); return Status; }