Exemplo n.º 1
0
/* 
 * HMCSIM_ALLOCATE_MEMORY
 * 
 */
extern int	hmcsim_allocate_memory( struct hmcsim_t *hmc )
{
	if( hmc == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "HMC STRUCTURE IS NULL" );
#endif
		return -1;
	}

	hmc->__ptr_devs	= malloc( sizeof( struct hmc_dev_t ) * hmc->num_devs );
	if( hmc->__ptr_devs == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_devs" );
#endif
		return -1;
	}

	hmc->__ptr_quads = malloc( sizeof( struct hmc_quad_t ) * hmc->num_devs * hmc->num_quads );
	if( hmc->__ptr_quads == NULL ) { 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_quads" );
#endif
		return -1;
	}

	hmc->__ptr_vaults = malloc( sizeof( struct hmc_vault_t ) * hmc->num_devs * hmc->num_vaults );
	if( hmc->__ptr_vaults == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_vaults" );
#endif
		return -1;
	}

	hmc->__ptr_dres = malloc( sizeof( struct hmc_dre_t ) * hmc->num_devs * hmc->num_dres );
	if( hmc->__ptr_dres == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_dres" );
#endif
		return -1;
	}	

	hmc->__ptr_banks = malloc( sizeof( struct hmc_bank_t ) 
					* hmc->num_devs * hmc->num_vaults * hmc->num_banks );
	if( hmc->__ptr_banks == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_banks" );
#endif
		return -1;
	}

	hmc->__ptr_drams = malloc( sizeof( struct hmc_dram_t ) 
					* hmc->num_devs * hmc->num_vaults * hmc->num_banks 
					* hmc->num_drams );
	if( hmc->__ptr_drams == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_drams" );
#endif
		return -1;
	}

	hmc->__ptr_links = malloc( sizeof( struct hmc_link_t ) * hmc->num_devs * hmc->num_links );
	if( hmc->__ptr_links == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_links" );
#endif
		return -1;
	}

	hmc->__ptr_xbars = malloc( sizeof( struct hmc_xbar_t ) * hmc->num_devs * hmc->num_links );
	if( hmc->__ptr_xbars == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_xbars" );
#endif
		return -1;
	}

#if 0
	hmc->__ptr_stor = malloc( sizeof( uint64_t ) * hmc->num_devs * hmc->capacity * HMC_1GB );
	if( hmc->__ptr_stor == NULL ){ 
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_stor" );
#endif
		return -1;
	}
#endif

	hmc->__ptr_xbar_rqst = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs 
								* hmc->xbar_depth 
								* hmc->num_links );
	if( hmc->__ptr_xbar_rqst == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_xbar_rqst" );
#endif
		return -1;
	}

	hmc->__ptr_xbar_rsp = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs 
								* hmc->xbar_depth 
								* hmc->num_links );
	if( hmc->__ptr_xbar_rsp == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_xbar_rsp" );
#endif
		return -1;
	}


	hmc->__ptr_vault_rqst = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs * hmc->num_vaults * hmc->queue_depth );
	if( hmc->__ptr_vault_rqst == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_vault_rqst" );
#endif
		return -1;
	}

	hmc->__ptr_vault_rsp = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs * hmc->num_vaults * hmc->queue_depth );
	if( hmc->__ptr_vault_rsp == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_vault_rsp" );
#endif
		return -1;
	}

	hmc->__ptr_dre_rqst = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs * hmc->num_dres * hmc->dre_depth);
	if( hmc->__ptr_dre_rqst == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_dre_rqst" );
#endif
		return -1;
	}

	hmc->__ptr_dre_rsp = malloc( sizeof( struct hmc_queue_t ) * hmc->num_devs * hmc->num_dres * hmc->dre_depth);
	if( hmc->__ptr_dre_rsp == NULL ){
#ifdef HMC_DEBUG
                HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE __ptr_dre_rsp" );
#endif
		return -1;
	}	

	return 0;
}
Exemplo n.º 2
0
/* 
 * HMCSIM_INIT
 * 
 */
extern int hmcsim_init(	struct hmcsim_t *hmc, 
			uint32_t num_devs, 
			uint32_t num_links, 
			uint32_t num_vaults, 
			uint32_t queue_depth,
			uint32_t num_banks, 
			uint32_t num_drams, 
			uint32_t capacity, 
			uint32_t xbar_depth )
{
	/* vars */
	uint32_t i	= 0;
	/* ---- */

	/*
	 * ensure we have a good structure
	 * 
	 */
	if( hmc == NULL ){ 
		return -1;
	}

	/* 
	 * sanity check the args 
	 *
	 */	
	if( (num_devs > HMC_MAX_DEVS) || (num_devs < 1) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_links < HMC_MIN_LINKS) || (num_links > HMC_MAX_LINKS) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_vaults < HMC_MIN_VAULTS) || (num_vaults > HMC_MAX_VAULTS) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_banks < HMC_MIN_BANKS) || (num_banks > HMC_MAX_BANKS) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_drams < HMC_MIN_DRAMS) || (num_drams > HMC_MAX_DRAMS) ){ 
		return HMC_ERROR_PARAMS;
	}else if( (capacity < HMC_MIN_CAPACITY) || (capacity > HMC_MAX_CAPACITY) ){
		return HMC_ERROR_PARAMS;
	}else if( (queue_depth < HMC_MIN_QUEUE_DEPTH ) || (queue_depth > HMC_MAX_QUEUE_DEPTH ) ){
		return HMC_ERROR_PARAMS;
	}else if( (xbar_depth < HMC_MIN_QUEUE_DEPTH ) || (xbar_depth > HMC_MAX_QUEUE_DEPTH ) ){
		return HMC_ERROR_PARAMS;
	}

#ifdef HMC_DEBUG
	HMCSIM_PRINT_TRACE( "PASSED LEVEL1 INIT SANITY CHECK" );
#endif

	/* 
	 * look deeper to make sure the default addressing works
	 * and the vault counts
	 * 
	 */
	if( (num_banks != 8) && (num_banks != 16) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_links != 4) && (num_links != 8) ){
		return HMC_ERROR_PARAMS;
	}else if( (num_vaults/num_links) != 4 ){
		/* always maintain 4 vaults per quad, or link */
		return HMC_ERROR_PARAMS;
	}else if( (capacity%2) != 0 ){
		return HMC_ERROR_PARAMS;
	}

#ifdef HMC_DEBUG
	HMCSIM_PRINT_TRACE( "PASSED LEVEL2 INIT SANITY CHECK" );
#endif

	/* 
	 * go deeper still...
	 * 
	 */
	if( (capacity == 2) && ( (num_banks == 16) || (num_links==8) ) ){
		return HMC_ERROR_PARAMS;
	}else if( (capacity == 4) && ( (num_banks == 8) && (num_links==4) ) ){
		return HMC_ERROR_PARAMS;
	}else if( (capacity == 4) && ( (num_banks == 16) && (num_links==8) ) ){
		return HMC_ERROR_PARAMS;
	}else if( (capacity == 8) && ( (num_banks == 8 ) || (num_links==4) ) ){
		return HMC_ERROR_PARAMS;
	}	

#ifdef HMC_DEBUG
	HMCSIM_PRINT_TRACE( "PASSED LEVEL3 INIT SANITY CHECK" );
#endif

	/* 
	 * init all the internals 
	 * 
 	 */
	hmc->tfile	= NULL;
	hmc->tracelevel	= 0x00;
	
	hmc->num_devs	= num_devs;
	hmc->num_links	= num_links;
	hmc->num_vaults	= num_vaults;
	hmc->num_banks	= num_banks;
	hmc->num_drams	= num_drams;
	hmc->capacity	= capacity;
	hmc->queue_depth= queue_depth;
	hmc->xbar_depth	= xbar_depth;

	hmc->clk	= 0x00ll;

	if( num_links == 4 ){ 
		hmc->num_quads = 4;
	}else{ 
		hmc->num_quads = 8;
	}

	/* 
	 * pointers
	 */
	hmc->__ptr_devs			= NULL;
	hmc->__ptr_quads		= NULL;
	hmc->__ptr_vaults		= NULL;
	hmc->__ptr_banks		= NULL;
	hmc->__ptr_drams		= NULL;
	hmc->__ptr_links		= NULL;
	hmc->__ptr_xbars		= NULL;
	hmc->__ptr_stor			= NULL;
	hmc->__ptr_xbar_rqst		= NULL;
	hmc->__ptr_xbar_rsp		= NULL;
	hmc->__ptr_vault_rqst		= NULL;
	hmc->__ptr_vault_rsp		= NULL;

	/* 
	 * 
	 * allocate memory 
	 * 
	 */	
	if( hmcsim_allocate_memory( hmc ) != 0 ){ 
		/* 
		 * probably ran out of memory 
		 *
		 */
#ifdef HMC_DEBUG
		HMCSIM_PRINT_TRACE( "FAILED TO ALLOCATE INTERNAL MEMORY" );
#endif

		return -1;
	}


	/* 
	 * configure all the devices 
	 * 
	 */
	if( hmcsim_config_devices( hmc ) != 0 ){
#ifdef HMC_DEBUG
		HMCSIM_PRINT_TRACE( "FAILED TO CONFIGURE THE INTERNAL DEVICE STRUCTURE" );
#endif

		hmcsim_free_memory( hmc );
		return -1;
	}

	/* 
	 * warm reset all the devices
	 * 
	 */
	for( i=0; i<hmc->num_devs; i++ ) { 

		//hmc_reset_device( hmc, i );
		
	}	

	return 0;
}