Search This Blog

Wednesday, June 29, 2011

Library Compiler Error - don't know how to make

遇到 don't know how to make LibraryX.lib 的情況,可以用以下的方式排除
1. 確定LibraryX.lib 在 AAA.dsc裡面有去定義這個AAA.inf
2. 若在build這個AAA.inf的library的時候就遇到compiler error,請先解決這個compiler error (可能是LibraryX建的方式有問題,可以參照其他現成的library做法)
3. 若你在BBB的檔案要引用這個LibraryX的時候,請先確定在build出來的temp目錄層底下,有長出LibraryX.lib的檔案。
4. 若有,請在BBB.inf裡確定以下兩點
[includes.common]
  $(EFI_SOURCE)\(Library_ROOT)  //要指定路徑在library那一層
[libraries.common]
  LibraryX
5.記住呼叫的Libray名字不要打錯,不然就會造成complier "don't know how to make" 的error

Monday, June 27, 2011

SATA及USB介面傳輸速度比較表

SATA版本
頻寬
速度       傳輸一部6G高清電影
SATA 3.0
6Gb/s
600MB            10 (理想值)
SATA 2.0
3Gb/s
300MB            20 (理想值)
SATA 1.0
1.5Gb/s
150MB            40 (理想值)



USB版本
頻寬
速度       傳輸一部6G高清電影
USB 3.0
5 Gb/s
500MB            12 (理想值)
USB 2.0
480Mb/s
48MB              125 (理想值)
USB 1.1
120Mb/s
1.2MB             5000 (理想值)
 USB 1.0           1.5Mb/s        150KB              40000 (理想值)

Wednesday, June 22, 2011

How to make an EFI library?

1. 在inf檔裡修改
[defines]
  BASE_NAME       =  HelloLib
  COMPONENT_TYPE  =  LIBRARY

[sources.common]
  Hello\Hello.c
  Hello\Hello.h


2. 把你需要的library function加到hello.c及hello.h裡

3.在EFI driver去引用HelloLib的時候要去修改以下的檔案
   AbcDriver.inf
   AbcDriver.c


4.AbcDriver.c要加入
   #include "Hello.h"

   用extern的方式加入library的function名字
   並在你的function去呼叫你要用的library function即可

5.AbcDriver.inf要加入
[includes.common]
  $(EFI_SOURCE)\Library\Hello  <== 指到放Hello.h的那一層目錄

[libraries.common] 
   HelloLib

Monday, May 30, 2011

INT 15h E820 Query Memory Map Use Debug32.exe

;Input:
;       eax   - function code 0E820H
;       ebx   - continuation code, zero for first call
;       es:di - buffer pointer , point to an buffer for BIOS to fill in.
;       ecx   - buffer size , minimum is 20 bytes
;       edx   - signature 'SMAP'

C:\debug32
-r32
-a
  mov eax, 0000e820
  mov ebx, 0
  mov ecx, 14
  mov edx, 534d4150
  mov di, 200
  int 15
  int 3
  p
-go


;Output:
;       CF    - non-carry indicates no error
;       eax   - signature return 'SMAP'
;       es:di - buffer pointer, same as input
;       ecx   - real buffer size return
;       ebx   - continuation code , zero return if last run occured

Thursday, May 26, 2011

ACPI can't recogize OS type with Ubuntu operating system

ACPI can't recogize OS type with Ubuntu operating system

Remove "Linux" from supported _OSI strings.
The Linux OS no longer wants to respond true for this string.
The only safe strings are windows-related as they represent the tested path through the BIOS-provided ASL.
===========================================================================

現在Ubuntu不支援用_OSI strings的方式來回報OS類型

Monday, May 23, 2011

A20 Gate

1.   8086的系統,當初只設計20根位址線。透過Segment + Offset的方式來定址,Ex. F000 : 0010h = F0000+ 0010h = F0010h  那衍生了一個問題就是當CS : IP的值為FFFF : FFFFh = FFFF0 + FFFFh = 10FFEFh = 1M + 64K – 16 Bytes  但系統只能存取到1M以下,這該如何是好? 所以大於1M,系統會直接回繞。

2.   80286的系統,位址線變成了24根,但又要向下相容,就衍生了A20的模式,當A20disable,就等同於8086的架構,A20 Enable,系統就可以存取到2 ^ 24次方 = 16M byte,也就是Segment變成最大值為FFFFFh 而不是FFFFh

3.   開啟A20 Gate的方法,最簡單就是對IO Port 92h 的bit 1給設起來;反之關閉A20 Gate的方法,就是清掉IO Port 92h 的bit 1。

enable_A20:
        cli

        call    a20wait
        mov     al,0xAD  ; Disable Keyboard
        out     0x64,al

        call    a20wait
        mov     al,0xD0
        out     0x64,al

        call    a20wait2
        in      al,0x60
        push    eax

        call    a20wait
        mov     al,0xD1
        out     0x64,al

        call    a20wait
        pop     eax
        or      al,2
        out     0x60,al

        call    a20wait
        mov     al,0xAE   ; Enable Keyboard
        out     0x64,al

        call    a20wait
        sti
        ret

a20wait:
        in      al,0x64
        test    al,2
        jnz     a20wait
        ret


a20wait2:
        in      al,0x64
        test    al,1
        jz      a20wait2
        ret

Wednesday, May 18, 2011

8259 Control Word


RTC Lost Power

After remove RTC coin battery, system plug-in RTC coin battery the CMOS  register 0xE access by (index port 0x70/ data port 0x71) bit 7 will be set. After check this bit, we also need to clear this bit by code.















============================================================================

在移除RTC水銀電池後,然後再次插上,這時後CMOS register offset 0xE的位址,在(使用index port 0x70/ data port 0x71)方式存取,這時候的0xE的bit 7會被設起來,在code裡面,一檢查完,就需要清掉這個位元。

Tuesday, May 17, 2011

About IO Decode (AMD Chipset)

1.Set IO base address in south bridge register
2.Enable Alternative Wide IO Range in south bridge register
3.Enable Wide IO Port in south bridge register
if system still can't open IO decode, we need to check  is occupied by another device using the same IO resource or not. We can check the value in each of PCI bridge offset 0x1C.PCI bridger IO resource is aligned to a 4KB boundary.

============================================================================

1.設定要做IO decode去設定南橋暫存器的IO Base Adress
2.開啟南橋暫存器的Alternative Wide IO Range
3.開啟南橋暫存器的Wide IO Port
若還是無法開啟IO decode,這時候就要檢查是否有別的device佔用到相同的IO decode的位址,可以先檢查每個PCI bridge的offset 0x1C的值,PCI bridge一次就是佔4K的IO resource。

Monday, May 16, 2011

The Different Between LegacyBiosInt86 And LegacyBiosFarCall86

When we wanna issue a software interrupt, we need to call LegacyBiosInt86 thunk function call.
When we wanna jump to OPROM or other legacy address, we need to call LegacyBiosFarCall86 thunk function call.

========================================================================

LegacyBiosInt86是我們需要使用程式去呼叫INT時所使用到的thunk function ,像是CALL INT10...
LegacyBiosFarCall86是我們需要跳到option ROM address所需要用到的thunk function

Tuesday, May 10, 2011

Bring Up BIOS

1. Modify GPIO that depends on platform design
2. Modify FDLA (Firmware Device Linear Address)
3. Change VBIOS
4. Change SPI ROM size
5. Disable KSC

===========================================================================

做一個Bring-up BIOS主要的工作如下:
1. 依照platform的layout去修改GPIO
2. 修改FDLA (Firmware Device Linear Address)
3. 換掉VBIOS
4. 依照platform的設計改變SPI ROM大小
5. 移除KSC

Friday, May 6, 2011

Software SMI Behavior

ACPI Enable and Disable Behavior

ACPI Enable
OSPM performs this transition by writing the ACPI_ENABLE value to the SMI_CMD, which generates an event to the hardware to transition the platform into ACPI mode. When hardware has finished the transition, it sets the SCI_EN bit and returns control back to OSPM.

ACPI Disable
While in the G0 “working state,” OSPM can request a transition to Legacy mode by writing the ACPI_DISABLE value to the SMI_CMD register, which results in the hardware going into legacy mode and resetting the SCI_EN bit LOW.

=======================================================================

ACPI Enable
由OS去寫ACPI_ENABLE的值到SMI_CMD port,會由BIOS所註冊的ACPI Enable的SMI handler去處理將SCI_EN bit設起來,在這handler裡,OEM可以自行加入程式碼以達到一些特殊的需求,再將控制權交還給BIOS。

ACPI Disable
在ACPI_ENABLE下,也可由OS去寫ACPI_DISABLE的值到SMI_CMD port,會由BIOS所註冊的ACPI Disable的SMI handler去處理將SCI_EN bit清為零。

Can't Access PCIe Network IO Resource at early POST

Question:
Can't access PCIe network IO resource at early POST issue.

Solution:
The PCI command register set to 0x07 and assign IO resource forPCIe network device. It also needs to set the PCI command register set to 0x07 on PCIe bridge.

=======================================================================

問題:
最近有遇到一個要存取掛在PCIe Bridge底下的PCIe網卡設定問題,狀況是無法在early POST時存取到PCIe網卡底下的IO resource。

解決方案:
PCIe網卡的PCI command register設成0x07以及指派IO resource外,注意也需要把PCIe Bridge的PCI command register設成0x07。

Set Watch Dog Timer for AMD chipset

WatchDogTimerConfig - RW - 8 bits [PM_Reg:4Ch]
WatchDogDisable         bit 0    -  0 / 1 Enable/Disable WatchDog function
WatchDogFreq             bit 2:1    00 / 11  32KHz/1Hz

WatchDogTimerEn - RW - 32 bits [PM_Reg:48h]
WatchDogDecodeEn    bit 0 - 1 to enable decoding of WatchDogTimer address
WatchDogBase             bit 31:3 - WatchDogTimer base address

WatchDogControl - RW - 32 bits - [WD_Mem_Reg:00h]
WatchDogRunStopB      bit 0 - 0/1 Watchdog is in the Stopped/Running state
WatchDogAction            bit 2 - 0/1 System reset/power off
WatchDogDisable           bit 3 - 0/1 Enable/Disable
WatchDogTrigger (WO) bit 7 - write one to trigger the watchdog

WatchDogCount - RW - 32 bits - [WD_Mem_Reg:04h]
WatchDogCount            bit 15:0 - Set Count

1. Set the WatchDogDisable to enable and WatchDogFreq in WatchDogTimerConfig register.
2. Get the WatchDogBase address
3. Set the WatchDogCount
4. Set the WatchDogRunStopB  to run
5. Trigger the WatchDogTrigger

=========================================================================

1. 設定WatchDogTimerConfig的WatchDogDisable位元及設定WatchDogFreq的頻率.
2. 讀取WatchDogBase的位址
3. 設定WatchDogCount去決定最大計數個數
4. 設定WatchDogRunStopB成執行模式
5. 設定WatchDogTrigger位元去啟動Watch Dog Timer

Thursday, April 28, 2011

Disable XHCI pme when enter sleep mode on AMD chipset

We can use the SciSleepDisable (SMI_REG : 20h) register to disable sleep SCI.
If XHCI pme use L Event 24, it should be set the SciSleepDisable bit 24 to 1.
The system enter sleep mode will not resume when L Event 24 be triggered.

======================================================================

最近遇到一個USB 3.0 port上接USB hub1.1後面再接Keyboard或Mouse進S3後會自動被喚醒的問題。為了解決這問題,當系統不支援USB喚醒的時候就去設定SciSleepDisable暫存器(SMI_REG : 20h)去禁止有任何event被觸發而讓系統自動喚醒。
當XHCI pme是使用L Event24時,就去設定SciSleepDisable的第24位元為1。
如此一來,當系統進入S3的時候,它就會自動擋掉來自於L Event 24的任何Evnet了。

Wednesday, April 20, 2011

Retrieve the index of the CPU to trigger SMI

We can know which CPU core (index) to trigger SMI as below.

EFI_STATUS
GetCpuCoreIndex (
  OUT UINTN *CpuIndex
  )
{
  UINT8 Index;
  EFI_STATUS Status;
  EFI_SMM_SAVE_STATE_IO_INFO *IoInfomation;
  Status = EFI_SUCCESS;
  Status = mSmst->SmmAllocatePool (EfiRuntimeServicesData,
                    sizeof (EFI_SMM_SAVE_STATE_IO_INFO),
                    (VOID **) &IoInfomation);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  //
  // Find the CPU that triggered the software SMI.
  //
  for (Index = 0; Index < mSmst->NumberOfCpus; Index++) {
    Status = mSmmCpuSaveState->ReadSaveState (
                                 mSmmCpuSaveState,
                                 sizeof (IoInfo),
                                 EFI_SMM_SAVE_STATE_REGISTER_IO,
                                 Index,
                                 IoInfomation);
    if (Status == EFI_SUCCESS &&
        (IoInfo->IoPort  == (UINT16) mSwSmiCommandPort) &&
        * (UINT8*) IoInfo->IoData == (UINT8) mSmbiosPnpSwSmiValue) {
      *CpuIndex = Index;
      break;
    }
  }
  mSmst->SmmFreePool (IoInfo);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if (i == mSmst->NumberOfCpus) {
    return EFI_NOT_FOUND;
  } else {
    return EFI_SUCCESS;
  }
} // GetCpuCoreIndex

Monday, April 18, 2011

SVID and SSID

What is the SVID and SSID?
SVID - Subsystem Vendor ID
SSID - Subsystem ID

Where is the SVID and SSID?
The SVID will be filled in PCI device register offset 0x2C to 0x2D (2 Bytes) by BIOS.
The SSID will be filled in PCI device register offset 0x2E to 0x2F (2 Bytes) by BIOS.

What can the SVID and SSID do?
The SVID and SSID can provide device driver to recongize in order to determine what driver function needs to be supported.

=========================================================================

什麼是SVID和SSID?
SVID - Subsystem Vendor ID
SSID - Subsystem ID

BIOS要在哪裡去填SVID和SSID?
BIOS應該在PCI裝置上的0x2C到0x2D (2 Bytes)去填SVID
BIOS應該在PCI裝置上的0x2E到0x2F (2 Bytes)去填SSID

SVID和SSID的功用?
SVID和SSID可以提供裝置的驅動程式去辦別什麼功能是需要被支援(使用)的,如此一來裝置製造商也可以為很多裝置提供共用的驅動程式。

Friday, April 15, 2011

Disable EC SMI (GPI) on AMD Chipset

How to disable EC SMI on AMD Chipset?
We can set the SMI registers to turn off EC SMI in FCH specification.
SMI registers are accessed by memory-mapped IO or IO-mapped, the range from "AcpiMMioAddr" + 0x200 to "AcpiMMioAddr" + 0x2FF offset 0x14 that register name is SmiSciEn. Every bit presents every GEvent. If Gevent 23 is EC SMI pin, we need to clear the value of SmiSciEn bit 23 that can disable EC SMI. When SmiSciStatus bit 23 is set and SmiSciEn bit 23 is set, it will trigger a SMI to call the BIOS to do SMI function.

=========================================================================

如何禁能AMD chipset的EC SMI?
透過設定FCH的SMI暫存器去關掉EC SMI。
SMI暫存器可以使用記憶體映對IO或IO映對的方式存取,其範圍從"AcpiMMioAddr" + 0x200 to "AcpiMMioAddr" + 0x2FF offset 0x14的SmiSciEn暫存器名稱,每一個位元都代表一個GEevent。
如果EC SMI腳位是使用GEvent 23,我們可以透過清掉SmiSciEn的位元23去禁能EC SMI。當SmiSciStatus bit23被設成1且SmiSciEn bit23被設定成1,將會觸發一個SMI去呼叫BIOS的SMI function。

Thursday, April 14, 2011

What is the BIOS?

What is the BIOS?
BIOS - Basic Input/Output System
When user pressed the power button, the main job of BIOS is let platform to enter operating system.

Where is the BIOS?
The BIOS is stored in flash ROM on the mother board. The ROM size is depended on BIOS binary size.

What is the legacy BIOS? What is the EFI BIOS?
The legacy BIOS is written by assembly code.
The EFI(Extensible Firmware Interface) BIOS is written by C code.
The legacy BIOS is replaced by EFI BIOS little by little.
The EFI BIOS is more easy to write for progarmmer.

How to boot to operating system by the EFI BIOS?
The EFI BIOS has four phases to boot to OS.
1. SEC phase: Check security and cache as RAM in order to build the PEI foundation to provide interface
2. PEI phase: CPU/chipset early initial and most important thing is memory sizing then enter DXE IPL.
3. DXE phase: Execute all the driver in order to let system has full function.
4. BDS phase: Connent all boot device and let system boot to be selected boot device.
System Power On -> SEC -> PEI -> DXE -> BDS -> OS

=======================================================================

何謂BIOS?
BIOS - 基本輸入輸出系統
當使用者按下電源鈕之後,讓系統能順利進到OS,並且達到客製化的需求,這就是BIOS的主要職責。

BIOS放在那裡?
BIOS被存放在主機板上的快閃記憶體內。快閃記憶體的容量大小是取決於BIOS的執行檔大小。
何謂legacy BIOS? 何謂EFI BIOS?
Lgacy BIOS的原始碼是使用組合語言來撰寫。
EFI(Extensible Firmware Interface) BIOS的原始碼是使用C語言來撰寫。
現今,legacy BIOS已漸漸地被EFI BIOS所取代。
EFI BIOS對於程式設計師來說,比較容易看懂,不需要碰到太多硬體底層的程式。

EFI BIOS是如何開機至作業系統的?
EFI BIOS需要經過四個階段的開機流程到作業系統。
1. SEC階段: 檢查系統安全性並將快取記憶體當作記憶體來使用以利建構PEI 環境並轉移至PEI 階段。
2. PEI 階段: CPU/chipset初始化及記憶體初始化讓系統進入到DXE IPL。
3. DXE階段: 執行所有driver為了讓系統能有完整的功能。
4. BDS階段: 連接所有可開機的裝置且讓系統開機到被選中的可開機裝置。
系統Power on -> SEC -> PEI -> DXE -> BDS -> 作業系統

Wednesday, April 13, 2011

AMD GPIO Setting Guide

Setting multi-function pin register in AMD FCH IoMux register(AcpiMMioAddr + 0xD00 ~ 0xDFF).
According to hardware setting to set what kind of function that BIOS should set to FCH IoMux register.

For example





    

    

     Function 0: CLK_REQ1#
     Function 1: FANOUT4
     Function 2: GPIO61
     That means IoMux<61> register should set to 0x00(CLK_REQ1#)

     If this pin isn't for GPIO use, we don't care the GPIO register setting.

According to hardware design some pins to GPI or GPO,
we should set GPIO<0 ~ 228> register to GPI or GPO, pull-up or pull down and sticky or not.

The GPIO registers also control the GEvent pins. The GEvent<X> pins,
where the X is in the range of 0 ~ 23, map to the offset range 60h ~ 77h (or 96 ~119 in decimal).


Between BIOS and EC

When system enter POST phase, the BIOS should send EC command to notify EC now is in POST.
Before system enter Windows, the BIOS should send EC command to notify EC now is in ACPI mode.

EC is in ACPI mode:
For example
In Windows --> Unplug AC Adaptor --> Trigger EC SCI Pin --> Notify OS Acpi Driver --> Do Q Event (AC unplug ASL code)

EC is not in ACPI mode:
For example
In DOS --> Unplug AC Adaptor --> Trigger EC SMI Pin --> Enter SMM Mode --> Do SMI Handler (AC unplug SMI code)




 








======================================================================

當系統在POST階段,BIOS需要送EC command告訴EC現在在POST階段。
在系統進入到Windows之前,BIOS需要送EC command告訴EC現在要進入ACPI mode, 去服務SCI。

EC在ACPI mode:
例如:
在Windows環境裡 --> 移除AC電源 --> 觸發EC SCI Pin --> 告訴OS Acpi 的驅動程式 --> 執行Q Event (AC unplug ASL code)

EC不在ACPI mode:
例如:
在DOS環境裡 --> --> 移除AC電源 --> 觸發EC SMI Pin --> 進入SMM Mode --> 執行SMI Handler (AC unplug SMI code)

Tuesday, April 12, 2011

Keyboard Buffer Concept and Tool

Location
Description
Size
40:1Ah
Keyboard, Head of Buffer Pointer
word
40:1Ch
Keyboard, End of Buffer Pointer
word
40:1Eh
Keyboard, Buffer
16 words

If the value of location 40:1Ah points to the same address as in location 40:1Ch, there are no keys in the buffer.

40:1Ah as a key is removed from the buffer, that pointer is incremented by 2, until the last word of the buffer is reached. At the point it is reset to the start of the keyboard buffer area.

40:1Ch as a key is added from the buffer, that pointer is incremented by 2, until the last word of the buffer is reached. At the point it is reset to the start of the keyboard buffer area.

40:1Eh is 16 words FIFO buffer holds up to 15 keys.
The scan code is in the upper byte of the word.
The ASCII conversion of the scan code is in the lower byte of the word.

In the BIOS code, the keyboard buffer should be cleared before end of INT19h.


Keyboard Buffer Tool (for DOS)














>> Click Here to Download <<

Monday, April 11, 2011

KBC Command

KBC Command
Function Description
0xAD
Disable keyboard interface
0xAE
Enable keyboard interface
0xED
Update keyboard LED status(Caps Lock/Scroll Lock/Num Lock)
0xAA
8042 controller self test
0xAB
Keyboard interface test

Thursday, April 7, 2011

ATI PowerXpress 4.0

ATI PX 4.0 supports two mode as below.

Dynamic Mode :
ATI driver will depend on loading to automatic to enhance performance.

Fixed Mode:
1.  High performance mode: Always turn on dGPU and iGPU to enhance performance.
2.  Power saving mode: turn off dGPU in order to saving more power.

Wednesday, April 6, 2011

ASL Code Method _BCL and _BCM

1. OS will get brightness level from _BCL

Method(_BCL, 0, NotSerialized)
{
    Return(Package(){100,    // AC Default Level 16
                                  33,    // DC Default Level 5
                                  13,    // Level 1
                                  18,    // Level 2
                                  23,    // Level 3
                                  28,    // Level 4
                                  33,    // Level 5
                                  38,    // Level 6
                                  43,    // Level 7
                                  48,    // Level 8
                                  54,    // Level 9
                                  60,    // Level 10
                                  66,    // Level 11
                                  72,    // Level 12
                                  78,    // Level 13
                                  84,    // Level 14
                                  90,    // Level 15
                                 100    // Level 16
                                })
}



2. OS will set brightness from _BCM

Method(_BCM, 1, NotSerialized)
{
    if (LEqual(\_SB.PCI0.VGA.AF7E, 0x80000001)) // Brightness control by driver
    {                                        
        // Using the equation (Arg0*3+19)/20 to convert the "0 to 100%" BCL levels
        // to "0 to 15" based.
        Divide(Add(Multiply(Arg0, 3), 19), 20, Local1, Local0)
        Store (DeRefOf(Index(BLVL, Local0)), Local3) // Get 0-255 range level from buffer
         \_SB.PCI0.AFN7(Local3)
    }
}


=======================================================================

1. OS會從ACPI的Method _BCL去得到需要所訂定的明亮度

Method(_BCL, 0, NotSerialized)
{
    Return(Package(){100,    // AC 預設 Level 16 (預設一插上AC電源就將明亮度調至100%)
                                  33,    // DC 預設  Level 5 (預設DC電源就將明亮度調至33%)
                                  13,    // Level 1
                                  18,    // Level 2
                                  23,    // Level 3
                                  28,    // Level 4
                                  33,    // Level 5
                                  38,    // Level 6
                                  43,    // Level 7
                                  48,    // Level 8
                                  54,    // Level 9
                                  60,    // Level 10
                                  66,    // Level 11
                                  72,    // Level 12
                                  78,    // Level 13
                                  84,    // Level 14
                                  90,    // Level 15
                                 100    // Level 16
                                })
}



2. OS從ACPI的Method_BCM去設定明亮度

Method(_BCM, 1, NotSerialized)
{
    if (LEqual(\_SB.PCI0.VGA.AF7E, 0x80000001)) // Brightness control by driver
    {                                        
        // Using the equation (Arg0*3+19)/20 轉換 "0 to 100%" BCL levels至 to "0 to 15" 階.
        Divide(Add(Multiply(Arg0, 3), 19), 20, Local1, Local0)
        Store (DeRefOf(Index(BLVL, Local0)), Local3) // 從buffer抓0-255的範圍
         \_SB.PCI0.AFN7(Local3)
    }
}

_BCL和_BCM僅使用在筆記型電腦,桌上型電腦不需支援

Monday, April 4, 2011

IRQ Resource Assign

IRQ Resource Assign @ PCI Register in 0x3C(Interrupt Line) and 0x3D(Interrupt Pin)















IRQ Routing (For Example)





$PIR is located in memory address from F0000h to FFFFFh.
This table is filled by system BIOS and OS will use this table to assign PCI IRQ resource.

Bit Translator Widget














>> Click here to download <<

[Interrupt Vector] INT 10h and INT 15h

The different bewteen INT10h and INT15h.



Thursday, March 17, 2011

How to Access Byte Data on SMBus (Simple)

#define SMBusStatus         0x00
#define SMBusSlaveStatus 0x01
#define SMBusControl       0x02
#define SMBusHostCmd    0x03
#define SMBusAddress      0x04
#define SMBusData0          0x05
#define DeviceAddress       0xA0  // It depends on H/W design.
#define RWDataByte          0x48
#define SMBusInterrupt      1 << 1
#define BIT0                      1

UINT8
SMBusReadByte (
  IN UINT8 RegisterIndex
)
{
  UINT8 Data8;
 
  do {
     IoWrite8 (SMBusBaseAddress + SMBusStatus, 0xFF);
     IoRead8 (SMBusBaseAddress + SMBusStatus, Data8);
  } while (Data8 != 0);                                                                  // Waiting for all status be cleared

  IoWrite8 (SMBusBaseAddress + SMBusAddress, (DeviceAddress << 1) | BIT0);  //Read
  IoWrite8 (SMBusBaseAddress + SMBusHostCmd, RegisterIndex);
  IoWrite8 (SMBusBaseAddress + SMBusControl, RWDataByte);
  do {
     IoRead8 (SMBusBaseAddress + SMBusStatus, Data8);
  } while (Data8 != SMBusInterrupt);                                                     // Check SMBus read ready
  IoRead8 (SMBusBaseAddress + SMBusData0, Data8);
  Return Data8;
}

VOID
SMBusWriteByte (
  IN UINT8 RegisterIndex,
  IN UINT8 WriteData
)
{
  UINT8 Data8;
 
  do {
     IoWrite8 (SMBusBaseAddress + SMBusStatus, 0xFF);
     IoRead8 (SMBusBaseAddress + SMBusStatus, Data8);
  } while (Data8 != 0);                                                                     // Waiting for all status be cleared

  IoWrite8 (SMBusBaseAddress + SMBusAddress, (DeviceAddress << 1));  // Write
  IoWrite8 (SMBusBaseAddress + SMBusData0, WriteData);
  IoWrite8 (SMBusBaseAddress + SMBusHostCmd, RegisterIndex);
  IoWrite8 (SMBusBaseAddress + SMBusControl, RWDataByte);
  do {
     IoRead8 (SMBusBaseAddress + SMBusStatus, Data8);
  } while (Data8 != SMBusInterrupt);                                            // Check SMBus write ready
}

Wednesday, March 9, 2011

SLP - System Locked Preinstallation

Version Windows
SLP       Windows XP,    Windows Server 2003
SLP 2.0 Windows Vista, Windows Server 2008
SLP 2.1 Windows 7,       Windows Server 2008 R2

Implement SLP that requirement as below.
1. OEMID and table ID should be provided by ODM.
2. OEMID and table ID should be the same in RSDT and SLIC table.
3. Need to install SLP public binary key into system BIOS.

Saturday, March 5, 2011

gEfiPciEnumerationCompleteGuid

The PCI deivce will complete enumeration when gEfiPciEnumerationCompleteGuid be installed.
So we can access PCI device behind PCI bridge when gEfiPciEnumerationCompleteGuid  be installed.

Thursday, February 24, 2011

Event Log

What is event log?
A: The event log is a message to inform end-user that system has error occur.

Why do we need event log?
A: When system POST has error, it should be recorded by system BIOS in order to notify end-user system has error occur.

Where can I find the event log?
A: The event log will be saved in SMBIOS type 15h by system BIOS.


Wednesday, February 23, 2011

How to call interrupt vector by SMM thunk?

...
if (InSmm) {
  Status = SmmRt->LocateProtocol (
                                  &gModulesSmmThunkProtocolGuid,
                                  NULL,
                                  &smmthunk
                                  );

  //
  // Before we execute smmthunk, we should clean the regs. In order to aviod strange issue.
  //
  EfiZeroMem (&Regs, sizeof (Regs)); 

  Status = smmthunk->SctIsr86 (
                                      smmthunk,
                                      0x10,           // Interrupt vector
                                      &Regs);
} else {
  ...
}
...

Monday, February 21, 2011

AMD Switchable Graphics

1. Implement PEI phase power sequence.
2. If the step one is right, the dGPU PCI device should be regconized under OS.
3. Need add a VBIOS for dGPU.
4. Load VBIOS to memory in DXE phase and create ACPI SSDT table for OS to active SG function.
5. Fill SVID/SSID to dGPU PCI register.
6. Save dGPU PCI register 0x00 ~ 0x3F for restore when system resume from S3.
7. If nothing is wrong, the SG should be worked very well.

ACPI Wake Up Event

How to implement ACPI wake up event?


1. Add a wake up device and namespace for _PRW

Scope(\_SB.PCI0)                                       // General-Purpose Event
{
  Device(XHC0)                 // USB 3.0 Devices
  {
      Name(_ADR,0x100000) // Device 16 Fun0
      Name(_PRW,Package(2)
      {
          0x18,                // Wake from USB PME#
          0x04                // Lowest sleep state to wake from
      })
  }
}



2. Add a GPE event for notify device

Scope(\_GPE)                                       // General-Purpose Event
{
  Method(_L18,0x0,Notserialized)        // USB PME# wake event
  {
    Notify(\_SB.PCI0.XHC0, 2)           // It will notify XHC0 driver
    ...
  } 

  ...



3. The SciMap of Xhc0 device need to change to 0x18 for AMD chipset (SB900).


The GPE event number should be the same with _PRW.
L event number need to refer chipset setting.
Q event number need to refer EC setting.

Tuesday, February 15, 2011

CMOS Access

CMOS是透過IO的方式去存取,Intel Chipset和AMD Chipset有兩個Bank(128 Bytes * 2)可以存取,但是設計上有些許差異,在使用上必須注意。

Intel
  存取Bank 0 是透過 IO port 0x70 去設定索引值(Index port),Index 值可以為0x00 ~ 0xFF,  但是0x00~0x7F會對映到0x80~0xFF為同一位置。
從IO port 0x71去取得資料(Data port)。
  存取Bank 1 是透過 IO port 0x72 去設定索引值(Index port),Index 值可以為0x00 ~ 0xFF,  但是0x00~0x7F會對映到0x80~0xFF為同一位置。
從IO port 0x73去取得資料(Data port)。

AMD
  存取Bank 0 是透過 IO port 0x70 去設定索引值(Index port),Index 值可以為0x00 ~ 0xFF,  但是0x00~0x7F會對映到0x80~0xFF為同一位置。
從IO port 0x71去取得資料(Data port)。
  存取Bank 1 是透過 IO port 0x72 去設定索引值(Index port),Index 值可以為0x00 ~ 0xFF,  但是0x00~0x7F會對映到Bank 0 0x00~0x7F的位置,而0x80~0xFF則是Bank 1 0x80~0xFF的位置。
從IO port 0x73去取得資料(Data port)。

Friday, February 4, 2011

LPC Bus

LPC - Low Pin Count

    LPC Bus用來取代傳統多腳位的的ISA Bus,最高時脈可達33MHz,像是parallel port device / serial port device / PS2 keyboard / PS2 mouse / floppy disk / EC / BIOS 比較低速的週邊裝置都使用LPC Bus來傳輸資料,避免猶如機車(慢速)騎上高速公路(BUS)去佔汽車(快速)的車道而造成塞車現象,關於LPC的詳細資料可到Intel網站去下載Low Pin Count specification。不過現在SPI Bus也開始漸漸取代LPC Bus的地位。下一篇文章會有SPI的介紹。