Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.1.4.2
      1  1.1.4.2  tls /* $NetBSD: cpu.h,v 1.1.4.2 2014/08/20 00:02:39 tls Exp $ */
      2  1.1.4.2  tls 
      3  1.1.4.2  tls /*-
      4  1.1.4.2  tls  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  1.1.4.2  tls  * All rights reserved.
      6  1.1.4.2  tls  *
      7  1.1.4.2  tls  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.4.2  tls  * by Matt Thomas of 3am Software Foundry.
      9  1.1.4.2  tls  *
     10  1.1.4.2  tls  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  tls  * modification, are permitted provided that the following conditions
     12  1.1.4.2  tls  * are met:
     13  1.1.4.2  tls  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  tls  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  tls  *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  tls  *
     19  1.1.4.2  tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.4.2  tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.4.2  tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.4.2  tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.4.2  tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.4.2  tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.4.2  tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.4.2  tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.4.2  tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.4.2  tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.4.2  tls  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.4.2  tls  */
     31  1.1.4.2  tls 
     32  1.1.4.2  tls #ifndef _AARCH64_CPU_H_
     33  1.1.4.2  tls #define _AARCH64_CPU_H_
     34  1.1.4.2  tls 
     35  1.1.4.2  tls #ifdef __aarch64__
     36  1.1.4.2  tls 
     37  1.1.4.2  tls #if defined(_KERNEL) || defined(_KMEMUSER)
     38  1.1.4.2  tls struct clockframe {
     39  1.1.4.2  tls 	uintptr_t cf_pc;
     40  1.1.4.2  tls 	uint32_t cf_psr;
     41  1.1.4.2  tls 	int cf_intr_depth;
     42  1.1.4.2  tls };
     43  1.1.4.2  tls 
     44  1.1.4.2  tls #define CLKF_USERMODE(cf)	(((cf)->cf_psr & 0x0f) == 0)
     45  1.1.4.2  tls #define CLKF_PC(cf)		((cf)->cf_pc)
     46  1.1.4.2  tls #define CLKF_INTR(cf)		((cf)->cf_intr_depth > 0)
     47  1.1.4.2  tls 
     48  1.1.4.2  tls #include <sys/cpu_data.h>
     49  1.1.4.2  tls #include <sys/device_if.h>
     50  1.1.4.2  tls #include <sys/intr.h>
     51  1.1.4.2  tls 
     52  1.1.4.2  tls struct cpu_info {
     53  1.1.4.2  tls 	struct cpu_data ci_data;
     54  1.1.4.2  tls 	device_t ci_dev;
     55  1.1.4.2  tls 	cpuid_t ci_cpuid;
     56  1.1.4.2  tls 	cpuid_t ci_gicid;		// used for IPIs
     57  1.1.4.2  tls 	struct lwp *ci_curlwp;
     58  1.1.4.2  tls 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     59  1.1.4.2  tls 
     60  1.1.4.2  tls 	uint64_t ci_lastintr;
     61  1.1.4.2  tls 
     62  1.1.4.2  tls 	int ci_mtx_oldspl;
     63  1.1.4.2  tls 	int ci_mtx_count;
     64  1.1.4.2  tls 
     65  1.1.4.2  tls 	int ci_want_resched;
     66  1.1.4.2  tls 	int ci_cpl;
     67  1.1.4.2  tls 	u_int ci_softints;
     68  1.1.4.2  tls 	volatile u_int ci_astpending;
     69  1.1.4.2  tls 	volatile u_int ci_intr_depth;
     70  1.1.4.2  tls };
     71  1.1.4.2  tls 
     72  1.1.4.2  tls static inline struct cpu_info *
     73  1.1.4.2  tls curcpu(void)
     74  1.1.4.2  tls {
     75  1.1.4.2  tls 	struct cpu_info *ci;
     76  1.1.4.2  tls 	__asm __volatile("mrs %0, tpidr_el1" : "=r"(ci));
     77  1.1.4.2  tls 	return ci;
     78  1.1.4.2  tls }
     79  1.1.4.2  tls 
     80  1.1.4.2  tls #define curlwp		(curcpu()->ci_curlwp)
     81  1.1.4.2  tls 
     82  1.1.4.2  tls static inline cpuid_t
     83  1.1.4.2  tls cpu_number(void)
     84  1.1.4.2  tls {
     85  1.1.4.2  tls 	return curcpu()->ci_gicid;
     86  1.1.4.2  tls }
     87  1.1.4.2  tls 
     88  1.1.4.2  tls void	cpu_set_curpri(int);
     89  1.1.4.2  tls void	cpu_proc_fork(struct proc *, struct proc *);
     90  1.1.4.2  tls void	cpu_signotify(struct lwp *);
     91  1.1.4.2  tls void	cpu_need_proftick(struct lwp *l);
     92  1.1.4.2  tls void	cpu_boot_secondary_processors(void);
     93  1.1.4.2  tls 
     94  1.1.4.2  tls #define CPU_INFO_ITERATOR	cpuid_t
     95  1.1.4.2  tls #define CPU_INFO_FOREACH(cii, ci) \
     96  1.1.4.2  tls 	(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
     97  1.1.4.2  tls 
     98  1.1.4.2  tls static inline void
     99  1.1.4.2  tls cpu_dosoftints(void)
    100  1.1.4.2  tls {
    101  1.1.4.2  tls 	extern void dosoftints(void);
    102  1.1.4.2  tls         struct cpu_info * const ci = curcpu();
    103  1.1.4.2  tls         if (ci->ci_intr_depth == 0
    104  1.1.4.2  tls 	    && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
    105  1.1.4.2  tls                 dosoftints();
    106  1.1.4.2  tls }
    107  1.1.4.2  tls 
    108  1.1.4.2  tls static inline bool
    109  1.1.4.2  tls cpu_intr_p(void)
    110  1.1.4.2  tls {
    111  1.1.4.2  tls 	return curcpu()->ci_intr_depth > 0;
    112  1.1.4.2  tls }
    113  1.1.4.2  tls 
    114  1.1.4.2  tls #endif /* _KERNEL || _KMEMUSER */
    115  1.1.4.2  tls 
    116  1.1.4.2  tls #elif defined(__arm__)
    117  1.1.4.2  tls 
    118  1.1.4.2  tls #include <arm/cpu.h>
    119  1.1.4.2  tls 
    120  1.1.4.2  tls #endif
    121  1.1.4.2  tls 
    122  1.1.4.2  tls #endif /* _AARCH64_CPU_H_ */
    123