How to find Physical Memory size from a boot time driver ?

Temporal Need:: On a PEA or 64bit system I would want to know what is the total amount of physical memory OS thinks it has.

ZwQuerySystemInformation is one option using SystemBasicInformation, but I don’t think it is a document DDI !

If I see system has (let say) more than 32GB , I would like to make the DMA interface tobe 32bit ( not worried about double buffering or transperant bounce buffering performance hit at this time as well as any possbile data corruption due to DAC related issues). Also the virtual memory assoicated with these physical host addresses are not in my control ( in other words it is not my allocation so I can not specify what is absolute highest physical address I would like to have for these allocation).

I can not use the win32 WAE interface, since it is boot time.

Thx
-pro

What about MmQuerySystemSize()? It’s documented as returning an estimate, and I don’t really know what that means exactly, but it’s probably worth a shot.

mm

Please ignore that last post. I just looked it up and realized that I had it confused with something else. I thought it returned an estimated amount, but it returns an enumerate.

mm

Nt(Zw) QuerySystemInformation is documented online at MSDN (and not in the
‘official’ ddk docs?) but the definition of SYSTEM_BASIC_INFORMATION is
obfuscated.

typedef struct _SYSTEM_BASIC_INFORMATION {

BYTE Reserved1[24];

PVOID Reserved2[4];

CCHAR NumberOfProcessors;

} SYSTEM_BASIC_INFORMATION;

http://msdn2.microsoft.com/en-us/library/ms724509.aspx

Google reveals that the page size is the third ULONG in the Reserved1 block
of stuff and the number of physical pages is the fourth. Obviously you
cannot count on those fields as they aren’t documented but you can certainly
check that page size makes sense before using number of physical pages.

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Prokash Sinha
Sent: Friday, September 28, 2007 12:24 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to find Physical Memory size from a boot time driver ?

Temporal Need:: On a PEA or 64bit system I would want to know what is the
total amount of physical memory OS thinks it has.

ZwQuerySystemInformation is one option using SystemBasicInformation, but I
don’t think it is a document DDI !

If I see system has (let say) more than 32GB , I would like to make the DMA
interface tobe 32bit ( not worried about double buffering or transperant
bounce buffering performance hit at this time as well as any possbile data
corruption due to DAC related issues). Also the virtual memory assoicated
with these physical host addresses are not in my control ( in other words it
is not my allocation so I can not specify what is absolute highest physical
address I would like to have for these allocation).

I can not use the win32 WAE interface, since it is boot time.

Thx

-pro


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

A few ideas, two undocumented, one documented more or less but cumbersome.

  1. There is a non-exported symbol MmNumberOfPhysicalPages that is accessible through the debugger data block. The problems with this are obvious.

  2. You could parse the system memory information (REG_RESOURCE_LIST) located under

HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory.Translated

  1. You get get the same information using MmGetPhysicalMemoryRanges(), which returns an array of

struct PHYSICAL_MEMORY_RANGE
{
PHYSICAL_ADDRESS BaseAddress;
LARGE_INTEGER NumberOfBytes;
};

with the last entry in the list containing 0’s.

  1. You could parse the SMBIOS tables to get this information. This method, though ugly, is more or less documented, including in a Microsoft whitepaper updated for Vista (which kind of suprised me):

http://download.microsoft.com/download/5/D/6/5D6EAF2B-7DDF-476B-93DC-7CF0072878E6/SMBIOS.doc

http://www.dmtf.org/standards/published_documents/DSP0134.pdf

There has to be an easier way than the last, but it is documented, sort of.

Good luck,

mm

Thanks Mark,

This is probably I will have to use. I will also look at the links MM gave.

I was looking for few possiblities —

  1. Any registry entries in the system hive ? No luck !

  2. Any global kernel exports ( it is an ugly thought ).

  3. Any Bios probe at early stage ( even uglier than (2), soon we would all be in (U)EFI …)

  4. Documented DDI to use

  5. Undocumented DDI ( What a (wo)man got a do is what a … kind of approach )

  6. Did not think about probing tables as suggested by MM

  7. Testing memory in a loop ( not a well thought out plan though )

-pro

----- Original Message -----
From: Mark Roddy
To: Windows System Software Devs Interest List
Sent: Friday, September 28, 2007 5:55 AM
Subject: RE: [ntdev] How to find Physical Memory size from a boot time driver ?

Nt(Zw) QuerySystemInformation is documented online at MSDN (and not in the ‘official’ ddk docs?) but the definition of SYSTEM_BASIC_INFORMATION is obfuscated.

typedef struct _SYSTEM_BASIC_INFORMATION {

BYTE Reserved1[24];

PVOID Reserved2[4];

CCHAR NumberOfProcessors;

} SYSTEM_BASIC_INFORMATION;

http://msdn2.microsoft.com/en-us/library/ms724509.aspx

Google reveals that the page size is the third ULONG in the Reserved1 block of stuff and the number of physical pages is the fourth. Obviously you cannot count on those fields as they aren’t documented but you can certainly check that page size makes sense before using number of physical pages.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Prokash Sinha
Sent: Friday, September 28, 2007 12:24 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to find Physical Memory size from a boot time driver ?

Temporal Need:: On a PEA or 64bit system I would want to know what is the total amount of physical memory OS thinks it has.

ZwQuerySystemInformation is one option using SystemBasicInformation, but I don’t think it is a document DDI !

If I see system has (let say) more than 32GB , I would like to make the DMA interface tobe 32bit ( not worried about double buffering or transperant bounce buffering performance hit at this time as well as any possbile data corruption due to DAC related issues). Also the virtual memory assoicated with these physical host addresses are not in my control ( in other words it is not my allocation so I can not specify what is absolute highest physical address I would like to have for these allocation).

I can not use the win32 WAE interface, since it is boot time.

Thx

-pro


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I posted some information about the registry information. It’s a REG_RESOURCE_LIST.

I know the question is how to do it via a boot driver. I know how to find it from Registry. Most of the registry entries can be read from the driver. I dont know whether the one I about to point out can or not and also I dont know if the Registry Hives would have been built by the time your boot driver is accessing it. But this is also a possible way.
HKLM\HARDWARE\RESOURCEMAP\System Resources\Physical Memory after you go there double click on Translated, highlight the Bus Number Interface Type line and then click on Display. In the memory column add up the length. Can this done programatically? I dont know.
regards
anand

Prokash Sinha wrote:

Temporal Need:: On a PEA or 64bit system I would want to know what
is the total amount of physical memory OS thinks it has.

ZwQuerySystemInformation is one option using SystemBasicInformation,
but I don’t think it is a document DDI !

If I see system has (let say) more than 32GB , I would like to make
the DMA interface tobe 32bit

Why? That’s an odd requirement. If your hardware can’t handle 64-bit
addresses, then your problems start at the 4GB mark, not the 32GB mark.


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

Yes it is odd. I will find it soon, why there is such a restriction ( from
the HW point of view ).

-pro

On 9/28/07, Tim Roberts wrote:
>
> Prokash Sinha wrote:
> > Temporal Need:: On a PEA or 64bit system I would want to know what
> > is the total amount of physical memory OS thinks it has.
> >
> > ZwQuerySystemInformation is one option using SystemBasicInformation,
> > but I don’t think it is a document DDI !
> >
> > If I see system has (let say) more than 32GB , I would like to make
> > the DMA interface tobe 32bit
>
> Why? That’s an odd requirement. If your hardware can’t handle 64-bit
> addresses, then your problems start at the 4GB mark, not the 32GB mark.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

You might see if the registry key
HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory is
available early enough. I know only the system hive is loaded from disk by
ntldr, but HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP I thought was dynamically
built (there is no HARDWARE hive file), so this key may have been populated
by the time you need it.

Jan


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Prokash Sinha
Sent: Thursday, September 27, 2007 9:24 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to find Physical Memory size from a boot time driver ?

Temporal Need:: On a PEA or 64bit system I would want to know what is the
total amount of physical memory OS thinks it has.

ZwQuerySystemInformation is one option using SystemBasicInformation, but I
don’t think it is a document DDI !

If I see system has (let say) more than 32GB , I would like to make the DMA
interface tobe 32bit ( not worried about double buffering or transperant
bounce buffering performance hit at this time as well as any possbile data
corruption due to DAC related issues). Also the virtual memory assoicated
with these physical host addresses are not in my control ( in other words it
is not my allocation so I can not specify what is absolute highest physical
address I would like to have for these allocation).

I can not use the win32 WAE interface, since it is boot time.

Thx

-pro


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer