Пример #1
0
void *pci_alloc_consistent(void *pdev, size_t size, dma_addr_t *dma_handle)
{
	IOBufferMemoryDescriptor    *memDesc;
	IOVirtualAddress            virt_address;
	IOPhysicalAddress           phys_address;

	// construct a memory descriptor for a buffer below the 4Gb line,
	// addressable by 32 bit DMA and page aligned.
	memDesc = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,
		kIOMemoryPhysicallyContiguous, size, PAGE_SIZE);
	if (memDesc) {
		IOByteCount		offset = 0;
		IOByteCount		length;

		memDesc->prepare();
		virt_address = (IOVirtualAddress)memDesc->getBytesNoCopy();
		phys_address = memDesc->getPhysicalSegment(offset, &length);

		g_bcm_dma_info->setObject(memDesc);
	} else {
		virt_address = NULL;
		phys_address = NULL;
		IOLog("pci_alloc_consistent:IOBufferMemoryDescriptor::inTaskWithOptions failed\n");
	}

	//IOLog("pci_alloc_consistent paddr(0x%X), size(0x%X)\n", (unsigned int)phys_address, size);
	*dma_handle = phys_address;
	return (void*)virt_address;
}
Пример #2
0
bool AppleMacIO::selfTest( void )
{
    IODBDMADescriptor			*dmaDescriptors;
    UInt32				dmaDescriptorsPhys;
    UInt32				i;
    UInt32				status;
    IODBDMADescriptor			*dmaDesc;
    IOBufferMemoryDescriptor		*buffer;
    volatile IODBDMAChannelRegisters	*ioBaseDMA;
    bool				ok = false;
    enum { 				kTestChannel = 0x8000 };

    ioBaseDMA = (volatile IODBDMAChannelRegisters *)
		(((UInt32)fMemory->getVirtualAddress())
		+ kTestChannel );

    do {
	buffer = IOBufferMemoryDescriptor::withCapacity(page_size, kIODirectionOutIn, true);
	dmaDescriptors = (IODBDMADescriptor*)buffer->getBytesNoCopy();

        if (!dmaDescriptors)
	    continue;

        if ( (UInt32)dmaDescriptors & (page_size - 1) ) {
            IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__);
	    continue;
        }

        bzero( dmaDescriptors, page_size );

        IODBDMAReset( ioBaseDMA );

        dmaDesc = dmaDescriptors;

        IOMakeDBDMADescriptor( dmaDesc,
                            kdbdmaNop,
                            kdbdmaKeyStream0,
                            kdbdmaIntNever,
                            kdbdmaBranchNever,
                            kdbdmaWaitNever,
                            0,
                            0 );

        dmaDesc++;

	dmaDescriptorsPhys = (UInt32) (buffer->getPhysicalSegment(0, NULL, 0));

        IOMakeDBDMADescriptorDep( dmaDesc,
                                kdbdmaStoreQuad,
                                kdbdmaKeySystem,
                                kdbdmaIntNever,
                                kdbdmaBranchNever,
                                kdbdmaWaitNever,
                                4,
                                dmaDescriptorsPhys+16*sizeof(IODBDMADescriptor),
                                0x12345678 );

        dmaDesc++;

        IOMakeDBDMADescriptor( dmaDesc,
                            kdbdmaStop,
                            kdbdmaKeyStream0,
                            kdbdmaIntNever,
                            kdbdmaBranchNever,
                            kdbdmaWaitNever,
                            0,
                            0 );


        for ( i = 0; (!ok) && (i < 3); i++ )
        {
            dmaDescriptors[16].operation = 0;

            IOSetDBDMACommandPtr( ioBaseDMA, dmaDescriptorsPhys );
            IODBDMAContinue( ioBaseDMA );

            IODelay( 200 );

            status = IOGetDBDMAChannelStatus( ioBaseDMA );

            if ( ((status & kdbdmaActive) == 0)
                &&  ((status & kdbdmaDead) == 0)
                    && (OSReadSwapInt32( &dmaDescriptors[16].operation, 0 ) == 0x12345678 ))
                ok = true;
        }

        IODBDMAReset( ioBaseDMA );

    } while (false);

    if (buffer)
	    buffer->release();

    return ok;
}