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