#ifndef _AARCH64_CPU_H_
#define _AARCH64_CPU_H_
#include <arm/cpu.h>
#ifdef __aarch64__
#ifdef _KERNEL_OPT
#include "opt_gprof.h"
#include "opt_multiprocessor.h"
#endif
#include <sys/param.h>
#if defined(_KERNEL) || defined(_KMEMUSER)
#include <sys/evcnt.h>
#include <aarch64/armreg.h>
#include <aarch64/frame.h>
struct clockframe {
struct trapframe cf_tf;
};
#define CLKF_USERMODE(cf) ((((cf)->cf_tf.tf_spsr) & 0x0f) == 0)
#define CLKF_PC(cf) ((cf)->cf_tf.tf_pc)
#define CLKF_INTR(cf) ((void)(cf), curcpu()->ci_intr_depth > 1)
#define LWP_PC(l) ((l)->l_md.md_utf->tf_pc)
#include <sys/cpu_data.h>
#include <sys/device_if.h>
#include <sys/intr.h>
struct aarch64_cpufuncs {
void (*cf_set_ttbr0)(uint64_t);
void (*cf_icache_sync_range)(vaddr_t, vsize_t);
};
#define MAX_CACHE_LEVEL 8
struct aarch64_cache_unit {
u_int cache_type;
#define CACHE_TYPE_VPIPT 0
#define CACHE_TYPE_VIVT 1
#define CACHE_TYPE_VIPT 2
#define CACHE_TYPE_PIPT 3
u_int cache_line_size;
u_int cache_ways;
u_int cache_sets;
u_int cache_way_size;
u_int cache_size;
};
struct aarch64_cache_info {
u_int cacheable;
#define CACHE_CACHEABLE_NONE 0
#define CACHE_CACHEABLE_ICACHE 1
#define CACHE_CACHEABLE_DCACHE 2
#define CACHE_CACHEABLE_IDCACHE 3
#define CACHE_CACHEABLE_UNIFIED 4
struct aarch64_cache_unit icache;
struct aarch64_cache_unit dcache;
};
struct aarch64_low_power_idle {
uint32_t min_res;
uint32_t wakeup_latency;
uint32_t save_restore_flags;
#define LPI_SAVE_RESTORE_CORE __BIT(0)
#define LPI_SAVE_RESTORE_TRACE __BIT(1)
#define LPI_SAVE_RESTORE_GICR __BIT(2)
#define LPI_SAVE_RESTORE_GICD __BIT(3)
uint32_t reg_addr;
#define LPI_REG_ADDR_WFI 0xffffffff
char *name;
struct evcnt events;
};
struct cpu_info {
struct cpu_data ci_data;
device_t ci_dev;
cpuid_t ci_cpuid;
int ci_want_resched __aligned(COHERENCY_UNIT);
struct lwp *ci_curlwp __aligned(COHERENCY_UNIT);
struct lwp *ci_onproc;
struct lwp *ci_softlwps[SOFTINT_COUNT] __aligned(COHERENCY_UNIT);
uint64_t ci_lastintr;
int ci_mtx_oldspl;
int ci_mtx_count;
int ci_cpl;
volatile int ci_hwpl;
volatile u_int ci_softints;
volatile u_int ci_intr_depth;
volatile uint32_t ci_blocked_pics;
volatile uint32_t ci_pending_pics;
volatile uint32_t ci_pending_ipls;
int ci_kfpu_spl;
tlb_asid_t ci_pmap_asid_cur;
struct evcnt ci_vfp_use;
struct evcnt ci_vfp_reuse;
struct evcnt ci_vfp_save;
struct evcnt ci_vfp_release;
struct evcnt ci_uct_trap;
struct evcnt ci_intr_preempt;
struct evcnt ci_rndrrs_fail;
uint32_t ci_capacity_dmips_mhz;
u_int ci_gic_redist;
uint64_t ci_gic_sgir;
uint32_t ci_acpiid;
uint32_t ci_nlpi;
struct aarch64_low_power_idle *ci_lpi;
uint64_t ci_last_idle;
uint64_t ci_sctlr_el1;
uint64_t ci_sctlr_el2;
struct aarch64_sysctl_cpu_id ci_id;
#define ci_midr ci_id.ac_midr
struct aarch64_cache_info ci_cacheinfo[MAX_CACHE_LEVEL];
struct aarch64_cpufuncs ci_cpufuncs;
#if defined(GPROF) && defined(MULTIPROCESSOR)
struct gmonparam *ci_gmon;
#endif
} __aligned(COHERENCY_UNIT);
#ifdef _KERNEL
static inline __always_inline struct lwp * __attribute__ ((const))
aarch64_curlwp(void)
{
struct lwp *l;
__asm("mrs %0, tpidr_el1" : "=r"(l));
return l;
}
static __inline struct cpu_info *lwp_getcpu(struct lwp *);
#define curcpu() (lwp_getcpu(aarch64_curlwp()))
#define setsoftast(ci) (cpu_signotify((ci)->ci_onproc))
#undef curlwp
#define curlwp (aarch64_curlwp())
#define curpcb ((struct pcb *)lwp_getpcb(curlwp))
void cpu_signotify(struct lwp *l);
void cpu_need_proftick(struct lwp *l);
void cpu_hatch(struct cpu_info *);
extern struct cpu_info *cpu_info[];
extern struct cpu_info cpu_info_store[];
#define CPU_INFO_ITERATOR int
#if defined(MULTIPROCESSOR) || defined(_MODULE)
#define cpu_number() (curcpu()->ci_index)
#define CPU_IS_PRIMARY(ci) ((ci)->ci_index == 0)
#define CPU_INFO_FOREACH(cii, ci) \
cii = 0, ci = cpu_info[0]; \
cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL; \
cii++
#else
#define cpu_number() 0
#define CPU_IS_PRIMARY(ci) true
#define CPU_INFO_FOREACH(cii, ci) \
cii = 0, __USE(cii), ci = curcpu(); ci != NULL; ci = NULL
#endif
#define LWP0_CPU_INFO (&cpu_info_store[0])
#define __HAVE_CPU_DOSOFTINTS_CI
static inline void
cpu_dosoftints_ci(struct cpu_info *ci)
{
#if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
void dosoftints(void);
if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0) {
dosoftints();
}
#endif
}
static inline void
cpu_dosoftints(void)
{
#if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
KDASSERT(kpreempt_disabled());
cpu_dosoftints_ci(curcpu());
#endif
}
struct cpufeature_attach_args {
struct cpu_info *ci;
};
#endif
#endif
#endif
#endif