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

📄 intc.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Shared interrupt handling code for IPR and INTC2 types of IRQs. * * Copyright (C) 2007 Magnus Damm * * Based on intc2.c and ipr.c * * Copyright (C) 1999  Niibe Yutaka & Takeshi Yaegashi * Copyright (C) 2000  Kazumoto Kojima * Copyright (C) 2001  David J. Mckay (david.mckay@st.com) * Copyright (C) 2003  Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp> * Copyright (C) 2005, 2006  Paul Mundt * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. */#include <linux/init.h>#include <linux/irq.h>#include <linux/module.h>#include <linux/io.h>#include <linux/interrupt.h>#include <linux/bootmem.h>#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \	((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \	 ((addr_e) << 16) | ((addr_d << 24)))#define _INTC_SHIFT(h) (h & 0x1f)#define _INTC_WIDTH(h) ((h >> 5) & 0xf)#define _INTC_FN(h) ((h >> 9) & 0xf)#define _INTC_MODE(h) ((h >> 13) & 0x7)#define _INTC_ADDR_E(h) ((h >> 16) & 0xff)#define _INTC_ADDR_D(h) ((h >> 24) & 0xff)struct intc_handle_int {	unsigned int irq;	unsigned long handle;};struct intc_desc_int {	unsigned long *reg;#ifdef CONFIG_SMP	unsigned long *smp;#endif	unsigned int nr_reg;	struct intc_handle_int *prio;	unsigned int nr_prio;	struct intc_handle_int *sense;	unsigned int nr_sense;	struct irq_chip chip;};#ifdef CONFIG_SMP#define IS_SMP(x) x.smp#define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))#define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)#else#define IS_SMP(x) 0#define INTC_REG(d, x, c) (d->reg[(x)])#define SMP_NR(d, x) 1#endifstatic unsigned int intc_prio_level[NR_IRQS]; /* for now */static inline struct intc_desc_int *get_intc_desc(unsigned int irq){	struct irq_chip *chip = get_irq_chip(irq);	return (void *)((char *)chip - offsetof(struct intc_desc_int, chip));}static inline unsigned int set_field(unsigned int value,				     unsigned int field_value,				     unsigned int handle){	unsigned int width = _INTC_WIDTH(handle);	unsigned int shift = _INTC_SHIFT(handle);	value &= ~(((1 << width) - 1) << shift);	value |= field_value << shift;	return value;}static void write_8(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outb(set_field(0, data, h), addr);}static void write_16(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outw(set_field(0, data, h), addr);}static void write_32(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outl(set_field(0, data, h), addr);}static void modify_8(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outb(set_field(ctrl_inb(addr), data, h), addr);}static void modify_16(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outw(set_field(ctrl_inw(addr), data, h), addr);}static void modify_32(unsigned long addr, unsigned long h, unsigned long data){	ctrl_outl(set_field(ctrl_inl(addr), data, h), addr);}enum {	REG_FN_ERR = 0, REG_FN_WRITE_BASE = 1, REG_FN_MODIFY_BASE = 5 };static void (*intc_reg_fns[])(unsigned long addr,			      unsigned long h,			      unsigned long data) = {	[REG_FN_WRITE_BASE + 0] = write_8,	[REG_FN_WRITE_BASE + 1] = write_16,	[REG_FN_WRITE_BASE + 3] = write_32,	[REG_FN_MODIFY_BASE + 0] = modify_8,	[REG_FN_MODIFY_BASE + 1] = modify_16,	[REG_FN_MODIFY_BASE + 3] = modify_32,};enum {	MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */	MODE_MASK_REG,       /* Bit(s) set -> interrupt disabled */	MODE_DUAL_REG,       /* Two registers, set bit to enable / disable */	MODE_PRIO_REG,       /* Priority value written to enable interrupt */	MODE_PCLR_REG,       /* Above plus all bits set to disable interrupt */};static void intc_mode_field(unsigned long addr,			    unsigned long handle,			    void (*fn)(unsigned long,				       unsigned long,				       unsigned long),			    unsigned int irq){	fn(addr, handle, ((1 << _INTC_WIDTH(handle)) - 1));}static void intc_mode_zero(unsigned long addr,			   unsigned long handle,			   void (*fn)(unsigned long,				       unsigned long,				       unsigned long),			   unsigned int irq){	fn(addr, handle, 0);}static void intc_mode_prio(unsigned long addr,			   unsigned long handle,			   void (*fn)(unsigned long,				       unsigned long,				       unsigned long),			   unsigned int irq){	fn(addr, handle, intc_prio_level[irq]);}static void (*intc_enable_fns[])(unsigned long addr,				 unsigned long handle,				 void (*fn)(unsigned long,					    unsigned long,					    unsigned long),				 unsigned int irq) = {	[MODE_ENABLE_REG] = intc_mode_field,	[MODE_MASK_REG] = intc_mode_zero,	[MODE_DUAL_REG] = intc_mode_field,	[MODE_PRIO_REG] = intc_mode_prio,	[MODE_PCLR_REG] = intc_mode_prio,};static void (*intc_disable_fns[])(unsigned long addr,				  unsigned long handle,				  void (*fn)(unsigned long,					     unsigned long,					     unsigned long),				  unsigned int irq) = {	[MODE_ENABLE_REG] = intc_mode_zero,	[MODE_MASK_REG] = intc_mode_field,	[MODE_DUAL_REG] = intc_mode_field,	[MODE_PRIO_REG] = intc_mode_zero,	[MODE_PCLR_REG] = intc_mode_field,};static inline void _intc_enable(unsigned int irq, unsigned long handle){	struct intc_desc_int *d = get_intc_desc(irq);	unsigned long addr;	unsigned int cpu;	for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {		addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);		intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\						    [_INTC_FN(handle)], irq);	}}static void intc_enable(unsigned int irq){	_intc_enable(irq, (unsigned long)get_irq_chip_data(irq));}static void intc_disable(unsigned int irq){	struct intc_desc_int *d = get_intc_desc(irq);	unsigned long handle = (unsigned long) get_irq_chip_data(irq);	unsigned long addr;	unsigned int cpu;	for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {		addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);		intc_disable_fns[_INTC_MODE(handle)](addr, handle,intc_reg_fns\						     [_INTC_FN(handle)], irq);	}}static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,					     unsigned int nr_hp,					     unsigned int irq){	int i;	/* this doesn't scale well, but...	 *	 * this function should only be used for cerain uncommon	 * operations such as intc_set_priority() and intc_set_sense()	 * and in those rare cases performance doesn't matter that much.	 * keeping the memory footprint low is more important.	 *	 * one rather simple way to speed this up and still keep the	 * memory footprint down is to make sure the array is sorted	 * and then perform a bisect to lookup the irq.	 */	for (i = 0; i < nr_hp; i++) {		if ((hp + i)->irq != irq)			continue;		return hp + i;	}	return NULL;}int intc_set_priority(unsigned int irq, unsigned int prio){	struct intc_desc_int *d = get_intc_desc(irq);	struct intc_handle_int *ihp;	if (!intc_prio_level[irq] || prio <= 1)		return -EINVAL;	ihp = intc_find_irq(d->prio, d->nr_prio, irq);	if (ihp) {		if (prio >= (1 << _INTC_WIDTH(ihp->handle)))			return -EINVAL;		intc_prio_level[irq] = prio;		/*		 * only set secondary masking method directly		 * primary masking method is using intc_prio_level[irq]		 * priority level will be set during next enable()		 */		if (_INTC_FN(ihp->handle) != REG_FN_ERR)			_intc_enable(irq, ihp->handle);	}	return 0;}#define VALID(x) (x | 0x80)static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = {	[IRQ_TYPE_EDGE_FALLING] = VALID(0),	[IRQ_TYPE_EDGE_RISING] = VALID(1),	[IRQ_TYPE_LEVEL_LOW] = VALID(2),	[IRQ_TYPE_LEVEL_HIGH] = VALID(3),};static int intc_set_sense(unsigned int irq, unsigned int type){	struct intc_desc_int *d = get_intc_desc(irq);	unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK];	struct intc_handle_int *ihp;	unsigned long addr;	if (!value)		return -EINVAL;	ihp = intc_find_irq(d->sense, d->nr_sense, irq);	if (ihp) {		addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0);		intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value);	}	return 0;}static unsigned int __init intc_get_reg(struct intc_desc_int *d,				 unsigned long address){	unsigned int k;	for (k = 0; k < d->nr_reg; k++) {		if (d->reg[k] == address)			return k;	}	BUG();	return 0;}

⌨️ 快捷键说明

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