XilinxProcessorIPLib/drivers/aiengine/src/lib/ext/xaieio.c
XAieIO_Mem *XAieIO_MemAllocate(uint64_t Size, u32 Attr)
{
	XAieIO_Mem *IO_MemInstPtr;
	char shm_name[32];
	unsigned int id, flag = 0;
	int ret;

	id = metal_bitmap_next_clear_bit(IOInst.shm_ids, 0, SHM_MAX_IDS);
	if (id >= SHM_MAX_IDS) {
		goto err_out;
	}

	XAieIO_Init();

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

	/* The name, ion.reserved, and snprintf() are linux specific */
	snprintf(shm_name, sizeof(shm_name), "ion.reserved/shm%d", id);
	if (!(Attr & XAIELIB_MEM_ATTR_CACHE)) {
		flag = METAL_SHM_NOTCACHED;
	}
	ret = metal_shmem_open(shm_name, Size, flag, &IO_MemInstPtr->shm);
	if (ret) {
		goto free_mem_inst;
	}

	IO_MemInstPtr->sg = metal_shm_attach(IO_MemInstPtr->shm, IOInst.device,
			METAL_SHM_DIR_DEV_RW);
	if (!IO_MemInstPtr->sg) {
		goto shm_close;
	}

	IO_MemInstPtr->io = IO_MemInstPtr->sg->ios;
	IO_MemInstPtr->io_base = metal_io_phys(IO_MemInstPtr->sg->ios, 0);
	IO_MemInstPtr->id = id;
	metal_bitmap_set_bit(IOInst.shm_ids, id);

	return IO_MemInstPtr;

shm_close:
	metal_shmem_close(IO_MemInstPtr->shm);
free_mem_inst:
	metal_free_memory(IO_MemInstPtr);
io_finish:
	XAieIO_Finish();
err_out:
	return NULL;
}
/*****************************************************************************/
/**
*
* This is the IO memory function to allocate a memory
*
* @param	Size: Size of the memory
* @param	Attr: Any of XAIELIB_MEM_ATTR_*
*
* @return	Pointer to the allocated IO memory instance.
*
* @note		None.
*
*******************************************************************************/
This is the IO memory function to allocate a memory
This is the IO memory function to allocate a memory
XAieIO_Mem *XAieIO_MemAllocate(uint64_t Size, u32 Attr)
{
	XAieIO_Mem *IO_MemInstPtr;
	char shm_name[32];
	unsigned int id, flag = 0;
	int ret;
	id = metal_bitmap_next_clear_bit(IOInst.shm_ids, 0, SHM_MAX_IDS);
	if (id >= SHM_MAX_IDS) {
		goto err_out;
	}
	XAieIO_Init();
	IO_MemInstPtr = metal_allocate_memory(sizeof(*IO_MemInstPtr));
	if (!IO_MemInstPtr) {
		goto io_finish;
	}
	snprintf(shm_name, sizeof(shm_name), "ion.reserved/shm%d", id);
	if (!(Attr & XAIELIB_MEM_ATTR_CACHE)) {
		flag = METAL_SHM_NOTCACHED;
	}
	ret = metal_shmem_open(shm_name, Size, flag, &IO_MemInstPtr->shm);
	if (ret) {
		goto free_mem_inst;
	}
	IO_MemInstPtr->sg = metal_shm_attach(IO_MemInstPtr->shm, IOInst.device,
			METAL_SHM_DIR_DEV_RW);
	if (!IO_MemInstPtr->sg) {
		goto shm_close;
	}
	IO_MemInstPtr->io = IO_MemInstPtr->sg->ios;
	IO_MemInstPtr->io_base = metal_io_phys(IO_MemInstPtr->sg->ios, 0);
	IO_MemInstPtr->id = id;
	metal_bitmap_set_bit(IOInst.shm_ids, id);
	return IO_MemInstPtr;
shm_close:
	metal_shmem_close(IO_MemInstPtr->shm);
free_mem_inst:
	metal_free_memory(IO_MemInstPtr);
io_finish:
	XAieIO_Finish();
err_out:
	return NULL;
}
XAieIO_Mem * XAieIO_MemAllocate ( uint64_t Size , u32 Attr ) { XAieIO_Mem * IO_MemInstPtr ; char shm_name [ 32 ] ; unsigned int id , flag = 0 ; int ret ; id = metal_bitmap_next_clear_bit ( IOInst . shm_ids , 0 , SHM_MAX_IDS ) ; if ( id >= SHM_MAX_IDS ) { goto err_out ; } XAieIO_Init ( ) ; IO_MemInstPtr = metal_allocate_memory ( sizeof ( * IO_MemInstPtr ) ) ; if ( ! IO_MemInstPtr ) { goto io_finish ; } snprintf ( shm_name , sizeof ( shm_name ) , " " , id ) ; if ( ! ( Attr & XAIELIB_MEM_ATTR_CACHE ) ) { flag = METAL_SHM_NOTCACHED ; } ret = metal_shmem_open ( shm_name , Size , flag , & IO_MemInstPtr -> shm ) ; if ( ret ) { goto free_mem_inst ; } IO_MemInstPtr -> sg = metal_shm_attach ( IO_MemInstPtr -> shm , IOInst . device , METAL_SHM_DIR_DEV_RW ) ; if ( ! IO_MemInstPtr -> sg ) { goto shm_close ; } IO_MemInstPtr -> io = IO_MemInstPtr -> sg -> ios ; IO_MemInstPtr -> io_base = metal_io_phys ( IO_MemInstPtr -> sg -> ios , 0 ) ; IO_MemInstPtr -> id = id ; metal_bitmap_set_bit ( IOInst . shm_ids , id ) ; return IO_MemInstPtr ; shm_close : metal_shmem_close ( IO_MemInstPtr -> shm ) ; free_mem_inst : metal_free_memory ( IO_MemInstPtr ) ; io_finish : XAieIO_Finish ( ) ; err_out : return NULL ; }
This is the IO memory function to allocate a memory
This is the IO memory function to allocate a memory
/* The name, ion.reserved, and snprintf() are linux specific */