Home | History | Annotate | Line # | Download | only in hd6446x
hd6446xintc.c revision 1.2.16.2
      1 /*	$NetBSD: hd6446xintc.c,v 1.2.16.2 2006/12/30 20:46:04 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: hd6446xintc.c,v 1.2.16.2 2006/12/30 20:46:04 yamt Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 
     45 #include <sh3/devreg.h>
     46 #include <hpcsh/dev/hd6446x/hd6446xintcreg.h>
     47 #include <hpcsh/dev/hd6446x/hd6446xintcvar.h>
     48 
     49 struct hd6446x_intrhand hd6446x_intrhand[_HD6446X_INTR_N];
     50 uint16_t hd6446x_imask[_IPL_N];
     51 uint16_t hd6446x_ienable;
     52 
     53 static void hd6446x_intr_priority_update(void);
     54 
     55 
     56 void
     57 hd6446x_intr_init(void)
     58 {
     59 
     60 	/* Initialize interrupt priority masks. */
     61 	hd6446x_intr_priority_update();
     62 }
     63 
     64 void *
     65 hd6446x_intr_establish(int irq, int mode, int level,
     66     int (*func)(void *), void *arg)
     67 {
     68 	struct hd6446x_intrhand *hh = &hd6446x_intrhand[ffs(irq) - 1];
     69 	int s;
     70 
     71 	s = splhigh();
     72 
     73 	/* Register interrupt handler */
     74 	hh->hh_func = func;
     75 	hh->hh_arg = arg;
     76 	hh->hh_ipl = level << 4;
     77 	hh->hh_imask = irq;
     78 	hd6446x_ienable |= hh->hh_imask;
     79 
     80 	/* Update interrupt priority masks. */
     81 	hd6446x_intr_priority_update();
     82 
     83 	splx(s);
     84 
     85 	return (hh);
     86 }
     87 
     88 void
     89 hd6446x_intr_disestablish(void *handle)
     90 {
     91 	struct hd6446x_intrhand *hh = handle;
     92 	int s;
     93 
     94 	s = splhigh();
     95 
     96 	/* Update interrupt priority masks */
     97 	hd6446x_ienable &= ~hh->hh_imask;
     98 	memset(hh, 0, sizeof(*hh));
     99 	hd6446x_intr_priority_update();
    100 
    101 	splx(s);
    102 }
    103 
    104 void
    105 hd6446x_intr_priority(int irq, int level)
    106 {
    107 	struct hd6446x_intrhand *hh = &hd6446x_intrhand[ffs(irq) - 1];
    108 	int s;
    109 
    110 	KDASSERT(hh->hh_func != NULL);
    111 	s = splhigh();
    112 	hh->hh_ipl = level << 4;
    113 	hd6446x_intr_priority_update();
    114 	splx(s);
    115 }
    116 
    117 static void
    118 hd6446x_intr_priority_update(void)
    119 {
    120 	int ipl, src;
    121 
    122 	for (ipl = 0; ipl < _IPL_N; ipl++) {
    123 		uint16_t mask = ~hd6446x_ienable; /* mask disabled */
    124 
    125 		/* mask sources interrupting at <= ipl */
    126 		for (src = 0; src < _HD6446X_INTR_N; ++src) {
    127 			struct hd6446x_intrhand *hh = &hd6446x_intrhand[src];
    128 
    129 			if (hh->hh_func != NULL && hh->hh_ipl <= (ipl << 4))
    130 				mask |= 1 << src;
    131 		}
    132 
    133 		hd6446x_imask[ipl] = mask;
    134 	}
    135 }
    136