Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.4.20.1
      1  1.4.20.1  christos /* $NetBSD: cpu.h,v 1.4.20.1 2019/06/10 22:06:41 christos 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 _RISCV_CPU_H_
     33       1.1      matt #define _RISCV_CPU_H_
     34       1.1      matt 
     35       1.1      matt #if defined(_KERNEL) || defined(_KMEMUSER)
     36       1.4      matt 
     37       1.1      matt struct clockframe {
     38       1.1      matt 	uintptr_t cf_pc;
     39       1.1      matt 	uint32_t cf_sr;
     40       1.1      matt 	int cf_intr_depth;
     41       1.1      matt };
     42       1.1      matt 
     43       1.1      matt #define CLKF_USERMODE(cf)	(((cf)->cf_sr & 1) == 0)
     44       1.1      matt #define CLKF_PC(cf)		((cf)->cf_pc)
     45       1.1      matt #define CLKF_INTR(cf)		((cf)->cf_intr_depth > 0)
     46       1.1      matt 
     47       1.1      matt #include <sys/cpu_data.h>
     48       1.1      matt #include <sys/device_if.h>
     49       1.1      matt #include <sys/evcnt.h>
     50       1.1      matt #include <sys/intr.h>
     51       1.1      matt 
     52       1.1      matt struct cpu_info {
     53       1.1      matt 	struct cpu_data ci_data;
     54       1.1      matt 	device_t ci_dev;
     55       1.1      matt 	cpuid_t ci_cpuid;
     56       1.1      matt 	struct lwp *ci_curlwp;
     57       1.1      matt 	struct lwp *ci_softlwps[SOFTINT_COUNT];
     58       1.1      matt 	struct trapframe *ci_ddb_regs;
     59       1.1      matt 
     60       1.1      matt 	uint64_t ci_lastintr;
     61       1.1      matt 
     62       1.1      matt 	int ci_mtx_oldspl;
     63       1.1      matt 	int ci_mtx_count;
     64       1.1      matt 
     65       1.1      matt 	int ci_want_resched;
     66       1.1      matt 	int ci_cpl;
     67       1.1      matt 	u_int ci_softints;
     68       1.1      matt 	volatile u_int ci_intr_depth;
     69       1.1      matt 
     70       1.1      matt 	tlb_asid_t ci_pmap_asid_cur;
     71  1.4.20.1  christos 
     72  1.4.20.1  christos 	union pmap_segtab *ci_pmap_user_segtab;
     73       1.1      matt #ifdef _LP64
     74  1.4.20.1  christos 	union pmap_segtab *ci_pmap_user_seg0tab;
     75       1.1      matt #endif
     76       1.1      matt 
     77       1.1      matt 	struct evcnt ci_ev_fpu_saves;
     78       1.1      matt 	struct evcnt ci_ev_fpu_loads;
     79       1.1      matt 	struct evcnt ci_ev_fpu_reenables;
     80       1.1      matt };
     81       1.1      matt 
     82       1.4      matt #endif /* _KERNEL || _KMEMUSER */
     83       1.4      matt 
     84       1.4      matt #ifdef _KERNEL
     85       1.4      matt 
     86       1.1      matt extern struct cpu_info cpu_info_store;
     87       1.1      matt 
     88       1.3      matt // This is also in <sys/lwp.h>
     89       1.3      matt struct lwp;
     90       1.3      matt static inline struct cpu_info *lwp_getcpu(struct lwp *);
     91       1.3      matt 
     92       1.2      matt register struct lwp *riscv_curlwp __asm("tp");
     93       1.1      matt #define	curlwp		riscv_curlwp
     94       1.3      matt #define	curcpu()	lwp_getcpu(curlwp)
     95       1.1      matt 
     96       1.1      matt static inline cpuid_t
     97       1.1      matt cpu_number(void)
     98       1.1      matt {
     99       1.1      matt #ifdef MULTIPROCESSOR
    100       1.1      matt 	return curcpu()->ci_cpuid;
    101       1.1      matt #else
    102       1.1      matt 	return 0;
    103       1.1      matt #endif
    104       1.1      matt }
    105       1.1      matt 
    106       1.1      matt void	cpu_set_curpri(int);
    107       1.1      matt void	cpu_proc_fork(struct proc *, struct proc *);
    108       1.1      matt void	cpu_signotify(struct lwp *);
    109       1.1      matt void	cpu_need_proftick(struct lwp *l);
    110       1.1      matt void	cpu_boot_secondary_processors(void);
    111       1.1      matt 
    112       1.1      matt #define CPU_INFO_ITERATOR	cpuid_t
    113       1.1      matt #ifdef MULTIPROCESSOR
    114       1.1      matt #define CPU_INFO_FOREACH(cii, ci) \
    115       1.1      matt 	(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
    116       1.1      matt #else
    117       1.1      matt #define CPU_INFO_FOREACH(cii, ci) \
    118       1.1      matt 	(cii) = 0, (ci) = curcpu(); (cii) == 0; (cii)++
    119       1.1      matt #endif
    120       1.1      matt 
    121       1.1      matt #define CPU_INFO_CURPMAP(ci)	(curlwp->l_proc->p_vmspace->vm_map.pmap)
    122       1.1      matt 
    123       1.1      matt static inline void
    124       1.1      matt cpu_dosoftints(void)
    125       1.1      matt {
    126       1.1      matt 	extern void dosoftints(void);
    127       1.1      matt         struct cpu_info * const ci = curcpu();
    128       1.1      matt         if (ci->ci_intr_depth == 0
    129       1.1      matt 	    && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
    130       1.1      matt                 dosoftints();
    131       1.1      matt }
    132       1.1      matt 
    133       1.1      matt static inline bool
    134       1.1      matt cpu_intr_p(void)
    135       1.1      matt {
    136       1.1      matt 	return curcpu()->ci_intr_depth > 0;
    137       1.1      matt }
    138       1.1      matt 
    139       1.1      matt #define LWP_PC(l)	cpu_lwp_pc(l)
    140       1.1      matt 
    141       1.1      matt vaddr_t	cpu_lwp_pc(struct lwp *);
    142       1.1      matt 
    143       1.1      matt static inline void
    144       1.1      matt cpu_idle(void)
    145       1.1      matt {
    146       1.1      matt }
    147       1.1      matt 
    148       1.4      matt #endif /* _KERNEL */
    149       1.1      matt 
    150       1.1      matt #endif /* _RISCV_CPU_H_ */
    151