Greetings,
You need to prepare() before getting the physical or virtual
addresses. The act of preparing the memory is likely to move the
memory in physically and may alter the virtual address as well.
Here's some of the code I've done for this:
desc = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,
kIOMemoryPhysicallyContiguous, 8192, 8192);
if (desc) {
map = desc->map(kIOMapInhibitCache);
desc->prepare(kIODirectionInOut);
vbase = map->getVirtualAddress();
pbase = map->getPhysicalAddress();
} else
return false;
It's also worth noting that if the size of memory you are allocating
is larger than 1 VM page (4KB) then you must be aware that the OS
does not guarantee alignment of the physical address. The docs don't
(or didn't when I was working on this) say this explicitly, but the
alignment parameter only applies to the virtual address. (This lame,
but that's what is provided.)
You must handle physical alignment yourself by allocating extra
memory and using part of that to get any physical alignment you need.
Good luck and I'm happy to help further!
-Mike
On Nov 25, 2005, at 10:01 AM, Locatelli Jérôme wrote:
> Hello, does anybody can help me ?
>
> I try to get work a dma transfert in a pci-vme card. But it crashes
> computer.
>
> This is a summary:
>
> 1) I create a buffer for receving or sending data :
>
> mem = IOBufferMemoryDescriptor::inTaskWithOptions
> (kernel_task,kIOMemoryPhysicallyContiguous,DMA_MAX_SIZE,
> BIT3_PAGE_LEN);
>
> 2) I give physical segment to a register of pci-vme card:
>
> pa_org = mem->getPhysicalAddress();
> for(i = 0;i < n_windows;i++) {
> pa = pa_org + i*BIT3_PAGE_LEN;
> // Writing physical address to special register in the card
> val = DMAREG(pa,0,0);
> fBit3PCI->ioWrite32(MR_DMA_PCI + 4 * i, val,mapping_registers_base);
> }
>
> 3) I prepare memory
>
> if (READ) {
> // wire it and make sure we can write it
> err = mem->prepare(kIODirectionIn);
> if( kIOReturnSuccess != err) {
> IOLog("IOBufferDescriptor::prepare failed(%x)\n", err);
> goto fin;
> }
> }
> else {
> // wire it and make sure we can write it
> err = mem->prepare(kIODirectionOut);
> if( kIOReturnSuccess != err) {
> IOLog("IOBufferDescriptor::prepare failed(%x)\n", err);
> goto fin;
> }
> }
>
> 4) start dma processing on pci-vme card, and I see tranfert from
> the VME bus started but,
>
> the computer become completly fixed
>
>
>
> What can be wrong in that???
>
>
> Thanks for help.
>
> ---------------------------------------------------
> Locatelli Jérôme
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list (
Darwin-drivers@list...)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/subscriber%40opensubscriber.com
This email sent to subscriber@opensubscriber.c
opensubscriber is not affiliated with the authors of this message nor responsible for its content.