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