Note: 剖析ACPIEC Part I

在 Windows 平台上, 從 Win98 就開始引入 ACPI and ACPIEC driver stack, 好玩的是就Microsoft 有提供的source code(早期的DDK有附, Win2000) 看來, 實際上 ACPIEC.Sys 的Source code 應該是Intel 的 Bob Moore 所撰寫, 而我現在實測編譯出來的binary size 為 12.1KB(12,416Byte) 比XP Sp3還大一點, 底下是Build log, 研判應該是編譯參數問題, 有 9成的把握該Driver 在 XP 還是依據這個原始的Source, 要注意的是這個source 並不在 6001.18001內, 這是從舊的DDK內取出的!(Update: http://www.osronline.com/showthread.cfm?link=150332 跟據這個討論串中由 Jake Oshins/MSFT 指出從Vista開始已經將 ACPIEC一些功能直接整進 ACPI.SYS了)

BUILD: Computing Include file dependencies:
BUILD: Examining c:winddk6001.18001srcwdmacpiecec directory for files to compile.
skipping post pass 0 command
Compiling and Linking c:winddk6001.18001srcwdmacpiecec *************
‘nmake.exe /nologo BUILDMSG=Stop. -i BUILD_PASS=PASS2 LINKONLY=1 NOPASS0=1 MAKEDIR_RELATIVE_TO_BASEDIR=srcwdmacpiecec’
c:winddk6001.18001srcwdmacpiecec: TARGETPATH is obj
BUILDMSG: _NT_TARGET_VERSION SET TO WINXP
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386echo.msg not found
Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
Copyright (C) Microsoft Corporation.  All rights reserved.
cl.exe @c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386cl.rsp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.278 for 80×86
Copyright (C) Microsoft Corporation.  All rights reserved.
cl /Fo"c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386/"
/FC
/Ii386
/I.
/I..inc
/Ic:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386
/IC:WinDDK6001.18001incapi
/IC:WinDDK6001.18001incapi
/IC:WinDDK6001.18001incddk
/IC:WinDDK6001.18001incddk
/IC:WinDDK6001.18001inccrt
/D_X86_=1
/Di386=1
/DSTD_CALL
/DCONDITION_HANDLING=1
/DNT_INST=0
/DWIN32=100
/D_NT1X_=100
/DWINNT=1
/D_WIN32_WINNT=0x0501
/DWINVER=0x0501
/D_WIN32_IE=0x0603
/DWIN32_LEAN_AND_MEAN=1
/DDEVL=1
/D__BUILDMACHINE__=WinDDK
/DFPO=0
/DNDEBUG
/D_DLL=1
/DNDEBUG
/DNTDDI_VERSION=0x05010200
/c
/Zc:wchar_t-
/Zl
/Zp8
/Gy
/Gm-
-cbstring
-W3
-WX
/WX
/Gz
/hotpatch
/EHs-c-
/GR-
/GF
/GS
/Zi
/Oxs
/Oy-
/Zi
/Fdc:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386
/DKMDF_MAJOR_VERSION=01
/DKMDF_MINOR_VERSION=007
/FIC:WinDDK6001.18001incapiwarning.h
.acpiec.c .eclowio.c .ecpnp.c .handlers.c .service.c .query.c
acpiec.c
eclowio.c
ecpnp.c
handlers.c
service.c
query.c
Generating Code…
link.exe /out:c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386acpiec.sys /machine:ix86 @c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386lnk.rsp
Microsoft (R) Incremental Linker Version 8.00.50727.278
Copyright (C) Microsoft Corporation.  All rights reserved.
/MERGE:_PAGE=PAGE
/MERGE:_TEXT=.text
/SECTION:INIT,d
/OPT:REF
/OPT:ICF
/IGNORE:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221
/INCREMENTAL:NO
/release
/NODEFAULTLIB
/WX
/debug
/debugtype:cv,fixup,pdata
/version:6.0
/osversion:6.0
/functionpadmin:5
/safeseh
/pdbcompress
/STACK:0x40000,0x1000
/driver
/base:0x10000
/align:0x80 /stub:c:winddk6001.18001libwxpstub512.com
/subsystem:native,5.01
/entry:GsDriverEntry@8
/out:c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386acpiec.sys
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386acpiec.res
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386acpiec.obj
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386eclowio.obj
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386ecpnp.obj
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386handlers.obj
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386service.obj
c:winddk6001.18001srcwdmacpiececobjfre_wxp_x86i386query.obj
c:winddk6001.18001libwxpi386BufferOverflowK.lib
c:winddk6001.18001libwxpi386ntoskrnl.lib
c:winddk6001.18001libwxpi386hal.lib
c:winddk6001.18001libwxpi386wmilib.lib
c:winddk6001.18001libwxpi386sehupd.lib

所有的 ACPI Customer Driver 應該由 GUID_ACPI_INTERFACE_STANDARD 取得 ACPI Driver 本身的界面, 如 ACPIEC driver 的 source 中有一個檔案為 eclowio.c 裡面有一個 AcpiEcGetAcpiInterfaces. 它是在OS的 PNP Manager 去執行 ECAddDevice (in ecpnp.c) 時所被呼叫.

NTSTATUS
AcpiEcGetAcpiInterfaces (
IN PECDATA          EcData
)
/*++

Routine Description:

Call ACPI driver to get the direct-call interfaces.

Arguments:

EcData          – Pointer to the EC driver device extension

Return Value:

Status is returned.

–*/
{
KEVENT              event;
IO_STATUS_BLOCK     ioStatus;
NTSTATUS            status;
PIRP                irp;
PIO_STACK_LOCATION  irpSp;

PAGED_CODE();

//
// Initialize an event to block on
//
KeInitializeEvent( &event, SynchronizationEvent, FALSE );

//
// Build an irp
//
irp = IoBuildSynchronousFsdRequest(
IRP_MJ_PNP,
EcData->LowerDeviceObject,
NULL,
0,
NULL,
&event,
&ioStatus
);

if (!irp) {
return STATUS_INSUFFICIENT_RESOURCES;
}

irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
irp->IoStatus.Information = 0;

//
// Get the the current irp location
//
irpSp = IoGetNextIrpStackLocation( irp );

//
// Use QUERY_INTERFACE to get the address of the direct-call
// ACPI interfaces.
//
irpSp->MajorFunction = IRP_MJ_PNP;
irpSp->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpSp->Parameters.QueryInterface.InterfaceType          = (LPGUID) &GUID_ACPI_INTERFACE_STANDARD;
irpSp->Parameters.QueryInterface.Version                = 1;
irpSp->Parameters.QueryInterface.Size                   = sizeof (AcpiInterfaces);
irpSp->Parameters.QueryInterface.Interface              = (PINTERFACE) &AcpiInterfaces;
irpSp->Parameters.QueryInterface.InterfaceSpecificData  = NULL;

//
// send the request down
//
status = IoCallDriver( EcData->LowerDeviceObject, irp );
if (status == STATUS_PENDING) {

KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );
status = ioStatus.Status;

}

//
// Done
//
return status;
}

但是在可以看到當 ECAddDevice 還沒取得 ACPI interface 時, 就在將自己本身掛上 Driver list 後就已經去讀取 EC的 _GPE, 此時就已經可以發IRP 給底層的 ACPI.sys, 去取得ASL中的值!

更有趣的是, 如果用Google 查找 Bob Moore 的話可以找到 Bob Moore robert.moore@intel.com 針對ACPICA/Linux 的commit 所以基本上不管 Windows and Linux 上的 ACPI Driver Stack 應該都是Intel 的一群人寫出來的!

 

廣告

3 回應 to “Note: 剖析ACPIEC Part I”

  1. XD, EC-BIOS-DRIVER 你都会,牛人!

  2. 嚴重懷疑你是 稱讚自己 :P

  3. 我懂的都是皮毛XD, 向你好好学习!

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: