Home | History | Annotate | Line # | Download | only in marvell
pic_discovery.c revision 1.6
      1 /*	$NetBSD: pic_discovery.c,v 1.6 2012/01/30 23:31:28 matt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed for the NetBSD Project by
     18  *      Allegro Networks, Inc., and Wasabi Systems, Inc.
     19  * 4. The name of Allegro Networks, Inc. may not be used to endorse
     20  *    or promote products derived from this software without specific prior
     21  *    written permission.
     22  * 5. The name of Wasabi Systems, Inc. may not be used to endorse
     23  *    or promote products derived from this software without specific prior
     24  *    written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
     27  * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     29  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30  * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: pic_discovery.c,v 1.6 2012/01/30 23:31:28 matt Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/bus.h>
     45 #include <sys/malloc.h>
     46 #include <sys/intr.h>
     47 
     48 #include <powerpc/pic/picvar.h>
     49 
     50 #include <dev/marvell/gtvar.h>
     51 #include <dev/marvell/gtintrreg.h>
     52 #include <dev/marvell/gtintrvar.h>
     53 
     54 
     55 __CTASSERT(sizeof(imask_t) == sizeof(uint64_t));
     56 
     57 struct discovery_gpp_pic_ops;
     58 
     59 struct discovery_pic_ops {
     60 	struct pic_ops pic;
     61 	union {
     62 		uint64_t mask64;
     63 		uint32_t mask32[2];
     64 	} _mask;
     65 #define enable_mask		_mask.mask64
     66 #define enable_mask_high	_mask.mask32[1]
     67 #define enable_mask_low		_mask.mask32[0]
     68 };
     69 struct discovery_gpp_pic_ops {
     70 	struct pic_ops pic;
     71 
     72 	int gpp_base;
     73 };
     74 
     75 
     76 static void discovery_enable_irq(struct pic_ops *, int, int);
     77 static void discovery_disable_irq(struct pic_ops *, int);
     78 static int discovery_get_irq(struct pic_ops *, int);
     79 static void discovery_ack_irq(struct pic_ops *, int);
     80 
     81 static void discovery_gpp_enable_irq(struct pic_ops *, int, int);
     82 static void discovery_gpp_disable_irq(struct pic_ops *, int);
     83 static int discovery_gpp_get_irq(struct pic_ops *, int);
     84 static void discovery_gpp_ack_irq(struct pic_ops *, int);
     85 
     86 
     87 struct pic_ops *
     88 setup_discovery_pic(void)
     89 {
     90 	struct discovery_pic_ops *discovery;
     91 	struct pic_ops *pic;
     92 
     93 	discovery =
     94 	    malloc(sizeof(struct discovery_pic_ops), M_DEVBUF, M_NOWAIT);
     95 	KASSERT(discovery != NULL);
     96 
     97 	pic = &discovery->pic;
     98 	pic->pic_numintrs = 64;
     99 	pic->pic_cookie = (void *)NULL;			/* set later */
    100 	pic->pic_enable_irq = discovery_enable_irq;
    101 	pic->pic_reenable_irq = discovery_enable_irq;
    102 	pic->pic_disable_irq = discovery_disable_irq;
    103 	pic->pic_get_irq = discovery_get_irq;
    104 	pic->pic_ack_irq = discovery_ack_irq;
    105 	pic->pic_establish_irq = dummy_pic_establish_intr;
    106 	pic->pic_finish_setup = NULL;
    107 	strcpy(pic->pic_name, "discovery");
    108 	pic_add(pic);
    109 
    110 	discovery->enable_mask = 0;
    111 
    112 	return pic;
    113 }
    114 
    115 static void
    116 discovery_enable_irq(struct pic_ops *pic, int irq, int type)
    117 {
    118 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    119 
    120 	discovery->enable_mask |= (1 << irq);
    121 	discovery_enable_intr(pic->pic_cookie, irq);
    122 }
    123 
    124 static void
    125 discovery_disable_irq(struct pic_ops *pic, int irq)
    126 {
    127 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    128 
    129 	discovery->enable_mask &= ~(1 << irq);
    130 	discovery_disable_intr(pic->pic_cookie, irq);
    131 }
    132 
    133 static int
    134 discovery_get_irq(struct pic_ops *pic, int mode)
    135 {
    136 	struct discovery_pic_ops *discovery = (struct discovery_pic_ops *)pic;
    137 	uint32_t cause;
    138 	int irq, base, msk;
    139 
    140 	cause = discovery_mic_low(pic->pic_cookie) & discovery->enable_mask_low;
    141 	if (cause)
    142 		base = 0;
    143 	else {
    144 		cause = discovery_mic_high(pic->pic_cookie);
    145 		cause &= discovery->enable_mask_high;
    146 		if (!cause)
    147 			return 255;
    148 		base = 32;
    149 	}
    150 	for (irq = base, msk = 0x00000001; !(cause & msk); irq++, msk <<= 1);
    151 
    152 	return irq;
    153 }
    154 
    155 static void
    156 discovery_ack_irq(struct pic_ops *pic, int irq)
    157 {
    158 
    159 	/* nothing */
    160 }
    161 
    162 
    163 struct pic_ops *
    164 setup_discovery_gpp_pic(void *discovery, int gpp_base)
    165 {
    166 	struct discovery_gpp_pic_ops *discovery_gpp;
    167 	struct pic_ops *pic;
    168 
    169 	discovery_gpp =
    170 	    malloc(sizeof(struct discovery_gpp_pic_ops), M_DEVBUF, M_NOWAIT);
    171 	KASSERT(discovery_gpp != NULL);
    172 
    173 	pic = &discovery_gpp->pic;
    174 	pic->pic_numintrs = 32;
    175 	pic->pic_cookie = discovery;
    176 	pic->pic_enable_irq = discovery_gpp_enable_irq;
    177 	pic->pic_reenable_irq = discovery_gpp_enable_irq;
    178 	pic->pic_disable_irq = discovery_gpp_disable_irq;
    179 	pic->pic_get_irq = discovery_gpp_get_irq;
    180 	pic->pic_ack_irq = discovery_gpp_ack_irq;
    181 	pic->pic_establish_irq = dummy_pic_establish_intr;
    182 	pic->pic_finish_setup = NULL;
    183 	strcpy(pic->pic_name, "discovery_gpp");
    184 	pic_add(pic);
    185 
    186 	discovery_gpp->gpp_base = gpp_base;
    187 
    188 	return pic;
    189 }
    190 
    191 static void
    192 discovery_gpp_enable_irq(struct pic_ops *pic, int irq, int type)
    193 {
    194 	struct discovery_gpp_pic_ops *discovery_gpp =
    195 	    (struct discovery_gpp_pic_ops *)pic;
    196 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    197 
    198 	discovery_gpp_enable_intr(discovery->pic.pic_cookie,
    199 	    discovery_gpp->gpp_base + irq);
    200 }
    201 
    202 static void
    203 discovery_gpp_disable_irq(struct pic_ops *pic, int irq)
    204 {
    205 	struct discovery_gpp_pic_ops *discovery_gpp =
    206 	    (struct discovery_gpp_pic_ops *)pic;
    207 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    208 
    209 	discovery_gpp_disable_intr(discovery->pic.pic_cookie,
    210 	    discovery_gpp->gpp_base + irq);
    211 }
    212 
    213 static int
    214 discovery_gpp_get_irq(struct pic_ops *pic, int mode)
    215 {
    216 	struct discovery_gpp_pic_ops *discovery_gpp =
    217 	    (struct discovery_gpp_pic_ops *)pic;
    218 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    219 	uint32_t cause, mask;
    220 	int irq, msk, base;
    221 
    222 	cause = discovery_gpp_cause(discovery->pic.pic_cookie);
    223 	mask = discovery_gpp_mask(discovery->pic.pic_cookie);
    224 
    225 	base = discovery_gpp->gpp_base;
    226 	cause &= (mask & (0xff << base));
    227 	if (!cause)
    228 		return 255;
    229 
    230 	for (irq = base, msk = (1 << base); !(cause & msk); irq++, msk <<= 1);
    231 
    232 	return irq;
    233 }
    234 
    235 static void
    236 discovery_gpp_ack_irq(struct pic_ops *pic, int irq)
    237 {
    238 	struct discovery_gpp_pic_ops *discovery_gpp =
    239 	    (struct discovery_gpp_pic_ops *)pic;
    240 	struct discovery_pic_ops *discovery = discovery_gpp->pic.pic_cookie;
    241 
    242 	discovery_gpp_clear_cause(discovery->pic.pic_cookie,
    243 	    discovery_gpp->gpp_base + irq);
    244 }
    245