xref: /netbsd/sys/arch/arm/xscale/i80200_icu.c (revision 1b0b818d)
1*1b0b818dSskrll /*	$NetBSD: i80200_icu.c,v 1.10 2012/08/02 15:56:07 skrll Exp $	*/
2d70b940cSthorpej 
3d70b940cSthorpej /*
4d70b940cSthorpej  * Copyright (c) 2002 Wasabi Systems, Inc.
5d70b940cSthorpej  * All rights reserved.
6d70b940cSthorpej  *
7d70b940cSthorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8d70b940cSthorpej  *
9d70b940cSthorpej  * Redistribution and use in source and binary forms, with or without
10d70b940cSthorpej  * modification, are permitted provided that the following conditions
11d70b940cSthorpej  * are met:
12d70b940cSthorpej  * 1. Redistributions of source code must retain the above copyright
13d70b940cSthorpej  *    notice, this list of conditions and the following disclaimer.
14d70b940cSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
15d70b940cSthorpej  *    notice, this list of conditions and the following disclaimer in the
16d70b940cSthorpej  *    documentation and/or other materials provided with the distribution.
17d70b940cSthorpej  * 3. All advertising materials mentioning features or use of this software
18d70b940cSthorpej  *    must display the following acknowledgement:
19d70b940cSthorpej  *	This product includes software developed for the NetBSD Project by
20d70b940cSthorpej  *	Wasabi Systems, Inc.
21d70b940cSthorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22d70b940cSthorpej  *    or promote products derived from this software without specific prior
23d70b940cSthorpej  *    written permission.
24d70b940cSthorpej  *
25d70b940cSthorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26d70b940cSthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27d70b940cSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28d70b940cSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29d70b940cSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30d70b940cSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31d70b940cSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32d70b940cSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33d70b940cSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34d70b940cSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35d70b940cSthorpej  * POSSIBILITY OF SUCH DAMAGE.
36d70b940cSthorpej  */
37d70b940cSthorpej 
38d70b940cSthorpej /*
39d70b940cSthorpej  * Intel i80200 Interrupt Controller Unit support.
40d70b940cSthorpej  */
41d70b940cSthorpej 
4208716eaeSlukem #include <sys/cdefs.h>
43*1b0b818dSskrll __KERNEL_RCSID(0, "$NetBSD: i80200_icu.c,v 1.10 2012/08/02 15:56:07 skrll Exp $");
4408716eaeSlukem 
45d70b940cSthorpej #include <sys/param.h>
46d70b940cSthorpej #include <sys/systm.h>
47d70b940cSthorpej 
48d70b940cSthorpej #include <arm/cpufunc.h>
49d70b940cSthorpej 
50d70b940cSthorpej #include <arm/xscale/i80200reg.h>
51d70b940cSthorpej #include <arm/xscale/i80200var.h>
52d70b940cSthorpej 
53d70b940cSthorpej /* Software shadow copy of INTCTL. */
545f1c88d7Sperry static volatile uint32_t intctl;
55d70b940cSthorpej 
56e33cde59Sthorpej /* Pointer to board-specific external IRQ dispatcher. */
57*1b0b818dSskrll void	(*i80200_extirq_dispatch)(struct trapframe *);
58e33cde59Sthorpej 
59e33cde59Sthorpej static void
i80200_default_extirq_dispatch(struct trapframe * framep)60*1b0b818dSskrll i80200_default_extirq_dispatch(struct trapframe *framep)
61e33cde59Sthorpej {
62e33cde59Sthorpej 
63e33cde59Sthorpej 	panic("external IRQ with no dispatch routine");
64e33cde59Sthorpej }
65e33cde59Sthorpej 
66d70b940cSthorpej /*
6741f47f03Sthorpej  * i80200_icu_init:
68d70b940cSthorpej  *
69d70b940cSthorpej  *	Initialize the i80200 ICU.
70d70b940cSthorpej  */
71d70b940cSthorpej void
i80200_icu_init(void)7241f47f03Sthorpej i80200_icu_init(void)
73d70b940cSthorpej {
74d70b940cSthorpej 
75d70b940cSthorpej 	/* Disable all interrupt sources. */
76d70b940cSthorpej 	intctl = 0;
775f1c88d7Sperry 	__asm volatile("mcr p13, 0, %0, c0, c0"
78d70b940cSthorpej 		:
79d70b940cSthorpej 		: "r" (intctl));
80d70b940cSthorpej 
81d70b940cSthorpej 	/* Steer PMU and BMU to IRQ. */
825f1c88d7Sperry 	__asm volatile("mcr p13, 0, %0, c8, c0"
83d70b940cSthorpej 		:
84d70b940cSthorpej 		: "r" (0));
85e33cde59Sthorpej 
86e33cde59Sthorpej 	i80200_extirq_dispatch = i80200_default_extirq_dispatch;
87d70b940cSthorpej }
88d70b940cSthorpej 
89d70b940cSthorpej /*
90d70b940cSthorpej  * i80200_intr_enable:
91d70b940cSthorpej  *
92d70b940cSthorpej  *	Enable an interrupt source in the i80200 ICU.
93d70b940cSthorpej  */
94d70b940cSthorpej void
i80200_intr_enable(uint32_t intr)95d70b940cSthorpej i80200_intr_enable(uint32_t intr)
96d70b940cSthorpej {
97d70b940cSthorpej 	u_int oldirqstate;
98d70b940cSthorpej 
99d70b940cSthorpej 	oldirqstate = disable_interrupts(I32_bit|F32_bit);
100d70b940cSthorpej 
101d70b940cSthorpej 	intctl |= intr;
1025f1c88d7Sperry 	__asm volatile("mcr p13, 0, %0, c0, c0"
103d70b940cSthorpej 		:
104d70b940cSthorpej 		: "r" (intctl));
105d70b940cSthorpej 
106d70b940cSthorpej 	restore_interrupts(oldirqstate);
107d70b940cSthorpej }
108d70b940cSthorpej 
109d70b940cSthorpej /*
110d70b940cSthorpej  * i80200_intr_disable:
111d70b940cSthorpej  *
112d70b940cSthorpej  *	Disable an interrupt source in the i80200 ICU.
113d70b940cSthorpej  */
114d70b940cSthorpej void
i80200_intr_disable(uint32_t intr)115d70b940cSthorpej i80200_intr_disable(uint32_t intr)
116d70b940cSthorpej {
117d70b940cSthorpej 	u_int oldirqstate;
118d70b940cSthorpej 
119d70b940cSthorpej 	oldirqstate = disable_interrupts(I32_bit|F32_bit);
120d70b940cSthorpej 
121d70b940cSthorpej 	intctl &= ~intr;
1225f1c88d7Sperry 	__asm volatile("mcr p13, 0, %0, c0, c0"
123d70b940cSthorpej 		:
124d70b940cSthorpej 		: "r" (intctl));
125d70b940cSthorpej 
126d70b940cSthorpej 	restore_interrupts(oldirqstate);
127d70b940cSthorpej }
128