Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: machdep.h,v 1.19 2024/02/07 04:20:26 msaitoh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2017 Ryo Shimizu
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _AARCH64_MACHDEP_H_
     30 #define _AARCH64_MACHDEP_H_
     31 
     32 #include <sys/proc.h>
     33 #include <sys/lwp.h>
     34 #include <sys/siginfo.h>
     35 
     36 // initarm_common
     37 #include <machine/bootconfig.h>
     38 
     39 struct boot_physmem;
     40 
     41 static inline paddr_t
     42 aarch64_kern_vtophys(vaddr_t va)
     43 {
     44 	extern u_long kern_vtopdiff;
     45 
     46 	return va - kern_vtopdiff;
     47 }
     48 
     49 static inline vaddr_t
     50 aarch64_kern_phystov(paddr_t pa)
     51 {
     52 	extern u_long kern_vtopdiff;
     53 
     54 	return pa + kern_vtopdiff;
     55 }
     56 
     57 #define KERN_VTOPHYS(va)	aarch64_kern_vtophys(va)
     58 #define KERN_PHYSTOV(pa)	aarch64_kern_phystov(pa)
     59 
     60 extern paddr_t physical_start;
     61 extern paddr_t physical_end;
     62 extern vaddr_t module_start;
     63 extern vaddr_t module_end;
     64 
     65 extern void (*cpu_reset_address0)(void);
     66 extern void (*cpu_reset_address)(void);
     67 extern void (*cpu_powerdown_address)(void);
     68 
     69 extern char *booted_kernel;
     70 
     71 /*
     72  * note that we use void * as all the platforms have different ideas on what
     73  * the structure is
     74  */
     75 vaddr_t initarm(void *);
     76 
     77 vaddr_t initarm_common(vaddr_t, vsize_t, const struct boot_physmem *, size_t);
     78 void cpu_kernel_vm_init(paddr_t, psize_t);
     79 void uartputc(int);
     80 
     81 void parse_mi_bootargs(char *);
     82 void dumpsys(void);
     83 
     84 void cpu_startup_hook(void);
     85 void cpu_startup_default(void);
     86 
     87 struct trapframe;
     88 
     89 /* fault.c */
     90 void data_abort_handler(struct trapframe *, uint32_t);
     91 
     92 /* trap.c */
     93 void lwp_trampoline(void);
     94 void configure_cpu_traps(void);
     95 void cpu_dosoftints(void);
     96 void cpu_switchto_softint(struct lwp *, int);
     97 void dosoftints(void);
     98 int fetch_arm_insn(uint64_t, uint64_t, uint32_t *);
     99 void trap_doast(struct trapframe *);
    100 
    101 void trap_el1t_sync(struct trapframe *);
    102 void trap_el1t_irq(struct trapframe *);
    103 void trap_el1t_fiq(struct trapframe *);
    104 void trap_el1t_error(struct trapframe *);
    105 void trap_el1h_sync(struct trapframe *);
    106 void trap_el1h_fiq(struct trapframe *);
    107 void trap_el1h_error(struct trapframe *);
    108 void trap_el0_sync(struct trapframe *);
    109 void trap_el0_fiq(struct trapframe *);
    110 void trap_el0_error(struct trapframe *);
    111 void trap_el0_32sync(struct trapframe *);
    112 void trap_el0_32fiq(struct trapframe *);
    113 void trap_el0_32error(struct trapframe *);
    114 void cpu_irq(struct trapframe *);
    115 void cpu_fiq(struct trapframe *);
    116 
    117 /* cpu_onfault */
    118 int cpu_set_onfault(struct faultbuf *) __returns_twice;
    119 void cpu_jump_onfault(struct trapframe *, const struct faultbuf *, int);
    120 
    121 #if defined(_KERNEL)
    122 static inline void
    123 cpu_unset_onfault(void)
    124 {
    125 	curlwp->l_md.md_onfault = NULL;
    126 }
    127 
    128 static inline void
    129 cpu_enable_onfault(struct faultbuf *fb)
    130 {
    131 	curlwp->l_md.md_onfault = fb;
    132 }
    133 
    134 static inline struct faultbuf *
    135 cpu_disable_onfault(void)
    136 {
    137 	struct faultbuf * const fb = curlwp->l_md.md_onfault;
    138 	if (fb != NULL)
    139 		curlwp->l_md.md_onfault = NULL;
    140 	return fb;
    141 }
    142 #endif
    143 
    144 /* exec_machdep.c */
    145 void aarch64_setregs_ptrauth(struct lwp *, bool);
    146 
    147 /* fpu.c */
    148 void fpu_attach(struct cpu_info *);
    149 struct fpreg;
    150 void load_fpregs(const struct fpreg *);
    151 void save_fpregs(struct fpreg *);
    152 
    153 #ifdef TRAP_SIGDEBUG
    154 #define do_trapsignal(l, signo, code, addr, trap) \
    155     do_trapsignal1(__func__, __LINE__, tf, l, signo, code, addr, trap)
    156 #else
    157 #define do_trapsignal(l, signo, code, addr, trap) \
    158     do_trapsignal1(l, signo, code, addr, trap)
    159 #endif
    160 
    161 void do_trapsignal1(
    162 #ifdef TRAP_SIGDEBUG
    163     const char *func, size_t line, struct trapframe *tf,
    164 #endif
    165     struct lwp *l, int signo, int code, void *addr, int trap);
    166 
    167 const char *eclass_trapname(uint32_t);
    168 
    169 #include <sys/pcu.h>
    170 
    171 extern const pcu_ops_t pcu_fpu_ops;
    172 
    173 static inline bool
    174 fpu_used_p(lwp_t *l)
    175 {
    176 	return pcu_valid_p(&pcu_fpu_ops, l);
    177 }
    178 
    179 static inline void
    180 fpu_save(lwp_t *l)
    181 {
    182 	pcu_save(&pcu_fpu_ops, l);
    183 }
    184 
    185 static inline void
    186 fpu_load(lwp_t *l)
    187 {
    188 	pcu_load(&pcu_fpu_ops);
    189 }
    190 
    191 static inline void
    192 fpu_discard(lwp_t *l, bool usesw)
    193 {
    194 	pcu_discard(&pcu_fpu_ops, l, usesw);
    195 }
    196 
    197 #endif /* _AARCH64_MACHDEP_H_ */
    198