Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438662
  • 博文数量: 90
  • 博客积分: 2158
  • 博客等级: 大尉
  • 技术积分: 1425
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-12 17:02
个人简介

怎么了选择

文章分类
文章存档

2023年(1)

2019年(1)

2018年(5)

2017年(5)

2015年(1)

2014年(1)

2013年(1)

2012年(74)

分类: Windows平台

2018-01-04 17:30:39

1ACPI table 在BIOS 里面用ASL code 去描述。而ACPI Table又分成不同类型的Table(RSDT/FADT/DSDT...etc).

2像是我们比较常使用的DSDT Table就是放了一些event code.简单说就是当某个H/W event发生后,系统会依照

描述在这个DSDT Table中的ASL code去执行,而这些Acpi Table 包在BIOS ROM 中的形式是AML Code (类似

机器码)。

3. BIOS在开机过程中会把包在BIOS ROM中的Acpi Table 载入到RAM中,然后留下一些信息给OS来找到他们,

最简单的例子就是RSDP Structure会放在1M以下的某个位置(一般是E0000h~FFFFh),然后OS就可以透过搜寻

Signature(某个标记字)的方式来找到其他的Acpi Table entry point。

4. OS 需要有一个AML翻译器去翻译这些AML code,然后去执行他们。

5.每个 Platform 的host controller的寄存器位置不同,所以BIOS需要透过ACPI Table来告知OS这些寄存器的

位置,这样子做的好处是OS不需要知道你是在什么Platform,因为他只单纯看BIOS所提供的HW信息。


结合ASL代码学习ACPI

1.从  _STA 说起.

_STA 描述了一个设备的当前状态,比如说它可以告诉操作系统某个device 是否存在,或者说,是否要show出来。具体参考ACPI spec 6.3.7(version 6.0)

这个object 描述了某个device 的当前状态,它可以是这三种情况:enabled, disabled 或者removed.


OSPM(其实就是OS) 在调用 INI 之前会先执行_STA 这个method.   先检测到它存在了,再去初始化它,不存在,也就没有初始化一说了。


如果某个device 下面,没有放这个_STA method ,我们默认它是存在并且正常工作的。


参数:

None


返回值:

Bit[0]   如果device 存在将会被置起

Bit[1]  如果device 被置起,并且decode 到相应的resource

Bit[2]  如果希望将其在UI中show出来,那么将这一位置起

Bit[3]  如果能正常工作,这一位会被置起。

Bit[4]  如果电池存在,置起这一位

Bit[31:5] 保留起来,以后用




[cpp] view plain copy
  1. // _STA (Status)  
  2. //  
  3. // This object returns the current status of a device.  
  4. //  
  5. // Arguments: (0)  
  6. //   None  
  7. // Return Value:  
  8. //   An Integer containing a device status bitmap:  
  9. //    Bit 0 - Set if the device is present.  
  10. //    Bit 1 - Set if the device is enabled and decoding its resources.  
  11. //    Bit 2 - Set if the device should be shown in the UI.  
  12. //    Bit 3 - Set if the device is functioning properly (cleared if device failed its diagnostics).  
  13. //    Bit 4 - Set if the battery is present.  
  14. //    Bits 5-31 - Reserved (must be cleared).  
  15. //  
  16. Method(_STA)  
  17. {  
  18.   If (LEqual(DPTF,1)){  
  19.     Return(0x0F)  
  20.   } Else {  
  21.     Return(0x00)  
  22.   }  
  23. }  








动动手:一个小实验

这张图截自windows 设备管理器,他显示了系统下有哪些device.


如果你想其中某个隐藏起来,就在asl code 中找到它(比如通过hid). 然后在下面写一个_STA 方法,返回全0.

[cpp] view plain copy
  1. Device(RTC) // RTC  
  2. {  
  3.   Name(_HID,EISAID("PNP0B00"))  
  4.   
  5.   Name(_CRS,ResourceTemplate()  
  6.   {  
  7.     IO(Decode16,0x70,0x70,0x01,0x08)  
  8.     IRQNoFlags() {8}  
  9.   })  
  10. }  


加几句,写成:


[cpp] view plain copy
  1. Device(RTC) // RTC  
  2. {  
  3.   Name(_HID,EISAID("PNP0B00"))  
  4.   
  5.   Name(_CRS,ResourceTemplate()  
  6.   {  
  7.     IO(Decode16,0x70,0x70,0x01,0x08)  
  8.     IRQNoFlags() {8}  
  9.   })  
  10.     
  11.   Method(_STA, 0)  
  12.   {  
  13.    Return (0)  
  14.   }  
  15. }  







然后,看看结果,是不是看不到RTC了?





FAQ?


谁去调用这些ASL code 中的这些method?

OS.

随便打开一份ACPI compatible (Linux , windows )的源代码,搜索_STA

ReactOS-0.3.14\drivers\bus\acpi\acpica\namespace\nsxfname.c  (取自ReactOS)

有这么几行


[cpp] view plain copy
  1. /* 
  2.  * Get extra info for ACPI Device/Processor objects only: 
  3.  * Run the _STA, _ADR and, SxW, and _SxD methods. 
  4.  * 
  5.  * Note: none of these methods are required, so they may or may 
  6.  * not be present for this device. The Info->Valid bitfield is used 
  7.  * to indicate which methods were found and run successfully. 
  8.  */  
  9.   
  10. /* Execute the Device._STA method */  
  11.   
  12. Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);  
  13. if (ACPI_SUCCESS (Status))  
  14. {  
  15.     Valid |= ACPI_VALID_STA;  
  16. }  
  17.   
  18. /* Execute the Device._ADR method */  
  19.   
  20. Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,  
  21.             &Info->Address);  
  22. if (ACPI_SUCCESS (Status))  
  23. {  
  24.     Valid |= ACPI_VALID_ADR;  
  25. }  
  26.   
  27. /* Execute the Device._SxW methods */  
  28.   
  29. Status = AcpiUtExecutePowerMethods (Node,  
  30.             AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,  
  31.             Info->LowestDstates);  
  32. if (ACPI_SUCCESS (Status))  
  33. {  
  34.     Valid |= ACPI_VALID_SXWS;  
  35. }  





2. OS 如何找到ACPI table?


通过RSDP 这个signature


[cpp] view plain copy
  1. /******************************************************************************* 
  2.  * 
  3.  * FUNCTION:    Acpi_tb_scan_memory_for_rsdp 
  4.  * 
  5.  * PARAMETERS:  Start_address       - Starting pointer for search 
  6.  *              Length              - Maximum length to search 
  7.  * 
  8.  * RETURN:      Pointer to the RSDP if found, otherwise NULL. 
  9.  * 
  10.  * DESCRIPTION: Search a block of memory for the RSDP signature 
  11.  * 
  12.  ******************************************************************************/  
  13.   
  14. u8 *  
  15. acpi_tb_scan_memory_for_rsdp (  
  16.     u8                      *start_address,  
  17.     u32                     length)  
  18. {  
  19.     u32                     offset;  
  20.     u8                      *mem_rover;  
  21.   
  22.   
  23.     /* Search from given start addr for the requested length  */  
  24.   
  25.     for (offset = 0, mem_rover = start_address;  
  26.          offset < length;  
  27.          offset += RSDP_SCAN_STEP, mem_rover += RSDP_SCAN_STEP)  
  28.     {  
  29.   
  30.         /* The signature and checksum must both be correct */  
  31.   
  32.         if (STRNCMP ((NATIVE_CHAR *) mem_rover,  
  33.                 RSDP_SIG, sizeof (RSDP_SIG)-1) == 0 &&  
  34.             acpi_tb_checksum (mem_rover, RSDP_CHECKSUM_LENGTH) == 0)  
  35.         {  
  36.             /* If so, we have found the RSDP */  
  37.   
  38.             return (mem_rover);  
  39.         }  
  40.     }  
  41.   
  42.     /* Searched entire block, no RSDP was found */  
  43.   
  44.     return (NULL);  
  45. }  
阅读(10137) | 评论(0) | 转发(0) |
0

上一篇:ACPI asl code

下一篇:SCI与SMI

给主人留下些什么吧!~~