VOID EFIAPI PlatformInitializeUart0MuxGalileo ( VOID ) /*++ Routine Description: This is the routine to initialize UART0 for DBG2 support. The hardware used in this process is a Legacy Bridge (Legacy GPIO), I2C controller, a bi-directional MUX and a Cypress CY8C9540A chip. Arguments: None. Returns: None. --*/ { EFI_STATUS Status; EFI_I2C_DEVICE_ADDRESS I2CSlaveAddress; UINTN Length; UINT8 Buffer[2]; if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) { I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR; } else { I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR; } // // Set GPIO_SUS<2> as an output, raise voltage to Vdd. // PlatformLegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, 2, TRUE); // // Select Port 3 // Length = 2; Buffer[0] = 0x18; //sub-address Buffer[1] = 0x03; //data Status = mI2cBus->WriteMultipleByte ( mI2cBus, I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); // // Set "Pin Direction" bit4 and bit5 as outputs // Length = 2; Buffer[0] = 0x1C; //sub-address Buffer[1] = 0xCF; //data Status = mI2cBus->WriteMultipleByte ( mI2cBus, I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); // // Lower GPORT3 bit4 and bit5 to Vss // Length = 2; Buffer[0] = 0x0B; //sub-address Buffer[1] = 0xCF; //data Status = mI2cBus->WriteMultipleByte ( mI2cBus, I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); }
/** Initialize state of I2C GPIO expanders. **/ EFI_STATUS EarlyPlatformConfigGpioExpanders ( VOID ) { EFI_STATUS Status; EFI_I2C_DEVICE_ADDRESS I2CSlaveAddress; UINTN Length; UINTN ReadLength; UINT8 Buffer[2]; // // Configure GPIO expanders for Galileo // Set all GPIO expander pins connected to the Reset Button as inputs // Route I2C pins to Arduino header // // // Detect the I2C Slave Address of the GPIO Expander // if (PlatformLegacyGpioGetLevel(R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) { I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR; } else { I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR; } DEBUG((EFI_D_INFO, "Galileo GPIO Expender Slave Address = %02x\n", I2CSlaveAddress.I2CDeviceAddress)); // // Set I2C_MUX (GPORT1_BIT5) low to route I2C to Arduino Shield connector // // // Select GPIO Expander GPORT1 // Length = 2; Buffer[0] = 0x18; //sub-address Buffer[1] = 0x01; //data Status = I2cWriteMultipleByte( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); if (EFI_ERROR(Status)) { DEBUG((EFI_D_WARN, "Fail to select GPIO Expander\n")); return EFI_SUCCESS; } // // Read "Pin Direction" of GPIO Expander GPORT1 // Length = 1; ReadLength = 1; Buffer[1] = 0x1C; Status = I2cReadMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &ReadLength, &Buffer[1] ); ASSERT_EFI_ERROR (Status); // // Configure GPIO Expander GPORT1_BIT5 as an output // Length = 2; Buffer[0] = 0x1C; //sub-address Buffer[1] = (UINT8)(Buffer[1] & (~BIT5)); //data Status = I2cWriteMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); // // Set GPIO Expander GPORT1_BIT5 low // Length = 2; Buffer[0] = 0x09; //sub-address Buffer[1] = (UINT8)(~BIT5); //data Status = I2cWriteMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); // // Configure RESET_N_SHLD (GPORT5_BIT0) and SW_RESET_N_SHLD (GPORT5_BIT1) as inputs // // // Select GPIO Expander GPORT5 // Length = 2; Buffer[0] = 0x18; Buffer[1] = 0x05; Status = I2cWriteMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); // // Read "Pin Direction" of GPIO Expander GPORT5 // Length = 1; ReadLength = 1; Buffer[1] = 0x1C; Status = I2cReadMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &ReadLength, &Buffer[1] ); ASSERT_EFI_ERROR (Status); // // Configure GPIO Expander GPORT5_BIT0 and GPORT5_BIT1 as inputs // Length = 2; Buffer[0] = 0x1C; Buffer[1] = Buffer[1] | BIT0 | BIT1; Status = I2cWriteMultipleByte ( I2CSlaveAddress, EfiI2CSevenBitAddrMode, &Length, &Buffer ); ASSERT_EFI_ERROR (Status); return EFI_SUCCESS; }
EFI_STATUS AcpiPlatformEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_ACPI_TABLE_PROTOCOL *AcpiTable; EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; INTN Instance; EFI_ACPI_COMMON_HEADER *CurrentTable; UINTN TableHandle; UINT32 FvStatus; UINTN Size; EFI_ACPI_TABLE_VERSION Version; EFI_HANDLE Handle; UINTN Index; PCI_DEVICE_INFO *PciDeviceInfo; EFI_ACPI_HANDLE PciRootHandle; BOOLEAN UpdatePRT; BOOLEAN UpdatePRW; PCI_DEVICE_SETTING *mConfigData; DEBUG((DEBUG_INFO, "ACPI Platform start...\n")); Instance = 0; TableHandle = 0; CurrentTable = NULL; mConfigData = NULL; // // Initialize the EFI Driver Library // ASSERT (sizeof (EFI_GLOBAL_NVS_AREA) == 512); Status = gBS->AllocatePool ( EfiACPIMemoryNVS, sizeof (EFI_GLOBAL_NVS_AREA), (VOID**)&mGlobalNvsArea.Area ); Handle = NULL; Status = gBS->InstallProtocolInterface ( &Handle, &gEfiGlobalNvsAreaProtocolGuid, EFI_NATIVE_INTERFACE, &mGlobalNvsArea ); ASSERT_EFI_ERROR (Status); if (!EFI_ERROR (Status)) { SetMem ( mGlobalNvsArea.Area, sizeof (EFI_GLOBAL_NVS_AREA), 0 ); } // // Initialize the data. Eventually, this will be controlled by setup options. // mGlobalNvsArea.Area->HpetEnable = PcdGetBool (PcdHpetEnable); mGlobalNvsArea.Area->Pm1blkIoBaseAddress = PcdGet16(PcdPm1blkIoBaseAddress); mGlobalNvsArea.Area->PmbaIoBaseAddress = PcdGet16(PcdPmbaIoBaseAddress); mGlobalNvsArea.Area->Gpe0blkIoBaseAddress = PcdGet16(PcdGpe0blkIoBaseAddress); mGlobalNvsArea.Area->GbaIoBaseAddress = PcdGet16(PcdGbaIoBaseAddress); mGlobalNvsArea.Area->SmbaIoBaseAddress = PcdGet16(PcdSmbaIoBaseAddress); mGlobalNvsArea.Area->WdtbaIoBaseAddress = PcdGet16(PcdWdtbaIoBaseAddress); mGlobalNvsArea.Area->HpetBaseAddress = (UINT32)PcdGet64(PcdHpetBaseAddress); mGlobalNvsArea.Area->HpetSize = (UINT32)PcdGet64(PcdHpetSize); mGlobalNvsArea.Area->PciExpressBaseAddress= (UINT32)PcdGet64(PcdPciExpressBaseAddress); mGlobalNvsArea.Area->PciExpressSize = (UINT32)PcdGet64(PcdPciExpressSize); mGlobalNvsArea.Area->RcbaMmioBaseAddress = (UINT32)PcdGet64(PcdRcbaMmioBaseAddress); mGlobalNvsArea.Area->RcbaMmioSize = (UINT32)PcdGet64(PcdRcbaMmioSize); mGlobalNvsArea.Area->IoApicBaseAddress = (UINT32)PcdGet64(PcdIoApicBaseAddress); mGlobalNvsArea.Area->IoApicSize = (UINT32)PcdGet64(PcdIoApicSize); mGlobalNvsArea.Area->TpmPresent = (UINT32)(FALSE); mGlobalNvsArea.Area->DBG2Present = (UINT32)(FALSE); mGlobalNvsArea.Area->PlatformType = (UINT32)PcdGet16 (PcdPlatformType); // // Configure platform IO expander I2C Slave Address. // if (mGlobalNvsArea.Area->PlatformType == Galileo) { if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) { mGlobalNvsArea.Area->AlternateSla = FALSE; } else { mGlobalNvsArea.Area->AlternateSla = TRUE; } } // // Find the AcpiTable protocol // Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID**)&AcpiTable); if (EFI_ERROR (Status)) { return EFI_ABORTED; } // // Initialize MADT table // Status = MadtTableInitialize (&CurrentTable, &Size); ASSERT_EFI_ERROR (Status); // // Perform any table specific updates. // AcpiUpdateTable ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable, &Version); // // Update the check sum // It needs to be zeroed before the checksum calculation // ((EFI_ACPI_SDT_HEADER *)CurrentTable)->Checksum = 0; ((EFI_ACPI_SDT_HEADER *)CurrentTable)->Checksum = CalculateCheckSum8 ((VOID *)CurrentTable, CurrentTable->Length); // // Add the table // TableHandle = 0; Status = AcpiTable->InstallAcpiTable ( AcpiTable, CurrentTable, CurrentTable->Length, &TableHandle ); ASSERT_EFI_ERROR (Status); CurrentTable = NULL; // // Init Pci Device PRT PRW information structure from PCD // mConfigData = (PCI_DEVICE_SETTING *)AllocateZeroPool (sizeof (PCI_DEVICE_SETTING)); ASSERT (mConfigData != NULL); InitPciDeviceInfoStructure (mConfigData); // // Get the Acpi SDT protocol for manipulation on acpi table // Status = gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **)&mAcpiSdt); ASSERT_EFI_ERROR (Status); // // Locate the firmware volume protocol // Status = LocateSupportProtocol (&gEfiFirmwareVolume2ProtocolGuid, (VOID**)&FwVol, 1); if (EFI_ERROR (Status)) { return EFI_ABORTED; } // // Read tables from the storage file. // while (Status == EFI_SUCCESS) { Status = FwVol->ReadSection ( FwVol, (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), EFI_SECTION_RAW, Instance, (VOID**)&CurrentTable, &Size, &FvStatus ); if (!EFI_ERROR(Status)) { // // Perform any table specific updates. // AcpiUpdateTable ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable, &Version); // // Update the check sum // It needs to be zeroed before the checksum calculation // ((EFI_ACPI_SDT_HEADER *)CurrentTable)->Checksum = 0; ((EFI_ACPI_SDT_HEADER *)CurrentTable)->Checksum = CalculateCheckSum8 ((VOID *)CurrentTable, CurrentTable->Length); // // Add the table // TableHandle = 0; Status = AcpiTable->InstallAcpiTable ( AcpiTable, CurrentTable, ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length, &TableHandle ); if (EFI_ERROR(Status)) { return EFI_ABORTED; } // // If this table is the DSDT table, then update the _PRT and _PRW based on // the settings from pcds // if (CurrentTable->Signature == EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) { // // Create the root handle for DSDT table // Status = mAcpiSdt->OpenSdt (TableHandle, &mDsdtHandle); ASSERT_EFI_ERROR (Status); PciRootHandle = NULL; PciRootHandle = SdtGetRootBridgeHandle (mAcpiSdt, mDsdtHandle); ASSERT (PciRootHandle != NULL); PciDeviceInfo = NULL; for (Index = 0; Index < mConfigData->PciDeviceInfoNumber; Index++) { PciDeviceInfo = &(mConfigData->PciDeviceInfo[Index]); // // Check whether this is a valid item // if ((PciDeviceInfo->BridgeAddress != 0xFFFFFFFF) && (PciDeviceInfo->DeviceAddress != 0xFFFFFFFF)) { //DEBUG ((EFI_D_ERROR, "Valid pci info structure: bridge address:0x%x, device address:0x%x\n", PciDeviceInfo->BridgeAddress, PciDeviceInfo->DeviceAddress)); UpdatePRT = FALSE; UpdatePRW = FALSE; SdtCheckPciDeviceInfoChanged (PciDeviceInfo, &UpdatePRT, &UpdatePRW); // // Check whether there is any valid pci routing item // if (UpdatePRT) { // // Update the pci routing information // //DEBUG ((EFI_D_ERROR, "Update _PRT\n")); SdtUpdatePciRouting (mAcpiSdt, PciRootHandle, PciDeviceInfo); } // // Check whether there is any valid pci routing item // if (UpdatePRW) { // // Update the pci wakeup information // //DEBUG ((EFI_D_ERROR, "Update _PRW\n")); SdtUpdatePowerWake (mAcpiSdt, PciRootHandle, PciDeviceInfo); } } } Status = mAcpiSdt->Close (PciRootHandle); ASSERT_EFI_ERROR (Status); // // Mark the root handle as modified , let SDT protocol recaculate the checksum // ((EFI_AML_HANDLE *)mDsdtHandle)->Modified = TRUE; Status = mAcpiSdt->Close (mDsdtHandle); ASSERT_EFI_ERROR (Status); } // // Increment the instance // Instance++; CurrentTable = NULL; } } gBS->FreePool (mConfigData); return EFI_SUCCESS; }