18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_MACH_LOONGSON64_CPUCFG_EMUL_H_ 38c2ecf20Sopenharmony_ci#define _ASM_MACH_LOONGSON64_CPUCFG_EMUL_H_ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/cpu-info.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_LOONGSON3_CPUCFG_EMULATION 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <loongson_regs.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define LOONGSON_FPREV_MASK 0x7 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_civoid loongson3_cpucfg_synthesize_data(struct cpuinfo_mips *c); 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic inline bool loongson3_cpucfg_emulation_enabled(struct cpuinfo_mips *c) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci /* All supported cores have non-zero LOONGSON_CFG1 data. */ 188c2ecf20Sopenharmony_ci return c->loongson3_cpucfg_data[0] != 0; 198c2ecf20Sopenharmony_ci} 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic inline u32 loongson3_cpucfg_read_synthesized(struct cpuinfo_mips *c, 228c2ecf20Sopenharmony_ci __u64 sel) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci switch (sel) { 258c2ecf20Sopenharmony_ci case LOONGSON_CFG0: 268c2ecf20Sopenharmony_ci return c->processor_id; 278c2ecf20Sopenharmony_ci case LOONGSON_CFG1: 288c2ecf20Sopenharmony_ci case LOONGSON_CFG2: 298c2ecf20Sopenharmony_ci case LOONGSON_CFG3: 308c2ecf20Sopenharmony_ci return c->loongson3_cpucfg_data[sel - 1]; 318c2ecf20Sopenharmony_ci case LOONGSON_CFG4: 328c2ecf20Sopenharmony_ci case LOONGSON_CFG5: 338c2ecf20Sopenharmony_ci /* CPUCFG selects 4 and 5 are related to the input clock 348c2ecf20Sopenharmony_ci * signal. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * Unimplemented for now. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci return 0; 398c2ecf20Sopenharmony_ci case LOONGSON_CFG6: 408c2ecf20Sopenharmony_ci /* CPUCFG select 6 is for the undocumented Safe Extension. */ 418c2ecf20Sopenharmony_ci return 0; 428c2ecf20Sopenharmony_ci case LOONGSON_CFG7: 438c2ecf20Sopenharmony_ci /* CPUCFG select 7 is for the virtualization extension. 448c2ecf20Sopenharmony_ci * We don't know if the two currently known features are 458c2ecf20Sopenharmony_ci * supported on older cores according to the public 468c2ecf20Sopenharmony_ci * documentation, so leave this at zero. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci return 0; 498c2ecf20Sopenharmony_ci } 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /* 528c2ecf20Sopenharmony_ci * Return 0 for unrecognized CPUCFG selects, which is real hardware 538c2ecf20Sopenharmony_ci * behavior observed on Loongson 3A R4. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci return 0; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci#else 588c2ecf20Sopenharmony_cistatic inline void loongson3_cpucfg_synthesize_data(struct cpuinfo_mips *c) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline bool loongson3_cpucfg_emulation_enabled(struct cpuinfo_mips *c) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return false; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic inline u32 loongson3_cpucfg_read_synthesized(struct cpuinfo_mips *c, 688c2ecf20Sopenharmony_ci __u64 sel) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return 0; 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#endif /* _ASM_MACH_LOONGSON64_CPUCFG_EMUL_H_ */ 75