Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.4
      1 /* $NetBSD: cpu.h,v 1.4 2018/07/21 13:08:35 ryo 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 #ifdef _KERNEL_OPT
     38 #include "opt_multiprocessor.h"
     39 #endif
     40 
     41 #if defined(_KERNEL) || defined(_KMEMUSER)
     42 #include <sys/evcnt.h>
     43 #include <aarch64/frame.h>
     44 
     45 struct clockframe {
     46 	struct trapframe cf_tf;
     47 };
     48 
     49 /* (spsr & 15) == SPSR_M_EL0T(64bit,0) or USER(32bit,0) */
     50 #define CLKF_USERMODE(cf)	((((cf)->cf_tf.tf_spsr) & 0x0f) == 0)
     51 #define CLKF_PC(cf)		((cf)->cf_tf.tf_pc)
     52 #define CLKF_INTR(cf)		((void)(cf), curcpu()->ci_intr_depth > 1)
     53 
     54 #include <sys/cpu_data.h>
     55 #include <sys/device_if.h>
     56 #include <sys/intr.h>
     57 
     58 struct cpu_info {
     59 	struct cpu_data ci_data;
     60 	device_t ci_dev;
     61 	cpuid_t ci_cpuid;
     62 	struct lwp *ci_curlwp;
     63 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     64 
     65 	uint64_t ci_lastintr;
     66 
     67 	int ci_mtx_oldspl;
     68 	int ci_mtx_count;
     69 
     70 	int ci_want_resched;
     71 	int ci_cpl;
     72 	volatile u_int ci_softints;
     73 	volatile u_int ci_astpending;
     74 	volatile u_int ci_intr_depth;
     75 
     76 	/* event counters */
     77 	struct evcnt ci_vfp_use;
     78 	struct evcnt ci_vfp_reuse;
     79 	struct evcnt ci_vfp_save;
     80 	struct evcnt ci_vfp_release;
     81 
     82 	/* per cpu pmap private */
     83 	uint64_t ci_pmap_flags;
     84 };
     85 
     86 static inline struct cpu_info *
     87 curcpu(void)
     88 {
     89 	struct cpu_info *ci;
     90 	__asm __volatile ("mrs %0, tpidr_el1" : "=r"(ci));
     91 	return ci;
     92 }
     93 #define curlwp			(curcpu()->ci_curlwp)
     94 
     95 #define setsoftast(ci)		atomic_or_uint(&(ci)->ci_astpending, __BIT(0))
     96 #define cpu_signotify(l)	setsoftast((l)->l_cpu)
     97 void cpu_set_curpri(int);
     98 void cpu_proc_fork(struct proc *, struct proc *);
     99 void cpu_need_proftick(struct lwp *l);
    100 void cpu_boot_secondary_processors(void);
    101 void cpu_hatch(struct cpu_info *);
    102 
    103 extern struct cpu_info *cpu_info[];
    104 extern volatile u_int arm_cpu_hatched;	/* MULTIPROCESSOR */
    105 extern uint32_t cpus_midr[];		/* MULTIPROCESSOR */
    106 extern uint64_t cpus_mpidr[];		/* MULTIPROCESSOR */
    107 
    108 #define CPU_INFO_ITERATOR	cpuid_t
    109 #ifdef MULTIPROCESSOR
    110 #define cpu_number()		(curcpu()->ci_index)
    111 #define CPU_IS_PRIMARY(ci)	((ci)->ci_index == 0)
    112 #define CPU_INFO_FOREACH(cii, ci)					\
    113 	cii = 0, ci = cpu_info[0];					\
    114 	cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL;	\
    115 	cii++
    116 #else /* MULTIPROCESSOR */
    117 #define cpu_number()		0
    118 #define CPU_IS_PRIMARY(ci)	true
    119 #define CPU_INFO_FOREACH(cii, ci)					\
    120 	cii = 0, __USE(cii), ci = curcpu(); ci != NULL; ci = NULL
    121 #endif /* MULTIPROCESSOR */
    122 
    123 
    124 static inline void
    125 cpu_dosoftints(void)
    126 {
    127 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
    128 	void dosoftints(void);
    129 	struct cpu_info * const ci = curcpu();
    130 
    131 	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
    132 		dosoftints();
    133 #endif
    134 }
    135 
    136 static inline bool
    137 cpu_intr_p(void)
    138 {
    139 #ifdef __HAVE_PIC_FAST_SOFTINTS
    140 	if (ci->ci_cpl < IPL_VM)
    141 		return false;
    142 #endif
    143 	return curcpu()->ci_intr_depth > 0;
    144 }
    145 
    146 void	cpu_attach(device_t, cpuid_t);
    147 
    148 #endif /* _KERNEL || _KMEMUSER */
    149 
    150 #elif defined(__arm__)
    151 
    152 #include <arm/cpu.h>
    153 
    154 #endif
    155 
    156 #endif /* _AARCH64_CPU_H_ */
    157