Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.1
      1 /* $NetBSD: cpu.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matt Thomas of 3am Software Foundry.
      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 #ifndef _AARCH64_CPU_H_
     33 #define _AARCH64_CPU_H_
     34 
     35 #ifdef __aarch64__
     36 
     37 #if defined(_KERNEL) || defined(_KMEMUSER)
     38 struct clockframe {
     39 	uintptr_t cf_pc;
     40 	uint32_t cf_psr;
     41 	int cf_intr_depth;
     42 };
     43 
     44 #define CLKF_USERMODE(cf)	(((cf)->cf_psr & 0x0f) == 0)
     45 #define CLKF_PC(cf)		((cf)->cf_pc)
     46 #define CLKF_INTR(cf)		((cf)->cf_intr_depth > 0)
     47 
     48 #include <sys/cpu_data.h>
     49 #include <sys/device_if.h>
     50 #include <sys/intr.h>
     51 
     52 struct cpu_info {
     53 	struct cpu_data ci_data;
     54 	device_t ci_dev;
     55 	cpuid_t ci_cpuid;
     56 	cpuid_t ci_gicid;		// used for IPIs
     57 	struct lwp *ci_curlwp;
     58 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     59 
     60 	uint64_t ci_lastintr;
     61 
     62 	int ci_mtx_oldspl;
     63 	int ci_mtx_count;
     64 
     65 	int ci_want_resched;
     66 	int ci_cpl;
     67 	u_int ci_softints;
     68 	volatile u_int ci_astpending;
     69 	volatile u_int ci_intr_depth;
     70 };
     71 
     72 static inline struct cpu_info *
     73 curcpu(void)
     74 {
     75 	struct cpu_info *ci;
     76 	__asm __volatile("mrs %0, tpidr_el1" : "=r"(ci));
     77 	return ci;
     78 }
     79 
     80 #define curlwp		(curcpu()->ci_curlwp)
     81 
     82 static inline cpuid_t
     83 cpu_number(void)
     84 {
     85 	return curcpu()->ci_gicid;
     86 }
     87 
     88 void	cpu_set_curpri(int);
     89 void	cpu_proc_fork(struct proc *, struct proc *);
     90 void	cpu_signotify(struct lwp *);
     91 void	cpu_need_proftick(struct lwp *l);
     92 void	cpu_boot_secondary_processors(void);
     93 
     94 #define CPU_INFO_ITERATOR	cpuid_t
     95 #define CPU_INFO_FOREACH(cii, ci) \
     96 	(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
     97 
     98 static inline void
     99 cpu_dosoftints(void)
    100 {
    101 	extern void dosoftints(void);
    102         struct cpu_info * const ci = curcpu();
    103         if (ci->ci_intr_depth == 0
    104 	    && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
    105                 dosoftints();
    106 }
    107 
    108 static inline bool
    109 cpu_intr_p(void)
    110 {
    111 	return curcpu()->ci_intr_depth > 0;
    112 }
    113 
    114 #endif /* _KERNEL || _KMEMUSER */
    115 
    116 #elif defined(__arm__)
    117 
    118 #include <arm/cpu.h>
    119 
    120 #endif
    121 
    122 #endif /* _AARCH64_CPU_H_ */
    123