memset( dev_priv, 0, sizeof(drm_mga_private_t) ); 
dev_priv = dev->dev_private; 
static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init ){	drm_mga_private_t *dev_priv;	int ret;	DRM_DEBUG( "\n" );	dev_priv = drm_alloc( sizeof(drm_mga_private_t), DRM_MEM_DRIVER );	if ( !dev_priv )		return DRM_ERR(ENOMEM);	memset( dev_priv, 0, sizeof(drm_mga_private_t) );	dev_priv->chipset = init->chipset;	dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;	if ( init->sgram ) {		dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_BLK;	} else {		dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;	}	dev_priv->maccess	= init->maccess;	dev_priv->fb_cpp	= init->fb_cpp;	dev_priv->front_offset	= init->front_offset;	dev_priv->front_pitch	= init->front_pitch;	dev_priv->back_offset	= init->back_offset;	dev_priv->back_pitch	= init->back_pitch;	dev_priv->depth_cpp	= init->depth_cpp;	dev_priv->depth_offset	= init->depth_offset;	dev_priv->depth_pitch	= init->depth_pitch;	/* FIXME: Need to support AGP textures...	 */	dev_priv->texture_offset = init->texture_offset[0];	dev_priv->texture_size = init->texture_size[0];	DRM_GETSAREA();	if(!dev_priv->sarea) {		DRM_ERROR( "failed to find sarea!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);	if(!dev_priv->mmio) {		DRM_ERROR( "failed to find mmio region!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev_priv->status = drm_core_findmap(dev, init->status_offset);	if(!dev_priv->status) {		DRM_ERROR( "failed to find status page!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev_priv->warp = drm_core_findmap(dev, init->warp_offset);	if(!dev_priv->warp) {		DRM_ERROR( "failed to find warp microcode region!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev_priv->primary = drm_core_findmap(dev, init->primary_offset);	if(!dev_priv->primary) {		DRM_ERROR( "failed to find primary dma region!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);	if(!dev->agp_buffer_map) {		DRM_ERROR( "failed to find dma buffer region!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(EINVAL);	}	dev_priv->sarea_priv =		(drm_mga_sarea_t *)((u8 *)dev_priv->sarea->handle +				    init->sarea_priv_offset);	drm_core_ioremap( dev_priv->warp, dev );	drm_core_ioremap( dev_priv->primary, dev );	drm_core_ioremap( dev->agp_buffer_map, dev );	if(!dev_priv->warp->handle ||	   !dev_priv->primary->handle ||	   !dev->agp_buffer_map->handle ) {		DRM_ERROR( "failed to ioremap agp regions!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(ENOMEM);	}	ret = mga_warp_install_microcode( dev_priv );	if ( ret < 0 ) {		DRM_ERROR( "failed to install WARP ucode!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return ret;	}	ret = mga_warp_init( dev_priv );	if ( ret < 0 ) {		DRM_ERROR( "failed to init WARP engine!\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return ret;	}	dev_priv->prim.status = (u32 *)dev_priv->status->handle;	mga_do_wait_for_idle( dev_priv );	/* Init the primary DMA registers.	 */	MGA_WRITE( MGA_PRIMADDRESS,		   dev_priv->primary->offset | MGA_DMA_GENERAL );#if 0	MGA_WRITE( MGA_PRIMPTR,		   virt_to_bus((void *)dev_priv->prim.status) |		   MGA_PRIMPTREN0 |	/* Soft trap, SECEND, SETUPEND */		   MGA_PRIMPTREN1 );	/* DWGSYNC */#endif	dev_priv->prim.start = (u8 *)dev_priv->primary->handle;	dev_priv->prim.end = ((u8 *)dev_priv->primary->handle			      + dev_priv->primary->size);	dev_priv->prim.size = dev_priv->primary->size;	dev_priv->prim.tail = 0;	dev_priv->prim.space = dev_priv->prim.size;	dev_priv->prim.wrapped = 0;	dev_priv->prim.last_flush = 0;	dev_priv->prim.last_wrap = 0;	dev_priv->prim.high_mark = 256 * DMA_BLOCK_SIZE;	dev_priv->prim.status[0] = dev_priv->primary->offset;	dev_priv->prim.status[1] = 0;	dev_priv->sarea_priv->last_wrap = 0;	dev_priv->sarea_priv->last_frame.head = 0;	dev_priv->sarea_priv->last_frame.wrap = 0;	if ( mga_freelist_init( dev, dev_priv ) < 0 ) {		DRM_ERROR( "could not initialize freelist\n" );		/* Assign dev_private so we can do cleanup. */		dev->dev_private = (void *)dev_priv;		mga_do_cleanup_dma( dev );		return DRM_ERR(ENOMEM);	}	/* Make dev_private visable to others. */	dev->dev_private = (void *)dev_priv;	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/6795c985a648d1e90b367cc1387c18205ecca4b8/mga_dma.c/clean/drivers/char/drm/mga_dma.c