xref: /netbsd-src/sys/arch/powerpc/include/openpic.h (revision 214426933468072a3cb6bdffc32347ec8dcee4b8)
1*21442693Smatt /*	$NetBSD: openpic.h,v 1.8 2012/02/01 02:03:51 matt Exp $	*/
2044caccfSbriggs 
3044caccfSbriggs /*-
4044caccfSbriggs  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
5044caccfSbriggs  *
6044caccfSbriggs  * Redistribution and use in source and binary forms, with or without
7044caccfSbriggs  * modification, are permitted provided that the following conditions
8044caccfSbriggs  * are met:
9044caccfSbriggs  * 1. Redistributions of source code must retain the above copyright
10044caccfSbriggs  *    notice, this list of conditions and the following disclaimer.
11044caccfSbriggs  * 2. Redistributions in binary form must reproduce the above copyright
12044caccfSbriggs  *    notice, this list of conditions and the following disclaimer in the
13044caccfSbriggs  *    documentation and/or other materials provided with the distribution.
14044caccfSbriggs  * 3. The name of the author may not be used to endorse or promote products
15044caccfSbriggs  *    derived from this software without specific prior written permission.
16044caccfSbriggs  *
17044caccfSbriggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18044caccfSbriggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19044caccfSbriggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20044caccfSbriggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21044caccfSbriggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22044caccfSbriggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23044caccfSbriggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24044caccfSbriggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25044caccfSbriggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26044caccfSbriggs  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27044caccfSbriggs  */
28044caccfSbriggs 
29044caccfSbriggs #include <machine/pio.h>
30044caccfSbriggs 
31044caccfSbriggs #include <machine/openpicreg.h>
32044caccfSbriggs 
33044caccfSbriggs extern volatile unsigned char *openpic_base;
34044caccfSbriggs 
35*21442693Smatt static __inline uint32_t openpic_read(u_int);
36*21442693Smatt static __inline void openpic_write(u_int, uint32_t);
3702cdf4d2Sdsl static __inline int openpic_read_irq(int);
3802cdf4d2Sdsl static __inline void openpic_eoi(int);
39044caccfSbriggs 
40*21442693Smatt static __inline uint32_t
openpic_read(u_int reg)41*21442693Smatt openpic_read(u_int reg)
42044caccfSbriggs {
43*21442693Smatt 	volatile uint8_t *addr = openpic_base + reg;
44044caccfSbriggs 
45044caccfSbriggs 	return in32rb(addr);
46044caccfSbriggs }
47044caccfSbriggs 
48fbae48b9Sperry static __inline void
openpic_write(u_int reg,uint32_t val)49*21442693Smatt openpic_write(u_int reg, uint32_t val)
50044caccfSbriggs {
51*21442693Smatt 	volatile uint8_t *addr = openpic_base + reg;
52044caccfSbriggs 
53044caccfSbriggs 	out32rb(addr, val);
54044caccfSbriggs }
55044caccfSbriggs 
56fbae48b9Sperry static __inline int
openpic_read_irq(int cpu)57*21442693Smatt openpic_read_irq(int cpu)
58044caccfSbriggs {
59044caccfSbriggs 	return openpic_read(OPENPIC_IACK(cpu)) & OPENPIC_VECTOR_MASK;
60044caccfSbriggs }
61044caccfSbriggs 
62fbae48b9Sperry static __inline void
openpic_eoi(int cpu)63*21442693Smatt openpic_eoi(int cpu)
64044caccfSbriggs {
65044caccfSbriggs 	openpic_write(OPENPIC_EOI(cpu), 0);
66044caccfSbriggs 	openpic_read(OPENPIC_EOI(cpu));
67044caccfSbriggs }
68