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

📄 ip2main.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 5 页
字号:
static int Eisa_slot;static int iindx;static char rirqs[IP2_MAX_BOARDS];static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};// Some functions to keep track of what irq's we havestatic int __initis_valid_irq(int irq){	int *i = Valid_Irqs;		while ((*i != 0) && (*i != irq)) {		i++;	}	return (*i);}static void __initmark_requested_irq( char irq ){	rirqs[iindx++] = irq;}#ifdef MODULEstatic int __initclear_requested_irq( char irq ){	int i;	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if (rirqs[i] == irq) {			rirqs[i] = 0;			return 1;		}	}	return 0;}#endifstatic int __inithave_requested_irq( char irq ){	// array init to zeros so 0 irq will not be requested as a side effect	int i;	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if (rirqs[i] == irq)			return 1;	}	return 0;}/******************************************************************************//* Function:   init_module()                                                  *//* Parameters: None                                                           *//* Returns:    Success (0)                                                    *//*                                                                            *//* Description:                                                               *//* This is a required entry point for an installable module. It simply calls  *//* the driver initialisation function and returns what it returns.            *//******************************************************************************/#ifdef MODULEintinit_module(void){#ifdef IP2DEBUG_INIT	printk (KERN_DEBUG "Loading module ...\n" );#endif    return 0;}#endif /* MODULE *//******************************************************************************//* Function:   cleanup_module()                                               *//* Parameters: None                                                           *//* Returns:    Nothing                                                        *//*                                                                            *//* Description:                                                               *//* This is a required entry point for an installable module. It has to return *//* the device and the driver to a passive state. It should not be necessary   *//* to reset the board fully, especially as the loadware is downloaded         *//* externally rather than in the driver. We just want to disable the board    *//* and clear the loadware to a reset state. To allow this there has to be a   *//* way to detect whether the board has the loadware running at init time to   *//* handle subsequent installations of the driver. All memory allocated by the *//* driver should be returned since it may be unloaded from memory.            *//******************************************************************************/#ifdef MODULEvoidcleanup_module(void){	int err;	int i;#ifdef IP2DEBUG_INIT	printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );#endif	/* Stop poll timer if we had one. */	if ( TimerOn ) {		del_timer ( &PollTimer );		TimerOn = 0;	}	/* Reset the boards we have. */	for( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if ( i2BoardPtrTable[i] ) {			iiReset( i2BoardPtrTable[i] );		}	}	/* The following is done at most once, if any boards were installed. */	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if ( i2BoardPtrTable[i] ) {			iiResetDelay( i2BoardPtrTable[i] );			/* free io addresses and Tibet */			release_region( ip2config.addr[i], 8 );#ifdef	CONFIG_DEVFS_FS			devfs_unregister (i2BoardPtrTable[i]->devfs_ipl_handle);			devfs_unregister (i2BoardPtrTable[i]->devfs_stat_handle);#endif		}		/* Disable and remove interrupt handler. */		if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {				free_irq ( ip2config.irq[i], (void *)&pcName);			clear_requested_irq( ip2config.irq[i]);		}	}	if ( ( err = tty_unregister_driver ( &ip2_tty_driver ) ) ) {		printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);	}	if ( ( err = tty_unregister_driver ( &ip2_callout_driver ) ) ) {		printk(KERN_ERR "IP2: failed to unregister callout driver (%d)\n", err);	}#ifdef	CONFIG_DEVFS_FS	if ( ( err = devfs_unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) )#else	if ( ( err = unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) )#endif	{		printk(KERN_ERR "IP2: failed to unregister IPL driver (%d)\n", err);	}	remove_proc_entry("ip2mem", &proc_root);	// free memory	for (i = 0; i < IP2_MAX_BOARDS; i++) {		void *pB;		if ((pB = i2BoardPtrTable[i]) != 0 ) {			kfree ( pB );			i2BoardPtrTable[i] = NULL;		}		if ((DevTableMem[i]) != NULL ) {			kfree ( DevTableMem[i]  );			DevTableMem[i] = NULL;		}	}	/* Cleanup the iiEllis subsystem. */	iiEllisCleanup();#ifdef IP2DEBUG_INIT	printk (KERN_DEBUG "IP2 Unloaded\n" );#endif}#endif /* MODULE *//******************************************************************************//* Function:   ip2_loadmain()                                                 *//* Parameters: irq, io from command line of insmod et. al.                    *//*		pointer to fip firmware and firmware size for boards	      *//* Returns:    Success (0)                                                    *//*                                                                            *//* Description:                                                               *//* This was the required entry point for all drivers (now in ip2.c)           *//* It performs all                                                            *//* initialisation of the devices and driver structures, and registers itself  *//* with the relevant kernel modules.                                          *//******************************************************************************//* SA_INTERRUPT- if set blocks all interrupts else only this line *//* SA_SHIRQ    - for shared irq PCI or maybe EISA only *//* SA_RANDOM   - can be source for cert. random number generators */#define IP2_SA_FLAGS	0int __initip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize) {#ifdef	CONFIG_DEVFS_FS	static devfs_handle_t devfs_handle;	int j, box;#endif	int i;	int err;	int status = 0;	static int loaded;	i2eBordStrPtr pB = NULL;	int rc = -1;	ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );	/* process command line arguments to modprobe or		insmod i.e. iop & irqp */	/* irqp and iop should ALWAYS be specified now...  But we check		them individually just to be sure, anyways... */	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if (iop) {			ip2config.addr[i] = iop[i];			if (irqp) {				if( irqp[i] >= 0 ) {					ip2config.irq[i] = irqp[i];				} else {					ip2config.irq[i] = 0;				}	// This is a little bit of a hack.  If poll_only=1 on command	// line back in ip2.c OR all IRQs on all specified boards are	// explicitly set to 0, then drop to poll only mode and override	// PCI or EISA interrupts.  This superceeds the old hack of	// triggering if all interrupts were zero (like da default).	// Still a hack but less prone to random acts of terrorism.	//	// What we really should do, now that the IRQ default is set	// to -1, is to use 0 as a hard coded, do not probe.	//	//	/\/\|=mhw=|\/\/				poll_only |= irqp[i];			}		}	}	poll_only = !poll_only;	Fip_firmware = firmware;	Fip_firmware_size = firmsize;	/* Announce our presence */	printk( KERN_INFO "%s version %s\n", pcName, pcVersion );	// ip2 can be unloaded and reloaded for no good reason	// we can't let that happen here or bad things happen	// second load hoses board but not system - fixme later	if (loaded) {		printk( KERN_INFO "Still loaded\n" );		return 0;	}	loaded++;	/* Initialise the iiEllis subsystem. */	iiEllisInit();	/* Initialize arrays. */	memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );	memset( DevTable, 0, sizeof DevTable );	memset( TtyTable, 0, sizeof TtyTable );	memset( Termios, 0, sizeof Termios );	memset( TermiosLocked, 0, sizeof TermiosLocked );	/* Initialise all the boards we can find (up to the maximum). */	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		switch ( ip2config.addr[i] ) { 		case 0:	/* skip this slot even if card is present */			break;		default: /* ISA */		   /* ISA address must be specified */			if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {				printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",							 i, ip2config.addr[i] );				ip2config.addr[i] = 0;			} else {				ip2config.type[i] = ISA;				/* Check for valid irq argument, set for polling if invalid */				if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {					printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);					ip2config.irq[i] = 0;// 0 is polling and is valid in that sense				}			}			break;		case PCI:#ifdef CONFIG_PCI#if (LINUX_VERSION_CODE < 0x020163) /* 2.1.99 */			if (pcibios_present()) {				unsigned char pci_bus, pci_devfn;				int Pci_index = 0;				status = pcibios_find_device(PCI_VENDOR_ID_COMPUTONE,							  PCI_DEVICE_ID_COMPUTONE_IP2EX, Pci_index,							  &pci_bus, &pci_devfn);				if (status == 0) {					unsigned int addr;					unsigned char pci_irq;					ip2config.type[i] = PCI;					/* 					 * Update Pci_index, so that the next time we go					 * searching for a PCI board we find a different					 * one.					 */					++Pci_index;					pcibios_read_config_dword(pci_bus, pci_devfn,								  PCI_BASE_ADDRESS_1, &addr);					if ( addr & 1 ) {						ip2config.addr[i]=(USHORT)(addr&0xfffe);					} else {						printk( KERN_ERR "IP2: PCI I/O address error\n");					}					pcibios_read_config_byte(pci_bus, pci_devfn,								  PCI_INTERRUPT_LINE, &pci_irq);//		If the PCI BIOS assigned it, lets try and use it.  If we//		can't acquire it or it screws up, deal with it then.//					if (!is_valid_irq(pci_irq)) {//						printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);//						pci_irq = 0;//					}					ip2config.irq[i] = pci_irq;				} else {	// ann error					ip2config.addr[i] = 0;					if (status == PCIBIOS_DEVICE_NOT_FOUND) {						printk( KERN_ERR "IP2: PCI board %d not found\n", i );					} else {						pcibios_strerror(status);					}				} 			} #else /* LINUX_VERSION_CODE > 2.1.99 */			if (pci_present()) {				struct pci_dev *pci_dev_i = NULL;				pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,							  PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);				if (pci_dev_i != NULL) {					unsigned int addr;					unsigned char pci_irq;					ip2config.type[i] = PCI;					status =					pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);					if ( addr & 1 ) {						ip2config.addr[i]=(USHORT)(addr&0xfffe);					} else {						printk( KERN_ERR "IP2: PCI I/O address error\n");					}					status =					pci_read_config_byte(pci_dev_i, PCI_INTERRUPT_LINE, &pci_irq);//		If the PCI BIOS assigned it, lets try and use it.  If we//		can't acquire it or it screws up, deal with it then.//					if (!is_valid_irq(pci_irq)) {//						printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);//						pci_irq = 0;//					}					ip2config.irq[i] = pci_irq;				} else {	// ann error					ip2config.addr[i] = 0;					if (status == PCIBIOS_DEVICE_NOT_FOUND) {						printk( KERN_ERR "IP2: PCI board %d not found\n", i );					} else {						pcibios_strerror(status);					}				} 			} #endif	/* ! 2_0_X */#else			printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");			printk( KERN_ERR "IP2: configured in this kernel.\n");			printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");#endif /* CONFIG_PCI */			break;		case EISA:			if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {				/* Eisa_irq set as side effect, boo */				ip2config.type[i] = EISA;			} 			ip2config.irq[i] = Eisa_irq;			break;		}	/* switch */	}	/* for */	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if ( ip2config.addr[i] ) {			pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);			if ( pB != NULL ) {				i2BoardPtrTable[i] = pB;				memset( pB, 0, sizeof(i2eBordStr) );				iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );				iiReset( pB );			} else {				printk(KERN_ERR "IP2: board memory allocation error\n");			}		}	}	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {			iiResetDelay( pB );			break;		}	}	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {		if ( i2BoardPtrTable[i] != NULL ) {			ip2_init_board( i );		}	}	ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );

⌨️ 快捷键说明

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