CeSetMemoryAttributes (Windows CE 5.0)

Send Feedback

This function provides device drivers and applications with a way to use memory attributes supported on some hardware platforms that the kernel does not support by default.

BOOLCeSetMemoryAttributes( LPVOID pVirtualAddr,LPVOID pShiftedPhysAddr,DWORD cbSize,DWORD dwAttributes);

Parameters

  • pVirtualAddr
    [in] Beginning virtual memory address.

    The memory address must be page aligned.

  • pShiftedPhysAddr
    [in] Corresponding physical memory address shifted by 8 bits or PHYSICAL_ADDRESS_UNKNOWN.

    If the value of this parameter is not set to PHYSICAL_ADDRESS_UNKNOWN, the physical address, which is pShiftedPhysAddr<<8, must be page aligned.

    Also, the range specified must be physically contiguous, which means that the range (pVirtualAddr -> pVirtualAddr + cbSize) must be mapped to (pPhysAddr -> pPhysAddr + cbSize).

  • cbSize
    [in] Size, in bytes, of the memory to be changed.

    The size must be in multiple of pages.

  • dwAttributes
    [in] Memory attribute to be set.

    Only PAGE_WRITECOMBINE is supported. Write-combining allows bus write transfers to be combined into a larger transfer before bursting.

Return Values

Nonzero indicates success.

Zero indicates failure.

To get extended error information, call GetLastError.

Remarks

The current support for memory attributes in the VirtualSetAttributes function is not generic enough that it requires #ifdef tags and queries to the OAL for drivers or applications to use these attributes.

CeSetMemoryAttributes is platform independent so driver developers and application developers can include this function in their code regardless of the platform.

Keep the following points in mind when using CeSetMemoryAttributes:

  • CeSetMemoryAttributes is a trusted API. For more information, see Trusted APIs.
  • This function is one-way, which means that after the attribute is set, it cannot be unset.

Some x86 CPUs, such as the x86 with PAT support, do not require the physical address to support write-combine; other CPUs require contiguous physical address such as the x86 with MTRR support. Microsoft recommends that driver developers and application developers call CeSetMemoryAttributes with a valid pShiftedPhysAddr if the range of physical address is known so that it works on either x86 CPUs.

The following code example shows an implementation of CeSetMemoryAttributes within a typical display driver code.

#define FRAMEBUFFER_PHYSADDR   0xdc000000   // Physical address of the frame buffer
#define FRAMEBUFFER_SIZE   0x00400000       // 4M of frame buffer

LPVOID InitFrameBuffer ()
{
   // Allocate and set up the frame buffer
   LPVOID pVirtualAddr = VirtualAlloc (NULL, FRAMEBUFFER_SIZE, MEM_RESERVE, PAGE_NOACCESS);
   if (!pVirtualAddr) {
      return NULL;
   }
   if (!VirtualCopy (pVirtualAddr, (LPVOID) (FRAMEBUFFER_PHYSADDR >> 8), FRAMEBUFFER_SIZE, PAGE_NOCACHE|PAGE_READWRITE)) {
      // Error
      VirtualFree (pVirtualAddr, 0, MEM_RELEASE);
      return NULL;
   }

   // Try to set 'Write-Combine' attribute on the frame buffer.
   // It does not matter if it succeeds or not.
   CeSetMemoryAttributes (pVirtualAddr, (LPVOID) (FRAMEBUFFER_PHYSADDR >> 8), FRAMEBUFFER_SIZE, PAGE_WRITECOMBINE);

   return pVirtualAddr;
}

Requirements

OS Versions: Windows CE 5.0 and later.
Header: Pkfuncs.h.
Link Library: Coredll.lib.

See Also

VirtualSetAttributes | pfnOEMSetMemoryAttributes

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.