Skip to contentSkip to conversation

nios2 Linux kernel port

PATCH Superseded Ley Foon Tan 17 participants 109 messages Jul 15, 2014 – Aug 8, 2014

Subsystems (8)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover nios2 Linux kernel port

This is the 2nd version of patchset adds the Linux kernel port for Nios II processor from Altera. All of the feedback from v1 patchseries has been addressed. Thanks to all who provided feedback on the previous version.

About Nios II Cores
-------------------
Nios II is a 32-bit embedded-processor architecture designed specifically for the Altera family of FPGAs.
More information is available at http://www.altera.com/devices/processor/nios2/ni2-index.html

Instruction set and architecture overview documents can be found on the following page:
http://www.altera.com/literature/lit-nio2.jsp

Nios2 GCC port is in mainline and will be in the FSF 4.9 release.

The patchset are based on v3.16-rc5 and can also be found in the following git tree:
git://git.rocketboards.org/linux-socfpga-next.git nios2-upstream

-----------------
v2:
* move "Build infrastructure" to last patch
* remove unused console.o from Makefile
* sorted nios2/Kconfig
* change outw/inw to writew/readw in arch/nios2/kernel/time.c
* update PAGE_SIZE to (_AC(1, UL) << PAGE_SHIFT)
* remove config GENERIC_FIND_NEXT_BIT
* rename NO_IOPORT to NO_IOPORT_MAP
* restructure and sort filename in Makefile
* add NIOS2 prefix to all nios2 specific configs
* add targets in Makefile
* remove arch specific misaligned profs
* add debug message when unhandled page fault
* include cpuinfo.h to registers.h
* use generic PTRACE_GETREGSET/PTRACE_SETREGSET
* set IO_SPACE_LIMIT to 0
* remove ZONE_DMA
* update sys_cacheflush()
* remove sys_mmap()
* remove signal domain translation
* update 3c120_devboard.dts
* remove hardcoded constants from soc_dev
* merge nios2_device_probe to nios2_soc_device_init
* add nios2 and timer dts bindings.
* use get_signal() signal_setup_done()
* remove virt_to_bus and bus_to_virt
* update io.h
* update nios2 documentation
* add futex support
* bug fixes

patchset history
-----------------
[v1] : https://lkml.org/lkml/2014/4/18/216

Ley Foon Tan (29):
nios2: Assembly macros and definitions
nios2: Kernel booting and initialization
nios2: Exception handling
nios2: Traps exception handling
nios2: Memory management
nios2: I/O Mapping
nios2: MMU Fault handling
nios2: Page table management
nios2: Process management
nios2: Cache handling
nios2: TLB handling
nios2: Interrupt handling
nios2: DMA mapping API
nios2: ELF definitions
nios2: System calls handling
nios2: Signal handling support
nios2: Library functions
nios2: Device tree support
nios2: Time keeping
nios2: Cpuinfo handling
nios2: Futex operations
nios2: Miscellaneous header files
nios2: Nios2 registers
nios2: Module support
nios2: ptrace support
Add ELF machine define for Nios2
MAINTAINERS: Add nios2 maintainer
Documentation: Add documentation for Nios2 architecture
nios2: Build infrastructure

 Documentation/devicetree/bindings/nios2/nios2.txt |  62 +++
 Documentation/devicetree/bindings/nios2/timer.txt |  19 +
 Documentation/nios2/README                        |  23 +
 MAINTAINERS                                       |   7 +
 arch/nios2/Kconfig                                | 199 ++++++++
 arch/nios2/Kconfig.debug                          |  17 +
 arch/nios2/Makefile                               |  78 +++
 arch/nios2/boot/Makefile                          |  52 ++
 arch/nios2/boot/dts/3c120_devboard.dts            | 155 ++++++
 arch/nios2/boot/linked_dtb.S                      |  19 +
 arch/nios2/configs/3c120_defconfig                |  76 +++
 arch/nios2/include/asm/Kbuild                     |  67 +++
 arch/nios2/include/asm/asm-macros.h               | 309 +++++++++++
 arch/nios2/include/asm/asm-offsets.h              |  20 +
 arch/nios2/include/asm/cache.h                    |  36 ++
 arch/nios2/include/asm/cacheflush.h               |  54 ++
 arch/nios2/include/asm/checksum.h                 |  78 +++
 arch/nios2/include/asm/cmpxchg.h                  |  61 +++
 arch/nios2/include/asm/cpuinfo.h                  |  57 +++
 arch/nios2/include/asm/delay.h                    |  92 ++++
 arch/nios2/include/asm/dma-mapping.h              | 106 ++++
 arch/nios2/include/asm/elf.h                      | 101 ++++
 arch/nios2/include/asm/entry.h                    | 152 ++++++
 arch/nios2/include/asm/futex-irq.h                | 130 +++++
 arch/nios2/include/asm/futex.h                    | 110 ++++
 arch/nios2/include/asm/gpio.h                     |  23 +
 arch/nios2/include/asm/io.h                       | 174 +++++++
 arch/nios2/include/asm/irq.h                      |  34 ++
 arch/nios2/include/asm/irqflags.h                 |  69 +++
 arch/nios2/include/asm/linkage.h                  |  25 +
 arch/nios2/include/asm/mmu.h                      |  18 +
 arch/nios2/include/asm/mmu_context.h              |  66 +++
 arch/nios2/include/asm/mutex.h                    |   1 +
 arch/nios2/include/asm/page.h                     | 113 +++++
 arch/nios2/include/asm/pci.h                      |  25 +
 arch/nios2/include/asm/pgalloc.h                  |  86 ++++
 arch/nios2/include/asm/pgtable-bits.h             |  35 ++
 arch/nios2/include/asm/pgtable.h                  | 305 +++++++++++
 arch/nios2/include/asm/processor.h                | 102 ++++
 arch/nios2/include/asm/ptrace.h                   |  33 ++
 arch/nios2/include/asm/registers.h                |  71 +++
 arch/nios2/include/asm/setup.h                    |  38 ++
 arch/nios2/include/asm/signal.h                   |  22 +
 arch/nios2/include/asm/string.h                   |  24 +
 arch/nios2/include/asm/switch_to.h                |  31 ++
 arch/nios2/include/asm/syscall.h                  | 138 +++++
 arch/nios2/include/asm/syscalls.h                 |  25 +
 arch/nios2/include/asm/thread_info.h              | 120 +++++
 arch/nios2/include/asm/timex.h                    |  27 +
 arch/nios2/include/asm/tlb.h                      |  34 ++
 arch/nios2/include/asm/tlbflush.h                 |  46 ++
 arch/nios2/include/asm/traps.h                    |  19 +
 arch/nios2/include/asm/uaccess.h                  | 233 +++++++++
 arch/nios2/include/asm/ucontext.h                 |  34 ++
 arch/nios2/include/uapi/asm/Kbuild                |  14 +
 arch/nios2/include/uapi/asm/byteorder.h           |  22 +
 arch/nios2/include/uapi/asm/elf.h                 |  67 +++
 arch/nios2/include/uapi/asm/ptrace.h              | 120 +++++
 arch/nios2/include/uapi/asm/sigcontext.h          |  30 ++
 arch/nios2/include/uapi/asm/signal.h              |  23 +
 arch/nios2/include/uapi/asm/stat.h                |  23 +
 arch/nios2/include/uapi/asm/statfs.h              |  24 +
 arch/nios2/include/uapi/asm/swab.h                |  37 ++
 arch/nios2/include/uapi/asm/unistd.h              |  25 +
 arch/nios2/kernel/Makefile                        |  24 +
 arch/nios2/kernel/asm-offsets.c                   |  88 ++++
 arch/nios2/kernel/cpuinfo.c                       | 201 ++++++++
 arch/nios2/kernel/entry.S                         | 554 ++++++++++++++++++++
 arch/nios2/kernel/head.S                          | 175 +++++++
 arch/nios2/kernel/insnemu.S                       | 592 ++++++++++++++++++++++
 arch/nios2/kernel/irq.c                           |  90 ++++
 arch/nios2/kernel/misaligned.c                    | 255 ++++++++++
 arch/nios2/kernel/module.c                        | 135 +++++
 arch/nios2/kernel/nios2_ksyms.c                   |  35 ++
 arch/nios2/kernel/process.c                       | 262 ++++++++++
 arch/nios2/kernel/prom.c                          |  66 +++
 arch/nios2/kernel/ptrace.c                        | 180 +++++++
 arch/nios2/kernel/setup.c                         | 222 ++++++++
 arch/nios2/kernel/signal.c                        | 316 ++++++++++++
 arch/nios2/kernel/sys_nios2.c                     |  66 +++
 arch/nios2/kernel/syscall_table.c                 |  29 ++
 arch/nios2/kernel/time.c                          | 150 ++++++
 arch/nios2/kernel/traps.c                         | 185 +++++++
 arch/nios2/kernel/vmlinux.lds.S                   |  75 +++
 arch/nios2/lib/Makefile                           |   8 +
 arch/nios2/lib/io.c                               |  59 +++
 arch/nios2/lib/memcpy.c                           | 199 ++++++++
 arch/nios2/lib/memmove.c                          |  82 +++
 arch/nios2/lib/memset.c                           |  81 +++
 arch/nios2/mm/Makefile                            |  14 +
 arch/nios2/mm/cacheflush.c                        | 270 ++++++++++
 arch/nios2/mm/dma-mapping.c                       | 186 +++++++
 arch/nios2/mm/extable.c                           |  25 +
 arch/nios2/mm/fault.c                             | 245 +++++++++
 arch/nios2/mm/init.c                              | 142 ++++++
 arch/nios2/mm/ioremap.c                           | 188 +++++++
 arch/nios2/mm/mmu_context.c                       | 116 +++++
 arch/nios2/mm/pgtable.c                           |  73 +++
 arch/nios2/mm/tlb.c                               | 274 ++++++++++
 arch/nios2/mm/uaccess.c                           | 162 ++++++
 arch/nios2/platform/Kconfig.platform              | 129 +++++
 arch/nios2/platform/Makefile                      |   1 +
 arch/nios2/platform/platform.c                    |  51 ++
 include/uapi/linux/elf-em.h                       |   1 +
 104 files changed, 10442 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nios2/nios2.txt
 create mode 100644 Documentation/devicetree/bindings/nios2/timer.txt
 create mode 100644 Documentation/nios2/README
 create mode 100644 arch/nios2/Kconfig
 create mode 100644 arch/nios2/Kconfig.debug
 create mode 100644 arch/nios2/Makefile
 create mode 100644 arch/nios2/boot/Makefile
 create mode 100644 arch/nios2/boot/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/boot/linked_dtb.S
 create mode 100644 arch/nios2/configs/3c120_defconfig
 create mode 100644 arch/nios2/include/asm/Kbuild
 create mode 100644 arch/nios2/include/asm/asm-macros.h
 create mode 100644 arch/nios2/include/asm/asm-offsets.h
 create mode 100644 arch/nios2/include/asm/cache.h
 create mode 100644 arch/nios2/include/asm/cacheflush.h
 create mode 100644 arch/nios2/include/asm/checksum.h
 create mode 100644 arch/nios2/include/asm/cmpxchg.h
 create mode 100644 arch/nios2/include/asm/cpuinfo.h
 create mode 100644 arch/nios2/include/asm/delay.h
 create mode 100644 arch/nios2/include/asm/dma-mapping.h
 create mode 100644 arch/nios2/include/asm/elf.h
 create mode 100644 arch/nios2/include/asm/entry.h
 create mode 100644 arch/nios2/include/asm/futex-irq.h
 create mode 100644 arch/nios2/include/asm/futex.h
 create mode 100644 arch/nios2/include/asm/gpio.h
 create mode 100644 arch/nios2/include/asm/io.h
 create mode 100644 arch/nios2/include/asm/irq.h
 create mode 100644 arch/nios2/include/asm/irqflags.h
 create mode 100644 arch/nios2/include/asm/linkage.h
 create mode 100644 arch/nios2/include/asm/mmu.h
 create mode 100644 arch/nios2/include/asm/mmu_context.h
 create mode 100644 arch/nios2/include/asm/mutex.h
 create mode 100644 arch/nios2/include/asm/page.h
 create mode 100644 arch/nios2/include/asm/pci.h
 create mode 100644 arch/nios2/include/asm/pgalloc.h
 create mode 100644 arch/nios2/include/asm/pgtable-bits.h
 create mode 100644 arch/nios2/include/asm/pgtable.h
 create mode 100644 arch/nios2/include/asm/processor.h
 create mode 100644 arch/nios2/include/asm/ptrace.h
 create mode 100644 arch/nios2/include/asm/registers.h
 create mode 100644 arch/nios2/include/asm/setup.h
 create mode 100644 arch/nios2/include/asm/signal.h
 create mode 100644 arch/nios2/include/asm/string.h
 create mode 100644 arch/nios2/include/asm/switch_to.h
 create mode 100644 arch/nios2/include/asm/syscall.h
 create mode 100644 arch/nios2/include/asm/syscalls.h
 create mode 100644 arch/nios2/include/asm/thread_info.h
 create mode 100644 arch/nios2/include/asm/timex.h
 create mode 100644 arch/nios2/include/asm/tlb.h
 create mode 100644 arch/nios2/include/asm/tlbflush.h
 create mode 100644 arch/nios2/include/asm/traps.h
 create mode 100644 arch/nios2/include/asm/uaccess.h
 create mode 100644 arch/nios2/include/asm/ucontext.h
 create mode 100644 arch/nios2/include/uapi/asm/Kbuild
 create mode 100644 arch/nios2/include/uapi/asm/byteorder.h
 create mode 100644 arch/nios2/include/uapi/asm/elf.h
 create mode 100644 arch/nios2/include/uapi/asm/ptrace.h
 create mode 100644 arch/nios2/include/uapi/asm/sigcontext.h
 create mode 100644 arch/nios2/include/uapi/asm/signal.h
 create mode 100644 arch/nios2/include/uapi/asm/stat.h
 create mode 100644 arch/nios2/include/uapi/asm/statfs.h
 create mode 100644 arch/nios2/include/uapi/asm/swab.h
 create mode 100644 arch/nios2/include/uapi/asm/unistd.h
 create mode 100644 arch/nios2/kernel/Makefile
 create mode 100644 arch/nios2/kernel/asm-offsets.c
 create mode 100644 arch/nios2/kernel/cpuinfo.c
 create mode 100644 arch/nios2/kernel/entry.S
 create mode 100644 arch/nios2/kernel/head.S
 create mode 100644 arch/nios2/kernel/insnemu.S
 create mode 100644 arch/nios2/kernel/irq.c
 create mode 100644 arch/nios2/kernel/misaligned.c
 create mode 100644 arch/nios2/kernel/module.c
 create mode 100644 arch/nios2/kernel/nios2_ksyms.c
 create mode 100644 arch/nios2/kernel/process.c
 create mode 100644 arch/nios2/kernel/prom.c
 create mode 100644 arch/nios2/kernel/ptrace.c
 create mode 100644 arch/nios2/kernel/setup.c
 create mode 100644 arch/nios2/kernel/signal.c
 create mode 100644 arch/nios2/kernel/sys_nios2.c
 create mode 100644 arch/nios2/kernel/syscall_table.c
 create mode 100644 arch/nios2/kernel/time.c
 create mode 100644 arch/nios2/kernel/traps.c
 create mode 100644 arch/nios2/kernel/vmlinux.lds.S
 create mode 100644 arch/nios2/lib/Makefile
 create mode 100644 arch/nios2/lib/io.c
 create mode 100644 arch/nios2/lib/memcpy.c
 create mode 100644 arch/nios2/lib/memmove.c
 create mode 100644 arch/nios2/lib/memset.c
 create mode 100644 arch/nios2/mm/Makefile
 create mode 100644 arch/nios2/mm/cacheflush.c
 create mode 100644 arch/nios2/mm/dma-mapping.c
 create mode 100644 arch/nios2/mm/extable.c
 create mode 100644 arch/nios2/mm/fault.c
 create mode 100644 arch/nios2/mm/init.c
 create mode 100644 arch/nios2/mm/ioremap.c
 create mode 100644 arch/nios2/mm/mmu_context.c
 create mode 100644 arch/nios2/mm/pgtable.c
 create mode 100644 arch/nios2/mm/tlb.c
 create mode 100644 arch/nios2/mm/uaccess.c
 create mode 100644 arch/nios2/platform/Kconfig.platform
 create mode 100644 arch/nios2/platform/Makefile
 create mode 100644 arch/nios2/platform/platform.c
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v2 1/29 nios2: Assembly macros and definitions

This patch add assembly macros and definitions used in the .S files across arch/nios2/ and together with asm-offsets.c.

---
 arch/nios2/include/asm/asm-macros.h  | 309 +++++++++++++++++++++++++++++++++++
 arch/nios2/include/asm/asm-offsets.h |  20 +++
 arch/nios2/kernel/asm-offsets.c      |  88 ++++++++++
 3 files changed, 417 insertions(+)
 create mode 100644 arch/nios2/include/asm/asm-macros.h
 create mode 100644 arch/nios2/include/asm/asm-offsets.h
 create mode 100644 arch/nios2/kernel/asm-offsets.c
arch/nios2/include/asm/asm-macros.h new file +309 -0
new file mode 100644
index 0000000..29fa2e4
@@ -0,0 +1,309 @@
+/*
+ * Macro used to simplify coding multi-line assembler.
+ * Some of the bit test macro can simplify down to one line
+ * depending on the mask value.
+ *
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ */
+#ifndef _ASM_NIOS2_ASMMACROS_H
+#define _ASM_NIOS2_ASMMACROS_H
+/*
+ * ANDs reg2 with mask and places the result in reg1.
+ *
+ * You cannnot use the same register for reg1 & reg2.
+ */
+
+.macro ANDI32	reg1, reg2, mask
+.if \mask & 0xffff
+	.if \mask & 0xffff0000
+		movhi	\reg1, %hi(\mask)
+		movui	\reg1, %lo(\mask)
+		and	\reg1, \reg1, \reg2
+	.else
+		andi	\reg1, \reg2, %lo(\mask)
+	.endif
+.else
+	andhi	\reg1, \reg2, %hi(\mask)
+.endif
+.endm
+
+/*
+ * ORs reg2 with mask and places the result in reg1.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro ORI32	reg1, reg2, mask
+.if \mask & 0xffff
+	.if \mask & 0xffff0000
+		orhi	\reg1, \reg2, %hi(\mask)
+		ori	\reg1, \reg2, %lo(\mask)
+	.else
+		ori	\reg1, \reg2, %lo(\mask)
+	.endif
+.else
+	orhi	\reg1, \reg2, %hi(\mask)
+.endif
+.endm
+
+/*
+ * XORs reg2 with mask and places the result in reg1.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro XORI32	reg1, reg2, mask
+.if \mask & 0xffff
+	.if \mask & 0xffff0000
+		xorhi	\reg1, \reg2, %hi(\mask)
+		xori	\reg1, \reg1, %lo(\mask)
+	.else
+		xori	\reg1, \reg2, %lo(\mask)
+	.endif
+.else
+	xorhi	\reg1, \reg2, %hi(\mask)
+.endif
+.endm
+
+/*
+ * This is a support macro for BTBZ & BTBNZ.  It checks
+ * the bit to make sure it is valid 32 value.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro BT	reg1, reg2, bit
+.if \bit > 31
+	.err
+.else
+	.if \bit < 16
+		andi	\reg1, \reg2, (1 << \bit)
+	.else
+		andhi	\reg1, \reg2, (1 << (\bit - 16))
+	.endif
+.endif
+.endm
+
+/*
+ * Tests the bit in reg2 and branches to label if the
+ * bit is zero.  The result of the bit test is stored in reg1.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTBZ	reg1, reg2, bit, label
+	BT	\reg1, \reg2, \bit
+	beq	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and branches to label if the
+ * bit is non-zero.  The result of the bit test is stored in reg1.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTBNZ	reg1, reg2, bit, label
+	BT	\reg1, \reg2, \bit
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then compliments the bit in reg2.
+ * The result of the bit test is stored in reg1.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTC	reg1, reg2, bit
+.if \bit > 31
+	.err
+.else
+	.if \bit < 16
+		andi	\reg1, \reg2, (1 << \bit)
+		xori	\reg2, \reg2, (1 << \bit)
+	.else
+		andhi	\reg1, \reg2, (1 << (\bit - 16))
+		xorhi	\reg2, \reg2, (1 << (\bit - 16))
+	.endif
+.endif
+.endm
+
+/*
+ * Tests the bit in reg2 and then sets the bit in reg2.
+ * The result of the bit test is stored in reg1.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTS	reg1, reg2, bit
+.if \bit > 31
+	.err
+.else
+	.if \bit < 16
+		andi	\reg1, \reg2, (1 << \bit)
+		ori	\reg2, \reg2, (1 << \bit)
+	.else
+		andhi	\reg1, \reg2, (1 << (\bit - 16))
+		orhi	\reg2, \reg2, (1 << (\bit - 16))
+	.endif
+.endif
+.endm
+
+/*
+ * Tests the bit in reg2 and then resets the bit in reg2.
+ * The result of the bit test is stored in reg1.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTR	reg1, reg2, bit
+.if \bit > 31
+	.err
+.else
+	.if \bit < 16
+		andi	\reg1, \reg2, (1 << \bit)
+		andi	\reg2, \reg2, %lo(~(1 << \bit))
+	.else
+		andhi	\reg1, \reg2, (1 << (\bit - 16))
+		andhi	\reg2, \reg2, %lo(~(1 << (\bit - 16)))
+	.endif
+.endif
+.endm
+
+/*
+ * Tests the bit in reg2 and then compliments the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTCBZ	reg1, reg2, bit, label
+	BTC	\reg1, \reg2, \bit
+	beq	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then compliments the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was non-zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTCBNZ	reg1, reg2, bit, label
+	BTC	\reg1, \reg2, \bit
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then sets the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTSBZ	reg1, reg2, bit, label
+	BTS	\reg1, \reg2, \bit
+	beq	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then sets the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was non-zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTSBNZ	reg1, reg2, bit, label
+	BTS	\reg1, \reg2, \bit
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then resets the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTRBZ	reg1, reg2, bit, label
+	BTR	\reg1, \reg2, \bit
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bit in reg2 and then resets the bit in reg2.
+ * The result of the bit test is stored in reg1.  If the
+ * original bit was non-zero it branches to label.
+ *
+ * It is NOT safe to use the same register for reg1 & reg2.
+ */
+
+.macro BTRBNZ	reg1, reg2, bit, label
+	BTR	\reg1, \reg2, \bit
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bits in mask against reg2 stores the result in reg1.
+ * If the all the bits in the mask are zero it branches to label.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro TSTBZ	reg1, reg2, mask, label
+	ANDI32	\reg1, \reg2, \mask
+	beq	\reg1, r0, \label
+.endm
+
+/*
+ * Tests the bits in mask against reg2 stores the result in reg1.
+ * If the any of the bits in the mask are 1 it branches to label.
+ *
+ * It is safe to use the same register for reg1 & reg2.
+ */
+
+.macro TSTBNZ	reg1, reg2, mask, label
+	ANDI32	\reg1, \reg2, \mask
+	bne	\reg1, r0, \label
+.endm
+
+/*
+ * Pushes reg onto the stack.
+ */
+
+.macro PUSH	reg
+	addi	sp, sp, -4
+	stw	\reg, 0(sp)
+.endm
+
+/*
+ * Pops the top of the stack into reg.
+ */
+
+.macro POP	reg
+	ldw	\reg, 0(sp)
+	addi	sp, sp, 4
+.endm
+
+
+#endif /* _ASM_NIOS2_ASMMACROS_H */
arch/nios2/include/asm/asm-offsets.h new file +20 -0
new file mode 100644
index 0000000..5b9f5e0
@@ -0,0 +1,20 @@
+/*
+ *  Copyright (C) 2010 Tobias Klauser <[email protected]>
+ *  Copyright (C) 2009 Thomas Chou <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <generated/asm-offsets.h>
arch/nios2/kernel/asm-offsets.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v2 2/29 nios2: Kernel booting and initialization

In reply to Ley Foon Tan

This patch adds the kernel booting and the initial setup code.

---
 arch/nios2/include/asm/entry.h | 152 ++++++++++++++++++++++++++++
 arch/nios2/include/asm/setup.h |  38 +++++++
 arch/nios2/kernel/head.S       | 175 ++++++++++++++++++++++++++++++++
 arch/nios2/kernel/setup.c      | 222 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 587 insertions(+)
 create mode 100644 arch/nios2/include/asm/entry.h
 create mode 100644 arch/nios2/include/asm/setup.h
 create mode 100644 arch/nios2/kernel/head.S
 create mode 100644 arch/nios2/kernel/setup.c
arch/nios2/include/asm/entry.h new file +152 -0
new file mode 100644
index 0000000..8b7cddd
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Based on m68knommu asm/entry.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_ENTRY_H
+#define _ASM_NIOS2_ENTRY_H
+
+#ifdef __ASSEMBLY__
+
+#include <asm/processor.h>
+#include <asm/registers.h>
+#include <asm/asm-offsets.h>
+
+/*
+ * Stack layout in 'ret_from_exception':
+ *
+ * This allows access to the syscall arguments in registers r4-r8
+ *
+ *	 0(sp) - r8
+ *	 4(sp) - r9
+ *	 8(sp) - r10
+ *	 C(sp) - r11
+ *	10(sp) - r12
+ *	14(sp) - r13
+ *	18(sp) - r14
+ *	1C(sp) - r15
+ *	20(sp) - r1
+ *	24(sp) - r2
+ *	28(sp) - r3
+ *	2C(sp) - r4
+ *	30(sp) - r5
+ *	34(sp) - r6
+ *	38(sp) - r7
+ *	3C(sp) - orig_r2
+ *	40(sp) - ra
+ *	44(sp) - fp
+ *	48(sp) - sp
+ *	4C(sp) - gp
+ *	50(sp) - estatus
+ *	54(sp) - status_extension (NOMMU only)
+ *	58(sp) - ea
+ */
+
+/*
+ * Standard Nios2 interrupt entry and exit macros.
+ * Must be called with interrupts disabled.
+ */
+.macro SAVE_ALL
+	rdctl	r24, estatus
+	andi	r24, r24, ESTATUS_EU
+	beq	r24, r0, 1f /* In supervisor mode, already on kernel stack */
+
+	movia	r24, _current_thread	/* Switch to current kernel stack */
+	ldw	r24, 0(r24)		/* using the thread_info */
+	addi	r24, r24, THREAD_SIZE-PT_REGS_SIZE
+	stw	sp, PT_SP(r24)		/* Save user stack before changing */
+	mov	sp, r24
+	br	2f
+
+1 :	mov	r24, sp
+	addi	sp, sp, -PT_REGS_SIZE	/* Backup the kernel stack pointer */
+	stw	r24, PT_SP(sp)
+2 :	stw	r1, PT_R1(sp)
+	stw	r2, PT_R2(sp)
+	stw	r3, PT_R3(sp)
+	stw	r4, PT_R4(sp)
+	stw	r5, PT_R5(sp)
+	stw	r6, PT_R6(sp)
+	stw	r7, PT_R7(sp)
+	stw	r8, PT_R8(sp)
+	stw	r9, PT_R9(sp)
+	stw	r10, PT_R10(sp)
+	stw	r11, PT_R11(sp)
+	stw	r12, PT_R12(sp)
+	stw	r13, PT_R13(sp)
+	stw	r14, PT_R14(sp)
+	stw	r15, PT_R15(sp)
+	stw	r2, PT_ORIG_R2(sp)
+	stw	r7, PT_ORIG_R7(sp)
+
+	stw	ra, PT_RA(sp)
+	stw	fp, PT_FP(sp)
+	stw	gp, PT_GP(sp)
+	rdctl	r24, estatus
+	stw	r24, PT_ESTATUS(sp)
+	stw	ea, PT_EA(sp)
+.endm
+
+.macro RESTORE_ALL
+	ldw	r1, PT_R1(sp)		/* Restore registers */
+	ldw	r2, PT_R2(sp)
+	ldw	r3, PT_R3(sp)
+	ldw	r4, PT_R4(sp)
+	ldw	r5, PT_R5(sp)
+	ldw	r6, PT_R6(sp)
+	ldw	r7, PT_R7(sp)
+	ldw	r8, PT_R8(sp)
+	ldw	r9, PT_R9(sp)
+	ldw	r10, PT_R10(sp)
+	ldw	r11, PT_R11(sp)
+	ldw	r12, PT_R12(sp)
+	ldw	r13, PT_R13(sp)
+	ldw	r14, PT_R14(sp)
+	ldw	r15, PT_R15(sp)
+	ldw	ra, PT_RA(sp)
+	ldw	fp, PT_FP(sp)
+	ldw	gp, PT_GP(sp)
+	ldw	r24, PT_ESTATUS(sp)
+	wrctl	estatus, r24
+	ldw	ea, PT_EA(sp)
+	ldw	sp, PT_SP(sp)		/* Restore sp last */
+.endm
+
+.macro	SAVE_SWITCH_STACK
+	addi	sp, sp, -SWITCH_STACK_SIZE
+	stw	r16, SW_R16(sp)
+	stw	r17, SW_R17(sp)
+	stw	r18, SW_R18(sp)
+	stw	r19, SW_R19(sp)
+	stw	r20, SW_R20(sp)
+	stw	r21, SW_R21(sp)
+	stw	r22, SW_R22(sp)
+	stw	r23, SW_R23(sp)
+	stw	fp, SW_FP(sp)
+	stw	gp, SW_GP(sp)
+	stw	ra, SW_RA(sp)
+.endm
+
+.macro	RESTORE_SWITCH_STACK
+	ldw	r16, SW_R16(sp)
+	ldw	r17, SW_R17(sp)
+	ldw	r18, SW_R18(sp)
+	ldw	r19, SW_R19(sp)
+	ldw	r20, SW_R20(sp)
+	ldw	r21, SW_R21(sp)
+	ldw	r22, SW_R22(sp)
+	ldw	r23, SW_R23(sp)
+	ldw	fp, SW_FP(sp)
+	ldw	gp, SW_GP(sp)
+	ldw	ra, SW_RA(sp)
+	addi	sp, sp, SWITCH_STACK_SIZE
+.endm
+
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_NIOS2_ENTRY_H */
arch/nios2/include/asm/setup.h new file +38 -0
new file mode 100644
index 0000000..a3e05a7
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_SETUP_H
+#define _ASM_NIOS2_SETUP_H
+
+#include <asm-generic/setup.h>
+
+#ifndef __ASSEMBLY__
+# ifdef __KERNEL__
+
+extern char exception_handler_hook[];
+extern char fast_handler[];
+extern char fast_handler_end[];
+
+extern void pagetable_init(void);
+
+extern void setup_early_printk(void);
+
+# endif/* __KERNEL__ */
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_NIOS2_SETUP_H */
arch/nios2/kernel/head.S new file +175 -0

175 lines not on this page · raw message

arch/nios2/kernel/setup.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#5 lore raw

PATCH v2 3/29 nios2: Exception handling

In reply to Ley Foon Tan

This patch contains the exception entry code (kernel/entry.S) and misaligned exception.

---
 arch/nios2/kernel/entry.S      | 554 +++++++++++++++++++++++++++++++++++++++++
 arch/nios2/kernel/misaligned.c | 255 +++++++++++++++++++
 2 files changed, 809 insertions(+)
 create mode 100644 arch/nios2/kernel/entry.S
 create mode 100644 arch/nios2/kernel/misaligned.c
arch/nios2/kernel/entry.S new file +554 -0
new file mode 100644
index 0000000..50c78d5
@@ -0,0 +1,554 @@
+/*
+ * linux/arch/nios2/kernel/entry.S
+ *
+ * Copyright (C) 2013  Altera Corporation
+ * Copyright (C) 2009, Wind River Systems Inc
+ *
+ * Implemented by [email protected] and [email protected]
+ *
+ * Based on:
+ *
+ * linux/arch/nios2/kernel/entry.S
+ *
+ *  Copyright (C) 1999-2002, Greg Ungerer ([email protected])
+ *  Copyright (C) 1998  D. Jeff Dionne <[email protected]>,
+ *                      Kenneth Albanowski <[email protected]>,
+ *  Copyright (C) 2000  Lineo Inc. (www.lineo.com)
+ *  Copyright (C) 2004  Microtronix Datacom Ltd.
+ *
+ * Based on:
+ *
+ *  linux/arch/m68knommu/kernel/entry.S
+ *
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Linux/m68k support by Hamish Macdonald
+ *
+ * 68060 fixes by Jesper Skov
+ * ColdFire support by Greg Ungerer ([email protected])
+ * 5307 fixes by David W. Miller
+ * linux 2.4 support David McCullough <[email protected]>
+ */
+
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/asm-offsets.h>
+#include <asm/asm-macros.h>
+#include <asm/thread_info.h>
+#include <asm/errno.h>
+#include <asm/setup.h>
+#include <asm/entry.h>
+#include <asm/unistd.h>
+#include <asm/processor.h>
+
+.macro GET_THREAD_INFO reg
+.if THREAD_SIZE & 0xffff0000
+	andhi	\reg, sp, %hi(~(THREAD_SIZE-1))
+.else
+	addi	\reg, r0, %lo(~(THREAD_SIZE-1))
+	and	\reg, \reg, sp
+.endif
+.endm
+
+.macro	kuser_cmpxchg_check
+	/*
+	 * Make sure our user space atomic helper is restarted if it was
+	 * interrupted in a critical region.
+	 * ea-4 = address of interrupted insn (ea must be preserved).
+	 * sp = saved regs.
+	 * cmpxchg_ldw = first critical insn, cmpxchg_stw = last critical insn.
+	 * If ea <= cmpxchg_stw and ea > cmpxchg_ldw then saved EA is set to
+	 * cmpxchg_ldw + 4.
+	*/
+	/* et = cmpxchg_stw + 4 */
+	movui   et, (KUSER_BASE + 4 + (cmpxchg_stw - __kuser_helper_start))
+	bgtu	ea, et, 1f
+
+	subi	et, et, (cmpxchg_stw - cmpxchg_ldw) /* et = cmpxchg_ldw + 4 */
+	bltu	ea, et, 1f
+	stw	et, PT_EA(sp)	/* fix up EA */
+	mov	ea, et
+1:
+.endm
+
+.section .rodata
+.align 4
+exception_table:
+	.word unhandled_exception	/* 0 - Reset */
+	.word unhandled_exception	/* 1 - Processor-only Reset */
+	.word external_interrupt	/* 2 - Interrupt */
+	.word handle_trap		/* 3 - Trap Instruction */
+
+	.word instruction_trap		/* 4 - Unimplemented instruction */
+	.word handle_illegal		/* 5 - Illegal instruction */
+	.word handle_unaligned		/* 6 - Misaligned data access */
+	.word handle_unaligned		/* 7 - Misaligned destination address */
+
+	.word handle_diverror		/* 8 - Division error */
+	.word protection_exception_ba	/* 9 - Supervisor-only instr. address */
+	.word protection_exception_instr /* 10 - Supervisor only instruction */
+	.word protection_exception_ba	/* 11 - Supervisor only data address */
+
+	.word unhandled_exception	/* 12 - Double TLB miss (data) */
+	.word protection_exception_pte	/* 13 - TLB permission violation (x) */
+	.word protection_exception_pte	/* 14 - TLB permission violation (r) */
+	.word protection_exception_pte	/* 15 - TLB permission violation (w) */
+
+	.word unhandled_exception	/* 16 - MPU region violation */
+
+trap_table:
+	.word	handle_system_call	/* 0  */
+	.word	instruction_trap	/* 1  */
+	.word	instruction_trap	/* 2  */
+	.word	instruction_trap	/* 3  */
+	.word	instruction_trap	/* 4  */
+	.word	instruction_trap	/* 5  */
+	.word	instruction_trap	/* 6  */
+	.word	instruction_trap	/* 7  */
+	.word	instruction_trap	/* 8  */
+	.word	instruction_trap	/* 9  */
+	.word	instruction_trap	/* 10 */
+	.word	instruction_trap	/* 11 */
+	.word	instruction_trap	/* 12 */
+	.word	instruction_trap	/* 13 */
+	.word	instruction_trap	/* 14 */
+	.word	instruction_trap	/* 15 */
+	.word	instruction_trap	/* 16 */
+	.word	instruction_trap	/* 17 */
+	.word	instruction_trap	/* 18 */
+	.word	instruction_trap	/* 19 */
+	.word	instruction_trap	/* 20 */
+	.word	instruction_trap	/* 21 */
+	.word	instruction_trap	/* 22 */
+	.word	instruction_trap	/* 23 */
+	.word	instruction_trap	/* 24 */
+	.word	instruction_trap	/* 25 */
+	.word	instruction_trap	/* 26 */
+	.word	instruction_trap	/* 27 */
+	.word	instruction_trap	/* 28 */
+	.word	instruction_trap	/* 29 */
+	.word	instruction_trap	/* 30 */
+	.word	handle_breakpoint	/* 31 */
+
+.text
+.set noat
+.set nobreak
+
+ENTRY(inthandler)
+	SAVE_ALL
+
+	kuser_cmpxchg_check
+
+	/* Clear EH bit before we get a new excpetion in the kernel
+	 * and after we have saved it to the exception frame. This is done
+	 * wheter it's trap, tlb-miss or interrupt. If we don't do this
+	 * estatus is not updated the next exception.
+	 */
+	rdctl	r24, status
+	movi	r9, %lo(~STATUS_EH)
+	and	r24, r24, r9
+	wrctl	status, r24
+
+	/* Read cause and vector and branch to the associated handler */
+	mov	r4, sp
+	rdctl	r5, exception
+	movia	r9, exception_table
+	add	r24, r9, r5
+	ldw	r24, 0(r24)
+	jmp	r24
+
+
+/***********************************************************************
+ * Handle traps
+ ***********************************************************************
+ */
+ENTRY(handle_trap)
+	ldw	r24, -4(ea)	/* instruction that caused the exception */
+	srli	r24, r24, 4
+	andi	r24, r24, 0x7c
+	movia	r9,trap_table
+	add	r24, r24, r9
+	ldw	r24, 0(r24)
+	jmp	r24
+
+
+/***********************************************************************
+ * Handle system calls
+ ***********************************************************************
+ */
+ENTRY(handle_system_call)
+	/* Enable interrupts */
+	rdctl	r10, status
+	ori	r10, r10, STATUS_PIE
+	wrctl	status, r10
+
+	/* Reload registers destroyed by common code. */
+	ldw	r4, PT_R4(sp)
+	ldw	r5, PT_R5(sp)
+
+	/* Check that the requested system call is within limits */
+	movui	r1, __NR_syscalls
+	bgeu	r2, r1, ret_invsyscall
+	slli	r1, r2, 2
+	movhi	r11, %hiadj(sys_call_table)
+	add	r1, r1, r11
+	ldw	r1, %lo(sys_call_table)(r1)
+	beq	r1, r0, ret_invsyscall
+
+	/* Check if we are being traced */
+	GET_THREAD_INFO r11
+	ldw	r11,TI_FLAGS(r11)
+	BTBNZ   r11,r11,TIF_SYSCALL_TRACE,traced_system_call
+
+	/* Execute the system call */
+	callr	r1
+
+	/* If the syscall returns a negative result:
+	 *   Set r7 to 1 to indicate error,
+	 *   Negate r2 to get a positive error code
+	 * If the syscall returns zero or a positive value:
+	 *   Set r7 to 0.
+	 * The sigreturn system calls will skip the code below by
+	 * adding to register ra. To avoid destroying registers
+	 */
+translate_rc_and_ret:
+	movi	r1, 0
+	bge	r2, zero, 3f
+	sub	r2, zero, r2
+	movi	r1, 1
+3:
+	stw	r2, PT_R2(sp)
+	stw	r1, PT_R7(sp)
+end_translate_rc_and_ret:
+
+ret_from_exception:
+	ldw	r1, PT_ESTATUS(sp)
+	/* if so, skip resched, signals */
+	TSTBNZ	r1, r1, ESTATUS_EU, Luser_return
+
+restore_all:
+	rdctl	r10, status			/* disable intrs */
+	andi	r10, r10, %lo(~STATUS_PIE)
+	wrctl	status, r10
+	RESTORE_ALL
+	eret
+
+	/* If the syscall number was invalid return ENOSYS */
+ret_invsyscall:
+	movi	r2, -ENOSYS
+	br	translate_rc_and_ret
+
+	/* This implements the same as above, except it calls
+	 * do_syscall_trace_enter and do_syscall_trace_exit before and after the
+	 * syscall in order for utilities like strace and gdb to work.
+	 */
+traced_system_call:
+	SAVE_SWITCH_STACK
+	call	do_syscall_trace_enter
+	RESTORE_SWITCH_STACK
+
+	/* Create system call register arguments. The 5th and 6th
+	   arguments on stack are already in place at the beginning
+	   of pt_regs. */
+	ldw	r2, PT_R2(sp)
+	ldw	r4, PT_R4(sp)
+	ldw	r5, PT_R5(sp)
+	ldw	r6, PT_R6(sp)
+	ldw	r7, PT_R7(sp)
+
+	/* Fetch the syscall function, we don't need to check the boundaries
+	 * since this is already done.
+	 */
+	slli	r1, r2, 2
+	movhi	r11,%hiadj(sys_call_table)
+	add	r1, r1, r11
+	ldw	r1, %lo(sys_call_table)(r1)
+
+	callr	r1
+
+	/* If the syscall returns a negative result:
+	 *   Set r7 to 1 to indicate error,
+	 *   Negate r2 to get a positive error code
+	 * If the syscall returns zero or a positive value:
+	 *   Set r7 to 0.
+	 * The sigreturn system calls will skip the code below by
+	 * adding to register ra. To avoid destroying registers
+	 */
+translate_rc_and_ret2:
+	movi	r1, 0
+	bge	r2, zero, 4f
+	sub	r2, zero, r2
+	movi	r1, 1
+4:
+	stw	r2, PT_R2(sp)
+	stw	r1, PT_R7(sp)
+end_translate_rc_and_ret2:
+	SAVE_SWITCH_STACK
+	call	do_syscall_trace_exit
+	RESTORE_SWITCH_STACK
+	br	ret_from_exception
+
+Luser_return:
+	GET_THREAD_INFO	r11			/* get thread_info pointer */
+	ldw	r10, TI_FLAGS(r11)		/* get thread_info->flags */
+	ANDI32	r11, r10, _TIF_WORK_MASK
+	beq	r11, r0, restore_all		/* Nothing to do */
+	BTBZ	r1, r10, TIF_NEED_RESCHED, Lsignal_return
+
+	/* Reschedule work */
+	call	schedule
+	br	ret_from_exception
+
+Lsignal_return:
+	ANDI32	r1, r10, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
+	beq	r1, r0, restore_all
+	mov	r4, sp			/* pt_regs */
+	SAVE_SWITCH_STACK
+	movi	r5, 1			/* in_syscall = 1 */
+	call	do_notify_resume
+	RESTORE_SWITCH_STACK
+	br	restore_all
+
+
+
+/***********************************************************************
+ * Handle external interrupts.
+ ***********************************************************************
+ */
+/*
+ * This is the generic interrupt handler (for all hardware interrupt
+ * sources). It figures out the vector number and calls the appropriate
+ * interrupt service routine directly.
+ */
+external_interrupt:
+	rdctl	r12, ipending
+	rdctl	r9, ienable
+	and	r12, r12, r9
+	/* skip if no interrupt is pending */
+	beq	r12, r0, ret_from_interrupt
+
+	movi	r24, -1
+	stw	r24, PT_ORIG_R2(sp)
+
+	/*
+	 * Process an external hardware interrupt.
+	 */
+
+	addi	ea, ea, -4	/* re-issue the interrupted instruction */
+	stw	ea, PT_EA(sp)
+2:	movi	r4, %lo(-1)	/* Start from bit position 0,
+					highest priority */
+				/* This is the IRQ # for handler call */
+1:	andi	r10, r12, 1	/* Isolate bit we are interested in */
+	srli	r12, r12, 1	/* shift count is costly without hardware
+					multiplier */
+	addi	r4, r4, 1
+	beq	r10, r0, 1b
+	mov	r5, sp		/* Setup pt_regs pointer for handler call */
+	call	do_IRQ
+	rdctl	r12, ipending	/* check again if irq still pending */
+	rdctl	r9, ienable	/* Isolate possible interrupts */
+	and	r12, r12, r9
+	bne	r12, r0, 2b
+	/* br	ret_from_interrupt */ /* fall throught to ret_from_interrupt */
+
+ENTRY(ret_from_interrupt)
+	ldw	r1, PT_ESTATUS(sp)	/* check if returning to kernel */
+	TSTBNZ	r1, r1, ESTATUS_EU, Luser_return
+
+#ifdef CONFIG_PREEMPT
+	GET_THREAD_INFO	r1
+	ldw	r4, TI_PREEMPT_COUNT(r1)
+	bne	r4, r0, restore_all
+
+need_resched:
+	ldw	r4, TI_FLAGS(r1)		/* ? Need resched set */
+	BTBZ	r10, r4, TIF_NEED_RESCHED, restore_all
+	ldw	r4, PT_ESTATUS(sp)	/* ? Interrupts off */
+	andi	r10, r4, ESTATUS_EPIE
+	beq	r10, r0, restore_all
+	movia	r4, PREEMPT_ACTIVE
+	stw	r4, TI_PREEMPT_COUNT(r1)
+	rdctl	r10, status		/* enable intrs again */
+	ori	r10, r10 ,STATUS_PIE
+	wrctl	status, r10
+	PUSH	r1
+	call	schedule
+	POP	r1
+	mov	r4, r0
+	stw	r4, TI_PREEMPT_COUNT(r1)
+	rdctl	r10, status		/* disable intrs */
+	andi	r10, r10, %lo(~STATUS_PIE)
+	wrctl	status, r10
+	br	need_resched
+#else
+	br	restore_all
+#endif
+
+/***********************************************************************
+ * A few syscall wrappers
+ ***********************************************************************
+ */
+/*
+ * int clone(unsigned long clone_flags, unsigned long newsp,
+ *		int __user * parent_tidptr, int __user * child_tidptr,
+ *		int tls_val)
+ */
+ENTRY(sys_clone)
+	SAVE_SWITCH_STACK
+	addi	sp, sp, -4
+	stw	r7, 0(sp)	/* Pass 5th arg thru stack */
+	mov	r7, r6		/* 4th arg is 3rd of clone() */
+	mov	r6, zero	/* 3rd arg always 0 */
+	call	do_fork
+	addi	sp, sp, 4
+	RESTORE_SWITCH_STACK
+	ret
+
+ENTRY(sys_rt_sigreturn)
+	SAVE_SWITCH_STACK
+	mov	r4, sp
+	call	do_rt_sigreturn
+	RESTORE_SWITCH_STACK
+	addi	ra, ra, (end_translate_rc_and_ret - translate_rc_and_ret)
+	ret
+
+/***********************************************************************
+ * A few other wrappers and stubs
+ ***********************************************************************
+ */
+protection_exception_pte:
+	rdctl	r6, pteaddr
+	slli	r6, r6, 10
+	call	do_page_fault
+	br	ret_from_exception
+
+protection_exception_ba:
+	rdctl	r6, badaddr
+	call	do_page_fault
+	br	ret_from_exception
+
+protection_exception_instr:
+	call	handle_supervisor_instr
+	br	ret_from_exception
+
+handle_breakpoint:
+	call	breakpoint_c
+	br	ret_from_exception
+
+#ifdef CONFIG_NIOS2_ALIGNMENT_TRAP
+handle_unaligned:
+	SAVE_SWITCH_STACK
+	call	handle_unaligned_c
+	RESTORE_SWITCH_STACK
+	br	ret_from_exception
+#else
+handle_unaligned:
+	call	handle_unaligned_c
+	br	ret_from_exception
+#endif
+
+handle_illegal:
+	call	handle_illegal_c
+	br	ret_from_exception
+
+handle_diverror:
+	call	handle_diverror_c
+	br	ret_from_exception
+
+/*
+ * Beware - when entering resume, prev (the current task) is
+ * in r4, next (the new task) is in r5, don't change these
+ * registers.
+ */
+ENTRY(resume)
+
+	rdctl	r7, status			/* save thread status reg */
+	stw	r7, TASK_THREAD + THREAD_KPSR(r4)
+
+	andi	r7, r7, %lo(~STATUS_PIE)	/* disable interrupts */
+	wrctl	status, r7
+
+	SAVE_SWITCH_STACK
+	stw	sp, TASK_THREAD + THREAD_KSP(r4)/* save kernel stack pointer */
+	ldw	sp, TASK_THREAD + THREAD_KSP(r5)/* restore new thread stack */
+	movia	r24, _current_thread		/* save thread */
+	GET_THREAD_INFO r1
+	stw	r1, 0(r24)
+	RESTORE_SWITCH_STACK
+
+	ldw	r7, TASK_THREAD + THREAD_KPSR(r5)/* restore thread status reg */
+	wrctl	status, r7
+	ret
+
+ENTRY(ret_from_fork)
+	call	schedule_tail
+	br	ret_from_exception
+
+ENTRY(ret_from_kernel_thread)
+	call	schedule_tail
+	mov	r4,r17	/* arg */
+	callr	r16	/* function */
+	br	ret_from_exception
+
+/*
+ * Kernel user helpers.
+ *
+ * Each segment is 64-byte aligned and will be mapped to the <User space>.
+ * New segments (if ever needed) must be added after the existing ones.
+ * This mechanism should be used only for things that are really small and
+ * justified, and not be abused freely.
+ *
+ */
+
+ /* Filling pads with undefined instructions. */
+.macro	kuser_pad sym size
+	.if	((. - \sym) & 3)
+	.rept	(4 - (. - \sym) & 3)
+	.byte	0
+	.endr
+	.endif
+	.rept	((\size - (. - \sym)) / 4)
+	.word	0xdeadbeef
+	.endr
+.endm
+
+	.align	6
+	.globl	__kuser_helper_start
+__kuser_helper_start:
+
+__kuser_helper_version:				/* @ 0x1000 */
+	.word	((__kuser_helper_end - __kuser_helper_start) >> 6)
+
+__kuser_cmpxchg:				/* @ 0x1004 */
+	/*
+	 * r4 pointer to exchange variable
+	 * r5 old value
+	 * r6 new value
+	 */
+cmpxchg_ldw:
+	ldw	r2, 0(r4)			/* load current value */
+	sub	r2, r2, r5			/* compare with old value */
+	bne	r2, zero, cmpxchg_ret
+
+	/* We had a match, store the new value */
+cmpxchg_stw:
+	stw	r6, 0(r4)
+cmpxchg_ret:
+	ret
+
+	kuser_pad __kuser_cmpxchg, 64
+
+	.globl	__kuser_sigtramp
+__kuser_sigtramp:
+	movi	r2, __NR_rt_sigreturn
+	trap
+
+	kuser_pad __kuser_sigtramp, 64
+
+	.globl	__kuser_helper_end
+__kuser_helper_end:
arch/nios2/kernel/misaligned.c new file +255 -0

255 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#6 lore raw

PATCH v2 4/29 nios2: Traps exception handling

In reply to Ley Foon Tan

This patch contains traps exception handling.

---
 arch/nios2/include/asm/traps.h |  19 ++
 arch/nios2/kernel/insnemu.S    | 592 +++++++++++++++++++++++++++++++++++++++++
 arch/nios2/kernel/traps.c      | 185 +++++++++++++
 3 files changed, 796 insertions(+)
 create mode 100644 arch/nios2/include/asm/traps.h
 create mode 100644 arch/nios2/kernel/insnemu.S
 create mode 100644 arch/nios2/kernel/traps.c
arch/nios2/include/asm/traps.h new file +19 -0
new file mode 100644
index 0000000..82a4847
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_TRAPS_H
+#define _ASM_NIOS2_TRAPS_H
+
+#define TRAP_ID_SYSCALL		0
+
+#ifndef __ASSEMBLY__
+void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr);
+#endif
+
+#endif /* _ASM_NIOS2_TRAPS_H */
arch/nios2/kernel/insnemu.S new file +592 -0

592 lines not on this page · raw message

arch/nios2/kernel/traps.c new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#7 lore raw

PATCH v2 5/29 nios2: Memory management

In reply to Ley Foon Tan

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map.

---
 arch/nios2/include/asm/mmu.h     |  18 +++
 arch/nios2/include/asm/page.h    | 113 +++++++++++++++++++
 arch/nios2/include/asm/uaccess.h | 233 +++++++++++++++++++++++++++++++++++++++
 arch/nios2/mm/init.c             | 142 ++++++++++++++++++++++++
 arch/nios2/mm/uaccess.c          | 162 +++++++++++++++++++++++++++
 5 files changed, 668 insertions(+)
 create mode 100644 arch/nios2/include/asm/mmu.h
 create mode 100644 arch/nios2/include/asm/page.h
 create mode 100644 arch/nios2/include/asm/uaccess.h
 create mode 100644 arch/nios2/mm/init.c
 create mode 100644 arch/nios2/mm/uaccess.c
arch/nios2/include/asm/mmu.h new file +18 -0
new file mode 100644
index 0000000..96ab052
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Taken from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_H
+#define _ASM_NIOS2_MMU_H
+
+/* Default "unsigned long" context */
+typedef unsigned long mm_context_t;
+
+#endif /* _ASM_NIOS2_MMU_H */
arch/nios2/include/asm/page.h new file +113 -0

113 lines not on this page · raw message

arch/nios2/include/asm/uaccess.h new file +233 -0

233 lines not on this page · raw message

arch/nios2/mm/init.c new file +142 -0

142 lines not on this page · raw message

arch/nios2/mm/uaccess.c new file +162 -0

162 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#15 lore raw

PATCH v2 6/29 nios2: I/O Mapping

In reply to Ley Foon Tan

This patch adds several definitions for I/O accessors and ioremap().

---
 arch/nios2/include/asm/io.h | 174 ++++++++++++++++++++++++++++++++++++++++
 arch/nios2/lib/io.c         |  59 ++++++++++++++
 arch/nios2/mm/ioremap.c     | 188 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 421 insertions(+)
 create mode 100644 arch/nios2/include/asm/io.h
 create mode 100644 arch/nios2/lib/io.c
 create mode 100644 arch/nios2/mm/ioremap.c
arch/nios2/include/asm/io.h new file +174 -0
new file mode 100644
index 0000000..7766a9f
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2014 Altera Corporation
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_IO_H
+#define _ASM_NIOS2_IO_H
+
+#include <asm/pgtable-bits.h>
+
+/* PCI is not supported in nios2, set this to 0. */
+#define IO_SPACE_LIMIT 0
+
+#ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE
+#define __IO_USE_DUFFS
+#endif
+
+#ifdef __IO_USE_DUFFS
+
+/* Use "Duff's Device" to unroll the loops. */
+#define __IO_OUT_LOOP(a, b, l)				\
+	do {						\
+		if (l > 0) {				\
+			int _n = (l + 7) / 8;		\
+			switch (l % 8) {		\
+			case 0:				\
+				do {			\
+					*a = *b++;	\
+			case 7:				\
+					*a = *b++;	\
+			case 6:				\
+					*a = *b++;	\
+			case 5:				\
+					*a = *b++;	\
+			case 4:				\
+					*a = *b++;	\
+			case 3:				\
+					*a = *b++;	\
+			case 2:				\
+					*a = *b++;	\
+			case 1:				\
+					*a = *b++;	\
+				} while (--_n > 0);	\
+			}				\
+		}					\
+	} while (0)
+
+#define __IO_IN_LOOP(a, b, l)				\
+	do {						\
+		if (l > 0) {				\
+			int _n = (l + 7) / 8;		\
+			switch (l % 8) {		\
+			case 0:				\
+				do {			\
+					*b++ = *a;	\
+			case 7:				\
+					*b++ = *a;	\
+			case 6:				\
+					*b++ = *a;	\
+			case 5:				\
+					*b++ = *a;	\
+			case 4:				\
+					*b++ = *a;	\
+			case 3:				\
+					*b++ = *a;	\
+			case 2:				\
+					*b++ = *a;	\
+			case 1:				\
+					*b++ = *a;	\
+				} while (--_n > 0);	\
+			}				\
+		}					\
+	} while (0)
+
+#else /* __IO_USE_DUFFS */
+
+/* Use simple loops. */
+#define __IO_OUT_LOOP(a, b, l)				\
+	do {						\
+		while (l--)				\
+			*a = *b++;			\
+	} while (0)
+
+#define __IO_IN_LOOP(a, b, l)				\
+	do {						\
+		while (l--)				\
+			*b++ = *a;			\
+	} while (0)
+
+#endif /* __IO_USE_DUFFS */
+
+extern void outsb(unsigned long addr, const void *buf, int len);
+extern void outsw(unsigned long addr, const void *buf, int len);
+extern void outsl(unsigned long addr, const void *buf, int len);
+extern void insb(unsigned long addr, void *buf, int len);
+extern void insw(unsigned long addr, void *buf, int len);
+extern void insl(unsigned long addr, void *buf, int len);
+#define outsb outsb
+#define outsw outsw
+#define outsl outsl
+#define insb insb
+#define insw insw
+#define insl insl
+
+#define readb_relaxed(addr)	readb(addr)
+#define readw_relaxed(addr)	readw(addr)
+#define readl_relaxed(addr)	readl(addr)
+
+#define writeb_relaxed(x, addr)	writeb(x, addr)
+#define writew_relaxed(x, addr)	writew(x, addr)
+#define writel_relaxed(x, addr)	writel(x, addr)
+
+#include <asm-generic/io.h>
+
+/*
+ * PCI is not enabled in nios2. Provide dummy implementation to get 'allyesconfig'
+ * to build successfully.
+ */
+#define inb(addr)	0
+#define inw(addr)	0
+#define inl(addr)	0
+#define outb(x, addr)
+#define outw(x, addr)
+#define outl(x, addr)
+
+extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size,
+			unsigned long cacheflag);
+extern void __iounmap(void __iomem *addr);
+
+static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
+{
+	return __ioremap(physaddr, size, 0);
+}
+
+static inline void __iomem *ioremap_nocache(unsigned long physaddr,
+						unsigned long size)
+{
+	return __ioremap(physaddr, size, 0);
+}
+
+static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
+						unsigned long size)
+{
+	return __ioremap(physaddr, size, 0);
+}
+
+static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
+						unsigned long size)
+{
+	return __ioremap(physaddr, size, _PAGE_CACHED);
+}
+
+static inline void iounmap(void __iomem *addr)
+{
+	__iounmap(addr);
+}
+
+/* Pages to physical address... */
+# define page_to_phys(page)	virt_to_phys(page_to_virt(page))
+# define page_to_bus(page)	page_to_virt(page)
+
+/* Macros used for converting between virtual and physical mappings. */
+# define phys_to_virt(vaddr)	\
+	((void *)((unsigned long)(vaddr) | CONFIG_NIOS2_KERNEL_REGION_BASE))
+/* Clear top 3 bits */
+# define virt_to_phys(vaddr)	\
+	((unsigned long)((unsigned long)(vaddr) & ~0xE0000000))
+
+#endif /* _ASM_NIOS2_IO_H */
arch/nios2/lib/io.c new file +59 -0

59 lines not on this page · raw message

arch/nios2/mm/ioremap.c new file +188 -0

188 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#19 lore raw

PATCH v2 8/29 nios2: Page table management

In reply to Ley Foon Tan

This patch adds support for page table management.

---
 arch/nios2/include/asm/pgalloc.h      |  86 ++++++++++
 arch/nios2/include/asm/pgtable-bits.h |  35 ++++
 arch/nios2/include/asm/pgtable.h      | 305 ++++++++++++++++++++++++++++++++++
 arch/nios2/mm/pgtable.c               |  73 ++++++++
 4 files changed, 499 insertions(+)
 create mode 100644 arch/nios2/include/asm/pgalloc.h
 create mode 100644 arch/nios2/include/asm/pgtable-bits.h
 create mode 100644 arch/nios2/include/asm/pgtable.h
 create mode 100644 arch/nios2/mm/pgtable.c
arch/nios2/include/asm/pgalloc.h new file +86 -0
new file mode 100644
index 0000000..6e2985e
@@ -0,0 +1,86 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
+ * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
+ */
+
+#ifndef _ASM_NIOS2_PGALLOC_H
+#define _ASM_NIOS2_PGALLOC_H
+
+#include <linux/mm.h>
+
+static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
+	pte_t *pte)
+{
+	set_pmd(pmd, __pmd((unsigned long)pte));
+}
+
+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
+	pgtable_t pte)
+{
+	set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
+}
+#define pmd_pgtable(pmd) pmd_page(pmd)
+
+/*
+ * Initialize a new pmd table with invalid pointers.
+ */
+extern void pmd_init(unsigned long page, unsigned long pagetable);
+
+extern pgd_t *pgd_alloc(struct mm_struct *mm);
+
+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+	free_pages((unsigned long)pgd, PGD_ORDER);
+}
+
+static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
+	unsigned long address)
+{
+	pte_t *pte;
+
+	pte = (pte_t *) __get_free_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO,
+					PTE_ORDER);
+
+	return pte;
+}
+
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
+	unsigned long address)
+{
+	struct page *pte;
+
+	pte = alloc_pages(GFP_KERNEL | __GFP_REPEAT, PTE_ORDER);
+	if (pte) {
+		if (!pgtable_page_ctor(pte)) {
+			__free_page(pte);
+			return NULL;
+		}
+		clear_highpage(pte);
+	}
+	return pte;
+}
+
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
+{
+	free_pages((unsigned long)pte, PTE_ORDER);
+}
+
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
+{
+	pgtable_page_dtor(pte);
+	__free_pages(pte, PTE_ORDER);
+}
+
+#define __pte_free_tlb(tlb, pte, addr)				\
+	do {							\
+		pgtable_page_dtor(pte);				\
+		tlb_remove_page((tlb), (pte));			\
+	} while (0)
+
+#define check_pgt_cache()	do { } while (0)
+
+#endif /* _ASM_NIOS2_PGALLOC_H */
arch/nios2/include/asm/pgtable-bits.h new file +35 -0
new file mode 100644
index 0000000..ce9e706
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ * Copyright (C) 2009 Wind River Systems Inc
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_PGTABLE_BITS_H
+#define _ASM_NIOS2_PGTABLE_BITS_H
+
+/*
+ * These are actual hardware defined protection bits in the tlbacc register
+ * which looks like this:
+ *
+ * 31 30 ... 26 25 24 23 22 21 20 19 18 ...  1  0
+ * ignored........  C  R  W  X  G PFN............
+ */
+#define _PAGE_GLOBAL	(1<<20)
+#define _PAGE_EXEC	(1<<21)
+#define _PAGE_WRITE	(1<<22)
+#define _PAGE_READ	(1<<23)
+#define _PAGE_CACHED	(1<<24)	/* C: data access cacheable */
+
+/*
+ * Software defined bits. They are ignored by the hardware and always read back
+ * as zero, but can be written as non-zero.
+ */
+#define _PAGE_PRESENT	(1<<25)	/* PTE contains a translation */
+#define _PAGE_ACCESSED	(1<<26)	/* page referenced */
+#define _PAGE_DIRTY	(1<<27)	/* dirty page */
+#define _PAGE_FILE	(1<<28)	/* PTE used for file mapping or swap */
+
+#endif /* _ASM_NIOS2_PGTABLE_BITS_H */
arch/nios2/include/asm/pgtable.h new file +305 -0

305 lines not on this page · raw message

arch/nios2/mm/pgtable.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#20 lore raw

PATCH v2 9/29 nios2: Process management

In reply to Ley Foon Tan

This patch adds support for thread creation and context switching.

---
 arch/nios2/include/asm/mmu_context.h |  66 +++++++++
 arch/nios2/include/asm/processor.h   | 102 ++++++++++++++
 arch/nios2/include/asm/switch_to.h   |  31 +++++
 arch/nios2/include/asm/thread_info.h | 120 ++++++++++++++++
 arch/nios2/kernel/process.c          | 262 +++++++++++++++++++++++++++++++++++
 arch/nios2/mm/mmu_context.c          | 116 ++++++++++++++++
 6 files changed, 697 insertions(+)
 create mode 100644 arch/nios2/include/asm/mmu_context.h
 create mode 100644 arch/nios2/include/asm/processor.h
 create mode 100644 arch/nios2/include/asm/switch_to.h
 create mode 100644 arch/nios2/include/asm/thread_info.h
 create mode 100644 arch/nios2/kernel/process.c
 create mode 100644 arch/nios2/mm/mmu_context.c
arch/nios2/include/asm/mmu_context.h new file +66 -0
new file mode 100644
index 0000000..294b4b1
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
+ * Copyright (C) 1999 Silicon Graphics, Inc.
+ *
+ * based on MIPS asm/mmu_context.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_CONTEXT_H
+#define _ASM_NIOS2_MMU_CONTEXT_H
+
+#include <asm-generic/mm_hooks.h>
+
+extern void mmu_context_init(void);
+extern unsigned long get_pid_from_context(mm_context_t *ctx);
+
+/*
+ * For the fast tlb miss handlers, we keep a pointer to the current pgd.
+ * processor.
+ */
+extern pgd_t *pgd_current;
+
+static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
+{
+}
+
+/*
+ * Initialize the context related info for a new mm_struct instance.
+ *
+ * Set all new contexts to 0, that way the generation will never match
+ * the currently running generation when this context is switched in.
+ */
+static inline int init_new_context(struct task_struct *tsk,
+					struct mm_struct *mm)
+{
+	mm->context = 0;
+	return 0;
+}
+
+/*
+ * Destroy context related info for an mm_struct that is about
+ * to be put to rest.
+ */
+static inline void destroy_context(struct mm_struct *mm)
+{
+}
+
+void switch_mm(struct mm_struct *prev, struct mm_struct *next,
+		struct task_struct *tsk);
+
+static inline void deactivate_mm(struct task_struct *tsk,
+				struct mm_struct *mm)
+{
+}
+
+/*
+ * After we have set current->mm to a new value, this activates
+ * the context for the new mm so we see the new mappings.
+ */
+void activate_mm(struct mm_struct *prev, struct mm_struct *next);
+
+#endif /* _ASM_NIOS2_MMU_CONTEXT_H */
arch/nios2/include/asm/processor.h new file +102 -0

102 lines not on this page · raw message

arch/nios2/include/asm/switch_to.h new file +31 -0
new file mode 100644
index 0000000..c47b3f4
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#ifndef _ASM_NIOS2_SWITCH_TO_H
+#define _ASM_NIOS2_SWITCH_TO_H
+
+/*
+ * switch_to(n) should switch tasks to task ptr, first checking that
+ * ptr isn't the current task, in which case it does nothing.  This
+ * also clears the TS-flag if the task we switched to has used the
+ * math co-processor latest.
+ */
+#define switch_to(prev, next, last)			\
+{							\
+	void *_last;					\
+	__asm__ __volatile__ (				\
+		"mov	r4, %1\n"			\
+		"mov	r5, %2\n"			\
+		"call	resume\n"			\
+		"mov	%0,r4\n"			\
+		: "=r" (_last)				\
+		: "r" (prev), "r" (next)		\
+		: "r4", "r5", "r7", "r8", "ra");	\
+	(last) = _last;					\
+}
+
+#endif /* _ASM_NIOS2_SWITCH_TO_H */
arch/nios2/include/asm/thread_info.h new file +120 -0

120 lines not on this page · raw message

arch/nios2/kernel/process.c new file +262 -0

262 lines not on this page · raw message

arch/nios2/mm/mmu_context.c new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#21 lore raw

PATCH v2 10/29 nios2: Cache handling

In reply to Ley Foon Tan

This patch adds functionality required for cache maintenance.

---
 arch/nios2/include/asm/cache.h      |  36 +++++
 arch/nios2/include/asm/cacheflush.h |  54 ++++++++
 arch/nios2/mm/cacheflush.c          | 270 ++++++++++++++++++++++++++++++++++++
 3 files changed, 360 insertions(+)
 create mode 100644 arch/nios2/include/asm/cache.h
 create mode 100644 arch/nios2/include/asm/cacheflush.h
 create mode 100644 arch/nios2/mm/cacheflush.c
arch/nios2/include/asm/cache.h new file +36 -0
new file mode 100644
index 0000000..2293cf5
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#ifndef _ASM_NIOS2_CACHE_H
+#define _ASM_NIOS2_CACHE_H
+
+#define NIOS2_DCACHE_SIZE	CONFIG_NIOS2_DCACHE_SIZE
+#define NIOS2_ICACHE_SIZE	CONFIG_NIOS2_ICACHE_SIZE
+#define NIOS2_DCACHE_LINE_SIZE	CONFIG_NIOS2_DCACHE_LINE_SIZE
+#define NIOS2_ICACHE_LINE_SHIFT	5
+#define NIOS2_ICACHE_LINE_SIZE	(1 << NIOS2_ICACHE_LINE_SHIFT)
+
+/* bytes per L1 cache line */
+#define L1_CACHE_SHIFT		NIOS2_ICACHE_LINE_SHIFT
+#define L1_CACHE_BYTES		NIOS2_ICACHE_LINE_SIZE
+
+#define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
+
+#define __cacheline_aligned
+#define ____cacheline_aligned
+
+#endif
arch/nios2/include/asm/cacheflush.h new file +54 -0

54 lines not on this page · raw message

arch/nios2/mm/cacheflush.c new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#22 lore raw

PATCH v2 11/29 nios2: TLB handling

In reply to Ley Foon Tan

This patch adds the TLB maintenance functions.

---
 arch/nios2/include/asm/tlb.h      |  34 +++++
 arch/nios2/include/asm/tlbflush.h |  46 +++++++
 arch/nios2/mm/tlb.c               | 274 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 354 insertions(+)
 create mode 100644 arch/nios2/include/asm/tlb.h
 create mode 100644 arch/nios2/include/asm/tlbflush.h
 create mode 100644 arch/nios2/mm/tlb.c
arch/nios2/include/asm/tlb.h new file +34 -0
new file mode 100644
index 0000000..d3bc648
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2009 Wind River Systems Inc
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_TLB_H
+#define _ASM_NIOS2_TLB_H
+
+#define tlb_flush(tlb)	flush_tlb_mm((tlb)->mm)
+
+extern void set_mmu_pid(unsigned long pid);
+
+/*
+ * NiosII doesn't need any special per-pte or per-vma handling, except
+ * we need to flush cache for the area to be unmapped.
+ */
+#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 { } while (0)
+#define __tlb_remove_tlb_entry(tlb, ptep, address)	do { } while (0)
+
+#include <linux/pagemap.h>
+#include <asm-generic/tlb.h>
+
+#endif /* _ASM_NIOS2_TLB_H */
arch/nios2/include/asm/tlbflush.h new file +46 -0

46 lines not on this page · raw message

arch/nios2/mm/tlb.c new file +274 -0

274 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#23 lore raw

PATCH v2 12/29 nios2: Interrupt handling

In reply to Ley Foon Tan

This patch adds the support for IRQ handling.

---
 arch/nios2/include/asm/irq.h      | 34 +++++++++++++++
 arch/nios2/include/asm/irqflags.h | 69 ++++++++++++++++++++++++++++++
 arch/nios2/kernel/irq.c           | 90 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 arch/nios2/include/asm/irq.h
 create mode 100644 arch/nios2/include/asm/irqflags.h
 create mode 100644 arch/nios2/kernel/irq.c
arch/nios2/include/asm/irq.h new file +34 -0
new file mode 100644
index 0000000..f7e94b9
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS	32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS			(NIOS2_CPU_NR_IRQS + 32)
+
+#ifndef NO_IRQ
+#define NO_IRQ			(-1)
+#endif
+
+#include <asm-generic/irq.h>
+#include <linux/irqdomain.h>
+
+#endif
arch/nios2/include/asm/irqflags.h new file +69 -0

69 lines not on this page · raw message

arch/nios2/kernel/irq.c new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#43 lore raw

PATCH v2 16/29 nios2: Signal handling support

In reply to Ley Foon Tan

This patch adds support for signal handling.

---
 arch/nios2/include/asm/signal.h          |  22 +++
 arch/nios2/include/asm/ucontext.h        |  34 ++++
 arch/nios2/include/uapi/asm/sigcontext.h |  30 +++
 arch/nios2/include/uapi/asm/signal.h     |  23 +++
 arch/nios2/kernel/signal.c               | 316 +++++++++++++++++++++++++++++++
 5 files changed, 425 insertions(+)
 create mode 100644 arch/nios2/include/asm/signal.h
 create mode 100644 arch/nios2/include/asm/ucontext.h
 create mode 100644 arch/nios2/include/uapi/asm/sigcontext.h
 create mode 100644 arch/nios2/include/uapi/asm/signal.h
 create mode 100644 arch/nios2/kernel/signal.c
arch/nios2/include/asm/signal.h new file +22 -0
new file mode 100644
index 0000000..bbcf11e
@@ -0,0 +1,22 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef _NIOS2_SIGNAL_H
+#define _NIOS2_SIGNAL_H
+
+#include <uapi/asm/signal.h>
+
+#endif	/* _NIOS2_SIGNAL_H */
arch/nios2/include/asm/ucontext.h new file +34 -0
new file mode 100644
index 0000000..5870ef4
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * derived from m68knommu
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_UCONTEXT_H
+#define _ASM_NIOS2_UCONTEXT_H
+
+typedef int greg_t;
+#define NGREG 32
+typedef greg_t gregset_t[NGREG];
+
+struct mcontext {
+	int version;
+	gregset_t gregs;
+};
+
+#define MCONTEXT_VERSION 2
+
+struct ucontext {
+	unsigned long	  uc_flags;
+	struct ucontext  *uc_link;
+	stack_t		  uc_stack;
+	struct mcontext	  uc_mcontext;
+	sigset_t	  uc_sigmask;	/* mask last for extensibility */
+};
+
+#endif
arch/nios2/include/uapi/asm/sigcontext.h new file +30 -0
new file mode 100644
index 0000000..6bfd880
@@ -0,0 +1,30 @@
+/*
+ * Taken from the m68knommu.
+ *
+ * Copyright (C) 2004, Microtronix Datacom Ltd.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#ifndef _ASM_NIOS2_SIGCONTEXT_H
+#define _ASM_NIOS2_SIGCONTEXT_H
+
+#include <asm/ptrace.h>
+
+struct sigcontext {
+	struct pt_regs regs;
+	unsigned long  sc_mask;	/* old sigmask */
+};
+
+#endif
arch/nios2/include/uapi/asm/signal.h new file +23 -0
new file mode 100644
index 0000000..f29ee63
@@ -0,0 +1,23 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef _ASM_NIOS2_SIGNAL_H
+#define _ASM_NIOS2_SIGNAL_H
+
+#define SA_RESTORER 0x04000000
+#include <asm-generic/signal.h>
+
+#endif /* _ASM_NIOS2_SIGNAL_H */
arch/nios2/kernel/signal.c new file +316 -0

316 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#47 lore raw

PATCH v2 18/29 nios2: Device tree support

In reply to Ley Foon Tan

Add device tree support to arch/nios2.

---
 Documentation/devicetree/bindings/nios2/nios2.txt |  62 +++++++++
 Documentation/devicetree/bindings/nios2/timer.txt |  19 +++
 arch/nios2/boot/dts/3c120_devboard.dts            | 155 ++++++++++++++++++++++
 arch/nios2/boot/linked_dtb.S                      |  19 +++
 arch/nios2/kernel/prom.c                          |  66 +++++++++
 arch/nios2/platform/platform.c                    |  51 +++++++
 6 files changed, 372 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nios2/nios2.txt
 create mode 100644 Documentation/devicetree/bindings/nios2/timer.txt
 create mode 100644 arch/nios2/boot/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/boot/linked_dtb.S
 create mode 100644 arch/nios2/kernel/prom.c
 create mode 100644 arch/nios2/platform/platform.c
Documentation/devicetree/bindings/nios2/nios2.txt new file +62 -0
new file mode 100644
index 0000000..d6d0a94
@@ -0,0 +1,62 @@
+* Nios II Processor Binding
+
+This binding specifies what properties available in the device tree
+representation of a Nios II Processor Core.
+
+Users can use sopc2dts tool for generating device tree sources (dts) from a
+Qsys system. See more detail in: http://www.alterawiki.com/wiki/Sopc2dts
+
+Required properties:
+
+- compatible: Compatible property value should be "altr,nios2-1.0".
+- reg: Contains CPU index.
+- interrupt-controller: Specifies that the node is an interrupt controller
+- #interrupt-cells: Specifies the number of cells needed to encode an
+		interrupt source, should be 1.
+- clock-frequency: Contains the clock frequency for CPU, in Hz.
+- dcache-line-size: Contains data cache line size.
+- icache-line-size: Contains instruction line size.
+- dcache-size: Contains data cache size.
+- icache-size: Contains instruction cache size.
+- altr,pid-num-bits: Specifies the number of bits to use to represent the process
+		identifier (PID).
+- altr,tlb-num-ways: Specifies the number of set-associativity ways in the TLB.
+- altr,tlb-num-entries: Specifies the number of entries in the TLB.
+- altr,tlb-ptr-sz: Specifies size of TLB pointer.
+- altr,has-mul: Specifies CPU hardware multipy support, should be 1.
+- altr,has-mmu: Specifies CPU support MMU support, should be 1.
+- altr,has-initda: Specifies CPU support initda instruction, should be 1.
+- altr,reset-addr: Specifies CPU reset address
+- altr,fast-tlb-miss-addr: Specifies CPU fast TLB miss exception address
+- altr,exception-addr: Specifies CPU exception address
+
+Optional properties:
+- altr,has-div: Specifies CPU hardware divide support
+- altr,implementation: Nios II core implementation, this should be "fast";
+
+Example:
+
+cpu@0x0 {
+	device_type = "cpu";
+	compatible = "altr,nios2-1.0";
+	reg = <0>;
+	interrupt-controller;
+	#interrupt-cells = <1>;
+	clock-frequency = <125000000>;
+	dcache-line-size = <32>;
+	icache-line-size = <32>;
+	dcache-size = <32768>;
+	icache-size = <32768>;
+	altr,implementation = "fast";
+	altr,pid-num-bits = <8>;
+	altr,tlb-num-ways = <16>;
+	altr,tlb-num-entries = <128>;
+	altr,tlb-ptr-sz = <7>;
+	altr,has-div = <1>;
+	altr,has-mul = <1>;
+	altr,reset-addr = <0xc2800000>;
+	altr,fast-tlb-miss-addr = <0xc7fff400>;
+	altr,exception-addr = <0xd0000020>;
+	altr,has-initda = <1>;
+	altr,has-mmu = <1>;
+};
Documentation/devicetree/bindings/nios2/timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
arch/nios2/boot/dts/3c120_devboard.dts new file +155 -0

155 lines not on this page · raw message

arch/nios2/boot/linked_dtb.S new file +19 -0
new file mode 100644
index 0000000..071f922
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 Thomas Chou <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+.section .dtb.init.rodata,"a"
+.incbin "arch/nios2/boot/system.dtb"
arch/nios2/kernel/prom.c new file +66 -0

66 lines not on this page · raw message

arch/nios2/platform/platform.c new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#58 lore raw

PATCH v2 20/29 nios2: Cpuinfo handling

In reply to Ley Foon Tan
---
 arch/nios2/include/asm/cpuinfo.h |  57 +++++++++++
 arch/nios2/kernel/cpuinfo.c      | 201 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 258 insertions(+)
 create mode 100644 arch/nios2/include/asm/cpuinfo.h
 create mode 100644 arch/nios2/kernel/cpuinfo.c
arch/nios2/include/asm/cpuinfo.h new file +57 -0
new file mode 100644
index 0000000..e88fcae
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_CPUINFO_H
+#define _ASM_NIOS2_CPUINFO_H
+
+#include <linux/types.h>
+
+struct cpuinfo {
+	/* Core CPU configuration */
+	char cpu_impl[12];
+	u32 cpu_clock_freq;
+	u32 mmu;
+	u32 has_div;
+	u32 has_mul;
+	u32 has_mulx;
+
+	/* CPU caches */
+	u32 icache_line_size;
+	u32 icache_size;
+	u32 dcache_line_size;
+	u32 dcache_size;
+
+	/* TLB */
+	u32 tlb_pid_num_bits;	/* number of bits used for the PID in TLBMISC */
+	u32 tlb_num_ways;
+	u32 tlb_num_ways_log2;
+	u32 tlb_num_entries;
+	u32 tlb_num_lines;
+	u32 tlb_ptr_sz;
+
+	/* Addresses */
+	u32 reset_addr;
+	u32 exception_addr;
+	u32 fast_tlb_miss_exc_addr;
+};
+
+extern struct cpuinfo cpuinfo;
+
+extern void setup_cpuinfo(void);
+
+#endif /* _ASM_NIOS2_CPUINFO_H */
arch/nios2/kernel/cpuinfo.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#62 lore raw

PATCH v2 21/29 nios2: Futex operations

In reply to Ley Foon Tan

This patch introduces the futex operation.

---
 arch/nios2/include/asm/futex-irq.h | 130 +++++++++++++++++++++++++++++++++++++
 arch/nios2/include/asm/futex.h     | 110 +++++++++++++++++++++++++++++++
 2 files changed, 240 insertions(+)
 create mode 100644 arch/nios2/include/asm/futex-irq.h
 create mode 100644 arch/nios2/include/asm/futex.h
arch/nios2/include/asm/futex-irq.h new file +130 -0
new file mode 100644
index 0000000..ade9296
@@ -0,0 +1,130 @@
+/*
+ *  Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Based on asm/futex.h from sh platform.
+ *
+ */
+
+#ifndef __ASM_NIOS2_FUTEX_IRQ_H
+#define __ASM_NIOS2_FUTEX_IRQ_H
+
+
+static inline int atomic_futex_op_xchg_set(int oparg, u32 __user *uaddr,
+					   int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(oparg, uaddr);
+
+	local_irq_restore(flags);
+
+	return ret;
+}
+
+static inline int atomic_futex_op_xchg_add(int oparg, u32 __user *uaddr,
+					   int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(*oldval + oparg, uaddr);
+
+	local_irq_restore(flags);
+
+	return ret;
+}
+
+static inline int atomic_futex_op_xchg_or(int oparg, u32 __user *uaddr,
+					  int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(*oldval | oparg, uaddr);
+
+	local_irq_restore(flags);
+
+	return ret;
+}
+
+static inline int atomic_futex_op_xchg_and(int oparg, u32 __user *uaddr,
+					   int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(*oldval & oparg, uaddr);
+
+	local_irq_restore(flags);
+
+	return ret;
+}
+
+static inline int atomic_futex_op_xchg_xor(int oparg, u32 __user *uaddr,
+					   int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(*oldval ^ oparg, uaddr);
+
+	local_irq_restore(flags);
+
+	return ret;
+}
+
+static inline int atomic_futex_op_cmpxchg_inatomic(u32 *uval,
+						u32 __user *uaddr,
+						u32 oldval, u32 newval)
+{
+	unsigned long flags;
+	int ret;
+	u32 prev = 0;
+
+	local_irq_save(flags);
+
+	ret = get_user(prev, uaddr);
+	if (!ret && oldval == prev)
+		ret = put_user(newval, uaddr);
+
+	local_irq_restore(flags);
+
+	*uval = prev;
+	return ret;
+}
+
+#endif /* __ASM_NIOS2_FUTEX_IRQ_H */
arch/nios2/include/asm/futex.h new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#74 lore raw

PATCH v2 22/29 nios2: Miscellaneous header files

In reply to Ley Foon Tan

This patch introduces a few nios2-specific header files.

---
 arch/nios2/include/asm/cmpxchg.h        | 61 +++++++++++++++++++++++++++++++++
 arch/nios2/include/asm/gpio.h           | 23 +++++++++++++
 arch/nios2/include/asm/linkage.h        | 25 ++++++++++++++
 arch/nios2/include/asm/mutex.h          |  1 +
 arch/nios2/include/asm/pci.h            | 25 ++++++++++++++
 arch/nios2/include/uapi/asm/byteorder.h | 22 ++++++++++++
 arch/nios2/include/uapi/asm/stat.h      | 23 +++++++++++++
 arch/nios2/include/uapi/asm/statfs.h    | 24 +++++++++++++
 arch/nios2/include/uapi/asm/swab.h      | 37 ++++++++++++++++++++
 9 files changed, 241 insertions(+)
 create mode 100644 arch/nios2/include/asm/cmpxchg.h
 create mode 100644 arch/nios2/include/asm/gpio.h
 create mode 100644 arch/nios2/include/asm/linkage.h
 create mode 100644 arch/nios2/include/asm/mutex.h
 create mode 100644 arch/nios2/include/asm/pci.h
 create mode 100644 arch/nios2/include/uapi/asm/byteorder.h
 create mode 100644 arch/nios2/include/uapi/asm/stat.h
 create mode 100644 arch/nios2/include/uapi/asm/statfs.h
 create mode 100644 arch/nios2/include/uapi/asm/swab.h
arch/nios2/include/asm/cmpxchg.h new file +61 -0
new file mode 100644
index 0000000..8593871
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_CMPXCHG_H
+#define _ASM_NIOS2_CMPXCHG_H
+
+#include <linux/irqflags.h>
+
+#define xchg(ptr, x)	\
+	((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
+
+struct __xchg_dummy { unsigned long a[100]; };
+#define __xg(x)		((volatile struct __xchg_dummy *)(x))
+
+static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
+					int size)
+{
+	unsigned long tmp, flags;
+
+	local_irq_save(flags);
+
+	switch (size) {
+	case 1:
+		__asm__ __volatile__(
+			"ldb	%0, %2\n"
+			"stb	%1, %2\n"
+			: "=&r" (tmp)
+			: "r" (x), "m" (*__xg(ptr))
+			: "memory");
+		break;
+	case 2:
+		__asm__ __volatile__(
+			"ldh	%0, %2\n"
+			"sth	%1, %2\n"
+			: "=&r" (tmp)
+			: "r" (x), "m" (*__xg(ptr))
+			: "memory");
+		break;
+	case 4:
+		__asm__ __volatile__(
+			"ldw	%0, %2\n"
+			"stw	%1, %2\n"
+			: "=&r" (tmp)
+			: "r" (x), "m" (*__xg(ptr))
+			: "memory");
+		break;
+	}
+
+	local_irq_restore(flags);
+	return tmp;
+}
+
+#include <asm-generic/cmpxchg.h>
+#include <asm-generic/cmpxchg-local.h>
+
+#endif /* _ASM_NIOS2_CMPXCHG_H */
arch/nios2/include/asm/gpio.h new file +23 -0
new file mode 100644
index 0000000..e726bfc
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_GPIO_H
+#define _ASM_NIOS2_GPIO_H
+
+#include <linux/gpio.h>
+
+#endif /* _ASM_NIOS2_GPIO_H */
arch/nios2/include/asm/linkage.h new file +25 -0
new file mode 100644
index 0000000..e0c6dec
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2009 Thomas Chou <[email protected]>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#ifndef _ASM_NIOS2_LINKAGE_H
+#define _ASM_NIOS2_LINKAGE_H
+
+/* This file is required by include/linux/linkage.h */
+#define __ALIGN .align 4
+#define __ALIGN_STR ".align 4"
+
+#endif
arch/nios2/include/asm/mutex.h new file +1 -0
new file mode 100644
index 0000000..ff6101a
@@ -0,0 +1 @@
+#include <asm-generic/mutex-dec.h>
arch/nios2/include/asm/pci.h new file +25 -0
new file mode 100644
index 0000000..69c86fa
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef __ASM_NIOS2_PCI_H__
+#define __ASM_NIOS2_PCI_H__
+
+/* We don't support PCI yet, but some drivers require this file anyway */
+
+#endif /* __ASM_NIOS2_PCI_H__ */
arch/nios2/include/uapi/asm/byteorder.h new file +22 -0
new file mode 100644
index 0000000..3ab5dc2
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2009   Thomas Chou <[email protected]>
+ * Copyright (C) 2004   Microtronix Datacom Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef _ASM_NIOS2_BYTEORDER_H
+#define _ASM_NIOS2_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif
arch/nios2/include/uapi/asm/stat.h new file +23 -0
new file mode 100644
index 0000000..009f505
@@ -0,0 +1,23 @@
+/*
+ * Copyright Altera Corporation (C) 2014. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _UAPI_ASM_NIOS2_STAT_H
+#define _UAPI_ASM_NIOS2_STAT_H
+
+#include <asm-generic/stat.h>
+
+#endif
arch/nios2/include/uapi/asm/statfs.h new file +24 -0
new file mode 100644
index 0000000..625c864
@@ -0,0 +1,24 @@
+/*
+ * Copyright Altera Corporation (C) 2014. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _UAPI_ASM_NIOS2_STATFS_H
+#define _UAPI_ASM_NIOS2_STATFS_H
+
+#define __statfs_word __s32
+#include <asm-generic/statfs.h>
+
+#endif
arch/nios2/include/uapi/asm/swab.h new file +37 -0
new file mode 100644
index 0000000..b4e22eb
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Tobias Klauser <[email protected]>
+ * Copyright (C) 2011 Pyramid Technical Consultants, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file COPYING in the main directory of this
+ * archive for more details.
+ */
+
+#ifndef _ASM_NIOS2_SWAB_H
+#define _ASM_NIOS2_SWAB_H
+
+#include <linux/types.h>
+#include <asm-generic/swab.h>
+
+#ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
+#ifdef __GNUC__
+
+#define __nios2_swab(x)		\
+	__builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
+
+static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
+{
+	return (__u16) __nios2_swab(((__u32) x) << 16);
+}
+#define __arch_swab16 __arch_swab16
+
+static inline __attribute__((const)) __u32 __arch_swab32(__u32 x)
+{
+	return (__u32) __nios2_swab(x);
+}
+#define __arch_swab32 __arch_swab32
+
+#endif /* __GNUC__ */
+#endif /* CONFIG_NIOS2_CI_SWAB_SUPPORT */
+
+#endif /* _ASM_NIOS2_SWAB_H */
Signature · 1 line
1.8.2.1
#81 lore raw

PATCH v2 23/29 nios2: Nios2 registers

In reply to Ley Foon Tan

This file contains constants for the instruction macros, cpu registers, fields and bits.

---
 arch/nios2/include/asm/registers.h | 71 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 arch/nios2/include/asm/registers.h
arch/nios2/include/asm/registers.h new file +71 -0
new file mode 100644
index 0000000..615bce1
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_REGISTERS_H
+#define _ASM_NIOS2_REGISTERS_H
+
+#ifndef __ASSEMBLY__
+#include <asm/cpuinfo.h>
+#endif
+
+/* control register numbers */
+#define CTL_STATUS	0
+#define CTL_ESTATUS	1
+#define CTL_BSTATUS	2
+#define CTL_IENABLE	3
+#define CTL_IPENDING	4
+#define CTL_CPUID	5
+#define CTL_RSV1	6
+#define CTL_EXCEPTION	7
+#define CTL_PTEADDR	8
+#define CTL_TLBACC	9
+#define CTL_TLBMISC	10
+#define CTL_RSV2	11
+#define CTL_BADADDR	12
+#define CTL_CONFIG	13
+#define CTL_MPUBASE	14
+#define CTL_MPUACC	15
+
+/* access control registers using GCC builtins */
+#define RDCTL(r)	__builtin_rdctl(r)
+#define WRCTL(r, v)	__builtin_wrctl(r, v)
+
+/* status register bits */
+#define STATUS_PIE	(1 << 0)	/* processor interrupt enable */
+#define STATUS_U	(1 << 1)	/* user mode */
+#define STATUS_EH	(1 << 2)	/* Exception mode */
+
+/* estatus register bits */
+#define ESTATUS_EPIE	(1 << 0)	/* processor interrupt enable */
+#define ESTATUS_EU	(1 << 1)	/* user mode */
+#define ESTATUS_EH	(1 << 2)	/* Exception mode */
+
+/* tlbmisc register bits */
+#define TLBMISC_PID_SHIFT	4
+#ifndef __ASSEMBLY__
+#define TLBMISC_PID_MASK	((1UL << cpuinfo.tlb_pid_num_bits) - 1)
+#endif
+#define TLBMISC_WAY_MASK	0xf
+#define TLBMISC_WAY_SHIFT	20
+
+#define TLBMISC_PID	(TLBMISC_PID_MASK << TLBMISC_PID_SHIFT)	/* TLB PID */
+#define TLBMISC_WE	(1 << 18)	/* TLB write enable */
+#define TLBMISC_RD	(1 << 19)	/* TLB read */
+#define TLBMISC_WAY	(TLBMISC_WAY_MASK << TLBMISC_WAY_SHIFT) /* TLB way */
+
+#endif /* _ASM_NIOS2_REGISTERS_H */
Signature · 1 line
1.8.2.1
#82 lore raw

PATCH v2 24/29 nios2: Module support

In reply to Ley Foon Tan

This patch adds support for loadable modules.

---
 arch/nios2/kernel/module.c | 135 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)
 create mode 100644 arch/nios2/kernel/module.c
arch/nios2/kernel/module.c new file +135 -0
new file mode 100644
index 0000000..360c53a
@@ -0,0 +1,135 @@
+/*
+ * Kernel module support for Nios II.
+ *
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *   Written by Wentao Xu <[email protected]>
+ * Copyright (C) 2001, 2003 Rusty Russell
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file COPYING in the main directory of this
+ * archive for more details.
+ */
+
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/mm.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#include <asm/pgtable.h>
+#include <asm/cacheflush.h>
+
+void *module_alloc(unsigned long size)
+{
+	if (size == 0)
+		return NULL;
+	return kmalloc(size, GFP_KERNEL);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+	kfree(module_region);
+}
+
+int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
+			unsigned int symindex, unsigned int relsec,
+			struct module *mod)
+{
+	unsigned int i;
+	Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
+
+	pr_debug("Applying relocate section %u to %u\n", relsec,
+		 sechdrs[relsec].sh_info);
+
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
+		/* This is where to make the change */
+		uint32_t word;
+		uint32_t *loc
+			= ((void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
+			   + rela[i].r_offset);
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
+		Elf32_Sym *sym
+			= ((Elf32_Sym *)sechdrs[symindex].sh_addr
+				+ ELF32_R_SYM(rela[i].r_info));
+		uint32_t v = sym->st_value + rela[i].r_addend;
+		pr_debug("reltype %d 0x%x name:<%s>\n",
+			ELF32_R_TYPE(rela[i].r_info),
+			rela[i].r_offset, strtab + sym->st_name);
+
+		switch (ELF32_R_TYPE(rela[i].r_info)) {
+		case R_NIOS2_NONE:
+			break;
+		case R_NIOS2_BFD_RELOC_32:
+			*loc += v;
+			break;
+		case R_NIOS2_PCREL16:
+			v -= (uint32_t)loc + 4;
+			if ((int32_t)v > 0x7fff ||
+				(int32_t)v < -(int32_t)0x8000) {
+				pr_err("module %s: relocation overflow\n",
+					mod->name);
+				return -ENOEXEC;
+			}
+			word = *loc;
+			*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
+				(word & 0x3f);
+			break;
+		case R_NIOS2_CALL26:
+			if (v & 3) {
+				pr_err("module %s: dangerous relocation\n",
+					mod->name);
+				return -ENOEXEC;
+			}
+			if ((v >> 28) != ((uint32_t)loc >> 28)) {
+				pr_err("module %s: relocation overflow\n",
+					mod->name);
+				return -ENOEXEC;
+			}
+			*loc = (*loc & 0x3f) | ((v >> 2) << 6);
+			break;
+		case R_NIOS2_HI16:
+			word = *loc;
+			*loc = ((((word >> 22) << 16) |
+				((v >> 16) & 0xffff)) << 6) | (word & 0x3f);
+			break;
+		case R_NIOS2_LO16:
+			word = *loc;
+			*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
+					(word & 0x3f);
+			break;
+		case R_NIOS2_HIADJ16:
+			{
+				Elf32_Addr word2;
+
+				word = *loc;
+				word2 = ((v >> 16) + ((v >> 15) & 1)) & 0xffff;
+				*loc = ((((word >> 22) << 16) | word2) << 6) |
+						(word & 0x3f);
+			}
+			break;
+
+		default:
+			pr_err("module %s: Unknown reloc: %u\n",
+				mod->name, ELF32_R_TYPE(rela[i].r_info));
+			return -ENOEXEC;
+		}
+	}
+
+	return 0;
+}
+
+int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
+			struct module *me)
+{
+	flush_cache_all();
+	return 0;
+}
+
+void module_arch_cleanup(struct module *mod)
+{
+}
Signature · 1 line
1.8.2.1
#88 lore raw

PATCH v2 25/29 nios2: ptrace support

In reply to Ley Foon Tan

Add ptrace support for nios2.

---
 arch/nios2/include/asm/ptrace.h      |  33 +++++++
 arch/nios2/include/uapi/asm/ptrace.h | 120 +++++++++++++++++++++++
 arch/nios2/kernel/ptrace.c           | 180 +++++++++++++++++++++++++++++++++++
 3 files changed, 333 insertions(+)
 create mode 100644 arch/nios2/include/asm/ptrace.h
 create mode 100644 arch/nios2/include/uapi/asm/ptrace.h
 create mode 100644 arch/nios2/kernel/ptrace.c
arch/nios2/include/asm/ptrace.h new file +33 -0
new file mode 100644
index 0000000..20fb1cf
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * based on m68k asm/processor.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_PTRACE_H
+#define _ASM_NIOS2_PTRACE_H
+
+#include <uapi/asm/ptrace.h>
+
+#ifndef __ASSEMBLY__
+#define user_mode(regs)	(((regs)->estatus & ESTATUS_EU))
+
+#define instruction_pointer(regs)	((regs)->ra)
+#define profile_pc(regs)		instruction_pointer(regs)
+#define user_stack_pointer(regs)	((regs)->sp)
+extern void show_regs(struct pt_regs *);
+
+#define current_pt_regs() \
+	((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE)\
+		- 1)
+
+int do_syscall_trace_enter(void);
+void do_syscall_trace_exit(void);
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_NIOS2_PTRACE_H */
arch/nios2/include/uapi/asm/ptrace.h new file +120 -0

120 lines not on this page · raw message

arch/nios2/kernel/ptrace.c new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#92 lore raw

PATCH v2 27/29 MAINTAINERS: Add nios2 maintainer

In reply to Ley Foon Tan
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index e31c874..db2bdf1 100644
@@ -6350,6 +6350,13 @@ S:	Maintained
 F:	Documentation/scsi/NinjaSCSI.txt
 F:	drivers/scsi/nsp32*
 
+NIOS2 ARCHITECTURE
+M:	Ley Foon Tan <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+T:	git://git.rocketboards.org/linux-socfpga.git
+S:	Maintained
+F:	arch/nios2/
+
 NTB DRIVER
 M:	Jon Mason <[email protected]>
 S:	Supported
Signature · 1 line
1.8.2.1
#95 lore raw

PATCH v2 28/29 Documentation: Add documentation for Nios2 architecture

In reply to Ley Foon Tan
---
 Documentation/nios2/README | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/nios2/README
Documentation/nios2/README new file +23 -0
new file mode 100644
index 0000000..054a67d
@@ -0,0 +1,23 @@
+Linux on the Nios II architecture
+=================================
+
+This is a port of Linux to Nios II (nios2) processor.
+
+In order to compile for Nios II, you need a version of GCC with support for the generic
+system call ABI. Please see this link for more information on how compiling and booting
+software for the Nios II platform:
+http://www.rocketboards.org/foswiki/Documentation/NiosIILinuxUserManual
+
+For reference, please see the following link:
+http://www.altera.com/literature/lit-nio2.jsp
+
+What is Nios II?
+================
+Nios II is a 32-bit embedded-processor architecture designed specifically for the
+Altera family of FPGAs. In order to support Linux, Nios II needs to be configured
+with MMU and hardware multiplier enabled.
+
+Nios II ABI
+===========
+Please refer to chapter "Application Binary Interface" in Nios II Processor Reference
+Handbook.
Signature · 1 line
1.8.2.1
#96 lore raw

PATCH v2 29/29 nios2: Build infrastructure

In reply to Ley Foon Tan

This patch adds Makefile and Kconfig files required for building a nios2 kernel.

---
 arch/nios2/Kconfig                   | 199 +++++++++++++++++++++++++++++++++++
 arch/nios2/Kconfig.debug             |  17 +++
 arch/nios2/Makefile                  |  78 ++++++++++++++
 arch/nios2/boot/Makefile             |  52 +++++++++
 arch/nios2/configs/3c120_defconfig   |  76 +++++++++++++
 arch/nios2/include/asm/Kbuild        |  67 ++++++++++++
 arch/nios2/include/uapi/asm/Kbuild   |  14 +++
 arch/nios2/kernel/Makefile           |  24 +++++
 arch/nios2/kernel/nios2_ksyms.c      |  35 ++++++
 arch/nios2/kernel/vmlinux.lds.S      |  75 +++++++++++++
 arch/nios2/lib/Makefile              |   8 ++
 arch/nios2/mm/Makefile               |  14 +++
 arch/nios2/platform/Kconfig.platform | 129 +++++++++++++++++++++++
 arch/nios2/platform/Makefile         |   1 +
 14 files changed, 789 insertions(+)
 create mode 100644 arch/nios2/Kconfig
 create mode 100644 arch/nios2/Kconfig.debug
 create mode 100644 arch/nios2/Makefile
 create mode 100644 arch/nios2/boot/Makefile
 create mode 100644 arch/nios2/configs/3c120_defconfig
 create mode 100644 arch/nios2/include/asm/Kbuild
 create mode 100644 arch/nios2/include/uapi/asm/Kbuild
 create mode 100644 arch/nios2/kernel/Makefile
 create mode 100644 arch/nios2/kernel/nios2_ksyms.c
 create mode 100644 arch/nios2/kernel/vmlinux.lds.S
 create mode 100644 arch/nios2/lib/Makefile
 create mode 100644 arch/nios2/mm/Makefile
 create mode 100644 arch/nios2/platform/Kconfig.platform
 create mode 100644 arch/nios2/platform/Makefile
arch/nios2/Kconfig new file +199 -0
new file mode 100644
index 0000000..2c8b64d
@@ -0,0 +1,199 @@
+config NIOS2
+	def_bool y
+	select ARCH_WANT_OPTIONAL_GPIOLIB
+	select CLKSRC_OF
+	select GENERIC_ATOMIC64
+	select GENERIC_CPU_DEVICES
+	select GENERIC_IRQ_PROBE
+	select GENERIC_IRQ_SHOW
+	select HAVE_ARCH_TRACEHOOK
+	select IRQ_DOMAIN
+	select MODULES_USE_ELF_RELA
+	select OF
+	select OF_EARLY_FLATTREE
+	select SOC_BUS
+	select USB_ARCH_HAS_HCD if USB_SUPPORT
+
+config GENERIC_CSUM
+	def_bool y
+
+config GENERIC_HWEIGHT
+	def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+	def_bool y
+
+config NO_IOPORT_MAP
+	def_bool y
+
+config HAS_DMA
+	def_bool y
+
+config FPU
+	def_bool n
+
+config SWAP
+	def_bool n
+
+config RWSEM_GENERIC_SPINLOCK
+	def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool n
+
+source "init/Kconfig"
+
+menu "Kernel features"
+
+source "kernel/Kconfig.preempt"
+
+source "kernel/Kconfig.freezer"
+
+source "kernel/Kconfig.hz"
+
+source "mm/Kconfig"
+
+config FORCE_MAX_ZONEORDER
+	int "Maximum zone order"
+	range 9 20
+	default "11"
+	help
+	  The kernel memory allocator divides physically contiguous memory
+	  blocks into "zones", where each zone is a power of two number of
+	  pages.  This option selects the largest power of two that the kernel
+	  keeps in the memory allocator.  If you need to allocate very large
+	  blocks of physically contiguous memory, then you may need to
+	  increase this value.
+
+	  This config option is actually maximum order plus one. For example,
+	  a value of 11 means that the largest free memory block is 2^10 pages.
+
+endmenu
+
+source "arch/nios2/platform/Kconfig.platform"
+
+menu "Processor type and features"
+
+config MMU
+	def_bool y
+
+config NIOS2_ALIGNMENT_TRAP
+	bool "Catch alignment trap"
+	default y
+	help
+	  Nios II CPUs cannot fetch/store data which is not bus aligned,
+	  i.e., a 2 or 4 byte fetch must start at an address divisible by
+	  2 or 4. Any non-aligned load/store instructions will be trapped and
+	  emulated in software if you say Y here, which has a performance
+	  impact.
+
+comment "Boot options"
+
+config CMDLINE_BOOL
+	bool "Default bootloader kernel arguments"
+	default y
+
+config CMDLINE
+	string "Default kernel command string"
+	default ""
+	depends on CMDLINE_BOOL
+	help
+	  On some platforms, there is currently no way for the boot loader to
+	  pass arguments to the kernel. For these platforms, you can supply
+	  some command-line options at build time by entering them here.  In
+	  other cases you can specify kernel args so that you don't have
+	  to set them up in board prom initialization routines.
+
+config CMDLINE_FORCE
+	bool "Force default kernel command string"
+	depends on CMDLINE_BOOL
+	help
+	  Set this to have arguments from the default kernel command string
+	  override those passed by the boot loader.
+
+config NIOS2_CMDLINE_IGNORE_DTB
+	bool "Ignore kernel command string from DTB"
+	depends on !CMDLINE_FORCE
+	default y
+	help
+	  Set this to ignore the bootargs property from the devicetree's
+	  chosen node and fall back to CMDLINE if nothing is passed.
+
+config NIOS2_PASS_CMDLINE
+	bool "Passed kernel command line from u-boot"
+	default n
+	help
+	  Use bootargs env variable from u-boot for kernel command line.
+	  will override "Default kernel command string".
+	  Say N if you are unsure.
+
+endmenu
+
+menu "Advanced setup"
+
+config ADVANCED_OPTIONS
+	bool "Prompt for advanced kernel configuration options"
+	help
+
+comment "Default settings for advanced configuration options are used"
+	depends on !ADVANCED_OPTIONS
+
+config NIOS2_KERNEL_MMU_REGION_BASE_BOOL
+	bool "Set custom kernel MMU region base address"
+	depends on ADVANCED_OPTIONS
+	help
+	  This option allows you to set the virtual address of the kernel MMU region.
+
+	  Say N here unless you know what you are doing.
+
+config NIOS2_KERNEL_MMU_REGION_BASE
+	hex "Virtual base address of the kernel MMU region " if NIOS2_KERNEL_MMU_REGION_BASE_BOOL
+	default "0x80000000"
+	help
+	  This option allows you to set the virtual base address of the kernel MMU region.
+
+config NIOS2_KERNEL_REGION_BASE_BOOL
+	bool "Set custom kernel region base address"
+	depends on ADVANCED_OPTIONS
+	help
+	  This option allows you to set the virtual address of the kernel region.
+
+	  Say N here unless you know what you are doing.
+
+config NIOS2_KERNEL_REGION_BASE
+	hex "Virtual base address of the kernel region " if NIOS2_KERNEL_REGION_BASE_BOOL
+	default "0xc0000000"
+
+config NIOS2_IO_REGION_BASE_BOOL
+	bool "Set custom I/O region base address"
+	depends on ADVANCED_OPTIONS
+	help
+	  This option allows you to set the virtual address of the I/O region.
+
+	  Say N here unless you know what you are doing.
+
+config NIOS2_IO_REGION_BASE
+	hex "Virtual base address of the I/O region" if NIOS2_IO_REGION_BASE_BOOL
+	default "0xe0000000"
+
+endmenu
+
+menu "Executable file formats"
+
+source "fs/Kconfig.binfmt"
+
+endmenu
+
+source "net/Kconfig"
+
+source "drivers/Kconfig"
+
+source "fs/Kconfig"
+
+source "arch/nios2/Kconfig.debug"
+
+source "security/Kconfig"
+
+source "crypto/Kconfig"
+
+source "lib/Kconfig"
arch/nios2/Kconfig.debug new file +17 -0
new file mode 100644
index 0000000..8d4e6ba
@@ -0,0 +1,17 @@
+menu "Kernel hacking"
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+
+source "lib/Kconfig.debug"
+
+config DEBUG_STACK_USAGE
+	bool "Enable stack utilization instrumentation"
+	depends on DEBUG_KERNEL
+	help
+	  Enables the display of the minimum amount of free stack which each
+	  task has ever had available in the sysrq-T and sysrq-P debug output.
+
+	  This option will slow down process creation somewhat.
+
+endmenu
arch/nios2/Makefile new file +78 -0

78 lines not on this page · raw message

arch/nios2/boot/Makefile new file +52 -0

52 lines not on this page · raw message

arch/nios2/configs/3c120_defconfig new file +76 -0

76 lines not on this page · raw message

arch/nios2/include/asm/Kbuild new file +67 -0

67 lines not on this page · raw message

arch/nios2/include/uapi/asm/Kbuild new file +14 -0
new file mode 100644
index 0000000..6d9f2e8
@@ -0,0 +1,14 @@
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += byteorder.h
+header-y += elf.h
+header-y += kvm_para.h
+header-y += processor.h
+header-y += ptrace.h
+header-y += setup.h
+header-y += sigcontext.h
+header-y += signal.h
+header-y += stat.h
+header-y += statfs.h
+header-y += swab.h
+header-y += unistd.h
arch/nios2/kernel/Makefile new file +24 -0
new file mode 100644
index 0000000..8ae7682
@@ -0,0 +1,24 @@
+#
+# Makefile for the nios2 linux kernel.
+#
+
+extra-y	+= head.o
+extra-y	+= vmlinux.lds
+
+obj-y	+= cpuinfo.o
+obj-y	+= entry.o
+obj-y	+= insnemu.o
+obj-y	+= irq.o
+obj-y	+= nios2_ksyms.o
+obj-y	+= process.o
+obj-y	+= prom.o
+obj-y	+= ptrace.o
+obj-y	+= setup.o
+obj-y	+= signal.o
+obj-y	+= sys_nios2.o
+obj-y	+= syscall_table.o
+obj-y	+= time.o
+obj-y	+= traps.o
+
+obj-$(CONFIG_MODULES)			+= module.o
+obj-$(CONFIG_NIOS2_ALIGNMENT_TRAP)	+= misaligned.o
arch/nios2/kernel/nios2_ksyms.c new file +35 -0
new file mode 100644
index 0000000..eaf7f0c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file COPYING in the main directory of this
+ * archive for more details.
+ */
+
+#include <linux/export.h>
+#include <linux/string.h>
+
+/* string functions */
+
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memset);
+EXPORT_SYMBOL(memmove);
+
+/*
+ * libgcc functions - functions that are used internally by the
+ * compiler...  (prototypes are not correct though, but that
+ * doesn't really matter since they're not versioned).
+ */
+#define DECLARE_EXPORT(name)	extern void name(void); EXPORT_SYMBOL(name)
+
+DECLARE_EXPORT(__gcc_bcmp);
+DECLARE_EXPORT(__divdi3);
+DECLARE_EXPORT(__divsi3);
+DECLARE_EXPORT(__moddi3);
+DECLARE_EXPORT(__modsi3);
+DECLARE_EXPORT(__udivdi3);
+DECLARE_EXPORT(__udivmoddi4);
+DECLARE_EXPORT(__udivsi3);
+DECLARE_EXPORT(__umoddi3);
+DECLARE_EXPORT(__umodsi3);
+DECLARE_EXPORT(__muldi3);
arch/nios2/kernel/vmlinux.lds.S new file +75 -0

75 lines not on this page · raw message

arch/nios2/lib/Makefile new file +8 -0
new file mode 100644
index 0000000..174aa54
@@ -0,0 +1,8 @@
+#
+# Makefile for Nios2-specific library files.
+#
+
+lib-y += io.o
+lib-y += memcpy.o
+lib-y += memmove.o
+lib-y += memset.o
arch/nios2/mm/Makefile new file +14 -0
new file mode 100644
index 0000000..3cbd084
@@ -0,0 +1,14 @@
+#
+# Makefile for the Nios2-specific parts of the memory manager.
+#
+
+obj-y	+= cacheflush.o
+obj-y	+= dma-mapping.o
+obj-y	+= extable.o
+obj-y	+= fault.o
+obj-y	+= init.o
+obj-y	+= ioremap.o
+obj-y	+= mmu_context.o
+obj-y	+= pgtable.o
+obj-y	+= tlb.o
+obj-y	+= uaccess.o
arch/nios2/platform/Kconfig.platform new file +129 -0

129 lines not on this page · raw message

arch/nios2/platform/Makefile new file +1 -0
new file mode 100644
index 0000000..46364f1
@@ -0,0 +1 @@
+obj-y += platform.o
Signature · 1 line
1.8.2.1
#18 lore raw

PATCH v2 7/29 nios2: MMU Fault handling

In reply to Ley Foon Tan

This patch adds support for the handling of the MMU faults (exception entry code introduced by a previous patch, kernel/entry.S).

---
 arch/nios2/mm/extable.c |  25 +++++
 arch/nios2/mm/fault.c   | 245 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 270 insertions(+)
 create mode 100644 arch/nios2/mm/extable.c
 create mode 100644 arch/nios2/mm/fault.c
arch/nios2/mm/extable.c new file +25 -0
new file mode 100644
index 0000000..4d2fc5a
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2010, Tobias Klauser <[email protected]>
+ * Copyright (C) 2009, Wind River Systems Inc
+ *   Implemented by [email protected] and [email protected]
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+	const struct exception_table_entry *fixup;
+
+	fixup = search_exception_tables(regs->ea);
+	if (fixup) {
+		regs->ea = fixup->fixup;
+		return 1;
+	}
+
+	return 0;
+}
arch/nios2/mm/fault.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#46 lore raw

PATCH v2 17/29 nios2: Library functions

In reply to Ley Foon Tan

Add optimised library functions for nios2.

---
 arch/nios2/include/asm/checksum.h |  78 +++++++++++++++
 arch/nios2/include/asm/string.h   |  24 +++++
 arch/nios2/lib/memcpy.c           | 199 ++++++++++++++++++++++++++++++++++++++
 arch/nios2/lib/memmove.c          |  82 ++++++++++++++++
 arch/nios2/lib/memset.c           |  81 ++++++++++++++++
 5 files changed, 464 insertions(+)
 create mode 100644 arch/nios2/include/asm/checksum.h
 create mode 100644 arch/nios2/include/asm/string.h
 create mode 100644 arch/nios2/lib/memcpy.c
 create mode 100644 arch/nios2/lib/memmove.c
 create mode 100644 arch/nios2/lib/memset.c
arch/nios2/include/asm/checksum.h new file +78 -0
new file mode 100644
index 0000000..6bc1f0d
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS_CHECKSUM_H
+#define _ASM_NIOS_CHECKSUM_H
+
+/* Take these from lib/checksum.c */
+extern __wsum csum_partial(const void *buff, int len, __wsum sum);
+extern __wsum csum_partial_copy(const void *src, void *dst, int len,
+				__wsum sum);
+extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
+					int len, __wsum sum, int *csum_err);
+#define csum_partial_copy_nocheck(src, dst, len, sum)	\
+	csum_partial_copy((src), (dst), (len), (sum))
+
+extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
+extern __sum16 ip_compute_csum(const void *buff, int len);
+
+/*
+ * Fold a partial checksum
+ */
+static inline __sum16 csum_fold(__wsum sum)
+{
+	__asm__ __volatile__(
+		"add	%0, %1, %0\n"
+		"cmpltu	r8, %0, %1\n"
+		"srli	%0, %0, 16\n"
+		"add	%0, %0, r8\n"
+		"nor	%0, %0, %0\n"
+		: "=r" (sum)
+		: "r" (sum << 16), "0" (sum)
+		: "r8");
+	return (__force __sum16) sum;
+}
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+#define csum_tcpudp_nofold csum_tcpudp_nofold
+static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
+					unsigned short len,
+					unsigned short proto,
+					__wsum sum)
+{
+	__asm__ __volatile__(
+		"add	%0, %1, %0\n"
+		"cmpltu	r8, %0, %1\n"
+		"add	%0, %0, r8\n"	/* add carry */
+		"add	%0, %2, %0\n"
+		"cmpltu	r8, %0, %2\n"
+		"add	%0, %0, r8\n"	/* add carry */
+		"add	%0, %3, %0\n"
+		"cmpltu	r8, %0, %3\n"
+		"add	%0, %0, r8\n"	/* add carry */
+		: "=r" (sum), "=r" (saddr)
+		: "r" (daddr), "r" ((ntohs(len) << 16) + (proto * 256)),
+		  "0" (sum),
+		  "1" (saddr)
+		: "r8");
+
+	return sum;
+}
+
+static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
+					unsigned short len,
+					unsigned short proto, __wsum sum)
+{
+	return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
+}
+
+#endif /* _ASM_NIOS_CHECKSUM_H */
arch/nios2/include/asm/string.h new file +24 -0
new file mode 100644
index 0000000..14dd570
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_STRING_H
+#define _ASM_NIOS2_STRING_H
+
+#ifdef __KERNEL__
+
+#define __HAVE_ARCH_MEMSET
+#define __HAVE_ARCH_MEMCPY
+#define __HAVE_ARCH_MEMMOVE
+
+extern void *memset(void *s, int c, size_t count);
+extern void *memcpy(void *d, const void *s, size_t count);
+extern void *memmove(void *d, const void *s, size_t count);
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_NIOS2_STRING_H */
arch/nios2/lib/memcpy.c new file +199 -0

199 lines not on this page · raw message

arch/nios2/lib/memmove.c new file +82 -0

82 lines not on this page · raw message

arch/nios2/lib/memset.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#50 lore raw

PATCH v2 19/29 nios2: Time keeping

In reply to Ley Foon Tan

Add time keeping code for nios2.

---
 arch/nios2/include/asm/delay.h |  92 +++++++++++++++++++++++++
 arch/nios2/include/asm/timex.h |  27 ++++++++
 arch/nios2/kernel/time.c       | 150 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 269 insertions(+)
 create mode 100644 arch/nios2/include/asm/delay.h
 create mode 100644 arch/nios2/include/asm/timex.h
 create mode 100644 arch/nios2/kernel/time.c
arch/nios2/include/asm/delay.h new file +92 -0
new file mode 100644
index 0000000..8070a09
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_DELAY_H
+#define _ASM_NIOS2_DELAY_H
+
+#include <asm/param.h>
+
+static inline void __delay(unsigned long loops)
+{
+	int dummy;
+
+	__asm__ __volatile__(
+	"1:\n\t"
+	"    beq    %0,zero,2f\n\t"
+	"    addi   %0, %0, -1\n\t"
+	"    br     1b\n\t"
+	"2:\n\t"
+	:  "=r" (dummy)		/* Need output for optimizer */
+	:  "0" (loops));	/* %0  Input */
+}
+
+/*
+ * Note that 19 * 226 == 4294 ==~ 2^32 / 10^6, so
+ * loops = (4294 * usecs * loops_per_jiffy * HZ) / 2^32.
+ *
+ * The mul instruction gives us loops = (a * b) / 2^32.
+ * We choose a = usecs * 19 * HZ and b = loops_per_jiffy * 226
+ * because this lets us support a wide range of HZ and
+ * loops_per_jiffy values without either a or b overflowing 2^32.
+ * Thus we need usecs * HZ <= (2^32 - 1) / 19 = 226050910 and
+ * loops_per_jiffy <= (2^32 - 1) / 226 = 19004280
+ * (which corresponds to ~3800 bogomips at HZ = 100).
+ *  -- paulus
+ */
+#define __MAX_UDELAY	(226050910UL/HZ)	/* maximum udelay argument */
+#define __MAX_NDELAY	(4294967295UL/HZ)	/* maximum ndelay argument */
+
+extern unsigned long loops_per_jiffy;
+
+static inline void __udelay(unsigned int x)
+{
+	unsigned int loops;
+
+	/*
+	 * Note, if this is compiled with -mhw-mulx it will produce a "mulxuu"
+	 * (at least in toolchain 145) so there is no need for inline
+	 * assembly here anymore, which might in turn be emulated if unsupported
+	 * by the design.
+	 */
+	loops = (unsigned int)((((unsigned long long)(x) *
+			(unsigned long long)(loops_per_jiffy * 226))) >> 32);
+
+/*
+	__asm__("mulxuu %0,%1,%2" : "=r" (loops) :
+		"r" (x), "r" (loops_per_jiffy * 226));
+*/
+	__delay(loops);
+}
+
+static inline void __ndelay(unsigned int x)
+{
+	unsigned int loops;
+
+	/* see comment in __udelay */
+	loops = (unsigned int)((((unsigned long long)(x) *
+			(unsigned long long)(loops_per_jiffy * 5))) >> 32);
+
+/*
+	__asm__("mulxuu %0,%1,%2" : "=r" (loops) :
+		"r" (x), "r" (loops_per_jiffy * 5));
+*/
+	__delay(loops);
+}
+
+extern void __bad_udelay(void);		/* deliberately undefined */
+extern void __bad_ndelay(void);		/* deliberately undefined */
+
+#define udelay(n) (__builtin_constant_p(n) ? \
+	((n) > __MAX_UDELAY ? __bad_udelay() : __udelay((n) * (19 * HZ))) : \
+	__udelay((n) * (19 * HZ)))
+
+#define ndelay(n) (__builtin_constant_p(n) ? \
+	((n) > __MAX_NDELAY ? __bad_ndelay() : __ndelay((n) * HZ)) : \
+	__ndelay((n) * HZ))
+
+#endif /* _ASM_NIOS2_DELAY_H */
arch/nios2/include/asm/timex.h new file +27 -0
new file mode 100644
index 0000000..524b47d
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_TIMEX_H
+#define _ASM_NIOS2_TIMEX_H
+
+/* Supply dummy tick-rate. Real value will be read from devicetree */
+#define CLOCK_TICK_RATE		(HZ * 100000UL)
+
+#include <asm-generic/timex.h>
+
+#endif
arch/nios2/kernel/time.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#39 lore raw

PATCH v2 14/29 nios2: ELF definitions

In reply to Ley Foon Tan

This patch adds definitions for the ELF format

---
 arch/nios2/include/asm/elf.h      | 101 ++++++++++++++++++++++++++++++++++++++
 arch/nios2/include/uapi/asm/elf.h |  67 +++++++++++++++++++++++++
 2 files changed, 168 insertions(+)
 create mode 100644 arch/nios2/include/asm/elf.h
 create mode 100644 arch/nios2/include/uapi/asm/elf.h
arch/nios2/include/asm/elf.h new file +101 -0
new file mode 100644
index 0000000..b7d655d
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_ELF_H
+#define _ASM_NIOS2_ELF_H
+
+#include <uapi/asm/elf.h>
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ((x)->e_machine == EM_ALTERA_NIOS2)
+
+#define ELF_PLAT_INIT(_r, load_addr)
+
+#define CORE_DUMP_USE_REGSET
+#define ELF_EXEC_PAGESIZE	4096
+
+/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+   use of this is to invoke "./ld.so someprog" to test out a new version of
+   the loader.  We need to make sure that it is out of the way of the program
+   that it will "exec", and that there is sufficient room for the brk.  */
+
+#define ELF_ET_DYN_BASE		0xD0000000UL
+
+/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
+   now struct_user_regs, they are different) */
+
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES	1
+struct linux_binprm;
+extern int arch_setup_additional_pages(struct linux_binprm *bprm,
+	int uses_interp);
+#define ELF_CORE_COPY_REGS(pr_reg, regs)				\
+{ do {									\
+	/* Bleech. */							\
+	pr_reg[0]  = regs->r8;						\
+	pr_reg[1]  = regs->r9;						\
+	pr_reg[2]  = regs->r10;						\
+	pr_reg[3]  = regs->r11;						\
+	pr_reg[4]  = regs->r12;						\
+	pr_reg[5]  = regs->r13;						\
+	pr_reg[6]  = regs->r14;						\
+	pr_reg[7]  = regs->r15;						\
+	pr_reg[8]  = regs->r1;						\
+	pr_reg[9]  = regs->r2;						\
+	pr_reg[10] = regs->r3;						\
+	pr_reg[11] = regs->r4;						\
+	pr_reg[12] = regs->r5;						\
+	pr_reg[13] = regs->r6;						\
+	pr_reg[14] = regs->r7;						\
+	pr_reg[15] = regs->orig_r2;					\
+	pr_reg[16] = regs->ra;						\
+	pr_reg[17] = regs->fp;						\
+	pr_reg[18] = regs->sp;						\
+	pr_reg[19] = regs->gp;						\
+	pr_reg[20] = regs->estatus;					\
+	pr_reg[21] = regs->ea;						\
+	pr_reg[22] = regs->orig_r7;					\
+	{								\
+		struct switch_stack *sw = ((struct switch_stack *)regs) - 1; \
+		pr_reg[23] = sw->r16;					\
+		pr_reg[24] = sw->r17;					\
+		pr_reg[25] = sw->r18;					\
+		pr_reg[26] = sw->r19;					\
+		pr_reg[27] = sw->r20;					\
+		pr_reg[28] = sw->r21;					\
+		pr_reg[29] = sw->r22;					\
+		pr_reg[30] = sw->r23;					\
+		pr_reg[31] = sw->fp;					\
+		pr_reg[32] = sw->gp;					\
+		pr_reg[33] = sw->ra;					\
+	}								\
+} while (0); }
+
+/* This yields a mask that user programs can use to figure out what
+   instruction set this cpu supports.  */
+
+#define ELF_HWCAP	(0)
+
+/* This yields a string that ld.so will use to load implementation
+   specific libraries for optimization.  This is more specific in
+   intent than poking at uname or /proc/cpuinfo.  */
+
+#define ELF_PLATFORM  (NULL)
+
+#endif /* _ASM_NIOS2_ELF_H */
arch/nios2/include/uapi/asm/elf.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#32 lore raw

PATCH v2 13/29 nios2: DMA mapping API

In reply to Ley Foon Tan

This patch adds support for the DMA mapping API.

---
 arch/nios2/include/asm/dma-mapping.h | 106 ++++++++++++++++++++
 arch/nios2/mm/dma-mapping.c          | 186 +++++++++++++++++++++++++++++++++++
 2 files changed, 292 insertions(+)
 create mode 100644 arch/nios2/include/asm/dma-mapping.h
 create mode 100644 arch/nios2/mm/dma-mapping.c
arch/nios2/include/asm/dma-mapping.h new file +106 -0
new file mode 100644
index 0000000..2db7ac3
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ * Copyright (C) 2009 Wind River Systems Inc
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file COPYING in the main directory of this
+ * archive for more details.
+ */
+
+#ifndef _ASM_NIOS2_DMA_MAPPING_H
+#define _ASM_NIOS2_DMA_MAPPING_H
+
+#include <linux/scatterlist.h>
+#include <linux/cache.h>
+#include <asm/cacheflush.h>
+
+static inline void __dma_sync(void *vaddr, size_t size,
+			      enum dma_data_direction direction)
+{
+	switch (direction) {
+	case DMA_FROM_DEVICE:	/* invalidate cache */
+		invalidate_dcache_range((unsigned long)vaddr,
+			(unsigned long)(vaddr + size));
+		break;
+	case DMA_TO_DEVICE:	/* flush and invalidate cache */
+	case DMA_BIDIRECTIONAL:
+		flush_dcache_range((unsigned long)vaddr,
+			(unsigned long)(vaddr + size));
+		break;
+	default:
+		BUG();
+	}
+}
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+
+void *dma_alloc_coherent(struct device *dev, size_t size,
+			   dma_addr_t *dma_handle, gfp_t flag);
+
+void dma_free_coherent(struct device *dev, size_t size,
+			 void *vaddr, dma_addr_t dma_handle);
+
+static inline dma_addr_t dma_map_single(struct device *dev, void *ptr,
+					size_t size,
+					enum dma_data_direction direction)
+{
+	__dma_sync(ptr, size, direction);
+	return virt_to_phys(ptr);
+}
+
+static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
+				size_t size, enum dma_data_direction direction)
+{
+}
+
+extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+	enum dma_data_direction direction);
+extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
+	unsigned long offset, size_t size, enum dma_data_direction direction);
+extern void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
+	size_t size, enum dma_data_direction direction);
+extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
+	int nhwentries, enum dma_data_direction direction);
+extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+	size_t size, enum dma_data_direction direction);
+extern void dma_sync_single_for_device(struct device *dev,
+	dma_addr_t dma_handle, size_t size, enum dma_data_direction direction);
+extern void dma_sync_single_range_for_cpu(struct device *dev,
+	dma_addr_t dma_handle, unsigned long offset, size_t size,
+	enum dma_data_direction direction);
+extern void dma_sync_single_range_for_device(struct device *dev,
+	dma_addr_t dma_handle, unsigned long offset, size_t size,
+	enum dma_data_direction direction);
+extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
+	int nelems, enum dma_data_direction direction);
+extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
+	int nelems, enum dma_data_direction direction);
+
+static inline int dma_supported(struct device *dev, u64 mask)
+{
+	return 1;
+}
+
+static inline int dma_set_mask(struct device *dev, u64 mask)
+{
+	if (!dev->dma_mask || !dma_supported(dev, mask))
+		return -EIO;
+
+	*dev->dma_mask = mask;
+
+	return 0;
+}
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return 0;
+}
+
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
+				  enum dma_data_direction direction)
+{
+	__dma_sync(vaddr, size, direction);
+}
+
+#endif /* _ASM_NIOS2_DMA_MAPPING_H */
arch/nios2/mm/dma-mapping.c new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#40 lore raw

PATCH v2 15/29 nios2: System calls handling

In reply to Ley Foon Tan

This patch adds support for system calls from userspaces. It uses the asm-generic/unistd.h definitions with architecture spcific syscall. The sys_call_table is just an array defined in a C file and it contains pointers to the syscall functions.

---
 arch/nios2/include/asm/syscall.h     | 138 +++++++++++++++++++++++++++++++++++
 arch/nios2/include/asm/syscalls.h    |  25 +++++++
 arch/nios2/include/uapi/asm/unistd.h |  25 +++++++
 arch/nios2/kernel/sys_nios2.c        |  66 +++++++++++++++++
 arch/nios2/kernel/syscall_table.c    |  29 ++++++++
 5 files changed, 283 insertions(+)
 create mode 100644 arch/nios2/include/asm/syscall.h
 create mode 100644 arch/nios2/include/asm/syscalls.h
 create mode 100644 arch/nios2/include/uapi/asm/unistd.h
 create mode 100644 arch/nios2/kernel/sys_nios2.c
 create mode 100644 arch/nios2/kernel/syscall_table.c
arch/nios2/include/asm/syscall.h new file +138 -0
new file mode 100644
index 0000000..9de2208
@@ -0,0 +1,138 @@
+/*
+ * Copyright Altera Corporation (C) <2014>. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_NIOS2_SYSCALL_H__
+#define __ASM_NIOS2_SYSCALL_H__
+
+#include <linux/err.h>
+#include <linux/sched.h>
+
+static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+	return regs->r2;
+}
+
+static inline void syscall_rollback(struct task_struct *task,
+				struct pt_regs *regs)
+{
+	regs->r2 = regs->orig_r2;
+	regs->r7 = regs->orig_r7;
+}
+
+static inline long syscall_get_error(struct task_struct *task,
+				struct pt_regs *regs)
+{
+	return regs->r7 ? regs->r2 : 0;
+}
+
+static inline long syscall_get_return_value(struct task_struct *task,
+	struct pt_regs *regs)
+{
+	return regs->r2;
+}
+
+static inline void syscall_set_return_value(struct task_struct *task,
+	struct pt_regs *regs, int error, long val)
+{
+	if (error) {
+		/* error < 0, but nios2 uses > 0 return value */
+		regs->r2 = -error;
+		regs->r7 = 1;
+	} else {
+		regs->r2 = val;
+		regs->r7 = 0;
+	}
+}
+
+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);
+
+	switch (i) {
+	case 0:
+		if (!n--)
+			break;
+		*args++ = regs->r4;
+	case 1:
+		if (!n--)
+			break;
+		*args++ = regs->r5;
+	case 2:
+		if (!n--)
+			break;
+		*args++ = regs->r6;
+	case 3:
+		if (!n--)
+			break;
+		*args++ = regs->r7;
+	case 4:
+		if (!n--)
+			break;
+		*args++ = regs->r8;
+	case 5:
+		if (!n--)
+			break;
+		*args++ = regs->r9;
+	case 6:
+		if (!n--)
+			break;
+	default:
+		BUG();
+	}
+}
+
+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);
+
+	switch (i) {
+	case 0:
+		if (!n--)
+			break;
+		regs->r4 = *args++;
+	case 1:
+		if (!n--)
+			break;
+		regs->r5 = *args++;
+	case 2:
+		if (!n--)
+			break;
+		regs->r6 = *args++;
+	case 3:
+		if (!n--)
+			break;
+		regs->r7 = *args++;
+	case 4:
+		if (!n--)
+			break;
+		regs->r8 = *args++;
+	case 5:
+		if (!n--)
+			break;
+		regs->r9 = *args++;
+	case 6:
+		if (!n)
+			break;
+	default:
+		BUG();
+	}
+}
+
+#endif
arch/nios2/include/asm/syscalls.h new file +25 -0
new file mode 100644
index 0000000..0245d78
@@ -0,0 +1,25 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef __ASM_NIOS2_SYSCALLS_H
+#define __ASM_NIOS2_SYSCALLS_H
+
+int sys_cacheflush(unsigned long addr, unsigned long len,
+				unsigned int op);
+
+#include <asm-generic/syscalls.h>
+
+#endif /* __ASM_NIOS2_SYSCALLS_H */
arch/nios2/include/uapi/asm/unistd.h new file +25 -0
new file mode 100644
index 0000000..c4bf795
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+ #define sys_mmap2 sys_mmap_pgoff
+
+/* Use the standard ABI for syscalls */
+#include <asm-generic/unistd.h>
+
+/* Additional Nios II specific syscalls. */
+#define __NR_cacheflush (__NR_arch_specific_syscall)
+__SYSCALL(__NR_cacheflush, sys_cacheflush)
arch/nios2/kernel/sys_nios2.c new file +66 -0

66 lines not on this page · raw message

arch/nios2/kernel/syscall_table.c new file +29 -0
new file mode 100644
index 0000000..06e6ac1
@@ -0,0 +1,29 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <linux/syscalls.h>
+#include <linux/signal.h>
+#include <linux/unistd.h>
+
+#include <asm/syscalls.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call) [nr] = (call),
+
+void *sys_call_table[__NR_syscalls] = {
+#include <asm/unistd.h>
+};
Signature · 1 line
1.8.2.1
#89 lore raw

PATCH v2 26/29 Add ELF machine define for Nios2

In reply to Ley Foon Tan
---
 include/uapi/linux/elf-em.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/elf-em.h +1 -0
index 01529bd..7f06c0d 100644
@@ -33,6 +33,7 @@
 #define EM_M32R		88	/* Renesas M32R */
 #define EM_MN10300	89	/* Panasonic/MEI MN10300, AM33 */
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
+#define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
 #define EM_AARCH64	183	/* ARM 64 bit */
 #define EM_FRV		0x5441	/* Fujitsu FR-V */
Signature · 1 line
1.8.2.1
#90 lore raw

Re: [PATCH v2 26/29] Add ELF machine define for Nios2

Quoted 1 line · Ley Foon Tan

This should probably be sent/applied before "[PATCH v2 14/29] nios2: ELF definitions", since there EM_ALTERA_NIOS2 is already used.

Quoted 24 lines
---
 include/uapi/linux/elf-em.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/elf-em.h +1 -0
index 01529bd..7f06c0d 100644
@@ -33,6 +33,7 @@
 #define EM_M32R		88	/* Renesas M32R */
 #define EM_MN10300	89	/* Panasonic/MEI MN10300, AM33 */
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
+#define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
 #define EM_TI_C6000	140	/* TI C6X DSPs */
 #define EM_AARCH64	183	/* ARM 64 bit */
 #define EM_FRV		0x5441	/* Fujitsu FR-V */
Signature · 6 lines
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#99 lore raw
In reply to Ley Foon Tan
Quoted 10 lines · Ley Foon Tan

This is the 2nd version of patchset adds the Linux kernel port for Nios II processor from Altera. All of the feedback from v1 patchseries has been addressed. Thanks to all who provided feedback on the previous version.

About Nios II Cores
-------------------
Nios II is a 32-bit embedded-processor architecture designed specifically for the Altera family of FPGAs.
More information is available at http://www.altera.com/devices/processor/nios2/ni2-index.html

Quoted 8 lines

Instruction set and architecture overview documents can be found on the following page:
http://www.altera.com/literature/lit-nio2.jsp

Nios2 GCC port is in mainline and will be in the FSF 4.9 release.

The patchset are based on v3.16-rc5 and can also be found in the following git tree:
git://git.rocketboards.org/linux-socfpga-next.git nios2-upstream

Very nice work Ley Foon! It's great to see the Nios II port finally making it upstream.

I'll test the series on the NEEK and my custom board some time this week.

Cheers
Tobias

maintainer
#16 lore raw

Re: [PATCH v2 06/29] nios2: I/O Mapping

In reply to Ley Foon Tan

arch/nios2/include/asm/io.h line 27

Quoted 5 lines · On Tuesday 15 July 2014 16:45:33 Ley Foon Tan wrote:
arch/nios2/include/asm/io.h new file +5 -0
+#ifdef __IO_USE_DUFFS
+
+/* Use "Duff's Device" to unroll the loops. */
+#define __IO_OUT_LOOP(a, b, l)				\
+	do {						\

The I/O loops can probably better go into the C file that uses them.

arch/nios2/include/asm/io.h line 129

Quoted 11 lines
arch/nios2/include/asm/io.h new file +11 -0
+
+/*
+ * PCI is not enabled in nios2. Provide dummy implementation to get 'allyesconfig'
+ * to build successfully.
+ */
+#define inb(addr)	0
+#define inw(addr)	0
+#define inl(addr)	0
+#define outb(x, addr)
+#define outw(x, addr)
+#define outl(x, addr)

These should either use inline functions or macros that behave like them, to avoid miscompilation. The normal way to define those macros is

#define inb(a) ({ 0; })
#define outb(x, a) do { } while (0)

arch/nios2/include/asm/io.h line 150

Quoted 5 lines
arch/nios2/include/asm/io.h new file +5 -0
+static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
+						unsigned long size)
+{
+	return __ioremap(physaddr, size, 0);
+}

ioremap_writethrough() is not a standard interface, just drop it.

arch/nios2/include/asm/io.h line 156

Quoted 5 lines
arch/nios2/include/asm/io.h new file +5 -0
+static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
+						unsigned long size)
+{
+	return __ioremap(physaddr, size, _PAGE_CACHED);
+}

This is more commonly called ioremap_cache().

ioremap_fullcache() is defined on some architectures but never used. If you don't use this in your own code, you can drop it as well.

Arnd

maintainer
#24 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Ley Foon Tan

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · On Tuesday 15 July 2014 16:45:39 Ley Foon Tan wrote:
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS	32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS			(NIOS2_CPU_NR_IRQS + 32)

Is this intentional? I would expect that you use SPARSE_IRQ instead and not define NR_IRQS.

arch/nios2/include/asm/irq.h line 29

Quoted 3 lines
arch/nios2/include/asm/irq.h new file +3 -0
+#ifndef NO_IRQ
+#define NO_IRQ			(-1)
+#endif

New architectures should no longer define NO_IRQ. Please fix all users you encounter instead.

arch/nios2/kernel/irq.c line 27

Quoted 8 lines
arch/nios2/kernel/irq.c new file +3 -0
new file mode 100644
index 0000000..8770d50
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>

Maybe move this into drivers/irqchip/? Probably doesn't matter either way, your choice.

Arnd

#100 lore raw
In reply to Tobias Klauser
Quoted 9 lines · Tobias Klauser

On 2014-07-15 at 10:45:27 +0200, Ley Foon Tan <[email protected]> wrote:

Very nice work Ley Foon! It's great to see the Nios II port finally making it upstream.

I'll test the series on the NEEK and my custom board some time this week.

Hi Tobias

FYI, you need new compiler that support generic ABI syscall. But, this new compiler is not public available yet.
Will let you know once it is available.

Ley Foon

maintainer
#33 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

In reply to Ley Foon Tan
Quoted 7 lines · On Tuesday 15 July 2014 16:45:40 Ley Foon Tan wrote:
arch/nios2/include/asm/dma-mapping.h new file +7 -0
+static inline void __dma_sync(void *vaddr, size_t size,
+			      enum dma_data_direction direction)
+{
+	switch (direction) {
+	case DMA_FROM_DEVICE:	/* invalidate cache */
+		invalidate_dcache_range((unsigned long)vaddr,
+			(unsigned long)(vaddr + size));

arch/nios2/include/asm/dma-mapping.h line 33

Quoted 10 lines
arch/nios2/include/asm/dma-mapping.h new file +10 -0
+		break;
+	case DMA_TO_DEVICE:	/* flush and invalidate cache */
+	case DMA_BIDIRECTIONAL:
+		flush_dcache_range((unsigned long)vaddr,
+			(unsigned long)(vaddr + size));
+		break;
+	default:
+		BUG();
+	}
+}

This seems strange. More on that below.

Quoted 3 lines
arch/nios2/include/asm/dma-mapping.h new file +3 -0
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+

...

arch/nios2/include/asm/dma-mapping.h line 104

Quoted 5 lines
arch/nios2/include/asm/dma-mapping.h new file +5 -0
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
+				  enum dma_data_direction direction)
+{
+	__dma_sync(vaddr, size, direction);
+}

IIRC dma_cache_sync should be empty if you define dma_alloc_noncoherent to be the same as dma_alloc_coherent: It's already coherent, so no sync should be needed. What does the CPU do if you try to invalidate the cache on a coherent mapping?

Quoted 7 lines
arch/nios2/mm/dma-mapping.c new file +7 -0
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+			     size_t size, enum dma_data_direction direction)
+{
+	BUG_ON(!valid_dma_direction(direction));
+
+	__dma_sync(phys_to_virt(dma_handle), size, direction);
+}

arch/nios2/mm/dma-mapping.c line 139

Quoted 10 lines
arch/nios2/mm/dma-mapping.c new file +10 -0
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+				size_t size, enum dma_data_direction direction)
+{
+	BUG_ON(!valid_dma_direction(direction));
+
+	__dma_sync(phys_to_virt(dma_handle), size, direction);
+}
+EXPORT_SYMBOL(dma_sync_single_for_device);

More importantly: you do the same operation for both _for_cpu and _for_device. I assume your CPU can never do speculative cache prefetches, so it's not incorrect, but you do twice the number of invalidations and flushes that you need.

Why would you do anything for _for_cpu here?

Arnd

#91 lore raw

Re: [PATCH v2 26/29] Add ELF machine define for Nios2

In reply to Tobias Klauser
Quoted 7 lines · Tobias Klauser
Quoted 1 line · Ley Foon Tan

This should probably be sent/applied before "[PATCH v2 14/29] nios2: ELF definitions", since there EM_ALTERA_NIOS2 is already used.

Yes, make sense.
Will move this patch before it is used.

maintainer
#48 lore raw

Re: [PATCH v2 18/29] nios2: Device tree support

In reply to Ley Foon Tan

arch/nios2/platform/platform.c line 24

Quoted 5 lines · On Tuesday 15 July 2014 16:45:45 Ley Foon Tan wrote:
arch/nios2/platform/platform.c new file +5 -0
+static struct of_device_id altera_of_bus_ids[] __initdata = {
+       { .compatible = "simple-bus", },
+       { .compatible = "altr,avalon", },
+       {}
+};

Can you change the avalon bus nodes to be compatible to with "simple-bus" as well, so you can use the default id list?

Quoted 17 lines
arch/nios2/platform/platform.c new file +16 -0
+static int __init nios2_soc_device_init(void)
+{
+       struct soc_device *soc_dev;
+       struct soc_device_attribute *soc_dev_attr;
+       const char *machine;
+
+       soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+       if (soc_dev_attr) {
+               machine = of_flat_dt_get_machine_name();
+               if (machine)
+                       soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
+                                               machine);
+
+               soc_dev_attr->family = "Nios II";
+
+               soc_dev = soc_device_register(soc_dev_attr);

arch/nios2/platform/platform.c line 51

Quoted 10 lines
arch/nios2/platform/platform.c new file +10 -0
+               if (IS_ERR(soc_dev)) {
+                       kfree(soc_dev_attr->machine);
+                       kfree(soc_dev_attr);
+               }
+       }
+
+       return of_platform_bus_probe(NULL, altera_of_bus_ids, NULL);
+}
+
+device_initcall(nios2_soc_device_init);

I think you should use of_platform_populate instead of of_platform_bus_probe here.

ARnd

maintainer
#51 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Ley Foon Tan
Quoted 4 lines · On Tuesday 15 July 2014 16:45:46 Ley Foon Tan wrote:
arch/nios2/include/asm/delay.h new file +4 -0
+
+static inline void __delay(unsigned long loops)
+{
+	int dummy;

arch/nios2/include/asm/delay.h line 26

Quoted 10 lines
arch/nios2/include/asm/delay.h new file +10 -0
+
+	__asm__ __volatile__(
+	"1:\n\t"
+	"    beq    %0,zero,2f\n\t"
+	"    addi   %0, %0, -1\n\t"
+	"    br     1b\n\t"
+	"2:\n\t"
+	:  "=r" (dummy)		/* Need output for optimizer */
+	:  "0" (loops));	/* %0  Input */
+}

Do you have a reliable clock source? If you do, it would be better to replace the delay loop with an implementation that waits for the exact time to pass instead. This will also avoid the loop calibration during boot and give you better boot times.

arch/nios2/include/asm/timex.h line 27

Quoted 9 lines
arch/nios2/include/asm/timex.h new file +9 -0
+#ifndef _ASM_NIOS2_TIMEX_H
+#define _ASM_NIOS2_TIMEX_H
+
+/* Supply dummy tick-rate. Real value will be read from devicetree */
+#define CLOCK_TICK_RATE		(HZ * 100000UL)
+
+#include <asm-generic/timex.h>
+
+#endif

CLOCK_TICK_RATE is no longer used anywhere, no need for this file.

arch/nios2/kernel/time.c

Quoted 5 lines
arch/nios2/kernel/time.c new file +0 -0
new file mode 100644
index 0000000..111ade1

Maybe move this to drivers/clocksource? Same argument as for the irqchip driver, so either move both or neither.

Arnd

maintainer
#59 lore raw

Re: [PATCH v2 20/29] nios2: Cpuinfo handling

In reply to Ley Foon Tan

arch/nios2/kernel/cpuinfo.c line 188

Quoted 12 lines · On Tuesday 15 July 2014 16:45:47 Ley Foon Tan wrote:
arch/nios2/kernel/cpuinfo.c new file +12 -0
+static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
+{
+       unsigned long i = *pos;
+
+       return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
+}
+
+static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return cpuinfo_start(m, pos);
+}

Do you actually have SMP support?

arch/nios2/kernel/cpuinfo.c line 199

Quoted 6 lines
arch/nios2/kernel/cpuinfo.c new file +6 -0
+const struct seq_operations cpuinfo_op = {
+       .start  = cpuinfo_start,
+       .next   = cpuinfo_next,
+       .stop   = cpuinfo_stop,
+       .show   = show_cpuinfo
+};

If not, you can use single_start/next/stop here rather than defining your own.

Arnd

#28 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Ley Foon Tan

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · Ley Foon Tan
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS	32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS			(NIOS2_CPU_NR_IRQS + 32)

Please use sparse irqs. Hardcoded limits tend to work out really bad.

Quoted 13 lines
arch/nios2/kernel/irq.c new file +13 -0
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>
+
+asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
+{
+	struct pt_regs *oldregs = set_irq_regs(regs);
+	int irq;
+
+	irq_enter();
+	irq = irq_find_mapping(NULL, hwirq);
+	generic_handle_irq(irq);
+	irq_exit();

arch/nios2/kernel/irq.c line 47

Quoted 10 lines
arch/nios2/kernel/irq.c new file +10 -0
+
+	set_irq_regs(oldregs);
+}
+
+static void chip_unmask(struct irq_data *d)
+{
+	u32 ien;
+	ien = RDCTL(CTL_IENABLE);
+	ien |= (1 << d->hwirq);
+	WRCTL(CTL_IENABLE, ien);

So this is UP only, right?

Also why don't you cache the register content so spare the extra read from the hardware?

Thanks,

tglx

#55 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Ley Foon Tan
Quoted 42 lines · Ley Foon Tan
arch/nios2/kernel/time.c new file +39 -0
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/time.h>
+#include <linux/timex.h>
+#include <linux/profile.h>
+#include <linux/clocksource.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/io.h>
+
+#define	TICK_SIZE		(tick_nsec / 1000)
+#define NIOS2_TIMER_PERIOD	(timer_freq / HZ)
+
+#define ALTERA_TIMER_STATUS_REG		0
+#define ALTERA_TIMER_CONTROL_REG	4
+#define ALTERA_TIMER_PERIODL_REG	8
+#define ALTERA_TIMER_PERIODH_REG	12
+#define ALTERA_TIMER_SNAPL_REG		16
+#define ALTERA_TIMER_SNAPH_REG		20
+
+#define ALTERA_TIMER_CONTROL_ITO_MSK	(0x1)
+#define ALTERA_TIMER_CONTROL_CONT_MSK	(0x2)
+#define ALTERA_TIMER_CONTROL_START_MSK	(0x4)
+#define ALTERA_TIMER_CONTROL_STOP_MSK	(0x8)
+
+static u32 nios2_timer_count;
+static void __iomem *timer_membase;

arch/nios2/kernel/time.c line 49

Quoted 10 lines
arch/nios2/kernel/time.c new file +10 -0
+static u32 timer_freq;
+
+static inline unsigned long read_timersnapshot(void)
+{
+	unsigned long count;
+
+	writew(0, timer_membase + ALTERA_TIMER_SNAPL_REG);
+	count =
+		readw(timer_membase + ALTERA_TIMER_SNAPH_REG) << 16 |
+		readw(timer_membase + ALTERA_TIMER_SNAPL_REG);

So you're serious about having a new architecture with a timer implementation which cant read 32bit in one go? I'm impressed ...

Quoted 16 lines
arch/nios2/kernel/time.c new file +16 -0
+	return count;
+}
+
+static inline void write_timerperiod(unsigned long period)
+{
+	writew(period, timer_membase + ALTERA_TIMER_PERIODL_REG);
+	writew(period >> 16, timer_membase + ALTERA_TIMER_PERIODH_REG);
+}
+
+/*
+ * timer_interrupt() needs to keep up the real-time clock,
+ * as well as call the "xtime_update()" routine every clocktick
+ */
+irqreturn_t timer_interrupt(int irq, void *dummy)
+{
+	/* Clear the interrupt condition */

arch/nios2/kernel/time.c line 76

Quoted 10 lines
arch/nios2/kernel/time.c new file +10 -0
+	writew(0, timer_membase + ALTERA_TIMER_STATUS_REG);
+	nios2_timer_count += NIOS2_TIMER_PERIOD;
+
+	profile_tick(CPU_PROFILING);
+
+	xtime_update(1);
+
+	update_process_times(user_mode(get_irq_regs()));
+
+	return IRQ_HANDLED;

Please use the clock events infrastructure. New users of the old style timer management are not welcome.

arch/nios2/kernel/time.c line 87

Quoted 11 lines
arch/nios2/kernel/time.c new file +11 -0
+}
+
+static cycle_t nios2_timer_read(struct clocksource *cs)
+{
+	unsigned long flags;
+	u32 cycles;
+	u32 tcn;
+
+	local_irq_save(flags);
+	tcn = NIOS2_TIMER_PERIOD - 1 - read_timersnapshot();
+	cycles = nios2_timer_count;

This is wrong and completely pointless. The core code takes care about the offset.

arch/nios2/kernel/time.c line 91

Quoted 4 lines
arch/nios2/kernel/time.c new file +4 -0
+	local_irq_restore(flags);
+
+	return cycles + tcn;
+}

Thanks,

tglx

#49 lore raw

Re: [PATCH v2 18/29] nios2: Device tree support

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

arch/nios2/platform/platform.c line 24

Quoted 5 lines · On Tuesday 15 July 2014 16:45:45 Ley Foon Tan wrote:
arch/nios2/platform/platform.c new file +5 -0
+static struct of_device_id altera_of_bus_ids[] __initdata = {
+       { .compatible = "simple-bus", },
+       { .compatible = "altr,avalon", },
+       {}
+};

Can you change the avalon bus nodes to be compatible to with "simple-bus" as well, so you can use the default id list?

Yes, it is compatible with both "altr,avalon" and "simple-bus". We can change it to default id list.

compatible = "altr,avalon", "simple-bus";

Quoted 22 lines
Quoted 22 lines
arch/nios2/platform/platform.c new file +21 -0
+static int __init nios2_soc_device_init(void)
+{
+       struct soc_device *soc_dev;
+       struct soc_device_attribute *soc_dev_attr;
+       const char *machine;
+
+       soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+       if (soc_dev_attr) {
+               machine = of_flat_dt_get_machine_name();
+               if (machine)
+                       soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
+                                               machine);
+
+               soc_dev_attr->family = "Nios II";
+
+               soc_dev = soc_device_register(soc_dev_attr);
+               if (IS_ERR(soc_dev)) {
+                       kfree(soc_dev_attr->machine);
+                       kfree(soc_dev_attr);
+               }
+       }
Quoted 8 lines

arch/nios2/platform/platform.c line 51

Quoted 6 lines
arch/nios2/platform/platform.c new file +5 -0
+
+       return of_platform_bus_probe(NULL, altera_of_bus_ids, NULL);
+}
+
+device_initcall(nios2_soc_device_init);

I think you should use of_platform_populate instead of of_platform_bus_probe here.

Okay, will change to of_platform_populate().

Regards
Ley Foon

#63 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Ley Foon Tan

On Tue, 15 Jul 2014, Ley Foon Tan wrote:
+static inline int atomic_futex_op_xchg_set(int oparg, u32 __user *uaddr,

arch/nios2/include/asm/futex-irq.h line 35

Quoted 10 lines
arch/nios2/include/asm/futex-irq.h new file +10 -0
+					   int *oldval)
+{
+	unsigned long flags;
+	int ret;
+
+	local_irq_save(flags);
+
+	ret = get_user(*oldval, uaddr);
+	if (!ret)
+		ret = put_user(oparg, uaddr);

This is wrong as it gets. get_user() might fault and sleep.

You need a proper implementation, which handles fault exceptions.

Thanks,

tglx

maintainer
#75 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Ley Foon Tan
Quoted 19 lines · On Tuesday 15 July 2014 16:45:49 Ley Foon Tan wrote:
arch/nios2/include/asm/gpio.h new file +13 -0
new file mode 100644
index 0000000..e726bfc
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with

arch/nios2/include/asm/gpio.h line 23

Quoted 10 lines
arch/nios2/include/asm/gpio.h new file +10 -0
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _ASM_NIOS2_GPIO_H
+#define _ASM_NIOS2_GPIO_H
+
+#include <linux/gpio.h>
+
+#endif /* _ASM_NIOS2_GPIO_H */

This seems wrong. If any device drivers rely on this, better fix them to use linux/gpio.h directly.

Quoted 21 lines
arch/nios2/include/asm/pci.h new file +15 -0
new file mode 100644
index 0000000..69c86fa
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.

arch/nios2/include/asm/pci.h line 25

Quoted 10 lines
arch/nios2/include/asm/pci.h new file +10 -0
+ *
+ */
+
+
+#ifndef __ASM_NIOS2_PCI_H__
+#define __ASM_NIOS2_PCI_H__
+
+/* We don't support PCI yet, but some drivers require this file anyway */
+
+#endif /* __ASM_NIOS2_PCI_H__ */

What's wrong with the generic version?

arch/nios2/include/asm/pci.h

Quoted 6 lines
arch/nios2/include/asm/pci.h new file +6 -0
+#ifndef _UAPI_ASM_NIOS2_STAT_H
+#define _UAPI_ASM_NIOS2_STAT_H
+
+#include <asm-generic/stat.h>
+
+#endif

This should just use the Kconfig logic to fall back on the generic file.

arch/nios2/include/asm/pci.h

Quoted 5 lines
arch/nios2/include/asm/pci.h new file +5 -0
+
+#ifndef _UAPI_ASM_NIOS2_STATFS_H
+#define _UAPI_ASM_NIOS2_STATFS_H
+
+#define __statfs_word __s32

Why this? Every other architecture except parisc uses the default __u32 here.

arch/nios2/include/asm/pci.h

Quoted 13 lines
arch/nios2/include/asm/pci.h new file +13 -0
+#include <linux/types.h>
+#include <asm-generic/swab.h>
+
+#ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
+#ifdef __GNUC__
+
+#define __nios2_swab(x)		\
+	__builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
+
+static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
+{
+	return (__u16) __nios2_swab(((__u32) x) << 16);
+}

Is this actually better than ___constant_swab16()?

Also, have you checked if you need to support old compiler versions that don't have __builtin_bswap16/32/64? With newer compilers you don't need to define any of these yourself.

Arnd

maintainer
#83 lore raw

Re: [PATCH v2 24/29] nios2: Module support

In reply to Ley Foon Tan

arch/nios2/kernel/module.c line 36

Quoted 12 lines · On Tuesday 15 July 2014 16:45:51 Ley Foon Tan wrote:
arch/nios2/kernel/module.c new file +12 -0
+void *module_alloc(unsigned long size)
+{
+	if (size == 0)
+		return NULL;
+	return kmalloc(size, GFP_KERNEL);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+	kfree(module_region);
+}

Any particular reason for defining these to use kmalloc rather than the default vmalloc based functions?

Note that kmalloc is more limited in size and won't work if the memory is fragmented, while vmalloc has a small overhead on some architectures due to TLB pressure, but only if the normal kernel memory is able to use huge pages.

arch/nios2/kernel/module.c line 135

Quoted 3 lines
arch/nios2/kernel/module.c new file +3 -0
+void module_arch_cleanup(struct module *mod)
+{
+}

This is not needed at all.

Arnd

#17 lore raw

Re: [PATCH v2 06/29] nios2: I/O Mapping

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

arch/nios2/include/asm/io.h line 27

Quoted 5 lines · On Tuesday 15 July 2014 16:45:33 Ley Foon Tan wrote:
arch/nios2/include/asm/io.h new file +5 -0
+#ifdef __IO_USE_DUFFS
+
+/* Use "Duff's Device" to unroll the loops. */
+#define __IO_OUT_LOOP(a, b, l)                               \
+     do {                                            \

The I/O loops can probably better go into the C file that uses them.

Okay.

Quoted 6 lines

These should either use inline functions or macros that behave like them, to avoid miscompilation. The normal way to define those macros is

#define inb(a) ({ 0; })
#define outb(x, a) do { } while (0)

Okay, will update these.

Quoted 8 lines

arch/nios2/include/asm/io.h line 150

Quoted 6 lines
arch/nios2/include/asm/io.h new file +5 -0
+static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
+                                             unsigned long size)
+{
+     return __ioremap(physaddr, size, 0);
+}

ioremap_writethrough() is not a standard interface, just drop it.

Okay, will drop this.

Quoted 11 lines

arch/nios2/include/asm/io.h line 156

Quoted 6 lines
arch/nios2/include/asm/io.h new file +5 -0
+static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
+                                             unsigned long size)
+{
+     return __ioremap(physaddr, size, _PAGE_CACHED);
+}

This is more commonly called ioremap_cache().

ioremap_fullcache() is defined on some architectures but never used. If you don't use this in your own code, you can drop it as well.

We are not using ioremap_fullcache(), will drop it.

Thanks.

Regards
Ley Foon

#76 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines

+

arch/nios2/include/uapi/asm/statfs.h line 21

Quoted 4 lines
arch/nios2/include/uapi/asm/statfs.h new file +4 -0
+#ifndef _UAPI_ASM_NIOS2_STATFS_H
+#define _UAPI_ASM_NIOS2_STATFS_H
+
+#define __statfs_word __s32

Why this? Every other architecture except parisc uses the default __u32 here.

Because include/uapi/asm/statfs.h has this:

#ifndef __statfs_word
#if __BITS_PER_LONG == 64
#define __statfs_word __kernel_long_t
#else
#define __statfs_word __u32
#endif
#endif
...

struct statfs64 {
        __statfs_word f_type;
        __statfs_word f_bsize;
        __u64 f_blocks;
        __u64 f_bfree;

...

While the bits/statfs.h header in glibc has this:
struct statfs

  {
    __SWORD_TYPE f_type;
    __SWORD_TYPE f_bsize;
    __field64(__fsblkcnt_t, __fsblkcnt64_t, f_blocks);
...
struct statfs64
  {
    __SWORD_TYPE f_type;
    __SWORD_TYPE f_bsize;
    __fsblkcnt64_t f_blocks;

...

Where __SWORD_TYPE is always a signed integer (int or long int depending on 32/64-bit word size). Hence we define the kernel __statfs_word to be signed 32-bit to match.

Supposedly, tilepro should have a similar issue too, though I guess this is quite obscure in practice. We so far haven't encountered any issues on nios2 without this __s32 override either, it's just by observation.

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
arch/nios2/include/uapi/asm/swab.h new file +5 -0
+#include <linux/types.h>
+#include <asm-generic/swab.h>
+
+#ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
+#ifdef __GNUC__
Quoted 8 lines

arch/nios2/include/uapi/asm/swab.h line 25

Quoted 8 lines
arch/nios2/include/uapi/asm/swab.h new file +8 -0
+
+#define __nios2_swab(x)		\
+	__builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
+
+static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
+{
+	return (__u16) __nios2_swab(((__u32) x) << 16);
+}

Is this actually better than ___constant_swab16()?

Quoted 5 lines

Also, have you checked if you need to support old compiler versions that don't have __builtin_bswap16/32/64? With newer compilers you don't need to define any of these yourself.

Arnd

This swap is configured/implemented using Nios II's custom instruction facility; it is not part of the compiler supported Nios II core instruction set. In fact, even the exact opcode allocated is not fixed.

So the custom swap will not be in a form usable by the compiler, and hence no use of it during code generation (if it is, you might not even need to use __builtin_swap*(), there's a optimization pass that recognizes the shift+or-ing C code patterns)

Thanks,
Chung-Lin

#93 lore raw

Re: [PATCH v2 27/29] MAINTAINERS: Add nios2 maintainer

In reply to Ley Foon Tan
Quoted 1 line · Ley Foon Tan

trivia:

MAINTAINERS

Quoted 1 line
MAINTAINERS +0 -0

[]

MAINTAINERS S: Maintained

Quoted 1 line
MAINTAINERS +0 -0
@@ -6350,6 +6350,13 @@ S:	Maintained

[]

MAINTAINERS S: Maintained · line 6356

Quoted 4 lines
MAINTAINERS +4 -0
+NIOS2 ARCHITECTURE
+M:	Ley Foon Tan <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+T:	git://git.rocketboards.org/linux-socfpga.git

this should be:
T: git git://git.rocketboards.org/linux-socfpga.git

#84 lore raw

Re: [PATCH v2 24/29] nios2: Module support

In reply to Arnd Bergmann
Quoted 16 lines · Arnd Bergmann

arch/nios2/kernel/module.c line 36

Quoted 12 lines · On Tuesday 15 July 2014 16:45:51 Ley Foon Tan wrote:
arch/nios2/kernel/module.c new file +12 -0
+void *module_alloc(unsigned long size)
+{
+	if (size == 0)
+		return NULL;
+	return kmalloc(size, GFP_KERNEL);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+	kfree(module_region);
+}

Any particular reason for defining these to use kmalloc rather than the default vmalloc based functions?

AFAIR this is due to relocation issues, as the FIXME comment in the "original" code [1] states. I don't know whether this still applies, though (or what would be the proper fix for this to overcome the relocation issues).

[1] https://github.com/tklauser/linux-nios2/blob/nios2/arch/nios2/kernel/module.c#L45

Cheers
Tobias

#101 lore raw
In reply to Ley Foon Tan

Hi Ley Foon

Quoted 8 lines · Ley Foon Tan
Quoted 7 lines · Tobias Klauser

On 2014-07-15 at 10:45:27 +0200, Ley Foon Tan <[email protected]> wrote:

Very nice work Ley Foon! It's great to see the Nios II port finally making it upstream.

Quoted 6 lines
Quoted 2 lines

I'll test the series on the NEEK and my custom board some time this week.

FYI, you need new compiler that support generic ABI syscall. But, this new compiler is not public available yet.
Will let you know once it is available.

Ah, thanks for the notice. Is it still possible to use the old syscall ABI as a replacement on top of this series and use the current toolchain from Mentor Graphics?

Thanks
Tobias

maintainer
#85 lore raw

Re: [PATCH v2 24/29] nios2: Module support

In reply to Tobias Klauser
Quoted 18 lines · On Tuesday 15 July 2014 13:12:37 Tobias Klauser wrote:
Quoted 16 lines · Arnd Bergmann

arch/nios2/kernel/module.c line 36

Quoted 12 lines · On Tuesday 15 July 2014 16:45:51 Ley Foon Tan wrote:
arch/nios2/kernel/module.c new file +12 -0
+void *module_alloc(unsigned long size)
+{
+   if (size == 0)
+           return NULL;
+   return kmalloc(size, GFP_KERNEL);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+   kfree(module_region);
+}

Any particular reason for defining these to use kmalloc rather than the default vmalloc based functions?

Quoted 7 lines

AFAIR this is due to relocation issues, as the FIXME comment in the "original" code [1] states. I don't know whether this still applies, though (or what would be the proper fix for this to overcome the relocation issues).

[1] https://github.com/tklauser/linux-nios2/blob/nios2/arch/nios2/kernel/module.c#L45

Ah, I see. Please at least copy over that comment then.

A long-term solution would be to copy what ARM does, since that has the same problem. The modules are allocated with __vmalloc_node_range, passing a virtual address range that is just before the kernel virtual address, taken out of the top 16MB of the user space addresses.

Arnd

maintainer
#77 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Chung-Lin Tang
Quoted 39 lines · On Tuesday 15 July 2014 19:03:35 Chung-Lin Tang wrote:
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines

+

arch/nios2/include/uapi/asm/statfs.h line 21

Quoted 4 lines
arch/nios2/include/uapi/asm/statfs.h new file +4 -0
+#ifndef _UAPI_ASM_NIOS2_STATFS_H
+#define _UAPI_ASM_NIOS2_STATFS_H
+
+#define __statfs_word __s32

Why this? Every other architecture except parisc uses the default __u32 here.

Because include/uapi/asm/statfs.h has this:

#ifndef __statfs_word
#if __BITS_PER_LONG == 64
#define __statfs_word __kernel_long_t
#else
#define __statfs_word __u32
#endif
#endif
...

struct statfs64 {
        __statfs_word f_type;
        __statfs_word f_bsize;
        __u64 f_blocks;
        __u64 f_bfree;

...

While the bits/statfs.h header in glibc has this:
struct statfs

  {
    __SWORD_TYPE f_type;
    __SWORD_TYPE f_bsize;
    __field64(__fsblkcnt_t, __fsblkcnt64_t, f_blocks);
...
struct statfs64
  {
    __SWORD_TYPE f_type;
    __SWORD_TYPE f_bsize;
    __fsblkcnt64_t f_blocks;

...

Quoted 7 lines

Where __SWORD_TYPE is always a signed integer (int or long int depending on 32/64-bit word size). Hence we define the kernel __statfs_word to be signed 32-bit to match.

Supposedly, tilepro should have a similar issue too, though I guess this is quite obscure in practice. We so far haven't encountered any issues on nios2 without this __s32 override either, it's just by observation.

I think you should just do what x86 (and presumably most other architectures) has, that also uses a signed type in user space and unsigned in kernel space.

It's not really clean, but it doesn't seem to cause problems elsewhere, and in cases like this you're normally better off copying the mistakes that everybody else made than doing something unusual.

Quoted 19 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
arch/nios2/include/uapi/asm/swab.h new file +5 -0
+#include <linux/types.h>
+#include <asm-generic/swab.h>
+
+#ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
+#ifdef __GNUC__
Quoted 8 lines

arch/nios2/include/uapi/asm/swab.h line 25

Quoted 8 lines
arch/nios2/include/uapi/asm/swab.h new file +8 -0
+
+#define __nios2_swab(x)		\
+	__builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
+
+static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
+{
+	return (__u16) __nios2_swab(((__u32) x) << 16);
+}

Is this actually better than ___constant_swab16()?

Quoted 3 lines

Also, have you checked if you need to support old compiler versions that don't have __builtin_bswap16/32/64? With newer compilers you don't need to define any of these yourself.

Quoted 8 lines

This swap is configured/implemented using Nios II's custom instruction facility; it is not part of the compiler supported Nios II core instruction set. In fact, even the exact opcode allocated is not fixed.

So the custom swap will not be in a form usable by the compiler, and hence no use of it during code generation (if it is, you might not even need to use __builtin_swap*(), there's a optimization pass that recognizes the shift+or-ing C code patterns).

Ok, I see.

Arnd

#103 lore raw
In reply to Ley Foon Tan
Quoted 1 line · Ley Foon Tan

Nios2 GCC port is in mainline and will be in the FSF 4.9 release.

I managed to build a nios2-linux-gnu cross compiler from gcc-4.9.0 that I can add to the Fedora cross-compiler set. I can't build libgcc without kernel headers, though:-/

David

#104 lore raw
Quoted 8 lines · David Howells
Quoted 1 line · Ley Foon Tan

Nios2 GCC port is in mainline and will be in the FSF 4.9 release.

I managed to build a nios2-linux-gnu cross compiler from gcc-4.9.0 that I can add to the Fedora cross-compiler set. I can't build libgcc without kernel headers, though:-/

Having it on https://www.kernel.org/pub/tools/crosstool/ would be also nice.

Quoted 5 lines

David
--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Thanks,
//richard
#105 lore raw
Quoted 1 line · Richard Weinberger

Having it on https://www.kernel.org/pub/tools/crosstool/ would be also nice.

Does the Fedora cross-compiler suite fit with your set? All the fedora cross-compilers are build from a single pair of SRPMS into a slew of binary RPMs and none of the resulting RPMs are relocatable (they all end up in /usr).

The easiest way to install them is:

yum install gcc-\*-linux-gnu

For reference, the current rawhide SRPMs can be found here:

	https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/source/SRPMS/c/cross-binutils-2.24-4.fc21.src.rpm
	https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/source/SRPMS/c/cross-gcc-4.9.0-3.fc21.src.rpm

I haven't yet pushed the NIOS2 arch changes (I'm waiting on a fix to allow me to build libgcc for Cris).

I haven't applied any of your patches, though I do apply the same patches that are applied to the core Fedora binutils and gcc. Note that this URL linked to on your page:

https://www.kernel.org/pub/tools/crosstool/patches/

does not seem to exist.

The compilers that I have managed to produce and install on my system are:

	gcc-aarch64-linux-gnu
	gcc-alpha-linux-gnu
	gcc-arm-linux-gnu
	gcc-avr32-linux-gnu
	gcc-bfin-linux-gnu
	gcc-c6x-linux-gnu
	gcc-cris-linux-gnu
	gcc-frv-linux-gnu
	gcc-h8300-linux-gnu
	gcc-hppa-linux-gnu
	gcc-hppa64-linux-gnu
	gcc-ia64-linux-gnu
	gcc-m32r-linux-gnu
	gcc-m68k-linux-gnu
	gcc-microblaze-linux-gnu
	gcc-mips64-linux-gnu
	gcc-mn10300-linux-gnu
	gcc-nios2-linux-gnu
	gcc-powerpc64-linux-gnu
	gcc-ppc64-linux-gnu
	gcc-s390x-linux-gnu
	gcc-sh-linux-gnu
	gcc-sh64-linux-gnu
	gcc-sparc64-linux-gnu
	gcc-tile-linux-gnu
	gcc-x86_64-linux-gnu
	gcc-xtensa-linux-gnu

All but cris, nios2, sh, sh64 and tile have a collection of libgcc built.

I don't build i386, mips, powerpc, s390, sh4 and sparc as these are covered by the ones I do build.

gcc doesn't support Metag or Openrisc, it considers Score obsolete and Hexagon and Unicore32 don't seem to have suitable binutils support.

David

#106 lore raw

Am 15.07.2014 16:20, schrieb David Howells:

Quoted 7 lines
Quoted 1 line · Richard Weinberger

Having it on https://www.kernel.org/pub/tools/crosstool/ would be also nice.

Does the Fedora cross-compiler suite fit with your set? All the fedora cross-compilers are build from a single pair of SRPMS into a slew of binary RPMs and none of the resulting RPMs are relocatable (they all end up in /usr).

I'm not using Fedora.

Quoted 41 lines

The easiest way to install them is:

yum install gcc-\*-linux-gnu

For reference, the current rawhide SRPMs can be found here:

	https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/source/SRPMS/c/cross-binutils-2.24-4.fc21.src.rpm
	https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/source/SRPMS/c/cross-gcc-4.9.0-3.fc21.src.rpm

I haven't yet pushed the NIOS2 arch changes (I'm waiting on a fix to allow me to build libgcc for Cris).

I haven't applied any of your patches, though I do apply the same patches that are applied to the core Fedora binutils and gcc. Note that this URL linked to on your page:

https://www.kernel.org/pub/tools/crosstool/patches/

does not seem to exist.

The compilers that I have managed to produce and install on my system are:

	gcc-aarch64-linux-gnu
	gcc-alpha-linux-gnu
	gcc-arm-linux-gnu
	gcc-avr32-linux-gnu
	gcc-bfin-linux-gnu
	gcc-c6x-linux-gnu
	gcc-cris-linux-gnu
	gcc-frv-linux-gnu
	gcc-h8300-linux-gnu
	gcc-hppa-linux-gnu
	gcc-hppa64-linux-gnu
	gcc-ia64-linux-gnu
	gcc-m32r-linux-gnu
	gcc-m68k-linux-gnu
	gcc-microblaze-linux-gnu
	gcc-mips64-linux-gnu
	gcc-mn10300-linux-gnu
	gcc-nios2-linux-gnu
	gcc-powerpc64-linux-gnu
Quoted 9 lines
	gcc-ppc64-linux-gnu
	gcc-s390x-linux-gnu
	gcc-sh-linux-gnu
	gcc-sh64-linux-gnu
	gcc-sparc64-linux-gnu
	gcc-tile-linux-gnu
	gcc-x86_64-linux-gnu
	gcc-xtensa-linux-gnu

Nice collection. Let's see whether I can repack your RPMs for openSUSE.

Thanks,
//richard

#107 lore raw
Quoted 1 line · Richard Weinberger

Nice collection. Let's see whether I can repack your RPMs for openSUSE.

It ought to be straightforward. Greg has been interested in doing it, but I don't think he's had the time.

David

#108 lore raw
Quoted 6 lines · David Howells
Quoted 1 line · Richard Weinberger

Nice collection. Let's see whether I can repack your RPMs for openSUSE.

It ought to be straightforward. Greg has been interested in doing it, but I don't think he's had the time.

No, and I don't really use openSUSE anymore, so my interest is even less these days, sorry.

Richard, please do so, it would be great to have these in OBS so that people can grab them for any distro.

thanks,

greg k-h

#94 lore raw

Re: [PATCH v2 27/29] MAINTAINERS: Add nios2 maintainer

In reply to Joe Perches
Quoted 9 lines · Joe Perches
Quoted 1 line · Ley Foon Tan

trivia:

MAINTAINERS

Quoted 1 line
MAINTAINERS +0 -0

[]

MAINTAINERS S: Maintained

Quoted 1 line
MAINTAINERS +0 -0
@@ -6350,6 +6350,13 @@ S:     Maintained

[]

Quoted 8 lines

MAINTAINERS S: Maintained · line 6356

Quoted 4 lines
MAINTAINERS +4 -0
+NIOS2 ARCHITECTURE
+M:   Ley Foon Tan <[email protected]>
+L:   [email protected] (moderated for non-subscribers)
+T:   git://git.rocketboards.org/linux-socfpga.git

this should be:
T: git git://git.rocketboards.org/linux-socfpga.git

Okay, will fix this.

#102 lore raw
In reply to Tobias Klauser
Quoted 6 lines · Tobias Klauser

Hi Ley Foon

Ah, thanks for the notice. Is it still possible to use the old syscall ABI as a replacement on top of this series and use the current toolchain from Mentor Graphics?

Hi Tobias

There are other changes in the nios2 kernel that requires new compiler. So, old syscall ABI replacement most probably won't work.

Regards
Ley Foon

#87 lore raw

Re: [PATCH v2 24/29] nios2: Module support

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

arch/nios2/kernel/module.c line 135

Quoted 3 lines · On Tuesday 15 July 2014 16:45:51 Ley Foon Tan wrote:
arch/nios2/kernel/module.c new file +3 -0
+void module_arch_cleanup(struct module *mod)
+{
+}

This is not needed at all.

Okay, will remove this.

#86 lore raw

Re: [PATCH v2 24/29] nios2: Module support

In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines

AFAIR this is due to relocation issues, as the FIXME comment in the "original" code [1] states. I don't know whether this still applies, though (or what would be the proper fix for this to overcome the relocation issues).

[1] https://github.com/tklauser/linux-nios2/blob/nios2/arch/nios2/kernel/module.c#L45

Ah, I see. Please at least copy over that comment then.

Will copy over the comment.

Quoted 6 lines

A long-term solution would be to copy what ARM does, since that has the same problem. The modules are allocated with __vmalloc_node_range, passing a virtual address range that is just before the kernel virtual address, taken out of the top 16MB of the user space addresses.

Noted, will investigate this for long-term solution.

Thanks.

Regards
Ley Foon

#80 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

arch/nios2/include/asm/gpio.h

Quoted 5 lines · On Tuesday 15 July 2014 16:45:49 Ley Foon Tan wrote:
arch/nios2/include/asm/gpio.h new file +0 -0
new file mode 100644
index 0000000..e726bfc

This seems wrong. If any device drivers rely on this, better fix them to use linux/gpio.h directly.

Okay, will remove this file.

Quoted 8 lines

arch/nios2/include/asm/gpio.h

Quoted 6 lines
arch/nios2/include/asm/gpio.h new file +6 -0
+#ifndef __ASM_NIOS2_PCI_H__
+#define __ASM_NIOS2_PCI_H__
+
+/* We don't support PCI yet, but some drivers require this file anyway */
+
+#endif /* __ASM_NIOS2_PCI_H__ */

What's wrong with the generic version?

Change to use generic pci.h.

Quoted 9 lines

arch/nios2/include/asm/gpio.h

Quoted 7 lines
arch/nios2/include/asm/gpio.h new file +6 -0
+#ifndef _UAPI_ASM_NIOS2_STAT_H
+#define _UAPI_ASM_NIOS2_STAT_H
+
+#include <asm-generic/stat.h>
+
+#endif

This should just use the Kconfig logic to fall back on the generic file.

Will use generic file.

Regards
Ley Foon

#97 lore raw

Re: [PATCH v2 29/29] nios2: Build infrastructure

In reply to Ley Foon Tan

Ley Foon,

Quoted 4 lines · Ley Foon Tan

This patch adds Makefile and Kconfig files required for building a nios2 kernel.

For what it's worth, this v2 indeed cleans up the few things I noted in the related 01/28 of v1.

So this series doesn't introduce any new Kconfig related oddities anymore; ie, oddities of the obvious type that my local script spots. That can't qualify as a review but I do think it's nice to see.

Thanks,

Paul Bolle

#25 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · On Tuesday 15 July 2014 16:45:39 Ley Foon Tan wrote:
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS    32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS                      (NIOS2_CPU_NR_IRQS + 32)

Is this intentional? I would expect that you use SPARSE_IRQ instead and not define NR_IRQS.

Okay, will change to use SPARSE_IRQ.

Quoted 7 lines

arch/nios2/include/asm/irq.h line 29

Quoted 4 lines
arch/nios2/include/asm/irq.h new file +3 -0
+#ifndef NO_IRQ
+#define NO_IRQ                       (-1)
+#endif

New architectures should no longer define NO_IRQ. Please fix all users you encounter instead.

Okay.

Quoted 12 lines

arch/nios2/kernel/irq.c line 27

Quoted 9 lines
arch/nios2/kernel/irq.c new file +3 -0
new file mode 100644
index 0000000..8770d50
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>

Maybe move this into drivers/irqchip/? Probably doesn't matter either way, your choice.

Will keep it here.
BTW, this interrupt controller is part of Nios2 cpu architecture. Should we move to drivers/irqchip/ if that's the case? Any example of arch doing this?
Thanks.

Regards
Ley Foon

#29 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Thomas Gleixner
Quoted 9 lines · Thomas Gleixner

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · Ley Foon Tan
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS    32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS                      (NIOS2_CPU_NR_IRQS + 32)

Please use sparse irqs. Hardcoded limits tend to work out really bad.

Yes, will change this.

Quoted 6 lines
Quoted 5 lines
arch/nios2/kernel/irq.c new file +4 -0
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>
+
Quoted 8 lines

arch/nios2/kernel/irq.c line 47

Quoted 6 lines
arch/nios2/kernel/irq.c new file +6 -0
+static void chip_unmask(struct irq_data *d)
+{
+     u32 ien;
+     ien = RDCTL(CTL_IENABLE);
+     ien |= (1 << d->hwirq);
+     WRCTL(CTL_IENABLE, ien);

So this is UP only, right?

Yes, this is to enable one interrupt.

Quoted 3 lines

Also why don't you cache the register content so spare the extra read from the hardware?

Need to make sure nobody modify the register if we cache the register content. Will keep as it is.

Thanks.

Regards
Ley Foon

maintainer
#26 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Ley Foon Tan
Quoted 33 lines · On Thursday 17 July 2014 14:15:44 Ley Foon Tan wrote:
Quoted 10 lines · Arnd Bergmann

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · On Tuesday 15 July 2014 16:45:39 Ley Foon Tan wrote:
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS    32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS                      (NIOS2_CPU_NR_IRQS + 32)

Is this intentional? I would expect that you use SPARSE_IRQ instead and not define NR_IRQS.

Okay, will change to use SPARSE_IRQ.

Quoted 7 lines

arch/nios2/include/asm/irq.h line 29

Quoted 4 lines
arch/nios2/include/asm/irq.h new file +3 -0
+#ifndef NO_IRQ
+#define NO_IRQ                       (-1)
+#endif

New architectures should no longer define NO_IRQ. Please fix all users you encounter instead.

Okay.

Quoted 12 lines

arch/nios2/kernel/irq.c line 27

Quoted 9 lines
arch/nios2/kernel/irq.c new file +3 -0
new file mode 100644
index 0000000..8770d50
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>

Maybe move this into drivers/irqchip/? Probably doesn't matter either way, your choice.

Quoted 4 lines

Will keep it here.
BTW, this interrupt controller is part of Nios2 cpu architecture. Should we move to drivers/irqchip/ if that's the case? Any example of arch doing this?

A lot of interrupt controllers can be used on multiple architectures, and a lot of architectures have a wide variety of interrupt controllers that can be used, so moving them all into drivers/irqchip is the generally preferred choice.

If your driver can't work on anything other than nios2 (e.g. because it uses special CPU instructions rather than MMIO access) or the CPU core always comes with this irqchip and doesn't have a way to use a different one, there is no problem leaving it in the arch code.

Arnd

#98 lore raw

Re: [PATCH v2 29/29] nios2: Build infrastructure

In reply to Ley Foon Tan

Hi Ley.

Looks much better than last time I reviewed this.
A bunch of small comments follows.

Sam

Quoted 19 lines
arch/nios2/Makefile new file +13 -0
new file mode 100644
index 0000000..62b789a
@@ -0,0 +1,78 @@
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 2013 Altera Corporation
+# Copyright (C) 1994, 95, 96, 2003 by Wind River Systems
+# Written by Fredrik Markstrom
+#
+# This file is included by the global makefile so that you can add your own
+# architecture-specific flags and dependencies. Remember to do have actions
+# for "archclean" cleaning up for this architecture.
+#

arch/nios2/Makefile line 23

Quoted 10 lines
arch/nios2/Makefile new file +10 -0
+# Nios2 port by Wind River Systems Inc trough:
+#   [email protected] and [email protected]
+
+UTS_SYSNAME = Linux
+
+export MMU
+
+cflags-y :=
+LDFLAGS		:=
+LDFLAGS_vmlinux	:=

These assignments are not needed.

arch/nios2/Makefile line 27

Quoted 4 lines
arch/nios2/Makefile new file +4 -0
+
+LIBGCC		:= $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
+
+KBUILD_AFLAGS += $(cflags-y)

This is nop since $(cflags-y) is empty.

arch/nios2/Makefile line 28

Quoted 1 line
arch/nios2/Makefile new file +1 -0
+KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__ $(cflags-y)

Here the $(cflags-y) can be dropped too.

arch/nios2/Makefile line 45

Quoted 2 lines
arch/nios2/Makefile new file +2 -0
+INSTALL_PATH ?= /tftpboot
+boot := arch/$(ARCH)/boot

In all other places you spell out nios2 - so do it here too.

Quoted 23 lines
arch/nios2/Makefile new file +23 -0
+BOOT_TARGETS = vmImage zImage
+PHONY += $(BOOT_TARGETS) install
+KBUILD_IMAGE := $(boot)/vmImage
+
+ifneq ($(CONFIG_NIOS2_DTB_SOURCE),"")
+	core-y	+= $(boot)/
+endif
+
+all: vmImage
+
+archclean:
+	$(Q)$(MAKE) $(clean)=$(boot)
+
+%.dtb:
+	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+dtbs:
+	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+$(BOOT_TARGETS): vmlinux
+	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+install:

arch/nios2/Makefile line 76

Quoted 10 lines
arch/nios2/Makefile new file +8 -0
+	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install
+
+define archhelp
+  echo  '* vmImage         - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage)'
 
 
+  echo  '  install         - Install kernel using'
+  echo  '                     (your) ~/bin/$(CROSS_COMPILE)installkernel or'
+  echo  '                     (distribution) PATH: $(CROSS_COMPILE)installkernel or'
+  echo  '                     install to $$(INSTALL_PATH)'

Is this explanation true for nios2?
I could not check because the install.sh script was not included.

Quoted 27 lines
arch/nios2/Makefile new file +2 -0
+  echo  '  dtbs            - Build device tree blobs for enabled boards'
+endef
arch/nios2/boot/Makefile new file +18 -0
new file mode 100644
index 0000000..35c80e8
@@ -0,0 +1,52 @@
+#
+# arch/nios2/boot/Makefile
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+
+UIMAGE_LOADADDR = $(shell $(NM) vmlinux | awk '$$NF == "_stext" {print $$1}')
+UIMAGE_ENTRYADDR = $(shell $(NM) vmlinux | awk '$$NF == "_start" {print $$1}')
+UIMAGE_COMPRESSION = gzip
+
+OBJCOPYFLAGS_vmlinux.bin := -O binary
+
+targets += vmlinux.bin vmlinux.gz vmImage
+
+$(obj)/vmlinux.bin: vmlinux FORCE
+	$(call if_changed,objcopy)

arch/nios2/boot/Makefile line 28

Quoted 10 lines
arch/nios2/boot/Makefile new file +10 -0
+
+$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
+	$(call if_changed,gzip)
+
+$(obj)/vmImage: $(obj)/vmlinux.gz
+	$(call if_changed,uimage)
+	@$(kecho) 'Kernel: $@ is ready'
+
+# Rule to build device tree blobs
+DTB_SRC := $(subst ",,$(CONFIG_NIOS2_DTB_SOURCE))

If you use:
$(patsubst "%"

Then my editor get less confused. This is also what is used for similar purposes for other architectures.

arch/nios2/boot/Makefile line 31

Quoted 3 lines
arch/nios2/boot/Makefile new file +3 -0
+
+# Make sure the generated dtb gets removed during clean
+extra-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += system.dtb

This is not needed as you cover this with the assignmnet to clean-files later in this file.

Quoted 11 lines
arch/nios2/boot/Makefile new file +11 -0
+
+$(obj)/system.dtb: $(DTB_SRC) FORCE
+	$(call cmd,dtc)
+
+# Ensure system.dtb exists
+$(obj)/linked_dtb.o: $(obj)/system.dtb
+
+obj-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += linked_dtb.o
+
+targets += $(dtb-y)
+

arch/nios2/boot/Makefile line 52

Quoted 10 lines
arch/nios2/boot/Makefile new file +10 -0
+# Rule to build device tree blobs with make command
+$(obj)/%.dtb: $(src)/dts/%.dts FORCE
+	$(call if_changed_dep,dtc)
+
+$(obj)/dtbs: $(addprefix $(obj)/, $(dtb-y))
+
+clean-files := *.dtb
+
+install:
+	sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"

The install.sh script is not included (or I did not find it).

arch/nios2/include/asm/Kbuild line 1

Quoted 7 lines
arch/nios2/include/asm/Kbuild new file +1 -0
new file mode 100644
index 0000000..dfe7a79
@@ -0,0 +1,67 @@
+include include/asm-generic/Kbuild.asm

The above include is wrong - please drop it.

arch/nios2/include/asm/Kbuild line 4

Quoted 2 lines
arch/nios2/include/asm/Kbuild new file +2 -0
+header-y += ucontext.h
+header-y += traps.h

We no longer visit include/asm for exported hedaders. So the two assignments above are not used.

You will likely move them to arch/nios2/include/uapi/asm/Kbuild to let them be exported.

#27 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Arnd Bergmann
Quoted 44 lines · Arnd Bergmann
Quoted 33 lines · On Thursday 17 July 2014 14:15:44 Ley Foon Tan wrote:
Quoted 10 lines · Arnd Bergmann

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · On Tuesday 15 July 2014 16:45:39 Ley Foon Tan wrote:
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS    32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS                      (NIOS2_CPU_NR_IRQS + 32)

Is this intentional? I would expect that you use SPARSE_IRQ instead and not define NR_IRQS.

Okay, will change to use SPARSE_IRQ.

Quoted 7 lines

arch/nios2/include/asm/irq.h line 29

Quoted 4 lines
arch/nios2/include/asm/irq.h new file +3 -0
+#ifndef NO_IRQ
+#define NO_IRQ                       (-1)
+#endif

New architectures should no longer define NO_IRQ. Please fix all users you encounter instead.

Okay.

Quoted 12 lines

arch/nios2/kernel/irq.c line 27

Quoted 9 lines
arch/nios2/kernel/irq.c new file +3 -0
new file mode 100644
index 0000000..8770d50
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>

Maybe move this into drivers/irqchip/? Probably doesn't matter either way, your choice.

Quoted 4 lines

Will keep it here.
BTW, this interrupt controller is part of Nios2 cpu architecture. Should we move to drivers/irqchip/ if that's the case? Any example of arch doing this?

A lot of interrupt controllers can be used on multiple architectures, and a lot of architectures have a wide variety of interrupt controllers that can be used, so moving them all into drivers/irqchip is the generally preferred choice.

Quoted 4 lines

If your driver can't work on anything other than nios2 (e.g. because it uses special CPU instructions rather than MMIO access) or the CPU core always comes with this irqchip and doesn't have a way to use a different one, there is no problem leaving it in the arch code.

Yes, this driver only can be used with nios2 and all these irq registers are part of nios2 control registers.
So, we just leave code here.

Thanks.

Regards
Ley Foon

#64 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Thomas Gleixner
Quoted 15 lines · Thomas Gleixner

On Tue, 15 Jul 2014, Ley Foon Tan wrote:
+static inline int atomic_futex_op_xchg_set(int oparg, u32 __user *uaddr,

arch/nios2/include/asm/futex-irq.h line 35

Quoted 10 lines
arch/nios2/include/asm/futex-irq.h new file +10 -0
+                                        int *oldval)
+{
+     unsigned long flags;
+     int ret;
+
+     local_irq_save(flags);
+
+     ret = get_user(*oldval, uaddr);
+     if (!ret)
+             ret = put_user(oparg, uaddr);

This is wrong as it gets. get_user() might fault and sleep.

Quoted 1 line

You need a proper implementation, which handles fault exceptions.

I have checked that we use nios2 specific get_user() in [1]. This function will not sleep and it handles fault exception. I think this should be fine.

[1] http://rocketboards.org/gitweb/?p=linux-socfpga-next.git;a=blob;f=arch/nios2/include/asm/uaccess.h;h=3e36f536afaba24c308a8416a66b8a2573e042a5;hb=refs/heads/nios2-upstream

Regards
Ley Foon

maintainer
#65 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

Quoted 16 lines · On Thursday 17 July 2014 18:55:49 Ley Foon Tan wrote:
Quoted 15 lines · Thomas Gleixner

On Tue, 15 Jul 2014, Ley Foon Tan wrote:
+static inline int atomic_futex_op_xchg_set(int oparg, u32 __user *uaddr,

arch/nios2/include/asm/futex-irq.h line 35

Quoted 10 lines
arch/nios2/include/asm/futex-irq.h new file +10 -0
+                                        int *oldval)
+{
+     unsigned long flags;
+     int ret;
+
+     local_irq_save(flags);
+
+     ret = get_user(*oldval, uaddr);
+     if (!ret)
+             ret = put_user(oparg, uaddr);

This is wrong as it gets. get_user() might fault and sleep.

Quoted 4 lines
Quoted 1 line

You need a proper implementation, which handles fault exceptions.

I have checked that we use nios2 specific get_user() in [1]. This function will not sleep and it handles fault exception. I think this should be fine.

The get_user/put_user functions really need to be annotated might_fault(), because that's what they do.

The whole point of get_user() is to access an unchecked user space
pointer, which can do a number of things based on what the pointer
points to:

- access a user space variable that resides in memory
- access a kernel pointer and fail because of the access_ok() check
- access a user space pointer that is not mapped and return through the __ex_table fixup.
- access a user space pointer that has a valid VMA but not PTE, causing a page fault to be resolved.

It's the last case that breaks here.

Arnd

#30 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Ley Foon Tan
Quoted 25 lines · Ley Foon Tan
Quoted 9 lines · Thomas Gleixner

arch/nios2/include/asm/irq.h line 25

Quoted 6 lines · Ley Foon Tan
arch/nios2/include/asm/irq.h new file +6 -0
+#ifndef _ASM_NIOS2_IRQ_H
+#define _ASM_NIOS2_IRQ_H
+
+#define NIOS2_CPU_NR_IRQS    32
+/* Reserve 32 additional interrupts for GPIO IRQs */
+#define NR_IRQS                      (NIOS2_CPU_NR_IRQS + 32)

Please use sparse irqs. Hardcoded limits tend to work out really bad.

Yes, will change this.

Quoted 6 lines
Quoted 5 lines
arch/nios2/kernel/irq.c new file +4 -0
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>
+
Quoted 8 lines

arch/nios2/kernel/irq.c line 47

Quoted 6 lines
arch/nios2/kernel/irq.c new file +6 -0
+static void chip_unmask(struct irq_data *d)
+{
+     u32 ien;
+     ien = RDCTL(CTL_IENABLE);
+     ien |= (1 << d->hwirq);
+     WRCTL(CTL_IENABLE, ien);

So this is UP only, right?

Quoted 1 line

Yes, this is to enable one interrupt.

The question was, whether this is always a UniProcessor machine.

Quoted 4 lines
Quoted 2 lines

Also why don't you cache the register content so spare the extra read from the hardware?

Need to make sure nobody modify the register if we cache the register content. Will keep as it is.

Sigh.

If this is a uniprocessor only design, then nothing can modify the cached values as all these functions are always called with interrupts disabled.

If this should be SMP safe, then you'd need serialization of the register access as well becasue the read/modify/write sequence is not atomic.

Thanks,

tglx

#60 lore raw

Re: [PATCH v2 20/29] nios2: Cpuinfo handling

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

arch/nios2/kernel/cpuinfo.c line 188

Quoted 12 lines · On Tuesday 15 July 2014 16:45:47 Ley Foon Tan wrote:
arch/nios2/kernel/cpuinfo.c new file +12 -0
+static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
+{
+       unsigned long i = *pos;
+
+       return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
+}
+
+static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return cpuinfo_start(m, pos);
+}

Do you actually have SMP support?

Not.

Quoted 8 lines

arch/nios2/kernel/cpuinfo.c line 199

Quoted 6 lines
arch/nios2/kernel/cpuinfo.c new file +6 -0
+const struct seq_operations cpuinfo_op = {
+       .start  = cpuinfo_start,
+       .next   = cpuinfo_next,
+       .stop   = cpuinfo_stop,
+       .show   = show_cpuinfo
+};

If not, you can use single_start/next/stop here rather than defining your own.

Okay, I will look into your suggestion.
Thanks.

Regards
Ley Foon

#66 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

The get_user/put_user functions really need to be annotated might_fault(), because that's what they do.

The whole point of get_user() is to access an unchecked user space pointer, which can do a number of things based on what the pointer points to:

- access a user space variable that resides in memory
- access a kernel pointer and fail because of the access_ok() check
- access a user space pointer that is not mapped and return through the __ex_table fixup.
- access a user space pointer that has a valid VMA but not PTE, causing a page fault to be resolved.

Quoted 1 line

It's the last case that breaks here.

So, do you mean that we can't use get_user/put_user in futex support? BTW, some architectures like sh,parisc, m68k use get_user in futex function as well.
Any recommendation way to support futex if we can't use get_user. Note, nios2 doesn't have atomic instruction.
Thanks.

Regards
Ley Foon

#78 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Arnd Bergmann

Hi Arnd,
Considering two other kernel interface issues that appeared earlier in the context of nios2 glibc/kernel upstreaming:

(1) The 64-bit time_t/timespec issue.
(2) Dropping renameat by default in favor of renameat2

What's the decision for these? Are they delayed to the next release?

Thanks,
Chung-Lin

#31 lore raw

Re: [PATCH v2 12/29] nios2: Interrupt handling

In reply to Thomas Gleixner
Quoted 13 lines · Thomas Gleixner
Quoted 11 lines · Ley Foon Tan
Quoted 10 lines · Thomas Gleixner

arch/nios2/kernel/irq.c line 47

Quoted 6 lines · Ley Foon Tan
arch/nios2/kernel/irq.c new file +6 -0
+static void chip_unmask(struct irq_data *d)
+{
+     u32 ien;
+     ien = RDCTL(CTL_IENABLE);
+     ien |= (1 << d->hwirq);
+     WRCTL(CTL_IENABLE, ien);

So this is UP only, right?

Quoted 3 lines
Quoted 1 line

Yes, this is to enable one interrupt.

The question was, whether this is always a UniProcessor machine.

Yes, it is UP.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Also why don't you cache the register content so spare the extra read from the hardware?

Need to make sure nobody modify the register if we cache the register content. Will keep as it is.

Sigh.

Quoted 7 lines

If this is a uniprocessor only design, then nothing can modify the cached values as all these functions are always called with interrupts disabled.

If this should be SMP safe, then you'd need serialization of the register access as well becasue the read/modify/write sequence is not atomic.

Okay, we can cache the value.
Thanks.

Regards
Ley Foon

#44 lore raw

Re: [PATCH v2 16/29] nios2: Signal handling support

In reply to Ley Foon Tan
Quoted 172 lines · Ley Foon Tan

This patch adds support for signal handling.

---
 arch/nios2/include/asm/signal.h          |  22 +++
 arch/nios2/include/asm/ucontext.h        |  34 ++++
 arch/nios2/include/uapi/asm/sigcontext.h |  30 +++
 arch/nios2/include/uapi/asm/signal.h     |  23 +++
 arch/nios2/kernel/signal.c               | 316 +++++++++++++++++++++++++++++++
 5 files changed, 425 insertions(+)
 create mode 100644 arch/nios2/include/asm/signal.h
 create mode 100644 arch/nios2/include/asm/ucontext.h
 create mode 100644 arch/nios2/include/uapi/asm/sigcontext.h
 create mode 100644 arch/nios2/include/uapi/asm/signal.h
 create mode 100644 arch/nios2/kernel/signal.c
arch/nios2/include/asm/signal.h new file +22 -0
new file mode 100644
index 0000000..bbcf11e
@@ -0,0 +1,22 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef _NIOS2_SIGNAL_H
+#define _NIOS2_SIGNAL_H
+
+#include <uapi/asm/signal.h>
+
+#endif /* _NIOS2_SIGNAL_H */
arch/nios2/include/asm/ucontext.h new file +34 -0
new file mode 100644
index 0000000..5870ef4
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ *
+ * derived from m68knommu
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_UCONTEXT_H
+#define _ASM_NIOS2_UCONTEXT_H
+
+typedef int greg_t;
+#define NGREG 32
+typedef greg_t gregset_t[NGREG];
+
+struct mcontext {
+       int version;
+       gregset_t gregs;
+};
+
+#define MCONTEXT_VERSION 2
+
+struct ucontext {
+       unsigned long     uc_flags;
+       struct ucontext  *uc_link;
+       stack_t           uc_stack;
+       struct mcontext   uc_mcontext;
+       sigset_t          uc_sigmask;   /* mask last for extensibility */
+};
+
+#endif
arch/nios2/include/uapi/asm/sigcontext.h new file +30 -0
new file mode 100644
index 0000000..6bfd880
@@ -0,0 +1,30 @@
+/*
+ * Taken from the m68knommu.
+ *
+ * Copyright (C) 2004, Microtronix Datacom Ltd.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#ifndef _ASM_NIOS2_SIGCONTEXT_H
+#define _ASM_NIOS2_SIGCONTEXT_H
+
+#include <asm/ptrace.h>
+
+struct sigcontext {
+       struct pt_regs regs;
+       unsigned long  sc_mask; /* old sigmask */
+};
+
+#endif
arch/nios2/include/uapi/asm/signal.h new file +23 -0
new file mode 100644
index 0000000..f29ee63
@@ -0,0 +1,23 @@
+/*
+ * Copyright Altera Corporation (C) 2013. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef _ASM_NIOS2_SIGNAL_H
+#define _ASM_NIOS2_SIGNAL_H
+
+#define SA_RESTORER 0x04000000
+#include <asm-generic/signal.h>
+
+#endif /* _ASM_NIOS2_SIGNAL_H */
arch/nios2/kernel/signal.c new file +17 -0
new file mode 100644
index 0000000..3f649d8
@@ -0,0 +1,316 @@
+/*
+ * Copyright (C) 2013 Altera Corporation
+ * Copyright (C) 2011-2012 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ *
+ * This file is based on kernel/signal.c from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/signal.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/uaccess.h>

arch/nios2/kernel/signal.c line 27

Quoted 10 lines
arch/nios2/kernel/signal.c new file +10 -0
+#include <linux/unistd.h>
+#include <linux/personality.h>
+#include <linux/tracehook.h>
+
+#include <asm/ucontext.h>
+#include <asm/cacheflush.h>
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+static int do_signal(struct pt_regs *regs, int in_syscall);

Do you really need this prototype?

Quoted 83 lines
arch/nios2/kernel/signal.c new file +83 -0
+/*
+ * Do a signal return; undo the signal stack.
+ *
+ * Keep the return code on the stack quadword aligned!
+ * That makes the cache flush below easier.
+ */
+
+struct rt_sigframe {
+       struct siginfo info;
+       struct ucontext uc;
+};
+
+static inline int rt_restore_ucontext(struct pt_regs *regs,
+                                       struct switch_stack *sw,
+                                       struct ucontext *uc, int *pr2)
+{
+       int temp;
+       greg_t *gregs = uc->uc_mcontext.gregs;
+       int err;
+
+       err = __get_user(temp, &uc->uc_mcontext.version);
+       if (temp != MCONTEXT_VERSION)
+               goto badframe;
+       /* restore passed registers */
+       err |= __get_user(regs->r1, &gregs[0]);
+       err |= __get_user(regs->r2, &gregs[1]);
+       err |= __get_user(regs->r3, &gregs[2]);
+       err |= __get_user(regs->r4, &gregs[3]);
+       err |= __get_user(regs->r5, &gregs[4]);
+       err |= __get_user(regs->r6, &gregs[5]);
+       err |= __get_user(regs->r7, &gregs[6]);
+       err |= __get_user(regs->r8, &gregs[7]);
+       err |= __get_user(regs->r9, &gregs[8]);
+       err |= __get_user(regs->r10, &gregs[9]);
+       err |= __get_user(regs->r11, &gregs[10]);
+       err |= __get_user(regs->r12, &gregs[11]);
+       err |= __get_user(regs->r13, &gregs[12]);
+       err |= __get_user(regs->r14, &gregs[13]);
+       err |= __get_user(regs->r15, &gregs[14]);
+       err |= __get_user(sw->r16, &gregs[15]);
+       err |= __get_user(sw->r17, &gregs[16]);
+       err |= __get_user(sw->r18, &gregs[17]);
+       err |= __get_user(sw->r19, &gregs[18]);
+       err |= __get_user(sw->r20, &gregs[19]);
+       err |= __get_user(sw->r21, &gregs[20]);
+       err |= __get_user(sw->r22, &gregs[21]);
+       err |= __get_user(sw->r23, &gregs[22]);
+       /* gregs[23] is handled below */
+       err |= __get_user(sw->fp, &gregs[24]);  /* Verify, should this be
+                                                       settable */
+       err |= __get_user(sw->gp, &gregs[25]);  /* Verify, should this be
+                                                       settable */
+
+       err |= __get_user(temp, &gregs[26]);  /* Not really necessary no user
+                                                       settable bits */
+       err |= __get_user(regs->ea, &gregs[27]);
+
+       err |= __get_user(regs->ra, &gregs[23]);
+       err |= __get_user(regs->sp, &gregs[28]);
+
+       regs->estatus = (regs->estatus & 0xffffffff);
+       regs->orig_r2 = -1;             /* disable syscall checks */
+
+       err |= restore_altstack(&uc->uc_stack);
+       if (err)
+               goto badframe;
+
+       *pr2 = regs->r2;
+       return err;
+
+badframe:
+       return 1;
+}
+
+asmlinkage int do_rt_sigreturn(struct switch_stack *sw)
+{
+       struct pt_regs *regs = (struct pt_regs *)(sw + 1);
+       /* Verify, can we follow the stack back */
+       struct rt_sigframe *frame = (struct rt_sigframe *) regs->sp;
+       sigset_t set;
+       int rval;
+
+       if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))

arch/nios2/kernel/signal.c line 121

Quoted 10 lines
arch/nios2/kernel/signal.c new file +10 -0
+               goto badframe;
+
+       if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+               goto badframe;
+
+       sigdelsetmask(&set, ~_BLOCKABLE);
+       spin_lock_irq(&current->sighand->siglock);
+       current->blocked = set;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);

Why aren't you using set_current_blocked() here?

Quoted 76 lines
arch/nios2/kernel/signal.c new file +76 -0
+       if (rt_restore_ucontext(regs, sw, &frame->uc, &rval))
+               goto badframe;
+
+       return rval;
+
+badframe:
+       force_sig(SIGSEGV, current);
+       return 0;
+}
+
+static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
+{
+       struct switch_stack *sw = (struct switch_stack *)regs - 1;
+       greg_t *gregs = uc->uc_mcontext.gregs;
+       int err = 0;
+
+       err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
+       err |= __put_user(regs->r1, &gregs[0]);
+       err |= __put_user(regs->r2, &gregs[1]);
+       err |= __put_user(regs->r3, &gregs[2]);
+       err |= __put_user(regs->r4, &gregs[3]);
+       err |= __put_user(regs->r5, &gregs[4]);
+       err |= __put_user(regs->r6, &gregs[5]);
+       err |= __put_user(regs->r7, &gregs[6]);
+       err |= __put_user(regs->r8, &gregs[7]);
+       err |= __put_user(regs->r9, &gregs[8]);
+       err |= __put_user(regs->r10, &gregs[9]);
+       err |= __put_user(regs->r11, &gregs[10]);
+       err |= __put_user(regs->r12, &gregs[11]);
+       err |= __put_user(regs->r13, &gregs[12]);
+       err |= __put_user(regs->r14, &gregs[13]);
+       err |= __put_user(regs->r15, &gregs[14]);
+       err |= __put_user(sw->r16, &gregs[15]);
+       err |= __put_user(sw->r17, &gregs[16]);
+       err |= __put_user(sw->r18, &gregs[17]);
+       err |= __put_user(sw->r19, &gregs[18]);
+       err |= __put_user(sw->r20, &gregs[19]);
+       err |= __put_user(sw->r21, &gregs[20]);
+       err |= __put_user(sw->r22, &gregs[21]);
+       err |= __put_user(sw->r23, &gregs[22]);
+       err |= __put_user(regs->ra, &gregs[23]);
+       err |= __put_user(sw->fp, &gregs[24]);
+       err |= __put_user(sw->gp, &gregs[25]);
+       err |= __put_user(regs->ea, &gregs[27]);
+       err |= __put_user(regs->sp, &gregs[28]);
+       return err;
+}
+
+static inline void push_cache(unsigned long vaddr)
+{
+       flush_dcache_range(vaddr, vaddr + 12);
+       flush_icache_range(vaddr, vaddr + 12);
+}
+
+static inline void *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
+                                size_t frame_size)
+{
+       unsigned long usp;
+
+       /* Default to using normal stack.  */
+       usp = regs->sp;
+
+       /* This is the X/Open sanctioned signal stack switching.  */
+       usp = sigsp(usp, ksig);
+
+       /* Verify, is it 32 or 64 bit aligned */
+       return (void *)((usp - frame_size) & -8UL);
+}
+
+static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+                         struct pt_regs *regs)
+{
+       struct rt_sigframe *frame;
+       int err = 0;
+
+       frame = get_sigframe(ksig, regs, sizeof(*frame));

arch/nios2/kernel/signal.c line 208

Quoted 10 lines
arch/nios2/kernel/signal.c new file +10 -0
+
+       if (ksig->ka.sa.sa_flags & SA_SIGINFO)
+               err |= copy_siginfo_to_user(&frame->info, &ksig->info);
+
+       /* Create the ucontext.  */
+       err |= __put_user(0, &frame->uc.uc_flags);
+       err |= __put_user(0, &frame->uc.uc_link);
+       err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
+       err |= rt_setup_ucontext(&frame->uc, regs);
+       err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

You neither check nor propagate this error code.

Quoted 114 lines
arch/nios2/kernel/signal.c new file +107 -1
+       /* Set up to return from userspace; jump to fixed address sigreturn
+          trampoline on kuser page.  */
+       regs->ra = (unsigned long) (0x1040);
+
+       /* Set up registers for signal handler */
+       regs->sp = (unsigned long) frame;
+       regs->r4 = (unsigned long) ksig->sig;
+       regs->r5 = (unsigned long) &frame->info;
+       regs->r6 = (unsigned long) &frame->uc;
+       regs->ea = (unsigned long) ksig->ka.sa.sa_handler;
+       return 0;
+}
+
+static inline void handle_restart(struct pt_regs *regs, struct k_sigaction *ka,
+                                 int has_handler)
+{
+       switch (regs->r2) {
+       case ERESTART_RESTARTBLOCK:
+       case ERESTARTNOHAND:
+               regs->r2 = EINTR;
+               regs->r7 = 1;
+               break;
+       case ERESTARTSYS:
+               if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
+                       regs->r2 = EINTR;
+                       regs->r7 = 1;
+                       break;
+               }
+       /* fallthrough */
+       case ERESTARTNOINTR:
+               regs->r2 = regs->orig_r2;
+               regs->r7 = regs->orig_r7;
+               regs->ea -= 4;
+               break;
+       }
+}
+
+/*
+ * OK, we're invoking a handler
+ */
+static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
+{
+       int ret;
+       sigset_t *oldset = sigmask_to_save();
+
+       /* set up the stack frame */
+       ret = setup_rt_frame(ksig, oldset, regs);
+
+       signal_setup_done(ret, ksig, 0);
+}
+
+static int do_signal(struct pt_regs *regs, int in_syscall)
+{
+       struct ksignal ksig;
+
+       current->thread.kregs = regs;
+
+       if (get_signal(&ksig)) {
+               /*
+                * Are we from a system call? If so, check system call
+                * restarting.
+                */
+               if (in_syscall)
+                       handle_restart(regs, &ksig.ka, 1);
+               /* Whee!  Actually deliver the signal.  */
+               handle_signal(&ksig, regs);
+               return 1;
+       }
+
+       /*
+        * No signal to deliver to the process - restart the syscall.
+        */
+       if (in_syscall) {
+               /* Did the syscall return an error code */
+               if (regs->r7 == 1) {
+                       if (regs->r2 == ERESTARTNOHAND ||
+                               regs->r2 == ERESTARTSYS ||
+                               regs->r2 == ERESTARTNOINTR) {
+                               regs->r2 = regs->orig_r2;
+                               regs->r7 = regs->orig_r7;
+                               regs->ea -= 4;
+                       } else if (regs->r2 == ERESTART_RESTARTBLOCK) {
+                               regs->r2 = __NR_restart_syscall;
+                               regs->ea -= 4;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+asmlinkage void do_notify_resume(struct pt_regs *regs, int in_syscall)
+{
+       /*
+        * We want the common case to go fast, which is why we may in certain
+        * cases get here from kernel mode. Just return without doing anything
+        * if so.
+        */
+       if (!user_mode(regs))
+               return;
+
+       if (test_thread_flag(TIF_SIGPENDING))
+               do_signal(regs, in_syscall);
+
+       if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
+               tracehook_notify_resume(regs);
+}
--

1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Thanks,
//richard
maintainer
#67 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Ley Foon Tan
Quoted 16 lines · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:
Quoted 15 lines · Arnd Bergmann

The get_user/put_user functions really need to be annotated might_fault(), because that's what they do.

The whole point of get_user() is to access an unchecked user space pointer, which can do a number of things based on what the pointer points to:

- access a user space variable that resides in memory
- access a kernel pointer and fail because of the access_ok() check
- access a user space pointer that is not mapped and return through the __ex_table fixup.
- access a user space pointer that has a valid VMA but not PTE, causing a page fault to be resolved.

Quoted 7 lines
Quoted 1 line

It's the last case that breaks here.

So, do you mean that we can't use get_user/put_user in futex support? BTW, some architectures like sh,parisc, m68k use get_user in futex function as well.
Any recommendation way to support futex if we can't use get_user. Note, nios2 doesn't have atomic instruction.
Thanks.

I looked at it again now and I'm no longer sure about my initial interpretation. The way it seems to work is that pagefault_disable() turns the case I mentioned into a simple error through the fixup, so we return -EFAULT from get_user, and retry the futex from futex_wake_op().

This would however also mean that there is no need for a spinlock at all, atomicity is already implied by pagefault_disable() here because you are running on a UP kernel and pagefault_disable() also means there is no preemption.

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

Arnd

maintainer
#79 lore raw

Re: [PATCH v2 22/29] nios2: Miscellaneous header files

In reply to Chung-Lin Tang
Quoted 8 lines · On Friday 18 July 2014 14:15:07 Chung-Lin Tang wrote:

Hi Arnd,
Considering two other kernel interface issues that appeared earlier in the context of nios2 glibc/kernel upstreaming:

(1) The 64-bit time_t/timespec issue.
(2) Dropping renameat by default in favor of renameat2

What's the decision for these? Are they delayed to the next release?

For renameat2, I believe we had patches to change the generic syscall list. It would be nice if you could include those in your patch series as a prerequisite and base your patches on top.

Regarding time_t, I've spent much more time looking into what we need to do for the other 32-bit architectures now. My feeling now is that we're better off not introducing another special case for nios2 here, as that will have the effect of making it harder to move everyone else over later. We already have to deal with:

- 32-bit architectures using 32-bit time_t
- 64-bit architectures using 64-bit time_t
- 64-bit architectures running 32-bit tasks with 32-bit time_t
- 64-bit x86-64 and soon arm64 running x32 user space with 64-bit time_t

and we will get in the future

- 32-bit architectures providing both 32-bit time_t and 64-bit time64_t
- 64-bit architectures with compat tasks running 64-bit time64_t

Adding a 32-bit architecture that has a native 64-bit time_t will just add another special case that we will have to live with for a long time and that can introduce bugs for the other cases if we get it wrong. I vote for keeping 32-bit time_t on nios2 and fixing it along with arm32 and x86-32 and the others.

Presumably this is not a huge problem for you as I expect it's easier for you to do another ABI change in user space when we get
there: once we have support for 64-bit time64_t in the kernel, you can change your toolchains to default to that in user space and rebuild everything. This is not something we can easily do in x86.

Arnd

#68 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Arnd Bergmann
Quoted 36 lines · Arnd Bergmann
Quoted 16 lines · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:
Quoted 15 lines · Arnd Bergmann

The get_user/put_user functions really need to be annotated might_fault(), because that's what they do.

The whole point of get_user() is to access an unchecked user space pointer, which can do a number of things based on what the pointer points to:

- access a user space variable that resides in memory
- access a kernel pointer and fail because of the access_ok() check
- access a user space pointer that is not mapped and return through the __ex_table fixup.
- access a user space pointer that has a valid VMA but not PTE, causing a page fault to be resolved.

Quoted 7 lines
Quoted 1 line

It's the last case that breaks here.

So, do you mean that we can't use get_user/put_user in futex support? BTW, some architectures like sh,parisc, m68k use get_user in futex function as well.
Any recommendation way to support futex if we can't use get_user. Note, nios2 doesn't have atomic instruction.
Thanks.

I looked at it again now and I'm no longer sure about my initial interpretation. The way it seems to work is that pagefault_disable() turns the case I mentioned into a simple error through the fixup, so we return -EFAULT from get_user, and retry the futex from futex_wake_op().

This would however also mean that there is no need for a spinlock at all, atomicity is already implied by pagefault_disable() here because you are running on a UP kernel and pagefault_disable() also means there is no preemption.

Quoted 6 lines

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

For UP relying of pagefault disable should be good enough indeed. I guess the asm for the other UP stuff results from looking at architectures or copying from architectures which did this in ASM :)

Thanks,

tglx

maintainer
#69 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

Quoted 10 lines · On Friday 18 July 2014 11:42:34 Thomas Gleixner wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 1 line · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:

On Thu, Jul 17, 2014 at 7:07 PM, Arnd Bergmann <[email protected]> wrote:

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

Quoted 3 lines

For UP relying of pagefault disable should be good enough indeed. I guess the asm for the other UP stuff results from looking at architectures or copying from architectures which did this in ASM

Ok, thanks for the confirmation!

Ley Foon Tan, I think the best way forward then is for you to take the m68k code and copy (or move) that into asm-generic/futex.h under an #ifndef CONFIG_SMP.

Arnd

#41 lore raw

Re: [PATCH v2 15/29] nios2: System calls handling

In reply to Ley Foon Tan

Hi,

Quoted 3 lines · Ley Foon Tan

This patch adds support for system calls from userspaces. It uses the asm-generic/unistd.h definitions with architecture spcific syscall. The sys_call_table is just an array defined in a C file and it contains pointers to the syscall functions.

I don't think you need the renameat syscall now that renameat2 exists.

Can I suggest preceding your patchset with this patch:
https://lkml.org/lkml/2014/4/23/197
([RFC 3/3] asm-generic: Drop renameat syscall from default list)

which drops renameat from the generic list unless __ARCH_WANT_RENAMEAT is defined in the arch's uapi/asm/unistd.h.

Cheers
James

#70 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann
Quoted 10 lines · On Friday 18 July 2014 11:42:34 Thomas Gleixner wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 1 line · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:

On Thu, Jul 17, 2014 at 7:07 PM, Arnd Bergmann <[email protected]> wrote:

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

Quoted 3 lines

For UP relying of pagefault disable should be good enough indeed. I guess the asm for the other UP stuff results from looking at architectures or copying from architectures which did this in ASM

Quoted 5 lines

Ok, thanks for the confirmation!

Ley Foon Tan, I think the best way forward then is for you to take the m68k code and copy (or move) that into asm-generic/futex.h under an #ifndef CONFIG_SMP.

Okay, I will copy m68k implementation to asm-generic/futex.h. Do you prefer this as separate patch submission or this can be part of nios2 patchset?
Thanks.

Regards
Ley Foon

maintainer
#71 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

Quoted 18 lines · On Monday 21 July 2014 11:20:02 Ley Foon Tan wrote:
Quoted 17 lines · Arnd Bergmann
Quoted 10 lines · On Friday 18 July 2014 11:42:34 Thomas Gleixner wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 1 line · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:

On Thu, Jul 17, 2014 at 7:07 PM, Arnd Bergmann <[email protected]> wrote:

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

Quoted 3 lines

For UP relying of pagefault disable should be good enough indeed. I guess the asm for the other UP stuff results from looking at architectures or copying from architectures which did this in ASM

Ok, thanks for the confirmation!

Quoted 7 lines
Quoted 3 lines

Ley Foon Tan, I think the best way forward then is for you to take the m68k code and copy (or move) that into asm-generic/futex.h under an #ifndef CONFIG_SMP.

Okay, I will copy m68k implementation to asm-generic/futex.h. Do you prefer this as separate patch submission or this can be part of nios2 patchset?

I think it's better for everybody if you include it in your nios2 patchset, once I've seen the patch and provided an Ack. You can send it separately for review at first.

Arnd

#52 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann
Quoted 11 lines · On Tuesday 15 July 2014 16:45:46 Ley Foon Tan wrote:
arch/nios2/include/asm/delay.h new file +11 -0
+
+static inline void __delay(unsigned long loops)
+{
+     int dummy;
+
+     __asm__ __volatile__(
+     "1:\n\t"
+     "    beq    %0,zero,2f\n\t"
+     "    addi   %0, %0, -1\n\t"
+     "    br     1b\n\t"
+     "2:\n\t"
Quoted 8 lines

arch/nios2/include/asm/delay.h line 26

Quoted 3 lines
arch/nios2/include/asm/delay.h new file +3 -0
+     :  "=r" (dummy)         /* Need output for optimizer */
+     :  "0" (loops));        /* %0  Input */
+}

Do you have a reliable clock source? If you do, it would be better to replace the delay loop with an implementation that waits for the exact time to pass instead. This will also avoid the loop calibration during boot and give you better boot times.

Okay, will change this to use timer instead.

Quoted 12 lines

arch/nios2/include/asm/timex.h line 27

Quoted 10 lines
arch/nios2/include/asm/timex.h new file +9 -0
+#ifndef _ASM_NIOS2_TIMEX_H
+#define _ASM_NIOS2_TIMEX_H
+
+/* Supply dummy tick-rate. Real value will be read from devicetree */
+#define CLOCK_TICK_RATE              (HZ * 100000UL)
+
+#include <asm-generic/timex.h>
+
+#endif

CLOCK_TICK_RATE is no longer used anywhere, no need for this file.

I found jiffies.h still using this define. Can we still remove this? In include/linux/jiffies.h:
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

Quoted 9 lines

arch/nios2/kernel/time.c

Quoted 6 lines
arch/nios2/kernel/time.c new file +0 -0
new file mode 100644
index 0000000..111ade1

Maybe move this to drivers/clocksource? Same argument as for the irqchip driver, so either move both or neither.

Will keep this here since we don't move irq driver.

Thanks.

Regards
Ley Foon

#72 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines

Okay, I will copy m68k implementation to asm-generic/futex.h. Do you prefer this as separate patch submission or this can be part of nios2 patchset?

I think it's better for everybody if you include it in your nios2 patchset, once I've seen the patch and provided an Ack. You can send it separately for review at first.

Okay. Will add to my next revision of nios2 patchset.

Thanks.

Regards
Ley Foon

maintainer
#53 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Ley Foon Tan
Quoted 13 lines · On Monday 21 July 2014 18:07:02 Ley Foon Tan wrote:
Quoted 12 lines

arch/nios2/include/asm/timex.h line 27

Quoted 10 lines
arch/nios2/include/asm/timex.h new file +9 -0
+#ifndef _ASM_NIOS2_TIMEX_H
+#define _ASM_NIOS2_TIMEX_H
+
+/* Supply dummy tick-rate. Real value will be read from devicetree */
+#define CLOCK_TICK_RATE              (HZ * 100000UL)
+
+#include <asm-generic/timex.h>
+
+#endif

CLOCK_TICK_RATE is no longer used anywhere, no need for this file.

Quoted 4 lines

I found jiffies.h still using this define. Can we still remove this? In include/linux/jiffies.h:
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

Ah, I thought we had killed off LATCH, but at least it is only used on architecture specific code, and only in two files:

arch/x86/kernel/apm_32.c:       outb_p(LATCH & 0xff, PIT_CH0);  /* LSB */
arch/unicore32/kernel/time.c:   writel(readl(OST_OSMR0) - LATCH, OST_OSCR);

We could decide to move the LATCH definition into those two files to remove it from common code, but it doesn't really hurt otherwise, and everything works fine if you don't define CLOCK_TICK_RATE on architectures that don't need LATCH or CLOCK_TICK_RATE in their architecture-specific code.

Arnd

#56 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner

arch/nios2/kernel/time.c line 49

Quoted 3 lines
arch/nios2/kernel/time.c new file +3 -0
+     count =
+             readw(timer_membase + ALTERA_TIMER_SNAPH_REG) << 16 |
+             readw(timer_membase + ALTERA_TIMER_SNAPL_REG);

So you're serious about having a new architecture with a timer implementation which cant read 32bit in one go? I'm impressed ...

This is to compatible with 16-bit and 32-bit processors. The older version of Nios is 16-bit and Nios II is 32-bit.
But this timer core doesn't get updated after Nios is end of life.

Quoted 8 lines
Quoted 8 lines
arch/nios2/kernel/time.c new file +8 -0
+irqreturn_t timer_interrupt(int irq, void *dummy)
+{
+     /* Clear the interrupt condition */
+     writew(0, timer_membase + ALTERA_TIMER_STATUS_REG);
+     nios2_timer_count += NIOS2_TIMER_PERIOD;
+
+     profile_tick(CPU_PROFILING);
+
Quoted 8 lines

arch/nios2/kernel/time.c line 76

Quoted 5 lines
arch/nios2/kernel/time.c new file +5 -0
+     xtime_update(1);
+
+     update_process_times(user_mode(get_irq_regs()));
+
+     return IRQ_HANDLED;

Please use the clock events infrastructure. New users of the old style timer management are not welcome.

Okay, will change this.

Quoted 15 lines

arch/nios2/kernel/time.c line 87

Quoted 12 lines
arch/nios2/kernel/time.c new file +11 -0
+}
+
+static cycle_t nios2_timer_read(struct clocksource *cs)
+{
+     unsigned long flags;
+     u32 cycles;
+     u32 tcn;
+
+     local_irq_save(flags);
+     tcn = NIOS2_TIMER_PERIOD - 1 - read_timersnapshot();
+     cycles = nios2_timer_count;

This is wrong and completely pointless. The core code takes care about the offset.

This offset is different from the core code. The core code is handling cycle counter overlapping.
But this is for the offset between last timer interrupt counter and current counter (read_timersnapshot()).

Thanks.

Regards
Ley Foon

#54 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Arnd Bergmann
Quoted 22 lines · Arnd Bergmann
Quoted 13 lines · On Monday 21 July 2014 18:07:02 Ley Foon Tan wrote:
Quoted 12 lines

arch/nios2/include/asm/timex.h line 27

Quoted 10 lines
arch/nios2/include/asm/timex.h new file +9 -0
+#ifndef _ASM_NIOS2_TIMEX_H
+#define _ASM_NIOS2_TIMEX_H
+
+/* Supply dummy tick-rate. Real value will be read from devicetree */
+#define CLOCK_TICK_RATE              (HZ * 100000UL)
+
+#include <asm-generic/timex.h>
+
+#endif

CLOCK_TICK_RATE is no longer used anywhere, no need for this file.

Quoted 4 lines

I found jiffies.h still using this define. Can we still remove this? In include/linux/jiffies.h:
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

Ah, I thought we had killed off LATCH, but at least it is only used on architecture specific code, and only in two files:

Quoted 8 lines
arch/x86/kernel/apm_32.c:       outb_p(LATCH & 0xff, PIT_CH0);  /* LSB */
arch/unicore32/kernel/time.c:   writel(readl(OST_OSMR0) - LATCH, OST_OSCR);

We could decide to move the LATCH definition into those two files to remove it from common code, but it doesn't really hurt otherwise, and everything works fine if you don't define CLOCK_TICK_RATE on architectures that don't need LATCH or CLOCK_TICK_RATE in their architecture-specific code.

Okay, will remove CLOCK_TICK_RATE define.

Thanks.

Regards
Ley Foon

#42 lore raw

Re: [PATCH v2 15/29] nios2: System calls handling

In reply to James Hogan
Quoted 7 lines · James Hogan

Hi,

Quoted 3 lines · Ley Foon Tan

This patch adds support for system calls from userspaces. It uses the asm-generic/unistd.h definitions with architecture spcific syscall. The sys_call_table is just an array defined in a C file and it contains pointers to the syscall functions.

Quoted 8 lines

I don't think you need the renameat syscall now that renameat2 exists.

Can I suggest preceding your patchset with this patch:
https://lkml.org/lkml/2014/4/23/197
([RFC 3/3] asm-generic: Drop renameat syscall from default list)

which drops renameat from the generic list unless __ARCH_WANT_RENAMEAT is defined in the arch's uapi/asm/unistd.h.

Yes, we don't need renameat syscall. Will add this patch.

Thanks.

Regards
Ley Foon

#57 lore raw

Re: [PATCH v2 19/29] nios2: Time keeping

In reply to Ley Foon Tan
Quoted 11 lines · Ley Foon Tan
Quoted 6 lines · Thomas Gleixner

arch/nios2/kernel/time.c line 49

Quoted 3 lines
arch/nios2/kernel/time.c new file +3 -0
+     count =
+             readw(timer_membase + ALTERA_TIMER_SNAPH_REG) << 16 |
+             readw(timer_membase + ALTERA_TIMER_SNAPL_REG);

So you're serious about having a new architecture with a timer implementation which cant read 32bit in one go? I'm impressed ...

This is to compatible with 16-bit and 32-bit processors. The older version of Nios is 16-bit and Nios II is 32-bit.
But this timer core doesn't get updated after Nios is end of life.

Sigh.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
arch/nios2/kernel/time.c new file +4 -0
+static cycle_t nios2_timer_read(struct clocksource *cs)
+{
+     unsigned long flags;
+     u32 cycles;
Quoted 8 lines

arch/nios2/kernel/time.c line 87

Quoted 5 lines
arch/nios2/kernel/time.c new file +5 -0
+     u32 tcn;
+
+     local_irq_save(flags);
+     tcn = NIOS2_TIMER_PERIOD - 1 - read_timersnapshot();
+     cycles = nios2_timer_count;

This is wrong and completely pointless. The core code takes care about the offset.

Quoted 4 lines

This offset is different from the core code. The core code is handling cycle counter overlapping.
But this is for the offset between last timer interrupt counter and current counter (read_timersnapshot()).

So IOW, if you ever lose a timer interrupt, your timekeeping is off by a full cycle.

Great hardware design, really.

Thanks,

tglx

#34 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

In reply to Arnd Bergmann
Quoted 26 lines · Arnd Bergmann
Quoted 7 lines · On Tuesday 15 July 2014 16:45:40 Ley Foon Tan wrote:
arch/nios2/include/asm/dma-mapping.h new file +7 -0
+static inline void __dma_sync(void *vaddr, size_t size,
+                           enum dma_data_direction direction)
+{
+     switch (direction) {
+     case DMA_FROM_DEVICE:   /* invalidate cache */
+             invalidate_dcache_range((unsigned long)vaddr,
+                     (unsigned long)(vaddr + size));

arch/nios2/include/asm/dma-mapping.h line 33

Quoted 10 lines
arch/nios2/include/asm/dma-mapping.h new file +10 -0
+             break;
+     case DMA_TO_DEVICE:     /* flush and invalidate cache */
+     case DMA_BIDIRECTIONAL:
+             flush_dcache_range((unsigned long)vaddr,
+                     (unsigned long)(vaddr + size));
+             break;
+     default:
+             BUG();
+     }
+}

This seems strange. More on that below.

Quoted 3 lines
arch/nios2/include/asm/dma-mapping.h new file +3 -0
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+

...

Quoted 10 lines

arch/nios2/include/asm/dma-mapping.h line 104

Quoted 5 lines
arch/nios2/include/asm/dma-mapping.h new file +5 -0
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
+                               enum dma_data_direction direction)
+{
+     __dma_sync(vaddr, size, direction);
+}

IIRC dma_cache_sync should be empty if you define dma_alloc_noncoherent to be the same as dma_alloc_coherent: It's already coherent, so no sync should be needed. What does the CPU do if you try to invalidate the cache on a coherent mapping?

Okay, I got what you mean here. I will leave this dma_cache_sync() function empty.
The CPU just do nothing if we try to invalidate cache on a coherent region. BTW, I found many other architectures still provide dma_cache_sync() even they define dma_alloc_noncoherent
same as dma_alloc_coherent. Eg: blackfin, x86 or xtense.

Quoted 24 lines
Quoted 8 lines
arch/nios2/mm/dma-mapping.c new file +7 -0
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                          size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}

arch/nios2/mm/dma-mapping.c line 139

Quoted 10 lines
arch/nios2/mm/dma-mapping.c new file +10 -0
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+                             size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}
+EXPORT_SYMBOL(dma_sync_single_for_device);

More importantly: you do the same operation for both _for_cpu and _for_device. I assume your CPU can never do speculative cache prefetches, so it's not incorrect, but you do twice the number of invalidations and flushes that you need.

Quoted 1 line

Why would you do anything for _for_cpu here?

I am a bit confused for _for_cpu and _for_device here. I found some architectures like c6x and hexagon have same operation for both _for_cpu and _for_device as well.
I have spent some times look at other architectures and below is what I found. Please correct me if I am wrong, especially for_device():DMA_FROM_DEVICE.

_for_cpu():
case DMA_BIDIRECTIONAL:
case DMA_FROM_DEVICE:

     /* invalidate cache */

break;
case DMA_TO_DEVICE:
/* do nothing */
break;

-------------------------
_for_device():
case DMA_BIDIRECTIONAL:
case DMA_TO_DEVICE:

     /* flush and invalidate cache */

break;
case DMA_FROM_DEVICE:
/* should we invalidate cache or do nothing? */
break;

Thanks for review.

Regards
Ley Foon

maintainer
#35 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

Quoted 16 lines · On Thursday 24 July 2014 19:37:11 Ley Foon Tan wrote:
Quoted 5 lines · Arnd Bergmann
Quoted 3 lines · On Tuesday 15 July 2014 16:45:40 Ley Foon Tan wrote:
arch/nios2/include/asm/dma-mapping.h new file +3 -0
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+

...

Quoted 10 lines

arch/nios2/include/asm/dma-mapping.h line 104

Quoted 5 lines
arch/nios2/include/asm/dma-mapping.h new file +5 -0
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
+                               enum dma_data_direction direction)
+{
+     __dma_sync(vaddr, size, direction);
+}

IIRC dma_cache_sync should be empty if you define dma_alloc_noncoherent to be the same as dma_alloc_coherent: It's already coherent, so no sync should be needed. What does the CPU do if you try to invalidate the cache on a coherent mapping?

Quoted 6 lines

Okay, I got what you mean here. I will leave this dma_cache_sync() function empty.
The CPU just do nothing if we try to invalidate cache on a coherent region. BTW, I found many other architectures still provide dma_cache_sync() even they define dma_alloc_noncoherent
same as dma_alloc_coherent. Eg: blackfin, x86 or xtense.

They are probably all wrong ;-)

It's not a big issue though, since the x86 operation is cheap and the other ones don't support any of the drivers that use dma_cache_sync.

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
arch/nios2/mm/dma-mapping.c new file +7 -0
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                          size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}

arch/nios2/mm/dma-mapping.c line 139

Quoted 10 lines
arch/nios2/mm/dma-mapping.c new file +10 -0
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+                             size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}
+EXPORT_SYMBOL(dma_sync_single_for_device);

More importantly: you do the same operation for both _for_cpu and _for_device. I assume your CPU can never do speculative cache prefetches, so it's not incorrect, but you do twice the number of invalidations and flushes that you need.

Quoted 4 lines
Quoted 1 line

Why would you do anything for _for_cpu here?

I am a bit confused for _for_cpu and _for_device here. I found some architectures like c6x and hexagon have same operation for both _for_cpu and _for_device as well.

(adding their maintainers to cc)

Yes, you are right, they seem to have the same bug and could see a noticeable DMA performance improvement if they change it as well.

Quoted 4 lines

I have spent some times look at other architectures and below is what I found. Please correct me if I am wrong, especially for_device():DMA_FROM_DEVICE.

Quoted 8 lines

_for_cpu():
case DMA_BIDIRECTIONAL:
case DMA_FROM_DEVICE:

     /* invalidate cache */
break;
case DMA_TO_DEVICE:
   /* do nothing */

break;

This seems fine: for a FROM_DEVICE mapping, we have flushed all dirty entries during the _for_device or the map operation, so if any clean entries are around, they need to be invalidated in order to read the data from the device.

for TO_DEVICE, we don't care about the cache, because we are going to overwrite the data, and we don't need to do anything.

Quoted 9 lines

-------------------------
_for_device():
case DMA_BIDIRECTIONAL:
case DMA_TO_DEVICE:

     /* flush and invalidate cache */

break;
case DMA_FROM_DEVICE:
/* should we invalidate cache or do nothing? */
break;

You actually don't need to invalidate the TO_DEVICE mappings in both _for_device and _for_cpu. You have to flush them in for_device, and you have to invalidate them at least once, but don't need to invalidate them again in for_cpu if you have done that already in for_device and your CPU does not do any speculative prefetches that might populate the dcache.

In case of for_device FROM_DEVICE, you have to invalidate or flush the caches to ensure that no dirty cache lines are written to memory, but only if your CPU has a write-back cache rather than write-through.

For bidirectional mappings, you may have to flush and invalidate.

Arnd

#8 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

In reply to Ley Foon Tan
Quoted 11 lines · Ley Foon Tan
arch/nios2/include/asm/mmu.h new file +8 -0
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Taken from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive

arch/nios2/include/asm/mmu.h line 18

Quoted 10 lines
arch/nios2/include/asm/mmu.h new file +10 -0
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_H
+#define _ASM_NIOS2_MMU_H
+
+/* Default "unsigned long" context */
+typedef unsigned long mm_context_t;
+
+#endif /* _ASM_NIOS2_MMU_H */

Any chance you can use mmu.h from asm-generic instead?
It uses a struct with a single "unsigned long end_brk" member (unless CONFIG_BINFMT_ELF_FDPIC is defined).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#36 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

In reply to Arnd Bergmann
Quoted 24 lines · Arnd Bergmann
Quoted 24 lines
Quoted 24 lines
Quoted 7 lines
arch/nios2/mm/dma-mapping.c new file +7 -0
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                          size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}

arch/nios2/mm/dma-mapping.c line 139

Quoted 10 lines
arch/nios2/mm/dma-mapping.c new file +10 -0
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+                             size_t size, enum dma_data_direction direction)
+{
+     BUG_ON(!valid_dma_direction(direction));
+
+     __dma_sync(phys_to_virt(dma_handle), size, direction);
+}
+EXPORT_SYMBOL(dma_sync_single_for_device);

More importantly: you do the same operation for both _for_cpu and _for_device. I assume your CPU can never do speculative cache prefetches, so it's not incorrect, but you do twice the number of invalidations and flushes that you need.

Why would you do anything for _for_cpu here?

Quoted 9 lines
Quoted 3 lines

I am a bit confused for _for_cpu and _for_device here. I found some architectures like c6x and hexagon have same operation for both _for_cpu and _for_device as well.

(adding their maintainers to cc)

Yes, you are right, they seem to have the same bug and could see a noticeable DMA performance improvement if they change it as well.

Yep that's a bug. Thanks for pointing this out.

-Richard Kuo

Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#37 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

In reply to Arnd Bergmann
Quoted 13 lines · Arnd Bergmann
Quoted 4 lines

I have spent some times look at other architectures and below is what I found. Please correct me if I am wrong, especially for_device():DMA_FROM_DEVICE.

Quoted 8 lines

_for_cpu():
case DMA_BIDIRECTIONAL:
case DMA_FROM_DEVICE:

     /* invalidate cache */
break;
case DMA_TO_DEVICE:
   /* do nothing */

break;

Quoted 7 lines

This seems fine: for a FROM_DEVICE mapping, we have flushed all dirty entries during the _for_device or the map operation, so if any clean entries are around, they need to be invalidated in order to read the data from the device.

for TO_DEVICE, we don't care about the cache, because we are going to overwrite the data, and we don't need to do anything.

Okay.

Quoted 11 lines
Quoted 10 lines

-------------------------
_for_device():
case DMA_BIDIRECTIONAL:
case DMA_TO_DEVICE:

     /* flush and invalidate cache */

break;
case DMA_FROM_DEVICE:
/* should we invalidate cache or do nothing? */
break;

Quoted 6 lines

You actually don't need to invalidate the TO_DEVICE mappings in both _for_device and _for_cpu. You have to flush them in for_device, and you have to invalidate them at least once, but don't need to invalidate them again in for_cpu if you have done that already in for_device and your CPU does not do any speculative prefetches that might populate the dcache.

Nios2 processor doesn't have flush-cache-only instruction. Its flush instruction will do 2 operations, flush and invalidate cache.

Quoted 4 lines

In case of for_device FROM_DEVICE, you have to invalidate or flush the caches to ensure that no dirty cache lines are written to memory, but only if your CPU has a write-back cache rather than write-through.

Nios2 has a write-back cache. So, will do invalidate cache here.

Quoted 1 line

For bidirectional mappings, you may have to flush and invalidate.

To confirm, do you mean bidirectional for both for_device and for_cpu?

Thanks.

Regards
Ley Foon

#9 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

In reply to Geert Uytterhoeven
Quoted 18 lines · Geert Uytterhoeven
Quoted 17 lines · Ley Foon Tan
arch/nios2/include/asm/mmu.h new file +14 -0
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Taken from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_H
+#define _ASM_NIOS2_MMU_H
+
Quoted 8 lines

arch/nios2/include/asm/mmu.h line 18

Quoted 4 lines
arch/nios2/include/asm/mmu.h new file +4 -0
+/* Default "unsigned long" context */
+typedef unsigned long mm_context_t;
+
+#endif /* _ASM_NIOS2_MMU_H */

Any chance you can use mmu.h from asm-generic instead?
It uses a struct with a single "unsigned long end_brk" member (unless CONFIG_BINFMT_ELF_FDPIC is defined).

From asm-generic/mmu.h, it is for nommu implementations. So, I will keep this as it is now.

Thanks.

Regards
Ley Foon

#10 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

Quoted 28 lines · Ley Foon Tan
Quoted 18 lines · Geert Uytterhoeven
Quoted 17 lines · Ley Foon Tan
arch/nios2/include/asm/mmu.h new file +14 -0
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Taken from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_H
+#define _ASM_NIOS2_MMU_H
+
Quoted 8 lines

arch/nios2/include/asm/mmu.h line 18

Quoted 4 lines
arch/nios2/include/asm/mmu.h new file +4 -0
+/* Default "unsigned long" context */
+typedef unsigned long mm_context_t;
+
+#endif /* _ASM_NIOS2_MMU_H */

Any chance you can use mmu.h from asm-generic instead?
It uses a struct with a single "unsigned long end_brk" member (unless CONFIG_BINFMT_ELF_FDPIC is defined).

Quoted 2 lines

From asm-generic/mmu.h, it is for nommu implementations. So, I will keep this as it is now.

Right, you have a MMU.
I got confused by the "Taken from m68knommu" comment, and you still only need a single "unsigned long".

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#11 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

Quoted 29 lines · Geert Uytterhoeven
Quoted 28 lines · Ley Foon Tan
Quoted 26 lines · Geert Uytterhoeven
Quoted 11 lines · Ley Foon Tan
arch/nios2/include/asm/mmu.h new file +8 -0
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * Taken from m68knommu.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive

arch/nios2/include/asm/mmu.h line 18

Quoted 10 lines
arch/nios2/include/asm/mmu.h new file +10 -0
+ * for more details.
+ */
+
+#ifndef _ASM_NIOS2_MMU_H
+#define _ASM_NIOS2_MMU_H
+
+/* Default "unsigned long" context */
+typedef unsigned long mm_context_t;
+
+#endif /* _ASM_NIOS2_MMU_H */

Any chance you can use mmu.h from asm-generic instead?
It uses a struct with a single "unsigned long end_brk" member (unless CONFIG_BINFMT_ELF_FDPIC is defined).

Quoted 6 lines
Quoted 2 lines

From asm-generic/mmu.h, it is for nommu implementations. So, I will keep this as it is now.

Right, you have a MMU.
I got confused by the "Taken from m68knommu" comment, and you still only need a single "unsigned long".

That comment stems from the initial Nios II NOMMU port done by Microtronix. Since Nios II NOMMU support was dropped for mainline submission anyhow, it might be better to drop that comment to avoid any future confusion :)

Cheers
Tobias

#13 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

In reply to Ley Foon Tan
Quoted 16 lines · Ley Foon Tan

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map.

---
 arch/nios2/include/asm/mmu.h     |  18 +++
 arch/nios2/include/asm/page.h    | 113 +++++++++++++++++++
 arch/nios2/include/asm/uaccess.h | 233 +++++++++++++++++++++++++++++++++++++++
 arch/nios2/mm/init.c             | 142 ++++++++++++++++++++++++
 arch/nios2/mm/uaccess.c          | 162 +++++++++++++++++++++++++++
 5 files changed, 668 insertions(+)
 create mode 100644 arch/nios2/include/asm/mmu.h
 create mode 100644 arch/nios2/include/asm/page.h
 create mode 100644 arch/nios2/include/asm/uaccess.h
 create mode 100644 arch/nios2/mm/init.c
 create mode 100644 arch/nios2/mm/uaccess.c

[...]

Quoted 6 lines
arch/nios2/include/asm/page.h new file +0 -0
new file mode 100644
index 0000000..b89c1d6

arch/nios2/include/asm/page.h line 10

Quoted 10 lines
arch/nios2/include/asm/page.h new file +10 -0
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * MMU support based on asm/page.h from mips which is:
+ *
+ * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ *
+ * NOMMU support based on asm/page.h from m68knommu.

You might want to remove this line to avoid confusion, since NOMMU is not supported anymore in this submission of the NIOS II port.

Quoted 5 lines
arch/nios2/include/asm/page.h new file +5 -0
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
#3 lore raw

Re: [PATCH v2 02/29] nios2: Kernel booting and initialization

In reply to Ley Foon Tan
Quoted 20 lines · Ley Foon Tan

This patch adds the kernel booting and the initial setup code.

---
 arch/nios2/include/asm/entry.h | 152 ++++++++++++++++++++++++++++
 arch/nios2/include/asm/setup.h |  38 +++++++
 arch/nios2/kernel/head.S       | 175 ++++++++++++++++++++++++++++++++
 arch/nios2/kernel/setup.c      | 222 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 587 insertions(+)
 create mode 100644 arch/nios2/include/asm/entry.h
 create mode 100644 arch/nios2/include/asm/setup.h
 create mode 100644 arch/nios2/kernel/head.S
 create mode 100644 arch/nios2/kernel/setup.c
arch/nios2/include/asm/entry.h new file +0 -0
new file mode 100644
index 0000000..8b7cddd
@@ -0,0 +1,152 @@

[...]

Quoted 21 lines

+/*
+ * Stack layout in 'ret_from_exception':
+ *
+ * This allows access to the syscall arguments in registers r4-r8
+ *
+ * 0(sp) - r8
+ * 4(sp) - r9
+ * 8(sp) - r10
+ * C(sp) - r11
+ * 10(sp) - r12
+ * 14(sp) - r13
+ * 18(sp) - r14
+ * 1C(sp) - r15
+ * 20(sp) - r1
+ * 24(sp) - r2
+ * 28(sp) - r3
+ * 2C(sp) - r4
+ * 30(sp) - r5
+ * 34(sp) - r6
+ * 38(sp) - r7
+ * 3C(sp) - orig_r2

Quoted 8 lines

+ * 40(sp) - ra
+ * 44(sp) - fp
+ * 48(sp) - sp
+ * 4C(sp) - gp
+ * 50(sp) - estatus
+ * 54(sp) - status_extension (NOMMU only)
+ * 58(sp) - ea
+ */

status_extension no longer exists and orig_r7 is missing in the list above. Since this corresponds to the order of struct pt_regs anyhow, this comment seems rather pointless to me, so you might as well want to remove it altogether.

#14 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

In reply to Tobias Klauser
Quoted 31 lines · Tobias Klauser
Quoted 16 lines · Ley Foon Tan

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map.

---
 arch/nios2/include/asm/mmu.h     |  18 +++
 arch/nios2/include/asm/page.h    | 113 +++++++++++++++++++
 arch/nios2/include/asm/uaccess.h | 233 +++++++++++++++++++++++++++++++++++++++
 arch/nios2/mm/init.c             | 142 ++++++++++++++++++++++++
 arch/nios2/mm/uaccess.c          | 162 +++++++++++++++++++++++++++
 5 files changed, 668 insertions(+)
 create mode 100644 arch/nios2/include/asm/mmu.h
 create mode 100644 arch/nios2/include/asm/page.h
 create mode 100644 arch/nios2/include/asm/uaccess.h
 create mode 100644 arch/nios2/mm/init.c
 create mode 100644 arch/nios2/mm/uaccess.c

[...]

Quoted 11 lines
arch/nios2/include/asm/page.h new file +5 -0
new file mode 100644
index 0000000..b89c1d6
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2011 Tobias Klauser <[email protected]>
+ * Copyright (C) 2004 Microtronix Datacom Ltd.
+ *
+ * MMU support based on asm/page.h from mips which is:
Quoted 8 lines

arch/nios2/include/asm/page.h line 10

Quoted 5 lines
arch/nios2/include/asm/page.h new file +5 -0
+ *
+ * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
+ * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
+ *
+ * NOMMU support based on asm/page.h from m68knommu.

You might want to remove this line to avoid confusion, since NOMMU is not supported anymore in this submission of the NIOS II port.

Okay.

Thanks.

Regards
Ley Foon

#12 lore raw

Re: [PATCH v2 05/29] nios2: Memory management

In reply to Tobias Klauser
Quoted 6 lines · Tobias Klauser
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Any chance you can use mmu.h from asm-generic instead?
It uses a struct with a single "unsigned long end_brk" member (unless CONFIG_BINFMT_ELF_FDPIC is defined).

From asm-generic/mmu.h, it is for nommu implementations. So, I will keep this as it is now.

Quoted 8 lines
Quoted 3 lines

Right, you have a MMU.
I got confused by the "Taken from m68knommu" comment, and you still only need a single "unsigned long".

That comment stems from the initial Nios II NOMMU port done by Microtronix. Since Nios II NOMMU support was dropped for mainline submission anyhow, it might be better to drop that comment to avoid any future confusion :)

Okay, I will remove these nommu comments.

Thanks.

Regards
Ley Foon

#4 lore raw

Re: [PATCH v2 02/29] nios2: Kernel booting and initialization

In reply to Tobias Klauser
Quoted 30 lines · Tobias Klauser
Quoted 28 lines

+/*
+ * Stack layout in 'ret_from_exception':
+ *
+ * This allows access to the syscall arguments in registers r4-r8
+ *

+ *    0(sp) - r8
+ *    4(sp) - r9
+ *    8(sp) - r10
+ *    C(sp) - r11
+ *   10(sp) - r12
+ *   14(sp) - r13
+ *   18(sp) - r14
+ *   1C(sp) - r15
+ *   20(sp) - r1
+ *   24(sp) - r2
+ *   28(sp) - r3
+ *   2C(sp) - r4
+ *   30(sp) - r5
+ *   34(sp) - r6
+ *   38(sp) - r7
+ *   3C(sp) - orig_r2
+ *   40(sp) - ra
+ *   44(sp) - fp
+ *   48(sp) - sp
+ *   4C(sp) - gp
+ *   50(sp) - estatus
+ *   54(sp) - status_extension (NOMMU only)
+ *   58(sp) - ea
Quoted 1 line

+ */

Quoted 4 lines

status_extension no longer exists and orig_r7 is missing in the list above. Since this corresponds to the order of struct pt_regs anyhow, this comment seems rather pointless to me, so you might as well want to remove it altogether.

Okay, I will remove these comments.
Thanks for review.

Regards
Ley Foon

#38 lore raw

Re: [PATCH v2 13/29] nios2: DMA mapping API

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

More importantly: you do the same operation for both _for_cpu and _for_device. I assume your CPU can never do speculative cache prefetches, so it's not incorrect, but you do twice the number of invalidations and flushes that you need.

That's not necessarily a correct assumption. A lot of CPUs (x86, arm, parisc) feel entitled to speculate provided they have a TLB entry. Usually they don't just do it for a whim, so the cpu has to be doing something to cause the speculation, like reading from an adjacent page. However, for DMA you always have to assume the possibility (unless you really, really know the architecture cannot).

Therefore the pattern should be (assuming your bus doesn't need some kind of flush and all flushes are only for the CPU).

DMA_TO_DEVICE: flush before (_for_device) do nothing after (_for_cpu)

DMA_FROM_DEVICE: do nothing before (_for_device), invalidate after (_for_cpu)

DMA_BIDIRECTIONAL: flush before (_for_device) and invalidate after (_for_cpu).

James

#73 lore raw

Re: [PATCH v2 21/29] nios2: Futex operations

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann
Quoted 10 lines · On Friday 18 July 2014 11:42:34 Thomas Gleixner wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 1 line · On Friday 18 July 2014 14:07:42 Ley Foon Tan wrote:

On Thu, Jul 17, 2014 at 7:07 PM, Arnd Bergmann <[email protected]> wrote:

If this understanding is right, we can probably just merge the m68k implementation into the asm-generic version, as that does exactly that, and just isn't SMP safe. I'm still unsure whether I'm missing something here though, as everything else seems to do this in assembly, even for non-SMP machines that could use the trivial method that m68k has.

Quoted 3 lines

For UP relying of pagefault disable should be good enough indeed. I guess the asm for the other UP stuff results from looking at architectures or copying from architectures which did this in ASM

Quoted 5 lines

Ok, thanks for the confirmation!

Ley Foon Tan, I think the best way forward then is for you to take the m68k code and copy (or move) that into asm-generic/futex.h under an #ifndef CONFIG_SMP.

Yes, that should work.

I tried that a while ago for OpenRISC, but never cleant it up and sent it out.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#61 lore raw

Re: [PATCH v2 20/29] nios2: Cpuinfo handling

In reply to Ley Foon Tan
Quoted 27 lines · Ley Foon Tan
Quoted 15 lines · Arnd Bergmann

arch/nios2/kernel/cpuinfo.c line 188

Quoted 12 lines · On Tuesday 15 July 2014 16:45:47 Ley Foon Tan wrote:
arch/nios2/kernel/cpuinfo.c new file +12 -0
+static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
+{
+       unsigned long i = *pos;
+
+       return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
+}
+
+static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return cpuinfo_start(m, pos);
+}

Do you actually have SMP support?

Not.

Quoted 8 lines

arch/nios2/kernel/cpuinfo.c line 199

Quoted 6 lines
arch/nios2/kernel/cpuinfo.c new file +6 -0
+const struct seq_operations cpuinfo_op = {
+       .start  = cpuinfo_start,
+       .next   = cpuinfo_next,
+       .stop   = cpuinfo_stop,
+       .show   = show_cpuinfo
+};

If not, you can use single_start/next/stop here rather than defining your own.

Quoted 2 lines

Okay, I will look into your suggestion.
Thanks.

I have tried this. But, it seem that we can't use single_start/next/stop here. They are static functions to fs/seq_file.c.

Regards
Ley Foon

#45 lore raw

Re: [PATCH v2 16/29] nios2: Signal handling support

In reply to Richard Weinberger
Quoted 9 lines · Richard Weinberger

arch/nios2/kernel/signal.c line 27

Quoted 7 lines
arch/nios2/kernel/signal.c new file +7 -0
+
+#include <asm/ucontext.h>
+#include <asm/cacheflush.h>
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+static int do_signal(struct pt_regs *regs, int in_syscall);

Do you really need this prototype?

Yes, we don't need this. Will remove this.

Quoted 14 lines
Quoted 14 lines
arch/nios2/kernel/signal.c new file +14 -0
+
+asmlinkage int do_rt_sigreturn(struct switch_stack *sw)
+{
+       struct pt_regs *regs = (struct pt_regs *)(sw + 1);
+       /* Verify, can we follow the stack back */
+       struct rt_sigframe *frame = (struct rt_sigframe *) regs->sp;
+       sigset_t set;
+       int rval;
+
+       if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
+               goto badframe;
+
+       if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+               goto badframe;
Quoted 8 lines

arch/nios2/kernel/signal.c line 121

Quoted 6 lines
arch/nios2/kernel/signal.c new file +6 -0
+
+       sigdelsetmask(&set, ~_BLOCKABLE);
+       spin_lock_irq(&current->sighand->siglock);
+       current->blocked = set;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);

Why aren't you using set_current_blocked() here?

Okay, will change to use set_current_blocked().

Quoted 11 lines
Quoted 11 lines
arch/nios2/kernel/signal.c new file +11 -0
+static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+                         struct pt_regs *regs)
+{
+       struct rt_sigframe *frame;
+       int err = 0;
+
+       frame = get_sigframe(ksig, regs, sizeof(*frame));
+
+       if (ksig->ka.sa.sa_flags & SA_SIGINFO)
+               err |= copy_siginfo_to_user(&frame->info, &ksig->info);
+
Quoted 8 lines

arch/nios2/kernel/signal.c line 208

Quoted 6 lines
arch/nios2/kernel/signal.c new file +6 -0
+       /* Create the ucontext.  */
+       err |= __put_user(0, &frame->uc.uc_flags);
+       err |= __put_user(0, &frame->uc.uc_link);
+       err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
+       err |= rt_setup_ucontext(&frame->uc, regs);
+       err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

You neither check nor propagate this error code.

Okay, will add error handling here.

Thanks.

Regards
Ley Foon