Home | History | Annotate | Line # | Download | only in pic
pic_splfuncs.c revision 1.4.2.2
      1  1.4.2.1       tls /*	$NetBSD: pic_splfuncs.c,v 1.4.2.2 2017/12/03 11:35:55 jdolecek Exp $	*/
      2      1.1       bsh /*-
      3      1.1       bsh  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      4      1.1       bsh  * All rights reserved.
      5      1.1       bsh  *
      6      1.1       bsh  * This code is derived from software contributed to The NetBSD Foundation
      7      1.1       bsh  * by Matt Thomas.
      8      1.1       bsh  *
      9      1.1       bsh  * Redistribution and use in source and binary forms, with or without
     10      1.1       bsh  * modification, are permitted provided that the following conditions
     11      1.1       bsh  * are met:
     12      1.1       bsh  * 1. Redistributions of source code must retain the above copyright
     13      1.1       bsh  *    notice, this list of conditions and the following disclaimer.
     14      1.1       bsh  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1       bsh  *    notice, this list of conditions and the following disclaimer in the
     16      1.1       bsh  *    documentation and/or other materials provided with the distribution.
     17      1.1       bsh  *
     18      1.1       bsh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19      1.1       bsh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20      1.1       bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21      1.1       bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22      1.1       bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23      1.1       bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24      1.1       bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25      1.1       bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26      1.1       bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27      1.1       bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28      1.1       bsh  * POSSIBILITY OF SUCH DAMAGE.
     29      1.1       bsh  */
     30      1.1       bsh #include <sys/cdefs.h>
     31  1.4.2.1       tls __KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.4.2.2 2017/12/03 11:35:55 jdolecek Exp $");
     32      1.1       bsh 
     33      1.1       bsh #define _INTR_PRIVATE
     34      1.1       bsh #include <sys/param.h>
     35      1.4      matt #include <sys/atomic.h>
     36      1.1       bsh #include <sys/evcnt.h>
     37  1.4.2.2  jdolecek #include <sys/lwp.h>
     38      1.4      matt #include <sys/kernel.h>
     39      1.4      matt 
     40      1.4      matt #include <dev/cons.h>
     41      1.1       bsh 
     42  1.4.2.2  jdolecek #if defined(__arm__)
     43      1.1       bsh #include <arm/armreg.h>
     44      1.1       bsh #include <arm/cpu.h>
     45      1.1       bsh #include <arm/cpufunc.h>
     46  1.4.2.2  jdolecek #elif defined(__aarch64__)
     47  1.4.2.2  jdolecek #include <aarch64/locore.h>
     48  1.4.2.2  jdolecek #define I32_bit		DAIF_I
     49  1.4.2.2  jdolecek #define F32_bit		DAIF_F
     50  1.4.2.2  jdolecek #endif
     51      1.1       bsh 
     52      1.1       bsh #include <arm/pic/picvar.h>
     53      1.1       bsh 
     54      1.1       bsh 
     55      1.1       bsh int
     56      1.1       bsh _splraise(int newipl)
     57      1.1       bsh {
     58      1.1       bsh 	struct cpu_info * const ci = curcpu();
     59      1.1       bsh 	const int oldipl = ci->ci_cpl;
     60      1.1       bsh 	KASSERT(newipl < NIPL);
     61      1.3      matt 	if (newipl > ci->ci_cpl) {
     62      1.3      matt 		pic_set_priority(ci, newipl);
     63      1.3      matt 	}
     64      1.1       bsh 	return oldipl;
     65      1.1       bsh }
     66      1.1       bsh int
     67      1.1       bsh _spllower(int newipl)
     68      1.1       bsh {
     69      1.1       bsh 	struct cpu_info * const ci = curcpu();
     70      1.1       bsh 	const int oldipl = ci->ci_cpl;
     71      1.1       bsh 	KASSERT(panicstr || newipl <= ci->ci_cpl);
     72      1.1       bsh 	if (newipl < ci->ci_cpl) {
     73      1.4      matt 		register_t psw = cpsid(I32_bit);
     74      1.2  jakllsch 		ci->ci_intr_depth++;
     75      1.1       bsh 		pic_do_pending_ints(psw, newipl, NULL);
     76      1.2  jakllsch 		ci->ci_intr_depth--;
     77  1.4.2.2  jdolecek 		if ((psw & I32_bit) == 0 || newipl == IPL_NONE)
     78      1.4      matt 			cpsie(I32_bit);
     79      1.4      matt 		cpu_dosoftints();
     80      1.1       bsh 	}
     81      1.1       bsh 	return oldipl;
     82      1.1       bsh }
     83      1.1       bsh 
     84      1.1       bsh void
     85      1.1       bsh splx(int savedipl)
     86      1.1       bsh {
     87      1.1       bsh 	struct cpu_info * const ci = curcpu();
     88      1.1       bsh 	KASSERT(savedipl < NIPL);
     89      1.4      matt 
     90      1.4      matt 	if (__predict_false(savedipl == ci->ci_cpl)) {
     91      1.4      matt 		return;
     92      1.1       bsh 	}
     93      1.4      matt 
     94      1.4      matt 	register_t psw = cpsid(I32_bit);
     95      1.4      matt 	KASSERTMSG(panicstr != NULL || savedipl < ci->ci_cpl,
     96      1.4      matt 	    "splx(%d) to a higher ipl than %d", savedipl, ci->ci_cpl);
     97      1.4      matt 
     98      1.4      matt 	ci->ci_intr_depth++;
     99      1.4      matt 	pic_do_pending_ints(psw, savedipl, NULL);
    100      1.4      matt 	ci->ci_intr_depth--;
    101      1.4      matt 	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
    102      1.4      matt 	    ci->ci_cpl, savedipl);
    103      1.4      matt 	if ((psw & I32_bit) == 0)
    104      1.4      matt 		cpsie(I32_bit);
    105  1.4.2.1       tls 	cpu_dosoftints();
    106      1.4      matt 	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
    107      1.4      matt 	    ci->ci_cpl, savedipl);
    108      1.1       bsh }
    109