Skip to contentSkip to conversation

C-SKY(csky) Linux Kernel Port

PATCH In review Guo Ren 4 participants 68 messages Oct 16, 2018 – Oct 25, 2018

Subsystems (9)
lore
Share & tools
lore

Guo Ren

author
#0 lore raw

v9 cover C-SKY(csky) Linux Kernel Port

This is the 9th version patchset to add the Linux kernel port for C-SKY(csky) based on linux-4.19-rc3.

There are only a few changes between V8 patchset. Hope it could be merged into linux-4.20 and I'm very grateful for any help.

Here is the LTP test report:
-----------------------------------------------
Total Tests: 1298
Total Skipped Tests: 280
Total Failures: 11
Kernel Version: 4.19.0-rc3+
Machine Architecture: csky
Hostname: buildroot
-----------------------------------------------

This patchset adds architecture support to Linux for C-SKY's 32-bit embedded

There are two ABI versions with several CPU cores in this patchset:
ABIv1: ck610 (16-bit instruction, 32-bit data path, VIPT Cache ...)
ABIv2: ck807 ck810 ck860 (16/32-bit variable length instruction, PIPT Cache,

	 SMP ...)

More information: http://en.c-sky.com
The development repo: https://github.com/c-sky/csky-linux
ABI Documentation: https://github.com/c-sky/csky-doc

Here is the pre-built cross compiler for fast test from our CI:
https://gitlab.com/c-sky/buildroot/-/jobs/101608095/artifacts/file/output/images/csky_toolchain_qemu_csky_ck807f_4.18_glibc_defconfig_482b221e52908be1c9b2ccb444255e1562bb7025.tar.xz

We use buildroot as our CI-test enviornment. "LTP, Lmbench ..." will be tested for every commit. See here for more details:
https://gitlab.com/c-sky/buildroot/pipelines

Any feedback is welcome.

Changes in v9:
- Remove unused code in smp.c and use per_cpu for ipi_data.
- Fixup r15 register access in abiv1/alignment.c.
- Improve the changelog comment in commit-msg.

Changes in v8:
- Pass make allmodconfig.
- Implement abiv1 get_user_dword().
- Remove set_irq_mapping() used by driver in smp.c.

Changes in v7:
- Use checkpatch.pl to check all patches and fixup as possible.
- Remove github.com/c-sky print in bootup.
- Give a return in DMA_ATTR_NON_CONSISTENT in csky_dma_alloc_atomic().
- Remove the NSIGXXX in fpu.c and use force_sig_fault() in fpu.c.
- Remove irq.h and add it in asm/Kbuild.
- Use byteswap helpers in abiv1/bswapXi.c.
- Fixup arch_sync_dma() only with one page problem.

Changes in v6:
- use asm-generic/bitops/atomic.h for all in asm/bitops.h
- fix flush_cache_range and tlb_start_vma
- fix compile error with include linux/bug.h in cmpxchg.h
- improve the comment

Changes in v5:
- remove redundant smp_mb operations in spinlock.h
- add commit message for dt-bindings docs
- add CPUHP_AP_CSKY_TIMER_STARTING in hotplug.h for csky_mptimer
- add COMPILE_TEST for timer-gx6605s Kconfig
- seperate csky two interrupt controllers with 2 patches
- add MAINTAINERS patch for csky
- move IPI_IRQ into csky_mptimer, fixup irq_mapping problem
- coding convension

Changes in v4:
- cleanup defconfig
- use ksys_ in syscall.c
- remove wrong comment in vdso.c
- Use GENERIC_IRQ_MULTI_HANDLER
- optimize the memset.c
- fixup dts warnings
- remove big-endian in byteorder.h

Changes in v3:
dc560f1 csky: change to EM_CSKY 252 for elf.h
2ac3ddf csky: remove gx6605s.dts
af00b8c csky: add defconfig and qemu.dts
6c87efb csky: remove the deprecate name.
f6dda39 csky: add dt-bindings doc.
d9f02a8 csky: remove KERNEL_VERSION in upstream branch 7bd663c csky: Use kernel/dma/noncoherent.c
1544c09 csky: bugfix emmc hang up LINS-976
e963271 csky: cleanup include/asm/Kbuild
cd267ba csky: remove CSKY_DEBUG_INFO
78950da csky: remove dcache invalid.
13fe51d csky: remove csum_ipv6_magic(), use generic one. a7372db csky: bugfix CK810 access twice error.
1bb7c69 csky: bugfix add gcc asm memory for barrier. 5ea3257 csky: add -msoft-float instead of -mfloat-abi=soft. 38b037d csky: bugfix losing cache flush range.
ab5e8c4 csky: Add ticket-spinlock and qrwlock support. c9aaec5 csky: rename cskyksyms.c to libgcc_ksyms.c 28c5e48 csky: avoid the MB on failure: trylock
f929c97 csky: bugfix idly4 may cause exception.
09dc496 csky: Use GENERIC_ASHLDI3/ASHRDI3 etc
6ecc99d csky: optimize smp boot code.
16f50df csky: asm/bug.h simple implement.
0ba532a csky: csky asm/atomic.h added.
df66947 csky: asm/compat.h added
275a06f csky: String operations optimization
4c021dd csky: ck860 SMP memory barrier optimize
fc39c66 csky: Add wait/doze/stop
d005144 csky: add GENERIC_ALLOCATOR
4a10074 csky: bugfix cma failed for highmem.
9f2ca70 csky: CMA supported :)
53791f4 csky: optimize csky_dma_alloc_nonatomic
974676e csky: optimize the cpuinfo printf.
2538669 csky: bugfix make headers_install error.
1158d0c csky: prevent hard-float and vdsp instructions. dc3c856 csky: increase Normal Memory to 1GB
6ee5932 csky: bugfix qemu mmu couldn't support 0xffffe000 1d7dfb8 csky: csky_dma_alloc_atomic added.
caf6610 csky: restruct the fixmap memory layout.
5a17eaa csky: use -Wa,-mcpu=ckxxxfv to the as.
4d51829 csky: use Kconfig.hz.
f3f88fa csky: BUGFIX add -mcpu=ck860f support
6192fd1 csky: support ck860 fpu.
7aa5e01 csky: BUGFIX add smp_mb before ldex.
15758e2 csky: BUGFIX tlbi couldn't handle ASID in another CPU core. d69640d csky: enable tlbi.vas to flush one tlb entry

Changes in v2:
a29bfc8 csky: add pre_mmu_init, move misc mmu setup to mm/init.c
4eab702 csky: no need kmap for !VM_EXEC.
6770eec csky: Use TEE as the name of CPU Trusted Execution Enviornment.
a56c8c7 csky: update the cache flush api.
1a48a95 csky: add C-SKY Trust Zone.
b7a0a44 csky: use CONFIG_RAM_BASE as the same in memory of dts.
15adf81 csky: remove unused code.
35c0d97 csky: bugfix lost a cacheline flush when start isn't cacheline-aligned.
4e82c8d csky: use tlbi.alls for ck860 smp temporary.
ae7149e csky: bugfix use kmap_atomic() to prevent no mapped addr.
5538795 csky: bugfix user access in kernel space.
a7aa591 csky: add 16bit user space bkpt.
0de70ec csky: add sync.is for cmpxchg in SMP.
c5c08a1 csky: seperate sync.is and sync for SMP and Non-SMP.
dbbf4dc csky: use sync.is for ck860 mb().
f33f8da csky: rewrite the alignment implement.
68152c7 csky: bugfix alignment pt_regs error.
d618d43 csky: support set_affinity for irq balance in SMP
ebf86c9 csky: bugfix compile error without CONFIG_SMP.
8537eea csky: remove debug code.
4ebc051 csky: bugfix compile error with linux-4.9.56
75a938e csky: C-SKY SMP supported.
0eebc07 csky: use internal function for map_sg.
3d29751 csky: bugfix can't support highmem
b545d2a csky: bugfix r26 is the link reg for jsri_to_jsr.
9e3313a csky: bugfix sync tls for abiv1 in ptrace.
587a0d2 csky: use __NR_rt_sigreturn in asm-generic.
f562b46 csky: bugfix gpr_set & fpr_set
f57266f csky: bugfix fpu_fpe_helper excute mtcr mfcr.
c676669 csky: bugfix ave is default enable on reset.
d40d34d csky: remove unused sc_mask in sigcontext.h.
274b7a2 csky: redesign the signal's api
7501771 csky: bugfix forget restore usp.
923e2ca csky: re-struct the pt_regs for regset.
2a1e499 csky: fixup config.
ada81ec csky: bugfix abiv1 compile error.
e34acb9 csky: bugfix abiv1 couldn't support -mno-stack-size.
ec53560 csky: change irq map, reserve soft_irq&private_irq space.
c7576f7 csky: bugfix modpost warning with -mno-stack-size
c8ff9d4 csky: support csky mp timer alpha version.
deabaaf csky: update .gitignore.
574815c csky: bugfix compile error with abiv1 in 4.15
0b426a7 csky: bugfix format of cpu verion id.
083435f csky: irq-csky-v2 alpha init.
21209e5 csky: add .gitignore
73e19b4 csky: remove FMFS_FPU_REGS/FMTS_FPU_REGS
07e8fac csky: add fpu regset in ptrace.c
cac779d csky: add CSKY_VECIRQ_LEGENCY for SOC bug.
54bab1d csky: move usp into pt_regs.
b167422 csky: support regset for ptrace.
a098d4c csky: remove ARCH_WANT_IPC_PARSE_VERSION
fe61a84 csky: add timer-of support.
27702e2 csky: bugfix boot error.
ebe3edb csky: bugfix gx6605s boot failed - add __HEAD to head.section for head.S - move INIT_SECTION together to fix compile warning. 7138cae csky: coding convension for timer-nationalchip.c
fa7f9bb csky: use ffs instead of fls.
ddc9e81 csky: change to generic irq chip for irq-csky.c
e9be8b9 irqchip: add generic irq chip for irq-nationalchip
2ee83fe csky: add set_handle_irq(), ref from openrisc & arm.
74181d6 csky: use irq_domain_add_linear instead of leagcy.
fa45ae4 csky: bugfix setup stroge order for uncached.
eb8030f csky: add HIGHMEM config in Kconfig
4f983d4 csky: remove "default n" in Kconfig
2467575 csky: use asm-generic/signal.h
77438e5 csky: coding conventions for irq.c
2e4a2b4 csky: optimize the cache flush ops.
96e1c58 csky: add CONFIG_CPU_ASID_BITS.
9339666 csky: add cprcr() cpwcr() for abiv1
ff05be4 csky: add THREAD_SHIFT define in asm/page.h
52ab022 csky: add mfcr() mtcr() in asm/reg_ops.h
bdcd8f3 csky: revert back Kconfig select.
590c7e6 csky: bugfix compile error with CONFIG_AUDIT
1989292 csky: revert some back with cleanup unistd.h
f1454fe csky: cleanup unistd.h
5d2985f csky: cleanup Kconfig and Makefile.
423d97e csky: cancel subdirectories
cae2af4 csky: use asm-generic/fcntl.h

Guo Ren (21):
csky: Build infrastructure
csky: defconfig
csky: Kernel booting
csky: Exception handling and mm-fault
csky: System Call
csky: Cache and TLB routines
csky: MMU and page table management
csky: Process management and Signal
csky: VDSO and rt_sigreturn
csky: IRQ handling
csky: Atomic operations
csky: ELF and module probe
csky: Library functions
csky: User access
csky: Debug and Ptrace GDB
csky: SMP support
csky: Misc headers
dt-bindings: csky CPU Bindings
dt-bindings: Add vendor prefix for csky
MAINTAINERS: Add csky
csky: support dword access for get_user_size()

 Documentation/devicetree/bindings/csky/cpus.txt    |  73 ++++
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 MAINTAINERS                                        |   9 +
 arch/csky/Kconfig                                  | 205 +++++++++++
 arch/csky/Kconfig.debug                            |   9 +
 arch/csky/Makefile                                 |  93 +++++
 arch/csky/abiv1/Makefile                           |   8 +
 arch/csky/abiv1/alignment.c                        | 326 +++++++++++++++++
 arch/csky/abiv1/bswapdi.c                          |  12 +
 arch/csky/abiv1/bswapsi.c                          |  12 +
 arch/csky/abiv1/cacheflush.c                       |  52 +++
 arch/csky/abiv1/inc/abi/cacheflush.h               |  49 +++
 arch/csky/abiv1/inc/abi/ckmmu.h                    |  75 ++++
 arch/csky/abiv1/inc/abi/elf.h                      |  26 ++
 arch/csky/abiv1/inc/abi/entry.h                    | 160 +++++++++
 arch/csky/abiv1/inc/abi/page.h                     |  27 ++
 arch/csky/abiv1/inc/abi/pgtable-bits.h             |  37 ++
 arch/csky/abiv1/inc/abi/reg_ops.h                  |  27 ++
 arch/csky/abiv1/inc/abi/regdef.h                   |  26 ++
 arch/csky/abiv1/inc/abi/string.h                   |  13 +
 arch/csky/abiv1/inc/abi/vdso.h                     |  17 +
 arch/csky/abiv1/memcpy.S                           | 347 ++++++++++++++++++
 arch/csky/abiv1/memset.c                           |  37 ++
 arch/csky/abiv1/mmap.c                             |  66 ++++
 arch/csky/abiv1/strksyms.c                         |   7 +
 arch/csky/abiv2/Makefile                           |  10 +
 arch/csky/abiv2/cacheflush.c                       |  60 ++++
 arch/csky/abiv2/fpu.c                              | 275 ++++++++++++++
 arch/csky/abiv2/inc/abi/cacheflush.h               |  46 +++
 arch/csky/abiv2/inc/abi/ckmmu.h                    |  87 +++++
 arch/csky/abiv2/inc/abi/elf.h                      |  43 +++
 arch/csky/abiv2/inc/abi/entry.h                    | 156 ++++++++
 arch/csky/abiv2/inc/abi/fpu.h                      |  66 ++++
 arch/csky/abiv2/inc/abi/page.h                     |  14 +
 arch/csky/abiv2/inc/abi/pgtable-bits.h             |  37 ++
 arch/csky/abiv2/inc/abi/reg_ops.h                  |  17 +
 arch/csky/abiv2/inc/abi/regdef.h                   |  26 ++
 arch/csky/abiv2/inc/abi/string.h                   |  27 ++
 arch/csky/abiv2/inc/abi/vdso.h                     |  23 ++
 arch/csky/abiv2/memcmp.S                           | 152 ++++++++
 arch/csky/abiv2/memcpy.S                           | 110 ++++++
 arch/csky/abiv2/memmove.S                          | 108 ++++++
 arch/csky/abiv2/memset.S                           |  83 +++++
 arch/csky/abiv2/strcmp.S                           | 168 +++++++++
 arch/csky/abiv2/strcpy.S                           | 123 +++++++
 arch/csky/abiv2/strksyms.c                         |  12 +
 arch/csky/abiv2/strlen.S                           |  97 +++++
 arch/csky/abiv2/sysdep.h                           |  30 ++
 arch/csky/boot/Makefile                            |  24 ++
 arch/csky/boot/dts/Makefile                        |  13 +
 arch/csky/boot/dts/include/dt-bindings             |   1 +
 arch/csky/configs/defconfig                        |  61 ++++
 arch/csky/include/asm/Kbuild                       |  72 ++++
 arch/csky/include/asm/addrspace.h                  |  10 +
 arch/csky/include/asm/atomic.h                     | 212 +++++++++++
 arch/csky/include/asm/barrier.h                    |  49 +++
 arch/csky/include/asm/bitops.h                     |  82 +++++
 arch/csky/include/asm/bug.h                        |  26 ++
 arch/csky/include/asm/cache.h                      |  30 ++
 arch/csky/include/asm/cacheflush.h                 |   9 +
 arch/csky/include/asm/checksum.h                   |  50 +++
 arch/csky/include/asm/cmpxchg.h                    |  73 ++++
 arch/csky/include/asm/elf.h                        |  85 +++++
 arch/csky/include/asm/fixmap.h                     |  27 ++
 arch/csky/include/asm/highmem.h                    |  51 +++
 arch/csky/include/asm/io.h                         |  24 ++
 arch/csky/include/asm/irqflags.h                   |  49 +++
 arch/csky/include/asm/mmu.h                        |  12 +
 arch/csky/include/asm/mmu_context.h                | 150 ++++++++
 arch/csky/include/asm/page.h                       | 104 ++++++
 arch/csky/include/asm/pgalloc.h                    | 115 ++++++
 arch/csky/include/asm/pgtable.h                    | 306 ++++++++++++++++
 arch/csky/include/asm/processor.h                  | 121 +++++++
 arch/csky/include/asm/reg_ops.h                    |  26 ++
 arch/csky/include/asm/segment.h                    |  19 +
 arch/csky/include/asm/shmparam.h                   |  11 +
 arch/csky/include/asm/smp.h                        |  26 ++
 arch/csky/include/asm/spinlock.h                   | 274 ++++++++++++++
 arch/csky/include/asm/spinlock_types.h             |  37 ++
 arch/csky/include/asm/string.h                     |  13 +
 arch/csky/include/asm/switch_to.h                  |  36 ++
 arch/csky/include/asm/syscall.h                    |  71 ++++
 arch/csky/include/asm/syscalls.h                   |  15 +
 arch/csky/include/asm/thread_info.h                |  75 ++++
 arch/csky/include/asm/tlb.h                        |  25 ++
 arch/csky/include/asm/tlbflush.h                   |  25 ++
 arch/csky/include/asm/traps.h                      |  44 +++
 arch/csky/include/asm/uaccess.h                    | 388 ++++++++++++++++++++
 arch/csky/include/asm/unistd.h                     |   4 +
 arch/csky/include/asm/vdso.h                       |  12 +
 arch/csky/include/uapi/asm/Kbuild                  |  33 ++
 arch/csky/include/uapi/asm/byteorder.h             |   9 +
 arch/csky/include/uapi/asm/cachectl.h              |  13 +
 arch/csky/include/uapi/asm/ptrace.h                | 104 ++++++
 arch/csky/include/uapi/asm/sigcontext.h            |  14 +
 arch/csky/include/uapi/asm/unistd.h                |  10 +
 arch/csky/kernel/Makefile                          |   8 +
 arch/csky/kernel/asm-offsets.c                     |  88 +++++
 arch/csky/kernel/atomic.S                          |  87 +++++
 arch/csky/kernel/cpu-probe.c                       |  79 ++++
 arch/csky/kernel/dumpstack.c                       |  66 ++++
 arch/csky/kernel/entry.S                           | 396 +++++++++++++++++++++
 arch/csky/kernel/head.S                            |  77 ++++
 arch/csky/kernel/irq.c                             |  22 ++
 arch/csky/kernel/module.c                          |  92 +++++
 arch/csky/kernel/power.c                           |  30 ++
 arch/csky/kernel/process.c                         | 136 +++++++
 arch/csky/kernel/ptrace.c                          | 314 ++++++++++++++++
 arch/csky/kernel/setup.c                           | 162 +++++++++
 arch/csky/kernel/signal.c                          | 355 ++++++++++++++++++
 arch/csky/kernel/smp.c                             | 237 ++++++++++++
 arch/csky/kernel/syscall.c                         |  43 +++
 arch/csky/kernel/syscall_table.c                   |  14 +
 arch/csky/kernel/time.c                            |  11 +
 arch/csky/kernel/traps.c                           | 172 +++++++++
 arch/csky/kernel/vdso.c                            |  86 +++++
 arch/csky/kernel/vmlinux.lds.S                     |  66 ++++
 arch/csky/lib/Makefile                             |   1 +
 arch/csky/lib/delay.c                              |  39 ++
 arch/csky/lib/usercopy.c                           | 262 ++++++++++++++
 arch/csky/mm/Makefile                              |  13 +
 arch/csky/mm/cachev1.c                             | 126 +++++++
 arch/csky/mm/cachev2.c                             |  79 ++++
 arch/csky/mm/dma-mapping.c                         | 254 +++++++++++++
 arch/csky/mm/fault.c                               | 220 ++++++++++++
 arch/csky/mm/highmem.c                             | 198 +++++++++++
 arch/csky/mm/init.c                                | 122 +++++++
 arch/csky/mm/ioremap.c                             |  48 +++
 arch/csky/mm/syscache.c                            |  32 ++
 arch/csky/mm/tlb.c                                 | 219 ++++++++++++
 130 files changed, 10678 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/csky/cpus.txt
 create mode 100644 arch/csky/Kconfig
 create mode 100644 arch/csky/Kconfig.debug
 create mode 100644 arch/csky/Makefile
 create mode 100644 arch/csky/abiv1/Makefile
 create mode 100644 arch/csky/abiv1/alignment.c
 create mode 100644 arch/csky/abiv1/bswapdi.c
 create mode 100644 arch/csky/abiv1/bswapsi.c
 create mode 100644 arch/csky/abiv1/cacheflush.c
 create mode 100644 arch/csky/abiv1/inc/abi/cacheflush.h
 create mode 100644 arch/csky/abiv1/inc/abi/ckmmu.h
 create mode 100644 arch/csky/abiv1/inc/abi/elf.h
 create mode 100644 arch/csky/abiv1/inc/abi/entry.h
 create mode 100644 arch/csky/abiv1/inc/abi/page.h
 create mode 100644 arch/csky/abiv1/inc/abi/pgtable-bits.h
 create mode 100644 arch/csky/abiv1/inc/abi/reg_ops.h
 create mode 100644 arch/csky/abiv1/inc/abi/regdef.h
 create mode 100644 arch/csky/abiv1/inc/abi/string.h
 create mode 100644 arch/csky/abiv1/inc/abi/vdso.h
 create mode 100644 arch/csky/abiv1/memcpy.S
 create mode 100644 arch/csky/abiv1/memset.c
 create mode 100644 arch/csky/abiv1/mmap.c
 create mode 100644 arch/csky/abiv1/strksyms.c
 create mode 100644 arch/csky/abiv2/Makefile
 create mode 100644 arch/csky/abiv2/cacheflush.c
 create mode 100644 arch/csky/abiv2/fpu.c
 create mode 100644 arch/csky/abiv2/inc/abi/cacheflush.h
 create mode 100644 arch/csky/abiv2/inc/abi/ckmmu.h
 create mode 100644 arch/csky/abiv2/inc/abi/elf.h
 create mode 100644 arch/csky/abiv2/inc/abi/entry.h
 create mode 100644 arch/csky/abiv2/inc/abi/fpu.h
 create mode 100644 arch/csky/abiv2/inc/abi/page.h
 create mode 100644 arch/csky/abiv2/inc/abi/pgtable-bits.h
 create mode 100644 arch/csky/abiv2/inc/abi/reg_ops.h
 create mode 100644 arch/csky/abiv2/inc/abi/regdef.h
 create mode 100644 arch/csky/abiv2/inc/abi/string.h
 create mode 100644 arch/csky/abiv2/inc/abi/vdso.h
 create mode 100644 arch/csky/abiv2/memcmp.S
 create mode 100644 arch/csky/abiv2/memcpy.S
 create mode 100644 arch/csky/abiv2/memmove.S
 create mode 100644 arch/csky/abiv2/memset.S
 create mode 100644 arch/csky/abiv2/strcmp.S
 create mode 100644 arch/csky/abiv2/strcpy.S
 create mode 100644 arch/csky/abiv2/strksyms.c
 create mode 100644 arch/csky/abiv2/strlen.S
 create mode 100644 arch/csky/abiv2/sysdep.h
 create mode 100644 arch/csky/boot/Makefile
 create mode 100644 arch/csky/boot/dts/Makefile
 create mode 120000 arch/csky/boot/dts/include/dt-bindings
 create mode 100644 arch/csky/configs/defconfig
 create mode 100644 arch/csky/include/asm/Kbuild
 create mode 100644 arch/csky/include/asm/addrspace.h
 create mode 100644 arch/csky/include/asm/atomic.h
 create mode 100644 arch/csky/include/asm/barrier.h
 create mode 100644 arch/csky/include/asm/bitops.h
 create mode 100644 arch/csky/include/asm/bug.h
 create mode 100644 arch/csky/include/asm/cache.h
 create mode 100644 arch/csky/include/asm/cacheflush.h
 create mode 100644 arch/csky/include/asm/checksum.h
 create mode 100644 arch/csky/include/asm/cmpxchg.h
 create mode 100644 arch/csky/include/asm/elf.h
 create mode 100644 arch/csky/include/asm/fixmap.h
 create mode 100644 arch/csky/include/asm/highmem.h
 create mode 100644 arch/csky/include/asm/io.h
 create mode 100644 arch/csky/include/asm/irqflags.h
 create mode 100644 arch/csky/include/asm/mmu.h
 create mode 100644 arch/csky/include/asm/mmu_context.h
 create mode 100644 arch/csky/include/asm/page.h
 create mode 100644 arch/csky/include/asm/pgalloc.h
 create mode 100644 arch/csky/include/asm/pgtable.h
 create mode 100644 arch/csky/include/asm/processor.h
 create mode 100644 arch/csky/include/asm/reg_ops.h
 create mode 100644 arch/csky/include/asm/segment.h
 create mode 100644 arch/csky/include/asm/shmparam.h
 create mode 100644 arch/csky/include/asm/smp.h
 create mode 100644 arch/csky/include/asm/spinlock.h
 create mode 100644 arch/csky/include/asm/spinlock_types.h
 create mode 100644 arch/csky/include/asm/string.h
 create mode 100644 arch/csky/include/asm/switch_to.h
 create mode 100644 arch/csky/include/asm/syscall.h
 create mode 100644 arch/csky/include/asm/syscalls.h
 create mode 100644 arch/csky/include/asm/thread_info.h
 create mode 100644 arch/csky/include/asm/tlb.h
 create mode 100644 arch/csky/include/asm/tlbflush.h
 create mode 100644 arch/csky/include/asm/traps.h
 create mode 100644 arch/csky/include/asm/uaccess.h
 create mode 100644 arch/csky/include/asm/unistd.h
 create mode 100644 arch/csky/include/asm/vdso.h
 create mode 100644 arch/csky/include/uapi/asm/Kbuild
 create mode 100644 arch/csky/include/uapi/asm/byteorder.h
 create mode 100644 arch/csky/include/uapi/asm/cachectl.h
 create mode 100644 arch/csky/include/uapi/asm/ptrace.h
 create mode 100644 arch/csky/include/uapi/asm/sigcontext.h
 create mode 100644 arch/csky/include/uapi/asm/unistd.h
 create mode 100644 arch/csky/kernel/Makefile
 create mode 100644 arch/csky/kernel/asm-offsets.c
 create mode 100644 arch/csky/kernel/atomic.S
 create mode 100644 arch/csky/kernel/cpu-probe.c
 create mode 100644 arch/csky/kernel/dumpstack.c
 create mode 100644 arch/csky/kernel/entry.S
 create mode 100644 arch/csky/kernel/head.S
 create mode 100644 arch/csky/kernel/irq.c
 create mode 100644 arch/csky/kernel/module.c
 create mode 100644 arch/csky/kernel/power.c
 create mode 100644 arch/csky/kernel/process.c
 create mode 100644 arch/csky/kernel/ptrace.c
 create mode 100644 arch/csky/kernel/setup.c
 create mode 100644 arch/csky/kernel/signal.c
 create mode 100644 arch/csky/kernel/smp.c
 create mode 100644 arch/csky/kernel/syscall.c
 create mode 100644 arch/csky/kernel/syscall_table.c
 create mode 100644 arch/csky/kernel/time.c
 create mode 100644 arch/csky/kernel/traps.c
 create mode 100644 arch/csky/kernel/vdso.c
 create mode 100644 arch/csky/kernel/vmlinux.lds.S
 create mode 100644 arch/csky/lib/Makefile
 create mode 100644 arch/csky/lib/delay.c
 create mode 100644 arch/csky/lib/usercopy.c
 create mode 100644 arch/csky/mm/Makefile
 create mode 100644 arch/csky/mm/cachev1.c
 create mode 100644 arch/csky/mm/cachev2.c
 create mode 100644 arch/csky/mm/dma-mapping.c
 create mode 100644 arch/csky/mm/fault.c
 create mode 100644 arch/csky/mm/highmem.c
 create mode 100644 arch/csky/mm/init.c
 create mode 100644 arch/csky/mm/ioremap.c
 create mode 100644 arch/csky/mm/syscache.c
 create mode 100644 arch/csky/mm/tlb.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v9 1/21 csky: Build infrastructure

This patch adds Makefile, Kconfig for build infrastructure.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- make allmodconfig is OK.
- Use BUILTIN_DTB as string, remove bool define for compile.
- Add xor.h in asm/Kbuild
- Add compat.h in asm/Kbuild.
- Add select DMA_DIRECT_OPS in Kconfig.
- remove kernel/platform.c in Makefile.
---

---
 arch/csky/Kconfig                      | 205 +++++++++++++++++++++++++++++++++
 arch/csky/Kconfig.debug                |   9 ++
 arch/csky/Makefile                     |  93 +++++++++++++++
 arch/csky/abiv1/Makefile               |   8 ++
 arch/csky/abiv2/Makefile               |  10 ++
 arch/csky/boot/Makefile                |  24 ++++
 arch/csky/boot/dts/Makefile            |  13 +++
 arch/csky/boot/dts/include/dt-bindings |   1 +
 arch/csky/include/asm/Kbuild           |  72 ++++++++++++
 arch/csky/include/uapi/asm/Kbuild      |  33 ++++++
 arch/csky/kernel/Makefile              |   8 ++
 arch/csky/lib/Makefile                 |   1 +
 arch/csky/mm/Makefile                  |  13 +++
 13 files changed, 490 insertions(+)
 create mode 100644 arch/csky/Kconfig
 create mode 100644 arch/csky/Kconfig.debug
 create mode 100644 arch/csky/Makefile
 create mode 100644 arch/csky/abiv1/Makefile
 create mode 100644 arch/csky/abiv2/Makefile
 create mode 100644 arch/csky/boot/Makefile
 create mode 100644 arch/csky/boot/dts/Makefile
 create mode 120000 arch/csky/boot/dts/include/dt-bindings
 create mode 100644 arch/csky/include/asm/Kbuild
 create mode 100644 arch/csky/include/uapi/asm/Kbuild
 create mode 100644 arch/csky/kernel/Makefile
 create mode 100644 arch/csky/lib/Makefile
 create mode 100644 arch/csky/mm/Makefile
arch/csky/Kconfig new file +205 -0
new file mode 100644
index 0000000..0a05585
@@ -0,0 +1,205 @@
+config CSKY
+	def_bool y
+	select ARCH_HAS_SYNC_DMA_FOR_CPU
+	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
+	select ARCH_USE_BUILTIN_BSWAP
+	select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2
+	select COMMON_CLK
+	select CLKSRC_MMIO
+	select CLKSRC_OF
+	select DMA_DIRECT_OPS
+	select DMA_NONCOHERENT_OPS
+	select IRQ_DOMAIN
+	select HANDLE_DOMAIN_IRQ
+	select DW_APB_TIMER_OF
+	select GENERIC_LIB_ASHLDI3
+	select GENERIC_LIB_ASHRDI3
+	select GENERIC_LIB_LSHRDI3
+	select GENERIC_LIB_MULDI3
+	select GENERIC_LIB_CMPDI2
+	select GENERIC_LIB_UCMPDI2
+	select GENERIC_ALLOCATOR
+	select GENERIC_ATOMIC64
+	select GENERIC_CLOCKEVENTS
+	select GENERIC_CPU_DEVICES
+	select GENERIC_IRQ_CHIP
+	select GENERIC_IRQ_PROBE
+	select GENERIC_IRQ_SHOW
+	select GENERIC_IRQ_MULTI_HANDLER
+	select GENERIC_SCHED_CLOCK
+	select GENERIC_SMP_IDLE_THREAD
+	select HAVE_ARCH_TRACEHOOK
+	select HAVE_GENERIC_DMA_COHERENT
+	select HAVE_KERNEL_GZIP
+	select HAVE_KERNEL_LZO
+	select HAVE_KERNEL_LZMA
+	select HAVE_C_RECORDMCOUNT
+	select HAVE_DMA_API_DEBUG
+	select HAVE_DMA_CONTIGUOUS
+	select HAVE_MEMBLOCK
+	select MAY_HAVE_SPARSE_IRQ
+	select MODULES_USE_ELF_RELA if MODULES
+	select NO_BOOTMEM
+	select OF
+	select OF_EARLY_FLATTREE
+	select OF_RESERVED_MEM
+	select PERF_USE_VMALLOC
+	select RTC_LIB
+	select TIMER_OF
+	select USB_ARCH_HAS_EHCI
+	select USB_ARCH_HAS_OHCI
+
+config CPU_HAS_CACHEV2
+	bool
+
+config CPU_HAS_FPUV2
+	bool
+
+config CPU_HAS_HILO
+	bool
+
+config CPU_HAS_TLBI
+	bool
+
+config CPU_HAS_LDSTEX
+	bool
+	help
+	  For SMP, CPU needs "ldex&stex" instrcutions to atomic operations.
+
+config CPU_NEED_TLBSYNC
+	bool
+
+config CPU_NEED_SOFTALIGN
+	bool
+
+config CPU_NO_USER_BKPT
+	bool
+	help
+	  For abiv2 we couldn't use "trap 1" as user space bkpt in gdbserver, because
+	  abiv2 is 16/32bit instruction set and "trap 1" is 32bit.
+	  So we need a 16bit instruction as user space bkpt, and it will cause an illegal
+	  instruction exception.
+	  In kernel we parse the *regs->pc to determine whether to send SIGTRAP or not.
+
+config GENERIC_CALIBRATE_DELAY
+	def_bool y
+
+config GENERIC_CSUM
+	def_bool y
+
+config GENERIC_HWEIGHT
+	def_bool y
+
+config MMU
+	def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+	def_bool y
+
+config TIME_LOW_RES
+	def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+
+config CPU_TLB_SIZE
+	int
+	default "128"	if (CPU_CK610 || CPU_CK807 || CPU_CK810)
+	default "1024"	if (CPU_CK860)
+
+config CPU_ASID_BITS
+	int
+	default "8"	if (CPU_CK610 || CPU_CK807 || CPU_CK810)
+	default "12"	if (CPU_CK860)
+
+config L1_CACHE_SHIFT
+	int
+	default "4"	if (CPU_CK610)
+	default "5"	if (CPU_CK807 || CPU_CK810)
+	default "6"	if (CPU_CK860)
+
+menu "Processor type and features"
+
+choice
+	prompt "CPU MODEL"
+	default CPU_CK807
+
+config CPU_CK610
+	bool "CSKY CPU ck610"
+	select CPU_NEED_TLBSYNC
+	select CPU_NEED_SOFTALIGN
+	select CPU_NO_USER_BKPT
+
+config CPU_CK810
+	bool "CSKY CPU ck810"
+	select CPU_HAS_HILO
+	select CPU_NEED_TLBSYNC
+
+config CPU_CK807
+	bool "CSKY CPU ck807"
+	select CPU_HAS_HILO
+
+config CPU_CK860
+	bool "CSKY CPU ck860"
+	select CPU_HAS_TLBI
+	select CPU_HAS_CACHEV2
+	select CPU_HAS_LDSTEX
+	select CPU_HAS_FPUV2
+endchoice
+
+choice
+	prompt "Power Manager Instruction (wait/doze/stop)"
+	default CPU_PM_NONE
+
+config CPU_PM_NONE
+	bool "None"
+
+config CPU_PM_WAIT
+	bool "wait"
+
+config CPU_PM_DOZE
+	bool "doze"
+
+config CPU_PM_STOP
+	bool "stop"
+endchoice
+
+config CPU_HAS_VDSP
+	bool "CPU has VDSP coprocessor"
+	depends on CPU_HAS_FPU && CPU_HAS_FPUV2
+
+config CPU_HAS_FPU
+	bool "CPU has FPU coprocessor"
+	depends on CPU_CK807 || CPU_CK810 || CPU_CK860
+
+config CPU_HAS_TEE
+	bool "CPU has Trusted Execution Environment"
+	depends on CPU_CK810
+
+config SMP
+	bool "Symmetric Multi-Processing (SMP) support for C-SKY"
+	depends on CPU_CK860
+	default n
+
+config NR_CPUS
+	int "Maximum number of CPUs (2-32)"
+	range 2 32
+	depends on SMP
+	default "2"
+
+config HIGHMEM
+	bool "High Memory Support"
+	depends on !CPU_CK610
+	default y
+
+config FORCE_MAX_ZONEORDER
+	int "Maximum zone order"
+	default "11"
+
+config RAM_BASE
+	hex "DRAM start addr (the same with memory-section in dts)"
+	default 0x0
+
+endmenu
+
+source "kernel/Kconfig.hz"
arch/csky/Kconfig.debug new file +9 -0
new file mode 100644
index 0000000..48cf6ff
@@ -0,0 +1,9 @@
+menu "C-SKY Debug Options"
+config CSKY_BUILTIN_DTB
+	string "Use kernel builtin dtb"
+	help
+	  User could define the dtb instead of the one which is passed from
+	  bootloader.
+	  Sometimes for debug, we want to use a built-in dtb and then we needn't
+	  modify bootloader at all.
+endmenu
arch/csky/Makefile new file +93 -0

93 lines not on this page · raw message

arch/csky/abiv1/Makefile new file +8 -0
new file mode 100644
index 0000000..7c06276
@@ -0,0 +1,8 @@
+obj-$(CONFIG_CPU_NEED_SOFTALIGN)	+= alignment.o
+obj-y					+= bswapdi.o
+obj-y					+= bswapsi.o
+obj-y					+= cacheflush.o
+obj-y					+= mmap.o
+obj-y					+= memcpy.o
+obj-y					+= memset.o
+obj-y					+= strksyms.o
arch/csky/abiv2/Makefile new file +10 -0
new file mode 100644
index 0000000..069ca72
@@ -0,0 +1,10 @@
+obj-y				+= cacheflush.o
+obj-$(CONFIG_CPU_HAS_FPU)	+= fpu.o
+obj-y				+= memcmp.o
+obj-y				+= memcpy.o
+obj-y				+= memmove.o
+obj-y				+= memset.o
+obj-y				+= strcmp.o
+obj-y				+= strcpy.o
+obj-y				+= strlen.o
+obj-y				+= strksyms.o
arch/csky/boot/Makefile new file +24 -0
new file mode 100644
index 0000000..47d3d72
@@ -0,0 +1,24 @@
+targets := Image zImage uImage
+targets += $(dtb-y)
+
+$(obj)/Image: vmlinux FORCE
+	$(call if_changed,objcopy)
+	@echo '  Kernel: $@ is ready'
+
+compress-$(CONFIG_KERNEL_GZIP) = gzip
+compress-$(CONFIG_KERNEL_LZO)  = lzo
+compress-$(CONFIG_KERNEL_LZMA) = lzma
+compress-$(CONFIG_KERNEL_XZ)   = xzkern
+compress-$(CONFIG_KERNEL_LZ4)  = lz4
+
+$(obj)/zImage:  $(obj)/Image FORCE
+	$(call if_changed,$(compress-y))
+	@echo '  Kernel: $@ is ready'
+
+UIMAGE_ARCH		= sandbox
+UIMAGE_COMPRESSION	= $(compress-y)
+UIMAGE_LOADADDR		= $(shell $(NM) vmlinux | awk '$$NF == "_start" {print $$1}')
+
+$(obj)/uImage: $(obj)/zImage
+	$(call if_changed,uimage)
+	@echo 'Image: $@ is ready'
arch/csky/boot/dts/Makefile new file +13 -0
new file mode 100644
index 0000000..305e81a
@@ -0,0 +1,13 @@
+dtstree	:= $(srctree)/$(src)
+
+ifneq '$(CONFIG_CSKY_BUILTIN_DTB)' '""'
+builtindtb-y := $(patsubst "%",%,$(CONFIG_CSKY_BUILTIN_DTB))
+dtb-y += $(builtindtb-y).dtb
+obj-y += $(builtindtb-y).dtb.o
+.SECONDARY: $(obj)/$(builtindtb-y).dtb.S
+else
+dtb-y := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts))
+endif
+
+always += $(dtb-y)
+clean-files += *.dtb *.dtb.S
arch/csky/boot/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..08c00e4
@@ -0,0 +1 @@
+../../../../../include/dt-bindings
\ No newline at end of file
arch/csky/include/asm/Kbuild new file +72 -0

72 lines not on this page · raw message

arch/csky/include/uapi/asm/Kbuild new file +33 -0
new file mode 100644
index 0000000..b65252b
@@ -0,0 +1,33 @@
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += cachectl.h
+header-y += stat.h
+
+generic-y += auxvec.h
+generic-y += param.h
+generic-y += bpf_perf_event.h
+generic-y += errno.h
+generic-y += fcntl.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += shmbuf.h
+generic-y += bitsperlong.h
+generic-y += mman.h
+generic-y += msgbuf.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += resource.h
+generic-y += sembuf.h
+generic-y += siginfo.h
+generic-y += signal.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += statfs.h
+generic-y += stat.h
+generic-y += setup.h
+generic-y += swab.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += types.h
+generic-y += ucontext.h
arch/csky/kernel/Makefile new file +8 -0
new file mode 100644
index 0000000..4422de7
@@ -0,0 +1,8 @@
+extra-y := head.o vmlinux.lds
+
+obj-y += entry.o atomic.o signal.o traps.o irq.o time.o vdso.o
+obj-y += power.o syscall.o syscall_table.o setup.o
+obj-y += process.o cpu-probe.o ptrace.o dumpstack.o
+
+obj-$(CONFIG_MODULES)			+= module.o
+obj-$(CONFIG_SMP)			+= smp.o
arch/csky/lib/Makefile new file +1 -0
new file mode 100644
index 0000000..d1f368c
@@ -0,0 +1 @@
+lib-y  := usercopy.o delay.o
arch/csky/mm/Makefile new file +13 -0
new file mode 100644
index 0000000..c870eb3
@@ -0,0 +1,13 @@
+ifeq ($(CONFIG_CPU_HAS_CACHEV2),y)
+obj-y +=			cachev2.o
+else
+obj-y +=			cachev1.o
+endif
+
+obj-y +=			dma-mapping.o
+obj-y +=			fault.o
+obj-$(CONFIG_HIGHMEM) +=	highmem.o
+obj-y +=			init.o
+obj-y +=			ioremap.o
+obj-y +=			syscache.o
+obj-y +=			tlb.o
Signature · 1 line
2.7.4
author
#2 lore raw

Re: [PATCH V9 01/21] csky: Build infrastructure

Hi Arnd,

Could you help me review the patch, seems the patch is skipped.
ref: https://lkml.org/lkml/2018/10/16/224

Thx

Quoted 613 lines · Guo Ren

This patch adds Makefile, Kconfig for build infrastructure.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- make allmodconfig is OK.
- Use BUILTIN_DTB as string, remove bool define for compile.
- Add xor.h in asm/Kbuild
- Add compat.h in asm/Kbuild.
- Add select DMA_DIRECT_OPS in Kconfig.
- remove kernel/platform.c in Makefile.
---

---
 arch/csky/Kconfig                      | 205 +++++++++++++++++++++++++++++++++
 arch/csky/Kconfig.debug                |   9 ++
 arch/csky/Makefile                     |  93 +++++++++++++++
 arch/csky/abiv1/Makefile               |   8 ++
 arch/csky/abiv2/Makefile               |  10 ++
 arch/csky/boot/Makefile                |  24 ++++
 arch/csky/boot/dts/Makefile            |  13 +++
 arch/csky/boot/dts/include/dt-bindings |   1 +
 arch/csky/include/asm/Kbuild           |  72 ++++++++++++
 arch/csky/include/uapi/asm/Kbuild      |  33 ++++++
 arch/csky/kernel/Makefile              |   8 ++
 arch/csky/lib/Makefile                 |   1 +
 arch/csky/mm/Makefile                  |  13 +++
 13 files changed, 490 insertions(+)
 create mode 100644 arch/csky/Kconfig
 create mode 100644 arch/csky/Kconfig.debug
 create mode 100644 arch/csky/Makefile
 create mode 100644 arch/csky/abiv1/Makefile
 create mode 100644 arch/csky/abiv2/Makefile
 create mode 100644 arch/csky/boot/Makefile
 create mode 100644 arch/csky/boot/dts/Makefile
 create mode 120000 arch/csky/boot/dts/include/dt-bindings
 create mode 100644 arch/csky/include/asm/Kbuild
 create mode 100644 arch/csky/include/uapi/asm/Kbuild
 create mode 100644 arch/csky/kernel/Makefile
 create mode 100644 arch/csky/lib/Makefile
 create mode 100644 arch/csky/mm/Makefile
arch/csky/Kconfig new file +205 -0
new file mode 100644
index 0000000..0a05585
@@ -0,0 +1,205 @@
+config CSKY
+	def_bool y
+	select ARCH_HAS_SYNC_DMA_FOR_CPU
+	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
+	select ARCH_USE_BUILTIN_BSWAP
+	select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2
+	select COMMON_CLK
+	select CLKSRC_MMIO
+	select CLKSRC_OF
+	select DMA_DIRECT_OPS
+	select DMA_NONCOHERENT_OPS
+	select IRQ_DOMAIN
+	select HANDLE_DOMAIN_IRQ
+	select DW_APB_TIMER_OF
+	select GENERIC_LIB_ASHLDI3
+	select GENERIC_LIB_ASHRDI3
+	select GENERIC_LIB_LSHRDI3
+	select GENERIC_LIB_MULDI3
+	select GENERIC_LIB_CMPDI2
+	select GENERIC_LIB_UCMPDI2
+	select GENERIC_ALLOCATOR
+	select GENERIC_ATOMIC64
+	select GENERIC_CLOCKEVENTS
+	select GENERIC_CPU_DEVICES
+	select GENERIC_IRQ_CHIP
+	select GENERIC_IRQ_PROBE
+	select GENERIC_IRQ_SHOW
+	select GENERIC_IRQ_MULTI_HANDLER
+	select GENERIC_SCHED_CLOCK
+	select GENERIC_SMP_IDLE_THREAD
+	select HAVE_ARCH_TRACEHOOK
+	select HAVE_GENERIC_DMA_COHERENT
+	select HAVE_KERNEL_GZIP
+	select HAVE_KERNEL_LZO
+	select HAVE_KERNEL_LZMA
+	select HAVE_C_RECORDMCOUNT
+	select HAVE_DMA_API_DEBUG
+	select HAVE_DMA_CONTIGUOUS
+	select HAVE_MEMBLOCK
+	select MAY_HAVE_SPARSE_IRQ
+	select MODULES_USE_ELF_RELA if MODULES
+	select NO_BOOTMEM
+	select OF
+	select OF_EARLY_FLATTREE
+	select OF_RESERVED_MEM
+	select PERF_USE_VMALLOC
+	select RTC_LIB
+	select TIMER_OF
+	select USB_ARCH_HAS_EHCI
+	select USB_ARCH_HAS_OHCI
+
+config CPU_HAS_CACHEV2
+	bool
+
+config CPU_HAS_FPUV2
+	bool
+
+config CPU_HAS_HILO
+	bool
+
+config CPU_HAS_TLBI
+	bool
+
+config CPU_HAS_LDSTEX
+	bool
+	help
+	  For SMP, CPU needs "ldex&stex" instrcutions to atomic operations.
+
+config CPU_NEED_TLBSYNC
+	bool
+
+config CPU_NEED_SOFTALIGN
+	bool
+
+config CPU_NO_USER_BKPT
+	bool
+	help
+	  For abiv2 we couldn't use "trap 1" as user space bkpt in gdbserver, because
+	  abiv2 is 16/32bit instruction set and "trap 1" is 32bit.
+	  So we need a 16bit instruction as user space bkpt, and it will cause an illegal
+	  instruction exception.
+	  In kernel we parse the *regs->pc to determine whether to send SIGTRAP or not.
+
+config GENERIC_CALIBRATE_DELAY
+	def_bool y
+
+config GENERIC_CSUM
+	def_bool y
+
+config GENERIC_HWEIGHT
+	def_bool y
+
+config MMU
+	def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+	def_bool y
+
+config TIME_LOW_RES
+	def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+
+config CPU_TLB_SIZE
+	int
+	default "128"	if (CPU_CK610 || CPU_CK807 || CPU_CK810)
+	default "1024"	if (CPU_CK860)
+
+config CPU_ASID_BITS
+	int
+	default "8"	if (CPU_CK610 || CPU_CK807 || CPU_CK810)
+	default "12"	if (CPU_CK860)
+
+config L1_CACHE_SHIFT
+	int
+	default "4"	if (CPU_CK610)
+	default "5"	if (CPU_CK807 || CPU_CK810)
+	default "6"	if (CPU_CK860)
+
+menu "Processor type and features"
+
+choice
+	prompt "CPU MODEL"
+	default CPU_CK807
+
+config CPU_CK610
+	bool "CSKY CPU ck610"
+	select CPU_NEED_TLBSYNC
+	select CPU_NEED_SOFTALIGN
+	select CPU_NO_USER_BKPT
+
+config CPU_CK810
+	bool "CSKY CPU ck810"
+	select CPU_HAS_HILO
+	select CPU_NEED_TLBSYNC
+
+config CPU_CK807
+	bool "CSKY CPU ck807"
+	select CPU_HAS_HILO
+
+config CPU_CK860
+	bool "CSKY CPU ck860"
+	select CPU_HAS_TLBI
+	select CPU_HAS_CACHEV2
+	select CPU_HAS_LDSTEX
+	select CPU_HAS_FPUV2
+endchoice
+
+choice
+	prompt "Power Manager Instruction (wait/doze/stop)"
+	default CPU_PM_NONE
+
+config CPU_PM_NONE
+	bool "None"
+
+config CPU_PM_WAIT
+	bool "wait"
+
+config CPU_PM_DOZE
+	bool "doze"
+
+config CPU_PM_STOP
+	bool "stop"
+endchoice
+
+config CPU_HAS_VDSP
+	bool "CPU has VDSP coprocessor"
+	depends on CPU_HAS_FPU && CPU_HAS_FPUV2
+
+config CPU_HAS_FPU
+	bool "CPU has FPU coprocessor"
+	depends on CPU_CK807 || CPU_CK810 || CPU_CK860
+
+config CPU_HAS_TEE
+	bool "CPU has Trusted Execution Environment"
+	depends on CPU_CK810
+
+config SMP
+	bool "Symmetric Multi-Processing (SMP) support for C-SKY"
+	depends on CPU_CK860
+	default n
+
+config NR_CPUS
+	int "Maximum number of CPUs (2-32)"
+	range 2 32
+	depends on SMP
+	default "2"
+
+config HIGHMEM
+	bool "High Memory Support"
+	depends on !CPU_CK610
+	default y
+
+config FORCE_MAX_ZONEORDER
+	int "Maximum zone order"
+	default "11"
+
+config RAM_BASE
+	hex "DRAM start addr (the same with memory-section in dts)"
+	default 0x0
+
+endmenu
+
+source "kernel/Kconfig.hz"
arch/csky/Kconfig.debug new file +9 -0
new file mode 100644
index 0000000..48cf6ff
@@ -0,0 +1,9 @@
+menu "C-SKY Debug Options"
+config CSKY_BUILTIN_DTB
+	string "Use kernel builtin dtb"
+	help
+	  User could define the dtb instead of the one which is passed from
+	  bootloader.
+	  Sometimes for debug, we want to use a built-in dtb and then we needn't
+	  modify bootloader at all.
+endmenu
arch/csky/Makefile new file +93 -0
new file mode 100644
index 0000000..67a4ae1
@@ -0,0 +1,93 @@
+OBJCOPYFLAGS		:=-O binary
+GZFLAGS			:=-9
+KBUILD_DEFCONFIG	:= defconfig
+
+ifdef CONFIG_CPU_HAS_FPU
+FPUEXT = f
+endif
+
+ifdef CONFIG_CPU_HAS_VDSP
+VDSPEXT = v
+endif
+
+ifdef CONFIG_CPU_HAS_TEE
+TEEEXT = t
+endif
+
+ifdef CONFIG_CPU_CK610
+CPUTYPE	= ck610
+CSKYABI	= abiv1
+endif
+
+ifdef CONFIG_CPU_CK810
+CPUTYPE = ck810
+CSKYABI	= abiv2
+endif
+
+ifdef CONFIG_CPU_CK807
+CPUTYPE = ck807
+CSKYABI	= abiv2
+endif
+
+ifdef CONFIG_CPU_CK860
+CPUTYPE = ck860
+CSKYABI	= abiv2
+endif
+
+ifneq ($(CSKYABI),)
+MCPU_STR = $(CPUTYPE)$(FPUEXT)$(VDSPEXT)$(TEEEXT)
+KBUILD_CFLAGS += -mcpu=$(MCPU_STR)
+KBUILD_CFLAGS += -DCSKYCPU_DEF_NAME=\"$(MCPU_STR)\"
+KBUILD_CFLAGS += -msoft-float -mdiv
+KBUILD_CFLAGS += -fno-tree-vectorize
+endif
+
+KBUILD_CFLAGS += -pipe
+ifeq ($(CSKYABI),abiv2)
+KBUILD_CFLAGS += -mno-stack-size
+endif
+
+abidirs := $(patsubst %,arch/csky/%/,$(CSKYABI))
+KBUILD_CFLAGS += $(patsubst %,-I$(srctree)/%inc,$(abidirs))
+
+KBUILD_CPPFLAGS += -mlittle-endian
+LDFLAGS += -EL
+
+KBUILD_AFLAGS += $(KBUILD_CFLAGS)
+
+head-y := arch/csky/kernel/head.o
+
+core-y += arch/csky/kernel/
+core-y += arch/csky/mm/
+core-y += arch/csky/$(CSKYABI)/
+
+libs-y += arch/csky/lib/ \
+	$(shell $(CC) $(KBUILD_CFLAGS) $(KCFLAGS) -print-libgcc-file-name)
+
+boot := arch/csky/boot
+ifneq '$(CONFIG_CSKY_BUILTIN_DTB)' '""'
+core-y += $(boot)/dts/
+endif
+
+all: zImage
+
+
+dtbs: scripts
+	$(Q)$(MAKE) $(build)=$(boot)/dts
+
+%.dtb %.dtb.S %.dtb.o: scripts
+	$(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
+
+zImage Image uImage: vmlinux dtbs
+	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+archclean:
+	$(Q)$(MAKE) $(clean)=$(boot)
+	$(Q)$(MAKE) $(clean)=$(boot)/dts
+	rm -rf arch/csky/include/generated
+
+define archhelp
+  echo  '* zImage       - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
+  echo  '  Image        - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
+  echo  '  uImage       - U-Boot wrapped zImage'
+endef
arch/csky/abiv1/Makefile new file +8 -0
new file mode 100644
index 0000000..7c06276
@@ -0,0 +1,8 @@
+obj-$(CONFIG_CPU_NEED_SOFTALIGN)	+= alignment.o
+obj-y					+= bswapdi.o
+obj-y					+= bswapsi.o
+obj-y					+= cacheflush.o
+obj-y					+= mmap.o
+obj-y					+= memcpy.o
+obj-y					+= memset.o
+obj-y					+= strksyms.o
arch/csky/abiv2/Makefile new file +10 -0
new file mode 100644
index 0000000..069ca72
@@ -0,0 +1,10 @@
+obj-y				+= cacheflush.o
+obj-$(CONFIG_CPU_HAS_FPU)	+= fpu.o
+obj-y				+= memcmp.o
+obj-y				+= memcpy.o
+obj-y				+= memmove.o
+obj-y				+= memset.o
+obj-y				+= strcmp.o
+obj-y				+= strcpy.o
+obj-y				+= strlen.o
+obj-y				+= strksyms.o
arch/csky/boot/Makefile new file +24 -0
new file mode 100644
index 0000000..47d3d72
@@ -0,0 +1,24 @@
+targets := Image zImage uImage
+targets += $(dtb-y)
+
+$(obj)/Image: vmlinux FORCE
+	$(call if_changed,objcopy)
+	@echo '  Kernel: $@ is ready'
+
+compress-$(CONFIG_KERNEL_GZIP) = gzip
+compress-$(CONFIG_KERNEL_LZO)  = lzo
+compress-$(CONFIG_KERNEL_LZMA) = lzma
+compress-$(CONFIG_KERNEL_XZ)   = xzkern
+compress-$(CONFIG_KERNEL_LZ4)  = lz4
+
+$(obj)/zImage:  $(obj)/Image FORCE
+	$(call if_changed,$(compress-y))
+	@echo '  Kernel: $@ is ready'
+
+UIMAGE_ARCH		= sandbox
+UIMAGE_COMPRESSION	= $(compress-y)
+UIMAGE_LOADADDR		= $(shell $(NM) vmlinux | awk '$$NF == "_start" {print $$1}')
+
+$(obj)/uImage: $(obj)/zImage
+	$(call if_changed,uimage)
+	@echo 'Image: $@ is ready'
arch/csky/boot/dts/Makefile new file +13 -0
new file mode 100644
index 0000000..305e81a
@@ -0,0 +1,13 @@
+dtstree	:= $(srctree)/$(src)
+
+ifneq '$(CONFIG_CSKY_BUILTIN_DTB)' '""'
+builtindtb-y := $(patsubst "%",%,$(CONFIG_CSKY_BUILTIN_DTB))
+dtb-y += $(builtindtb-y).dtb
+obj-y += $(builtindtb-y).dtb.o
+.SECONDARY: $(obj)/$(builtindtb-y).dtb.S
+else
+dtb-y := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts))
+endif
+
+always += $(dtb-y)
+clean-files += *.dtb *.dtb.S
arch/csky/boot/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..08c00e4
@@ -0,0 +1 @@
+../../../../../include/dt-bindings
\ No newline at end of file
arch/csky/include/asm/Kbuild new file +72 -0
new file mode 100644
index 0000000..014eb57
@@ -0,0 +1,72 @@
+generic-y += asm-offsets.h
+generic-y += bitsperlong.h
+generic-y += bugs.h
+generic-y += clkdev.h
+generic-y += compat.h
+generic-y += current.h
+generic-y += delay.h
+generic-y += device.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += dma-contiguous.h
+generic-y += dma-mapping.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += exec.h
+generic-y += fb.h
+generic-y += ftrace.h
+generic-y += futex.h
+generic-y += gpio.h
+generic-y += hardirq.h
+generic-y += hw_irq.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += irq.h
+generic-y += irq_regs.h
+generic-y += ipcbuf.h
+generic-y += irq_work.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += kprobes.h
+generic-y += kvm_para.h
+generic-y += linkage.h
+generic-y += local.h
+generic-y += local64.h
+generic-y += mman.h
+generic-y += mm-arch-hooks.h
+generic-y += module.h
+generic-y += msgbuf.h
+generic-y += mutex.h
+generic-y += param.h
+generic-y += pci.h
+generic-y += percpu.h
+generic-y += posix_types.h
+generic-y += poll.h
+generic-y += preempt.h
+generic-y += qrwlock.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += sembuf.h
+generic-y += serial.h
+generic-y += setup.h
+generic-y += shmbuf.h
+generic-y += shm.h
+generic-y += siginfo.h
+generic-y += signal.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += statfs.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += timex.h
+generic-y += topology.h
+generic-y += trace_clock.h
+generic-y += types.h
+generic-y += ucontext.h
+generic-y += unaligned.h
+generic-y += user.h
+generic-y += vga.h
+generic-y += vmlinux.lds.h
+generic-y += word-at-a-time.h
+generic-y += xor.h
arch/csky/include/uapi/asm/Kbuild new file +33 -0
new file mode 100644
index 0000000..b65252b
@@ -0,0 +1,33 @@
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += cachectl.h
+header-y += stat.h
+
+generic-y += auxvec.h
+generic-y += param.h
+generic-y += bpf_perf_event.h
+generic-y += errno.h
+generic-y += fcntl.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += shmbuf.h
+generic-y += bitsperlong.h
+generic-y += mman.h
+generic-y += msgbuf.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += resource.h
+generic-y += sembuf.h
+generic-y += siginfo.h
+generic-y += signal.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += statfs.h
+generic-y += stat.h
+generic-y += setup.h
+generic-y += swab.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += types.h
+generic-y += ucontext.h
arch/csky/kernel/Makefile new file +8 -0
new file mode 100644
index 0000000..4422de7
@@ -0,0 +1,8 @@
+extra-y := head.o vmlinux.lds
+
+obj-y += entry.o atomic.o signal.o traps.o irq.o time.o vdso.o
+obj-y += power.o syscall.o syscall_table.o setup.o
+obj-y += process.o cpu-probe.o ptrace.o dumpstack.o
+
+obj-$(CONFIG_MODULES)			+= module.o
+obj-$(CONFIG_SMP)			+= smp.o
arch/csky/lib/Makefile new file +1 -0
new file mode 100644
index 0000000..d1f368c
@@ -0,0 +1 @@
+lib-y  := usercopy.o delay.o
arch/csky/mm/Makefile new file +13 -0
new file mode 100644
index 0000000..c870eb3
@@ -0,0 +1,13 @@
+ifeq ($(CONFIG_CPU_HAS_CACHEV2),y)
+obj-y +=			cachev2.o
+else
+obj-y +=			cachev1.o
+endif
+
+obj-y +=			dma-mapping.o
+obj-y +=			fault.o
+obj-$(CONFIG_HIGHMEM) +=	highmem.o
+obj-y +=			init.o
+obj-y +=			ioremap.o
+obj-y +=			syscache.o
+obj-y +=			tlb.o
Signature · 1 line
2.7.4
maintainer Acked-by
#3 lore raw

Re: [PATCH V9 01/21] csky: Build infrastructure

Quoted 5 lines · Guo Ren

Hi Arnd,

Could you help me review the patch, seems the patch is skipped.
ref: https://lkml.org/lkml/2018/10/16/224

Ah right, I missed that. I think I originally had some thoughts on it but didn't immediately comment and then forgot about it. It's basically ok, so

but please have a look below for a follow-up patch:

Quoted 15 lines
Quoted 15 lines
arch/csky/include/asm/Kbuild new file +9 -0
new file mode 100644
index 0000000..014eb57
@@ -0,0 +1,72 @@
+generic-y += asm-offsets.h
+generic-y += bitsperlong.h
+generic-y += bugs.h
+generic-y += clkdev.h
+generic-y += compat.h
+generic-y += current.h
+generic-y += delay.h
+generic-y += device.h
+generic-y += div64.h

...

Quoted 1 line
Quoted 1 line

+generic-y += errno.h

...

Quoted 2 lines

arch/csky/include/asm/Kbuild

Quoted 2 lines
arch/csky/include/asm/Kbuild new file +2 -0
+generic-y += ioctl.h
+generic-y += ioctls.h

A number of the header files that are marked as generic-y in asm/Kbuild are also marked the same way in uapi/asm/Kbuild. I think this is a mistake, since we only need one of the two for each header.

When both exist, we just take the one from asm/, but then we install the uapi/asm/ version in the 'make headers_install' stage, and they both have the same contents, so I think you only need the uapi/asm/ version here.

Quoted 10 lines

arch/csky/include/uapi/asm/Kbuild line 4

Quoted 10 lines
arch/csky/include/uapi/asm/Kbuild new file +4 -0
new file mode 100644
index 0000000..b65252b
@@ -0,0 +1,33 @@
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += cachectl.h
+header-y += stat.h

It also seems that the second statement here (for stat.h) is from an older version, since that header no longer exists, at least if I'm reading your patches correctly.

Arnd

author
#4 lore raw

Re: [PATCH V9 01/21] csky: Build infrastructure

Quoted 4 lines · Arnd Bergmann
Quoted 3 lines · Guo Ren

Hi Arnd,

Quoted 8 lines
Quoted 2 lines

Could you help me review the patch, seems the patch is skipped.
ref: https://lkml.org/lkml/2018/10/16/224

Ah right, I missed that. I think I originally had some thoughts on it but didn't immediately comment and then forgot about it. It's basically ok, so

Thx.

Quoted 29 lines

but please have a look below for a follow-up patch:

Quoted 15 lines
Quoted 15 lines
arch/csky/include/asm/Kbuild new file +9 -0
new file mode 100644
index 0000000..014eb57
@@ -0,0 +1,72 @@
+generic-y += asm-offsets.h
+generic-y += bitsperlong.h
+generic-y += bugs.h
+generic-y += clkdev.h
+generic-y += compat.h
+generic-y += current.h
+generic-y += delay.h
+generic-y += device.h
+generic-y += div64.h

...

Quoted 1 line
Quoted 1 line

+generic-y += errno.h

...

Quoted 2 lines

arch/csky/include/asm/Kbuild

Quoted 2 lines
arch/csky/include/asm/Kbuild new file +2 -0
+generic-y += ioctl.h
+generic-y += ioctls.h

A number of the header files that are marked as generic-y in asm/Kbuild are also marked the same way in uapi/asm/Kbuild. I think this is a mistake, since we only need one of the two for each header.

Quoted 4 lines

When both exist, we just take the one from asm/, but then we install the uapi/asm/ version in the 'make headers_install' stage, and they both have the same contents, so I think you only need the uapi/asm/ version here.

Ok, I've cleaned them up.

Quoted 15 lines
Quoted 11 lines

arch/csky/include/uapi/asm/Kbuild line 4

Quoted 11 lines
arch/csky/include/uapi/asm/Kbuild new file +4 -0
new file mode 100644
index 0000000..b65252b
@@ -0,0 +1,33 @@
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += cachectl.h
+header-y += stat.h

It also seems that the second statement here (for stat.h) is from an older version, since that header no longer exists, at least if I'm reading your patches correctly.

Yes, no "header-y += stat.h" and I've removed it.

Thx for the reviewed.

Best Regards
Guo Ren

author
#5 lore raw

PATCH v9 2/21 csky: defconfig

In reply to Guo Ren

This patch adds csky defconfig.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/configs/defconfig | 61 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 arch/csky/configs/defconfig
arch/csky/configs/defconfig new file +61 -0
new file mode 100644
index 0000000..7ef4289
@@ -0,0 +1,61 @@
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_DEFAULT_HOSTNAME="csky"
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_AUDIT=y
+CONFIG_NO_HZ_IDLE=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_DEFAULT_DEADLINE=y
+CONFIG_CPU_CK807=y
+CONFIG_CPU_HAS_FPU=y
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=65536
+CONFIG_VT_HW_CONSOLE_BINDING=y
+CONFIG_SERIAL_NONSTANDARD=y
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_TTY_PRINTK=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_CSKY_MPTIMER=y
+CONFIG_GX6605S_TIMER=y
+CONFIG_PM_DEVFREQ=y
+CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND=y
+CONFIG_DEVFREQ_GOV_PERFORMANCE=y
+CONFIG_DEVFREQ_GOV_POWERSAVE=y
+CONFIG_DEVFREQ_GOV_USERSPACE=y
+CONFIG_GENERIC_PHY=y
+CONFIG_EXT4_FS=y
+CONFIG_FANOTIFY=y
+CONFIG_QUOTA=y
+CONFIG_FSCACHE=m
+CONFIG_FSCACHE_STATS=y
+CONFIG_CACHEFILES=m
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_UTF8=y
+CONFIG_NTFS_FS=y
+CONFIG_PROC_KCORE=y
+CONFIG_PROC_CHILDREN=y
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_CRAMFS=y
+CONFIG_ROMFS_FS=y
+CONFIG_NFS_FS=y
+CONFIG_PRINTK_TIME=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_FS=y
+CONFIG_MAGIC_SYSRQ=y
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v9 3/21 csky: Kernel booting

In reply to Guo Ren

This patch add boot code. Thx boot params is all in dtb and it's the only way to let kernel get bootloader param information.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- Use built-in dtb when dtb param is NULL.
- Add dummy console for allmodconfig.
---

---
 arch/csky/kernel/head.S        |  77 ++++++++++++++++++++
 arch/csky/kernel/setup.c       | 162 +++++++++++++++++++++++++++++++++++++++++
 arch/csky/kernel/vmlinux.lds.S |  66 +++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 arch/csky/kernel/head.S
 create mode 100644 arch/csky/kernel/setup.c
 create mode 100644 arch/csky/kernel/vmlinux.lds.S
arch/csky/kernel/head.S new file +77 -0
new file mode 100644
index 0000000..9c4ec47
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/linkage.h>
+#include <linux/init.h>
+#include <asm/page.h>
+#include <abi/entry.h>
+
+__HEAD
+ENTRY(_start)
+	/* set super user mode */
+	lrw	a3, DEFAULT_PSR_VALUE
+	mtcr    a3, psr
+	psrset  ee
+
+	SETUP_MMU a3
+
+	/* set stack point */
+	lrw     a3, init_thread_union + THREAD_SIZE
+	mov	sp, a3
+
+	jmpi	csky_start
+END(_start)
+
+#ifdef CONFIG_SMP
+.align 10
+ENTRY(_start_smp_secondary)
+	/* Invalid I/Dcache BTB BHT */
+	movi	a3, 7
+	lsli	a3, 16
+	addi	a3, (1<<4) | 3
+	mtcr	a3, cr17
+
+	tlbi.alls
+
+	/* setup PAGEMASK */
+	movi	a3, 0
+	mtcr	a3, cr<6, 15>
+
+	/* setup MEL0/MEL1 */
+	grs	a0, _start_smp_pc
+_start_smp_pc:
+	bmaski  a1, 13
+	andn    a0, a1
+	movi    a1, 0x00000006
+	movi    a2, 0x00001006
+	or      a1, a0
+	or      a2, a0
+	mtcr	a1, cr<2, 15>
+	mtcr	a2, cr<3, 15>
+
+	/* setup MEH */
+	mtcr	a0, cr<4, 15>
+
+	/* write TLB */
+	bgeni   a3, 28
+	mtcr	a3, cr<8, 15>
+
+	SETUP_MMU a3
+
+	/* enable MMU */
+	movi	a3, 1
+	mtcr    a3, cr18
+
+	jmpi	_goto_mmu_on
+_goto_mmu_on:
+	lrw	a3, DEFAULT_PSR_VALUE
+	mtcr    a3, psr
+	psrset  ee
+
+	/* set stack point */
+	lrw     a3, secondary_stack
+	ld.w	a3, (a3, 0)
+	mov	sp, a3
+
+	jmpi	csky_start_secondary
+END(_start_smp_secondary)
+#endif
arch/csky/kernel/setup.c new file +162 -0

162 lines not on this page · raw message

arch/csky/kernel/vmlinux.lds.S new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#9 lore raw

PATCH v9 4/21 csky: Exception handling and mm-fault

In reply to Guo Ren

This patch adds exception handling code, cpuinfo and mm-fault code.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- Fixup r15 may used by unalignment access and remove r1.
---

---
 arch/csky/abiv1/alignment.c     | 326 +++++++++++++++++++++++++++++++++
 arch/csky/abiv1/inc/abi/entry.h | 160 ++++++++++++++++
 arch/csky/abiv2/inc/abi/entry.h | 156 ++++++++++++++++
 arch/csky/include/asm/traps.h   |  44 +++++
 arch/csky/include/asm/unistd.h  |   4 +
 arch/csky/kernel/cpu-probe.c    |  79 ++++++++
 arch/csky/kernel/entry.S        | 396 ++++++++++++++++++++++++++++++++++++++++
 arch/csky/kernel/traps.c        | 172 +++++++++++++++++
 arch/csky/mm/fault.c            | 220 ++++++++++++++++++++++
 9 files changed, 1557 insertions(+)
 create mode 100644 arch/csky/abiv1/alignment.c
 create mode 100644 arch/csky/abiv1/inc/abi/entry.h
 create mode 100644 arch/csky/abiv2/inc/abi/entry.h
 create mode 100644 arch/csky/include/asm/traps.h
 create mode 100644 arch/csky/include/asm/unistd.h
 create mode 100644 arch/csky/kernel/cpu-probe.c
 create mode 100644 arch/csky/kernel/entry.S
 create mode 100644 arch/csky/kernel/traps.c
 create mode 100644 arch/csky/mm/fault.c
arch/csky/abiv1/alignment.c new file +326 -0
new file mode 100644
index 0000000..60205e9
@@ -0,0 +1,326 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/kernel.h>
+#include <linux/uaccess.h>
+#include <linux/ptrace.h>
+
+static int align_enable = 1;
+static int align_count;
+
+static inline uint32_t get_ptreg(struct pt_regs *regs, uint32_t rx)
+{
+	return rx == 15 ? regs->lr : *((uint32_t *)&(regs->a0) - 2 + rx);
+}
+
+static inline void put_ptreg(struct pt_regs *regs, uint32_t rx, uint32_t val)
+{
+	if (rx == 15)
+		regs->lr = val;
+	else
+		*((uint32_t *)&(regs->a0) - 2 + rx) = val;
+}
+
+/*
+ * Get byte-value from addr and set it to *valp.
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int ldb_asm(uint32_t addr, uint32_t *valp)
+{
+	uint32_t val;
+	int err;
+
+	if (!access_ok(VERIFY_READ, (void *)addr, 1))
+		return 1;
+
+	asm volatile (
+		"movi	%0, 0\n"
+		"1:\n"
+		"ldb	%1, (%2)\n"
+		"br	3f\n"
+		"2:\n"
+		"movi	%0, 1\n"
+		"br	3f\n"
+		".section __ex_table,\"a\"\n"
+		".align 2\n"
+		".long	1b, 2b\n"
+		".previous\n"
+		"3:\n"
+		: "=&r"(err), "=r"(val)
+		: "r" (addr)
+	);
+
+	*valp = val;
+
+	return err;
+}
+
+/*
+ * Put byte-value to addr.
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int stb_asm(uint32_t addr, uint32_t val)
+{
+	int err;
+
+	if (!access_ok(VERIFY_WRITE, (void *)addr, 1))
+		return 1;
+
+	asm volatile (
+		"movi	%0, 0\n"
+		"1:\n"
+		"stb	%1, (%2)\n"
+		"br	3f\n"
+		"2:\n"
+		"movi	%0, 1\n"
+		"br	3f\n"
+		".section __ex_table,\"a\"\n"
+		".align 2\n"
+		".long	1b, 2b\n"
+		".previous\n"
+		"3:\n"
+		: "=&r"(err)
+		: "r"(val), "r" (addr)
+	);
+
+	return err;
+}
+
+/*
+ * Get half-word from [rx + imm]
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int ldh_c(struct pt_regs *regs, uint32_t rz, uint32_t addr)
+{
+	uint32_t byte0, byte1;
+
+	if (ldb_asm(addr, &byte0))
+		return 1;
+	addr += 1;
+	if (ldb_asm(addr, &byte1))
+		return 1;
+
+	byte0 |= byte1 << 8;
+	put_ptreg(regs, rz, byte0);
+
+	return 0;
+}
+
+/*
+ * Store half-word to [rx + imm]
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int sth_c(struct pt_regs *regs, uint32_t rz, uint32_t addr)
+{
+	uint32_t byte0, byte1;
+
+	byte0 = byte1 = get_ptreg(regs, rz);
+
+	byte0 &= 0xff;
+
+	if (stb_asm(addr, byte0))
+		return 1;
+
+	addr += 1;
+	byte1 = (byte1 >> 8) & 0xff;
+	if (stb_asm(addr, byte1))
+		return 1;
+
+	return 0;
+}
+
+/*
+ * Get word from [rx + imm]
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int ldw_c(struct pt_regs *regs, uint32_t rz, uint32_t addr)
+{
+	uint32_t byte0, byte1, byte2, byte3;
+
+	if (ldb_asm(addr, &byte0))
+		return 1;
+
+	addr += 1;
+	if (ldb_asm(addr, &byte1))
+		return 1;
+
+	addr += 1;
+	if (ldb_asm(addr, &byte2))
+		return 1;
+
+	addr += 1;
+	if (ldb_asm(addr, &byte3))
+		return 1;
+
+	byte0 |= byte1 << 8;
+	byte0 |= byte2 << 16;
+	byte0 |= byte3 << 24;
+
+	put_ptreg(regs, rz, byte0);
+
+	return 0;
+}
+
+/*
+ * Store word to [rx + imm]
+ *
+ * Success: return 0
+ * Failure: return 1
+ */
+static int stw_c(struct pt_regs *regs, uint32_t rz, uint32_t addr)
+{
+	uint32_t byte0, byte1, byte2, byte3;
+
+	byte0 = byte1 = byte2 = byte3 = get_ptreg(regs, rz);
+
+	byte0 &= 0xff;
+
+	if (stb_asm(addr, byte0))
+		return 1;
+
+	addr += 1;
+	byte1 = (byte1 >> 8) & 0xff;
+	if (stb_asm(addr, byte1))
+		return 1;
+
+	addr += 1;
+	byte2 = (byte2 >> 16) & 0xff;
+	if (stb_asm(addr, byte2))
+		return 1;
+
+	addr += 1;
+	byte3 = (byte3 >> 24) & 0xff;
+	if (stb_asm(addr, byte3))
+		return 1;
+
+	align_count++;
+
+	return 0;
+}
+
+extern int fixup_exception(struct pt_regs *regs);
+
+#define OP_LDH 0xc000
+#define OP_STH 0xd000
+#define OP_LDW 0x8000
+#define OP_STW 0x9000
+
+void csky_alignment(struct pt_regs *regs)
+{
+	int ret;
+	uint16_t tmp;
+	uint32_t opcode = 0;
+	uint32_t rx     = 0;
+	uint32_t rz     = 0;
+	uint32_t imm    = 0;
+	uint32_t addr   = 0;
+
+	if (!user_mode(regs))
+		goto bad_area;
+
+	ret = get_user(tmp, (uint16_t *)instruction_pointer(regs));
+	if (ret) {
+		pr_err("%s get_user failed.\n", __func__);
+		goto bad_area;
+	}
+
+	opcode = (uint32_t)tmp;
+
+	rx  = opcode & 0xf;
+	imm = (opcode >> 4) & 0xf;
+	rz  = (opcode >> 8) & 0xf;
+	opcode &= 0xf000;
+
+	if (rx == 0 || rx == 1 || rz == 0 || rz == 1)
+		goto bad_area;
+
+	switch (opcode) {
+	case OP_LDH:
+		addr = get_ptreg(regs, rx) + (imm << 1);
+		ret = ldh_c(regs, rz, addr);
+		break;
+	case OP_LDW:
+		addr = get_ptreg(regs, rx) + (imm << 2);
+		ret = ldw_c(regs, rz, addr);
+		break;
+	case OP_STH:
+		addr = get_ptreg(regs, rx) + (imm << 1);
+		ret = sth_c(regs, rz, addr);
+		break;
+	case OP_STW:
+		addr = get_ptreg(regs, rx) + (imm << 2);
+		ret = stw_c(regs, rz, addr);
+		break;
+	}
+
+	if (ret)
+		goto bad_area;
+
+	regs->pc += 2;
+
+	return;
+
+bad_area:
+	if (!user_mode(regs)) {
+		if (fixup_exception(regs))
+			return;
+
+		bust_spinlocks(1);
+		pr_alert("%s opcode: %x, rz: %d, rx: %d, imm: %d, addr: %x.\n",
+				__func__, opcode, rz, rx, imm, addr);
+		show_regs(regs);
+		bust_spinlocks(0);
+		do_exit(SIGKILL);
+	}
+
+	force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)addr, current);
+}
+
+static struct ctl_table alignment_tbl[4] = {
+	{
+		.procname = "enable",
+		.data = &align_enable,
+		.maxlen = sizeof(align_enable),
+		.mode = 0666,
+		.proc_handler = &proc_dointvec
+	},
+	{
+		.procname = "count",
+		.data = &align_count,
+		.maxlen = sizeof(align_count),
+		.mode = 0666,
+		.proc_handler = &proc_dointvec
+	},
+	{}
+};
+
+static struct ctl_table sysctl_table[2] = {
+	{
+	 .procname = "csky_alignment",
+	 .mode = 0555,
+	 .child = alignment_tbl},
+	{}
+};
+
+static struct ctl_path sysctl_path[2] = {
+	{.procname = "csky"},
+	{}
+};
+
+static int __init csky_alignment_init(void)
+{
+	register_sysctl_paths(sysctl_path, sysctl_table);
+	return 0;
+}
+
+arch_initcall(csky_alignment_init);
arch/csky/abiv1/inc/abi/entry.h new file +160 -0

160 lines not on this page · raw message

arch/csky/abiv2/inc/abi/entry.h new file +156 -0

156 lines not on this page · raw message

arch/csky/include/asm/traps.h new file +44 -0

44 lines not on this page · raw message

arch/csky/include/asm/unistd.h new file +4 -0
new file mode 100644
index 0000000..2844874
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <uapi/asm/unistd.h>
arch/csky/kernel/cpu-probe.c new file +79 -0

79 lines not on this page · raw message

arch/csky/kernel/entry.S new file +396 -0

396 lines not on this page · raw message

arch/csky/kernel/traps.c new file +172 -0

172 lines not on this page · raw message

arch/csky/mm/fault.c new file +220 -0

220 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v9 5/21 csky: System Call

In reply to Guo Ren

This patch adds files related to syscall.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/include/asm/syscall.h     | 71 +++++++++++++++++++++++++++++++++++++
 arch/csky/include/asm/syscalls.h    | 15 ++++++++
 arch/csky/include/uapi/asm/unistd.h | 10 ++++++
 arch/csky/kernel/syscall.c          | 43 ++++++++++++++++++++++
 arch/csky/kernel/syscall_table.c    | 14 ++++++++
 5 files changed, 153 insertions(+)
 create mode 100644 arch/csky/include/asm/syscall.h
 create mode 100644 arch/csky/include/asm/syscalls.h
 create mode 100644 arch/csky/include/uapi/asm/unistd.h
 create mode 100644 arch/csky/kernel/syscall.c
 create mode 100644 arch/csky/kernel/syscall_table.c
arch/csky/include/asm/syscall.h new file +71 -0
new file mode 100644
index 0000000..926a64a
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_SYSCALL_H
+#define __ASM_SYSCALL_H
+
+#include <linux/sched.h>
+#include <linux/err.h>
+#include <abi/regdef.h>
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs_syscallid(regs);
+}
+
+static inline void
+syscall_rollback(struct task_struct *task, struct pt_regs *regs)
+{
+	regs->a0 = regs->orig_a0;
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+	unsigned long error = regs->a0;
+
+	return IS_ERR_VALUE(error) ? error : 0;
+}
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->a0;
+}
+
+static inline void
+syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
+		int error, long val)
+{
+	regs->a0 = (long) error ?: val;
+}
+
+static inline void
+syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, unsigned long *args)
+{
+	BUG_ON(i + n > 6);
+	if (i == 0) {
+		args[0] = regs->orig_a0;
+		args++;
+		i++;
+		n--;
+	}
+	memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
+}
+
+static inline void
+syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
+		      unsigned int i, unsigned int n, const unsigned long *args)
+{
+	BUG_ON(i + n > 6);
+	if (i == 0) {
+		regs->orig_a0 = args[0];
+		args++;
+		i++;
+		n--;
+	}
+	memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
+}
+
+#endif	/* __ASM_SYSCALL_H */
arch/csky/include/asm/syscalls.h new file +15 -0
new file mode 100644
index 0000000..5d48e5e
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_SYSCALLS_H
+#define __ASM_CSKY_SYSCALLS_H
+
+#include <asm-generic/syscalls.h>
+
+long sys_cacheflush(void __user *, unsigned long, int);
+
+long sys_set_thread_area(unsigned long addr);
+
+long sys_csky_fadvise64_64(int fd, int advice, loff_t offset, loff_t len);
+
+#endif /* __ASM_CSKY_SYSCALLS_H */
arch/csky/include/uapi/asm/unistd.h new file +10 -0
new file mode 100644
index 0000000..16ed71e
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#define __ARCH_WANT_SYS_CLONE
+#include <asm-generic/unistd.h>
+
+#define __NR_set_thread_area	(__NR_arch_specific_syscall + 0)
+__SYSCALL(__NR_set_thread_area, sys_set_thread_area)
+#define __NR_cacheflush		(__NR_arch_specific_syscall + 4)
+__SYSCALL(__NR_cacheflush, sys_cacheflush)
arch/csky/kernel/syscall.c new file +43 -0

43 lines not on this page · raw message

arch/csky/kernel/syscall_table.c new file +14 -0
new file mode 100644
index 0000000..a0c238c
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/syscalls.h>
+#include <asm/syscalls.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call)[nr] = (call),
+
+#define sys_fadvise64_64 sys_csky_fadvise64_64
+void * const sys_call_table[__NR_syscalls] __page_aligned_data = {
+	[0 ... __NR_syscalls - 1] = sys_ni_syscall,
+#include <asm/unistd.h>
+};
Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 5/21
#12 lore raw

Re: [PATCH V9 05/21] csky: System Call

Quoted 5 lines · Guo Ren

This patch adds files related to syscall.

Cc Arnd Bergmann <[email protected]>

I had a detailed look at this one and provided lots of comments, however one tiny thing escaped me:

arch/csky/include/uapi/asm/unistd.h line 10

Quoted 4 lines
arch/csky/include/uapi/asm/unistd.h new file +4 -0
+#define __NR_set_thread_area   (__NR_arch_specific_syscall + 0)
+__SYSCALL(__NR_set_thread_area, sys_set_thread_area)
+#define __NR_cacheflush                (__NR_arch_specific_syscall + 4)
+__SYSCALL(__NR_cacheflush, sys_cacheflush)

It's odd that the second one uses __NR_arch_specific_syscall + 4 rather than +1. If you can still change that changing too much other stuff, that might avoid some head-scratching later. If it causes problems, just leave it and maybe add a comment saying that the numbers inbetween are still available.

Arnd

author
#13 lore raw

Re: [PATCH V9 05/21] csky: System Call

Quoted 12 lines · Arnd Bergmann
Quoted 5 lines · Guo Ren

This patch adds files related to syscall.

Cc Arnd Bergmann <[email protected]>

I had a detailed look at this one and provided lots of comments, however one tiny thing escaped me:

Quoted 10 lines

arch/csky/include/uapi/asm/unistd.h line 10

Quoted 4 lines
arch/csky/include/uapi/asm/unistd.h new file +4 -0
+#define __NR_set_thread_area   (__NR_arch_specific_syscall + 0)
+__SYSCALL(__NR_set_thread_area, sys_set_thread_area)
+#define __NR_cacheflush                (__NR_arch_specific_syscall + 4)
+__SYSCALL(__NR_cacheflush, sys_cacheflush)

It's odd that the second one uses __NR_arch_specific_syscall + 4 rather than +1. If you can still change that changing too much other stuff, that might avoid some head-scratching later. If it causes problems, just leave it and maybe add a comment saying that the numbers inbetween are still available.

Change to (__NR_arch_specific_syscall + 1) is ok for now.

Best Regards
Guo Ren

author
#14 lore raw

PATCH v9 6/21 csky: Cache and TLB routines

In reply to Guo Ren

This patch adds cache and tlb sync codes for abiv1 & abiv2.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- fixup module compile error for EXPORT_SYMBOL(cache_wbinv_range).
- tlb.h & cacheflush.h:
fix flush_cache_range and tlb_start_vma of abiv1 in flush_cache_range(vma, ...). cache_wbinv_range() couldn't deal with vma->mm's asid for cache_flush_line and we use cache_wbinv_all() first. Wwe'll improve with cache_flush(vma, start, end) in future. For tlb_start_vma, we make it the same as other arch.
- remove the abi/tlb.h
---

---
 arch/csky/abiv1/cacheflush.c          |  52 ++++++++
 arch/csky/abiv1/inc/abi/cacheflush.h  |  49 ++++++++
 arch/csky/abiv2/cacheflush.c          |  60 ++++++++++
 arch/csky/abiv2/inc/abi/cacheflush.h  |  46 +++++++
 arch/csky/include/asm/barrier.h       |  49 ++++++++
 arch/csky/include/asm/cache.h         |  30 +++++
 arch/csky/include/asm/cacheflush.h    |   9 ++
 arch/csky/include/asm/io.h            |  24 ++++
 arch/csky/include/asm/tlb.h           |  25 ++++
 arch/csky/include/asm/tlbflush.h      |  25 ++++
 arch/csky/include/uapi/asm/cachectl.h |  13 ++
 arch/csky/mm/cachev1.c                | 126 +++++++++++++++++++
 arch/csky/mm/cachev2.c                |  79 ++++++++++++
 arch/csky/mm/syscache.c               |  32 +++++
 arch/csky/mm/tlb.c                    | 219 ++++++++++++++++++++++++++++++++++
 15 files changed, 838 insertions(+)
 create mode 100644 arch/csky/abiv1/cacheflush.c
 create mode 100644 arch/csky/abiv1/inc/abi/cacheflush.h
 create mode 100644 arch/csky/abiv2/cacheflush.c
 create mode 100644 arch/csky/abiv2/inc/abi/cacheflush.h
 create mode 100644 arch/csky/include/asm/barrier.h
 create mode 100644 arch/csky/include/asm/cache.h
 create mode 100644 arch/csky/include/asm/cacheflush.h
 create mode 100644 arch/csky/include/asm/io.h
 create mode 100644 arch/csky/include/asm/tlb.h
 create mode 100644 arch/csky/include/asm/tlbflush.h
 create mode 100644 arch/csky/include/uapi/asm/cachectl.h
 create mode 100644 arch/csky/mm/cachev1.c
 create mode 100644 arch/csky/mm/cachev2.c
 create mode 100644 arch/csky/mm/syscache.c
 create mode 100644 arch/csky/mm/tlb.c
arch/csky/abiv1/cacheflush.c new file +52 -0
new file mode 100644
index 0000000..10af8b6
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/syscalls.h>
+#include <linux/spinlock.h>
+#include <asm/page.h>
+#include <asm/cache.h>
+#include <asm/cacheflush.h>
+#include <asm/cachectl.h>
+
+void flush_dcache_page(struct page *page)
+{
+	struct address_space *mapping = page_mapping(page);
+	unsigned long addr;
+
+	if (mapping && !mapping_mapped(mapping)) {
+		set_bit(PG_arch_1, &(page)->flags);
+		return;
+	}
+
+	/*
+	 * We could delay the flush for the !page_mapping case too.  But that
+	 * case is for exec env/arg pages and those are %99 certainly going to
+	 * get faulted into the tlb (and thus flushed) anyways.
+	 */
+	addr = (unsigned long) page_address(page);
+	dcache_wb_range(addr, addr + PAGE_SIZE);
+}
+
+void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
+		      pte_t *pte)
+{
+	unsigned long addr;
+	struct page *page;
+	unsigned long pfn;
+
+	pfn = pte_pfn(*pte);
+	if (unlikely(!pfn_valid(pfn)))
+		return;
+
+	page = pfn_to_page(pfn);
+	addr = (unsigned long) page_address(page);
+
+	if (vma->vm_flags & VM_EXEC ||
+	    pages_do_alias(addr, address & PAGE_MASK))
+		cache_wbinv_all();
+
+	clear_bit(PG_arch_1, &(page)->flags);
+}
arch/csky/abiv1/inc/abi/cacheflush.h new file +49 -0

49 lines not on this page · raw message

arch/csky/abiv2/cacheflush.c new file +60 -0

60 lines not on this page · raw message

arch/csky/abiv2/inc/abi/cacheflush.h new file +46 -0

46 lines not on this page · raw message

arch/csky/include/asm/barrier.h new file +49 -0

49 lines not on this page · raw message

arch/csky/include/asm/cache.h new file +30 -0
new file mode 100644
index 0000000..d683734
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_CACHE_H
+#define __ASM_CSKY_CACHE_H
+
+/* bytes per L1 cache line */
+#define L1_CACHE_SHIFT	CONFIG_L1_CACHE_SHIFT
+
+#define L1_CACHE_BYTES	(1 << L1_CACHE_SHIFT)
+
+#define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
+
+#ifndef __ASSEMBLY__
+
+void dcache_wb_line(unsigned long start);
+
+void icache_inv_range(unsigned long start, unsigned long end);
+void icache_inv_all(void);
+
+void dcache_wb_range(unsigned long start, unsigned long end);
+void dcache_wbinv_all(void);
+
+void cache_wbinv_range(unsigned long start, unsigned long end);
+void cache_wbinv_all(void);
+
+void dma_wbinv_range(unsigned long start, unsigned long end);
+void dma_wb_range(unsigned long start, unsigned long end);
+
+#endif
+#endif  /* __ASM_CSKY_CACHE_H */
arch/csky/include/asm/cacheflush.h new file +9 -0
new file mode 100644
index 0000000..a96da67
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_CACHEFLUSH_H
+#define __ASM_CSKY_CACHEFLUSH_H
+
+#include <abi/cacheflush.h>
+
+#endif /* __ASM_CSKY_CACHEFLUSH_H */
arch/csky/include/asm/io.h new file +24 -0
new file mode 100644
index 0000000..ecae6b3
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_IO_H
+#define __ASM_CSKY_IO_H
+
+#include <abi/pgtable-bits.h>
+#include <linux/types.h>
+#include <linux/version.h>
+
+extern void __iomem *ioremap(phys_addr_t offset, size_t size);
+
+extern void iounmap(void *addr);
+
+extern int remap_area_pages(unsigned long address, phys_addr_t phys_addr,
+		size_t size, unsigned long flags);
+
+#define ioremap_nocache(phy, sz)	ioremap(phy, sz)
+#define ioremap_wc ioremap_nocache
+#define ioremap_wt ioremap_nocache
+
+#include <asm-generic/io.h>
+
+#endif /* __ASM_CSKY_IO_H */
arch/csky/include/asm/tlb.h new file +25 -0
new file mode 100644
index 0000000..8c7cc09
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_TLB_H
+#define __ASM_CSKY_TLB_H
+
+#include <asm/cacheflush.h>
+
+#define tlb_start_vma(tlb, vma) \
+	do { \
+		if (!tlb->fullmm) \
+			flush_cache_range(vma, vma->vm_start, vma->vm_end); \
+	}  while (0)
+
+#define tlb_end_vma(tlb, vma) \
+	do { \
+		if (!tlb->fullmm) \
+			flush_tlb_range(vma, vma->vm_start, vma->vm_end); \
+	}  while (0)
+
+#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
+
+#include <asm-generic/tlb.h>
+
+#endif /* __ASM_CSKY_TLB_H */
arch/csky/include/asm/tlbflush.h new file +25 -0
new file mode 100644
index 0000000..6845b06
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_TLBFLUSH_H
+#define __ASM_TLBFLUSH_H
+
+/*
+ * TLB flushing:
+ *
+ *  - flush_tlb_all() flushes all processes TLB entries
+ *  - flush_tlb_mm(mm) flushes the specified mm context TLB entries
+ *  - flush_tlb_page(vma, vmaddr) flushes one page
+ *  - flush_tlb_range(vma, start, end) flushes a range of pages
+ *  - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
+ */
+extern void flush_tlb_all(void);
+extern void flush_tlb_mm(struct mm_struct *mm);
+extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
+extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+			    unsigned long end);
+extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
+
+extern void flush_tlb_one(unsigned long vaddr);
+
+#endif
arch/csky/include/uapi/asm/cachectl.h new file +13 -0
new file mode 100644
index 0000000..ddf2f39
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_CACHECTL_H
+#define __ASM_CSKY_CACHECTL_H
+
+/*
+ * See "man cacheflush"
+ */
+#define ICACHE  (1<<0)
+#define DCACHE  (1<<1)
+#define BCACHE  (ICACHE|DCACHE)
+
+#endif /* __ASM_CSKY_CACHECTL_H */
arch/csky/mm/cachev1.c new file +126 -0

126 lines not on this page · raw message

arch/csky/mm/cachev2.c new file +79 -0

79 lines not on this page · raw message

arch/csky/mm/syscache.c new file +32 -0
new file mode 100644
index 0000000..c4645e4
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/syscalls.h>
+#include <asm/page.h>
+#include <asm/cache.h>
+#include <asm/cachectl.h>
+
+SYSCALL_DEFINE3(cacheflush,
+		void __user *, addr,
+		unsigned long, bytes,
+		int, cache)
+{
+	switch (cache) {
+	case ICACHE:
+		icache_inv_range((unsigned long)addr,
+				 (unsigned long)addr + bytes);
+		break;
+	case DCACHE:
+		dcache_wb_range((unsigned long)addr,
+				(unsigned long)addr + bytes);
+		break;
+	case BCACHE:
+		cache_wbinv_range((unsigned long)addr,
+				  (unsigned long)addr + bytes);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
arch/csky/mm/tlb.c new file +219 -0

219 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#16 lore raw

PATCH v9 7/21 csky: MMU and page table management

In reply to Guo Ren

This patch adds files related to memory management and here is our memory-layout:

   Fixmap       : 0xffc02000 – 0xfffff000       (4 MB - 12KB)
   Pkmap        : 0xff800000 – 0xffc00000       (4 MB)
   Vmalloc      : 0xf0200000 – 0xff000000       (238 MB)
   Lowmem       : 0x80000000 – 0xc0000000       (1GB)

abiv1 CPU (CK610) is VIPT cache and it doesn't support highmem. abiv2 CPUs are all PIPT cache and they could support highmem.

Lowmem is directly mapped by msa0 & msa1 reg, and we needn't setup memory page table for it.

---
Changelog:
- fixup pfn_valid(pfn) compile error for modules.
- fixup compile warning for CONFIG_DEBUG_HIGHMEM.
- fixup module compile error for EXPORT_SYMBOL(empty_zero_page).
- dma-mapping: fix up dma_mapping error
The arch_sync_dma_for_cpu()/arch_sync_dma_for_device() implementation is broken for some combinations that end up in a BUG() instead of performing the necessary flushes.

- Fixup arch_sync_dma() broken when size is larger than PAGE_SIZE. Ignore the DMA_ATTR_NON_CONSISTENT, remove the BUG() and use return NULL instead.

The implementation of arch should follow the following rules:
map for_cpu for_device unmap

   TO_DEV  writeback       none            writeback       none
   TO_CPU  invalidate      invalidate*     invalidate      invalidate*
   BIDIR   writeback       invalidate      writeback       invalidate
---
---
 arch/csky/abiv1/inc/abi/ckmmu.h        |  75 ++++++++
 arch/csky/abiv1/inc/abi/page.h         |  27 +++
 arch/csky/abiv1/inc/abi/pgtable-bits.h |  37 ++++
 arch/csky/abiv1/mmap.c                 |  66 +++++++
 arch/csky/abiv2/inc/abi/ckmmu.h        |  87 ++++++++++
 arch/csky/abiv2/inc/abi/page.h         |  14 ++
 arch/csky/abiv2/inc/abi/pgtable-bits.h |  37 ++++
 arch/csky/include/asm/addrspace.h      |  10 ++
 arch/csky/include/asm/fixmap.h         |  27 +++
 arch/csky/include/asm/highmem.h        |  51 ++++++
 arch/csky/include/asm/mmu.h            |  12 ++
 arch/csky/include/asm/page.h           | 104 +++++++++++
 arch/csky/include/asm/pgalloc.h        | 115 +++++++++++++
 arch/csky/include/asm/pgtable.h        | 306 +++++++++++++++++++++++++++++++++
 arch/csky/include/asm/segment.h        |  19 ++
 arch/csky/include/asm/shmparam.h       |  11 ++
 arch/csky/mm/dma-mapping.c             | 254 +++++++++++++++++++++++++++
 arch/csky/mm/highmem.c                 | 198 +++++++++++++++++++++
 arch/csky/mm/init.c                    | 122 +++++++++++++
 arch/csky/mm/ioremap.c                 |  48 ++++++
 20 files changed, 1620 insertions(+)
 create mode 100644 arch/csky/abiv1/inc/abi/ckmmu.h
 create mode 100644 arch/csky/abiv1/inc/abi/page.h
 create mode 100644 arch/csky/abiv1/inc/abi/pgtable-bits.h
 create mode 100644 arch/csky/abiv1/mmap.c
 create mode 100644 arch/csky/abiv2/inc/abi/ckmmu.h
 create mode 100644 arch/csky/abiv2/inc/abi/page.h
 create mode 100644 arch/csky/abiv2/inc/abi/pgtable-bits.h
 create mode 100644 arch/csky/include/asm/addrspace.h
 create mode 100644 arch/csky/include/asm/fixmap.h
 create mode 100644 arch/csky/include/asm/highmem.h
 create mode 100644 arch/csky/include/asm/mmu.h
 create mode 100644 arch/csky/include/asm/page.h
 create mode 100644 arch/csky/include/asm/pgalloc.h
 create mode 100644 arch/csky/include/asm/pgtable.h
 create mode 100644 arch/csky/include/asm/segment.h
 create mode 100644 arch/csky/include/asm/shmparam.h
 create mode 100644 arch/csky/mm/dma-mapping.c
 create mode 100644 arch/csky/mm/highmem.c
 create mode 100644 arch/csky/mm/init.c
 create mode 100644 arch/csky/mm/ioremap.c
arch/csky/abiv1/inc/abi/ckmmu.h new file +75 -0
new file mode 100644
index 0000000..3a00201
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_CKMMUV1_H
+#define __ASM_CSKY_CKMMUV1_H
+#include <abi/reg_ops.h>
+
+static inline int read_mmu_index(void)
+{
+	return cprcr("cpcr0");
+}
+
+static inline void write_mmu_index(int value)
+{
+	cpwcr("cpcr0", value);
+}
+
+static inline int read_mmu_entrylo0(void)
+{
+	return cprcr("cpcr2") << 6;
+}
+
+static inline int read_mmu_entrylo1(void)
+{
+	return cprcr("cpcr3") << 6;
+}
+
+static inline void write_mmu_pagemask(int value)
+{
+	cpwcr("cpcr6", value);
+}
+
+static inline int read_mmu_entryhi(void)
+{
+	return cprcr("cpcr4");
+}
+
+static inline void write_mmu_entryhi(int value)
+{
+	cpwcr("cpcr4", value);
+}
+
+/*
+ * TLB operations.
+ */
+static inline void tlb_probe(void)
+{
+	cpwcr("cpcr8", 0x80000000);
+}
+
+static inline void tlb_read(void)
+{
+	cpwcr("cpcr8", 0x40000000);
+}
+
+static inline void tlb_invalid_all(void)
+{
+	cpwcr("cpcr8", 0x04000000);
+}
+
+static inline void tlb_invalid_indexed(void)
+{
+	cpwcr("cpcr8", 0x02000000);
+}
+
+static inline void setup_pgd(unsigned long pgd, bool kernel)
+{
+	cpwcr("cpcr29", pgd);
+}
+
+static inline unsigned long get_pgd(void)
+{
+	return cprcr("cpcr29");
+}
+#endif /* __ASM_CSKY_CKMMUV1_H */
arch/csky/abiv1/inc/abi/page.h new file +27 -0
new file mode 100644
index 0000000..6336e92
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+extern unsigned long shm_align_mask;
+extern void flush_dcache_page(struct page *page);
+
+static inline unsigned long pages_do_alias(unsigned long addr1,
+					   unsigned long addr2)
+{
+	return (addr1 ^ addr2) & shm_align_mask;
+}
+
+static inline void clear_user_page(void *addr, unsigned long vaddr,
+				   struct page *page)
+{
+	clear_page(addr);
+	if (pages_do_alias((unsigned long) addr, vaddr & PAGE_MASK))
+		flush_dcache_page(page);
+}
+
+static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
+				  struct page *page)
+{
+	copy_page(to, from);
+	if (pages_do_alias((unsigned long) to, vaddr & PAGE_MASK))
+		flush_dcache_page(page);
+}
arch/csky/abiv1/inc/abi/pgtable-bits.h new file +37 -0
new file mode 100644
index 0000000..455075b
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_PGTABLE_BITS_H
+#define __ASM_CSKY_PGTABLE_BITS_H
+
+/* implemented in software */
+#define _PAGE_ACCESSED		(1<<3)
+#define PAGE_ACCESSED_BIT	(3)
+
+#define _PAGE_READ		(1<<1)
+#define _PAGE_WRITE		(1<<2)
+#define _PAGE_PRESENT		(1<<0)
+
+#define _PAGE_MODIFIED		(1<<4)
+#define PAGE_MODIFIED_BIT	(4)
+
+/* implemented in hardware */
+#define _PAGE_GLOBAL		(1<<6)
+
+#define _PAGE_VALID		(1<<7)
+#define PAGE_VALID_BIT		(7)
+
+#define _PAGE_DIRTY		(1<<8)
+#define PAGE_DIRTY_BIT		(8)
+
+#define _PAGE_CACHE		(3<<9)
+#define _PAGE_UNCACHE		(2<<9)
+
+#define _CACHE_MASK		(7<<9)
+
+#define _CACHE_CACHED		(_PAGE_VALID | _PAGE_CACHE)
+#define _CACHE_UNCACHED		(_PAGE_VALID | _PAGE_UNCACHE)
+
+#define HAVE_ARCH_UNMAPPED_AREA
+
+#endif /* __ASM_CSKY_PGTABLE_BITS_H */
arch/csky/abiv1/mmap.c new file +66 -0

66 lines not on this page · raw message

arch/csky/abiv2/inc/abi/ckmmu.h new file +87 -0

87 lines not on this page · raw message

arch/csky/abiv2/inc/abi/page.h new file +14 -0
new file mode 100644
index 0000000..0a70cb5
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+static inline void clear_user_page(void *addr, unsigned long vaddr,
+				   struct page *page)
+{
+	clear_page(addr);
+}
+
+static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
+				  struct page *page)
+{
+	copy_page(to, from);
+}
arch/csky/abiv2/inc/abi/pgtable-bits.h new file +37 -0
new file mode 100644
index 0000000..b20ae19
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_PGTABLE_BITS_H
+#define __ASM_CSKY_PGTABLE_BITS_H
+
+/* implemented in software */
+#define _PAGE_ACCESSED		(1<<7)
+#define PAGE_ACCESSED_BIT	(7)
+
+#define _PAGE_READ		(1<<8)
+#define _PAGE_WRITE		(1<<9)
+#define _PAGE_PRESENT		(1<<10)
+
+#define _PAGE_MODIFIED		(1<<11)
+#define PAGE_MODIFIED_BIT	(11)
+
+/* implemented in hardware */
+#define _PAGE_GLOBAL		(1<<0)
+
+#define _PAGE_VALID		(1<<1)
+#define PAGE_VALID_BIT		(1)
+
+#define _PAGE_DIRTY		(1<<2)
+#define PAGE_DIRTY_BIT		(2)
+
+#define _PAGE_SO		(1<<5)
+#define _PAGE_BUF		(1<<6)
+
+#define _PAGE_CACHE		(1<<3)
+
+#define _CACHE_MASK		_PAGE_CACHE
+
+#define _CACHE_CACHED		(_PAGE_VALID | _PAGE_CACHE | _PAGE_BUF)
+#define _CACHE_UNCACHED		(_PAGE_VALID | _PAGE_SO)
+
+#endif /* __ASM_CSKY_PGTABLE_BITS_H */
arch/csky/include/asm/addrspace.h new file +10 -0
new file mode 100644
index 0000000..d1c2ede
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_ADDRSPACE_H
+#define __ASM_CSKY_ADDRSPACE_H
+
+#define KSEG0		0x80000000ul
+#define KSEG0ADDR(a)	(((unsigned long)a & 0x1fffffff) | KSEG0)
+
+#endif /* __ASM_CSKY_ADDRSPACE_H */
arch/csky/include/asm/fixmap.h new file +27 -0
new file mode 100644
index 0000000..380ff0a
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_FIXMAP_H
+#define __ASM_CSKY_FIXMAP_H
+
+#include <asm/page.h>
+#ifdef CONFIG_HIGHMEM
+#include <linux/threads.h>
+#include <asm/kmap_types.h>
+#endif
+
+enum fixed_addresses {
+#ifdef CONFIG_HIGHMEM
+	FIX_KMAP_BEGIN,
+	FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS) - 1,
+#endif
+	__end_of_fixed_addresses
+};
+
+#define FIXADDR_TOP	0xffffc000
+#define FIXADDR_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
+#define FIXADDR_START	(FIXADDR_TOP - FIXADDR_SIZE)
+
+#include <asm-generic/fixmap.h>
+
+#endif /* __ASM_CSKY_FIXMAP_H */
arch/csky/include/asm/highmem.h new file +51 -0

51 lines not on this page · raw message

arch/csky/include/asm/mmu.h new file +12 -0
new file mode 100644
index 0000000..cb34467
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_MMU_H
+#define __ASM_CSKY_MMU_H
+
+typedef struct {
+	unsigned long asid[NR_CPUS];
+	void *vdso;
+} mm_context_t;
+
+#endif /* __ASM_CSKY_MMU_H */
arch/csky/include/asm/page.h new file +104 -0

104 lines not on this page · raw message

arch/csky/include/asm/pgalloc.h new file +115 -0

115 lines not on this page · raw message

arch/csky/include/asm/pgtable.h new file +306 -0

306 lines not on this page · raw message

arch/csky/include/asm/segment.h new file +19 -0
new file mode 100644
index 0000000..ffdc4c4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_SEGMENT_H
+#define __ASM_CSKY_SEGMENT_H
+
+typedef struct {
+	unsigned long seg;
+} mm_segment_t;
+
+#define KERNEL_DS		((mm_segment_t) { 0xFFFFFFFF })
+#define get_ds()		KERNEL_DS
+
+#define USER_DS			((mm_segment_t) { 0x80000000UL })
+#define get_fs()		(current_thread_info()->addr_limit)
+#define set_fs(x)		(current_thread_info()->addr_limit = (x))
+#define segment_eq(a, b)	((a).seg == (b).seg)
+
+#endif /* __ASM_CSKY_SEGMENT_H */
arch/csky/include/asm/shmparam.h new file +11 -0
new file mode 100644
index 0000000..efafe4c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_SHMPARAM_H
+#define __ASM_CSKY_SHMPARAM_H
+
+#define SHMLBA	(4 * PAGE_SIZE)
+
+#define __ARCH_FORCE_SHMLBA
+
+#endif /* __ASM_CSKY_SHMPARAM_H */
arch/csky/mm/dma-mapping.c new file +254 -0

254 lines not on this page · raw message

arch/csky/mm/highmem.c new file +198 -0

198 lines not on this page · raw message

arch/csky/mm/init.c new file +122 -0

122 lines not on this page · raw message

arch/csky/mm/ioremap.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 7/21
#17 lore raw

Re: [PATCH V9 07/21] csky: MMU and page table management

Quoted 12 lines · Guo Ren

This patch adds files related to memory management and here is our memory-layout:

   Fixmap       : 0xffc02000 – 0xfffff000       (4 MB - 12KB)
   Pkmap        : 0xff800000 – 0xffc00000       (4 MB)
   Vmalloc      : 0xf0200000 – 0xff000000       (238 MB)
   Lowmem       : 0x80000000 – 0xc0000000       (1GB)

abiv1 CPU (CK610) is VIPT cache and it doesn't support highmem. abiv2 CPUs are all PIPT cache and they could support highmem.

Quoted 7 lines

Lowmem is directly mapped by msa0 & msa1 reg, and we needn't setup memory page table for it.

Christoph had all the useful comments on this one, I just checked that I didn't spot anything beyond that.

Arnd

author
#18 lore raw

Re: [PATCH V9 07/21] csky: MMU and page table management

Quoted 21 lines · Arnd Bergmann
Quoted 12 lines · Guo Ren

This patch adds files related to memory management and here is our memory-layout:

   Fixmap       : 0xffc02000 – 0xfffff000       (4 MB - 12KB)
   Pkmap        : 0xff800000 – 0xffc00000       (4 MB)
   Vmalloc      : 0xf0200000 – 0xff000000       (238 MB)
   Lowmem       : 0x80000000 – 0xc0000000       (1GB)

abiv1 CPU (CK610) is VIPT cache and it doesn't support highmem. abiv2 CPUs are all PIPT cache and they could support highmem.

Quoted 7 lines

Lowmem is directly mapped by msa0 & msa1 reg, and we needn't setup memory page table for it.

Quoted 4 lines

Christoph had all the useful comments on this one, I just checked that I didn't spot anything beyond that.

Yes, Christoph help a lot and find a critical bug of "sync_dma > 4K".

Best Regards
Guo Ren

author
#19 lore raw

PATCH v9 8/21 csky: Process management and Signal

In reply to Guo Ren

This patch adds files related to task_switch, sigcontext, signal, fpu context switch.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- abiv2/fpu.c: Userspace should never be sent NSIGXXX as a si_code. Use FPE_FLTUNK instead.
- abiv2/fpu.c: Use force_sig_fault instead.
---

---
 arch/csky/abiv2/fpu.c                   | 275 +++++++++++++++++++++++++
 arch/csky/abiv2/inc/abi/fpu.h           |  66 ++++++
 arch/csky/include/asm/mmu_context.h     | 150 ++++++++++++++
 arch/csky/include/asm/processor.h       | 121 +++++++++++
 arch/csky/include/asm/switch_to.h       |  36 ++++
 arch/csky/include/asm/thread_info.h     |  75 +++++++
 arch/csky/include/uapi/asm/sigcontext.h |  14 ++
 arch/csky/kernel/process.c              | 136 ++++++++++++
 arch/csky/kernel/signal.c               | 355 ++++++++++++++++++++++++++++++++
 arch/csky/kernel/time.c                 |  11 +
 10 files changed, 1239 insertions(+)
 create mode 100644 arch/csky/abiv2/fpu.c
 create mode 100644 arch/csky/abiv2/inc/abi/fpu.h
 create mode 100644 arch/csky/include/asm/mmu_context.h
 create mode 100644 arch/csky/include/asm/processor.h
 create mode 100644 arch/csky/include/asm/switch_to.h
 create mode 100644 arch/csky/include/asm/thread_info.h
 create mode 100644 arch/csky/include/uapi/asm/sigcontext.h
 create mode 100644 arch/csky/kernel/process.c
 create mode 100644 arch/csky/kernel/signal.c
 create mode 100644 arch/csky/kernel/time.c
arch/csky/abiv2/fpu.c new file +275 -0
new file mode 100644
index 0000000..e7e1134
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/ptrace.h>
+#include <linux/uaccess.h>
+#include <abi/reg_ops.h>
+
+#define MTCR_MASK	0xFC00FFE0
+#define MFCR_MASK	0xFC00FFE0
+#define MTCR_DIST	0xC0006420
+#define MFCR_DIST	0xC0006020
+
+void __init init_fpu(void)
+{
+	mtcr("cr<1, 2>", 0);
+}
+
+/*
+ * fpu_libc_helper() is to help libc to excute:
+ *  - mfcr %a, cr<1, 2>
+ *  - mfcr %a, cr<2, 2>
+ *  - mtcr %a, cr<1, 2>
+ *  - mtcr %a, cr<2, 2>
+ */
+int fpu_libc_helper(struct pt_regs *regs)
+{
+	int fault;
+	unsigned long instrptr, regx = 0;
+	unsigned long index = 0, tmp = 0;
+	unsigned long tinstr = 0;
+	u16 instr_hi, instr_low;
+
+	instrptr = instruction_pointer(regs);
+	if (instrptr & 1)
+		return 0;
+
+	fault = __get_user(instr_low, (u16 *)instrptr);
+	if (fault)
+		return 0;
+
+	fault = __get_user(instr_hi, (u16 *)(instrptr + 2));
+	if (fault)
+		return 0;
+
+	tinstr = instr_hi | ((unsigned long)instr_low << 16);
+
+	if (((tinstr >> 21) & 0x1F) != 2)
+		return 0;
+
+	if ((tinstr & MTCR_MASK) == MTCR_DIST) {
+		index = (tinstr >> 16) & 0x1F;
+		if (index > 13)
+			return 0;
+
+		tmp = tinstr & 0x1F;
+		if (tmp > 2)
+			return 0;
+
+		regx =  *(&regs->a0 + index);
+
+		if (tmp == 1)
+			mtcr("cr<1, 2>", regx);
+		else if (tmp == 2)
+			mtcr("cr<2, 2>", regx);
+		else
+			return 0;
+
+		regs->pc += 4;
+		return 1;
+	}
+
+	if ((tinstr & MFCR_MASK) == MFCR_DIST) {
+		index = tinstr & 0x1F;
+		if (index > 13)
+			return 0;
+
+		tmp = ((tinstr >> 16) & 0x1F);
+		if (tmp > 2)
+			return 0;
+
+		if (tmp == 1)
+			regx = mfcr("cr<1, 2>");
+		else if (tmp == 2)
+			regx = mfcr("cr<2, 2>");
+		else
+			return 0;
+
+		*(&regs->a0 + index) = regx;
+
+		regs->pc += 4;
+		return 1;
+	}
+
+	return 0;
+}
+
+void fpu_fpe(struct pt_regs *regs)
+{
+	int sig, code;
+	unsigned int fesr;
+
+	fesr = mfcr("cr<2, 2>");
+
+	sig = SIGFPE;
+	code = FPE_FLTUNK;
+
+	if (fesr & FPE_ILLE) {
+		sig = SIGILL;
+		code = ILL_ILLOPC;
+	} else if (fesr & FPE_IDC) {
+		sig = SIGILL;
+		code = ILL_ILLOPN;
+	} else if (fesr & FPE_FEC) {
+		sig = SIGFPE;
+		if (fesr & FPE_IOC)
+			code = FPE_FLTINV;
+		else if (fesr & FPE_DZC)
+			code = FPE_FLTDIV;
+		else if (fesr & FPE_UFC)
+			code = FPE_FLTUND;
+		else if (fesr & FPE_OFC)
+			code = FPE_FLTOVF;
+		else if (fesr & FPE_IXC)
+			code = FPE_FLTRES;
+	}
+
+	force_sig_fault(sig, code, (void __user *)regs->pc, current);
+}
+
+#define FMFVR_FPU_REGS(vrx, vry)	\
+	"fmfvrl %0, "#vrx"\n"		\
+	"fmfvrh %1, "#vrx"\n"		\
+	"fmfvrl %2, "#vry"\n"		\
+	"fmfvrh %3, "#vry"\n"
+
+#define FMTVR_FPU_REGS(vrx, vry)	\
+	"fmtvrl "#vrx", %0\n"		\
+	"fmtvrh "#vrx", %1\n"		\
+	"fmtvrl "#vry", %2\n"		\
+	"fmtvrh "#vry", %3\n"
+
+#define STW_FPU_REGS(a, b, c, d)	\
+	"stw    %0, (%4, "#a")\n"	\
+	"stw    %1, (%4, "#b")\n"	\
+	"stw    %2, (%4, "#c")\n"	\
+	"stw    %3, (%4, "#d")\n"
+
+#define LDW_FPU_REGS(a, b, c, d)	\
+	"ldw    %0, (%4, "#a")\n"	\
+	"ldw    %1, (%4, "#b")\n"	\
+	"ldw    %2, (%4, "#c")\n"	\
+	"ldw    %3, (%4, "#d")\n"
+
+void save_to_user_fp(struct user_fp *user_fp)
+{
+	unsigned long flg;
+	unsigned long tmp1, tmp2;
+	unsigned long *fpregs;
+
+	local_irq_save(flg);
+
+	tmp1 = mfcr("cr<1, 2>");
+	tmp2 = mfcr("cr<2, 2>");
+
+	user_fp->fcr = tmp1;
+	user_fp->fesr = tmp2;
+
+	fpregs = &user_fp->vr[0];
+#ifdef CONFIG_CPU_HAS_FPUV2
+#ifdef CONFIG_CPU_HAS_VDSP
+	asm volatile(
+		"vstmu.32    vr0-vr3,   (%0)\n"
+		"vstmu.32    vr4-vr7,   (%0)\n"
+		"vstmu.32    vr8-vr11,  (%0)\n"
+		"vstmu.32    vr12-vr15, (%0)\n"
+		"fstmu.64    vr16-vr31, (%0)\n"
+		: "+a"(fpregs)
+		::"memory");
+#else
+	asm volatile(
+		"fstmu.64    vr0-vr31,  (%0)\n"
+		: "+a"(fpregs)
+		::"memory");
+#endif
+#else
+	{
+	unsigned long tmp3, tmp4;
+
+	asm volatile(
+		FMFVR_FPU_REGS(vr0, vr1)
+		STW_FPU_REGS(0, 4, 16, 20)
+		FMFVR_FPU_REGS(vr2, vr3)
+		STW_FPU_REGS(32, 36, 48, 52)
+		FMFVR_FPU_REGS(vr4, vr5)
+		STW_FPU_REGS(64, 68, 80, 84)
+		FMFVR_FPU_REGS(vr6, vr7)
+		STW_FPU_REGS(96, 100, 112, 116)
+		"addi	%4, 128\n"
+		FMFVR_FPU_REGS(vr8, vr9)
+		STW_FPU_REGS(0, 4, 16, 20)
+		FMFVR_FPU_REGS(vr10, vr11)
+		STW_FPU_REGS(32, 36, 48, 52)
+		FMFVR_FPU_REGS(vr12, vr13)
+		STW_FPU_REGS(64, 68, 80, 84)
+		FMFVR_FPU_REGS(vr14, vr15)
+		STW_FPU_REGS(96, 100, 112, 116)
+		: "=a"(tmp1), "=a"(tmp2), "=a"(tmp3),
+		  "=a"(tmp4), "+a"(fpregs)
+		::"memory");
+	}
+#endif
+
+	local_irq_restore(flg);
+}
+
+void restore_from_user_fp(struct user_fp *user_fp)
+{
+	unsigned long flg;
+	unsigned long tmp1, tmp2;
+	unsigned long *fpregs;
+
+	local_irq_save(flg);
+
+	tmp1 = user_fp->fcr;
+	tmp2 = user_fp->fesr;
+
+	mtcr("cr<1, 2>", tmp1);
+	mtcr("cr<2, 2>", tmp2);
+
+	fpregs = &user_fp->vr[0];
+#ifdef CONFIG_CPU_HAS_FPUV2
+#ifdef CONFIG_CPU_HAS_VDSP
+	asm volatile(
+		"vldmu.32    vr0-vr3,   (%0)\n"
+		"vldmu.32    vr4-vr7,   (%0)\n"
+		"vldmu.32    vr8-vr11,  (%0)\n"
+		"vldmu.32    vr12-vr15, (%0)\n"
+		"fldmu.64    vr16-vr31, (%0)\n"
+		: "+a"(fpregs)
+		::"memory");
+#else
+	asm volatile(
+		"fldmu.64    vr0-vr31,  (%0)\n"
+		: "+a"(fpregs)
+		::"memory");
+#endif
+#else
+	{
+	unsigned long tmp3, tmp4;
+
+	asm volatile(
+		LDW_FPU_REGS(0, 4, 16, 20)
+		FMTVR_FPU_REGS(vr0, vr1)
+		LDW_FPU_REGS(32, 36, 48, 52)
+		FMTVR_FPU_REGS(vr2, vr3)
+		LDW_FPU_REGS(64, 68, 80, 84)
+		FMTVR_FPU_REGS(vr4, vr5)
+		LDW_FPU_REGS(96, 100, 112, 116)
+		FMTVR_FPU_REGS(vr6, vr7)
+		"addi	%4, 128\n"
+		LDW_FPU_REGS(0, 4, 16, 20)
+		FMTVR_FPU_REGS(vr8, vr9)
+		LDW_FPU_REGS(32, 36, 48, 52)
+		FMTVR_FPU_REGS(vr10, vr11)
+		LDW_FPU_REGS(64, 68, 80, 84)
+		FMTVR_FPU_REGS(vr12, vr13)
+		LDW_FPU_REGS(96, 100, 112, 116)
+		FMTVR_FPU_REGS(vr14, vr15)
+		: "=a"(tmp1), "=a"(tmp2), "=a"(tmp3),
+		  "=a"(tmp4), "+a"(fpregs)
+		::"memory");
+	}
+#endif
+	local_irq_restore(flg);
+}
arch/csky/abiv2/inc/abi/fpu.h new file +66 -0

66 lines not on this page · raw message

arch/csky/include/asm/mmu_context.h new file +150 -0

150 lines not on this page · raw message

arch/csky/include/asm/processor.h new file +121 -0

121 lines not on this page · raw message

arch/csky/include/asm/switch_to.h new file +36 -0
new file mode 100644
index 0000000..35a39e8
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_SWITCH_TO_H
+#define __ASM_CSKY_SWITCH_TO_H
+
+#include <linux/thread_info.h>
+#ifdef CONFIG_CPU_HAS_FPU
+#include <abi/fpu.h>
+static inline void __switch_to_fpu(struct task_struct *prev,
+				   struct task_struct *next)
+{
+	save_to_user_fp(&prev->thread.user_fp);
+	restore_from_user_fp(&next->thread.user_fp);
+}
+#else
+static inline void __switch_to_fpu(struct task_struct *prev,
+				   struct task_struct *next)
+{}
+#endif
+
+/*
+ * Context switching is now performed out-of-line in switch_to.S
+ */
+extern struct task_struct *__switch_to(struct task_struct *,
+				       struct task_struct *);
+
+#define switch_to(prev, next, last)					\
+	do {								\
+		struct task_struct *__prev = (prev);			\
+		struct task_struct *__next = (next);			\
+		__switch_to_fpu(__prev, __next);			\
+		((last) = __switch_to((prev), (next)));			\
+	} while (0)
+
+#endif /* __ASM_CSKY_SWITCH_TO_H */
arch/csky/include/asm/thread_info.h new file +75 -0

75 lines not on this page · raw message

arch/csky/include/uapi/asm/sigcontext.h new file +14 -0
new file mode 100644
index 0000000..e81e7ff
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_SIGCONTEXT_H
+#define __ASM_CSKY_SIGCONTEXT_H
+
+#include <asm/ptrace.h>
+
+struct sigcontext {
+	struct pt_regs	sc_pt_regs;
+	struct user_fp	sc_user_fp;
+};
+
+#endif /* __ASM_CSKY_SIGCONTEXT_H */
arch/csky/kernel/process.c new file +136 -0

136 lines not on this page · raw message

arch/csky/kernel/signal.c new file +355 -0

355 lines not on this page · raw message

arch/csky/kernel/time.c new file +11 -0
new file mode 100644
index 0000000..b5fc944
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/clk-provider.h>
+#include <linux/clocksource.h>
+
+void __init time_init(void)
+{
+	of_clk_init(NULL);
+	timer_probe();
+}
Signature · 1 line
2.7.4
maintainer
#20 lore raw

Re: [PATCH V9 08/21] csky: Process management and Signal

Quoted 11 lines · Guo Ren

This patch adds files related to task_switch, sigcontext, signal, fpu context switch.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- abiv2/fpu.c: Userspace should never be sent NSIGXXX as a si_code. Use FPE_FLTUNK instead.
- abiv2/fpu.c: Use force_sig_fault instead.

I'm hesitant to provide a Reviewed-by: tag for this one, as I don't understand the signal handling enough myself, and it's something that should be reviewed properly because of the ABI implications.

Maybe someone else can have a closer look at this?

Arnd

author
#21 lore raw

Re: [PATCH V9 08/21] csky: Process management and Signal

Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Guo Ren

This patch adds files related to task_switch, sigcontext, signal, fpu context switch.

Cc Arnd Bergmann <[email protected]>

---
Changelog:
- abiv2/fpu.c: Userspace should never be sent NSIGXXX as a si_code. Use FPE_FLTUNK instead.
- abiv2/fpu.c: Use force_sig_fault instead.

Quoted 5 lines

I'm hesitant to provide a Reviewed-by: tag for this one, as I don't understand the signal handling enough myself, and it's something that should be reviewed properly because of the ABI implications.

Maybe someone else can have a closer look at this?

NSIGXXX and force_sig_fault modification is from Eric W. Biederman in PATCH V6 and I forget add:
Cc: "Eric W. Biederman" <[email protected]>

Best Regards
Guo Ren

author
#22 lore raw

PATCH v9 9/21 csky: VDSO and rt_sigreturn

In reply to Guo Ren

This patch adds files related to VDSO and our VDSO only support rt_sigreturn.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/abiv1/inc/abi/vdso.h | 17 +++++++++
 arch/csky/abiv2/inc/abi/vdso.h | 23 +++++++++++
 arch/csky/include/asm/vdso.h   | 12 ++++++
 arch/csky/kernel/vdso.c        | 86 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+)
 create mode 100644 arch/csky/abiv1/inc/abi/vdso.h
 create mode 100644 arch/csky/abiv2/inc/abi/vdso.h
 create mode 100644 arch/csky/include/asm/vdso.h
 create mode 100644 arch/csky/kernel/vdso.c
arch/csky/abiv1/inc/abi/vdso.h new file +17 -0
new file mode 100644
index 0000000..14352f5
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/uaccess.h>
+
+static inline int setup_vdso_page(unsigned short *ptr)
+{
+	int err = 0;
+
+	/* movi r1, 127 */
+	err |= __put_user(0x67f1, ptr + 0);
+	/* addi r1, (139 - 127) */
+	err |= __put_user(0x20b1, ptr + 1);
+	/* trap 0 */
+	err |= __put_user(0x0008, ptr + 2);
+
+	return err;
+}
arch/csky/abiv2/inc/abi/vdso.h new file +23 -0
new file mode 100644
index 0000000..b60d4a0
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ABI_CSKY_VDSO_H
+#define __ABI_CSKY_VDSO_H
+
+#include <linux/uaccess.h>
+
+static inline int setup_vdso_page(unsigned short *ptr)
+{
+	int err = 0;
+
+	/* movi r7, 173 */
+	err |= __put_user(0xea07, ptr);
+	err |= __put_user(0x008b,      ptr+1);
+
+	/* trap 0 */
+	err |= __put_user(0xc000,   ptr+2);
+	err |= __put_user(0x2020,   ptr+3);
+
+	return err;
+}
+
+#endif /* __ABI_CSKY_STRING_H */
arch/csky/include/asm/vdso.h new file +12 -0
new file mode 100644
index 0000000..d963d69
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_VDSO_H
+#define __ASM_CSKY_VDSO_H
+
+#include <abi/vdso.h>
+
+struct csky_vdso {
+	unsigned short rt_signal_retcode[4];
+};
+
+#endif /* __ASM_CSKY_VDSO_H */
arch/csky/kernel/vdso.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 9/21
#23 lore raw

Re: [PATCH V9 09/21] csky: VDSO and rt_sigreturn

Quoted 6 lines · Guo Ren

This patch adds files related to VDSO and our VDSO only support rt_sigreturn.

Cc Arnd Bergmann <[email protected]>

I was a little worried about the VDSO because of the discussion we had about 64-bit time_t. Since there is no gettimeofday call in here, that's fine, so

author
#24 lore raw

PATCH v9 10/21 csky: IRQ handling

In reply to Guo Ren

This patch adds IRQ handling files.

Cc Arnd Bergmann <[email protected]>
Cc Thomas Gleixner <[email protected]>

---
Changelog:
- Use CONFIG_GENERIC_IRQ_MULTI_HANDLER
---

---
 arch/csky/include/asm/irqflags.h | 49 ++++++++++++++++++++++++++++++++++++++++
 arch/csky/kernel/irq.c           | 22 ++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 arch/csky/include/asm/irqflags.h
 create mode 100644 arch/csky/kernel/irq.c
arch/csky/include/asm/irqflags.h new file +49 -0
new file mode 100644
index 0000000..9e3a569
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_IRQFLAGS_H
+#define __ASM_CSKY_IRQFLAGS_H
+#include <abi/reg_ops.h>
+
+static inline unsigned long arch_local_irq_save(void)
+{
+	unsigned long flags;
+
+	flags = mfcr("psr");
+	asm volatile("psrclr ie\n":::"memory");
+	return flags;
+}
+#define arch_local_irq_save arch_local_irq_save
+
+static inline void arch_local_irq_enable(void)
+{
+	asm volatile("psrset ee, ie\n":::"memory");
+}
+#define arch_local_irq_enable arch_local_irq_enable
+
+static inline void arch_local_irq_disable(void)
+{
+	asm volatile("psrclr ie\n":::"memory");
+}
+#define arch_local_irq_disable arch_local_irq_disable
+
+static inline unsigned long arch_local_save_flags(void)
+{
+	return mfcr("psr");
+}
+#define arch_local_save_flags arch_local_save_flags
+
+static inline void arch_local_irq_restore(unsigned long flags)
+{
+	mtcr("psr", flags);
+}
+#define arch_local_irq_restore arch_local_irq_restore
+
+static inline int arch_irqs_disabled_flags(unsigned long flags)
+{
+	return !(flags & (1<<6));
+}
+#define arch_irqs_disabled_flags arch_irqs_disabled_flags
+
+#include <asm-generic/irqflags.h>
+
+#endif /* __ASM_CSKY_IRQFLAGS_H */
arch/csky/kernel/irq.c new file +22 -0
new file mode 100644
index 0000000..03a1930
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <asm/traps.h>
+#include <asm/smp.h>
+
+void __init init_IRQ(void)
+{
+	irqchip_init();
+#ifdef CONFIG_SMP
+	setup_smp_ipi();
+#endif
+}
+
+asmlinkage void __irq_entry csky_do_IRQ(struct pt_regs *regs)
+{
+	handle_arch_irq(regs);
+}
Signature · 1 line
2.7.4
author
#26 lore raw

Re: [PATCH V9 10/21] csky: IRQ handling

Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Guo Ren

This patch adds IRQ handling files.

Cc Arnd Bergmann <[email protected]>
Cc Thomas Gleixner <[email protected]>

---
Changelog:
- Use CONFIG_GENERIC_IRQ_MULTI_HANDLER

Quoted 4 lines

Using CONFIG_GENERIC_IRQ_MULTI_HANDLER makes this really short, nice!

Yes, this is tglx's suggestion.

Best Regards
Guo Ren

author
#27 lore raw

PATCH v9 11/21 csky: Atomic operations

In reply to Guo Ren

This patch adds atomic, cmpxchg, spinlock files.

Cc Peter Zijlstra <[email protected]>
Cc Andrea Parri <[email protected]>
Cc Arnd Bergmann <[email protected]>

---
Changlog:
- SMP supported
- ticklock supported
- queue-rwlock supported
---

---
 arch/csky/include/asm/atomic.h         | 212 +++++++++++++++++++++++++
 arch/csky/include/asm/cmpxchg.h        |  73 +++++++++
 arch/csky/include/asm/spinlock.h       | 274 +++++++++++++++++++++++++++++++++
 arch/csky/include/asm/spinlock_types.h |  37 +++++
 arch/csky/kernel/atomic.S              |  87 +++++++++++
 5 files changed, 683 insertions(+)
 create mode 100644 arch/csky/include/asm/atomic.h
 create mode 100644 arch/csky/include/asm/cmpxchg.h
 create mode 100644 arch/csky/include/asm/spinlock.h
 create mode 100644 arch/csky/include/asm/spinlock_types.h
 create mode 100644 arch/csky/kernel/atomic.S
arch/csky/include/asm/atomic.h new file +212 -0
new file mode 100644
index 0000000..e369d73
@@ -0,0 +1,212 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_ATOMIC_H
+#define __ASM_CSKY_ATOMIC_H
+
+#include <linux/version.h>
+#include <asm/cmpxchg.h>
+#include <asm/barrier.h>
+
+#ifdef CONFIG_CPU_HAS_LDSTEX
+
+#define __atomic_add_unless __atomic_add_unless
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+	unsigned long tmp, ret;
+
+	smp_mb();
+
+	asm volatile (
+	"1:	ldex.w		%0, (%3) \n"
+	"	mov		%1, %0   \n"
+	"	cmpne		%0, %4   \n"
+	"	bf		2f	 \n"
+	"	add		%0, %2   \n"
+	"	stex.w		%0, (%3) \n"
+	"	bez		%0, 1b   \n"
+	"2:				 \n"
+		: "=&r" (tmp), "=&r" (ret)
+		: "r" (a), "r"(&v->counter), "r"(u)
+		: "memory");
+
+	if (ret != u)
+		smp_mb();
+
+	return ret;
+}
+
+#define ATOMIC_OP(op, c_op)						\
+static inline void atomic_##op(int i, atomic_t *v)			\
+{									\
+	unsigned long tmp;						\
+									\
+	asm volatile (							\
+	"1:	ldex.w		%0, (%2) \n"				\
+	"	" #op "		%0, %1   \n"				\
+	"	stex.w		%0, (%2) \n"				\
+	"	bez		%0, 1b   \n"				\
+		: "=&r" (tmp)						\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+}
+
+#define ATOMIC_OP_RETURN(op, c_op)					\
+static inline int atomic_##op##_return(int i, atomic_t *v)		\
+{									\
+	unsigned long tmp, ret;						\
+									\
+	smp_mb();							\
+	asm volatile (							\
+	"1:	ldex.w		%0, (%3) \n"				\
+	"	" #op "		%0, %2   \n"				\
+	"	mov		%1, %0   \n"				\
+	"	stex.w		%0, (%3) \n"				\
+	"	bez		%0, 1b   \n"				\
+		: "=&r" (tmp), "=&r" (ret)				\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+	smp_mb();							\
+									\
+	return ret;							\
+}
+
+#define ATOMIC_FETCH_OP(op, c_op)					\
+static inline int atomic_fetch_##op(int i, atomic_t *v)			\
+{									\
+	unsigned long tmp, ret;						\
+									\
+	smp_mb();							\
+	asm volatile (							\
+	"1:	ldex.w		%0, (%3) \n"				\
+	"	mov		%1, %0   \n"				\
+	"	" #op "		%0, %2   \n"				\
+	"	stex.w		%0, (%3) \n"				\
+	"	bez		%0, 1b   \n"				\
+		: "=&r" (tmp), "=&r" (ret)				\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+	smp_mb();							\
+									\
+	return ret;							\
+}
+
+#else /* CONFIG_CPU_HAS_LDSTEX */
+
+#include <linux/irqflags.h>
+
+#define __atomic_add_unless __atomic_add_unless
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+	unsigned long tmp, ret, flags;
+
+	raw_local_irq_save(flags);
+
+	asm volatile (
+	"	ldw		%0, (%3) \n"
+	"	mov		%1, %0   \n"
+	"	cmpne		%0, %4   \n"
+	"	bf		2f	 \n"
+	"	add		%0, %2   \n"
+	"	stw		%0, (%3) \n"
+	"2:				 \n"
+		: "=&r" (tmp), "=&r" (ret)
+		: "r" (a), "r"(&v->counter), "r"(u)
+		: "memory");
+
+	raw_local_irq_restore(flags);
+
+	return ret;
+}
+
+#define ATOMIC_OP(op, c_op)						\
+static inline void atomic_##op(int i, atomic_t *v)			\
+{									\
+	unsigned long tmp, flags;					\
+									\
+	raw_local_irq_save(flags);					\
+									\
+	asm volatile (							\
+	"	ldw		%0, (%2) \n"				\
+	"	" #op "		%0, %1   \n"				\
+	"	stw		%0, (%2) \n"				\
+		: "=&r" (tmp)						\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+									\
+	raw_local_irq_restore(flags);					\
+}
+
+#define ATOMIC_OP_RETURN(op, c_op)					\
+static inline int atomic_##op##_return(int i, atomic_t *v)		\
+{									\
+	unsigned long tmp, ret, flags;					\
+									\
+	raw_local_irq_save(flags);					\
+									\
+	asm volatile (							\
+	"	ldw		%0, (%3) \n"				\
+	"	" #op "		%0, %2   \n"				\
+	"	stw		%0, (%3) \n"				\
+	"	mov		%1, %0   \n"				\
+		: "=&r" (tmp), "=&r" (ret)				\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+									\
+	raw_local_irq_restore(flags);					\
+									\
+	return ret;							\
+}
+
+#define ATOMIC_FETCH_OP(op, c_op)					\
+static inline int atomic_fetch_##op(int i, atomic_t *v)			\
+{									\
+	unsigned long tmp, ret, flags;					\
+									\
+	raw_local_irq_save(flags);					\
+									\
+	asm volatile (							\
+	"	ldw		%0, (%3) \n"				\
+	"	mov		%1, %0   \n"				\
+	"	" #op "		%0, %2   \n"				\
+	"	stw		%0, (%3) \n"				\
+		: "=&r" (tmp), "=&r" (ret)				\
+		: "r" (i), "r"(&v->counter)				\
+		: "memory");						\
+									\
+	raw_local_irq_restore(flags);					\
+									\
+	return ret;							\
+}
+
+#endif /* CONFIG_CPU_HAS_LDSTEX */
+
+#define atomic_add_return atomic_add_return
+ATOMIC_OP_RETURN(add, +)
+#define atomic_sub_return atomic_sub_return
+ATOMIC_OP_RETURN(sub, -)
+
+#define atomic_fetch_add atomic_fetch_add
+ATOMIC_FETCH_OP(add, +)
+#define atomic_fetch_sub atomic_fetch_sub
+ATOMIC_FETCH_OP(sub, -)
+#define atomic_fetch_and atomic_fetch_and
+ATOMIC_FETCH_OP(and, &)
+#define atomic_fetch_or atomic_fetch_or
+ATOMIC_FETCH_OP(or, |)
+#define atomic_fetch_xor atomic_fetch_xor
+ATOMIC_FETCH_OP(xor, ^)
+
+#define atomic_and atomic_and
+ATOMIC_OP(and, &)
+#define atomic_or atomic_or
+ATOMIC_OP(or, |)
+#define atomic_xor atomic_xor
+ATOMIC_OP(xor, ^)
+
+#undef ATOMIC_FETCH_OP
+#undef ATOMIC_OP_RETURN
+#undef ATOMIC_OP
+
+#include <asm-generic/atomic.h>
+
+#endif /* __ASM_CSKY_ATOMIC_H */
arch/csky/include/asm/cmpxchg.h new file +73 -0

73 lines not on this page · raw message

arch/csky/include/asm/spinlock.h new file +274 -0

274 lines not on this page · raw message

arch/csky/include/asm/spinlock_types.h new file +37 -0
new file mode 100644
index 0000000..88b8243
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_SPINLOCK_TYPES_H
+#define __ASM_CSKY_SPINLOCK_TYPES_H
+
+#ifndef __LINUX_SPINLOCK_TYPES_H
+# error "please don't include this file directly"
+#endif
+
+#define TICKET_NEXT	16
+
+typedef struct {
+	union {
+		u32 lock;
+		struct __raw_tickets {
+			/* little endian */
+			u16 owner;
+			u16 next;
+		} tickets;
+	};
+} arch_spinlock_t;
+
+#define __ARCH_SPIN_LOCK_UNLOCKED	{ { 0 } }
+
+#ifdef CONFIG_QUEUED_RWLOCKS
+#include <asm-generic/qrwlock_types.h>
+
+#else /* CONFIG_NR_CPUS > 2 */
+
+typedef struct {
+	u32 lock;
+} arch_rwlock_t;
+
+#define __ARCH_RW_LOCK_UNLOCKED		{ 0 }
+
+#endif /* CONFIG_QUEUED_RWLOCKS */
+#endif /* __ASM_CSKY_SPINLOCK_TYPES_H */
arch/csky/kernel/atomic.S new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Acked-by on v9 11/21
#30 lore raw

Re: [PATCH V9 11/21] csky: Atomic operations

In reply to Guo Ren
Quoted 64 lines · Guo Ren
arch/csky/include/asm/spinlock.h new file +58 -0
new file mode 100644
index 0000000..0474603
@@ -0,0 +1,274 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_SPINLOCK_H
+#define __ASM_CSKY_SPINLOCK_H
+
+#include <linux/spinlock_types.h>
+#include <asm/barrier.h>
+
+#ifdef CONFIG_QUEUED_RWLOCKS
+
+/*
+ * Ticket-based spin-locking.
+ */
+static inline void arch_spin_lock(arch_spinlock_t *lock)
+{
+	arch_spinlock_t lockval;
+	u32 ticket_next = 1 << TICKET_NEXT;
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	asm volatile (
+		"1:	ldex.w		%0, (%2) \n"
+		"	mov		%1, %0	 \n"
+		"	add		%0, %3	 \n"
+		"	stex.w		%0, (%2) \n"
+		"	bez		%0, 1b   \n"
+		: "=&r" (tmp), "=&r" (lockval)
+		: "r"(p), "r"(ticket_next)
+		: "cc");
+
+	while (lockval.tickets.next != lockval.tickets.owner)
+		lockval.tickets.owner = READ_ONCE(lock->tickets.owner);
+
+	smp_mb();
+}
+
+static inline int arch_spin_trylock(arch_spinlock_t *lock)
+{
+	u32 tmp, contended, res;
+	u32 ticket_next = 1 << TICKET_NEXT;
+	u32 *p = &lock->lock;
+
+	do {
+		asm volatile (
+		"	ldex.w		%0, (%3)   \n"
+		"	movi		%2, 1	   \n"
+		"	rotli		%1, %0, 16 \n"
+		"	cmpne		%1, %0     \n"
+		"	bt		1f         \n"
+		"	movi		%2, 0	   \n"
+		"	add		%0, %0, %4 \n"
+		"	stex.w		%0, (%3)   \n"
+		"1:				   \n"
+		: "=&r" (res), "=&r" (tmp), "=&r" (contended)
+		: "r"(p), "r"(ticket_next)
+		: "cc");
+	} while (!res);
+

arch/csky/include/asm/spinlock.h line 68

Quoted 10 lines
arch/csky/include/asm/spinlock.h new file +10 -0
+	if (!contended)
+		smp_mb();
+
+	return !contended;
+}
+
+static inline void arch_spin_unlock(arch_spinlock_t *lock)
+{
+	smp_mb();
+	lock->tickets.owner++;
	WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1);
Quoted 20 lines
arch/csky/include/asm/spinlock.h new file +20 -0
+}
+
+static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
+{
+	return lock.tickets.owner == lock.tickets.next;
+}
+
+static inline int arch_spin_is_locked(arch_spinlock_t *lock)
+{
+	return !arch_spin_value_unlocked(READ_ONCE(*lock));
+}
+
+static inline int arch_spin_is_contended(arch_spinlock_t *lock)
+{
+	struct __raw_tickets tickets = READ_ONCE(lock->tickets);
+
+	return (tickets.next - tickets.owner) > 1;
+}
+#define arch_spin_is_contended	arch_spin_is_contended
+

arch/csky/include/asm/spinlock.h line 98

Quoted 10 lines
arch/csky/include/asm/spinlock.h new file +10 -0
+#include <asm/qrwlock.h>
+
+/* See include/linux/spinlock.h */
+#define smp_mb__after_spinlock()	smp_mb()
+
+#else /* CONFIG_QUEUED_RWLOCKS */
+
+/*
+ * Test-and-set spin-locking.
+ */

I'm still not entirely sure why you want to have two spinlock implementations; to me that is just extra maintenance overhead.

Quoted 19 lines
arch/csky/include/asm/spinlock.h new file +19 -0
+static inline void arch_spin_lock(arch_spinlock_t *lock)
+{
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	bnez		%0, 1b   \n"
+		"	movi		%0, 1    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
+	smp_mb();
+}
+
+static inline void arch_spin_unlock(arch_spinlock_t *lock)
+{

arch/csky/include/asm/spinlock.h line 127

Quoted 10 lines
arch/csky/include/asm/spinlock.h new file +10 -0
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	smp_mb();
+	asm volatile (
+		"	movi		%0, 0    \n"
+		"	stw		%0, (%1) \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
	WRITE_ONCE(lock->lock, 0);

?

Quoted 20 lines
arch/csky/include/asm/spinlock.h new file +20 -0
+}
+
+static inline int arch_spin_trylock(arch_spinlock_t *lock)
+{
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	bnez		%0, 2f   \n"
+		"	movi		%0, 1    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		"	movi		%0, 0    \n"
+		"2:				 \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
+
+	if (!tmp)

arch/csky/include/asm/spinlock.h line 157

Quoted 10 lines
arch/csky/include/asm/spinlock.h new file +10 -0
+		smp_mb();
+
+	return !tmp;
+}
+
+#define arch_spin_is_locked(x)	(READ_ONCE((x)->lock) != 0)
+
+/*
+ * read lock/unlock/trylock
+ */

Idem, why do you want a second rwlock_t implementation?

Quoted 24 lines
arch/csky/include/asm/spinlock.h new file +24 -0
+/*
+ * write lock/unlock/trylock
+ */
+static inline void arch_write_lock(arch_rwlock_t *lock)
+{
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	bnez		%0, 1b   \n"
+		"	subi		%0, 1    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
+	smp_mb();
+}
+
+static inline void arch_write_unlock(arch_rwlock_t *lock)
+{
+	u32 *p = &lock->lock;
+	u32 tmp;

arch/csky/include/asm/spinlock.h line 247

Quoted 10 lines
arch/csky/include/asm/spinlock.h new file +10 -0
+
+	smp_mb();
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	movi		%0, 0    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");

Isn't that:

	WRITE_ONCE(lock->lock, 0);
Quoted 65 lines
arch/csky/include/asm/spinlock.h new file +24 -0
+}
+
+static inline int arch_write_trylock(arch_rwlock_t *lock)
+{
+	u32 *p = &lock->lock;
+	u32 tmp;
+
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	bnez		%0, 2f   \n"
+		"	subi		%0, 1    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		"	movi		%0, 0    \n"
+		"2:				 \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
+
+	if (!tmp)
+		smp_mb();
+
+	return !tmp;
+}
arch/csky/kernel/atomic.S new file +34 -0
new file mode 100644
index 0000000..d2357c8
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/linkage.h>
+#include <abi/entry.h>
+
+.text
+
+/*
+ * int csky_cmpxchg(int oldval, int newval, int *ptr)
+ *
+ * If *ptr != oldval && return 1,
+ * else *ptr = newval return 0.
+ */
+#ifdef CONFIG_CPU_HAS_LDSTEX
+ENTRY(csky_cmpxchg)
+	USPTOKSP
+	mfcr	a3, epc
+	INCTRAP	a3
+
+	subi    sp, 8
+	stw     a3, (sp, 0)
+	mfcr    a3, epsr
+	stw     a3, (sp, 4)
+
+	psrset	ee
+1:
+	ldex	a3, (a2)
+	cmpne	a0, a3
+	bt16	2f
+	mov	a3, a1
+	stex	a3, (a2)
+	bez	a3, 1b
+2:

arch/csky/kernel/atomic.S line 44

Quoted 10 lines
arch/csky/kernel/atomic.S new file +10 -0
+	sync.is
+	mvc	a0
+	ldw	a3, (sp, 0)
+	mtcr	a3, epc
+	ldw     a3, (sp, 4)
+	mtcr	a3, epsr
+	addi	sp, 8
+	KSPTOUSP
+	rte
+END(csky_cmpxchg)

I don't understand why you have this; if the CPU has ll/sc, why do you need syscall support?

In any case, nothing terminally broken; so I suppose that's good enough for starters. I just really don't understand some decisions (like having two lock implementations and having that cmpxchg syscall when you have hardware ll/sc).

author
#31 lore raw

Re: [PATCH V9 11/21] csky: Atomic operations

Thx Peter,

Your review has been a great help.

Quoted 5 lines · Peter Zijlstra

Review

Quoted 2 lines · Guo Ren
(quoted diff) +2 -0
+	smp_mb();
+	lock->tickets.owner++;
	WRITE_ONCE(lock->tickets.owner, lock->tickets.owner + 1);

Yes, approve! I should use WRITE_ONCE/READ_ONCE as necessary.

Quoted 6 lines
Quoted 3 lines

+/*
+ * Test-and-set spin-locking.
+ */

I'm still not entirely sure why you want to have two spinlock implementations; to me that is just extra maintenance overhead.

Test and set (spinlock & rwlock) is easier for debug :P, and I don't know the details of queue-rwlock (maybe I should learn it).

From education's view, we could teach students both of them in arch/csky :)

Anyway, I just want to keep both of them.

Thx

Quoted 9 lines

arch/csky/include/asm/spinlock.h line 127

Quoted 6 lines
arch/csky/include/asm/spinlock.h new file +6 -0
+	asm volatile (
+		"	movi		%0, 0    \n"
+		"	stw		%0, (%1) \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");
	WRITE_ONCE(lock->lock, 0);

?

Cool ... I like WRITE_ONCE style.

Quoted 8 lines

arch/csky/include/asm/spinlock.h line 157

Quoted 6 lines
arch/csky/include/asm/spinlock.h new file +6 -0
+
+#define arch_spin_is_locked(x)	(READ_ONCE((x)->lock) != 0)
+
+/*
+ * read lock/unlock/trylock
+ */

Idem, why do you want a second rwlock_t implementation?

The same as above of spinlock.

Quoted 11 lines

arch/csky/include/asm/spinlock.h line 145

Quoted 8 lines
arch/csky/include/asm/spinlock.h new file +8 -0
+	asm volatile (
+		"1:	ldex.w		%0, (%1) \n"
+		"	movi		%0, 0    \n"
+		"	stex.w		%0, (%1) \n"
+		"	bez		%0, 1b   \n"
+		: "=&r" (tmp)
+		: "r"(p)
+		: "cc");

Isn't that:

Quoted 1 line
	WRITE_ONCE(lock->lock, 0);

Yes, no need ldex/stex and you've mentioned in spinlock before :P

Quoted 45 lines
Quoted 45 lines
arch/csky/kernel/atomic.S new file +39 -0
new file mode 100644
index 0000000..d2357c8
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/linkage.h>
+#include <abi/entry.h>
+
+.text
+
+/*
+ * int csky_cmpxchg(int oldval, int newval, int *ptr)
+ *
+ * If *ptr != oldval && return 1,
+ * else *ptr = newval return 0.
+ */
+#ifdef CONFIG_CPU_HAS_LDSTEX
+ENTRY(csky_cmpxchg)
+	USPTOKSP
+	mfcr	a3, epc
+	INCTRAP	a3
+
+	subi    sp, 8
+	stw     a3, (sp, 0)
+	mfcr    a3, epsr
+	stw     a3, (sp, 4)
+ 
+	psrset	ee
+1:
+	ldex	a3, (a2)
+	cmpne	a0, a3
+	bt16	2f
+	mov	a3, a1
+	stex	a3, (a2)
+	bez	a3, 1b
+2:
+	sync.is
+	mvc	a0
+	ldw	a3, (sp, 0)
+	mtcr	a3, epc
+	ldw     a3, (sp, 4)
Quoted 8 lines

arch/csky/kernel/atomic.S line 44

Quoted 5 lines
arch/csky/kernel/atomic.S new file +5 -0
+	mtcr	a3, epsr
+	addi	sp, 8
+	KSPTOUSP
+	rte
+END(csky_cmpxchg)

I don't understand why you have this; if the CPU has ll/sc, why do you need syscall support?

I've really considered your advice before, but from abi view 610/807/810 all have csky_cmpxchg trap and we want to make them the same. Some apps use the trap directly and not use libc api. Maybe we could delete the trap in future version of kernel.

Quoted 7 lines

In any case, nothing terminally broken; so I suppose that's good enough for starters. I just really don't understand some decisions (like having two lock implementations and having that cmpxchg syscall when you have hardware ll/sc).

Thx peter and the two questions which I've clarified in above.

Best Regards
Guo Ren

author
#32 lore raw

PATCH v9 12/21 csky: ELF and module probe

In reply to Guo Ren

This patch adds ELF definition and module relocate codes.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/abiv1/inc/abi/elf.h | 26 ++++++++++++
 arch/csky/abiv2/inc/abi/elf.h | 43 ++++++++++++++++++++
 arch/csky/include/asm/elf.h   | 85 +++++++++++++++++++++++++++++++++++++++
 arch/csky/kernel/module.c     | 92 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 246 insertions(+)
 create mode 100644 arch/csky/abiv1/inc/abi/elf.h
 create mode 100644 arch/csky/abiv2/inc/abi/elf.h
 create mode 100644 arch/csky/include/asm/elf.h
 create mode 100644 arch/csky/kernel/module.c
arch/csky/abiv1/inc/abi/elf.h new file +26 -0
new file mode 100644
index 0000000..3058cc0
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ABI_CSKY_ELF_H
+#define __ABI_CSKY_ELF_H
+
+#define ELF_CORE_COPY_REGS(pr_reg, regs) do {	\
+	pr_reg[0] = regs->pc;			\
+	pr_reg[1] = regs->regs[9];		\
+	pr_reg[2] = regs->usp;			\
+	pr_reg[3] = regs->sr;			\
+	pr_reg[4] = regs->a0;			\
+	pr_reg[5] = regs->a1;			\
+	pr_reg[6] = regs->a2;			\
+	pr_reg[7] = regs->a3;			\
+	pr_reg[8] = regs->regs[0];		\
+	pr_reg[9] = regs->regs[1];		\
+	pr_reg[10] = regs->regs[2];		\
+	pr_reg[11] = regs->regs[3];		\
+	pr_reg[12] = regs->regs[4];		\
+	pr_reg[13] = regs->regs[5];		\
+	pr_reg[14] = regs->regs[6];		\
+	pr_reg[15] = regs->regs[7];		\
+	pr_reg[16] = regs->regs[8];		\
+	pr_reg[17] = regs->lr;			\
+} while (0);
+#endif /* __ABI_CSKY_ELF_H */
arch/csky/abiv2/inc/abi/elf.h new file +43 -0

43 lines not on this page · raw message

arch/csky/include/asm/elf.h new file +85 -0

85 lines not on this page · raw message

arch/csky/kernel/module.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 12/21
#33 lore raw

Re: [PATCH V9 12/21] csky: ELF and module probe

arch/csky/include/asm/elf.h line 55

Quoted 11 lines · Guo Ren

This patch adds ELF definition and module relocate codes.

Cc Arnd Bergmann <[email protected]>
arch/csky/include/asm/elf.h new file +5 -0
+#ifdef __cskyBE__
+#define ELF_DATA       ELFDATA2MSB
+#else
+#define ELF_DATA       ELFDATA2LSB
+#endif

You removed support for big-endian, right? I guess the #ifdef can also get removed here then. Aside from that,

author
#34 lore raw

Re: [PATCH V9 12/21] csky: ELF and module probe

Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Guo Ren

This patch adds ELF definition and module relocate codes.

Cc Arnd Bergmann <[email protected]>
Quoted 8 lines

arch/csky/include/asm/elf.h line 55

Quoted 5 lines
arch/csky/include/asm/elf.h new file +5 -0
+#ifdef __cskyBE__
+#define ELF_DATA       ELFDATA2MSB
+#else
+#define ELF_DATA       ELFDATA2LSB
+#endif

You removed support for big-endian, right? I guess the #ifdef can also get removed here then. Aside from that,

Now, we only support little-endian and it could be removed. But maybe we need support big-endian in future, so I keep it here.

Best Regards
Guo Ren

maintainer
#35 lore raw

Re: [PATCH V9 12/21] csky: ELF and module probe

Quoted 17 lines · Guo Ren
Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Guo Ren

This patch adds ELF definition and module relocate codes.

Cc Arnd Bergmann <[email protected]>
Quoted 8 lines

arch/csky/include/asm/elf.h line 55

Quoted 5 lines
arch/csky/include/asm/elf.h new file +5 -0
+#ifdef __cskyBE__
+#define ELF_DATA       ELFDATA2MSB
+#else
+#define ELF_DATA       ELFDATA2LSB
+#endif

You removed support for big-endian, right? I guess the #ifdef can also get removed here then. Aside from that,

Quoted 2 lines

Now, we only support little-endian and it could be removed. But maybe we need support big-endian in future, so I keep it here.

Ok, just made sure it was intentional.

Arnd

author
#36 lore raw

PATCH v9 13/21 csky: Library functions

In reply to Guo Ren

This patch adds string optimize codes and some auxiliary codes.

---
Changelog:
- Use bt instead of jbt in asm, jbt will cause relocation problem.
- remove kernel/platform.c
---

---
 arch/csky/abiv1/bswapdi.c        |  12 ++
 arch/csky/abiv1/bswapsi.c        |  12 ++
 arch/csky/abiv1/inc/abi/string.h |  13 ++
 arch/csky/abiv1/memcpy.S         | 347 +++++++++++++++++++++++++++++++++++++++
 arch/csky/abiv1/memset.c         |  37 +++++
 arch/csky/abiv1/strksyms.c       |   7 +
 arch/csky/abiv2/inc/abi/string.h |  27 +++
 arch/csky/abiv2/memcmp.S         | 152 +++++++++++++++++
 arch/csky/abiv2/memcpy.S         | 110 +++++++++++++
 arch/csky/abiv2/memmove.S        | 108 ++++++++++++
 arch/csky/abiv2/memset.S         |  83 ++++++++++
 arch/csky/abiv2/strcmp.S         | 168 +++++++++++++++++++
 arch/csky/abiv2/strcpy.S         | 123 ++++++++++++++
 arch/csky/abiv2/strksyms.c       |  12 ++
 arch/csky/abiv2/strlen.S         |  97 +++++++++++
 arch/csky/abiv2/sysdep.h         |  30 ++++
 arch/csky/include/asm/string.h   |  13 ++
 arch/csky/kernel/power.c         |  30 ++++
 arch/csky/lib/delay.c            |  39 +++++
 19 files changed, 1420 insertions(+)
 create mode 100644 arch/csky/abiv1/bswapdi.c
 create mode 100644 arch/csky/abiv1/bswapsi.c
 create mode 100644 arch/csky/abiv1/inc/abi/string.h
 create mode 100644 arch/csky/abiv1/memcpy.S
 create mode 100644 arch/csky/abiv1/memset.c
 create mode 100644 arch/csky/abiv1/strksyms.c
 create mode 100644 arch/csky/abiv2/inc/abi/string.h
 create mode 100644 arch/csky/abiv2/memcmp.S
 create mode 100644 arch/csky/abiv2/memcpy.S
 create mode 100644 arch/csky/abiv2/memmove.S
 create mode 100644 arch/csky/abiv2/memset.S
 create mode 100644 arch/csky/abiv2/strcmp.S
 create mode 100644 arch/csky/abiv2/strcpy.S
 create mode 100644 arch/csky/abiv2/strksyms.c
 create mode 100644 arch/csky/abiv2/strlen.S
 create mode 100644 arch/csky/abiv2/sysdep.h
 create mode 100644 arch/csky/include/asm/string.h
 create mode 100644 arch/csky/kernel/power.c
 create mode 100644 arch/csky/lib/delay.c
arch/csky/abiv1/bswapdi.c new file +12 -0
new file mode 100644
index 0000000..f50a1d6
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/export.h>
+#include <linux/compiler.h>
+#include <uapi/linux/swab.h>
+
+unsigned long long notrace __bswapdi2(unsigned long long u)
+{
+	return ___constant_swab64(u);
+}
+EXPORT_SYMBOL(__bswapdi2);
arch/csky/abiv1/bswapsi.c new file +12 -0
new file mode 100644
index 0000000..0f79182
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/export.h>
+#include <linux/compiler.h>
+#include <uapi/linux/swab.h>
+
+unsigned int notrace __bswapsi2(unsigned int u)
+{
+	return ___constant_swab32(u);
+}
+EXPORT_SYMBOL(__bswapsi2);
arch/csky/abiv1/inc/abi/string.h new file +13 -0
new file mode 100644
index 0000000..5abe80b
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ABI_CSKY_STRING_H
+#define __ABI_CSKY_STRING_H
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *, int, __kernel_size_t);
+
+#endif /* __ABI_CSKY_STRING_H */
arch/csky/abiv1/memcpy.S new file +347 -0

347 lines not on this page · raw message

arch/csky/abiv1/memset.c new file +37 -0
new file mode 100644
index 0000000..b4aa75b
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/types.h>
+
+void *memset(void *dest, int c, size_t l)
+{
+	char *d = dest;
+	int ch = c & 0xff;
+	int tmp = (ch | ch << 8 | ch << 16 | ch << 24);
+
+	while (((uintptr_t)d & 0x3) && l--)
+		*d++ = ch;
+
+	while (l >= 16) {
+		*(((u32 *)d))   = tmp;
+		*(((u32 *)d)+1) = tmp;
+		*(((u32 *)d)+2) = tmp;
+		*(((u32 *)d)+3) = tmp;
+		l -= 16;
+		d += 16;
+	}
+
+	while (l > 3) {
+		*(((u32 *)d)) = tmp;
+		l -= 4;
+		d += 4;
+	}
+
+	while (l) {
+		*d = ch;
+		l--;
+		d++;
+	}
+
+	return dest;
+}
arch/csky/abiv1/strksyms.c new file +7 -0
new file mode 100644
index 0000000..436995c
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/module.h>
+
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memset);
arch/csky/abiv2/inc/abi/string.h new file +27 -0
new file mode 100644
index 0000000..f01bad2
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ABI_CSKY_STRING_H
+#define __ABI_CSKY_STRING_H
+
+#define __HAVE_ARCH_MEMCMP
+extern int memcmp(const void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMMOVE
+extern void *memmove(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *, int,  __kernel_size_t);
+
+#define __HAVE_ARCH_STRCMP
+extern int strcmp(const char *, const char *);
+
+#define __HAVE_ARCH_STRCPY
+extern char *strcpy(char *, const char *);
+
+#define __HAVE_ARCH_STRLEN
+extern __kernel_size_t strlen(const char *);
+
+#endif /* __ABI_CSKY_STRING_H */
arch/csky/abiv2/memcmp.S new file +152 -0

152 lines not on this page · raw message

arch/csky/abiv2/memcpy.S new file +110 -0

110 lines not on this page · raw message

arch/csky/abiv2/memmove.S new file +108 -0

108 lines not on this page · raw message

arch/csky/abiv2/memset.S new file +83 -0

83 lines not on this page · raw message

arch/csky/abiv2/strcmp.S new file +168 -0

168 lines not on this page · raw message

arch/csky/abiv2/strcpy.S new file +123 -0

123 lines not on this page · raw message

arch/csky/abiv2/strksyms.c new file +12 -0
new file mode 100644
index 0000000..06da723
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/module.h>
+
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memset);
+EXPORT_SYMBOL(memcmp);
+EXPORT_SYMBOL(memmove);
+EXPORT_SYMBOL(strcmp);
+EXPORT_SYMBOL(strcpy);
+EXPORT_SYMBOL(strlen);
arch/csky/abiv2/strlen.S new file +97 -0

97 lines not on this page · raw message

arch/csky/abiv2/sysdep.h new file +30 -0
new file mode 100644
index 0000000..bbbedfd
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __SYSDEP_H
+#define __SYSDEP_H
+
+#ifdef __ASSEMBLER__
+
+#if defined(__CK860__)
+#define LABLE_ALIGN	\
+	.balignw 16, 0x6c03
+
+#define PRE_BNEZAD(R)
+
+#define BNEZAD(R, L)	\
+	bnezad	R, L
+#else
+#define LABLE_ALIGN	\
+	.balignw 8, 0x6c03
+
+#define PRE_BNEZAD(R)	\
+	subi	R, 1
+
+#define BNEZAD(R, L)	\
+	bnez	R, L
+#endif
+
+#endif
+
+#endif
arch/csky/include/asm/string.h new file +13 -0
new file mode 100644
index 0000000..73142de
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef _CSKY_STRING_MM_H_
+#define _CSKY_STRING_MM_H_
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <abi/string.h>
+#endif
+
+#endif /* _CSKY_STRING_MM_H_ */
arch/csky/kernel/power.c new file +30 -0
new file mode 100644
index 0000000..923ee4e
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/reboot.h>
+
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_power_off(void)
+{
+	local_irq_disable();
+	if (pm_power_off)
+		pm_power_off();
+	asm volatile ("bkpt");
+}
+
+void machine_halt(void)
+{
+	local_irq_disable();
+	if (pm_power_off)
+		pm_power_off();
+	asm volatile ("bkpt");
+}
+
+void machine_restart(char *cmd)
+{
+	local_irq_disable();
+	do_kernel_restart(cmd);
+	asm volatile ("bkpt");
+}
arch/csky/lib/delay.c new file +39 -0
new file mode 100644
index 0000000..22570b0
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+
+void __delay(unsigned long loops)
+{
+	asm volatile (
+		"mov r0, r0\n"
+		"1:declt %0\n"
+		"bf	1b"
+		: "=r"(loops)
+		: "0"(loops));
+}
+EXPORT_SYMBOL(__delay);
+
+void __const_udelay(unsigned long xloops)
+{
+	unsigned long long loops;
+
+	loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
+
+	__delay(loops >> 32);
+}
+EXPORT_SYMBOL(__const_udelay);
+
+void __udelay(unsigned long usecs)
+{
+	__const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
+}
+EXPORT_SYMBOL(__udelay);
+
+void __ndelay(unsigned long nsecs)
+{
+	__const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
+}
+EXPORT_SYMBOL(__ndelay);
Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 13/21
#37 lore raw

Re: [PATCH V9 13/21] csky: Library functions

Quoted 19 lines · Guo Ren

+++ b/arch/csky/lib/delay.c

arch/csky/lib/delay.c new file +17 -0
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+
+void __delay(unsigned long loops)
+{
+       asm volatile (
+               "mov r0, r0\n"
+               "1:declt %0\n"
+               "bf     1b"
+               : "=r"(loops)
+               : "0"(loops));
+}
+EXPORT_SYMBOL(__delay);

arch/csky/lib/delay.c line 27

Quoted 10 lines
arch/csky/lib/delay.c new file +10 -0
+
+void __const_udelay(unsigned long xloops)
+{
+       unsigned long long loops;
+
+       loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
+
+       __delay(loops >> 32);
+}
+EXPORT_SYMBOL(__const_udelay);

I can't find any indication we discussed this part before. Can you explain (in the
changelog and in a reply) if there is a reliable high-resolution clocksource available in the architecture? If you can read the elapsed time here instead of using the loops_per_jiffy estimate, that would make this more robust, as well as speed up the boot.

If you can't do that in general, that's fine, and you can add my

author
#38 lore raw

Re: [PATCH V9 13/21] csky: Library functions

Quoted 39 lines · Arnd Bergmann
Quoted 19 lines · Guo Ren

+++ b/arch/csky/lib/delay.c

arch/csky/lib/delay.c new file +17 -0
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+
+void __delay(unsigned long loops)
+{
+       asm volatile (
+               "mov r0, r0\n"
+               "1:declt %0\n"
+               "bf     1b"
+               : "=r"(loops)
+               : "0"(loops));
+}
+EXPORT_SYMBOL(__delay);

arch/csky/lib/delay.c line 27

Quoted 10 lines
arch/csky/lib/delay.c new file +10 -0
+
+void __const_udelay(unsigned long xloops)
+{
+       unsigned long long loops;
+
+       loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
+
+       __delay(loops >> 32);
+}
+EXPORT_SYMBOL(__const_udelay);

I can't find any indication we discussed this part before. Can you explain (in the
changelog and in a reply) if there is a reliable high-resolution clocksource available in the architecture? If you can read the elapsed time here instead of using the loops_per_jiffy estimate, that would make this more robust, as well as speed up the boot.

Quoted 1 line

If you can't do that in general, that's fine, and you can add my

I'll add TODO list here, __delay should use get_cycles() and we didn't implement __udelay() __ndelay() ... We'll improve it next.

Best Regards
Guo Ren

author
#39 lore raw

PATCH v9 14/21 csky: User access

In reply to Guo Ren

The patch adds "user access from kernel" codes.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/include/asm/uaccess.h | 416 ++++++++++++++++++++++++++++++++++++++++
 arch/csky/lib/usercopy.c        | 262 +++++++++++++++++++++++++
 2 files changed, 678 insertions(+)
 create mode 100644 arch/csky/include/asm/uaccess.h
 create mode 100644 arch/csky/lib/usercopy.c
arch/csky/include/asm/uaccess.h new file +416 -0
new file mode 100644
index 0000000..acaf0e210
@@ -0,0 +1,416 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_UACCESS_H
+#define __ASM_CSKY_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include <linux/compiler.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/version.h>
+#include <asm/segment.h>
+
+#define VERIFY_READ	0
+#define VERIFY_WRITE	1
+
+static inline int access_ok(int type, const void *addr, unsigned long size)
+{
+	unsigned long limit = current_thread_info()->addr_limit.seg;
+
+	return (((unsigned long)addr < limit) &&
+		((unsigned long)(addr + size) < limit));
+}
+
+static inline int verify_area(int type, const void *addr, unsigned long size)
+{
+	return access_ok(type, addr, size) ? 0 : -EFAULT;
+}
+
+#define __addr_ok(addr) (access_ok(VERIFY_READ, addr, 0))
+
+extern int __put_user_bad(void);
+
+/*
+ * Tell gcc we read from memory instead of writing: this is because
+ * we do not write to any memory gcc knows about, so there are no
+ * aliasing issues.
+ */
+
+/*
+ * These are the main single-value transfer routines.  They automatically
+ * use the right size if we just have the right pointer type.
+ *
+ * This gets kind of ugly. We want to return _two_ values in "get_user()"
+ * and yet we don't want to do any pointers, because that is too much
+ * of a performance impact. Thus we have a few rather ugly macros here,
+ * and hide all the ugliness from the user.
+ *
+ * The "__xxx" versions of the user access functions are versions that
+ * do not verify the address space, that must have been done previously
+ * with a separate "access_ok()" call (this is used when we do multiple
+ * accesses to the same area of user memory).
+ *
+ * As we use the same address space for kernel and user data on
+ * Ckcore, we can just do these as direct assignments.  (Of course, the
+ * exception handling means that it's no longer "just"...)
+ */
+
+#define put_user(x, ptr) \
+	__put_user_check((x), (ptr), sizeof(*(ptr)))
+
+#define __put_user(x, ptr) \
+	__put_user_nocheck((x), (ptr), sizeof(*(ptr)))
+
+#define __ptr(x) ((unsigned long *)(x))
+
+#define get_user(x, ptr) \
+	__get_user_check((x), (ptr), sizeof(*(ptr)))
+
+#define __get_user(x, ptr) \
+	__get_user_nocheck((x), (ptr), sizeof(*(ptr)))
+
+#define __put_user_nocheck(x, ptr, size)				\
+({									\
+	long __pu_err = 0;						\
+	typeof(*(ptr)) *__pu_addr = (ptr);				\
+	typeof(*(ptr)) __pu_val = (typeof(*(ptr)))(x);			\
+	if (__pu_addr)							\
+		__put_user_size(__pu_val, (__pu_addr), (size),		\
+				__pu_err);				\
+	__pu_err;							\
+})
+
+#define __put_user_check(x, ptr, size)					\
+({									\
+	long __pu_err = -EFAULT;					\
+	typeof(*(ptr)) *__pu_addr = (ptr);				\
+	typeof(*(ptr)) __pu_val = (typeof(*(ptr)))(x);			\
+	if (access_ok(VERIFY_WRITE, __pu_addr, size) && __pu_addr)	\
+		__put_user_size(__pu_val, __pu_addr, (size), __pu_err);	\
+	__pu_err;							\
+})
+
+#define __put_user_size(x, ptr, size, retval)		\
+do {							\
+	retval = 0;					\
+	switch (size) {                                 \
+	case 1:						\
+		__put_user_asm_b(x, ptr, retval);	\
+		break;					\
+	case 2:						\
+		__put_user_asm_h(x, ptr, retval);	\
+		break;					\
+	case 4:						\
+		__put_user_asm_w(x, ptr, retval);	\
+		break;					\
+	case 8:						\
+		__put_user_asm_64(x, ptr, retval);	\
+		break;					\
+	default:					\
+		__put_user_bad();			\
+	}	                                        \
+} while (0)
+
+/*
+ * We don't tell gcc that we are accessing memory, but this is OK
+ * because we do not write to any memory gcc knows about, so there
+ * are no aliasing issues.
+ *
+ * Note that PC at a fault is the address *after* the faulting
+ * instruction.
+ */
+#define __put_user_asm_b(x, ptr, err)			\
+do {							\
+	int errcode;					\
+	asm volatile(					\
+	"1:     stb   %1, (%2,0)	\n"		\
+	"       br    3f		\n"		\
+	"2:     mov   %0, %3		\n"		\
+	"       br    3f		\n"		\
+	".section __ex_table, \"a\"	\n"		\
+	".align   2			\n"		\
+	".long    1b,2b			\n"		\
+	".previous			\n"		\
+	"3:				\n"		\
+	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
+	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
+	: "memory");					\
+} while (0)
+
+#define __put_user_asm_h(x, ptr, err)			\
+do {							\
+	int errcode;					\
+	asm volatile(					\
+	"1:     sth   %1, (%2,0)	\n"		\
+	"       br    3f		\n"		\
+	"2:     mov   %0, %3		\n"		\
+	"       br    3f		\n"		\
+	".section __ex_table, \"a\"	\n"		\
+	".align   2			\n"		\
+	".long    1b,2b			\n"		\
+	".previous			\n"		\
+	"3:				\n"		\
+	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
+	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
+	: "memory");					\
+} while (0)
+
+#define __put_user_asm_w(x, ptr, err)			\
+do {							\
+	int errcode;					\
+	asm volatile(					\
+	"1:     stw   %1, (%2,0)	\n"		\
+	"       br    3f		\n"		\
+	"2:     mov   %0, %3		\n"		\
+	"       br    3f		\n"		\
+	".section __ex_table,\"a\"	\n"		\
+	".align   2			\n"		\
+	".long    1b, 2b		\n"		\
+	".previous			\n"		\
+	"3:				\n"		\
+	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
+	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
+	: "memory");					\
+} while (0)
+
+#define __put_user_asm_64(x, ptr, err)				\
+do {								\
+	int tmp;						\
+	int errcode;						\
+	typeof(*(ptr))src = (typeof(*(ptr)))x;			\
+	typeof(*(ptr))*psrc = &src;				\
+								\
+	asm volatile(						\
+	"     ldw     %3, (%1, 0)     \n"			\
+	"1:   stw     %3, (%2, 0)     \n"			\
+	"     ldw     %3, (%1, 4)     \n"			\
+	"2:   stw     %3, (%2, 4)     \n"			\
+	"     br      4f              \n"			\
+	"3:   mov     %0, %4          \n"			\
+	"     br      4f              \n"			\
+	".section __ex_table, \"a\"   \n"			\
+	".align   2                   \n"			\
+	".long    1b, 3b              \n"			\
+	".long    2b, 3b              \n"			\
+	".previous                    \n"			\
+	"4:                           \n"			\
+	: "=r"(err), "=r"(psrc), "=r"(ptr),			\
+	  "=r"(tmp), "=r"(errcode)				\
+	: "0"(err), "1"(psrc), "2"(ptr), "3"(0), "4"(-EFAULT)	\
+	: "memory");						\
+} while (0)
+
+#define __get_user_nocheck(x, ptr, size)			\
+({								\
+	long  __gu_err;						\
+	__get_user_size(x, (ptr), (size), __gu_err);		\
+	__gu_err;						\
+})
+
+#define __get_user_check(x, ptr, size)				\
+({								\
+	int __gu_err = -EFAULT;					\
+	const __typeof__(*(ptr)) __user *__gu_ptr = (ptr);	\
+	if (access_ok(VERIFY_READ, __gu_ptr, size) && __gu_ptr)	\
+		__get_user_size(x, __gu_ptr, size, __gu_err);	\
+	__gu_err;						\
+})
+
+#define __get_user_size(x, ptr, size, retval)			\
+do {								\
+	switch (size) {						\
+	case 1:							\
+		__get_user_asm_common((x), ptr, "ldb", retval);	\
+		break;						\
+	case 2:							\
+		__get_user_asm_common((x), ptr, "ldh", retval);	\
+		break;						\
+	case 4:							\
+		__get_user_asm_common((x), ptr, "ldw", retval);	\
+		break;						\
+	default:						\
+		x = 0;						\
+		(retval) = __get_user_bad();			\
+	}							\
+} while (0)
+
+#define __get_user_asm_common(x, ptr, ins, err)			\
+do {								\
+	int errcode;						\
+	asm volatile(						\
+	"1:   " ins " %1, (%4,0)	\n"			\
+	"       br    3f		\n"			\
+	/* Fix up codes */					\
+	"2:     mov   %0, %2		\n"			\
+	"       movi  %1, 0		\n"			\
+	"       br    3f		\n"			\
+	".section __ex_table,\"a\"      \n"			\
+	".align   2			\n"			\
+	".long    1b, 2b		\n"			\
+	".previous			\n"			\
+	"3:				\n" 			\
+	: "=r"(err), "=r"(x), "=r"(errcode)			\
+	: "0"(0), "r"(ptr), "2"(-EFAULT)			\
+	: "memory");						\
+} while (0)
+
+extern int __get_user_bad(void);
+
+#define __copy_user(to, from, n)			\
+do {							\
+	int w0, w1, w2, w3;				\
+	asm volatile(					\
+	"0:     cmpnei  %1, 0           \n"		\
+	"       bf      8f              \n"		\
+	"       mov     %3, %1          \n"		\
+	"       or      %3, %2          \n"		\
+	"       andi    %3, 3           \n"		\
+	"       cmpnei  %3, 0           \n"		\
+	"       bf      1f              \n"		\
+	"       br      5f              \n"		\
+	"1:     cmplti  %0, 16          \n" /* 4W */	\
+	"       bt      3f              \n"		\
+	"       ldw     %3, (%2, 0)     \n"		\
+	"       ldw     %4, (%2, 4)     \n"		\
+	"       ldw     %5, (%2, 8)     \n"		\
+	"       ldw     %6, (%2, 12)    \n"		\
+	"2:     stw     %3, (%1, 0)     \n"		\
+	"9:     stw     %4, (%1, 4)     \n"		\
+	"10:    stw     %5, (%1, 8)     \n"		\
+	"11:    stw     %6, (%1, 12)    \n"		\
+	"       addi    %2, 16          \n"		\
+	"       addi    %1, 16          \n"		\
+	"       subi    %0, 16          \n"		\
+	"       br      1b              \n"		\
+	"3:     cmplti  %0, 4           \n" /* 1W */	\
+	"       bt      5f              \n"		\
+	"       ldw     %3, (%2, 0)     \n"		\
+	"4:     stw     %3, (%1, 0)     \n"		\
+	"       addi    %2, 4           \n"		\
+	"       addi    %1, 4           \n"		\
+	"       subi    %0, 4           \n"		\
+	"       br      3b              \n"		\
+	"5:     cmpnei  %0, 0           \n"  /* 1B */   \
+	"       bf      8f              \n"		\
+	"       ldb     %3, (%2, 0)     \n"		\
+	"6:     stb     %3, (%1, 0)     \n"		\
+	"       addi    %2,  1          \n"		\
+	"       addi    %1,  1          \n"		\
+	"       subi    %0,  1          \n"		\
+	"       br      5b              \n"		\
+	"7:     br      8f              \n"		\
+	".section __ex_table, \"a\"     \n"		\
+	".align   2                     \n"		\
+	".long    2b, 7b                \n"		\
+	".long    9b, 7b                \n"		\
+	".long   10b, 7b                \n"		\
+	".long   11b, 7b                \n"		\
+	".long    4b, 7b                \n"		\
+	".long    6b, 7b                \n"		\
+	".previous                      \n"		\
+	"8:                             \n"		\
+	: "=r"(n), "=r"(to), "=r"(from), "=r"(w0),	\
+	  "=r"(w1), "=r"(w2), "=r"(w3)			\
+	: "0"(n), "1"(to), "2"(from)			\
+	: "memory");					\
+} while (0)
+
+#define __copy_user_zeroing(to, from, n)		\
+do {							\
+	int tmp;					\
+	int nsave;					\
+	asm volatile(					\
+	"0:     cmpnei  %1, 0           \n"		\
+	"       bf      7f              \n"		\
+	"       mov     %3, %1          \n"		\
+	"       or      %3, %2          \n"		\
+	"       andi    %3, 3           \n"		\
+	"       cmpnei  %3, 0           \n"		\
+	"       bf      1f              \n"		\
+	"       br      5f              \n"		\
+	"1:     cmplti  %0, 16          \n"		\
+	"       bt      3f              \n"		\
+	"2:     ldw     %3, (%2, 0)     \n"		\
+	"10:    ldw     %4, (%2, 4)     \n"		\
+	"       stw     %3, (%1, 0)     \n"		\
+	"       stw     %4, (%1, 4)     \n"		\
+	"11:    ldw     %3, (%2, 8)     \n"		\
+	"12:    ldw     %4, (%2, 12)    \n"		\
+	"       stw     %3, (%1, 8)     \n"		\
+	"       stw     %4, (%1, 12)    \n"		\
+	"       addi    %2, 16          \n"		\
+	"       addi    %1, 16          \n"		\
+	"       subi    %0, 16          \n"		\
+	"       br      1b              \n"		\
+	"3:     cmplti  %0, 4           \n"		\
+	"       bt      5f              \n"		\
+	"4:     ldw     %3, (%2, 0)     \n"		\
+	"       stw     %3, (%1, 0)     \n"		\
+	"       addi    %2, 4           \n"		\
+	"       addi    %1, 4           \n"		\
+	"       subi    %0, 4           \n"		\
+	"       br      3b              \n"		\
+	"5:     cmpnei  %0, 0           \n"		\
+	"       bf      7f              \n"		\
+	"6:     ldb     %3, (%2, 0)     \n"		\
+	"       stb     %3, (%1, 0)     \n"		\
+	"       addi    %2,  1          \n"		\
+	"       addi    %1,  1          \n"		\
+	"       subi    %0,  1          \n"		\
+	"       br      5b              \n"		\
+	"8:     mov     %3, %0          \n"		\
+	"       movi    %4, 0           \n"		\
+	"9:     stb     %4, (%1, 0)     \n"		\
+	"       addi    %1, 1           \n"		\
+	"       subi    %3, 1           \n"		\
+	"       cmpnei  %3, 0           \n"		\
+	"       bt      9b              \n"		\
+	"       br      7f              \n"		\
+	".section __ex_table, \"a\"     \n"		\
+	".align   2                     \n"		\
+	".long    2b, 8b                \n"		\
+	".long   10b, 8b                \n"		\
+	".long   11b, 8b                \n"		\
+	".long   12b, 8b                \n"		\
+	".long    4b, 8b                \n"		\
+	".long    6b, 8b                \n"		\
+	".previous                      \n"		\
+	"7:                             \n"		\
+	: "=r"(n), "=r"(to), "=r"(from), "=r"(nsave),	\
+	  "=r"(tmp)					\
+	: "0"(n), "1"(to), "2"(from)			\
+	: "memory");					\
+} while (0)
+
+unsigned long raw_copy_from_user(void *to, const void *from, unsigned long n);
+unsigned long raw_copy_to_user(void *to, const void *from, unsigned long n);
+
+unsigned long clear_user(void *to, unsigned long n);
+unsigned long __clear_user(void __user *to, unsigned long n);
+
+long strncpy_from_user(char *dst, const char *src, long count);
+long __strncpy_from_user(char *dst, const char *src, long count);
+
+/*
+ * Return the size of a string (including the ending 0)
+ *
+ * Return 0 on exception, a value greater than N if too long
+ */
+long strnlen_user(const char *src, long n);
+
+#define strlen_user(str) strnlen_user(str, 32767)
+
+struct exception_table_entry {
+	unsigned long insn;
+	unsigned long nextinsn;
+};
+
+extern int fixup_exception(struct pt_regs *regs);
+
+#endif /* __ASM_CSKY_UACCESS_H */
arch/csky/lib/usercopy.c new file +262 -0

262 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 14/21
#40 lore raw

Re: [PATCH V9 14/21] csky: User access

Quoted 11 lines · Guo Ren

The patch adds "user access from kernel" codes.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/include/asm/uaccess.h | 416 ++++++++++++++++++++++++++++++++++++++++
 arch/csky/lib/usercopy.c        | 262 +++++++++++++++++++++++++
 2 files changed, 678 insertions(+)
 create mode 100644 arch/csky/include/asm/uaccess.h
 create mode 100644 arch/csky/lib/usercopy.c

The 64-bit __put_user() is usually what everyone gets wrong, but your version seems fine. Also the access_ok() checks and the copy_to_user() result value all look correct.

Arnd

author
#41 lore raw

PATCH v9 15/21 csky: Debug and Ptrace GDB

In reply to Guo Ren

This patch adds arch ptrace implementation, stack dump and bug.h.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/include/asm/bug.h         |  26 +++
 arch/csky/include/uapi/asm/ptrace.h | 104 ++++++++++++
 arch/csky/kernel/dumpstack.c        |  66 ++++++++
 arch/csky/kernel/ptrace.c           | 314 ++++++++++++++++++++++++++++++++++++
 4 files changed, 510 insertions(+)
 create mode 100644 arch/csky/include/asm/bug.h
 create mode 100644 arch/csky/include/uapi/asm/ptrace.h
 create mode 100644 arch/csky/kernel/dumpstack.c
 create mode 100644 arch/csky/kernel/ptrace.c
arch/csky/include/asm/bug.h new file +26 -0
new file mode 100644
index 0000000..bd7b323
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_BUG_H
+#define __ASM_CSKY_BUG_H
+
+#include <linux/compiler.h>
+#include <linux/const.h>
+#include <linux/types.h>
+
+#define BUG()				\
+do {					\
+	asm volatile ("bkpt\n");	\
+	unreachable();			\
+} while (0)
+
+#define HAVE_ARCH_BUG
+
+#include <asm-generic/bug.h>
+
+struct pt_regs;
+
+void die_if_kernel(char *str, struct pt_regs *regs, int nr);
+void show_regs(struct pt_regs *regs);
+
+#endif /* __ASM_CSKY_BUG_H */
arch/csky/include/uapi/asm/ptrace.h new file +104 -0

104 lines not on this page · raw message

arch/csky/kernel/dumpstack.c new file +66 -0

66 lines not on this page · raw message

arch/csky/kernel/ptrace.c new file +314 -0

314 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Reviewed-by on v9 15/21
#42 lore raw

Re: [PATCH V9 15/21] csky: Debug and Ptrace GDB

Quoted 5 lines · Guo Ren

This patch adds arch ptrace implementation, stack dump and bug.h.

Cc Arnd Bergmann <[email protected]>
Quoted 11 lines
arch/csky/include/asm/bug.h new file +5 -0
new file mode 100644
index 0000000..bd7b323
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_BUG_H
+#define __ASM_CSKY_BUG_H

arch/csky/include/asm/bug.h line 15

Quoted 10 lines
arch/csky/include/asm/bug.h new file +10 -0
+
+#include <linux/compiler.h>
+#include <linux/const.h>
+#include <linux/types.h>
+
+#define BUG()                          \
+do {                                   \
+       asm volatile ("bkpt\n");        \
+       unreachable();                  \
+} while (0)

Since you have a breakpoint instruction, a nice addition might be to use that for implementing WARN_ON as well, whenever you get around to doing that. It's certainly not required for the initial merge.

author
#43 lore raw

Re: [PATCH V9 15/21] csky: Debug and Ptrace GDB

Quoted 27 lines · Arnd Bergmann
Quoted 5 lines · Guo Ren

This patch adds arch ptrace implementation, stack dump and bug.h.

Cc Arnd Bergmann <[email protected]>
Quoted 18 lines
arch/csky/include/asm/bug.h new file +12 -0
new file mode 100644
index 0000000..bd7b323
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_BUG_H
+#define __ASM_CSKY_BUG_H
+
+#include <linux/compiler.h>
+#include <linux/const.h>
+#include <linux/types.h>
+
+#define BUG()                          \
+do {                                   \
Quoted 8 lines

arch/csky/include/asm/bug.h line 15

Quoted 3 lines
arch/csky/include/asm/bug.h new file +3 -0
+       asm volatile ("bkpt\n");        \
+       unreachable();                  \
+} while (0)

Since you have a breakpoint instruction, a nice addition might be to use that for implementing WARN_ON as well, whenever you get around to doing that. It's certainly not required for the initial merge.

Thx for remind and I'll improve it next.

Best Regards
Guo Ren

author
#44 lore raw

PATCH v9 16/21 csky: SMP support

In reply to Guo Ren

This patch adds boot, ipi, hotplug codes for SMP.

Cc Marc Zyngier <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnd Bergmann <[email protected]>

---
Changelog:
- Use PER_CPU_DEFINE for ipi_data.
- Remove unused variable and add static for enable_smp_ipi().
- Add comment to explain pass args from primary CPU to secondary CPU.
- Remove set_ipi_irq_mapping callback.
- Convert the cpumask to an interrupt-controller specific representation in driver's code, and not the SMP code's.
- csky: remove irq_mapping from smp.c
There are some feedbacks from irqchip, and we need to adjust "smp.c & smp.h" to match the csky_mp_intc modification.
- Move IPI_IRQ define into drivers/irqchip/csky_mpintc.c, because it's a interrupt controller specific.
- Bugfix request_irq with IPI_IRQ, we must use irq_mapping return value not directly use IPI_IRQ. The modification also involves csky_mp_intc.
---

---
 arch/csky/include/asm/smp.h |  26 +++++
 arch/csky/kernel/smp.c      | 237 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 263 insertions(+)
 create mode 100644 arch/csky/include/asm/smp.h
 create mode 100644 arch/csky/kernel/smp.c
arch/csky/include/asm/smp.h new file +26 -0
new file mode 100644
index 0000000..4a929c4
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_CSKY_SMP_H
+#define __ASM_CSKY_SMP_H
+
+#include <linux/cpumask.h>
+#include <linux/irqreturn.h>
+#include <linux/threads.h>
+
+#ifdef CONFIG_SMP
+
+void __init setup_smp(void);
+
+void __init setup_smp_ipi(void);
+
+void arch_send_call_function_ipi_mask(struct cpumask *mask);
+
+void arch_send_call_function_single_ipi(int cpu);
+
+void __init set_send_ipi(void (*func)(const struct cpumask *mask), int irq);
+
+#define raw_smp_processor_id()	(current_thread_info()->cpu)
+
+#endif /* CONFIG_SMP */
+
+#endif /* __ASM_CSKY_SMP_H */
arch/csky/kernel/smp.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#46 lore raw

PATCH v9 17/21 csky: Misc headers

In reply to Guo Ren

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

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/abiv1/inc/abi/reg_ops.h      | 27 +++++++++++
 arch/csky/abiv1/inc/abi/regdef.h       | 26 ++++++++++
 arch/csky/abiv2/inc/abi/reg_ops.h      | 17 +++++++
 arch/csky/abiv2/inc/abi/regdef.h       | 26 ++++++++++
 arch/csky/include/asm/bitops.h         | 82 +++++++++++++++++++++++++++++++
 arch/csky/include/asm/checksum.h       | 50 +++++++++++++++++++
 arch/csky/include/asm/reg_ops.h        | 26 ++++++++++
 arch/csky/include/uapi/asm/byteorder.h |  9 ++++
 arch/csky/kernel/asm-offsets.c         | 88 ++++++++++++++++++++++++++++++++++
 9 files changed, 351 insertions(+)
 create mode 100644 arch/csky/abiv1/inc/abi/reg_ops.h
 create mode 100644 arch/csky/abiv1/inc/abi/regdef.h
 create mode 100644 arch/csky/abiv2/inc/abi/reg_ops.h
 create mode 100644 arch/csky/abiv2/inc/abi/regdef.h
 create mode 100644 arch/csky/include/asm/bitops.h
 create mode 100644 arch/csky/include/asm/checksum.h
 create mode 100644 arch/csky/include/asm/reg_ops.h
 create mode 100644 arch/csky/include/uapi/asm/byteorder.h
 create mode 100644 arch/csky/kernel/asm-offsets.c
arch/csky/abiv1/inc/abi/reg_ops.h new file +27 -0
new file mode 100644
index 0000000..a153bd3
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ABI_REG_OPS_H
+#define __ABI_REG_OPS_H
+#include <asm/reg_ops.h>
+
+#define cprcr(reg)					\
+({							\
+	unsigned int tmp;				\
+	asm volatile("cprcr %0, "reg"\n":"=b"(tmp));	\
+	tmp;						\
+})
+
+#define cpwcr(reg, val)					\
+({							\
+	asm volatile("cpwcr %0, "reg"\n"::"b"(val));	\
+})
+
+static inline unsigned int mfcr_hint(void)
+{
+	return mfcr("cr30");
+}
+
+static inline unsigned int mfcr_ccr2(void) { return 0; }
+
+#endif /* __ABI_REG_OPS_H */
arch/csky/abiv1/inc/abi/regdef.h new file +26 -0
new file mode 100644
index 0000000..8766892
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_REGDEF_H
+#define __ASM_CSKY_REGDEF_H
+
+#define syscallid	r1
+#define r11_sig		r11
+
+#define regs_syscallid(regs) regs->regs[9]
+
+/*
+ * PSR format:
+ * | 31 | 30-24 | 23-16 | 15 14 | 13-0 |
+ *   S     CPID     VEC     TM
+ *
+ *    S: Super Mode
+ * CPID: Coprocessor id, only 15 for MMU
+ *  VEC: Exception Number
+ *   TM: Trace Mode
+ */
+#define DEFAULT_PSR_VALUE	0x8f000000
+
+#define SYSTRACE_SAVENUM	2
+
+#endif /* __ASM_CSKY_REGDEF_H */
arch/csky/abiv2/inc/abi/reg_ops.h new file +17 -0
new file mode 100644
index 0000000..ae82c3f
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ABI_REG_OPS_H
+#define __ABI_REG_OPS_H
+#include <asm/reg_ops.h>
+
+static inline unsigned int mfcr_hint(void)
+{
+	return mfcr("cr31");
+}
+
+static inline unsigned int mfcr_ccr2(void)
+{
+	return mfcr("cr23");
+}
+#endif /* __ABI_REG_OPS_H */
arch/csky/abiv2/inc/abi/regdef.h new file +26 -0
new file mode 100644
index 0000000..c72abb7
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_REGDEF_H
+#define __ASM_CSKY_REGDEF_H
+
+#define syscallid	r7
+#define r11_sig		r11
+
+#define regs_syscallid(regs) regs->regs[3]
+
+/*
+ * PSR format:
+ * | 31 | 30-24 | 23-16 | 15 14 | 13-10 | 9 | 8-0 |
+ *   S              VEC     TM            MM
+ *
+ *   S: Super Mode
+ * VEC: Exception Number
+ *  TM: Trace Mode
+ *  MM: Memory unaligned addr access
+ */
+#define DEFAULT_PSR_VALUE	0x80000200
+
+#define SYSTRACE_SAVENUM	5
+
+#endif /* __ASM_CSKY_REGDEF_H */
arch/csky/include/asm/bitops.h new file +82 -0

82 lines not on this page · raw message

arch/csky/include/asm/checksum.h new file +50 -0

50 lines not on this page · raw message

arch/csky/include/asm/reg_ops.h new file +26 -0
new file mode 100644
index 0000000..cccf7d5
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __ASM_REGS_OPS_H
+#define __ASM_REGS_OPS_H
+
+#define mfcr(reg)		\
+({				\
+	unsigned int tmp;	\
+	asm volatile(		\
+	"mfcr %0, "reg"\n"	\
+	: "=r"(tmp)		\
+	:			\
+	: "memory");		\
+	tmp;			\
+})
+
+#define mtcr(reg, val)		\
+({				\
+	asm volatile(		\
+	"mtcr %0, "reg"\n"	\
+	:			\
+	: "r"(val)		\
+	: "memory");		\
+})
+
+#endif /* __ASM_REGS_OPS_H */
arch/csky/include/uapi/asm/byteorder.h new file +9 -0
new file mode 100644
index 0000000..b079ec7
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_BYTEORDER_H
+#define __ASM_CSKY_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* __ASM_CSKY_BYTEORDER_H */
arch/csky/kernel/asm-offsets.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#48 lore raw

PATCH v9 18/21 dt-bindings: csky CPU Bindings

In reply to Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Cc Rob Herring <[email protected]>

---
Changelog:
- Add compatible.
- Remove status part.
---

---
 Documentation/devicetree/bindings/csky/cpus.txt | 73 +++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/csky/cpus.txt
Documentation/devicetree/bindings/csky/cpus.txt new file +73 -0
new file mode 100644
index 0000000..ae79412
@@ -0,0 +1,73 @@
+==================
+C-SKY CPU Bindings
+==================
+
+The device tree allows to describe the layout of CPUs in a system through
+the "cpus" node, which in turn contains a number of subnodes (ie "cpu")
+defining properties for every cpu.
+
+Only SMP system need to care about the cpus node and single processor
+needn't define cpus node at all.
+
+=====================================
+cpus and cpu node bindings definition
+=====================================
+
+- cpus node
+
+	Description: Container of cpu nodes
+
+	The node name must be "cpus".
+
+	A cpus node must define the following properties:
+
+	- #address-cells
+		Usage: required
+		Value type: <u32>
+		Definition: must be set to 1
+	- #size-cells
+		Usage: required
+		Value type: <u32>
+		Definition: must be set to 0
+
+- cpu node
+
+	Description: Describes one of SMP cores
+
+	PROPERTIES
+
+	- device_type
+		Usage: required
+		Value type: <string>
+		Definition: must be "cpu"
+	- reg
+		Usage: required
+		Value type: <u32>
+		Definition: CPU index
+	- compatible:
+		Usage: required
+		Value type: <string>
+		Definition: must contain "csky", eg:
+			"csky,610"
+			"csky,807"
+			"csky,810"
+			"csky,860"
+
+Example:
+--------
+
+	cpus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		cpu@0 {
+			device_type = "cpu";
+			reg = <0>;
+			status = "ok";
+		};
+
+		cpu@1 {
+			device_type = "cpu";
+			reg = <1>;
+			status = "ok";
+		};
+	};
Signature · 1 line
2.7.4
maintainer
#49 lore raw

Re: [PATCH V9 18/21] dt-bindings: csky CPU Bindings

Quoted 6 lines · Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Cc Rob Herring <[email protected]>

I don't see anything wrong, but I'll let Rob or some other DT maintainer provide an Ack when they are happy.

Arnd

author
#50 lore raw

Re: [PATCH V9 18/21] dt-bindings: csky CPU Bindings

Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Cc Rob Herring <[email protected]>

I don't see anything wrong, but I'll let Rob or some other DT maintainer provide an Ack when they are happy.

Yes, Rob help a lot for reviewing the DT-docs of csky subsystem. Thx Bob :)

Best Regards
Guo Ren

author
#51 lore raw

Re: [PATCH V9 18/21] dt-bindings: csky CPU Bindings

Quoted 6 lines · Guo Ren
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Cc Rob Herring <[email protected]>

I don't see anything wrong, but I'll let Rob or some other DT maintainer provide an Ack when they are happy.

Yes, Rob help a lot for reviewing the DT-docs of csky subsystem. Thx Bob :)

Sorry, Thx Rob.

Quoted 3 lines

Best Regards
Guo Ren

maintainer Reviewed-by on v9 18/21
#52 lore raw

Re: [PATCH V9 18/21] dt-bindings: csky CPU Bindings

In reply to Guo Ren
Quoted 10 lines · Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Cc Rob Herring <[email protected]>

---
Changelog:
- Add compatible.
- Remove status part.
---

Quoted 5 lines
---
 Documentation/devicetree/bindings/csky/cpus.txt | 73 +++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/csky/cpus.txt
author
#53 lore raw

Re: [PATCH V9 18/21] dt-bindings: csky CPU Bindings

Quoted 17 lines · Rob Herring
Quoted 10 lines · Guo Ren

This patch adds the documentation to describe that how to add cpu nodes in dts for SMP.

Cc Rob Herring <[email protected]>

---
Changelog:
- Add compatible.
- Remove status part.
---

Quoted 5 lines
---
 Documentation/devicetree/bindings/csky/cpus.txt | 73 +++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/csky/cpus.txt
Quoted 1 line

Thx Rob

Best Regards
Guo Ren

author
#54 lore raw

PATCH v9 19/21 dt-bindings: Add vendor prefix for csky

In reply to Guo Ren

Add csky vendor definition.

---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 2c3fc51..a728ee3 100644
@@ -84,6 +84,7 @@ cosmic	Cosmic Circuits
 crane	Crane Connectivity Solutions
 creative	Creative Technology Ltd
 crystalfontz	Crystalfontz America, Inc.
+csky	Hangzhou C-SKY Microsystems Co., Ltd
 cubietech	Cubietech, Ltd.
 cypress	Cypress Semiconductor Corporation
 cznic	CZ.NIC, z.s.p.o.
Signature · 1 line
2.7.4
author
#55 lore raw

PATCH v9 20/21 MAINTAINERS: Add csky

In reply to Guo Ren

Add a maintainer information for the csky(C-SKY) architecture.

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index d870cb5..9dac20e 100644
@@ -3211,6 +3211,15 @@ T:	git git://git.alsa-project.org/alsa-kernel.git
 S:	Maintained
 F:	sound/pci/oxygen/
 
+C-SKY ARCHITECTURE
+M:	Guo Ren <[email protected]>
+T:	git https://github.com/c-sky/csky-linux.git
+S:	Supported
+F:	arch/csky/
+F:	Documentation/devicetree/bindings/csky/
+K:	csky
+N:	csky
+
 C6X ARCHITECTURE
 M:	Mark Salter <[email protected]>
 M:	Aurelien Jacquiot <[email protected]>
Signature · 1 line
2.7.4
author
#57 lore raw

PATCH v9 21/21 csky: support dword access for get_user_size()

In reply to Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

abiv1 couldn't support __get_user_dword now.

Cc Arnd Bergmann <[email protected]>
---
 arch/csky/include/asm/uaccess.h | 140 ++++++++++++++++------------------------
 1 file changed, 56 insertions(+), 84 deletions(-)
arch/csky/include/asm/uaccess.h +56 -84
index acaf0e210..80233e4 100644
@@ -96,90 +96,32 @@ extern int __put_user_bad(void);
 	__pu_err;							\
 })
 
-#define __put_user_size(x, ptr, size, retval)		\
-do {							\
-	retval = 0;					\
-	switch (size) {                                 \
-	case 1:						\
-		__put_user_asm_b(x, ptr, retval);	\
-		break;					\
-	case 2:						\
-		__put_user_asm_h(x, ptr, retval);	\
-		break;					\
-	case 4:						\
-		__put_user_asm_w(x, ptr, retval);	\
-		break;					\
-	case 8:						\
-		__put_user_asm_64(x, ptr, retval);	\
-		break;					\
-	default:					\
-		__put_user_bad();			\
-	}	                                        \
-} while (0)
-
-/*
- * We don't tell gcc that we are accessing memory, but this is OK
- * because we do not write to any memory gcc knows about, so there
- * are no aliasing issues.
- *
- * Note that PC at a fault is the address *after* the faulting
- * instruction.
- */
-#define __put_user_asm_b(x, ptr, err)			\
-do {							\
-	int errcode;					\
-	asm volatile(					\
-	"1:     stb   %1, (%2,0)	\n"		\
-	"       br    3f		\n"		\
-	"2:     mov   %0, %3		\n"		\
-	"       br    3f		\n"		\
-	".section __ex_table, \"a\"	\n"		\
-	".align   2			\n"		\
-	".long    1b,2b			\n"		\
-	".previous			\n"		\
-	"3:				\n"		\
-	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
-	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
-	: "memory");					\
-} while (0)
-
-#define __put_user_asm_h(x, ptr, err)			\
-do {							\
-	int errcode;					\
-	asm volatile(					\
-	"1:     sth   %1, (%2,0)	\n"		\
-	"       br    3f		\n"		\
-	"2:     mov   %0, %3		\n"		\
-	"       br    3f		\n"		\
-	".section __ex_table, \"a\"	\n"		\
-	".align   2			\n"		\
-	".long    1b,2b			\n"		\
-	".previous			\n"		\
-	"3:				\n"		\
-	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
-	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
-	: "memory");					\
-} while (0)
-
-#define __put_user_asm_w(x, ptr, err)			\
-do {							\
-	int errcode;					\
-	asm volatile(					\
-	"1:     stw   %1, (%2,0)	\n"		\
-	"       br    3f		\n"		\
-	"2:     mov   %0, %3		\n"		\
-	"       br    3f		\n"		\
-	".section __ex_table,\"a\"	\n"		\
-	".align   2			\n"		\
-	".long    1b, 2b		\n"		\
-	".previous			\n"		\
-	"3:				\n"		\
-	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)	\
-	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)	\
-	: "memory");					\
+#define __put_user_size(x, ptr, size, retval)			\
+do {								\
+	retval = 0;						\
+	switch (size) {						\
+	case 1:							\
+		__put_user_asm_common(x, ptr, "stb", retval);	\
+		break;						\
+	case 2:							\
+		__put_user_asm_common(x, ptr, "sth", retval);	\
+		break;						\
+	case 4:							\
+		__put_user_asm_common(x, ptr, "stw", retval);	\
+		break;						\
+	case 8:							\
+		__put_user_asm_dword(x, ptr, retval);		\
+		break;						\
+	default:						\
+		__put_user_bad();				\
+	}							\
 } while (0)
 
-#define __put_user_asm_64(x, ptr, err)				\
+#if defined(__CSKYABIV2__)
+#define __put_user_asm_dword(x, ptr, err)			\
+	__put_user_asm_common(x, ptr, "st.d", err)
+#else
+#define __put_user_asm_dword(x, ptr, err)			\
 do {								\
 	int tmp;						\
 	int errcode;						\
@@ -205,6 +147,25 @@ do {								\
 	: "0"(err), "1"(psrc), "2"(ptr), "3"(0), "4"(-EFAULT)	\
 	: "memory");						\
 } while (0)
+#endif
+
+#define __put_user_asm_common(x, ptr, ins, err)			\
+do {								\
+	int errcode;						\
+	asm volatile(						\
+	"1:   " ins "	%1, (%2,0)	\n"			\
+	"       br	3f		\n"			\
+	"2:     mov	%0, %3		\n"			\
+	"       br	3f		\n"			\
+	".section __ex_table, \"a\"	\n"			\
+	".align   2			\n"			\
+	".long    1b,2b			\n"			\
+	".previous			\n"			\
+	"3:				\n"			\
+	: "=r"(err), "=r"(x), "=r"(ptr), "=r"(errcode)		\
+	: "0"(err), "1"(x), "2"(ptr), "3"(-EFAULT)		\
+	: "memory");						\
+} while (0)
 
 #define __get_user_nocheck(x, ptr, size)			\
 ({								\
@@ -222,6 +183,7 @@ do {								\
 	__gu_err;						\
 })
 
+extern int __get_user_bad(void);
 #define __get_user_size(x, ptr, size, retval)			\
 do {								\
 	switch (size) {						\
@@ -234,12 +196,24 @@ do {								\
 	case 4:							\
 		__get_user_asm_common((x), ptr, "ldw", retval);	\
 		break;						\
+	case 8:							\
+		__get_user_asm_common((x), ptr, "ld.d", retval);\
+		break;						\
 	default:						\
 		x = 0;						\
 		(retval) = __get_user_bad();			\
 	}							\
 } while (0)
 
+#if defined(__CSKYABIV2__)
+#define __get_user_asm_dword(x, ptr, err)			\
+	__get_user_asm_common(x, ptr, "ld.d", err)
+#else
+/* fixme: abiv1 not implement get_user_dword */
+#define __get_user_asm_dword(x, ptr, err)			\
+	__get_user_bad()
+#endif
+
 #define __get_user_asm_common(x, ptr, ins, err)			\
 do {								\
 	int errcode;						\
@@ -260,8 +234,6 @@ do {								\
 	: "memory");						\
 } while (0)
 
-extern int __get_user_bad(void);
-
 #define __copy_user(to, from, n)			\
 do {							\
 	int w0, w1, w2, w3;				\
Signature · 1 line
2.7.4
maintainer
#58 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Arnd

author
#59 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 18 lines · Arnd Bergmann
Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}
Quoted 3 lines

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Ah... BUG! I only consider the get_user(u64, u64 *) :P

Change to:
case 8: \
__get_user_asm_dword((x), ptr, "ld.d", retval); \
break;

#define __get_user_asm_dword(x, ptr, err) \

do {							\
	u64 tmp;					\
	__get_user_asm_common(tmp, ptr, "ld.d", err);	\
	x = typeof(x) tmp;				\
} while(0)

#define __put_user_asm_dword(x, ptr, err) \

do {							\
	u64 tmp = (u64) x;				\
	__put_user_asm_common(tmp, ptr, "st.d", err);	\
} while(0)

Hmm?

Best Regards
Guo Ren

maintainer
#60 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 35 lines · Guo Ren
Quoted 18 lines · Arnd Bergmann
Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}
Quoted 3 lines

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Ah... BUG! I only consider the get_user(u64, u64 *) :P

Change to:
case 8: \
__get_user_asm_dword((x), ptr, "ld.d", retval); \
break;

#define __get_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp;                                        \
        __get_user_asm_common(tmp, ptr, "ld.d", err);   \
        x = typeof(x) tmp;                              \
Quoted 8 lines

} while(0)

#define __put_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp = (u64) x;                              \
        __put_user_asm_common(tmp, ptr, "st.d", err);   \

} while(0)

I think this will cause warnings for code that passes a pointer.

The 64-bit __get_user() is really hard, and most 32-bit architectures don't implement it at all. If you really want to add it, have a look at what x86 and arm do. IIRC they both use __builtin_choose_expr(),

Arnd

author
#61 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 45 lines · Arnd Bergmann
Quoted 35 lines · Guo Ren
Quoted 18 lines · Arnd Bergmann
Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}
Quoted 3 lines

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Ah... BUG! I only consider the get_user(u64, u64 *) :P

Change to:
case 8: \
__get_user_asm_dword((x), ptr, "ld.d", retval); \
break;

#define __get_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp;                                        \
        __get_user_asm_common(tmp, ptr, "ld.d", err);   \
        x = typeof(x) tmp;                              \
Quoted 8 lines

} while(0)

#define __put_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp = (u64) x;                              \
        __put_user_asm_common(tmp, ptr, "st.d", err);   \

} while(0)

Quoted 5 lines

I think this will cause warnings for code that passes a pointer.

The 64-bit __get_user() is really hard, and most 32-bit architectures don't implement it at all. If you really want to add it, have a look at what x86 and arm do. IIRC they both use __builtin_choose_expr(),

Thx for the tips and I'll drop the patch first for the upstream.

I want to implement it because of make allmodconfig and drivers/android/binder.c need it. I'll learn __builtin_choose_expr() and prepare patch next.

Best Regards
Guo Ren

maintainer
#62 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 49 lines · Guo Ren
Quoted 47 lines · Arnd Bergmann
Quoted 35 lines · Guo Ren
Quoted 18 lines · Arnd Bergmann
Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}
Quoted 3 lines

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Ah... BUG! I only consider the get_user(u64, u64 *) :P

Change to:
case 8: \
__get_user_asm_dword((x), ptr, "ld.d", retval); \
break;

#define __get_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp;                                        \
        __get_user_asm_common(tmp, ptr, "ld.d", err);   \
        x = typeof(x) tmp;                              \
Quoted 8 lines

} while(0)

#define __put_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp = (u64) x;                              \
        __put_user_asm_common(tmp, ptr, "st.d", err);   \

} while(0)

I think this will cause warnings for code that passes a pointer.

Quoted 8 lines
Quoted 3 lines

The 64-bit __get_user() is really hard, and most 32-bit architectures don't implement it at all. If you really want to add it, have a look at what x86 and arm do. IIRC they both use __builtin_choose_expr(),

Thx for the tips and I'll drop the patch first for the upstream.

I want to implement it because of make allmodconfig and drivers/android/binder.c need it. I'll learn __builtin_choose_expr() and prepare patch next.

I think we should fix binder.c instead. Many other architectures have the same problem.

Arnd

author
#63 lore raw

Re: [PATCH V9 21/21] csky: support dword access for get_user_size()

Quoted 53 lines · Arnd Bergmann
Quoted 52 lines · Guo Ren
Quoted 50 lines · Arnd Bergmann
Quoted 35 lines · Guo Ren
Quoted 18 lines · Arnd Bergmann
Quoted 7 lines · Guo Ren

Support dword access for get_user_size and redesign put_user_size with the same style of get_user_size. It's Ok to use xxx_user_asm_common for all size of variable with ldb, ldh, ldw, ld.d

ld.d rx, (addr, 0) could "rx <= addr" "and r(x+1) <= addr+4" and this also follow abiv2 gcc ABI for dword access.

Are you sure this is correct for this?

static inline u32 get_64_to_32(__u64 __user *p)

{
      u32 ret;
      get_user(ret, p);
      return ret;
}
Quoted 3 lines

If I read __get_user_asm_common() right, the ld.d would overwrite two registers, but the caller only expects one, so it clobbers one that might be in use.

Ah... BUG! I only consider the get_user(u64, u64 *) :P

Change to:
case 8: \
__get_user_asm_dword((x), ptr, "ld.d", retval); \
break;

#define __get_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp;                                        \
        __get_user_asm_common(tmp, ptr, "ld.d", err);   \
        x = typeof(x) tmp;                              \
Quoted 8 lines

} while(0)

#define __put_user_asm_dword(x, ptr, err)               \
do {                                                    \
        u64 tmp = (u64) x;                              \
        __put_user_asm_common(tmp, ptr, "st.d", err);   \

} while(0)

I think this will cause warnings for code that passes a pointer.

The 64-bit __get_user() is really hard, and most 32-bit architectures don't implement it at all. If you really want to add it, have a look at what x86 and arm do. IIRC they both use __builtin_choose_expr(),

Quoted 8 lines
Quoted 5 lines

Thx for the tips and I'll drop the patch first for the upstream.

I want to implement it because of make allmodconfig and drivers/android/binder.c need it. I'll learn __builtin_choose_expr() and prepare patch next.

I think we should fix binder.c instead. Many other architectures have the same problem.

Yes, and I'll study the file.

Best Regards
Guo Ren

maintainer
#64 lore raw
In reply to Guo Ren
Quoted 6 lines · Guo Ren

This is the 9th version patchset to add the Linux kernel port for C-SKY(csky) based on linux-4.19-rc3.

There are only a few changes between V8 patchset. Hope it could be merged into linux-4.20 and I'm very grateful for any help.

I've gone through the entire series once more and saw no show-stoppers. The last patch looked like it introduced a bug, but with that one dropped, I'm happy for the architecture to get merged, unless anyone else has any last-minute concerns. (Alternatively, explain why I'm wrong and the code works correctly, of course).

I'd appreciate having someone else take another look at the signal handling code, the atomics, and the DT bindings and provide another Ack for those.

The remaining open question is about the 32-bit time_t interfaces. With 4.20, I did not manage to get the required system calls in place for using 64-bit time_t in a new architecture, so you will at least start out using 32-bit time_t and likely have to keep supporting that going forward, unless we decide to break the ABI here later on .This is something we normally don't do, but we might make an exception here, under the assumption that there are no existing users with the ABI. We can debate that once we get there.

Arnd

author
#65 lore raw
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Guo Ren

This is the 9th version patchset to add the Linux kernel port for C-SKY(csky) based on linux-4.19-rc3.

Quoted 8 lines
Quoted 2 lines

There are only a few changes between V8 patchset. Hope it could be merged into linux-4.20 and I'm very grateful for any help.

I've gone through the entire series once more and saw no show-stoppers. The last patch looked like it introduced a bug, but with that one dropped, I'm happy for the architecture to get merged, unless anyone else has any last-minute concerns. (Alternatively, explain why I'm wrong and the code works correctly, of course).

Ok and thx for the job of csky subsystem.

Quoted 5 lines

I'd appreciate having someone else take another look at the signal handling code, the atomics, and the DT bindings and provide another Ack for those.

Quoted 8 lines

The remaining open question is about the 32-bit time_t interfaces. With 4.20, I did not manage to get the required system calls in place for using 64-bit time_t in a new architecture, so you will at least start out using 32-bit time_t and likely have to keep supporting that going forward, unless we decide to break the ABI here later on .This is something we normally don't do, but we might make an exception here, under the assumption that there are no existing users with the ABI. We can debate that once we get there.

We support uclibc-ng and glibc.

1. For uclibc-ng, linux-4.20 could run with it.

2. For glibc, Maybe we could support 32-bit + 64-bit time_t with KERNEL_VERSION, or just only 64-bit then linux-4.20 couldn't work with the csky first glibc release.

Best Regards
Guo Ren

maintainer
#66 lore raw
Quoted 30 lines · Guo Ren
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Guo Ren

This is the 9th version patchset to add the Linux kernel port for C-SKY(csky) based on linux-4.19-rc3.

Quoted 8 lines
Quoted 2 lines

There are only a few changes between V8 patchset. Hope it could be merged into linux-4.20 and I'm very grateful for any help.

I've gone through the entire series once more and saw no show-stoppers. The last patch looked like it introduced a bug, but with that one dropped, I'm happy for the architecture to get merged, unless anyone else has any last-minute concerns. (Alternatively, explain why I'm wrong and the code works correctly, of course).

Ok and thx for the job of csky subsystem.

Quoted 5 lines

I'd appreciate having someone else take another look at the signal handling code, the atomics, and the DT bindings and provide another Ack for those.

Quoted 8 lines

The remaining open question is about the 32-bit time_t interfaces. With 4.20, I did not manage to get the required system calls in place for using 64-bit time_t in a new architecture, so you will at least start out using 32-bit time_t and likely have to keep supporting that going forward, unless we decide to break the ABI here later on .This is something we normally don't do, but we might make an exception here, under the assumption that there are no existing users with the ABI. We can debate that once we get there.

Quoted 7 lines

We support uclibc-ng and glibc.

1. For uclibc-ng, linux-4.20 could run with it.

2. For glibc, Maybe we could support 32-bit + 64-bit time_t with KERNEL_VERSION, or just only 64-bit then linux-4.20 couldn't work with the csky first glibc release.

Yes, it is always an option to make glibc more restrictive than the kernel. We could also just make it a configuration option in the kernel whether the system calls are provided, so they don't use memory for the implementation.

You will probably want musl support at some point. musl-1.x always uses 32-bit time_t today, but musl-2.x will use the 64-bit interfaces, so just waiting a bit will probably make it work out for you.

Arnd

author
#67 lore raw
Quoted 35 lines · Arnd Bergmann
Quoted 34 lines · Guo Ren
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Guo Ren

This is the 9th version patchset to add the Linux kernel port for C-SKY(csky) based on linux-4.19-rc3.

Quoted 8 lines
Quoted 2 lines

There are only a few changes between V8 patchset. Hope it could be merged into linux-4.20 and I'm very grateful for any help.

I've gone through the entire series once more and saw no show-stoppers. The last patch looked like it introduced a bug, but with that one dropped, I'm happy for the architecture to get merged, unless anyone else has any last-minute concerns. (Alternatively, explain why I'm wrong and the code works correctly, of course).

Ok and thx for the job of csky subsystem.

Quoted 5 lines

I'd appreciate having someone else take another look at the signal handling code, the atomics, and the DT bindings and provide another Ack for those.

Quoted 8 lines

The remaining open question is about the 32-bit time_t interfaces. With 4.20, I did not manage to get the required system calls in place for using 64-bit time_t in a new architecture, so you will at least start out using 32-bit time_t and likely have to keep supporting that going forward, unless we decide to break the ABI here later on .This is something we normally don't do, but we might make an exception here, under the assumption that there are no existing users with the ABI. We can debate that once we get there.

We support uclibc-ng and glibc.

1. For uclibc-ng, linux-4.20 could run with it.

Quoted 8 lines
Quoted 3 lines

2. For glibc, Maybe we could support 32-bit + 64-bit time_t with KERNEL_VERSION, or just only 64-bit then linux-4.20 couldn't work with the csky first glibc release.

Yes, it is always an option to make glibc more restrictive than the kernel. We could also just make it a configuration option in the kernel whether the system calls are provided, so they don't use memory for the implementation.

Ok.

Quoted 3 lines

You will probably want musl support at some point. musl-1.x always uses 32-bit time_t today, but musl-2.x will use the 64-bit interfaces, so just waiting a bit will probably make it work out for you.

Thx for the tips, we'll consider musl in the future.

Best Regards
Guo Ren