Hi,
I’m making up an MDL by hand, using it to contain pages allocated
by AllocateCommonBuffer. I allocate the common buffer a page at a
time and I’m stuffing the information into an MDL preallocated to
be big enough. I create the main mdl like so:
mdl = IoAllocateMdl(0, frame_size, FALSE, FALSE, 0);
where frame_size is the size in bytes of the region, and is a multiple
of PAGE_SIZE. I then allocate, in a loop, the target page from
AllocateCommonBuffer (non-cached), and I make up the PFN for the
preallocated MDL like so:
mtmp = IoAllocateMdl(page_vrt, PAGE_SIZE, FALSE, FALSE, 0);
MmGetMdlPfnArray(mdl) [idx] = MmGetMdlPfnArray(mtmp) [0];
IoFreeMdl(mtmp);
(page_vrt) is the “virtual” address from AllocateCommonBuffer.)
Finally, I fix up the constructed MDL like so:
mdl->MdlFlags |= MDL_ALLOCATED_FIXED_SIZE;
mdl->MdlFlags |= MDL_PAGES_LOCKED;
mdl->MdlFlags |= MDL_SOURCE_IS_NONPAGED_POOL;
I use this mdl as an argument to MmMapLockedPagesSpecifyCache to
make these pages available to UserMode, and it generally seems to
work perfectly. As intended, the device and the usermode application
now share this memory.
Is there any reason to believe this is wrong? I’m wondering if this
may be influencing my other topic on this list, Re: MmMapLockedPages…
One thing I would question, the Mdl structure is ‘suppose’ to be opaque.
Therefore by setting the flags that you do manually, may lead to
assumptions with particular calls made by the system that are invalid
due to how the Mdl was created.
Maybe someone else can clarify whether setting the MDL_xxx flags
manually is ‘ok’.
Pete
Peter Scott
xxxxx@KernelDrivers.com
http://www.KernelDrivers.com
>-----Original Message-----
>From: xxxxx@lists.osr.com [mailto:bounce-ntdev-
>xxxxx@lists.osr.com] On Behalf Of Stephen Williams
>Sent: Thursday, June 20, 2002 11:28 AM
>To: NT Developers Interest List
>Subject: [ntdev] Details of making MDLs
>
>
>Hi,
>
>I’m making up an MDL by hand, using it to contain pages allocated
>by AllocateCommonBuffer. I allocate the common buffer a page at a
>time and I’m stuffing the information into an MDL preallocated to
>be big enough. I create the main mdl like so:
>
> mdl = IoAllocateMdl(0, frame_size, FALSE, FALSE, 0);
>
>where frame_size is the size in bytes of the region, and is a multiple
>of PAGE_SIZE. I then allocate, in a loop, the target page from
>AllocateCommonBuffer (non-cached), and I make up the PFN for the
>preallocated MDL like so:
>
> mtmp = IoAllocateMdl(page_vrt, PAGE_SIZE, FALSE, FALSE, 0);
> MmGetMdlPfnArray(mdl) [idx] = MmGetMdlPfnArray(mtmp) [0];
> IoFreeMdl(mtmp);
>
> (page_vrt) is the “virtual” address from
AllocateCommonBuffer.)
>
>Finally, I fix up the constructed MDL like so:
>
> mdl->MdlFlags |= MDL_ALLOCATED_FIXED_SIZE;
> mdl->MdlFlags |= MDL_PAGES_LOCKED;
> mdl->MdlFlags |= MDL_SOURCE_IS_NONPAGED_POOL;
>
>I use this mdl as an argument to MmMapLockedPagesSpecifyCache to
>make these pages available to UserMode, and it generally seems to
>work perfectly. As intended, the device and the usermode application
>now share this memory.
>
>Is there any reason to believe this is wrong? I’m wondering if this
>may be influencing my other topic on this list, Re:
MmMapLockedPages…
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@KernelDrivers.com
>To unsubscribe send a blank email to %%email.unsub%%
xxxxx@KernelDrivers.com said:
One thing I would question, the Mdl structure is ‘suppose’ to be
opaque.
I got this from one of the MicroSoft mapping examples:
src\kernel\agp\agplib\intrface.c
I use IoAllocateMdl instead of MmCreateMdl.
Steve Williams “The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
steve at picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”
abuse@xo.com
xxxxx@ftc.gov
Modifying the MDL flags directly is not a good idea. Have you thought about
allocating the pages in user mode and locking them in the kernel ? That’s a
much better approach.
–
This posting is provided “AS IS” with no warranties, and confers no rights.
“Stephen Williams” wrote in message news:xxxxx@ntdev…
>
>
> xxxxx@KernelDrivers.com said:
> > One thing I would question, the Mdl structure is ‘suppose’ to be
> > opaque.
>
> I got this from one of the MicroSoft mapping examples:
> src\kernel\agp\agplib\intrface.c
>
> I use IoAllocateMdl instead of MmCreateMdl.
> –
> Steve Williams “The woods are lovely, dark and deep.
> steve at icarus.com But I have promises to keep,
> steve at picturel.com and lines to code before I sleep,
> http://www.picturel.com And lines to code before I sleep.”
>
> abuse@xo.com
> xxxxx@ftc.gov
>
>
>
>
xxxxx@windows.microsoft.com said:
Modifying the MDL flags directly is not a good idea. Have you thought
about allocating the pages in user mode and locking them in the kernel
? That’s a much better approach.
Then issues of high memory come up. The memory is to be shared with
a PCI device, and using AllocateCommonBuffer assures that it is
pulled from memory accessible to the PCI device, as well as getting
the addresses for both the processor and the device right.
Steve Williams “The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
steve at picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”
abuse@xo.com
xxxxx@ftc.gov
In that case you can do something like this. You get a virtual address from
HalAllocateCommonBuffer. You should use that to build the MDL (instead of
filling the PFN’s directly). You could use code like the one below.
mdl = IoAllocateMdl(va , length, FALSE, TRUE, NULL);
if (!mdl) {
return STATUS_INSUFFICIENT_RESOURCES;
}
MmBuildMdlForNonPagedPool(mdl);
UserModeBase = MmMapLockedPagesSpecifyCache(mdl,
UserMode,
MmNonCached,
NULL,
FALSE,
LowPagePriority);
if (UserModeBase == NULL) {
IoFreeMdl(mdl);
return STATUS_INSUFFICIENT_RESOURCES;
}
–
This posting is provided “AS IS” with no warranties, and confers no rights.
“Stephen Williams” wrote in message news:xxxxx@ntdev…
>
>
> xxxxx@windows.microsoft.com said:
> > Modifying the MDL flags directly is not a good idea. Have you thought
> > about allocating the pages in user mode and locking them in the kernel
> > ? That’s a much better approach.
>
> Then issues of high memory come up. The memory is to be shared with
> a PCI device, and using AllocateCommonBuffer assures that it is
> pulled from memory accessible to the PCI device, as well as getting
> the addresses for both the processor and the device right.
> –
> Steve Williams “The woods are lovely, dark and deep.
> steve at icarus.com But I have promises to keep,
> steve at picturel.com and lines to code before I sleep,
> http://www.picturel.com And lines to code before I sleep.”
>
> abuse@xo.com
> xxxxx@ftc.gov
>
>
>
>