Beispiel #1
0
int __init __symbol_put_init(void) 
{ 
	const char * symbol_name ;	
	const char * mod_name ;
	struct module * fmodule ;

	symbol_name = "symbol_A";
	mod_name = "test_module";  //定义待查找的模块名为“test_module”
	fmodule = find_module( mod_name );  //调用查找模块函数

	if(fmodule != NULL )
	{
		printk("<0>before calling __symbol_put,\n");
		printk("<0>ref of %s is: %d\n",mod_name, module_refcount(fmodule));

		__symbol_put(symbol_name); //will dec the count

		printk("<0>after calling __symbol_put,\n");
		printk("<0>ref of %s is: %d\n",mod_name, module_refcount(fmodule));
	}
	else
	{
		printk("<0>find %s failed!\n", mod_name );
	}

	return 0; 
}
Beispiel #2
0
static int hello_init(void)
{
	uint64_t a = 1048576;
	uint32_t b = 4096;

	void (* func_p)(void);
/*	unsigned int cpu = get_cpu();
	struct module *mod;
	printk("this module: %p==%p\n", &__this_module, THIS_MODULE );
	printk("module state: %d\n", THIS_MODULE->state );
	printk("module name: %s\n", THIS_MODULE->name );
	list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list )
		printk(KERN_ALERT "module name: %s\n", mod->name );*/
	func_p = __symbol_get("hello_func");
	printk("func_p's addr is %p\n", func_p);
	if(!func_p){
		printk("func can not find!\n");
	}
	else{
		__symbol_put("hello_func");
		func_p();
		printk("symbol exist. p=%p\n", func_p);
	}
	printk("a/b = %u.\n", a/b);
	return 0;
}
Beispiel #3
0
static int me_probe_pci(struct pci_dev* raw_dev, const struct pci_device_id* id)
{
	int err = ME_ERRNO_SUCCESS;
	struct pci_local_dev* dev;

	me_constr_t constructor = NULL;
	me_device_t* n_device = NULL;
	me_device_t* o_device = NULL;

	char constructor_name[20]="me0000_pci_constr\0";
	char module_name[16]="me0000PCI\0";

 	PDEBUG("executed.\n");

 	/// Allocate structures.
 	dev = kzalloc(sizeof(struct pci_local_dev), GFP_KERNEL);
	if (!dev)
	{
		PERROR("Can't get memory for device's instance.");
		err = -ENOMEM;
		goto ERROR;
	}

	/// Check this board
	if (me_pci_board_check(dev, raw_dev))
	{
		PERROR("NOT SUPPORTED! This is not Meilhaus board.\n");
		err = -ENODEV;
		goto ERROR;
	}

	constructor_name[2] += (char)((dev->device >> 12) & 0x000F);
	constructor_name[3] += (char)((dev->device >> 8) & 0x000F);
 	PDEBUG("constructor_name: %s\n", constructor_name);
	module_name[2] += (char)((dev->device >> 12) & 0x000F);
	module_name[3] += (char)((dev->device >> 8) & 0x000F);
	if (module_name[2] == '6')
	{// Exceptions: me61xx, me62xx, me63xx are handled by one driver.
		module_name[3] = '0';
	}
	if (module_name[2] == '4')
	{
		if (module_name[3] == '8')
		{// Exceptions: me46xx and me48xx are handled by one driver.
			module_name[3] = '6';
		}
		else if (module_name[3] == '5')
		{// Exceptions: me45xx and me47xx are handled by one driver.
			module_name[3] = '7';
		}
	}
 	PDEBUG("module_name: %s\n", module_name);

/**
	Choice:
	a) New device connected.  Add to device list.
	b) Old device reconected. Refresh device structure.
*/
	o_device = find_device_on_list(dev, ME_PLUGGED_ANY);
	if(o_device)
	{
		PDEBUG("Device already registred.\n");
		// Old device.
		if (o_device->bus.plugged == ME_PLUGGED_IN)
		{
			// Error device is already on list mark as active!
			PERROR("Device is already on list mark as active!\n");
			o_device->me_device_disconnect(o_device);
		}
	}
	else
	{
		PDEBUG("New device.\n");
	}
	constructor = (me_constr_t) __symbol_get(constructor_name);
	if (!constructor)
	{
		PDEBUG("request_module: '%s'.\n", module_name);
		if (!request_module("%s", module_name))
		{
			constructor = (me_constr_t) __symbol_get(constructor_name);
			if (!constructor)
			{
				if(o_device)
				{
					PERROR_CRITICAL("Module loaded. Failed to get %s driver module constructor!\n", module_name);
				}
				else
				{
					PERROR("Can't get %s driver module constructor.\n", module_name);
				}
				err = -ENODEV;
				goto ERROR;
			}
		}
		else
		{
			PERROR("Can't get requested module: %s.\n", module_name);
			err = -ENODEV;
			goto ERROR;
		}
	}

	n_device = (*constructor)(dev, o_device);
	if (!n_device)
	{
		PERROR("Executing '%s()' failed.\n", constructor_name);
		__symbol_put(constructor_name);
		err = -ENODEV;
		goto ERROR;
	}
	else if (!o_device)
	{
		insert_to_device_list(n_device);
	}

	if (n_device->me_device_postinit)
	{
		if (n_device->me_device_postinit(n_device, NULL))
		{
			PERROR("Error while calling me_device_postinit().\n");
			/// This error can be ignored.
		}
		else
		{
			PDEBUG("me_device_postinit() was sucessful.\n");
		}
	}
	else
	{
		PERROR("me_device_postinit() not registred!\n");
	}

ERROR:
	if (dev)
		kfree(dev);
	dev = NULL;

	return err;
}