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

📄 ecard.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)			continue;		if (ec->ops && ec->ops->irqpending)			pending = ec->ops->irqpending(ec);		else			pending = ecard_default_ops.irqpending(ec);		if (pending) {			do_ecard_IRQ(ec->irq, regs);			called ++;		}	}	cli();	if (called == 0)		ecard_check_lockup();}#ifdef HAS_EXPMASKstatic unsigned char priority_masks[] ={	0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff};static unsigned char first_set[] ={	0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,	0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00};static voidecard_irq_expmask(int intr_no, void *dev_id, struct pt_regs *regs){	const unsigned int statusmask = 15;	unsigned int status;	status = __raw_readb(EXPMASK_STATUS) & statusmask;	if (status) {		unsigned int slot;		ecard_t *ec;again:		slot = first_set[status];		ec = slot_to_ecard(slot);		if (ec->claimed) {			unsigned int oldexpmask;			/*			 * this ugly code is so that we can operate a			 * prioritorising system:			 *			 * Card 0 	highest priority			 * Card 1			 * Card 2			 * Card 3	lowest priority			 *			 * Serial cards should go in 0/1, ethernet/scsi in 2/3			 * otherwise you will lose serial data at high speeds!			 */			oldexpmask = have_expmask;			have_expmask &= priority_masks[slot];			__raw_writeb(have_expmask, EXPMASK_ENABLE);			sti();			do_ecard_IRQ(ec->irq, regs);			cli();			have_expmask = oldexpmask;			__raw_writeb(have_expmask, EXPMASK_ENABLE);			status = __raw_readb(EXPMASK_STATUS) & statusmask;			if (status)				goto again;		} else {			printk(KERN_WARNING "card%d: interrupt from unclaimed "			       "card???\n", slot);			have_expmask &= ~(1 << slot);			__raw_writeb(have_expmask, EXPMASK_ENABLE);		}	} else		printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");}static void __init ecard_probeirqhw(void){	ecard_t *ec;	int found;	__raw_writeb(0x00, EXPMASK_ENABLE);	__raw_writeb(0xff, EXPMASK_STATUS);	found = (__raw_readb(EXPMASK_STATUS) & 15) == 0;	__raw_writeb(0xff, EXPMASK_ENABLE);	if (!found)		return;	printk(KERN_DEBUG "Expansion card interrupt "	       "management hardware found\n");	irqexpansioncard.handler = ecard_irq_expmask;	/* for each card present, set a bit to '1' */	have_expmask = 0x80000000;	for (ec = cards; ec; ec = ec->next)		have_expmask |= 1 << ec->slot_no;	__raw_writeb(have_expmask, EXPMASK_ENABLE);}#else#define ecard_probeirqhw() do { } while (0)#endif#ifndef IO_EC_MEMC8_BASE#define IO_EC_MEMC8_BASE 0#endifunsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed){	unsigned long address = 0;	int slot = ec->slot_no;	if (ec->slot_no == 8)		return IO_EC_MEMC8_BASE;	ectcr &= ~(1 << slot);	switch (type) {	case ECARD_MEMC:		if (slot < 4)			address = IO_EC_MEMC_BASE + (slot << 12);		break;	case ECARD_IOC:		if (slot < 4)			address = IO_EC_IOC_BASE + (slot << 12);#ifdef IO_EC_IOC4_BASE		else			address = IO_EC_IOC4_BASE + ((slot - 4) << 12);#endif		if (address)			address +=  speed << 17;		break;#ifdef IO_EC_EASI_BASE	case ECARD_EASI:		address = IO_EC_EASI_BASE + (slot << 22);		if (speed == ECARD_FAST)			ectcr |= 1 << slot;		break;#endif	default:		break;	}#ifdef IOMD_ECTCR	iomd_writeb(ectcr, IOMD_ECTCR);#endif	return address;}static int ecard_prints(char *buffer, ecard_t *ec){	char *start = buffer;	buffer += sprintf(buffer, "  %d: %s ", ec->slot_no,			  ec->type == ECARD_EASI ? "EASI" : "    ");	if (ec->cid.id == 0) {		struct in_chunk_dir incd;		buffer += sprintf(buffer, "[%04X:%04X] ",			ec->cid.manufacturer, ec->cid.product);		if (!ec->card_desc && ec->cid.cd &&		    ecard_readchunk(&incd, ec, 0xf5, 0)) {			ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);			if (ec->card_desc)				strcpy((char *)ec->card_desc, incd.d.string);		}		buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");	} else		buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);	return buffer - start;}static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count){	ecard_t *ec = cards;	off_t at = 0;	int len, cnt;	cnt = 0;	while (ec && count > cnt) {		len = ecard_prints(buf, ec);		at += len;		if (at >= pos) {			if (!*start) {				*start = buf + (pos - (at - len));				cnt = at - pos;			} else				cnt += len;			buf += len;		}		ec = ec->next;	}	return (count > cnt) ? cnt : count;}static struct proc_dir_entry *proc_bus_ecard_dir = NULL;static void ecard_proc_init(void){	proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);	create_proc_info_entry("devices", 0, proc_bus_ecard_dir,		get_ecard_dev_info);}#define ec_set_resource(ec,nr,st,sz,flg)			\	do {							\		(ec)->resource[nr].name = ec->name;	 	\		(ec)->resource[nr].start = st;			\		(ec)->resource[nr].end = (st) + (sz) - 1;	\		(ec)->resource[nr].flags = flg;			\	} while (0)static void __init ecard_init_resources(struct expansion_card *ec){	unsigned long base = PODSLOT_IOC4_BASE;	unsigned int slot = ec->slot_no;	int i;	if (slot < 4) {		ec_set_resource(ec, ECARD_RES_MEMC,				PODSLOT_MEMC_BASE + (slot << 14),				PODSLOT_MEMC_SIZE, IORESOURCE_MEM);		base = PODSLOT_IOC0_BASE;	}#ifdef CONFIG_ARCH_RPC	if (slot < 8) {		ec_set_resource(ec, ECARD_RES_EASI,				PODSLOT_EASI_BASE + (slot << 24),				PODSLOT_EASI_SIZE, IORESOURCE_MEM);	}	if (slot == 8) {		ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE,				NETSLOT_SIZE, IORESOURCE_MEM);	} else#endif	for (i = 0; i < ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++) {		ec_set_resource(ec, i + ECARD_RES_IOCSLOW,				base + (slot << 14) + (i << 19),				PODSLOT_IOC_SIZE, IORESOURCE_MEM);	}	for (i = 0; i < ECARD_NUM_RESOURCES; i++) {		if (ec->resource[i].start &&		    request_resource(&iomem_resource, &ec->resource[i])) {			printk(KERN_ERR "ecard%d: resource(s) not available\n",				ec->slot_no);			ec->resource[i].end -= ec->resource[i].start;			ec->resource[i].start = 0;		}	}}/* * Probe for an expansion card. * * If bit 1 of the first byte of the card is set, then the * card does not exist. */static int __initecard_probe(int slot, card_type_t type){	ecard_t **ecp;	ecard_t *ec;	struct ex_ecid cid;	int i, rc = -ENOMEM;	ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);	if (!ec)		goto nomem;	memset(ec, 0, sizeof(ecard_t));	ec->slot_no	= slot;	ec->type	= type;	ec->irq		= NO_IRQ;	ec->fiq		= NO_IRQ;	ec->dma		= NO_DMA;	ec->card_desc	= NULL;	ec->ops		= &ecard_default_ops;	rc = -ENODEV;	if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)		goto nodev;	cid.r_zero = 1;	ecard_readbytes(&cid, ec, 0, 16, 0);	if (cid.r_zero)		goto nodev;	ec->cid.id	= cid.r_id;	ec->cid.cd	= cid.r_cd;	ec->cid.is	= cid.r_is;	ec->cid.w	= cid.r_w;	ec->cid.manufacturer = ecard_getu16(cid.r_manu);	ec->cid.product = ecard_getu16(cid.r_prod);	ec->cid.country = cid.r_country;	ec->cid.irqmask = cid.r_irqmask;	ec->cid.irqoff  = ecard_gets24(cid.r_irqoff);	ec->cid.fiqmask = cid.r_fiqmask;	ec->cid.fiqoff  = ecard_gets24(cid.r_fiqoff);	ec->fiqaddr	=	ec->irqaddr	= (unsigned char *)ioaddr(ec->podaddr);	if (ec->cid.is) {		ec->irqmask = ec->cid.irqmask;		ec->irqaddr += ec->cid.irqoff;		ec->fiqmask = ec->cid.fiqmask;		ec->fiqaddr += ec->cid.fiqoff;	} else {		ec->irqmask = 1;		ec->fiqmask = 4;	}	for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)		if (blacklist[i].manufacturer == ec->cid.manufacturer &&		    blacklist[i].product == ec->cid.product) {			ec->card_desc = blacklist[i].type;			break;		}	snprintf(ec->name, sizeof(ec->name), "ecard %04x:%04x",		 ec->cid.manufacturer, ec->cid.product);	ecard_init_resources(ec);	/*	 * hook the interrupt handlers	 */	if (slot < 8) {		ec->irq = 32 + slot;		irq_desc[ec->irq].mask_ack = ecard_disableirq;		irq_desc[ec->irq].mask     = ecard_disableirq;		irq_desc[ec->irq].unmask   = ecard_enableirq;		irq_desc[ec->irq].valid    = 1;	}#ifdef IO_EC_MEMC8_BASE	if (slot == 8)		ec->irq = 11;#endif#ifdef CONFIG_ARCH_RPC	/* On RiscPC, only first two slots have DMA capability */	if (slot < 2)		ec->dma = 2 + slot;#endif	for (ecp = &cards; *ecp; ecp = &(*ecp)->next);	*ecp = ec;	slot_to_expcard[slot] = ec;	return 0;nodev:	kfree(ec);nomem:	return rc;}static ecard_t *finding_pos;void ecard_startfind(void){	finding_pos = NULL;}ecard_t *ecard_find(int cid, const card_ids *cids){	if (!finding_pos)		finding_pos = cards;	else		finding_pos = finding_pos->next;	for (; finding_pos; finding_pos = finding_pos->next) {		if (finding_pos->claimed || finding_pos->driver)			continue;		if (!cids) {			if ((finding_pos->cid.id ^ cid) == 0)				break;		} else {			unsigned int manufacturer, product;			int i;			manufacturer = finding_pos->cid.manufacturer;			product = finding_pos->cid.product;			for (i = 0; cids[i].manufacturer != 65535; i++)				if (manufacturer == cids[i].manufacturer &&				    product == cids[i].product)					break;			if (cids[i].manufacturer != 65535)				break;		}	}	return finding_pos;}static void __init ecard_free_all(void){	ecard_t *ec, *ecn;	for (ec = cards; ec; ec = ecn) {		ecn = ec->next;		kfree(ec);	}	cards = NULL;	memset(slot_to_expcard, 0, sizeof(slot_to_expcard));}/* * Initialise the expansion card system. * Locate all hardware - interrupt management and * actual cards. */void __init ecard_init(void){	int slot;#ifdef CONFIG_CPU_32	init_waitqueue_head(&ecard_wait);#endif	printk("Probing expansion cards\n");	for (slot = 0; slot < 8; slot ++) {		if (ecard_probe(slot, ECARD_EASI) == -ENODEV)			ecard_probe(slot, ECARD_IOC);	}#ifdef IO_EC_MEMC8_BASE	ecard_probe(8, ECARD_IOC);#endif	ecard_probeirqhw();	if (setup_arm_irq(IRQ_EXPANSIONCARD, &irqexpansioncard)) {		printk(KERN_ERR "Unable to claim IRQ%d for expansion cards\n",		       IRQ_EXPANSIONCARD);		ecard_free_all();	}	ecard_proc_init();}/* *	ECARD driver functions */static const struct ecard_id *ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec){	int i;	for (i = 0; ids[i].manufacturer != 65535; i++)		if (ec->cid.manufacturer == ids[i].manufacturer &&		    ec->cid.product == ids[i].product)			return ids + i;	return NULL;}static int ecard_drv_probe(struct expansion_card *ec, const struct ecard_id *id){	struct ecard_driver *drv = ec->driver;	int ret;	ecard_claim(ec);	ret = drv->probe(ec, id);	if (ret)		ecard_release(ec);	return ret;}static int ecard_drv_remove(struct expansion_card *ec){	struct ecard_driver *drv = ec->driver;	drv->remove(ec);	ecard_release(ec);	return 0;}/* * Before rebooting, we must make sure that the expansion card is in a * sensible state, so it can be re-detected.  This means that the first * page of the ROM must be visible.  We call the expansion cards reset * handler, if any. */static void ecard_drv_shutdown(struct expansion_card *ec){	struct ecard_driver *drv = ec->driver;	struct ecard_request req;	if (drv && drv->shutdown)		drv->shutdown(ec);	ecard_release(ec);	req.req = req_reset;	req.ec = ec;	ecard_call(&req);}int ecard_register_driver(struct ecard_driver *drv){	struct expansion_card *ec;	int ret, found = 0;	for (ec = cards; ec; ec = ec->next) {		const struct ecard_id *id;		if (ec->driver || ec->claimed)			continue;		if (drv->id_table) {			id = ecard_match_device(drv->id_table, ec);			ret = id != NULL;		} else {			id = NULL;			ret = ec->cid.id == drv->id;		}		if (ret) {			ec->driver = drv;			ret = ecard_drv_probe(ec, id);			if (ret) {				ec->driver = NULL;			} else {				found++;			}		}	}	return found ? 0 : -ENODEV;}void ecard_remove_driver(struct ecard_driver *drv){	struct expansion_card *ec;	for (ec = cards; ec; ec = ec->next)		if (ec->driver == drv) {			ecard_drv_remove(ec);			ec->driver = NULL;		}}/* * This function is responsible for resetting the expansion cards to a * sensible state immediately prior to rebooting the system.  This function * has process state (keventd), so we can sleep. * * Possible "val" values here: *  SYS_RESTART   -  restarting system *  SYS_HALT      - halting system *  SYS_POWER_OFF - powering down system * * We ignore all calls, unless it is a SYS_RESTART call - power down/halts * will be followed by a SYS_RESTART if ctrl-alt-del is pressed again. */static int ecard_reboot(struct notifier_block *me, unsigned long val, void *v){	struct expansion_card *ec;	if (val != SYS_RESTART)		return 0;	for (ec = cards; ec; ec = ec->next)		if (ec->driver || ec->claimed)			ecard_drv_shutdown(ec);	/*	 * Disable the expansion card interrupt	 */	disable_irq(IRQ_EXPANSIONCARD);	/*	 * Finally, reset the expansion card interrupt mask to	 * all enable (RISC OS doesn't set this)	 */#ifdef HAS_EXPMASK	have_expmask = ~0;	__raw_writeb(have_expmask, EXPMASK_ENABLE);#endif	return 0;}static struct notifier_block ecard_reboot_notifier = {	.notifier_call	= ecard_reboot,};static int ecard_bus_init(void){	register_reboot_notifier(&ecard_reboot_notifier);	return 0;}__initcall(ecard_bus_init);EXPORT_SYMBOL(ecard_startfind);EXPORT_SYMBOL(ecard_find);EXPORT_SYMBOL(ecard_readchunk);EXPORT_SYMBOL(ecard_address);EXPORT_SYMBOL(ecard_register_driver);EXPORT_SYMBOL(ecard_remove_driver);

⌨️ 快捷键说明

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