#There are some UEFI BIOS code snippet
Last active
July 13, 2016 02:45
-
-
Save allenyllee/292a75264a03d6a8ede55867446ed710 to your computer and use it in GitHub Desktop.
There are some UEFI BIOS code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------------------------------------------- | |
// Read EC RAM | |
// Arg0 = RAM location address (two bytes) | |
//----------------------------------------------------------- | |
Method(RRAM,1,Serialized) { | |
If (LEqual(Acquire(MUEC,0xFFFF),0)) { // if not time-out | |
Store(Arg0, Local0) | |
And(Local0, 0xFF, Local1) | |
ShiftRight(Local0, 8, Local0) | |
And(Local0, 0xFF, Local0) | |
Store(Local1, CDT2) // Address low byte | |
Store(Local0, CDT1) // Address high byte | |
Store(0x80, CMD1) | |
Store(0x0F, ESEM) | |
Store(0x7F, Local0) | |
While(LAnd(Local0, CMD1)) { | |
Sleep(1) | |
Decrement(Local0) | |
} | |
If(LEqual(CMD1, Zero)) { | |
Store(EDA1, Local0) | |
} | |
Else { | |
Store(Ones, Local0) | |
} | |
Release(MUEC) | |
Return(Local0) | |
} | |
Return(Ones) | |
} | |
//----------------------------------------------------------- | |
// Write EC RAM | |
// Arg0 = RAM location address | |
// Arg1 = Data | |
//----------------------------------------------------------- | |
Method(WRAM,2,Serialized) { | |
If (LEqual(Acquire(MUEC,0xFFFF),0)) { // if not time-out | |
Store(Arg0, Local0) | |
And(Local0, 0xFF, Local1) | |
ShiftRight(Local0, 8, Local0) | |
And(Local0, 0xFF, Local0) | |
Store(Local1, CDT2) // Address low byte | |
Store(Local0, CDT1) // Address high byte | |
Store(Arg1, CDT3) | |
Store(0x81, CMD1) | |
Store(0x0F, ESEM) | |
Store(0x7F, Local0) | |
While(LAnd(Local0, CMD1)) { | |
Sleep(1) | |
Decrement(Local0) | |
} | |
If(LEqual(CMD1, Zero)) { | |
Store(One, Local0) | |
} | |
Else { | |
Store(Ones, Local0) | |
} | |
Release(MUEC) | |
Return(Local0) | |
} | |
Return(Ones) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Flag of PeakShift (PKFG) | |
// Bit15~8 : reserved (must be 0) | |
// Bit7 : AC Adapter connect status | |
// 1 = connected | |
// 0 = disconnected | |
// Bit6~3 : reserved | |
// Bit2 : battery charge during S3/S4/S5 | |
// 1 = Not Charge Mode | |
// 0 = Charge Mode | |
// Bit1 : battery charge during S0 | |
// 1 = Not Charge Mode | |
// 0 = Charge Mode | |
// Bit0 : forced battery operation | |
// 1 = Enable | |
// 0 = Disable | |
Name(PKFG, 0x0000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <PegaCommonHeaders.h> | |
#define ACPI_TIMER_ADDRESS (PM_BASE_ADDR+0x08) | |
#define BITS_IN_ACPI_TIMER 24 // The current bits in ACPI Timer - Porting need | |
VOID SB_ACPIDelay(UINTN MicroSeconds) | |
{ | |
UINTN TicksNeeded; | |
UINT32 TimerValue, NewTimerValue; | |
UINTN OverFlow; | |
UINTN TheRest, EndValue; | |
// The num of ticks of ACPI Timer in 1us is 3.258 | |
TicksNeeded = MicroSeconds*3; | |
TicksNeeded += (MicroSeconds) / 2; | |
TicksNeeded += (MicroSeconds*2) / 25; | |
TheRest = TicksNeeded; | |
OverFlow = TicksNeeded / (1 << BITS_IN_ACPI_TIMER); | |
TheRest = TicksNeeded % (1 << BITS_IN_ACPI_TIMER); | |
// read ACPI Timer | |
TimerValue = PegaIoRead32(ACPI_TIMER_ADDRESS); | |
TimerValue = TimerValue % (1 << BITS_IN_ACPI_TIMER); // mask invalid bits | |
// need to adjust the values based off of the start time | |
EndValue = TheRest + TimerValue; | |
// check for overflow on addition. possibly a problem | |
if (EndValue < TimerValue) | |
OverFlow++; | |
else{ | |
// here make sure that EndValue is less than the max value of the counter | |
OverFlow += EndValue / (1 << BITS_IN_ACPI_TIMER); | |
EndValue = EndValue % (1 << BITS_IN_ACPI_TIMER); | |
} | |
// let the timer wrap around as many times as calculated | |
while (OverFlow) { | |
// read timer and see if the new value read is less than | |
// the current timer value. if this happens the timer overflowed | |
NewTimerValue = PegaIoRead32(ACPI_TIMER_ADDRESS); | |
NewTimerValue = NewTimerValue % (1 << BITS_IN_ACPI_TIMER); // mask invalid bits | |
if (NewTimerValue < TimerValue) | |
OverFlow--; | |
TimerValue = NewTimerValue; | |
} | |
// now wait for the correct number of ticks that need to occur after | |
// all the needed overflows | |
while (EndValue > TimerValue) { | |
NewTimerValue = PegaIoRead32(ACPI_TIMER_ADDRESS); | |
// Check to see if the timer overflowed. If it did then | |
// the time has elapsed. Because EndValue should be greater than TimerValue | |
if (NewTimerValue < TimerValue) | |
break; | |
TimerValue = NewTimerValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Set GPIO Pin Level | |
//Arg0: First Pin Number | |
//Arg1: Total Consecutive Pins to Be Set | |
//Arg2: Value | |
Method(SGPL,3,Serialized) { | |
Store(Arg0, Local0) | |
Store(Arg1, Local1) | |
Store(Arg2, Local3) | |
Store(Zero, Local4) | |
While(Local1) { | |
Store(ShiftLeft(1,Local4),Local2) | |
If(And(Local2,Local3)){ | |
SGLV(Local0,1) | |
}Else{ | |
SGLV(Local0,0) | |
} | |
Increment(Local0) | |
Decrement(Local1) | |
Increment(Local4) | |
} | |
} | |
//Read GPIO Pin Level | |
//Arg0: First Pin Number | |
//Arg1: Total Consecutive Pins to Be Read | |
Method(RGPL,2,Serialized) { | |
Store(Arg0, Local0) | |
Store(Arg1, Local1) | |
Store(Zero, Local3) | |
Store(Zero, Local4) | |
While(Local1) { | |
If(RGLV(Local0)){ | |
Or(ShiftLeft(1,Local4),Local3,Local3) | |
} | |
Increment(Local0) | |
Decrement(Local1) | |
Increment(Local4) | |
} | |
Return(Local3) | |
} | |
//Get GPIO Level | |
//Arg0: Pin Number | |
Method(RGLV,1,Serialized) { | |
Add(Multiply(Arg0, 8), FixedPcdGet16(PcdPchGpioBaseAddress), Local0) | |
Add(Local0, 0x100, Local0) | |
OperationRegion(GLVX, SystemIO, Local0, 0x32) | |
Field(GLVX, ByteAcc, Lock, Preserve) { | |
GPXX, 32, | |
} | |
If(And(GPXX,0x40000000)){ | |
Return (1) | |
}else{ | |
Return (0) | |
} | |
} | |
//Set GPIO Level | |
//Arg0: Pin Number | |
//Arg1: Value | |
Method(SGLV,2,Serialized) { | |
Add(Multiply(Arg0, 8), FixedPcdGet16(PcdPchGpioBaseAddress), Local0) | |
Add(Local0, 0x100, Local0) | |
OperationRegion(GLVX, SystemIO, Local0, 0x32) | |
Field(GLVX, ByteAcc, Lock, Preserve) { | |
GPXX, 32, | |
} | |
If(Arg1){ | |
Or(GPXX,0x80000000,GPXX) // Bit31: GPIO_OUT | |
}Else{ | |
And(GPXX,0x7FFFFFFF,GPXX) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment