/*
 * interrupt.h -- 680x0 Linux general interrupt handling definitions.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file README.legal in the main directory of this archive
 * for more details.
 */

#ifndef _LINUX_INTERRUPT_H_
#define _LINUX_INTERRUPT_H_

/*
 * Interrupt source definitions
 * General interrupt sources are the level 1-7.
 * Adding an interrupt service routine for one of these sources
 * results in the addition of that routine to a chain of routines.
 * Each one is called in succession.  Each individual interrupt
 * service routine should determine if the device associated with
 * that routine requires service.
 */

#define IRQ1		 (1)    /* level 1 interrupt */
#define IRQ2		 (2)    /* level 2 interrupt */
#define IRQ3		 (3)    /* level 3 interrupt */
#define IRQ4		 (4)    /* level 4 interrupt */
#define IRQ5		 (5)    /* level 5 interrupt */
#define IRQ6		 (6)    /* level 6 interrupt */
#define IRQ7		 (7)    /* level 7 interrupt (non-maskable) */

#define IRQMF0   (8)    /* MFP Non-Autovector-Interrupt */
#define IRQMF1   (9)    /* MFP Non-Autovector-Interrupt */
#define IRQMF2   (10)    /* MFP Non-Autovector-Interrupt */
#define IRQMF3   (11)    /* MFP Non-Autovector-Interrupt */
#define IRQMF4   (12)    /* MFP Non-Autovector-Interrupt */
#define IRQMF5   (13)    /* MFP Non-Autovector-Interrupt */
#define IRQMF6   (14)    /* MFP Non-Autovector-Interrupt */
#define IRQMF7   (15)    /* MFP Non-Autovector-Interrupt */
#define IRQMF8   (16)    /* MFP Non-Autovector-Interrupt */
#define IRQMF9   (17)    /* MFP Non-Autovector-Interrupt */
#define IRQMF10   (18)    /* MFP Non-Autovector-Interrupt */
#define IRQMF11   (19)    /* MFP Non-Autovector-Interrupt */
#define IRQMF12   (20)    /* MFP Non-Autovector-Interrupt */
#define IRQMF13   (21)    /* MFP Non-Autovector-Interrupt */
#define IRQMF14   (22)    /* MFP Non-Autovector-Interrupt */
#define IRQMF15   (23)    /* MFP Non-Autovector-Interrupt */

/*
 * "Generic" interrupt sources
 */

#define IRQ_SCHED_TIMER  (21)    /* interrupt source for scheduling timer */

/*
 * Machine specific interrupt sources.
 *
 * Adding an interrupt service routine for a source with this bit
 * set indicates a special machine specific interrupt source.
 * The machine specific files define these sources.
 */

#define IRQ_MACHSPEC	 (0x10000000L)

/*
 * This structure is used to chain together the ISRs for a particular
 * interrupt source (if it supports chaining).
 */
typedef struct isr_node {
    isrfunc	    isr;
    int 	    pri;
    void            *data; /* data to be passed to the isr */
    struct isr_node *next;
} isr_node_t;

/* count of spurious interrupts */
unsigned long num_spurious;

/*
 * This function returns a new isr_node_t
 */
extern isr_node_t *new_isr_node(void);

/*
 * This function is used to add a specific interrupt service routine
 * for the specified interrupt source.
 *
 * If the source is machine specific, it will be passed along to the
 * machine specific routine.
 *
 * "data" is user specified data which will be passed to the isr routine.
 *
 * (isrfunc is defined in linux/config.h)
 */
extern int add_isr (unsigned long source, isrfunc isr, int pri, void *data);

/*
 * This routine will insert an isr_node_t into a chain of nodes, using
 * the priority stored in the node.
 */
extern void insert_isr (isr_node_t **listp, isr_node_t *node);

/*
 * This routine may be used to call the isr routines in the passed list.
 */
extern void call_isr_list (isr_node_t *p, struct intframe *fp);





/* Interrupt "Bottom Half" (software interrupt) definitions */

struct bh_struct {
	void (*routine)(void *);
	void *data;
};

extern unsigned long bh_active;
extern unsigned long bh_mask;
extern struct bh_struct bh_base[32];

/* Who gets which entry in bh_base.  Things which will occur most often
   should come first. */
enum {
	TIMER_BH = 0,
	CONSOLE_BH,
	SERIAL_BH,
	TTY_BH,
	INET_BH,
	KEYBOARD_BH
};

static inline void mark_bh(int nr)
{
	__asm__ __volatile__("bfset %0:%1:#1":"=m" (bh_active):"d" (31-nr));
}

static inline void disable_bh(int nr)
{
	__asm__ __volatile__("bfclr %0:%1,#1":"=m" (bh_mask):"ir" (31-nr));
}

static inline void enable_bh(int nr)
{
	__asm__ __volatile__("bfset %0,%1:#1":"=m" (bh_mask):"ir" (31-nr));
}


#endif /* linux/interrupt.h */
