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

📄 ecard.c

📁 arm平台上的uclinux系统全部源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * linux/arch/arm/kernel/ecard.c * *  Find all installed expansion cards, and handle interrupts from them. * * Copyright 1995-1998 Russell King * * Created from information from Acorns RiscOS3 PRMs * * 08-Dec-1996	RMK	Added code for the 9'th expansion card - the ether *			podule slot. * 06-May-1997  RMK	Added blacklist for cards whose loader doesn't work. * 12-Sep-1997	RMK	Created new handling of interrupt enables/disables *			- cards can now register their own routine to control *			interrupts (recommended). * 29-Sep-1997	RMK	Expansion card interrupt hardware not being re-enabled *			on reset from Linux. (Caused cards not to respond *			under RiscOS without hard reset). * 15-Feb-1998	RMK	Added DMA support * 12-Sep-1998	RMK	Added EASI support * 10-Jan-1999	RMK	Run loaders in a simulated RISC OS environment. */#define ECARD_C#define __KERNEL_SYSCALLS__#include <linux/config.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/mm.h>#include <linux/malloc.h>#include <linux/errno.h>#include <linux/unistd.h>#include <asm/dma.h>#include <asm/ecard.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/arch/irq.h>#include <asm/pgtable.h>#ifdef CONFIG_ARCH_ARC#include <asm/arch/oldlatches.h>#else#define oldlatch_init()#endifenum req {	req_readbytes,	req_reset};struct ecard_request {	enum req	req;	ecard_t		*ec;	unsigned int	address;	unsigned int	length;	unsigned int	use_loader;	void		*buffer;};struct expcard_blacklist {	unsigned short	 manufacturer;	unsigned short	 product;	const char	*type;};static pid_t ecard_pid;static struct wait_queue *ecard_wait;static struct wait_queue *ecard_done;static struct ecard_request *ecard_req;static struct task_struct *ecard_tsk;static ecard_t *cards;static ecard_t *slot_to_expcard[MAX_ECARDS];#ifdef HAS_EXPMASKstatic unsigned int have_expmask;#endif/* List of descriptions of cards which don't have an extended * identification, or chunk directories containing a description. */static const struct expcard_blacklist blacklist[] = {	{ MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }};asmlinkage extern int ecard_loader_reset(volatile unsigned char *pa,					 loader_t loader);asmlinkage extern int ecard_loader_read(int off, volatile unsigned char *pa,					loader_t loader);extern int setup_arm_irq(int, struct irqaction *);extern void do_fast_IRQ(int irq);static voidecard_irq_noexpmask(int intr_no, void *dev_id, struct pt_regs *regs);static struct irqaction irqexpansioncard = {	ecard_irq_noexpmask, 0, 0, "expansion cards", NULL, NULL};static inline unsigned shortecard_getu16(unsigned char *v){	return v[0] | v[1] << 8;}static inline signed longecard_gets24(unsigned char *v){	return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);}static inline ecard_t *slot_to_ecard(unsigned int slot){	return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;}/* ===================== Expansion card daemon ======================== *//* * Since the loader programs on the expansion cards need to be run * in a specific environment, create a separate task with this * environment up, and pass requests to this task as and when we * need to. * * This should allow 99% of loaders to be called from Linux. * * From a security standpoint, we trust the card vendors.  This * may be a misplaced trust. */#define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)#define POD_INT_ADDR(x)	((volatile unsigned char *)\			 ((BUS_ADDR((x)) - IO_BASE) + IO_START))static voidecard_task_reset(struct ecard_request *req){	if (req->ec == NULL) {		ecard_t *ec;		for (ec = cards; ec; ec = ec->next) {			printk(KERN_DEBUG "Resetting card %d\n",			       ec->slot_no);			if (ec->loader)				ecard_loader_reset(POD_INT_ADDR(ec->podaddr),						   ec->loader);		}		printk(KERN_DEBUG "All cards reset\n");	} else if (req->ec->loader)		ecard_loader_reset(POD_INT_ADDR(req->ec->podaddr),				   req->ec->loader);}static voidecard_task_readbytes(struct ecard_request *req){	unsigned char *buf = (unsigned char *)req->buffer;	volatile unsigned char *base_addr =		(volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);	unsigned int len = req->length;	if (req->ec->slot_no == 8) {		/*		 * The card maintains an index which		 * increments the address into a 4096-byte		 * page on each access.  We need to keep		 * track of the counter.		 */		static unsigned int index;		unsigned int offset, page;		unsigned char byte = 0; /* keep gcc quiet */		offset = req->address & 4095;		page   = req->address >> 12;		if (page > 256)			return;		page *= 4;		if (offset == 0 || index > offset) {			/*			 * We need to reset the index counter.			 */			*base_addr = 0;			index = 0;		}		while (index <= offset) {			byte = base_addr[page];			index += 1;		}		while (len--) {			*buf++ = byte;			if (len) {				byte = base_addr[page];				index += 1;			}		}	} else {		unsigned int off = req->address;		if (!req->use_loader || !req->ec->loader) {			off *= 4;			while (len--) {				*buf++ = base_addr[off];				off += 4;			}		} else {			while(len--) {				/*				 * The following is required by some				 * expansion card loader programs.				 */				*(unsigned long *)0x108 = 0;				*buf++ = ecard_loader_read(off++, base_addr,							   req->ec->loader);			}		}	}}#if !defined(CONFIG_CPU_ARM2) && !defined(CONFIG_CPU_ARM3)/* * Set up the expansion card daemon's environment. */static voidecard_init_task(void){	/* We want to set up the page tables for the following mapping:	 *  Virtual	Physical	 *  0x03000000	0x03000000	 *  0x03010000	unmapped	 *  0x03210000	0x03210000	 *  0x03400000	unmapped	 *  0x08000000	0x08000000	 *  0x10000000	unmapped	 *	 * FIXME: we don't follow this 100% yet.	 */	pgd_t *src_pgd, *dst_pgd;	unsigned int dst_addr = IO_START;	src_pgd = pgd_offset(current->mm, IO_BASE);	dst_pgd = pgd_offset(current->mm, dst_addr);	while (dst_addr < IO_START + IO_SIZE) {		*dst_pgd++ = *src_pgd++;		dst_addr += PGDIR_SIZE;	}	flush_tlb_range(current->mm, IO_START, IO_START + IO_SIZE);	dst_addr = EASI_START;	src_pgd = pgd_offset(current->mm, EASI_BASE);	dst_pgd = pgd_offset(current->mm, dst_addr);	while (dst_addr < EASI_START + EASI_SIZE) {		*dst_pgd++ = *src_pgd++;		dst_addr += PGDIR_SIZE;	}	flush_tlb_range(current->mm, EASI_START, EASI_START + EASI_SIZE);}static intecard_task(void * unused){	ecard_tsk = current;	current->session = 1;	current->pgrp = 1;	/*	 * We don't want /any/ signals, not even SIGKILL	 */	current->blocked = -1;	current->signal = 0;	strcpy(current->comm, "kecardd");	/*	 * Set up the environment	 */	ecard_init_task();	while (1) {		struct ecard_request *req;		do {			req = xchg(&ecard_req, NULL);			if (req == NULL) {				current->signal = 0;				interruptible_sleep_on(&ecard_wait);			}		} while (req == NULL);		switch (req->req) {		case req_readbytes:			ecard_task_readbytes(req);			break;		case req_reset:			ecard_task_reset(req);			break;		}		wake_up(&ecard_done);	}}/* * Wake the expansion card daemon to action our request. * * FIXME: The test here is not sufficient to detect if the * kcardd is running. */static inline voidecard_call(struct ecard_request *req){	/*	 * If we're called from task 0, or from an	 * interrupt (will be keyboard interrupt),	 * we forcefully set up the memory map, and	 * call the loader.  We can't schedule, or	 * sleep for this call.	 */	if ((current == task[0] || intr_count == 1) &&	    req->req == req_reset && req->ec == NULL) {		ecard_init_task();		ecard_task_reset(req);	} else {		if (ecard_pid <= 0)			ecard_pid = kernel_thread(ecard_task, NULL, 0);		ecard_req = req;		wake_up(&ecard_wait);		sleep_on(&ecard_done);	}}#else/* * On 26-bit processors, we don't need the kcardd thread to access the * expansion card loaders.  We do it directly. */static inline voidecard_call(struct ecard_request *req){	if (req->req == req_reset)		ecard_task_reset(req);	else		ecard_task_readbytes(req);}#endif/* ======================= Mid-level card control ===================== *//* * This is called to reset the loaders for each expansion card on reboot. * * This is required to make sure that the card is in the correct state * that RiscOS expects it to be. */voidecard_reset(int slot){	struct ecard_request req;	req.req = req_reset;	if (slot < 0)		req.ec = NULL;	else		req.ec = slot_to_ecard(slot);	ecard_call(&req);#ifdef HAS_EXPMASK	if (have_expmask && slot < 0) {		have_expmask |= ~0;		EXPMASK_ENABLE = have_expmask;	}#endif}static voidecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld){	struct ecard_request req;	req.req		= req_readbytes;	req.ec		= ec;	req.address	= off;	req.length	= len;	req.use_loader	= useld;	req.buffer	= addr;	ecard_call(&req);}int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num){	struct ex_chunk_dir excd;	int index = 16;	int useld = 0;	if (!ec->cid.cd)		return 0;	while(1) {		ecard_readbytes(&excd, ec, index, 8, useld);		index += 8;		if (c_id(&excd) == 0) {			if (!useld && ec->loader) {				useld = 1;				index = 0;				continue;			}			return 0;		}		if (c_id(&excd) == 0xf0) { /* link */			index = c_start(&excd);			continue;		}		if (c_id(&excd) == 0x80) { /* loader */			if (!ec->loader) {				ec->loader = (loader_t)kmalloc(c_len(&excd),							       GFP_KERNEL);				ecard_readbytes(ec->loader, ec,						(int)c_start(&excd),						c_len(&excd), useld);			}			continue;		}		if (c_id(&excd) == id && num-- == 0)			break;	}	if (c_id(&excd) & 0x80) {		switch (c_id(&excd) & 0x70) {		case 0x70:			ecard_readbytes((unsigned char *)excd.d.string, ec,					(int)c_start(&excd), c_len(&excd),					useld);			break;		case 0x00:			break;		}	}	cd->start_offset = c_start(&excd);	memcpy(cd->d.string, excd.d.string, 256);	return 1;}/* ======================= Interrupt control ============================ */static void ecard_def_irq_enable(ecard_t *ec, int irqnr){#ifdef HAS_EXPMASK	if (irqnr < 4 && have_expmask) {		have_expmask |= 1 << irqnr;		EXPMASK_ENABLE = have_expmask;	}#endif}static void ecard_def_irq_disable(ecard_t *ec, int irqnr){#ifdef HAS_EXPMASK	if (irqnr < 4 && have_expmask) {		have_expmask &= ~(1 << irqnr);		EXPMASK_ENABLE = have_expmask;	}#endif}static int ecard_def_irq_pending(ecard_t *ec){	return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;}static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr){	panic("ecard_def_fiq_enable called - impossible");}static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr){	panic("ecard_def_fiq_disable called - impossible");}static int ecard_def_fiq_pending(ecard_t *ec){	return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;}static expansioncard_ops_t ecard_default_ops = {	ecard_def_irq_enable,

⌨️ 快捷键说明

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