Re: How To?: Kernel Memory Mapped to User Space
Re: How To?: Kernel Memory Mapped to User Space
- Subject: Re: How To?: Kernel Memory Mapped to User Space
- From: Andrew Gallatin <email@hidden>
- Date: Thu, 6 Jun 2002 22:08:57 -0400 (EDT)
Scott Taggart writes:
>
yea, but that does not satisfy my requirements:
>
>
1) My driver have the buffer available before any apps start
>
2) The buffer be persistent when apps come and go.
>
>
Maybe something is far easier, but it is not of use if it doesn't meet the
>
requirements. So, is what I ask for doable or not?
We do the following to map a few pages of board memory (memory mapped
PCI) to user space. It should work for normal physical memory I
think. "kva" is the kernel virtual address we are mapping out to user
space. Bounds checking, etc, is omitted so you can just see the calls
you need:
md = IOMemoryDescriptor::withAddress (kva, len, kIODirectionOutIn);
if (!md)
{
IOLog ("IOMemoryDescriptor::withAddress failed for %p len %d\n",
kva, len);
goto abort_with_entry;
}
/* create a region len bytes long in this process's address space */
user_map = md->map (current_task(), (unsigned int) 0, kIOMapAnywhere, 0, len);
if (!user_map)
{
IOLog ("IOMemoryDescriptor::withAddress failed for %p len %d\n",
kva, len);
goto abort_with_md;
}
va = (void *) user_map->getVirtualAddress ();
copyout (&va, arg, sizeof (va) != 0)
{
goto abort_with_user_map;
}
Then we save off md and user_map. When the application closes our
device or exits, we do:
user_map->unmap ();
user_map->release ();
md->release ();
I hope this helps,
Drew
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.