1 /* $NetBSD: m68k.h,v 1.38 2026/04/28 03:29:09 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1982, 1990, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: Utah $Hdr: cpu.h 1.16 91/03/25$ 37 * from: @(#)cpu.h 8.4 (Berkeley) 1/5/94 38 */ 39 40 #ifndef _M68K_M68K_H_ 41 #define _M68K_M68K_H_ 42 43 /* 44 * Declarations for things exported by sources in this directory, 45 * or required by sources in here and not declared elsewhere. 46 * 47 * These declarations generally do NOT belong in <machine/cpu.h>, 48 * because that defines the interface between the common code and 49 * the machine-dependent code, whereas this defines the interface 50 * between the shared m68k code and the machine-dependent code. 51 * 52 * The MMU stuff is exported separately so it can be used just 53 * where it is really needed. Same for function codes, etc. 54 */ 55 56 #ifdef _KERNEL 57 58 #include <uvm/uvm_prot.h> /* for vm_prot_t */ 59 60 /* 61 * All m68k ports must provide these globals. 62 */ 63 extern int cputype; /* CPU on this host */ 64 extern int mmutype; /* MMU on this host */ 65 #endif /* _KERNEL */ 66 67 /* values for cputype */ 68 #define CPU_68010 -1 /* 68010 */ 69 #define CPU_68020 0 /* 68020 */ 70 #define CPU_68030 1 /* 68030 */ 71 #define CPU_68040 2 /* 68040 */ 72 #define CPU_68060 3 /* 68060 */ 73 74 /* values for ectype */ 75 #define EC_PHYS -1 /* external physical address cache */ 76 #define EC_NONE 0 /* no external cache */ 77 #define EC_VIRT 1 /* external virtual address cache */ 78 79 /* values for fputype */ 80 #define FPU_NONE 0 /* no FPU */ 81 #define FPU_68881 1 /* 68881 FPU */ 82 #define FPU_68882 2 /* 68882 FPU */ 83 #define FPU_68040 3 /* 68040 on-chip FPU */ 84 #define FPU_68060 4 /* 68060 on-chip FPU */ 85 #define FPU_UNKNOWN 5 /* placeholder; unknown FPU */ 86 87 /* 88 * values for mmutype (assigned for quick testing). Assembly 89 * code relies on this ordering, so do not change it! 90 */ 91 #define MMU_UNKNOWN -5 /* unknown MMU type */ 92 #define MMU_CUSTOM -4 /* bespoke machine-specific MMU */ 93 #define MMU_68060 -3 /* 68060 on-chip MMU */ 94 #define MMU_68040 -2 /* 68040 on-chip MMU */ 95 #define MMU_68030 -1 /* 68030 on-chip subset of 68851 */ 96 #define MMU_HP 0 /* HP proprietary */ 97 #define MMU_68851 1 /* Motorola 68851 */ 98 #define MMU_SUN 2 /* Sun MMU */ 99 100 101 #ifdef _KERNEL 102 103 /* 104 * Delay divisor estimation for 68020/6830, 68040, and 68060, 105 * based on CPU clock frequency. This is based on a x1024 106 * delay magnification factor. 107 * 108 * These provide a reasonable starting point; it is always 109 * best to calibrate the delay_divisor against a known clock 110 * source, if possible, a known-rate counter or a timer of 111 * some sort where expiration can be checked reliably. When 112 * picking a default, it's safest to assume the fastest machine 113 * you're likely to see, which may result in longer delays, 114 * but is a safer bet if those delays are needed for minimum 115 * hardware timings, etc. 116 * 117 * When calibrating the delay_divisor, it is best to start 118 * assuming a slower CPU, which results in a larger delay 119 * divisor and the delay loop completing more quickly. The 120 * calibration loop can then check to see if the reference 121 * has reached the desired value. If it has not, decrement 122 * the delay_divisor, thus slowing down the delay loop, and 123 * try again. For this purpose, we provide a "weight" macro 124 * that drags down the estimated lower CPU speed boundary 125 * by (very) roughly 10%. 126 * 127 * Note that the delay_divisor_est*() macros are reciprocal; given 128 * a calibrated delay_divisor value, you can use that to get the 129 * rough CPU speed in MHz. 130 */ 131 #define DELAY_MAGSHIFT 10 132 #define DELAY_MAGFACTOR (1 << DELAY_MAGSHIFT) 133 #define DELAY_MAXVAL (0xffffffffU >> DELAY_MAGSHIFT) 134 #define delay_divisor_est(x) ((DELAY_MAGFACTOR * 8) / (x)) 135 #define delay_divisor_est40(x) ((DELAY_MAGFACTOR * 3) / (x)) 136 #define delay_divisor_est60(x) ((DELAY_MAGFACTOR * 1) / (x)) 137 #define delay_calibration_weight(x) ((x) - ((x) / 10)) 138 139 extern int delay_divisor; 140 141 struct pcb; 142 struct trapframe; 143 struct fpframe; 144 145 /* copypage.s */ 146 void copypage040(void *fromaddr, void *toaddr); 147 void copypage(void *fromaddr, void *toaddr); 148 void zeropage(void *addr); 149 150 /* switch_subr.s */ 151 void lwp_trampoline(void); 152 void m68881_save(struct fpframe *); 153 void m68881_restore(struct fpframe *); 154 void savectx(struct pcb *); 155 156 /* w16copy.s */ 157 void w16zero(void *, u_int); 158 void w16copy(const void *, void *, u_int); 159 160 /* fpu.c */ 161 extern int fputype; /* FPU on this host */ 162 void fpu_init(void); 163 164 /* m68k_machdep.c */ 165 extern int ectype; 166 extern int ecsize; 167 extern int cpuspeed_khz; 168 extern int fpuspeed_khz; 169 void machine_init_common(paddr_t); 170 void machine_set_model(void); 171 #ifdef __HAVE_M68K_MACHINE_PRINT_MODEL 172 void machine_print_model(void (*)(const char *, ...) 173 __printflike(1, 2)); 174 #endif 175 void cpu_startup_common(void); 176 #ifdef __HAVE_CPU_STARTUP_PRINT_MACHINE_MODEL 177 void cpu_startup_print_machine_model(void (*)(const char *, ...) 178 __printflike(1, 2)); 179 #endif 180 #ifdef __HAVE_CPU_STARTUP_PRINT_TOTAL_MEMORY 181 void cpu_startup_print_total_memory(void (*)(const char *, ...) 182 __printflike(1, 2)); 183 #endif 184 int cpu_reboot_poll_console(bool); 185 void cpu_reboot_common(int, char *) __dead; 186 void machine_powerdown_default(void); 187 void machine_powerdown(void); 188 void machine_halt_default(void); 189 void machine_halt(void); 190 void machine_reboot(int, char *); 191 void bootsync(void); 192 int mm_md_physacc_regular(paddr_t, vm_prot_t); 193 194 /* m68k_trap.c */ 195 extern label_t *nofault; 196 bool badaddr_read(volatile void *, size_t, void *); 197 bool badaddr_write(volatile void *, size_t, uintmax_t); 198 199 #define badaddr(a) badaddr_read((a), 2, NULL) 200 #define badbaddr(a) badaddr_read((a), 1, NULL) 201 #define badaddr_sz(a, s) badaddr_read((a), (s), NULL) 202 203 /* regdump.c */ 204 void regdump(struct trapframe *, int); 205 206 /* sys_machdep.c */ 207 int cachectl1(u_long, vaddr_t, size_t, struct proc *); 208 int dma_cachectl(void *, int); 209 210 /* vm_machdep.c */ 211 int kvtop(void *); 212 void physaccess(void *, void *, int, int); 213 void physunaccess(void *, int); 214 215 #endif /* _KERNEL */ 216 #endif /* _M68K_M68K_H_ */ 217