The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/arm/fiq.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: fiq.c,v 1.5 2002/04/03 23:33:27 thorpej Exp $  */
    2 
    3 /*-
    4  * SPDX-License-Identifier: BSD-4-Clause
    5  *
    6  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
    7  * All rights reserved.
    8  *
    9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed for the NetBSD Project by
   22  *      Wasabi Systems, Inc.
   23  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   24  *    or promote products derived from this software without specific prior
   25  *    written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL 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 __FBSDID("$FreeBSD$");
   42 
   43 #include <sys/param.h>
   44 #include <sys/systm.h>
   45 
   46 #include <machine/armreg.h>
   47 #include <machine/cpufunc.h>
   48 #include <machine/fiq.h>
   49 #include <vm/vm.h>
   50 #include <machine/pcb.h>
   51 #include <vm/pmap.h>
   52 #include <machine/cpu.h>
   53 
   54 TAILQ_HEAD(, fiqhandler) fiqhandler_stack =
   55     TAILQ_HEAD_INITIALIZER(fiqhandler_stack);
   56 
   57 extern char *fiq_nullhandler_code;
   58 extern uint32_t fiq_nullhandler_size;
   59 
   60 /*
   61  * fiq_installhandler:
   62  *
   63  *      Actually install the FIQ handler down at the FIQ vector.
   64  *
   65  *      The FIQ vector is fixed by the hardware definition as the
   66  *      seventh 32-bit word in the vector page.
   67  *
   68  *      Note: If the FIQ is invoked via an extra layer of
   69  *      indirection, the actual FIQ code store lives in the
   70  *      data segment, so there is no need to manipulate
   71  *      the vector page's protection.
   72  */
   73 static void
   74 fiq_installhandler(void *func, size_t size)
   75 {
   76         const uint32_t fiqvector = 7 * sizeof(uint32_t);
   77 
   78         memcpy((void *)(vector_page + fiqvector), func, size);
   79         icache_sync((vm_offset_t) fiqvector, size);
   80 }
   81 
   82 /*
   83  * fiq_claim:
   84  *
   85  *      Claim the FIQ vector.
   86  */
   87 int
   88 fiq_claim(struct fiqhandler *fh)
   89 {
   90         struct fiqhandler *ofh;
   91         u_int oldirqstate;
   92         int error = 0;
   93 
   94         if (fh->fh_size > 0x100)
   95                 return (EFBIG);
   96 
   97         oldirqstate = disable_interrupts(PSR_F);
   98 
   99         if ((ofh = TAILQ_FIRST(&fiqhandler_stack)) != NULL) {
  100                 if ((ofh->fh_flags & FH_CANPUSH) == 0) {
  101                         error = EBUSY;
  102                         goto out;
  103                 }
  104 
  105                 /* Save the previous FIQ handler's registers. */
  106                 if (ofh->fh_regs != NULL)
  107                         fiq_getregs(ofh->fh_regs);
  108         }
  109 
  110         /* Set FIQ mode registers to ours. */
  111         if (fh->fh_regs != NULL)
  112                 fiq_setregs(fh->fh_regs);
  113 
  114         TAILQ_INSERT_HEAD(&fiqhandler_stack, fh, fh_list);
  115 
  116         /* Now copy the actual handler into place. */
  117         fiq_installhandler(fh->fh_func, fh->fh_size);
  118 
  119         /* Make sure FIQs are enabled when we return. */
  120         oldirqstate &= ~PSR_F;
  121 
  122  out:
  123         restore_interrupts(oldirqstate);
  124         return (error);
  125 }
  126 
  127 /*
  128  * fiq_release:
  129  *
  130  *      Release the FIQ vector.
  131  */
  132 void
  133 fiq_release(struct fiqhandler *fh)
  134 {
  135         u_int oldirqstate;
  136         struct fiqhandler *ofh;
  137 
  138         oldirqstate = disable_interrupts(PSR_F);
  139 
  140         /*
  141          * If we are the currently active FIQ handler, then we
  142          * need to save our registers and pop the next one back
  143          * into the vector.
  144          */
  145         if (fh == TAILQ_FIRST(&fiqhandler_stack)) {
  146                 if (fh->fh_regs != NULL)
  147                         fiq_getregs(fh->fh_regs);
  148                 TAILQ_REMOVE(&fiqhandler_stack, fh, fh_list);
  149                 if ((ofh = TAILQ_FIRST(&fiqhandler_stack)) != NULL) {
  150                         if (ofh->fh_regs != NULL)
  151                                 fiq_setregs(ofh->fh_regs);
  152                         fiq_installhandler(ofh->fh_func, ofh->fh_size);
  153                 }
  154         } else
  155                 TAILQ_REMOVE(&fiqhandler_stack, fh, fh_list);
  156 
  157         if (TAILQ_FIRST(&fiqhandler_stack) == NULL) {
  158                 /* Copy the NULL handler back down into the vector. */
  159                 fiq_installhandler(fiq_nullhandler_code, fiq_nullhandler_size);
  160 
  161                 /* Make sure FIQs are disabled when we return. */
  162                 oldirqstate |= PSR_F;
  163         }
  164 
  165         restore_interrupts(oldirqstate);
  166 }

Cache object: f98090bb8c0e8390d2c9c7810f77d577


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.