#ifndef _CPU_H_
#define _CPU_H_
#ifdef _LOCORE
#error Use assym.h to get definitions from <mips/cpu.h>
#endif
#if defined(_KERNEL) || defined(_KMEMUSER)
#if defined(_KERNEL_OPT)
#include "opt_cputype.h"
#include "opt_gprof.h"
#include "opt_lockdebug.h"
#include "opt_multiprocessor.h"
#endif
#include <mips/frame.h>
#include <sys/cpu_data.h>
#include <sys/device_if.h>
#include <sys/evcnt.h>
#include <sys/kcpuset.h>
#include <sys/intr.h>
typedef struct cpu_watchpoint {
register_t cw_addr;
register_t cw_mask;
uint32_t cw_asid;
uint32_t cw_mode;
} cpu_watchpoint_t;
#define CPUWATCH_WRITE __BIT(0)
#define CPUWATCH_READ __BIT(1)
#define CPUWATCH_EXEC __BIT(2)
#define CPUWATCH_MASK __BIT(3)
#define CPUWATCH_ASID __BIT(4)
#define CPUWATCH_RWX (CPUWATCH_EXEC|CPUWATCH_READ|CPUWATCH_WRITE)
#define CPUWATCH_MAX 8
u_int cpuwatch_discover(void);
void cpuwatch_free(cpu_watchpoint_t *);
cpu_watchpoint_t *cpuwatch_alloc(void);
void cpuwatch_set_all(void);
void cpuwatch_clr_all(void);
void cpuwatch_set(cpu_watchpoint_t *);
void cpuwatch_clr(cpu_watchpoint_t *);
struct cpu_info {
struct cpu_data ci_data;
void *ci_nmi_stack;
struct cpu_softc *ci_softc;
device_t ci_dev;
cpuid_t ci_cpuid;
u_long ci_cctr_freq;
u_long ci_cpu_freq;
u_long ci_cycles_per_hz;
u_long ci_divisor_delay;
u_long ci_divisor_recip;
struct lwp *ci_curlwp;
struct lwp *ci_onproc;
volatile int ci_want_resched;
int ci_mtx_count;
int ci_mtx_oldspl;
int ci_idepth;
int ci_cpl;
uint32_t ci_next_cp0_clk_intr;
struct evcnt ci_ev_count_compare;
struct evcnt ci_ev_count_compare_missed;
struct lwp *ci_softlwps[SOFTINT_COUNT];
volatile u_int ci_softints;
struct evcnt ci_ev_fpu_loads;
struct evcnt ci_ev_fpu_saves;
struct evcnt ci_ev_dsp_loads;
struct evcnt ci_ev_dsp_saves;
struct evcnt ci_ev_tlbmisses;
int ci_tlb_slot;
u_int ci_pmap_asid_cur;
struct pmap_tlb_info *ci_tlb_info;
union pmap_segtab *ci_pmap_segtabs[2];
#define ci_pmap_user_segtab ci_pmap_segtabs[0]
#define ci_pmap_kern_segtab ci_pmap_segtabs[1]
#ifdef _LP64
union pmap_segtab *ci_pmap_seg0tabs[2];
#define ci_pmap_user_seg0tab ci_pmap_seg0tabs[0]
#define ci_pmap_kern_seg0tab ci_pmap_seg0tabs[1]
#endif
vaddr_t ci_pmap_srcbase;
vaddr_t ci_pmap_dstbase;
u_int ci_cpuwatch_count;
cpu_watchpoint_t ci_cpuwatch_tab[CPUWATCH_MAX];
#ifdef MULTIPROCESSOR
volatile u_long ci_flags;
volatile uint64_t ci_request_ipis;
uint64_t ci_active_ipis;
uint32_t ci_ksp_tlb_slot;
struct evcnt ci_evcnt_all_ipis;
struct evcnt ci_evcnt_per_ipi[NIPIS];
struct evcnt ci_evcnt_synci_activate_rqst;
struct evcnt ci_evcnt_synci_onproc_rqst;
struct evcnt ci_evcnt_synci_deferred_rqst;
struct evcnt ci_evcnt_synci_ipi_rqst;
#define CPUF_PRIMARY __BIT(0)
#define CPUF_PRESENT __BIT(1)
#define CPUF_RUNNING __BIT(2)
#define CPUF_PAUSED __BIT(3)
#define CPUF_USERPMAP __BIT(5)
kcpuset_t *ci_shootdowncpus;
kcpuset_t *ci_multicastcpus;
kcpuset_t *ci_watchcpus;
kcpuset_t *ci_ddbcpus;
#endif
#if defined(GPROF) && defined(MULTIPROCESSOR)
struct gmonparam *ci_gmon;
#endif
};
#endif
#ifdef _KERNEL
#ifdef MULTIPROCESSOR
#define CPU_INFO_ITERATOR int
#define CPU_INFO_FOREACH(cii, ci) \
cii = 0, ci = &cpu_info_store; \
ci != NULL; \
cii++, \
ncpu ? (ci = cpu_infos[cii]) \
: (ci = NULL)
#else
#define CPU_INFO_ITERATOR int __unused
#define CPU_INFO_FOREACH(cii, ci) \
ci = &cpu_info_store; ci != NULL; ci = NULL
#endif
#define MIPS_CURLWP_QUOTED "$24"
#define MIPS_CURLWP_LABEL _L_T8
#define MIPS_CURLWP_REG _R_T8
extern struct cpu_info cpu_info_store;
#ifdef MULTIPROCESSOR
extern struct cpu_info *cpuid_infos[];
#endif
register struct lwp *mips_curlwp asm(MIPS_CURLWP_QUOTED);
#define curlwp mips_curlwp
#define curcpu() lwp_getcpu(curlwp)
#define curpcb ((struct pcb *)lwp_getpcb(curlwp))
#ifdef MULTIPROCESSOR
#define cpu_number() (curcpu()->ci_index)
#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY)
#else
#define cpu_number() (0)
#define CPU_IS_PRIMARY(ci) (true)
#endif
void cpu_broadcast_ipi(int);
void cpu_multicast_ipi(const kcpuset_t *, int);
int cpu_send_ipi(struct cpu_info *, int);
void cpu_intr(int, vaddr_t, uint32_t);
struct clockframe {
vaddr_t pc;
uint32_t sr;
bool intr;
};
uint32_t cpu_clkf_usermode_mask(void);
#define CLKF_USERMODE(framep) ((framep)->sr & cpu_clkf_usermode_mask())
#define CLKF_PC(framep) ((framep)->pc + 0)
#define CLKF_INTR(framep) ((framep)->intr + 0)
#define LWP_PC(l) cpu_lwp_pc(l)
struct proc;
struct lwp;
struct pcb;
struct reg;
void cpu_signotify(struct lwp *);
void cpu_need_proftick(struct lwp *);
void cpu_boot_secondary_processors(void);
void * cpu_uarea_alloc(bool);
bool cpu_uarea_free(void *);
void cpu_proc_fork(struct proc *, struct proc *);
vaddr_t cpu_lwp_pc(struct lwp *);
#ifdef _LP64
void cpu_vmspace_exec(struct lwp *, vaddr_t, vaddr_t);
#endif
#endif
#define CPU_CONSDEV 1
#define CPU_BOOTED_KERNEL 2
#define CPU_ROOT_DEVICE 3
#define CPU_LLSC 4
#define CPU_LMMI 5
#endif