Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

csky: Misc headers

This patch adds csky registers' definition, bitops, byteorder,
asm-offsets codes.

Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>

Guo Ren 735ee005 99106986

+351
+27
arch/csky/abiv1/inc/abi/reg_ops.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ABI_REG_OPS_H 5 + #define __ABI_REG_OPS_H 6 + #include <asm/reg_ops.h> 7 + 8 + #define cprcr(reg) \ 9 + ({ \ 10 + unsigned int tmp; \ 11 + asm volatile("cprcr %0, "reg"\n":"=b"(tmp)); \ 12 + tmp; \ 13 + }) 14 + 15 + #define cpwcr(reg, val) \ 16 + ({ \ 17 + asm volatile("cpwcr %0, "reg"\n"::"b"(val)); \ 18 + }) 19 + 20 + static inline unsigned int mfcr_hint(void) 21 + { 22 + return mfcr("cr30"); 23 + } 24 + 25 + static inline unsigned int mfcr_ccr2(void) { return 0; } 26 + 27 + #endif /* __ABI_REG_OPS_H */
+26
arch/csky/abiv1/inc/abi/regdef.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ASM_CSKY_REGDEF_H 5 + #define __ASM_CSKY_REGDEF_H 6 + 7 + #define syscallid r1 8 + #define r11_sig r11 9 + 10 + #define regs_syscallid(regs) regs->regs[9] 11 + 12 + /* 13 + * PSR format: 14 + * | 31 | 30-24 | 23-16 | 15 14 | 13-0 | 15 + * S CPID VEC TM 16 + * 17 + * S: Super Mode 18 + * CPID: Coprocessor id, only 15 for MMU 19 + * VEC: Exception Number 20 + * TM: Trace Mode 21 + */ 22 + #define DEFAULT_PSR_VALUE 0x8f000000 23 + 24 + #define SYSTRACE_SAVENUM 2 25 + 26 + #endif /* __ASM_CSKY_REGDEF_H */
+17
arch/csky/abiv2/inc/abi/reg_ops.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ABI_REG_OPS_H 5 + #define __ABI_REG_OPS_H 6 + #include <asm/reg_ops.h> 7 + 8 + static inline unsigned int mfcr_hint(void) 9 + { 10 + return mfcr("cr31"); 11 + } 12 + 13 + static inline unsigned int mfcr_ccr2(void) 14 + { 15 + return mfcr("cr23"); 16 + } 17 + #endif /* __ABI_REG_OPS_H */
+26
arch/csky/abiv2/inc/abi/regdef.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ASM_CSKY_REGDEF_H 5 + #define __ASM_CSKY_REGDEF_H 6 + 7 + #define syscallid r7 8 + #define r11_sig r11 9 + 10 + #define regs_syscallid(regs) regs->regs[3] 11 + 12 + /* 13 + * PSR format: 14 + * | 31 | 30-24 | 23-16 | 15 14 | 13-10 | 9 | 8-0 | 15 + * S VEC TM MM 16 + * 17 + * S: Super Mode 18 + * VEC: Exception Number 19 + * TM: Trace Mode 20 + * MM: Memory unaligned addr access 21 + */ 22 + #define DEFAULT_PSR_VALUE 0x80000200 23 + 24 + #define SYSTRACE_SAVENUM 5 25 + 26 + #endif /* __ASM_CSKY_REGDEF_H */
+82
arch/csky/include/asm/bitops.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ASM_CSKY_BITOPS_H 5 + #define __ASM_CSKY_BITOPS_H 6 + 7 + #include <linux/compiler.h> 8 + #include <asm/barrier.h> 9 + 10 + /* 11 + * asm-generic/bitops/ffs.h 12 + */ 13 + static inline int ffs(int x) 14 + { 15 + if (!x) 16 + return 0; 17 + 18 + asm volatile ( 19 + "brev %0\n" 20 + "ff1 %0\n" 21 + "addi %0, 1\n" 22 + : "=&r"(x) 23 + : "0"(x)); 24 + return x; 25 + } 26 + 27 + /* 28 + * asm-generic/bitops/__ffs.h 29 + */ 30 + static __always_inline unsigned long __ffs(unsigned long x) 31 + { 32 + asm volatile ( 33 + "brev %0\n" 34 + "ff1 %0\n" 35 + : "=&r"(x) 36 + : "0"(x)); 37 + return x; 38 + } 39 + 40 + /* 41 + * asm-generic/bitops/fls.h 42 + */ 43 + static __always_inline int fls(int x) 44 + { 45 + asm volatile( 46 + "ff1 %0\n" 47 + : "=&r"(x) 48 + : "0"(x)); 49 + 50 + return (32 - x); 51 + } 52 + 53 + /* 54 + * asm-generic/bitops/__fls.h 55 + */ 56 + static __always_inline unsigned long __fls(unsigned long x) 57 + { 58 + return fls(x) - 1; 59 + } 60 + 61 + #include <asm-generic/bitops/ffz.h> 62 + #include <asm-generic/bitops/fls64.h> 63 + #include <asm-generic/bitops/find.h> 64 + 65 + #ifndef _LINUX_BITOPS_H 66 + #error only <linux/bitops.h> can be included directly 67 + #endif 68 + 69 + #include <asm-generic/bitops/sched.h> 70 + #include <asm-generic/bitops/hweight.h> 71 + #include <asm-generic/bitops/lock.h> 72 + #include <asm-generic/bitops/atomic.h> 73 + 74 + /* 75 + * bug fix, why only could use atomic!!!! 76 + */ 77 + #include <asm-generic/bitops/non-atomic.h> 78 + #define __clear_bit(nr, vaddr) clear_bit(nr, vaddr) 79 + 80 + #include <asm-generic/bitops/le.h> 81 + #include <asm-generic/bitops/ext2-atomic.h> 82 + #endif /* __ASM_CSKY_BITOPS_H */
+50
arch/csky/include/asm/checksum.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ASM_CSKY_CHECKSUM_H 5 + #define __ASM_CSKY_CHECKSUM_H 6 + 7 + #include <linux/in6.h> 8 + #include <asm/byteorder.h> 9 + 10 + static inline __sum16 csum_fold(__wsum csum) 11 + { 12 + u32 tmp; 13 + 14 + asm volatile( 15 + "mov %1, %0\n" 16 + "rori %0, 16\n" 17 + "addu %0, %1\n" 18 + "lsri %0, 16\n" 19 + : "=r"(csum), "=r"(tmp) 20 + : "0"(csum)); 21 + 22 + return (__force __sum16) ~csum; 23 + } 24 + #define csum_fold csum_fold 25 + 26 + static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 27 + unsigned short len, unsigned short proto, __wsum sum) 28 + { 29 + asm volatile( 30 + "clrc\n" 31 + "addc %0, %1\n" 32 + "addc %0, %2\n" 33 + "addc %0, %3\n" 34 + "inct %0\n" 35 + : "=r"(sum) 36 + : "r"((__force u32)saddr), "r"((__force u32)daddr), 37 + #ifdef __BIG_ENDIAN 38 + "r"(proto + len), 39 + #else 40 + "r"((proto + len) << 8), 41 + #endif 42 + "0" ((__force unsigned long)sum) 43 + : "cc"); 44 + return sum; 45 + } 46 + #define csum_tcpudp_nofold csum_tcpudp_nofold 47 + 48 + #include <asm-generic/checksum.h> 49 + 50 + #endif /* __ASM_CSKY_CHECKSUM_H */
+26
arch/csky/include/asm/reg_ops.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_REGS_OPS_H 4 + #define __ASM_REGS_OPS_H 5 + 6 + #define mfcr(reg) \ 7 + ({ \ 8 + unsigned int tmp; \ 9 + asm volatile( \ 10 + "mfcr %0, "reg"\n" \ 11 + : "=r"(tmp) \ 12 + : \ 13 + : "memory"); \ 14 + tmp; \ 15 + }) 16 + 17 + #define mtcr(reg, val) \ 18 + ({ \ 19 + asm volatile( \ 20 + "mtcr %0, "reg"\n" \ 21 + : \ 22 + : "r"(val) \ 23 + : "memory"); \ 24 + }) 25 + 26 + #endif /* __ASM_REGS_OPS_H */
+9
arch/csky/include/uapi/asm/byteorder.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #ifndef __ASM_CSKY_BYTEORDER_H 5 + #define __ASM_CSKY_BYTEORDER_H 6 + 7 + #include <linux/byteorder/little_endian.h> 8 + 9 + #endif /* __ASM_CSKY_BYTEORDER_H */
+88
arch/csky/kernel/asm-offsets.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 + 4 + #include <linux/sched.h> 5 + #include <linux/kernel_stat.h> 6 + #include <linux/kbuild.h> 7 + #include <abi/regdef.h> 8 + 9 + int main(void) 10 + { 11 + /* offsets into the task struct */ 12 + DEFINE(TASK_STATE, offsetof(struct task_struct, state)); 13 + DEFINE(TASK_THREAD_INFO, offsetof(struct task_struct, stack)); 14 + DEFINE(TASK_FLAGS, offsetof(struct task_struct, flags)); 15 + DEFINE(TASK_PTRACE, offsetof(struct task_struct, ptrace)); 16 + DEFINE(TASK_THREAD, offsetof(struct task_struct, thread)); 17 + DEFINE(TASK_MM, offsetof(struct task_struct, mm)); 18 + DEFINE(TASK_ACTIVE_MM, offsetof(struct task_struct, active_mm)); 19 + 20 + /* offsets into the thread struct */ 21 + DEFINE(THREAD_KSP, offsetof(struct thread_struct, ksp)); 22 + DEFINE(THREAD_SR, offsetof(struct thread_struct, sr)); 23 + DEFINE(THREAD_ESP0, offsetof(struct thread_struct, esp0)); 24 + DEFINE(THREAD_FESR, offsetof(struct thread_struct, user_fp.fesr)); 25 + DEFINE(THREAD_FCR, offsetof(struct thread_struct, user_fp.fcr)); 26 + DEFINE(THREAD_FPREG, offsetof(struct thread_struct, user_fp.vr)); 27 + DEFINE(THREAD_DSPHI, offsetof(struct thread_struct, hi)); 28 + DEFINE(THREAD_DSPLO, offsetof(struct thread_struct, lo)); 29 + 30 + /* offsets into the thread_info struct */ 31 + DEFINE(TINFO_FLAGS, offsetof(struct thread_info, flags)); 32 + DEFINE(TINFO_PREEMPT, offsetof(struct thread_info, preempt_count)); 33 + DEFINE(TINFO_ADDR_LIMIT, offsetof(struct thread_info, addr_limit)); 34 + DEFINE(TINFO_TP_VALUE, offsetof(struct thread_info, tp_value)); 35 + DEFINE(TINFO_TASK, offsetof(struct thread_info, task)); 36 + 37 + /* offsets into the pt_regs */ 38 + DEFINE(PT_PC, offsetof(struct pt_regs, pc)); 39 + DEFINE(PT_ORIG_AO, offsetof(struct pt_regs, orig_a0)); 40 + DEFINE(PT_SR, offsetof(struct pt_regs, sr)); 41 + 42 + DEFINE(PT_A0, offsetof(struct pt_regs, a0)); 43 + DEFINE(PT_A1, offsetof(struct pt_regs, a1)); 44 + DEFINE(PT_A2, offsetof(struct pt_regs, a2)); 45 + DEFINE(PT_A3, offsetof(struct pt_regs, a3)); 46 + DEFINE(PT_REGS0, offsetof(struct pt_regs, regs[0])); 47 + DEFINE(PT_REGS1, offsetof(struct pt_regs, regs[1])); 48 + DEFINE(PT_REGS2, offsetof(struct pt_regs, regs[2])); 49 + DEFINE(PT_REGS3, offsetof(struct pt_regs, regs[3])); 50 + DEFINE(PT_REGS4, offsetof(struct pt_regs, regs[4])); 51 + DEFINE(PT_REGS5, offsetof(struct pt_regs, regs[5])); 52 + DEFINE(PT_REGS6, offsetof(struct pt_regs, regs[6])); 53 + DEFINE(PT_REGS7, offsetof(struct pt_regs, regs[7])); 54 + DEFINE(PT_REGS8, offsetof(struct pt_regs, regs[8])); 55 + DEFINE(PT_REGS9, offsetof(struct pt_regs, regs[9])); 56 + DEFINE(PT_R15, offsetof(struct pt_regs, lr)); 57 + #if defined(__CSKYABIV2__) 58 + DEFINE(PT_R16, offsetof(struct pt_regs, exregs[0])); 59 + DEFINE(PT_R17, offsetof(struct pt_regs, exregs[1])); 60 + DEFINE(PT_R18, offsetof(struct pt_regs, exregs[2])); 61 + DEFINE(PT_R19, offsetof(struct pt_regs, exregs[3])); 62 + DEFINE(PT_R20, offsetof(struct pt_regs, exregs[4])); 63 + DEFINE(PT_R21, offsetof(struct pt_regs, exregs[5])); 64 + DEFINE(PT_R22, offsetof(struct pt_regs, exregs[6])); 65 + DEFINE(PT_R23, offsetof(struct pt_regs, exregs[7])); 66 + DEFINE(PT_R24, offsetof(struct pt_regs, exregs[8])); 67 + DEFINE(PT_R25, offsetof(struct pt_regs, exregs[9])); 68 + DEFINE(PT_R26, offsetof(struct pt_regs, exregs[10])); 69 + DEFINE(PT_R27, offsetof(struct pt_regs, exregs[11])); 70 + DEFINE(PT_R28, offsetof(struct pt_regs, exregs[12])); 71 + DEFINE(PT_R29, offsetof(struct pt_regs, exregs[13])); 72 + DEFINE(PT_R30, offsetof(struct pt_regs, exregs[14])); 73 + DEFINE(PT_R31, offsetof(struct pt_regs, exregs[15])); 74 + DEFINE(PT_RHI, offsetof(struct pt_regs, rhi)); 75 + DEFINE(PT_RLO, offsetof(struct pt_regs, rlo)); 76 + #endif 77 + DEFINE(PT_USP, offsetof(struct pt_regs, usp)); 78 + 79 + /* offsets into the irq_cpustat_t struct */ 80 + DEFINE(CPUSTAT_SOFTIRQ_PENDING, offsetof(irq_cpustat_t, 81 + __softirq_pending)); 82 + 83 + /* signal defines */ 84 + DEFINE(SIGSEGV, SIGSEGV); 85 + DEFINE(SIGTRAP, SIGTRAP); 86 + 87 + return 0; 88 + }