Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.1.28.6
      1  1.1.28.6  pgoyette /* $NetBSD: cpu.h,v 1.1.28.6 2018/11/26 01:52:16 pgoyette Exp $ */
      2       1.1      matt 
      3       1.1      matt /*-
      4       1.1      matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by Matt Thomas of 3am Software Foundry.
      9       1.1      matt  *
     10       1.1      matt  * Redistribution and use in source and binary forms, with or without
     11       1.1      matt  * modification, are permitted provided that the following conditions
     12       1.1      matt  * are met:
     13       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      matt  *    documentation and/or other materials provided with the distribution.
     18       1.1      matt  *
     19       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      matt  */
     31       1.1      matt 
     32       1.1      matt #ifndef _AARCH64_CPU_H_
     33       1.1      matt #define _AARCH64_CPU_H_
     34       1.1      matt 
     35       1.1      matt #ifdef __aarch64__
     36       1.1      matt 
     37  1.1.28.1  pgoyette #ifdef _KERNEL_OPT
     38  1.1.28.1  pgoyette #include "opt_multiprocessor.h"
     39  1.1.28.1  pgoyette #endif
     40  1.1.28.1  pgoyette 
     41  1.1.28.3  pgoyette #include <sys/param.h>
     42  1.1.28.3  pgoyette 
     43       1.1      matt #if defined(_KERNEL) || defined(_KMEMUSER)
     44  1.1.28.1  pgoyette #include <sys/evcnt.h>
     45  1.1.28.6  pgoyette 
     46  1.1.28.1  pgoyette #include <aarch64/frame.h>
     47  1.1.28.6  pgoyette #include <aarch64/armreg.h>
     48  1.1.28.1  pgoyette 
     49       1.1      matt struct clockframe {
     50  1.1.28.1  pgoyette 	struct trapframe cf_tf;
     51       1.1      matt };
     52       1.1      matt 
     53  1.1.28.1  pgoyette /* (spsr & 15) == SPSR_M_EL0T(64bit,0) or USER(32bit,0) */
     54  1.1.28.1  pgoyette #define CLKF_USERMODE(cf)	((((cf)->cf_tf.tf_spsr) & 0x0f) == 0)
     55  1.1.28.1  pgoyette #define CLKF_PC(cf)		((cf)->cf_tf.tf_pc)
     56  1.1.28.1  pgoyette #define CLKF_INTR(cf)		((void)(cf), curcpu()->ci_intr_depth > 1)
     57       1.1      matt 
     58  1.1.28.6  pgoyette /*
     59  1.1.28.6  pgoyette  * LWP_PC: Find out the program counter for the given lwp.
     60  1.1.28.6  pgoyette  */
     61  1.1.28.6  pgoyette #define LWP_PC(l)		((l)->l_md.md_utf->tf_pc)
     62  1.1.28.6  pgoyette 
     63       1.1      matt #include <sys/cpu_data.h>
     64       1.1      matt #include <sys/device_if.h>
     65       1.1      matt #include <sys/intr.h>
     66       1.1      matt 
     67       1.1      matt struct cpu_info {
     68       1.1      matt 	struct cpu_data ci_data;
     69       1.1      matt 	device_t ci_dev;
     70       1.1      matt 	cpuid_t ci_cpuid;
     71       1.1      matt 	struct lwp *ci_curlwp;
     72       1.1      matt 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     73       1.1      matt 
     74       1.1      matt 	uint64_t ci_lastintr;
     75       1.1      matt 
     76       1.1      matt 	int ci_mtx_oldspl;
     77       1.1      matt 	int ci_mtx_count;
     78       1.1      matt 
     79       1.1      matt 	int ci_want_resched;
     80       1.1      matt 	int ci_cpl;
     81  1.1.28.1  pgoyette 	volatile u_int ci_softints;
     82       1.1      matt 	volatile u_int ci_astpending;
     83       1.1      matt 	volatile u_int ci_intr_depth;
     84  1.1.28.1  pgoyette 
     85  1.1.28.1  pgoyette 	/* event counters */
     86  1.1.28.1  pgoyette 	struct evcnt ci_vfp_use;
     87  1.1.28.1  pgoyette 	struct evcnt ci_vfp_reuse;
     88  1.1.28.1  pgoyette 	struct evcnt ci_vfp_save;
     89  1.1.28.1  pgoyette 	struct evcnt ci_vfp_release;
     90  1.1.28.3  pgoyette 
     91  1.1.28.3  pgoyette 	/* interrupt controller */
     92  1.1.28.3  pgoyette 	u_int ci_gic_redist;	/* GICv3 redistributor index */
     93  1.1.28.3  pgoyette 	uint64_t ci_gic_sgir;	/* GICv3 SGIR target */
     94  1.1.28.3  pgoyette 
     95  1.1.28.5  pgoyette 	/* ACPI */
     96  1.1.28.5  pgoyette 	uint64_t ci_acpiid;	/* ACPI Processor Unique ID */
     97  1.1.28.5  pgoyette 
     98  1.1.28.6  pgoyette 	struct aarch64_sysctl_cpu_id ci_id;
     99  1.1.28.3  pgoyette 
    100  1.1.28.3  pgoyette 	struct aarch64_cache_info *ci_cacheinfo;
    101  1.1.28.3  pgoyette 
    102  1.1.28.3  pgoyette } __aligned(COHERENCY_UNIT);
    103       1.1      matt 
    104       1.1      matt static inline struct cpu_info *
    105       1.1      matt curcpu(void)
    106       1.1      matt {
    107       1.1      matt 	struct cpu_info *ci;
    108  1.1.28.1  pgoyette 	__asm __volatile ("mrs %0, tpidr_el1" : "=r"(ci));
    109       1.1      matt 	return ci;
    110       1.1      matt }
    111  1.1.28.1  pgoyette #define curlwp			(curcpu()->ci_curlwp)
    112       1.1      matt 
    113  1.1.28.1  pgoyette #define setsoftast(ci)		atomic_or_uint(&(ci)->ci_astpending, __BIT(0))
    114  1.1.28.1  pgoyette #define cpu_signotify(l)	setsoftast((l)->l_cpu)
    115  1.1.28.5  pgoyette 
    116  1.1.28.1  pgoyette void cpu_set_curpri(int);
    117  1.1.28.1  pgoyette void cpu_proc_fork(struct proc *, struct proc *);
    118  1.1.28.1  pgoyette void cpu_need_proftick(struct lwp *l);
    119  1.1.28.1  pgoyette void cpu_boot_secondary_processors(void);
    120  1.1.28.5  pgoyette void cpu_mpstart(void);
    121  1.1.28.2  pgoyette void cpu_hatch(struct cpu_info *);
    122  1.1.28.1  pgoyette 
    123  1.1.28.1  pgoyette extern struct cpu_info *cpu_info[];
    124  1.1.28.1  pgoyette extern volatile u_int arm_cpu_hatched;	/* MULTIPROCESSOR */
    125  1.1.28.4  pgoyette extern uint64_t cpu_mpidr[];		/* MULTIPROCESSOR */
    126       1.1      matt 
    127       1.1      matt #define CPU_INFO_ITERATOR	cpuid_t
    128  1.1.28.1  pgoyette #ifdef MULTIPROCESSOR
    129  1.1.28.1  pgoyette #define cpu_number()		(curcpu()->ci_index)
    130  1.1.28.1  pgoyette #define CPU_IS_PRIMARY(ci)	((ci)->ci_index == 0)
    131  1.1.28.2  pgoyette #define CPU_INFO_FOREACH(cii, ci)					\
    132  1.1.28.2  pgoyette 	cii = 0, ci = cpu_info[0];					\
    133  1.1.28.2  pgoyette 	cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL;	\
    134  1.1.28.1  pgoyette 	cii++
    135  1.1.28.1  pgoyette #else /* MULTIPROCESSOR */
    136  1.1.28.1  pgoyette #define cpu_number()		0
    137  1.1.28.1  pgoyette #define CPU_IS_PRIMARY(ci)	true
    138  1.1.28.2  pgoyette #define CPU_INFO_FOREACH(cii, ci)					\
    139  1.1.28.1  pgoyette 	cii = 0, __USE(cii), ci = curcpu(); ci != NULL; ci = NULL
    140  1.1.28.1  pgoyette #endif /* MULTIPROCESSOR */
    141  1.1.28.1  pgoyette 
    142       1.1      matt 
    143       1.1      matt static inline void
    144       1.1      matt cpu_dosoftints(void)
    145       1.1      matt {
    146  1.1.28.1  pgoyette #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
    147  1.1.28.1  pgoyette 	void dosoftints(void);
    148  1.1.28.1  pgoyette 	struct cpu_info * const ci = curcpu();
    149  1.1.28.1  pgoyette 
    150  1.1.28.1  pgoyette 	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
    151  1.1.28.1  pgoyette 		dosoftints();
    152  1.1.28.1  pgoyette #endif
    153       1.1      matt }
    154       1.1      matt 
    155       1.1      matt static inline bool
    156       1.1      matt cpu_intr_p(void)
    157       1.1      matt {
    158  1.1.28.1  pgoyette #ifdef __HAVE_PIC_FAST_SOFTINTS
    159  1.1.28.1  pgoyette 	if (ci->ci_cpl < IPL_VM)
    160  1.1.28.1  pgoyette 		return false;
    161  1.1.28.1  pgoyette #endif
    162       1.1      matt 	return curcpu()->ci_intr_depth > 0;
    163       1.1      matt }
    164       1.1      matt 
    165  1.1.28.1  pgoyette void	cpu_attach(device_t, cpuid_t);
    166  1.1.28.1  pgoyette 
    167       1.1      matt #endif /* _KERNEL || _KMEMUSER */
    168       1.1      matt 
    169       1.1      matt #elif defined(__arm__)
    170       1.1      matt 
    171       1.1      matt #include <arm/cpu.h>
    172       1.1      matt 
    173       1.1      matt #endif
    174       1.1      matt 
    175       1.1      matt #endif /* _AARCH64_CPU_H_ */
    176