for ( i = entry->handle, j = 0 ; j < pages ; i += PAGE_SIZE, j++ ) { 
for (i = (unsigned long)entry->virtual, j = 0; j < pages; i += PAGE_SIZE, j++) { 
int drm_sg_alloc( struct inode *inode, struct file *filp,		   unsigned int cmd, unsigned long arg ){	drm_file_t *priv = filp->private_data;	drm_device_t *dev = priv->head->dev;	drm_scatter_gather_t __user *argp = (void __user *)arg;	drm_scatter_gather_t request;	drm_sg_mem_t *entry;	unsigned long pages, i, j;	DRM_DEBUG( "%s\n", __FUNCTION__ );	if (!drm_core_check_feature(dev, DRIVER_SG))		return -EINVAL;	if ( dev->sg )		return -EINVAL;	if ( copy_from_user( &request, argp, sizeof(request) ) )		return -EFAULT;	entry = drm_alloc( sizeof(*entry), DRM_MEM_SGLISTS );	if ( !entry )		return -ENOMEM;   	memset( entry, 0, sizeof(*entry) );	pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;	DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );	entry->pages = pages;	entry->pagelist = drm_alloc( pages * sizeof(*entry->pagelist),				     DRM_MEM_PAGES );	if ( !entry->pagelist ) {		drm_free( entry, sizeof(*entry), DRM_MEM_SGLISTS );		return -ENOMEM;	}	memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));	entry->busaddr = drm_alloc( pages * sizeof(*entry->busaddr),				     DRM_MEM_PAGES );	if ( !entry->busaddr ) {		drm_free( entry->pagelist,			   entry->pages * sizeof(*entry->pagelist),			   DRM_MEM_PAGES );		drm_free( entry,			   sizeof(*entry),			   DRM_MEM_SGLISTS );		return -ENOMEM;	}	memset( (void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr) );	entry->virtual = vmalloc_32( pages << PAGE_SHIFT );	if ( !entry->virtual ) {		drm_free( entry->busaddr,			   entry->pages * sizeof(*entry->busaddr),			   DRM_MEM_PAGES );		drm_free( entry->pagelist,			   entry->pages * sizeof(*entry->pagelist),			   DRM_MEM_PAGES );		drm_free( entry,			   sizeof(*entry),			   DRM_MEM_SGLISTS );		return -ENOMEM;	}	/* This also forces the mapping of COW pages, so our page list	 * will be valid.  Please don't remove it...	 */	memset( entry->virtual, 0, pages << PAGE_SHIFT );	entry->handle = (unsigned long)entry->virtual;	DRM_DEBUG( "sg alloc handle  = %08lx\n", entry->handle );	DRM_DEBUG( "sg alloc virtual = %p\n", entry->virtual );	for ( i = entry->handle, j = 0 ; j < pages ; i += PAGE_SIZE, j++ ) {		entry->pagelist[j] = vmalloc_to_page((void *)i);		if (!entry->pagelist[j])			goto failed;		SetPageReserved(entry->pagelist[j]);	}	request.handle = entry->handle;	if ( copy_to_user( argp, &request, sizeof(request) ) ) {		drm_sg_cleanup( entry );		return -EFAULT;	}	dev->sg = entry;#if DEBUG_SCATTER	/* Verify that each page points to its virtual address, and vice	 * versa.	 */	{	int error = 0;	for ( i = 0 ; i < pages ; i++ ) {		unsigned long *tmp;		tmp = page_address( entry->pagelist[i] );		for ( j = 0 ;		      j < PAGE_SIZE / sizeof(unsigned long) ;		      j++, tmp++ ) {			*tmp = 0xcafebabe;		}		tmp = (unsigned long *)((u8 *)entry->virtual +					(PAGE_SIZE * i));		for( j = 0 ;		     j < PAGE_SIZE / sizeof(unsigned long) ;		     j++, tmp++ ) {			if ( *tmp != 0xcafebabe && error == 0 ) {				error = 1;				DRM_ERROR( "Scatter allocation error, "					   "pagelist does not match "					   "virtual mapping\n" );			}		}		tmp = page_address( entry->pagelist[i] );		for(j = 0 ;		    j < PAGE_SIZE / sizeof(unsigned long) ;		    j++, tmp++) {			*tmp = 0;		}	}	if (error == 0)		DRM_ERROR( "Scatter allocation matches pagelist\n" );	}#endif	return 0; failed:	drm_sg_cleanup( entry );	return -ENOMEM;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/d1f2b55ad2c11f46e30547a9f7754e99b478348e/drm_scatter.c/clean/drivers/char/drm/drm_scatter.c