vieyahn2017 / iBlog

44 stars 0 forks source link

ACPI - 高级配置和电源管理接口(Advanced Configuration and Power Management Interface) #394

Open vieyahn2017 opened 1 month ago

vieyahn2017 commented 1 month ago

ACPI其实是一种电源管理标准,ACPI是Advanced Configuration and Power Interface的首字母缩写,一般翻译成高级电源管理,是Intel、Microsoft和东芝共同开发的一种电源管理标准。

vieyahn2017 commented 1 month ago

基本概念

  1. ACPI是一种定义BIOS和OS之间接口的方法。和DTS等不同,ACPI支持函数接口,也就是说OS可以通过“调用”BIOS ACPI表中的函数接口来实现功能;所谓的调用有几种可能: a. BIOS中给定一个数据结构,整体描述了一个函数,该函数本身就是CPU的本地汇编。BIOS把整个数据接口传递到OS管理的内存空间,OS直接调用这个空间中的函数。 b. BIOS中给定一个数据结构,整体描述了一个函数,该函数本身就是CPU的本地汇编。这个数据结构留在BIOS控制的内存中,传递给OS一个指针,OS远程调用这个指令的地址,完成请求。 c. BIOS中实现了一个本地函数,然后把这个函数的位置和格式告知OS,OS通过一个统一的接口把函数的标识和请求的参数传递给BIOS,BIOS内部完成调用,然后把结果通知OS。 d. BIOS给定一个数据结构,整体描述了一个函数,用一种平台无关的格式标识,这个数据结构整体提供给OS,OS上有一个解释器,解释执行这个平台无关的格式,实现对功能的执行。
  2. ACPI表DSDT.dsl文件中实现相关描述与Method,是一种解释型的语言,而不是被编成了二进制;
  3. OS中存在一个解释器,AML是一个类似java的Bincode,通过解释器建立数据结构,从而可以解释执行;
  4. Linux内核的具体实现:ACPI Method Execute-flow:acpi_evaluate_integer-->acpi_evaluate_object-->acpi_ns_evaluate-->acpi_ps_execute_method-->acpi_ps_parse_aml;
  5. /sys/firmware/acpi/tables:DSDT:单板目录;
  6. zypper install iasl:安装解析工具;
  7. iasl -d DSDT:解析ACPI文件;
  8. vim DSDT.dsl:相当于dts文件;
vieyahn2017 commented 1 month ago

参考资料

  1. Linux设备驱动--pci总线的初始化:https://blog.csdn.net/whenloce/article/details/90901438
  2. 解析acpi表:
  3. AML工作原理快速调研:https://zhuanlan.zhihu.com/p/113296734
  4. ACPI Summary:https://maggie262.github.io/2020/02/06/acpi-summary/
  5. ASL tutorial:https://acpica.org/sites/acpica/files/asl_tutorial_v20190625.pdf
  6. ACPI Introduction:https://acpica.org/sites/acpica/files/ACPI-Introduction.pdf
  7. 路电 x86 2146新单板启动劣化:http://rnd-isourceb.huawei.com/Euler/rtos_r3/issues/17783
vieyahn2017 commented 1 month ago

解析acpi表

下载开源acpi工具
git clone https://github.com/acpica/acpica.git 编译

ll bin total 2772 -rwxr-xr-x 1 55416 Apr 26 20:17 acpibin -rwxr-xr-x 1 65456 Apr 26 20:17 acpidump -rwxr-xr-x 1 257504 Apr 26 20:17 acpiexamples -rwxr-xr-x 1 675424 Apr 26 20:18 acpiexec -rwxr-xr-x 1 144856 Apr 26 20:18 acpihelp -rwxr-xr-x 1 280968 Apr 26 20:18 acpinames -rwxr-xr-x 1 97184 Apr 26 20:18 acpisrc -rwxr-xr-x 1 45640 Apr 26 20:18 acpi

acpidump -o ACPI_table.out 【 输出到文件 】 acpixtract -a ACPI_table.out 【从文件解析】 ll /sys/firmware/acpi/tables/ iasl -d dsdt.dat 【 生成 dsdt.dsl 】

acpidump – dump a system’s ACPI tables to an ASCII file acpixtract – convert ASCII acpidump output to raw binary table turbostat – gather performance statistics

IASL:ACPI Source Language compiler/decompiler

vieyahn2017 commented 1 month ago

或者 yum install acpica-tools

vieyahn2017 commented 1 month ago

iasl

Intel ACPI Component Architecture ASL+ Optimizing Compiler/Disassembler version 20200528 Copyright (c) 2000 - 2020 Intel Corporation

Supports ACPI Specification Revision 6.3

Usage: iasl [Options] [Files] Options:

General: -@ Specify command file -I

Specify additional include directory -p Specify path/filename prefix for all output files -v Display compiler version -vd Display compiler build date and time -vo Enable optimization comments -vs Disable signon

Help: -h This message -hc Display operators allowed in constant expressions -hd Info for obtaining and disassembling binary ACPI tables -hf Display help for output filename generation -hr Display ACPI reserved method names -ht Display currently supported ACPI table names

Preprocessor: -D Define symbol for preprocessor use -li Create preprocessed output file (.i) -P Preprocess only and create preprocessor output file (.i) -Pn Disable preprocessor

Errors, Warnings, and Remarks: -va Disable all errors/warnings/remarks -ve Report only errors (ignore warnings and remarks) -vi Less verbose errors and warnings for use with IDEs -vr Disable remarks -vw Ignore specific error, warning or remark -vx Expect a specific warning, remark, or error -w <1|2|3> Set warning reporting level -we Report warnings as errors -ww Report specific warning or remark as error

AML Bytecode Generation (*.aml): -oa Disable all optimizations (compatibility mode) -of Disable constant folding -oi Disable integer optimization to Zero/One/Ones -on Disable named reference string optimization -ot Disable typechecking -cr Disable Resource Descriptor error checking -in Ignore NoOp operators -r Override table header Revision (1-255)

Listings: -l Create mixed listing file (ASL source and AML) (.lst) -lm Create hardware summary map file (.map) -ln Create namespace file (.nsp) -ls Create combined source file (expanded includes) (.src) -lx Create cross-reference file (*.xrf)

Firmware Support - C Text Output: -tc Create hex AML table in C (.hex) -sc Create named hex AML arrays in C (.c) -ic Create include file in C for -sc symbols (.h) -so Create namespace AML offset table in C (.offset.h)

Firmware Support - Assembler Text Output: -ta Create hex AML table in assembler (.hex) -sa Create named hex AML arrays in assembler (.asm) -ia Create include file in assembler for -sa symbols (*.inc)

Firmware Support - ASL Text Output: -ts Create hex AML table in ASL (Buffer object) (*.hex)

Legacy-ASL to ASL+ Converter: -ca Convert legacy-ASL source file to new ASL+ file (Original comments are passed through to ASL+ file)

Data Table Compiler: -tp Compile tables with flex/bison prototype -G Compile custom table that contains generic operators -T |ALL Create ACPI table template/example files -T Emit DSDT and SSDTs to same file -vt Create verbose template files (full disassembly)

AML Disassembler: -d <f1 f2 ...> Disassemble or decode binary ACPI tables to file (*.dsl) (Optional, file type is automatically detected) -da <f1 f2 ...> Disassemble multiple tables from single namespace -db Do not translate Buffers to Resource Templates -dc <f1 f2 ...> Disassemble AML and immediately compile it (Obtain DSDT from current system if no input file) -df Force disassembler to assume table contains valid AML -dl Emit legacy ASL code only (no C-style operators) -e <f1 f2 ...> Include ACPI table(s) for external symbol resolution -fe Specify external symbol declaration file -in Ignore NoOp opcodes -l Disassemble to mixed ASL and AML code -vt Dump binary table data in hex format within output file

Debug Options: -bc Create converter debug file (.cdb) -bf Create debug file (full output) (.txt) -bs Create debug file (parse tree only) (*.txt) -bp Prune ASL parse tree -bt Object type to be pruned from the parse tree -f Ignore errors, force creation of AML output file(s) -m Set internal line buffer size (in Kbytes) -n Parse only, no output generation -oc Display compile times and statistics -x Set debug level for trace output -z Do not insert new compiler ID for DataTables

vieyahn2017 commented 1 month ago

ll /sys/firmware/acpi/tables total 0 -r-------- 1 root root 772 Aug 1 17:08 APIC -r-------- 1 root root 165 Aug 1 17:08 'ASF!' -r-------- 1 root root 48 Aug 1 17:08 BDAT -r-------- 1 root root 48 Aug 1 17:08 BERT -r-------- 1 root root 40 Aug 1 17:08 BOOT drwxr-xr-x 2 root root 0 Aug 1 17:08 data -r-------- 1 root root 52 Aug 1 17:08 DBGP -r-------- 1 root root 280 Aug 1 17:08 DMAR -r-------- 1 root root 186073 Aug 1 17:08 DSDT drwxr-xr-x 2 root root 0 Aug 1 17:08 dynamic -r-------- 1 root root 336 Aug 1 17:08 EINJ -r-------- 1 root root 560 Aug 1 17:08 ERST -r-------- 1 root root 268 Aug 1 17:08 FACP -r-------- 1 root root 64 Aug 1 17:08 FACS -r-------- 1 root root 68 Aug 1 17:08 FPDT -r-------- 1 root root 168 Aug 1 17:08 HEST -r-------- 1 root root 56 Aug 1 17:08 HPET -r-------- 1 root root 60 Aug 1 17:08 MCFG -r-------- 1 root root 209 Aug 1 17:08 PRAD -r-------- 1 root root 108 Aug 1 17:08 SLIT -r-------- 1 root root 65 Aug 1 17:08 SPMI -r-------- 1 root root 976 Aug 1 17:08 SRAT -r-------- 1 root root 1480 Aug 1 17:08 SSDT1 -r-------- 1 root root 1608 Aug 1 17:08 SSDT2 -r-------- 1 root root 566 Aug 1 17:08 UEFI1 -r-------- 1 root root 66 Aug 1 17:08 UEFI2 -r-------- 1 root root 404 Aug 1 17:08 WDAT

vieyahn2017 commented 1 month ago

ACPI定义了很多的表,这里不一一说明,下面是其中的一些:

• Root System Description Table (RSDT) • Fixed ACPI Description Table (FADT) • Firmware ACPI Control Structure (FACS) • Differentiated System Description Table (DSDT) 差异化系统描述表 • Secondary System Description Table (SSDT) • Multiple APIC Description Table (MADT) • Smart Battery Table (SBST) • Extended System Description Table (XSDT) • Embedded Controller Boot Resources Table (ECDT) • System Locality Distance Information Table (SLIT) • System Resource Affinity Table (SRAT) • Corrected Platform Error Polling Table (CPEP) • Maximum System Characteristics Table (MSCT) • ACPI RAS Feature Table (RASF) • Memory Power State Table (MPST) • Platform Memory Topology Table (PMTT) • Boot Graphics Resource Table (BGRT) • Firmware Performance Data Table (FPDT) 固件性能数据表 • Generic Timer Description Table (GTDT) • NVDIMM Firmware Interface Table (NFIT)

ACPI Spec的第五章ACPI Software Programming Model中对它们有介绍。

vieyahn2017 commented 1 month ago

参考 https://github.com/edk2-porting/edk2-msm/blob/7352c1a46b208ab90184cbc7e97b63d3088dc574/Platform/Xiaomi/sm6225/AcpiTables/fog/DSDT.dsl#L4

DefinitionBlock ("", "DSDT", 2, "QCOMM ", "SM6225 ", 0x00000003)
vieyahn2017 commented 1 month ago

Linux内核深入理解定时器和时间管理(6):x86_64 相关的时钟源(kvm-clock,tsc,acpi_pm,hpet)

https://blog.csdn.net/Rong_Toa/article/details/115350561

vieyahn2017 commented 1 month ago

在BIOS向OS报告的ACPI表中,最重要的是SRAT(System Resource Affinity Table 系统资源亲和性表)和SLIT(System Locality Information Table 系统位置信息表)。

SRAT中包含两个结构

Processor Local APIC/SAPIC Affinity Structure:每个逻辑Processor在Proximity Domain所处的位置。每个逻辑Processor都有不同的Local APIC ID,所以Processor用Local APIC ID表示。 Memory Affinity Structure:记录内存的信息,即每块内存都从属于哪个Proximity Domain。 有了这个表OSPM就可以描绘出一个CPU和内存的关系图,包括有几个node,每个node里面有那些逻辑Processor和内存。

SLIT表则记录了各个结点之间的距离

通过这两个表,OS可以在内存中建立整体Processor和内存的亲缘关系图和距离表,作为任务调度和内存分配的依据。详细信息可以查看ACPI Spec 6.1的第17章节

=== 【这两跟NUMA相关】