1 /* $NetBSD: pic_bebox.c,v 1.12 2020/11/18 03:46:25 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Tim Rightnour 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: pic_bebox.c,v 1.12 2020/11/18 03:46:25 thorpej Exp $"); 34 35 #include "opt_multiprocessor.h" 36 37 #include <sys/param.h> 38 #include <sys/kmem.h> 39 #include <sys/kernel.h> 40 41 #include <uvm/uvm_extern.h> 42 43 #include <machine/bebox.h> 44 #include <machine/pio.h> 45 46 #include <arch/powerpc/pic/picvar.h> 47 48 49 static void bebox_enable_irq(struct pic_ops *, int, int); 50 static void bebox_disable_irq(struct pic_ops *, int); 51 static int bebox_get_irq(struct pic_ops *, int); 52 static void bebox_ack_irq(struct pic_ops *, int); 53 struct pic_ops * setup_bebox_intr(void); 54 55 struct pic_ops * 56 setup_bebox_intr(void) 57 { 58 struct pic_ops *pic; 59 60 pic = kmem_alloc(sizeof(struct pic_ops), KM_SLEEP); 61 pic->pic_numintrs = 32; 62 pic->pic_cookie = (void *)BEBOX_REG; 63 pic->pic_enable_irq = bebox_enable_irq; 64 pic->pic_reenable_irq = bebox_enable_irq; 65 pic->pic_disable_irq = bebox_disable_irq; 66 pic->pic_get_irq = bebox_get_irq; 67 pic->pic_ack_irq = bebox_ack_irq; 68 pic->pic_establish_irq = dummy_pic_establish_intr; 69 strcpy(pic->pic_name, "bebox"); 70 pic_add(pic); 71 72 #ifdef MULTIPROCESSOR 73 setup_bebox_ipi(); 74 #endif 75 76 return(pic); 77 } 78 79 static void 80 bebox_enable_irq(struct pic_ops *pic, int irq, int type) 81 { 82 83 SET_BEBOX_REG(CPU0_INT_MASK, 1 << (31 - irq)); 84 } 85 86 static void 87 bebox_disable_irq(struct pic_ops *pic, int irq) 88 { 89 90 CLEAR_BEBOX_REG(CPU0_INT_MASK, 1 << (31 - irq)); 91 } 92 93 static int 94 bebox_get_irq(struct pic_ops *pic, int mode) 95 { 96 unsigned int state; 97 98 state = READ_BEBOX_REG(INT_SOURCE); 99 state &= BEBOX_INTR_MASK; 100 state &= READ_BEBOX_REG(CPU0_INT_MASK); 101 if (state == 0) 102 return 255; 103 return __builtin_clz(state); 104 } 105 106 static void 107 bebox_ack_irq(struct pic_ops *pic, int irq) 108 { 109 /* do nothing */ 110 } 111