i80321_intr.h revision 135669
1135669Scognet/*	$NetBSD: i80321_intr.h,v 1.5 2004/01/12 10:25:06 scw Exp $	*/
2135669Scognet
3135669Scognet/*
4135669Scognet * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5135669Scognet * All rights reserved.
6135669Scognet *
7135669Scognet * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8135669Scognet *
9135669Scognet * Redistribution and use in source and binary forms, with or without
10135669Scognet * modification, are permitted provided that the following conditions
11135669Scognet * are met:
12135669Scognet * 1. Redistributions of source code must retain the above copyright
13135669Scognet *    notice, this list of conditions and the following disclaimer.
14135669Scognet * 2. Redistributions in binary form must reproduce the above copyright
15135669Scognet *    notice, this list of conditions and the following disclaimer in the
16135669Scognet *    documentation and/or other materials provided with the distribution.
17135669Scognet * 3. All advertising materials mentioning features or use of this software
18135669Scognet *    must display the following acknowledgement:
19135669Scognet *	This product includes software developed for the NetBSD Project by
20135669Scognet *	Wasabi Systems, Inc.
21135669Scognet * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22135669Scognet *    or promote products derived from this software without specific prior
23135669Scognet *    written permission.
24135669Scognet *
25135669Scognet * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26135669Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27135669Scognet * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28135669Scognet * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29135669Scognet * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30135669Scognet * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31135669Scognet * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32135669Scognet * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33135669Scognet * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34135669Scognet * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35135669Scognet * POSSIBILITY OF SUCH DAMAGE.
36135669Scognet *
37135669Scognet * $FreeBSD: head/sys/arm/xscale/i80321/i80321_intr.h 135669 2004-09-23 22:45:36Z cognet $
38135669Scognet *
39135669Scognet */
40135669Scognet
41135669Scognet#ifndef _I80321_INTR_H_
42135669Scognet#define _I80321_INTR_H_
43135669Scognet
44135669Scognet#define	ARM_IRQ_HANDLER	_C_LABEL(i80321_intr_dispatch)
45135669Scognet
46135669Scognet#ifndef _LOCORE
47135669Scognet
48135669Scognet#include <machine/armreg.h>
49135669Scognet#include <machine/cpufunc.h>
50135669Scognet
51135669Scognet#include <arm/xscale/i80321/i80321reg.h>
52135669Scognet
53135669Scognetvoid i80321_do_pending(void);
54135669Scognet
55135669Scognetextern __volatile uint32_t intr_enabled;
56135669Scognetextern uint32_t intr_steer;
57135669Scognet
58135669Scognetstatic __inline void __attribute__((__unused__))
59135669Scogneti80321_set_intrmask(void)
60135669Scognet{
61135669Scognet
62135669Scognet	__asm __volatile("mcr p6, 0, %0, c0, c0, 0"
63135669Scognet		:
64135669Scognet		: "r" (intr_enabled & ICU_INT_HWMASK));
65135669Scognet}
66135669Scognet
67135669Scognetstatic __inline void
68135669Scogneti80321_set_intrsteer(void)
69135669Scognet{
70135669Scognet
71135669Scognet	__asm __volatile("mcr p6, 0, %0, c4, c0, 0"
72135669Scognet	    :
73135669Scognet	    : "r" (intr_steer & ICU_INT_HWMASK));
74135669Scognet}
75135669Scognet
76135669Scognet#define INT_SWMASK                                                      \
77135669Scognet        ((1U << ICU_INT_bit26) | (1U << ICU_INT_bit22) |                \
78135669Scognet         (1U << ICU_INT_bit5)  | (1U << ICU_INT_bit4))
79135669Scognet
80135669Scognet#if 0
81135669Scognetstatic __inline void __attribute__((__unused__))
82135669Scogneti80321_splx(int new)
83135669Scognet{
84135669Scognet	extern __volatile uint32_t intr_enabled;
85135669Scognet	extern __volatile int current_spl_level;
86135669Scognet	extern __volatile int i80321_ipending;
87135669Scognet	extern void i80321_do_pending(void);
88135669Scognet	int oldirqstate, hwpend;
89135669Scognet
90135669Scognet	/* Don't let the compiler re-order this code with preceding code */
91135669Scognet	__insn_barrier();
92135669Scognet
93135669Scognet	current_spl_level = new;
94135669Scognet
95135669Scognet	hwpend = (i80321_ipending & ICU_INT_HWMASK) & ~new;
96135669Scognet	if (hwpend != 0) {
97135669Scognet		oldirqstate = disable_interrupts(I32_bit);
98135669Scognet		intr_enabled |= hwpend;
99135669Scognet		i80321_set_intrmask();
100135669Scognet		restore_interrupts(oldirqstate);
101135669Scognet	}
102135669Scognet
103135669Scognet	if ((i80321_ipending & INT_SWMASK) & ~new)
104135669Scognet		i80321_do_pending();
105135669Scognet}
106135669Scognet
107135669Scognetstatic __inline int __attribute__((__unused__))
108135669Scogneti80321_splraise(int ipl)
109135669Scognet{
110135669Scognet	extern __volatile int current_spl_level;
111135669Scognet	extern int i80321_imask[];
112135669Scognet	int	old;
113135669Scognet
114135669Scognet	old = current_spl_level;
115135669Scognet	current_spl_level |= i80321_imask[ipl];
116135669Scognet
117135669Scognet	/* Don't let the compiler re-order this code with subsequent code */
118135669Scognet	__insn_barrier();
119135669Scognet
120135669Scognet	return (old);
121135669Scognet}
122135669Scognet
123135669Scognetstatic __inline int __attribute__((__unused__))
124135669Scogneti80321_spllower(int ipl)
125135669Scognet{
126135669Scognet	extern __volatile int current_spl_level;
127135669Scognet	extern int i80321_imask[];
128135669Scognet	int old = current_spl_level;
129135669Scognet
130135669Scognet	i80321_splx(i80321_imask[ipl]);
131135669Scognet	return(old);
132135669Scognet}
133135669Scognet
134135669Scognet#endif
135135669Scognet#if !defined(EVBARM_SPL_NOINLINE)
136135669Scognet
137135669Scognet#define splx(new)		i80321_splx(new)
138135669Scognet#define	_spllower(ipl)		i80321_spllower(ipl)
139135669Scognet#define	_splraise(ipl)		i80321_splraise(ipl)
140135669Scognetvoid	_setsoftintr(int);
141135669Scognet
142135669Scognet#else
143135669Scognet
144135669Scognetint	_splraise(int);
145135669Scognetint	_spllower(int);
146135669Scognetvoid	splx(int);
147135669Scognetvoid	_setsoftintr(int);
148135669Scognet
149135669Scognet#endif /* ! EVBARM_SPL_NOINLINE */
150135669Scognet
151135669Scognet#endif /* _LOCORE */
152135669Scognet
153135669Scognet#endif /* _I80321_INTR_H_ */
154