1*fbae48b9Sperry /* $NetBSD: openpic.h,v 1.5 2006/02/16 20:17:14 perry 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 33e96035c5Sbriggs /* void openpic_init(): defined in machdep code, must set openpic_base */ 34044caccfSbriggs void openpic_enable_irq __P((int, int)); 35044caccfSbriggs void openpic_disable_irq __P((int)); 36044caccfSbriggs void openpic_set_priority __P((int, int)); 37044caccfSbriggs 38044caccfSbriggs extern volatile unsigned char *openpic_base; 39044caccfSbriggs 40*fbae48b9Sperry static __inline u_int openpic_read __P((int)); 41*fbae48b9Sperry static __inline void openpic_write __P((int, u_int)); 42*fbae48b9Sperry static __inline int openpic_read_irq __P((int)); 43*fbae48b9Sperry static __inline void openpic_eoi __P((int)); 44044caccfSbriggs 45*fbae48b9Sperry static __inline u_int 46044caccfSbriggs openpic_read(reg) 47044caccfSbriggs int reg; 48044caccfSbriggs { 49044caccfSbriggs volatile unsigned char *addr = openpic_base + reg; 50044caccfSbriggs 51044caccfSbriggs return in32rb(addr); 52044caccfSbriggs } 53044caccfSbriggs 54*fbae48b9Sperry static __inline void 55044caccfSbriggs openpic_write(reg, val) 56044caccfSbriggs int reg; 57044caccfSbriggs u_int val; 58044caccfSbriggs { 59044caccfSbriggs volatile unsigned char *addr = openpic_base + reg; 60044caccfSbriggs 61044caccfSbriggs out32rb(addr, val); 62044caccfSbriggs } 63044caccfSbriggs 64*fbae48b9Sperry static __inline int 65044caccfSbriggs openpic_read_irq(cpu) 66044caccfSbriggs int cpu; 67044caccfSbriggs { 68044caccfSbriggs return openpic_read(OPENPIC_IACK(cpu)) & OPENPIC_VECTOR_MASK; 69044caccfSbriggs } 70044caccfSbriggs 71*fbae48b9Sperry static __inline void 72044caccfSbriggs openpic_eoi(cpu) 73044caccfSbriggs int cpu; 74044caccfSbriggs { 75044caccfSbriggs openpic_write(OPENPIC_EOI(cpu), 0); 76044caccfSbriggs openpic_read(OPENPIC_EOI(cpu)); 77044caccfSbriggs } 78