示例#1
0
// Инициализация коммуникаций (1), перевод глобальных параметров в локальные процессора (2),
// инициализация ускорителя (2.5), выделение памяти (3), загрузка начальных/сохраненных данных (4)
// Для задачи Б-Л загрузка проницаемостей из файла.
void initialization(long int* time_counter, int argc, char* argv[])
{
	communication_initialization(argc, argv); // (1)

	print_task_name();

	sizes_initialization();

	blocks_initialization();

	global_to_local_vars(); // (2)

	device_initialization(); // (2.5)

	memory_allocation(); // (3)

	load_permeability(HostArraysPtr.K); // (5)

	data_initialization(time_counter);

	load_data_to_device(HostArraysPtr.P_w, DevArraysPtrLoc->P_w);
	load_data_to_device(HostArraysPtr.S_w, DevArraysPtrLoc->S_w);
	load_data_to_device(HostArraysPtr.S_n, DevArraysPtrLoc->S_n);
	load_data_to_device(HostArraysPtr.S_g, DevArraysPtrLoc->S_g);
	load_data_to_device(HostArraysPtr.roS_w_old, DevArraysPtrLoc->roS_w_old);
	load_data_to_device(HostArraysPtr.roS_n_old, DevArraysPtrLoc->roS_n_old);
	load_data_to_device(HostArraysPtr.roS_g_old, DevArraysPtrLoc->roS_g_old);
	load_data_to_device(HostArraysPtr.m, DevArraysPtrLoc->m);
	load_data_to_device(HostArraysPtr.K, DevArraysPtrLoc->K);
#ifdef ENERGY
	load_data_to_device(HostArraysPtr.T, DevArraysPtrLoc->T);
#endif
}
static int __init initfunc(void)
{
	int ret1;
	int minorno;	
	int l;
	dev_t devno;
	int ret2;

	minorno=MINORNO;

	#ifdef DEBUG 
		printk(KERN_ALERT"Hello Kernel \n");
	#endif

	ret1=alloc_chrdev_region(&devid,minorno,nod,DEVNAME);

	if(ret1<0)
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : alloc_chrdev_region failed!!");
			goto OUT;
		#endif
	}

	#ifdef DEBUG 
		printk(KERN_ALERT"Registration Successful!! \n");
	#endif

	dev=kmalloc(sizeof(struct Dev)*nod,GFP_KERNEL);
	
	if(!dev)
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : kmalloc failed!!");
			goto OUT;
		#endif
	}

	memset(dev,'\0',sizeof(struct Dev)*nod);

	#ifdef DEBUG
		printk(KERN_ALERT"Memory Allocation Successful!!");
	#endif

	device_initialization();

	for(l=0;l<nod;l++)
	{
		devno = MKDEV(MAJOR(devid),l);

		cdev_init(&dev[l].c_dev,&fops);

		dev[l].c_dev.owner = THIS_MODULE;
		dev[l].c_dev.ops = &fops;

		dev[l].devsize = dev_size;
		dev[l].datasize = data_size;
		dev[l].qsetsize = qset_size;
		dev[l].quantumsize = quantum_size;

		ret2=cdev_add(&dev[l].c_dev,devno,1);
	
		if(ret2<0)
		{
			#ifdef DEBUG
			printk(KERN_ERR"Error : cdev_add failed!!");
			goto OUT;
			#endif
		}

		#ifdef DEBUG
			printk(KERN_ALERT"Device%d (Major = %d,Minor = %d)",l+1,MAJOR(devno),MINOR(devno));
		#endif
	}

	return 0;
OUT:
	return -1;
}
static int __init initfunc(void)
{
	int ret1;
	int minorno;	
	dev_t devno;
	int ret2;

	minorno=MINORNO;

	#ifdef DEBUG 
		printk(KERN_ALERT"Hello Kernel \n");
	#endif

	ret1=alloc_chrdev_region(&devid,minorno,1,DEVNAME);

	if(ret1<0)
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : alloc_chrdev_region failed!! \n");
			goto OUT;
		#endif
	}

	#ifdef DEBUG 
		printk(KERN_ALERT"Registration Successful!! \n");
	#endif

	dev=kmalloc(sizeof(struct Dev),GFP_KERNEL);
	
	if(!dev)
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : kmalloc failed!! \n");
			goto OUT;
		#endif
	}

	memset(dev,'\0',sizeof(struct Dev));

	#ifdef DEBUG
		printk(KERN_ALERT"Memory Allocation Successful!! \n");
	#endif

	device_initialization();

	devno = MKDEV(MAJOR(devid),0);

	cdev_init(&dev->c_dev,&fops);

	dev->c_dev.owner = THIS_MODULE;
	dev->c_dev.ops = &fops;

	ret2=cdev_add(&dev->c_dev,devno,1);
	
	if(ret2<0)
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : cdev_add failed!! \n");
			goto OUT;
		#endif
	}

	#ifdef DEBUG
		printk(KERN_ALERT"(Major = %d,Minor = %d)",MAJOR(devno),MINOR(devno));
	#endif

	if( check_region(BASE,8) < 8 )
	{
		#ifdef DEBUG
			printk(KERN_ALERT"Releasing resources!! \n");
		#endif

		release_region(BASE,8);
	}	

	if( !request_region(BASE,8,DEVNAME) )
	{
		#ifdef DEBUG
			printk(KERN_ERR"Error : request_region failed!! \n");
			goto OUT;
		#endif
	}

	return 0;
OUT:
	return -1;
}