⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 divasmain.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
			return (-1);		}	} else {		release_region(port, length);	}	return (0);}void __iomem *divasa_remap_pci_bar(diva_os_xdi_adapter_t *a, int id, unsigned long bar, unsigned long area_length){	void __iomem *ret = ioremap(bar, area_length);	DBG_TRC(("remap(%08x)->%p", bar, ret));	return (ret);}void divasa_unmap_pci_bar(void __iomem *bar){	if (bar) {		iounmap(bar);	}}/********************************************************* ** I/O port access  *********************************************************/byte __inline__ inpp(void __iomem *addr){	return (inb((unsigned long) addr));}word __inline__ inppw(void __iomem *addr){	return (inw((unsigned long) addr));}void __inline__ inppw_buffer(void __iomem *addr, void *P, int length){	insw((unsigned long) addr, (word *) P, length >> 1);}void __inline__ outppw_buffer(void __iomem *addr, void *P, int length){	outsw((unsigned long) addr, (word *) P, length >> 1);}void __inline__ outppw(void __iomem *addr, word w){	outw(w, (unsigned long) addr);}void __inline__ outpp(void __iomem *addr, word p){	outb(p, (unsigned long) addr);}/* --------------------------------------------------------------------------    IRQ request / remove     -------------------------------------------------------------------------- */int diva_os_register_irq(void *context, byte irq, const char *name){	int result = request_irq(irq, diva_os_irq_wrapper,				 SA_INTERRUPT | SA_SHIRQ, name, context);	return (result);}void diva_os_remove_irq(void *context, byte irq){	free_irq(irq, context);}/* --------------------------------------------------------------------------    DPC framework implementation   -------------------------------------------------------------------------- */static void diva_os_dpc_proc(unsigned long context){	diva_os_thread_dpc_t *psoft_isr = (diva_os_thread_dpc_t *) context;	diva_os_soft_isr_t *pisr = psoft_isr->psoft_isr;	(*(pisr->callback)) (pisr, pisr->callback_context);}int diva_os_initialize_soft_isr(diva_os_soft_isr_t * psoft_isr,				diva_os_soft_isr_callback_t callback,				void *callback_context){	diva_os_thread_dpc_t *pdpc;	pdpc = (diva_os_thread_dpc_t *) diva_os_malloc(0, sizeof(*pdpc));	if (!(psoft_isr->object = pdpc)) {		return (-1);	}	memset(pdpc, 0x00, sizeof(*pdpc));	psoft_isr->callback = callback;	psoft_isr->callback_context = callback_context;	pdpc->psoft_isr = psoft_isr;	tasklet_init(&pdpc->divas_task, diva_os_dpc_proc, (unsigned long)pdpc);	return (0);}int diva_os_schedule_soft_isr(diva_os_soft_isr_t * psoft_isr){	if (psoft_isr && psoft_isr->object) {		diva_os_thread_dpc_t *pdpc =		    (diva_os_thread_dpc_t *) psoft_isr->object;		tasklet_schedule(&pdpc->divas_task);	}	return (1);}int diva_os_cancel_soft_isr(diva_os_soft_isr_t * psoft_isr){	return (0);}void diva_os_remove_soft_isr(diva_os_soft_isr_t * psoft_isr){	if (psoft_isr && psoft_isr->object) {		diva_os_thread_dpc_t *pdpc =		    (diva_os_thread_dpc_t *) psoft_isr->object;		void *mem;		tasklet_kill(&pdpc->divas_task);		flush_scheduled_work();		mem = psoft_isr->object;		psoft_isr->object = NULL;		diva_os_free(0, mem);	}}/* * kernel/user space copy functions */static intxdi_copy_to_user(void *os_handle, void __user *dst, const void *src, int length){	if (copy_to_user(dst, src, length)) {		return (-EFAULT);	}	return (length);}static intxdi_copy_from_user(void *os_handle, void *dst, const void __user *src, int length){	if (copy_from_user(dst, src, length)) {		return (-EFAULT);	}	return (length);}/* * device node operations */static int divas_open(struct inode *inode, struct file *file){	return (0);}static int divas_release(struct inode *inode, struct file *file){	if (file->private_data) {		diva_xdi_close_adapter(file->private_data, file);	}	return (0);}static ssize_t divas_write(struct file *file, const char __user *buf,			   size_t count, loff_t * ppos){	int ret = -EINVAL;	if (!file->private_data) {		file->private_data = diva_xdi_open_adapter(file, buf,							   count,							   xdi_copy_from_user);	}	if (!file->private_data) {		return (-ENODEV);	}	ret = diva_xdi_write(file->private_data, file,			     buf, count, xdi_copy_from_user);	switch (ret) {	case -1:		/* Message should be removed from rx mailbox first */		ret = -EBUSY;		break;	case -2:		/* invalid adapter was specified in this call */		ret = -ENOMEM;		break;	case -3:		ret = -ENXIO;		break;	}	DBG_TRC(("write: ret %d", ret));	return (ret);}static ssize_t divas_read(struct file *file, char __user *buf,			  size_t count, loff_t * ppos){	int ret = -EINVAL;	if (!file->private_data) {		file->private_data = diva_xdi_open_adapter(file, buf,							   count,							   xdi_copy_from_user);	}	if (!file->private_data) {		return (-ENODEV);	}	ret = diva_xdi_read(file->private_data, file,			    buf, count, xdi_copy_to_user);	switch (ret) {	case -1:		/* RX mailbox is empty */		ret = -EAGAIN;		break;	case -2:		/* no memory, mailbox was cleared, last command is failed */		ret = -ENOMEM;		break;	case -3:		/* can't copy to user, retry */		ret = -EFAULT;		break;	}	DBG_TRC(("read: ret %d", ret));	return (ret);}static unsigned int divas_poll(struct file *file, poll_table * wait){	if (!file->private_data) {		return (POLLERR);	}	return (POLLIN | POLLRDNORM);}static struct file_operations divas_fops = {	.owner   = THIS_MODULE,	.llseek  = no_llseek,	.read    = divas_read,	.write   = divas_write,	.poll    = divas_poll,	.open    = divas_open,	.release = divas_release};static void divas_unregister_chrdev(void){	devfs_remove(DEVNAME);	unregister_chrdev(major, DEVNAME);}static int DIVA_INIT_FUNCTION divas_register_chrdev(void){	if ((major = register_chrdev(0, DEVNAME, &divas_fops)) < 0)	{		printk(KERN_ERR "%s: failed to create /dev entry.\n",		       DRIVERLNAME);		return (0);	}	devfs_mk_cdev(MKDEV(major, 0), S_IFCHR|S_IRUSR|S_IWUSR, DEVNAME);	return (1);}/* --------------------------------------------------------------------------    PCI driver section   -------------------------------------------------------------------------- */static int __devinit divas_init_one(struct pci_dev *pdev,				    const struct pci_device_id *ent){	void *pdiva = NULL;	u8 pci_latency;	u8 new_latency = 32;	DBG_TRC(("%s bus: %08x fn: %08x insertion.\n",		 CardProperties[ent->driver_data].Name,		 pdev->bus->number, pdev->devfn))	printk(KERN_INFO "%s: %s bus: %08x fn: %08x insertion.\n",		DRIVERLNAME, CardProperties[ent->driver_data].Name,		pdev->bus->number, pdev->devfn);	if (pci_enable_device(pdev)) {		DBG_TRC(("%s: %s bus: %08x fn: %08x device init failed.\n",			 DRIVERLNAME,			 CardProperties[ent->driver_data].Name,			 pdev->bus->number,			 pdev->devfn))		printk(KERN_ERR			"%s: %s bus: %08x fn: %08x device init failed.\n",			DRIVERLNAME,			CardProperties[ent->driver_data].			Name, pdev->bus->number,			pdev->devfn);		return (-EIO);	}	pci_set_master(pdev);	pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);	if (!pci_latency) {		DBG_TRC(("%s: bus: %08x fn: %08x fix latency.\n",			 DRIVERLNAME, pdev->bus->number, pdev->devfn))		printk(KERN_INFO			"%s: bus: %08x fn: %08x fix latency.\n",			 DRIVERLNAME, pdev->bus->number, pdev->devfn);		pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);	}	if (!(pdiva = diva_driver_add_card(pdev, ent->driver_data))) {		DBG_TRC(("%s: %s bus: %08x fn: %08x card init failed.\n",			 DRIVERLNAME,			 CardProperties[ent->driver_data].Name,			 pdev->bus->number,			 pdev->devfn))		printk(KERN_ERR			"%s: %s bus: %08x fn: %08x card init failed.\n",			DRIVERLNAME,			CardProperties[ent->driver_data].			Name, pdev->bus->number,			pdev->devfn);		return (-EIO);	}	pci_set_drvdata(pdev, pdiva);	return (0);}static void __devexit divas_remove_one(struct pci_dev *pdev){	void *pdiva = pci_get_drvdata(pdev);	DBG_TRC(("bus: %08x fn: %08x removal.\n",		 pdev->bus->number, pdev->devfn))	printk(KERN_INFO "%s: bus: %08x fn: %08x removal.\n",		DRIVERLNAME, pdev->bus->number, pdev->devfn);	if (pdiva) {		diva_driver_remove_card(pdiva);	}}/* --------------------------------------------------------------------------    Driver Load / Startup     -------------------------------------------------------------------------- */static int DIVA_INIT_FUNCTION divas_init(void){	char tmprev[50];	int ret = 0;	printk(KERN_INFO "%s\n", DRIVERNAME);	printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_DIVAS);	strcpy(tmprev, main_revision);	printk("%s  Build: %s(%s)\n", getrev(tmprev),	       diva_xdi_common_code_build, DIVA_BUILD);	printk(KERN_INFO "%s: support for: ", DRIVERLNAME);#ifdef CONFIG_ISDN_DIVAS_BRIPCI	printk("BRI/PCI ");#endif#ifdef CONFIG_ISDN_DIVAS_PRIPCI	printk("PRI/PCI ");#endif	printk("adapters\n");	if (!divasfunc_init(dbgmask)) {		printk(KERN_ERR "%s: failed to connect to DIDD.\n",		       DRIVERLNAME);		ret = -EIO;		goto out;	}	if (!divas_register_chrdev()) {#ifdef MODULE		divasfunc_exit();#endif		ret = -EIO;		goto out;	}	if (!create_divas_proc()) {#ifdef MODULE		remove_divas_proc();		divas_unregister_chrdev();		divasfunc_exit();#endif		printk(KERN_ERR "%s: failed to create proc entry.\n",		       DRIVERLNAME);		ret = -EIO;		goto out;	}	if ((ret = pci_register_driver(&diva_pci_driver))) {#ifdef MODULE		remove_divas_proc();		divas_unregister_chrdev();		divasfunc_exit();#endif		printk(KERN_ERR "%s: failed to init pci driver.\n",		       DRIVERLNAME);		goto out;	}	printk(KERN_INFO "%s: started with major %d\n", DRIVERLNAME, major);      out:	return (ret);}/* --------------------------------------------------------------------------    Driver Unload   -------------------------------------------------------------------------- */static void DIVA_EXIT_FUNCTION divas_exit(void){	pci_unregister_driver(&diva_pci_driver);	remove_divas_proc();	divas_unregister_chrdev();	divasfunc_exit();	printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);}module_init(divas_init);module_exit(divas_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -