Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.20
      1 /* $NetBSD: cpu.h,v 1.20 2020/02/12 06:05:46 riastradh 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 #include <sys/param.h>
     42 
     43 #if defined(_KERNEL) || defined(_KMEMUSER)
     44 #include <sys/evcnt.h>
     45 
     46 #include <aarch64/frame.h>
     47 #include <aarch64/armreg.h>
     48 
     49 struct clockframe {
     50 	struct trapframe cf_tf;
     51 };
     52 
     53 /* (spsr & 15) == SPSR_M_EL0T(64bit,0) or USER(32bit,0) */
     54 #define CLKF_USERMODE(cf)	((((cf)->cf_tf.tf_spsr) & 0x0f) == 0)
     55 #define CLKF_PC(cf)		((cf)->cf_tf.tf_pc)
     56 #define CLKF_INTR(cf)		((void)(cf), curcpu()->ci_intr_depth > 1)
     57 
     58 /*
     59  * LWP_PC: Find out the program counter for the given lwp.
     60  */
     61 #define LWP_PC(l)		((l)->l_md.md_utf->tf_pc)
     62 
     63 #include <sys/cpu_data.h>
     64 #include <sys/device_if.h>
     65 #include <sys/intr.h>
     66 
     67 struct aarch64_cpufuncs {
     68 	void (*cf_set_ttbr0)(uint64_t);
     69 };
     70 
     71 struct cpu_info {
     72 	struct cpu_data ci_data;
     73 	device_t ci_dev;
     74 	cpuid_t ci_cpuid;
     75 	struct lwp *ci_curlwp;
     76 	struct lwp *ci_onproc;
     77 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     78 
     79 	uint64_t ci_lastintr;
     80 
     81 	int ci_mtx_oldspl;
     82 	int ci_mtx_count;
     83 
     84 	int ci_want_resched;
     85 	int ci_cpl;
     86 	volatile u_int ci_softints;
     87 	volatile u_int ci_astpending;
     88 	volatile u_int ci_intr_depth;
     89 
     90 	/* event counters */
     91 	struct evcnt ci_vfp_use;
     92 	struct evcnt ci_vfp_reuse;
     93 	struct evcnt ci_vfp_save;
     94 	struct evcnt ci_vfp_release;
     95 
     96 	/* FDT or similar supplied "cpu capacity" */
     97 	uint32_t ci_capacity_dmips_mhz;
     98 
     99 	/* interrupt controller */
    100 	u_int ci_gic_redist;	/* GICv3 redistributor index */
    101 	uint64_t ci_gic_sgir;	/* GICv3 SGIR target */
    102 
    103 	/* ACPI */
    104 	uint64_t ci_acpiid;	/* ACPI Processor Unique ID */
    105 
    106 	struct aarch64_sysctl_cpu_id ci_id;
    107 #define arm_cpu_mpidr(ci)	((ci)->ci_id.ac_mpidr)
    108 
    109 	struct aarch64_cache_info *ci_cacheinfo;
    110 	struct aarch64_cpufuncs ci_cpufuncs;
    111 
    112 } __aligned(COHERENCY_UNIT);
    113 
    114 static inline struct cpu_info *
    115 curcpu(void)
    116 {
    117 	struct cpu_info *ci;
    118 	__asm __volatile ("mrs %0, tpidr_el1" : "=r"(ci));
    119 	return ci;
    120 }
    121 #define curlwp			(curcpu()->ci_curlwp)
    122 
    123 #define setsoftast(ci)		atomic_or_uint(&(ci)->ci_astpending, __BIT(0))
    124 #define cpu_signotify(l)	setsoftast((l)->l_cpu)
    125 
    126 void cpu_proc_fork(struct proc *, struct proc *);
    127 void cpu_need_proftick(struct lwp *l);
    128 void cpu_boot_secondary_processors(void);
    129 void cpu_mpstart(void);
    130 void cpu_hatch(struct cpu_info *);
    131 
    132 extern struct cpu_info *cpu_info[];
    133 extern uint64_t cpu_mpidr[];		/* MULTIPROCESSOR */
    134 bool cpu_hatched_p(u_int);		/* MULTIPROCESSOR */
    135 
    136 #define CPU_INFO_ITERATOR	cpuid_t
    137 #if defined(MULTIPROCESSOR) || defined(_MODULE)
    138 #define cpu_number()		(curcpu()->ci_index)
    139 #define CPU_IS_PRIMARY(ci)	((ci)->ci_index == 0)
    140 #define CPU_INFO_FOREACH(cii, ci)					\
    141 	cii = 0, ci = cpu_info[0];					\
    142 	cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL;	\
    143 	cii++
    144 #else /* MULTIPROCESSOR */
    145 #define cpu_number()		0
    146 #define CPU_IS_PRIMARY(ci)	true
    147 #define CPU_INFO_FOREACH(cii, ci)					\
    148 	cii = 0, __USE(cii), ci = curcpu(); ci != NULL; ci = NULL
    149 #endif /* MULTIPROCESSOR */
    150 
    151 
    152 static inline void
    153 cpu_dosoftints(void)
    154 {
    155 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
    156 	void dosoftints(void);
    157 	struct cpu_info * const ci = curcpu();
    158 
    159 	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
    160 		dosoftints();
    161 #endif
    162 }
    163 
    164 void	cpu_attach(device_t, cpuid_t);
    165 
    166 #endif /* _KERNEL || _KMEMUSER */
    167 
    168 #elif defined(__arm__)
    169 
    170 #include <arm/cpu.h>
    171 
    172 #endif
    173 
    174 #endif /* _AARCH64_CPU_H_ */
    175