2018年7月24日 星期二

[ACPI] ASL Operator


本篇文章參考
ACPI Specification Version 6.2 (Errata A)
ACPI Specification Version 5.1 (Errata B)
參考章節為CH19 ACPI Source Language(ASL) Reference

Add

Add(Addend1, Addend2, Result) => Integer
將Addend1與Addend2相加存放到Result。

CreateWordField

CreateWordField(SourceBuffer, ByteIndex, WordFieldName)
在SourceBuffer的ByteIndex Offset建立一個Word長度且名為WordFieldName的Object。

DerefOf

DerefOf(Source) => Object
回傳Source所Reference的Object。

Device

Device(DeviceName) {TermList}
建立一個名為DeviceName的Object,用以代表processor、bus或device等硬體。並會開啟一個name scope。

EISAID

EISAID(EisaIdString) => DWordConst
將形式為"UUUNNNN"(U為大寫字母,N為十六進位數字)的文字字串轉換為4 byte長度的EISA ID數字編碼。

Field

Field (RegionName, AccessType, LockRule, UpdateRule) {FieldUnitList}
可用以代表RegionName中的某段區塊資料。
AccessType為預設存取寬度,可為AnyAccByteAccWordAccDWordAccQWordAcc
FileUnitList的Entry可為下列幾種形式,
FieldUnitName, BitLength - Field Unit所使用的命名與長度。Field Unit用以代表某段資料。
Offect (ByteOffset) - 下個Field Unit的Offset。

Include

Include(FilePathName)
引入其他ASL File。

Index

Index (Source, IndexNum, Destination) => ObjectReference
取得 Source 中第 IndexNum項的 Reference。
如 Source為 Buffer,Index會回傳第IndexNum的byte的Reference。
如 Source為 String,Index會回傳第IndexNum的字元的Reference。
如 Source為 Package,Index會回傳第IndexNum的Object的Reference。

Method

Method (MethodName, NumArgs, SerializeRule, SyncLevel, ReturnType, ParameterTypes) {TermList}
建立一個名為MethodName的control method,並會開啟一個name scope。
NumArgs代表Method的參數數量。為optional如不使用則代表此Method不使用參數,而最多可使用7個參數,參數分別reference到Arg0 - Arg6
SerializeRule可填為SerializedNotSerialized,Serialized代表此Method不會被其他thread同時存取,用以防止產生相同namespace object。若沒有指定則視為NotSerialized

Name

Name(ObjectName, Object)
建立名為ObjectName的Object,並且references到Object。

OperationRegion

OperationRegion(RegionName, RegionSpace, Offset, Length)
宣告名為RegionName的Operation Region,配合Field Object用以讀取系統硬體空間。

PowerResource

PowerResource(ResourceName, SystemLevel, ResourceOrder) {ObjectList}
宣告名為ResourceName的power resource。

Scope

Scope(Location) {ObjectList}
宣告名為Location的namespace,並且ObjectList以Location為參考namespace。
或將目前namespace切換成已存在的namespace。


Beyond BIOS Note - Ch1 Introduction

Chapter 1 Introduction


The suddenness of the leap from hardware to software cannot but produce a period of anarchy and collapse, especially in the developed countries.
- Marshall McLuhan

UEFI - UEFI is about booting, or passing control to successive layer of control

PI - PI describes the phase of control from the platform reset and into the success phase of operation

UEFI在於提供介面來讓其他應用來使用系統服務,而PI則在於規劃系統韌體的流程。


2018年7月17日 星期二

[ACPI] Device Configuration


本篇文章參考
ACPI Specification Version 6.2 (Errata A)
ACPI Specification Version 5.1 (Errata B)
參考章節為CH6 Device Configuration

OSPM 會根據 Configuration Object去管理操作相關的 Device,其大致分為幾個類型:

Device identification objects

_ADR (Address)

提供OSPM此裝置在所屬的Bus上的Address。
Bus   Address Encoding  
PCI   High word - Device Number, Low word - Function Number  
(ex: device 3, function 2 會是 0x00030002)  
若要參照device的所有function,Function Number則使用0xFFFF  
USB Ports   Port Number (1-n )  

Device configuration objects

_DIS (Disable)

用來 disable device。

_PRT (PCI Routing Table)

回傳包含PCI interrupt mapping package列表的package。

Device insertion and removal objects

_RMV (Status)

通知OSPM此裝置是否隨時都為可移除。

_STA (Status)

回傳裝置的狀態,其狀態可為enabled、disabled和removal。
若裝置的Object沒有_STA,則視為設起所有的return bit(present、enabled、shown in UI and functioning)。

Other Objects and Control Methods


_INI (Init)

用來對裝置進行特定的初始化操作,在OSPM加載description table時執行,會根據_STA來決定_INI是否及如何執行。


2018年7月12日 星期四

EDK常見的Macro - CR

在追EDK的Source Code時,會常看見Macro CR()的使用,其意義在於利用某個struct成員的記憶體位址,來獲得該struct的起始記憶體位址, 以此可以在記憶體操作上做更靈活的運用, 通常用於EFI Protocol。


#define CR (Record, TYPE, Field) \
  ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))


Record - Struct成員的記憶體位址
TYPE - Struct所宣告的型態
Field - Struct成員使用的名稱


CR拆解


1. &(((TYPE *) 0)->Field)
取得Struct成員在Struct中的offset

2. (CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)
用Struct成員的實際記憶體位址減去Offset,就可得到Struct的記憶體位址

3. (TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field))
再轉型回Struct的宣告型態


2018年7月8日 星期日

使用Visual Studio Community 2017/2019 Build EDK2 on Windows

參考來源
https://github.com/tianocore/tianocore.github.io/wiki/Windows-systems
https://github.com/tianocore/tianocore.github.io/wiki/UDK2018#how-to-build-UDK2018

Source

Visual Studio Community 2017
https://visualstudio.microsoft.com

UDK2018
https://github.com/tianocore/edk2/releases/tag/vUDK2018

Basetools-Win32
https://github.com/tianocore/edk2-BaseTools-win32

Python2.7
https://www.python.org/

Cygwin
https://www.cygwin.com/

NASM
https://www.nasm.us/

iASL
https://acpica.org/downloads/binary-tools

Environment Variable

PYTHON_HOME - Python安裝路徑 (預設C:\Python27)
CYGWIN_HOME - Cygwin安裝路徑 (預設C:\cygwin64)
EDK_TOOLS_BIN - Basetools-Win32路徑
NASM_PREFIX - NASM路徑
IASL_PREFIX - iASL路徑

target.txt

ACTIVE_PLATFORM
指定要build的DSC file的路徑。Ex: Nt32Pkg/Nt32Pkg.dsc。
(build -p Nt32Pkg/Nt32Pkg.dsc)

TARGET
指定build target。Ex: DEBUG RELEASE。
(build -b DEBUG)

TARGET_ARCH
指定使用架構。Ex: IA32 X64。
(build -a X64)

TOOL_CHAIN_TAG
指定Tool Chain的Tagname。Ex: VS2017。
(build -t VS2017)

Setup Reference

Directory Structure

C:\
├ ─ ─ ─ Python27
└ ─ ─ ─ cygwin64
└ ─ ─ ─ Program Files (x86)
    └ ─ ─ ─ Microsoft Visual Studio
        └ ─ ─ ─ 2017
            └ ─ ─ ─ Community

(WORKSPACE)
├ ─ ─ ─ UDK2018
└ ─ ─ ─ edk2-BaseTools-win32
└ ─ ─ ─ iasl-win-20180629
└ ─ ─ ─ nasm-2.13.03
└ ─ ─ ─ (Build-UDK2018)

Build-UDK2018.bat

@echo off

set PYTHON_HOME=C:\Python27
set CYGWIN_HOME=C:\cygwin64

set EDK_TOOLS_BIN=%cd%\edk2-BaseTools-win32
set NASM_PREFIX=%cd%\nasm-2.13.03\
set IASL_PREFIX=%cd%\iasl-win-20180629\

cd .\UDK2018

call edksetup.bat
cmd

Run Nt32Pkg

1. Build the Nt32Pkg
build -p Nt32Pkg/Nt32Pkg.dsc -t VS2017 -a X64

2. Run the Nt32 emulation
build -t VS2017 -a X64 run


2019/04/08 Note:
在更新完EDK的source code之後,會出現build failed ...\CryptoPkg\Library\OpensslLib\OpensslLibCrypto.inf(31): error 000E: File/directory not found in workspace
  ...\CryptoPkg\Library\OpensslLib\openssl\e_os.h

參考檔案 CryptoPkg\Library\OpensslLib\OpenSSL-HOWTO.txt 需加入OpenSSL submodule

在已擁有local source且未加入submodule的情況下,加入OpenSSL submodule git submodule update --init --recursive

若還未擁有local source,可直接使用"--recursive" flag git clone --recursive https://github.com/tianocore/edk2

2020/08/09 Note:
要build最新 edk2 EmulatorPkg,basetool部分需要重新rebuild
且需使用VC2019,使用VC2017會build不過


2021/10/06 Note:
在另一台電腦重新架環境,並rebuild BaseTools的時候會遇到 assert.h
找不到的問題。後來才發現 %include%的 path有問題,原因是那台電腦中安裝的
WDK可能造成在設定 SDK path的時候出問題,後來解除安裝 WDK就能避開這個問題。


2018年7月3日 星期二

PSPP (PCIe Speed Power Policy)

本篇文章參考來源:
AGESA Interface Specification for Arch2008
BKDG for AMD Family 12h Processors

PSPP 是動態調整PCIe的Link Speed的使用策略,藉此來達到省電的效果,需有處理器的支援。
其透過 Driver及 Interrupt來使用 BIOS所提供的 ACPI method ALIB(ACPI ASL Library) 達成其在Runtime時的所需的功能。

ALIB

ALIB method是由幾組Function所構成的服務。

ALIB (Arg0, Arg1)


 Arg0
     所要使用的Function的號碼。
 Arg1
     Function的輸入及輸出參數,會根據Function而有所不同。

Function 3 - PSPP Start/Stop Management Request

 用來決定是否使用PSPP。