XilinxProcessorIPLib/drivers/aiengine/src/lib/ext/xaieio.c
XAieIO_Mem *XAieIO_MemAttach(uint64_t Vaddr, uint64_t Paddr, uint64_t Size,
		uint64_t MemHandle)
{
	XAieIO_Mem *IO_MemInstPtr;

	XAieIO_Init();

	IO_MemInstPtr = metal_allocate_memory(sizeof(*IO_MemInstPtr));
	if (!IO_MemInstPtr) {
		goto io_finish;
	}

	IO_MemInstPtr->shm = metal_allocate_memory(sizeof(*IO_MemInstPtr->shm));
	if (!IO_MemInstPtr->shm) {
		goto free_mem_inst;
	}
	metal_list_init(&IO_MemInstPtr->shm->refs);
	metal_mutex_init(&IO_MemInstPtr->shm->lock);

	/*
	 * FIXME: dummy allocate to retreive the dmabuf ops. This can be
	 * removed if libemtal allows to attach the dmabuf ops to shm object
	 * allocated outside.
	 */
	IO_MemInstPtr->shm->provider = metal_shmem_get_provider("ion.reserved");
	IO_MemInstPtr->shm->provider->alloc(IO_MemInstPtr->shm->provider,
			IO_MemInstPtr->shm, 1);
	IO_MemInstPtr->shm->provider->free(IO_MemInstPtr->shm->provider,
			IO_MemInstPtr->shm);

	/* Expect the dmabuf fd as a handle*/
	IO_MemInstPtr->shm->id = MemHandle;
	IO_MemInstPtr->shm->size = Size;
	IO_MemInstPtr->sg = metal_shm_attach(IO_MemInstPtr->shm, IOInst.device,
			METAL_SHM_DIR_DEV_RW);
	if (!IO_MemInstPtr->sg) {
		goto free_shm;
	}

	/* This can be cross-checked if it matches as given argument */
	IO_MemInstPtr->io_base = metal_io_phys(IO_MemInstPtr->sg->ios, 0);
	IO_MemInstPtr->io = IO_MemInstPtr->sg->ios;

	return IO_MemInstPtr;

free_shm:
	metal_free_memory(IO_MemInstPtr->shm);
free_mem_inst:
	metal_free_memory(IO_MemInstPtr);
io_finish:
	XAieIO_Finish();
	return NULL;
}
/*****************************************************************************/
/**
*
* This is the IO memory function to attach the external memory to device
*
* @param	Vaddr: Optional. Vaddr of the memory
* @param	Paddr: Optional. Paddr of the memory
* @param	Size: Required. Size of the memory
* @param	MemHandle: Required. Handle of the memory. For linux, dmabuf fd
*
* @return	Pointer to the attached IO memory instance.
*
* @note		None.
*
*******************************************************************************/
This is the IO memory function to attach the external memory to device
This is the IO memory function to attach the external memory to device
XAieIO_Mem *XAieIO_MemAttach(uint64_t Vaddr, uint64_t Paddr, uint64_t Size,
		uint64_t MemHandle)
{
	XAieIO_Mem *IO_MemInstPtr;
	XAieIO_Init();
	IO_MemInstPtr = metal_allocate_memory(sizeof(*IO_MemInstPtr));
	if (!IO_MemInstPtr) {
		goto io_finish;
	}
	IO_MemInstPtr->shm = metal_allocate_memory(sizeof(*IO_MemInstPtr->shm));
	if (!IO_MemInstPtr->shm) {
		goto free_mem_inst;
	}
	metal_list_init(&IO_MemInstPtr->shm->refs);
	metal_mutex_init(&IO_MemInstPtr->shm->lock);
	IO_MemInstPtr->shm->provider = metal_shmem_get_provider("ion.reserved");
	IO_MemInstPtr->shm->provider->alloc(IO_MemInstPtr->shm->provider,
			IO_MemInstPtr->shm, 1);
	IO_MemInstPtr->shm->provider->free(IO_MemInstPtr->shm->provider,
			IO_MemInstPtr->shm);
	IO_MemInstPtr->shm->id = MemHandle;
	IO_MemInstPtr->shm->size = Size;
	IO_MemInstPtr->sg = metal_shm_attach(IO_MemInstPtr->shm, IOInst.device,
			METAL_SHM_DIR_DEV_RW);
	if (!IO_MemInstPtr->sg) {
		goto free_shm;
	}
	IO_MemInstPtr->io_base = metal_io_phys(IO_MemInstPtr->sg->ios, 0);
	IO_MemInstPtr->io = IO_MemInstPtr->sg->ios;
	return IO_MemInstPtr;
free_shm:
	metal_free_memory(IO_MemInstPtr->shm);
free_mem_inst:
	metal_free_memory(IO_MemInstPtr);
io_finish:
	XAieIO_Finish();
	return NULL;
}
XAieIO_Mem * XAieIO_MemAttach ( uint64_t Vaddr , uint64_t Paddr , uint64_t Size , uint64_t MemHandle ) { XAieIO_Mem * IO_MemInstPtr ; XAieIO_Init ( ) ; IO_MemInstPtr = metal_allocate_memory ( sizeof ( * IO_MemInstPtr ) ) ; if ( ! IO_MemInstPtr ) { goto io_finish ; } IO_MemInstPtr -> shm = metal_allocate_memory ( sizeof ( * IO_MemInstPtr -> shm ) ) ; if ( ! IO_MemInstPtr -> shm ) { goto free_mem_inst ; } metal_list_init ( & IO_MemInstPtr -> shm -> refs ) ; metal_mutex_init ( & IO_MemInstPtr -> shm -> lock ) ; IO_MemInstPtr -> shm -> provider = metal_shmem_get_provider ( " " ) ; IO_MemInstPtr -> shm -> provider -> alloc ( IO_MemInstPtr -> shm -> provider , IO_MemInstPtr -> shm , 1 ) ; IO_MemInstPtr -> shm -> provider -> free ( IO_MemInstPtr -> shm -> provider , IO_MemInstPtr -> shm ) ; IO_MemInstPtr -> shm -> id = MemHandle ; IO_MemInstPtr -> shm -> size = Size ; IO_MemInstPtr -> sg = metal_shm_attach ( IO_MemInstPtr -> shm , IOInst . device , METAL_SHM_DIR_DEV_RW ) ; if ( ! IO_MemInstPtr -> sg ) { goto free_shm ; } IO_MemInstPtr -> io_base = metal_io_phys ( IO_MemInstPtr -> sg -> ios , 0 ) ; IO_MemInstPtr -> io = IO_MemInstPtr -> sg -> ios ; return IO_MemInstPtr ; free_shm : metal_free_memory ( IO_MemInstPtr -> shm ) ; free_mem_inst : metal_free_memory ( IO_MemInstPtr ) ; io_finish : XAieIO_Finish ( ) ; return NULL ; }
This is the IO memory function to attach the external memory to device
This is the IO memory function to attach the external memory to device
/*
	 * FIXME: dummy allocate to retreive the dmabuf ops. This can be
	 * removed if libemtal allows to attach the dmabuf ops to shm object
	 * allocated outside.
	 */ /* Expect the dmabuf fd as a handle*/ /* This can be cross-checked if it matches as given argument */