Reading an UEFI variable in driver

Hi

I have a feature, which possibly will be exposed by OEM by providing a choice in the the BIOS.

I need to read that variable during my driver load time to follow appropriate code path (and then PCI/ACPI .sys invokes _DSW/_ON/_OFF methods with appropriate value).

I was looking at the ACPI spec and there is _DSM facility. I could ask OEM to add this
-http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf - 9.1.1 _DSM (Device Specific Method)

How do I read it in my driver (@ EvtDeviceAdd() or probably DriverEntry() itself)

  • Do I just use this custom driver specific GUID in WdfFdoQueryForInterface()?
  • Else any other better/shorter way to achieve this (like having an OEM component write to my driver registry hive before my driver loads - Windows Boot-Manager/OS-Laoder stages, not sure OEM have hooks during those stages though)

Windows has below pre-defined GUIDS already.

WDMGUID.H
//
// Interface GUIDs used for IRP_MN_QUERY_INTERFACE
//

#if (NTDDI_VERSION >= NTDDI_WIN2K)
DEFINE_GUID( GUID_BUS_INTERFACE_STANDARD, 0x496B8280L, 0x6F25, 0x11D0, 0xBE, 0xAF, 0x08, 0x00, 0x2B, 0xE2, 0x09, 0x2F );
DEFINE_GUID( GUID_PCI_BUS_INTERFACE_STANDARD, 0x496B8281L, 0x6F25, 0x11D0, 0xBE, 0xAF, 0x08, 0x00, 0x2B, 0xE2, 0x09, 0x2F );
DEFINE_GUID( GUID_PCI_BUS_INTERFACE_STANDARD2, 0xde94e966L, 0xfdff, 0x4c9c, 0x99, 0x98, 0x67, 0x47, 0xb1, 0x50, 0xe7, 0x4c );
DEFINE_GUID( GUID_ARBITER_INTERFACE_STANDARD, 0xe644f185L, 0x8c0e, 0x11d0, 0xbe, 0xcf, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f );
DEFINE_GUID( GUID_TRANSLATOR_INTERFACE_STANDARD, 0x6c154a92L, 0xaacf, 0x11d0, 0x8d, 0x2a, 0x00, 0xa0, 0xc9, 0x06, 0xb2, 0x44 );
DEFINE_GUID( GUID_ACPI_INTERFACE_STANDARD, 0xb091a08aL, 0xba97, 0x11d0, 0xbd, 0x14, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a );
DEFINE_GUID( GUID_INT_ROUTE_INTERFACE_STANDARD, 0x70941bf4L, 0x0073, 0x11d1, 0xa0, 0x9e, 0x00, 0xc0, 0x4f, 0xc3, 0x40, 0xb1 );
DEFINE_GUID( GUID_PCMCIA_BUS_INTERFACE_STANDARD, 0x76173af0L, 0xc504, 0x11d1, 0x94, 0x7f, 0x00, 0xc0, 0x4f, 0xb9, 0x60, 0xee );
DEFINE_GUID( GUID_ACPI_REGS_INTERFACE_STANDARD, 0x06141966L, 0x7245, 0x6369, 0x46, 0x2e, 0x4e, 0x65, 0x6c, 0x73, 0x6f, 0x6e );
DEFINE_GUID( GUID_LEGACY_DEVICE_DETECTION_STANDARD, 0x50feb0deL, 0x596a, 0x11d2, 0xa5, 0xb8, 0x00, 0x00, 0xf8, 0x1a, 0x46, 0x19 );
DEFINE_GUID( GUID_PCI_DEVICE_PRESENT_INTERFACE, 0xd1b82c26L, 0xbf49, 0x45ef, 0xb2, 0x16, 0x71, 0xcb, 0xd7, 0x88, 0x9b, 0x57 );
DEFINE_GUID( GUID_MF_ENUMERATION_INTERFACE, 0xaeb895f0L, 0x5586, 0x11d1, 0x8d, 0x84, 0x00, 0xa0, 0xc9, 0x06, 0xb2, 0x44 );
DEFINE_GUID( GUID_REENUMERATE_SELF_INTERFACE_STANDARD, 0x2aeb0243, 0x6a6e, 0x486b, 0x82, 0xfc, 0xd8, 0x15, 0xf6, 0xb9, 0x70, 0x06 );
#endif

#if (NTDDI_VERSION >= NTDDI_WINXP)
DEFINE_GUID( GUID_AGP_TARGET_BUS_INTERFACE_STANDARD, 0xB15CFCE8L, 0x06D1, 0x4D37, 0x9D, 0x4C, 0xBE, 0xDD, 0xE0, 0xC2, 0xA6, 0xFF );
DEFINE_GUID( GUID_ACPI_CMOS_INTERFACE_STANDARD, 0x3a8d0384L, 0x6505, 0x40ca, 0xbc, 0x39, 0x56, 0xc1, 0x5f, 0x8c, 0x5f, 0xed );
DEFINE_GUID( GUID_ACPI_PORT_RANGES_INTERFACE_STANDARD, 0xf14f609bL, 0xcbbd, 0x4957, 0xa6, 0x74, 0xbc, 0x0, 0x21, 0x3f, 0x1c, 0x97 );
#endif

#if (NTDDI_VERSION >= NTDDI_VISTA)
DEFINE_GUID( GUID_ACPI_INTERFACE_STANDARD2, 0xe8695f63L, 0x1831, 0x4870, 0xa8, 0xcf, 0x9c, 0x2f, 0x03, 0xf9, 0xdc, 0xb5 );
DEFINE_GUID( GUID_PNP_LOCATION_INTERFACE, 0x70211b0e, 0x0afb, 0x47db, 0xaf, 0xc1, 0x41, 0x0b, 0xf8, 0x42, 0x49, 0x7a );
DEFINE_GUID( GUID_PCI_EXPRESS_LINK_QUIESCENT_INTERFACE, 0x146cd41cL, 0xdae3, 0x4437, 0x8a, 0xff, 0x2a, 0xf3, 0xf0, 0x38, 0x09, 0x9b );
DEFINE_GUID( GUID_PCI_EXPRESS_ROOT_PORT_INTERFACE, 0x83a7734aL, 0x84c7, 0x4161, 0x9a, 0x98, 0x60, 0x00, 0xed, 0x0c, 0x4a, 0x33 );
DEFINE_GUID( GUID_MSIX_TABLE_CONFIG_INTERFACE, 0x1a6a460b, 0x194f, 0x455d, 0xb3, 0x4b, 0xb8, 0x4c, 0x5b, 0x05, 0x71, 0x2b );
DEFINE_GUID( GUID_D3COLD_SUPPORT_INTERFACE, 0xb38290e5, 0x3cd0, 0x4f9d, 0x99, 0x37, 0xf5, 0xfe, 0x2b, 0x44, 0xd4, 0x7a );
#endif

#if (NTDDI_VERSION >= NTDDI_WIN7)
DEFINE_GUID( GUID_PROCESSOR_PCC_INTERFACE_STANDARD, 0x37b17e9a, 0xc21c, 0x4296, 0x97, 0x2d, 0x11, 0xc4, 0xb3, 0x2b, 0x28, 0xf0);
DEFINE_GUID( GUID_PCI_VIRTUALIZATION_INTERFACE, 0x64897b47, 0x3a4a, 0x4d75, 0xbc, 0x74, 0x89, 0xdd, 0x6c, 0x7, 0x82, 0x93);
#endif

#if (NTDDI_VERSION >= NTDDI_WIN8)
DEFINE_GUID( GUID_PCC_INTERFACE_STANDARD, 0x3ee8ba63, 0x0f59, 0x4a24, 0x8a, 0x45, 0x35, 0x80, 0x8b, 0xdd, 0x12, 0x49);
DEFINE_GUID( GUID_PCC_INTERFACE_INTERNAL, 0x7cce62ce, 0xc189, 0x4814, 0xa6, 0xa7, 0x12, 0x11, 0x20, 0x89, 0xe9, 0x38);
DEFINE_GUID( GUID_THERMAL_COOLING_INTERFACE, 0xecbe47a8L, 0xc498, 0x4bb9, 0xbd, 0x70, 0xe8, 0x67, 0xe0, 0x94, 0x0d, 0x22 );
#endif

#if (NTDDI_VERSION >= NTDDI_WINTHRESHOLD)
DEFINE_GUID( GUID_DMA_CACHE_COHERENCY_INTERFACE, 0xb520f7fa, 0x8a5a, 0x4e40, 0xa3, 0xf6, 0x6b, 0xe1, 0xe1, 0x62, 0xd9, 0x35 );
DEFINE_GUID( GUID_DEVICE_RESET_INTERFACE_STANDARD, 0x649fdf26, 0x3bc0, 0x4813, 0xad, 0x24, 0x7e, 0xc, 0x1e, 0xda, 0x3f, 0xa3 );
DEFINE_GUID( GUID_IOMMU_BUS_INTERFACE, 0x1efee0b2, 0xd278, 0x4ae4, 0xbd, 0xdc, 0x1b, 0x34, 0xdd, 0x64, 0x80, 0x43 );
DEFINE_GUID( GUID_PCI_SECURITY_INTERFACE, 0x6e7f1451, 0x199e, 0x4acc, 0xba, 0x2d, 0x76, 0x2b, 0x4e, 0xdf, 0x46, 0x74);
#endif

How about ExGetFirmwareEnvironmentVariable ?

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Thursday, June 29, 2017 12:52 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Reading an UEFI variable in driver

Hi

I have a feature, which possibly will be exposed by OEM by providing a choice in the the BIOS.

I need to read that variable during my driver load time to follow appropriate code path (and then PCI/ACPI .sys invokes _DSW/_ON/_OFF methods with appropriate value).

I was looking at the ACPI spec and there is _DSM facility. I could ask OEM to add this
-https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.uefi.org%2Fsites%2Fdefault%2Ffiles%2Fresources%2FACPI_6.0.pdf&data=02%7C01%7CDoron.Holan%40microsoft.com%7Cc6039e0a7ef948b79a5b08d4bf2850fc%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C636343627267173622&sdata=EdMGn9CQhhoFlC4FmGKj7M10w4rX9Zw2FngThi65TUM%3D&reserved=0 - 9.1.1 _DSM (Device Specific Method)

How do I read it in my driver (@ EvtDeviceAdd() or probably DriverEntry() itself)
- Do I just use this custom driver specific GUID in WdfFdoQueryForInterface()?
- Else any other better/shorter way to achieve this (like having an OEM component write to my driver registry hive before my driver loads - Windows Boot-Manager/OS-Laoder stages, not sure OEM have hooks during those stages though)

Windows has below pre-defined GUIDS already.

WDMGUID.H
//
// Interface GUIDs used for IRP_MN_QUERY_INTERFACE //

#if (NTDDI_VERSION >= NTDDI_WIN2K)
DEFINE_GUID( GUID_BUS_INTERFACE_STANDARD, 0x496B8280L, 0x6F25, 0x11D0, 0xBE, 0xAF, 0x08, 0x00, 0x2B, 0xE2, 0x09, 0x2F );
DEFINE_GUID( GUID_PCI_BUS_INTERFACE_STANDARD, 0x496B8281L, 0x6F25, 0x11D0, 0xBE, 0xAF, 0x08, 0x00, 0x2B, 0xE2, 0x09, 0x2F );
DEFINE_GUID( GUID_PCI_BUS_INTERFACE_STANDARD2, 0xde94e966L, 0xfdff, 0x4c9c, 0x99, 0x98, 0x67, 0x47, 0xb1, 0x50, 0xe7, 0x4c );
DEFINE_GUID( GUID_ARBITER_INTERFACE_STANDARD, 0xe644f185L, 0x8c0e, 0x11d0, 0xbe, 0xcf, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f );
DEFINE_GUID( GUID_TRANSLATOR_INTERFACE_STANDARD, 0x6c154a92L, 0xaacf, 0x11d0, 0x8d, 0x2a, 0x00, 0xa0, 0xc9, 0x06, 0xb2, 0x44 );
DEFINE_GUID( GUID_ACPI_INTERFACE_STANDARD, 0xb091a08aL, 0xba97, 0x11d0, 0xbd, 0x14, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a );
DEFINE_GUID( GUID_INT_ROUTE_INTERFACE_STANDARD, 0x70941bf4L, 0x0073, 0x11d1, 0xa0, 0x9e, 0x00, 0xc0, 0x4f, 0xc3, 0x40, 0xb1 );
DEFINE_GUID( GUID_PCMCIA_BUS_INTERFACE_STANDARD, 0x76173af0L, 0xc504, 0x11d1, 0x94, 0x7f, 0x00, 0xc0, 0x4f, 0xb9, 0x60, 0xee );
DEFINE_GUID( GUID_ACPI_REGS_INTERFACE_STANDARD, 0x06141966L, 0x7245, 0x6369, 0x46, 0x2e, 0x4e, 0x65, 0x6c, 0x73, 0x6f, 0x6e );
DEFINE_GUID( GUID_LEGACY_DEVICE_DETECTION_STANDARD, 0x50feb0deL, 0x596a, 0x11d2, 0xa5, 0xb8, 0x00, 0x00, 0xf8, 0x1a, 0x46, 0x19 );
DEFINE_GUID( GUID_PCI_DEVICE_PRESENT_INTERFACE, 0xd1b82c26L, 0xbf49, 0x45ef, 0xb2, 0x16, 0x71, 0xcb, 0xd7, 0x88, 0x9b, 0x57 );
DEFINE_GUID( GUID_MF_ENUMERATION_INTERFACE, 0xaeb895f0L, 0x5586, 0x11d1, 0x8d, 0x84, 0x00, 0xa0, 0xc9, 0x06, 0xb2, 0x44 );
DEFINE_GUID( GUID_REENUMERATE_SELF_INTERFACE_STANDARD, 0x2aeb0243, 0x6a6e, 0x486b, 0x82, 0xfc, 0xd8, 0x15, 0xf6, 0xb9, 0x70, 0x06 ); #endif

#if (NTDDI_VERSION >= NTDDI_WINXP)
DEFINE_GUID( GUID_AGP_TARGET_BUS_INTERFACE_STANDARD, 0xB15CFCE8L, 0x06D1, 0x4D37, 0x9D, 0x4C, 0xBE, 0xDD, 0xE0, 0xC2, 0xA6, 0xFF );
DEFINE_GUID( GUID_ACPI_CMOS_INTERFACE_STANDARD, 0x3a8d0384L, 0x6505, 0x40ca, 0xbc, 0x39, 0x56, 0xc1, 0x5f, 0x8c, 0x5f, 0xed );
DEFINE_GUID( GUID_ACPI_PORT_RANGES_INTERFACE_STANDARD, 0xf14f609bL, 0xcbbd, 0x4957, 0xa6, 0x74, 0xbc, 0x0, 0x21, 0x3f, 0x1c, 0x97 ); #endif

#if (NTDDI_VERSION >= NTDDI_VISTA)
DEFINE_GUID( GUID_ACPI_INTERFACE_STANDARD2, 0xe8695f63L, 0x1831, 0x4870, 0xa8, 0xcf, 0x9c, 0x2f, 0x03, 0xf9, 0xdc, 0xb5 );
DEFINE_GUID( GUID_PNP_LOCATION_INTERFACE, 0x70211b0e, 0x0afb, 0x47db, 0xaf, 0xc1, 0x41, 0x0b, 0xf8, 0x42, 0x49, 0x7a );
DEFINE_GUID( GUID_PCI_EXPRESS_LINK_QUIESCENT_INTERFACE, 0x146cd41cL, 0xdae3, 0x4437, 0x8a, 0xff, 0x2a, 0xf3, 0xf0, 0x38, 0x09, 0x9b );
DEFINE_GUID( GUID_PCI_EXPRESS_ROOT_PORT_INTERFACE, 0x83a7734aL, 0x84c7, 0x4161, 0x9a, 0x98, 0x60, 0x00, 0xed, 0x0c, 0x4a, 0x33 );
DEFINE_GUID( GUID_MSIX_TABLE_CONFIG_INTERFACE, 0x1a6a460b, 0x194f, 0x455d, 0xb3, 0x4b, 0xb8, 0x4c, 0x5b, 0x05, 0x71, 0x2b );
DEFINE_GUID( GUID_D3COLD_SUPPORT_INTERFACE, 0xb38290e5, 0x3cd0, 0x4f9d, 0x99, 0x37, 0xf5, 0xfe, 0x2b, 0x44, 0xd4, 0x7a );
#endif

#if (NTDDI_VERSION >= NTDDI_WIN7)
DEFINE_GUID( GUID_PROCESSOR_PCC_INTERFACE_STANDARD, 0x37b17e9a, 0xc21c, 0x4296, 0x97, 0x2d, 0x11, 0xc4, 0xb3, 0x2b, 0x28, 0xf0); DEFINE_GUID( GUID_PCI_VIRTUALIZATION_INTERFACE, 0x64897b47, 0x3a4a, 0x4d75, 0xbc, 0x74, 0x89, 0xdd, 0x6c, 0x7, 0x82, 0x93); #endif

#if (NTDDI_VERSION >= NTDDI_WIN8)
DEFINE_GUID( GUID_PCC_INTERFACE_STANDARD, 0x3ee8ba63, 0x0f59, 0x4a24, 0x8a, 0x45, 0x35, 0x80, 0x8b, 0xdd, 0x12, 0x49); DEFINE_GUID( GUID_PCC_INTERFACE_INTERNAL, 0x7cce62ce, 0xc189, 0x4814, 0xa6, 0xa7, 0x12, 0x11, 0x20, 0x89, 0xe9, 0x38); DEFINE_GUID( GUID_THERMAL_COOLING_INTERFACE, 0xecbe47a8L, 0xc498, 0x4bb9, 0xbd, 0x70, 0xe8, 0x67, 0xe0, 0x94, 0x0d, 0x22 ); #endif

#if (NTDDI_VERSION >= NTDDI_WINTHRESHOLD) DEFINE_GUID( GUID_DMA_CACHE_COHERENCY_INTERFACE, 0xb520f7fa, 0x8a5a, 0x4e40, 0xa3, 0xf6, 0x6b, 0xe1, 0xe1, 0x62, 0xd9, 0x35 ); DEFINE_GUID( GUID_DEVICE_RESET_INTERFACE_STANDARD, 0x649fdf26, 0x3bc0, 0x4813, 0xad, 0x24, 0x7e, 0xc, 0x1e, 0xda, 0x3f, 0xa3 ); DEFINE_GUID( GUID_IOMMU_BUS_INTERFACE, 0x1efee0b2, 0xd278, 0x4ae4, 0xbd, 0xdc, 0x1b, 0x34, 0xdd, 0x64, 0x80, 0x43 ); DEFINE_GUID( GUID_PCI_SECURITY_INTERFACE, 0x6e7f1451, 0x199e, 0x4acc, 0xba, 0x2d, 0x76, 0x2b, 0x4e, 0xdf, 0x46, 0x74); #endif


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

xxxxx@yahoo.com wrote:

I have a feature, which possibly will be exposed by OEM by providing a choice in the the BIOS.

I need to read that variable during my driver load time to follow appropriate code path (and then PCI/ACPI .sys invokes _DSW/_ON/_OFF methods with appropriate value).

I was looking at the ACPI spec and there is _DSM facility. I could ask OEM to add this
-http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf - 9.1.1 _DSM (Device Specific Method)

How do I read it in my driver (@ EvtDeviceAdd() or probably DriverEntry() itself)

  • Do I just use this custom driver specific GUID in WdfFdoQueryForInterface()?
  • Else any other better/shorter way to achieve this (like having an OEM component write to my driver registry hive before my driver loads - Windows Boot-Manager/OS-Laoder stages, not sure OEM have hooks during those stages though)

Good question, and one for which sample source is very difficult to find.

The _DSM method needs to be declared in the ACPI section for your
device. That way, the ACPI driver knows where to route your request.

You need to submit an IRP_MJ_DEVICE_CONTROL IRP to the next driver below
you, with the ioctl IOCTL_ACPI_EVAL_METHOD. The input is an
ACPI_EVAL_INPUT_BUFFER structure if you don’t need to specify any
parameters, or ACPI_EVAL_INPUT_BUFFER_COMPLEX if you do. Include the
method name (‘MDS_’, if you want to use the long constant feature). The
output is an ACPI_EVAL_OUTPUT_BUFFER. There are a few examples on the web.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

There’s an example of calling a DSM method here:

https://github.com/uri247/wdk81/blob/master/SpbAccelerometer%20Sample%20Driver%20(UMDF%20Version%201)/C%2B%2B/AccelerometerDevice.cpp#L203

It’s in UMDF, but the code for building the necessary input and output
buffers is the same as kernel mode (see PrepareInputParametersForDsm for
building the input buffer)

-scott
OSR
@OSRDrivers

“Tim Roberts” wrote in message news:xxxxx@ntdev…

xxxxx@yahoo.com wrote:

I have a feature, which possibly will be exposed by OEM by providing a
choice in the the BIOS.

I need to read that variable during my driver load time to follow
appropriate code path (and then PCI/ACPI .sys invokes _DSW/_ON/_OFF
methods with appropriate value).

I was looking at the ACPI spec and there is _DSM facility. I could ask OEM
to add this
-http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf - 9.1.1
_DSM (Device Specific Method)

How do I read it in my driver (@ EvtDeviceAdd() or probably DriverEntry()
itself)

  • Do I just use this custom driver specific GUID in
    WdfFdoQueryForInterface()?
  • Else any other better/shorter way to achieve this (like having an OEM
    component write to my driver registry hive before my driver loads -
    Windows Boot-Manager/OS-Laoder stages, not sure OEM have hooks during
    those stages though)

Good question, and one for which sample source is very difficult to find.

The _DSM method needs to be declared in the ACPI section for your
device. That way, the ACPI driver knows where to route your request.

You need to submit an IRP_MJ_DEVICE_CONTROL IRP to the next driver below
you, with the ioctl IOCTL_ACPI_EVAL_METHOD. The input is an
ACPI_EVAL_INPUT_BUFFER structure if you don’t need to specify any
parameters, or ACPI_EVAL_INPUT_BUFFER_COMPLEX if you do. Include the
method name (‘MDS_’, if you want to use the long constant feature). The
output is an ACPI_EVAL_OUTPUT_BUFFER. There are a few examples on the web.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.