OpenRISC Architecture: Patch set version 2
Subsystems (9)
Jonas Bonn
maintainerThis is version 2 of the OpenRISC architecture patch set. Changes since version 1 include:
- general cleanups, removing unused code and variables, taking care of compiler warnings, etc.
- cleanups for all the errors spotted by checkpatch.pl
- changes in response to the feedback received for version 1 of the patch set
- simplification of the fixmap code
- simplification of the DMA code
- calculate loops_per_jiffy from cpu frequency passed in via devicetree
- rework io.h to use more generic code
- rework the delay code, making it more generic
- also, the module code has been reworked, making it more generic; this is not included in this patch as the generic parts are still pending review
Since version 1:
54 files changed, 793 insertions(+), 1900 deletions(-)
Once again, all this code can be found in the 'for-upstream' branch at:
git://openrisc.net/jonas/linux
Note, that there are three patches at the base of the branch that make some changes to generic kernel code that are necessary for the OpenRISC patches to work. Those patches aren't included in this post as they have already been posted for review earlier.
In this series:
[PATCH v2 01/19] OpenRISC: Boot code
[PATCH v2 02/19] OpenRISC: Device tree
[PATCH v2 03/19] OpenRISC: Memory management [PATCH v2 04/19] OpenRISC: Signal handling [PATCH v2 05/19] OpenRISC: Build infrastructure [PATCH v2 06/19] OpenRISC: PTrace
[PATCH v2 07/19] OpenRISC: DMA
[PATCH v2 08/19] OpenRISC: Timekeeping
[PATCH v2 09/19] OpenRISC: IRQ
[PATCH v2 10/19] OpenRISC: System calls
[PATCH v2 11/19] OpenRISC: Idle/Power management [PATCH v2 12/19] OpenRISC: Scheduling/Process management [PATCH v2 13/19] OpenRISC: GPIO
[PATCH v2 14/19] OpenRISC: Module support [PATCH v2 15/19] OpenRISC: Traps
[PATCH v2 16/19] OpenRISC: Headers
[PATCH v2 17/19] OpenRISC: Library routines [PATCH v2 18/19] OpenRISC: Miscellaneous
[PATCH v2 19/19] OpenRISC: Add MAINTAINERS entry
Looking forward to further feedback!
/Jonas
Diffstat for entire series:
MAINTAINERS | 8 + arch/openrisc/Kconfig | 207 ++++ arch/openrisc/Makefile | 66 ++ arch/openrisc/README.openrisc | 102 ++ arch/openrisc/TODO.openrisc | 18 + arch/openrisc/boot/Makefile | 15 + arch/openrisc/boot/dts/atlys.dts | 78 ++ arch/openrisc/boot/dts/or1ksim.dts | 73 ++ arch/openrisc/configs/or1ksim_defconfig | 67 ++ arch/openrisc/include/asm/Kbuild | 64 ++ arch/openrisc/include/asm/asm-offsets.h | 1 + arch/openrisc/include/asm/bitops.h | 59 ++ arch/openrisc/include/asm/bitops/__ffs.h | 33 + arch/openrisc/include/asm/bitops/__fls.h | 33 + arch/openrisc/include/asm/bitops/ffs.h | 32 + arch/openrisc/include/asm/bitops/fls.h | 33 + arch/openrisc/include/asm/byteorder.h | 1 + arch/openrisc/include/asm/cache.h | 29 + arch/openrisc/include/asm/cpuinfo.h | 34 + arch/openrisc/include/asm/delay.h | 24 + arch/openrisc/include/asm/dma-mapping.h | 62 ++ arch/openrisc/include/asm/elf.h | 109 ++ arch/openrisc/include/asm/fixmap.h | 88 ++ arch/openrisc/include/asm/gpio.h | 65 ++ arch/openrisc/include/asm/io.h | 51 + arch/openrisc/include/asm/irq.h | 27 + arch/openrisc/include/asm/irqflags.h | 29 + arch/openrisc/include/asm/linkage.h | 25 + arch/openrisc/include/asm/memblock.h | 24 + arch/openrisc/include/asm/mmu.h | 26 + arch/openrisc/include/asm/mmu_context.h | 43 + arch/openrisc/include/asm/mutex.h | 27 + arch/openrisc/include/asm/page.h | 112 +++ arch/openrisc/include/asm/param.h | 26 + arch/openrisc/include/asm/pgalloc.h | 142 +++ arch/openrisc/include/asm/pgtable.h | 449 +++++++++ arch/openrisc/include/asm/processor.h | 112 +++ arch/openrisc/include/asm/prom.h | 92 ++ arch/openrisc/include/asm/ptrace.h | 124 +++ arch/openrisc/include/asm/serial.h | 36 + arch/openrisc/include/asm/sigcontext.h | 38 + arch/openrisc/include/asm/spinlock.h | 24 + arch/openrisc/include/asm/spr.h | 42 + arch/openrisc/include/asm/spr_defs.h | 604 +++++++++++ arch/openrisc/include/asm/syscall.h | 77 ++ arch/openrisc/include/asm/syscalls.h | 27 + arch/openrisc/include/asm/system.h | 35 + arch/openrisc/include/asm/thread_info.h | 149 +++ arch/openrisc/include/asm/timex.h | 36 + arch/openrisc/include/asm/tlb.h | 34 + arch/openrisc/include/asm/tlbflush.h | 72 ++ arch/openrisc/include/asm/uaccess.h | 385 +++++++ arch/openrisc/include/asm/unaligned.h | 51 + arch/openrisc/include/asm/unistd.h | 29 + arch/openrisc/kernel/Makefile | 14 + arch/openrisc/kernel/asm-offsets.c | 70 ++ arch/openrisc/kernel/dma.c | 86 ++ arch/openrisc/kernel/entry.S | 1134 +++++++++++++++++++++ arch/openrisc/kernel/head.S | 1607 ++++++++++++++++++++++++++++++ arch/openrisc/kernel/idle.c | 77 ++ arch/openrisc/kernel/init_task.c | 41 + arch/openrisc/kernel/irq.c | 172 ++++ arch/openrisc/kernel/module.c | 126 +++ arch/openrisc/kernel/or32_ksyms.c | 46 + arch/openrisc/kernel/process.c | 305 ++++++ arch/openrisc/kernel/prom.c | 109 ++ arch/openrisc/kernel/ptrace.c | 574 +++++++++++ arch/openrisc/kernel/ptrace.h | 37 + arch/openrisc/kernel/setup.c | 386 +++++++ arch/openrisc/kernel/signal.c | 404 ++++++++ arch/openrisc/kernel/sys_call_table.c | 28 + arch/openrisc/kernel/sys_or32.c | 83 ++ arch/openrisc/kernel/time.c | 181 ++++ arch/openrisc/kernel/traps.c | 367 +++++++ arch/openrisc/kernel/vmlinux.h | 12 + arch/openrisc/kernel/vmlinux.lds.S | 115 +++ arch/openrisc/lib/Makefile | 5 + arch/openrisc/lib/delay.c | 60 ++ arch/openrisc/lib/string.S | 204 ++++ arch/openrisc/mm/Makefile | 5 + arch/openrisc/mm/fault.c | 338 +++++++ arch/openrisc/mm/init.c | 283 ++++++ arch/openrisc/mm/ioremap.c | 113 +++ arch/openrisc/mm/tlb.c | 191 ++++ arch/openrisc/or1ksim.cfg | 888 +++++++++++++++++ 85 files changed, 12310 insertions(+), 0 deletions(-)
Jonas Bonn
maintainerPATCH v2 1/19 OpenRISC: Boot code
Architecture code and early setup routines for booting Linux.
--- arch/openrisc/kernel/entry.S | 1134 +++++++++++++++++++++++++++ arch/openrisc/kernel/head.S | 1607 ++++++++++++++++++++++++++++++++++++++ arch/openrisc/kernel/init_task.c | 41 + arch/openrisc/kernel/setup.c | 387 +++++++++ 4 files changed, 3169 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/kernel/entry.S create mode 100644 arch/openrisc/kernel/head.S create mode 100644 arch/openrisc/kernel/init_task.c create mode 100644 arch/openrisc/kernel/setup.c
arch/openrisc/kernel/entry.S new file +1134 -0
@@ -0,0 +1,1134 @@ +/* + * OpenRISC entry.S + * + * Linux architectural port borrowing liberally from similar works of + * others. All original copyrights apply as per the original source + * declaration. + * + * Modifications for the OpenRISC architecture: + * Copyright (C) 2003 Matjaz Breskvar <[email protected]> + * Copyright (C) 2005 Gyorgy Jeney <[email protected]> + * Copyright (C) 2010-2011 Jonas Bonn <[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. + */ + +#include <linux/linkage.h> + +#include <asm/processor.h> +#include <asm/unistd.h> +#include <asm/thread_info.h> +#include <asm/errno.h> +#include <asm/spr_defs.h> +#include <asm/page.h> +#include <asm/mmu.h> +#include <asm/pgtable.h> +#include <asm/asm-offsets.h> + +#define DISABLE_INTERRUPTS(t1,t2) \ + l.mfspr t2,r0,SPR_SR ;\ + l.movhi t1,hi(~(SPR_SR_IEE|SPR_SR_TEE)) ;\ + l.ori t1,t1,lo(~(SPR_SR_IEE|SPR_SR_TEE)) ;\ + l.and t2,t2,t1 ;\ + l.mtspr r0,t2,SPR_SR + +#define ENABLE_INTERRUPTS(t1) \ + l.mfspr t1,r0,SPR_SR ;\ + l.ori t1,t1,lo(SPR_SR_IEE|SPR_SR_TEE) ;\ + l.mtspr r0,t1,SPR_SR + +/* =========================================================[ macros ]=== */ + +/* + * We need to disable interrupts at beginning of RESTORE_ALL + * since interrupt might come in after we've loaded EPC return address + * and overwrite EPC with address somewhere in RESTORE_ALL + * which is of course wrong! + */ + +#define RESTORE_ALL \ + DISABLE_INTERRUPTS(r3,r4) ;\ + l.lwz r3,PT_PC(r1) ;\ + l.mtspr r0,r3,SPR_EPCR_BASE ;\ + l.lwz r3,PT_SR(r1) ;\ + l.mtspr r0,r3,SPR_ESR_BASE ;\ + l.lwz r2,PT_GPR2(r1) ;\ + l.lwz r3,PT_GPR3(r1) ;\ + l.lwz r4,PT_GPR4(r1) ;\ + l.lwz r5,PT_GPR5(r1) ;\ + l.lwz r6,PT_GPR6(r1) ;\ + l.lwz r7,PT_GPR7(r1) ;\ + l.lwz r8,PT_GPR8(r1) ;\ + l.lwz r9,PT_GPR9(r1) ;\ + l.lwz r10,PT_GPR10(r1) ;\ + l.lwz r11,PT_GPR11(r1) ;\ + l.lwz r12,PT_GPR12(r1) ;\ + l.lwz r13,PT_GPR13(r1) ;\ + l.lwz r14,PT_GPR14(r1) ;\ + l.lwz r15,PT_GPR15(r1) ;\ + l.lwz r16,PT_GPR16(r1) ;\ + l.lwz r17,PT_GPR17(r1) ;\ + l.lwz r18,PT_GPR18(r1) ;\ + l.lwz r19,PT_GPR19(r1) ;\ + l.lwz r20,PT_GPR20(r1) ;\ + l.lwz r21,PT_GPR21(r1) ;\ + l.lwz r22,PT_GPR22(r1) ;\ + l.lwz r23,PT_GPR23(r1) ;\ + l.lwz r24,PT_GPR24(r1) ;\ + l.lwz r25,PT_GPR25(r1) ;\ + l.lwz r26,PT_GPR26(r1) ;\ + l.lwz r27,PT_GPR27(r1) ;\ + l.lwz r28,PT_GPR28(r1) ;\ + l.lwz r29,PT_GPR29(r1) ;\ + l.lwz r30,PT_GPR30(r1) ;\ + l.lwz r31,PT_GPR31(r1) ;\ + l.lwz r1,PT_SP(r1) ;\ + l.rfe + + +#define EXCEPTION_ENTRY(handler) \ + .global handler ;\ +handler: ;\ + /* r1, EPCR, ESR a already saved */ ;\ + l.sw PT_GPR2(r1),r2 ;\ + l.sw PT_GPR3(r1),r3 ;\ + l.sw PT_ORIG_GPR11(r1),r11 ;\ + /* r4 already save */ ;\ + l.sw PT_GPR5(r1),r5 ;\ + l.sw PT_GPR6(r1),r6 ;\ + l.sw PT_GPR7(r1),r7 ;\ + l.sw PT_GPR8(r1),r8 ;\ + l.sw PT_GPR9(r1),r9 ;\ + /* r10 already saved */ ;\ + l.sw PT_GPR11(r1),r11 ;\ + /* r12 already saved */ ;\ + l.sw PT_GPR13(r1),r13 ;\ + l.sw PT_GPR14(r1),r14 ;\ + l.sw PT_GPR15(r1),r15 ;\ + l.sw PT_GPR16(r1),r16 ;\ + l.sw PT_GPR17(r1),r17 ;\ + l.sw PT_GPR18(r1),r18 ;\ + l.sw PT_GPR19(r1),r19 ;\ + l.sw PT_GPR20(r1),r20 ;\ + l.sw PT_GPR21(r1),r21 ;\ + l.sw PT_GPR22(r1),r22 ;\ + l.sw PT_GPR23(r1),r23 ;\ + l.sw PT_GPR24(r1),r24 ;\ + l.sw PT_GPR25(r1),r25 ;\ + l.sw PT_GPR26(r1),r26 ;\ + l.sw PT_GPR27(r1),r27 ;\ + l.sw PT_GPR28(r1),r28 ;\ + l.sw PT_GPR29(r1),r29 ;\ + /* r30 already save */ ;\ +/* l.sw PT_GPR30(r1),r30*/ ;\ + l.sw PT_GPR31(r1),r31 ;\ + l.sw PT_SYSCALLNO(r1),r0 + +#define UNHANDLED_EXCEPTION(handler,vector) \ + .global handler ;\ +handler: ;\ + /* r1, EPCR, ESR already saved */ ;\ + l.sw PT_GPR2(r1),r2 ;\ + l.sw PT_GPR3(r1),r3 ;\ + l.sw PT_ORIG_GPR11(r1),r11 ;\ + l.sw PT_GPR5(r1),r5 ;\ + l.sw PT_GPR6(r1),r6 ;\ + l.sw PT_GPR7(r1),r7 ;\ + l.sw PT_GPR8(r1),r8 ;\ + l.sw PT_GPR9(r1),r9 ;\ + /* r10 already saved */ ;\ + l.sw PT_GPR11(r1),r11 ;\ + /* r12 already saved */ ;\ + l.sw PT_GPR13(r1),r13 ;\ + l.sw PT_GPR14(r1),r14 ;\ + l.sw PT_GPR15(r1),r15 ;\ + l.sw PT_GPR16(r1),r16 ;\ + l.sw PT_GPR17(r1),r17 ;\ + l.sw PT_GPR18(r1),r18 ;\ + l.sw PT_GPR19(r1),r19 ;\ + l.sw PT_GPR20(r1),r20 ;\ + l.sw PT_GPR21(r1),r21 ;\ + l.sw PT_GPR22(r1),r22 ;\ + l.sw PT_GPR23(r1),r23 ;\ + l.sw PT_GPR24(r1),r24 ;\ + l.sw PT_GPR25(r1),r25 ;\ + l.sw PT_GPR26(r1),r26 ;\ + l.sw PT_GPR27(r1),r27 ;\ + l.sw PT_GPR28(r1),r28 ;\ + l.sw PT_GPR29(r1),r29 ;\ + /* r31 already saved */ ;\ + l.sw PT_GPR30(r1),r30 ;\ +/* l.sw PT_GPR31(r1),r31 */ ;\ + l.sw PT_SYSCALLNO(r1),r0 ;\ + l.addi r3,r1,0 ;\ + /* r4 is exception EA */ ;\ + l.addi r5,r0,vector ;\ + l.jal unhandled_exception ;\ + l.nop ;\ + l.j _ret_from_exception ;\ + l.nop + +/* + * NOTE: one should never assume that SPR_EPC, SPR_ESR, SPR_EEAR + * contain the same values as when exception we're handling + * occured. in fact they never do. if you need them use + * values saved on stack (for SPR_EPC, SPR_ESR) or content + * of r4 (for SPR_EEAR). for details look at EXCEPTION_HANDLE() + * in 'arch/or32/kernel/head.S' + */ + +/* =====================================================[ exceptions] === */ + +/* ---[ 0x100: RESET exception ]----------------------------------------- */ + +EXCEPTION_ENTRY(_tng_kernel_start) + l.jal _start + l.andi r0,r0,0 + +/* ---[ 0x200: BUS exception ]------------------------------------------- */ + +EXCEPTION_ENTRY(_bus_fault_handler) + /* r4: EA of fault (set by EXCEPTION_HANDLE) */ + l.jal do_bus_fault + l.addi r3,r1,0 /* pt_regs */ + + l.j _ret_from_exception + l.nop + +/* ---[ 0x300: Data Page Fault exception ]------------------------------- */ + +EXCEPTION_ENTRY(_data_page_fault_handler) + /* set up parameters for do_page_fault */ + l.addi r3,r1,0 // pt_regs + /* r4 set be EXCEPTION_HANDLE */ // effective address of fault + l.ori r5,r0,0x300 // exception vector + + /* + * __PHX__: TODO + * + * all this can be written much simpler. look at + * DTLB miss handler in the CONFIG_GUARD_PROTECTED_CORE part + */ +#ifdef CONFIG_OPENRISC_NO_SPR_SR_DSX + l.lwz r6,PT_PC(r3) // address of an offending insn + l.lwz r6,0(r6) // instruction that caused pf + + l.srli r6,r6,26 // check opcode for jump insn + l.sfeqi r6,0 // l.j + l.bf 8f + l.sfeqi r6,1 // l.jal + l.bf 8f + l.sfeqi r6,3 // l.bnf + l.bf 8f + l.sfeqi r6,4 // l.bf + l.bf 8f + l.sfeqi r6,0x11 // l.jr + l.bf 8f + l.sfeqi r6,0x12 // l.jalr + l.bf 8f + + l.nop + + l.j 9f + l.nop +8: + + l.lwz r6,PT_PC(r3) // address of an offending insn + l.addi r6,r6,4 + l.lwz r6,0(r6) // instruction that caused pf + l.srli r6,r6,26 // get opcode +9: + +#else + + l.mfspr r6,r0,SPR_SR // SR +// l.lwz r6,PT_SR(r3) // ESR + l.andi r6,r6,SPR_SR_DSX // check for delay slot exception + l.sfeqi r6,0x1 // exception happened in delay slot + l.bnf 7f + l.lwz r6,PT_PC(r3) // address of an offending insn + + l.addi r6,r6,4 // offending insn is in delay slot +7: + l.lwz r6,0(r6) // instruction that caused pf + l.srli r6,r6,26 // check opcode for write access +#endif + + l.sfgeui r6,0x34 // check opcode for write access + l.bnf 1f + l.sfleui r6,0x37 + l.bnf 1f + l.ori r6,r0,0x1 // write access + l.j 2f + l.nop +1: l.ori r6,r0,0x0 // !write access +2: + + /* call fault.c handler in or32/mm/fault.c */ + l.jal do_page_fault + l.nop + l.j _ret_from_exception + l.nop + +/* ---[ 0x400: Insn Page Fault exception ]------------------------------- */ + +EXCEPTION_ENTRY(_insn_page_fault_handler) + /* set up parameters for do_page_fault */ + l.addi r3,r1,0 // pt_regs + /* r4 set be EXCEPTION_HANDLE */ // effective address of fault + l.ori r5,r0,0x400 // exception vector + l.ori r6,r0,0x0 // !write access + + /* call fault.c handler in or32/mm/fault.c */ + l.jal do_page_fault + l.nop + l.j _ret_from_exception + l.nop + + +/* ---[ 0x500: Timer exception ]----------------------------------------- */ + +EXCEPTION_ENTRY(_timer_handler) + l.jal timer_interrupt + l.addi r3,r1,0 /* pt_regs */ + + l.j _ret_from_intr + l.nop + +/* ---[ 0x600: Aligment exception ]-------------------------------------- */ + +EXCEPTION_ENTRY(_alignment_handler) + /* r4: EA of fault (set by EXCEPTION_HANDLE) */ + l.jal do_unaligned_access + l.addi r3,r1,0 /* pt_regs */ + + l.j _ret_from_exception + l.nop + +#if 0 +EXCEPTION_ENTRY(_aligment_handler) +// l.mfspr r2,r0,SPR_EEAR_BASE /* Load the efective addres */ + l.addi r2,r4,0 +// l.mfspr r5,r0,SPR_EPCR_BASE /* Load the insn address */ + l.lwz r5,PT_PC(r1) + + l.lwz r3,0(r5) /* Load insn */ + l.srli r4,r3,26 /* Shift left to get the insn opcode */ + + l.sfeqi r4,0x00 /* Check if the load/store insn is in delay slot */ + l.bf jmp + l.sfeqi r4,0x01 + l.bf jmp + l.sfeqi r4,0x03 + l.bf jmp + l.sfeqi r4,0x04 + l.bf jmp + l.sfeqi r4,0x11 + l.bf jr + l.sfeqi r4,0x12 + l.bf jr + l.nop + l.j 1f + l.addi r5,r5,4 /* Increment PC to get return insn address */ + +jmp: + l.slli r4,r3,6 /* Get the signed extended jump length */ + l.srai r4,r4,4 + + l.lwz r3,4(r5) /* Load the real load/store insn */ + + l.add r5,r5,r4 /* Calculate jump target address */ + + l.j 1f + l.srli r4,r3,26 /* Shift left to get the insn opcode */ + +jr: + l.slli r4,r3,9 /* Shift to get the reg nb */ + l.andi r4,r4,0x7c + + l.lwz r3,4(r5) /* Load the real load/store insn */ + + l.add r4,r4,r1 /* Load the jump register value from the stack */ + l.lwz r5,0(r4) + + l.srli r4,r3,26 /* Shift left to get the insn opcode */ + + +1: +// l.mtspr r0,r5,SPR_EPCR_BASE + l.sw PT_PC(r1),r5 + + l.sfeqi r4,0x26 + l.bf lhs + l.sfeqi r4,0x25 + l.bf lhz + l.sfeqi r4,0x22 + l.bf lws + l.sfeqi r4,0x21 + l.bf lwz + l.sfeqi r4,0x37 + l.bf sh + l.sfeqi r4,0x35 + l.bf sw + l.nop + +1: l.j 1b /* I don't know what to do */ + l.nop + +lhs: l.lbs r5,0(r2) + l.slli r5,r5,8 + l.lbz r6,1(r2) + l.or r5,r5,r6 + l.srli r4,r3,19 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.j align_end + l.sw 0(r4),r5 + +lhz: l.lbz r5,0(r2) + l.slli r5,r5,8 + l.lbz r6,1(r2) + l.or r5,r5,r6 + l.srli r4,r3,19 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.j align_end + l.sw 0(r4),r5 + +lws: l.lbs r5,0(r2) + l.slli r5,r5,24 + l.lbz r6,1(r2) + l.slli r6,r6,16 + l.or r5,r5,r6 + l.lbz r6,2(r2) + l.slli r6,r6,8 + l.or r5,r5,r6 + l.lbz r6,3(r2) + l.or r5,r5,r6 + l.srli r4,r3,19 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.j align_end + l.sw 0(r4),r5 + +lwz: l.lbz r5,0(r2) + l.slli r5,r5,24 + l.lbz r6,1(r2) + l.slli r6,r6,16 + l.or r5,r5,r6 + l.lbz r6,2(r2) + l.slli r6,r6,8 + l.or r5,r5,r6 + l.lbz r6,3(r2) + l.or r5,r5,r6 + l.srli r4,r3,19 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.j align_end + l.sw 0(r4),r5 + +sh: + l.srli r4,r3,9 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.lwz r5,0(r4) + l.sb 1(r2),r5 + l.srli r5,r5,8 + l.j align_end + l.sb 0(r2),r5 + +sw: + l.srli r4,r3,9 + l.andi r4,r4,0x7c + l.add r4,r4,r1 + l.lwz r5,0(r4) + l.sb 3(r2),r5 + l.srli r5,r5,8 + l.sb 2(r2),r5 + l.srli r5,r5,8 + l.sb 1(r2),r5 + l.srli r5,r5,8 + l.j align_end + l.sb 0(r2),r5 + +align_end: + l.j _ret_from_intr + l.nop +#endif + +/* ---[ 0x700: Illegal insn exception ]---------------------------------- */ + +EXCEPTION_ENTRY(_illegal_instruction_handler) + /* r4: EA of fault (set by EXCEPTION_HANDLE) */ + l.jal do_illegal_instruction + l.addi r3,r1,0 /* pt_regs */ + + l.j _ret_from_exception + l.nop + +/* ---[ 0x800: External interrupt exception ]---------------------------- */ + +EXCEPTION_ENTRY(_external_irq_handler) +#ifdef CONFIG_OPENRISC_ESR_EXCEPTION_BUG_CHECK + l.lwz r4,PT_SR(r1) // were interrupts enabled ? + l.andi r4,r4,SPR_SR_IEE + l.sfeqi r4,0 + l.bnf 1f // ext irq enabled, all ok. + l.nop + + l.addi r1,r1,-0x8 + l.movhi r3,hi(42f) + l.ori r3,r3,lo(42f) + l.sw 0x0(r1),r3 + l.jal printk + l.sw 0x4(r1),r4 + l.addi r1,r1,0x8 + + .section .rodata, "a" +42: + .string "\n\rESR interrupt bug: in _external_irq_handler (ESR %x)\n\r" + .align 4 + .previous + + l.ori r4,r4,SPR_SR_IEE // fix the bug +// l.sw PT_SR(r1),r4 +1: +#endif + l.addi r3,r1,0 + l.movhi r8,hi(do_IRQ) + l.ori r8,r8,lo(do_IRQ) + l.jalr r8 + l.nop + l.j _ret_from_intr + l.nop + +/* ---[ 0x900: DTLB miss exception ]------------------------------------- */ + + +/* ---[ 0xa00: ITLB miss exception ]------------------------------------- */ + + +/* ---[ 0xb00: Range exception ]----------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0xb00,0xb00) + +/* ---[ 0xc00: Syscall exception ]--------------------------------------- */ + +/* + * Syscalls are a special type of exception in that they are + * _explicitly_ invoked by userspace and can therefore be + * held to conform to the same ABI as normal functions with + * respect to whether registers are preserved across the call + * or not. + */ + +/* Upon syscall entry we just save the callee-saved registers + * and not the call-clobbered ones. + */ + +_string_syscall_return: + .string "syscall return %ld \n\r\0" + .align 4 + +ENTRY(_sys_call_handler) + /* syscalls run with interrupts enabled */ + ENABLE_INTERRUPTS(r29) // enable interrupts, r29 is temp + + /* r1, EPCR, ESR a already saved */ + l.sw PT_GPR2(r1),r2 + /* r3-r8 must be saved because syscall restart relies + * on us being able to restart the syscall args... technically + * they should be clobbered, otherwise + */ + l.sw PT_GPR3(r1),r3 + /* r4 already saved */ + /* r4 holds the EEAR address of the fault, load the original r4 */ + l.lwz r4,PT_GPR4(r1) + l.sw PT_GPR5(r1),r5 + l.sw PT_GPR6(r1),r6 + l.sw PT_GPR7(r1),r7 + l.sw PT_GPR8(r1),r8 + l.sw PT_GPR9(r1),r9 + /* r10 already saved */ + l.sw PT_GPR11(r1),r11 + l.sw PT_ORIG_GPR11(r1),r11 + /* r12,r13 already saved */ + + /* r14-r28 (even) aren't touched by the syscall fast path below + * so we don't need to save them. However, the functions that return + * to userspace via a call to switch() DO need to save these because + * switch() effectively clobbers them... saving these registers for + * such functions is handled in their syscall wrappers (see fork, vfork, + * and clone, below). + + /* r30 is the only register we clobber in the fast path */ + /* r30 already saved */ +/* l.sw PT_GPR30(r1),r30 */ + /* This is used by do_signal to determine whether to check for + * syscall restart or not */ + l.sw PT_SYSCALLNO(r1),r11 + +_syscall_check_trace_enter: + /* If TIF_SYSCALL_TRACE is set, then we want to do syscall tracing */ + l.lwz r30,TI_FLAGS(r10) + l.andi r30,r30,_TIF_SYSCALL_TRACE + l.sfne r30,r0 + l.bf _syscall_trace_enter + l.nop + +_syscall_check: + /* Ensure that the syscall number is reasonable */ + l.sfgeui r11,__NR_syscalls + l.bf _syscall_badsys + l.nop + +_syscall_call: + l.movhi r29,hi(sys_call_table) + l.ori r29,r29,lo(sys_call_table) + l.slli r11,r11,2 + l.add r29,r29,r11 + l.lwz r29,0(r29) + + l.jalr r29 + l.nop + +_syscall_return: + /* All syscalls return here... just pay attention to ret_from_fork + * which does it in a round-about way. + */ + l.sw PT_GPR11(r1),r11 // save return value + +#if 0 +_syscall_debug: + l.movhi r3,hi(_string_syscall_return) + l.ori r3,r3,lo(_string_syscall_return) + l.ori r27,r0,1 + l.sw -4(r1),r27 + l.sw -8(r1),r11 + l.addi r1,r1,-8 + l.movhi r27,hi(printk) + l.ori r27,r27,lo(printk) + l.jalr r27 + l.nop + l.addi r1,r1,8 +#endif + +_syscall_check_trace_leave: + /* r30 is a callee-saved register so this should still hold the + * _TIF_SYSCALL_TRACE flag from _syscall_check_trace_enter above... + * _syscall_trace_leave expects syscall result to be in pt_regs->r11. + */ + l.sfne r30,r0 + l.bf _syscall_trace_leave + l.nop + +/* This is where the exception-return code begins... interrupts need to be + * disabled the rest of the way here because we can't afford to miss any + * interrupts that set NEED_RESCHED or SIGNALPENDING... really true? */ + +_syscall_check_work: + /* Here we need to disable interrupts */ + DISABLE_INTERRUPTS(r27,r29) + l.lwz r30,TI_FLAGS(r10) + l.andi r30,r30,_TIF_WORK_MASK + l.sfne r30,r0 + + l.bnf _syscall_resume_userspace + l.nop + + /* Work pending follows a different return path, so we need to + * make sure that all the call-saved registers get into pt_regs + * before branching... + */ + l.sw PT_GPR14(r1),r14 + l.sw PT_GPR16(r1),r16 + l.sw PT_GPR18(r1),r18 + l.sw PT_GPR20(r1),r20 + l.sw PT_GPR22(r1),r22 + l.sw PT_GPR24(r1),r24 + l.sw PT_GPR26(r1),r26 + l.sw PT_GPR28(r1),r28 + + /* _work_pending needs to be called with interrupts disabled */ + l.j _work_pending + l.nop + +_syscall_resume_userspace: +// ENABLE_INTERRUPTS(r29) + + +/* This is the hot path for returning to userspace from a syscall. If there's + * work to be done and the branch to _work_pending was taken above, then the + * return to userspace will be done via the normal exception return path... + * that path restores _all_ registers and will overwrite the "clobbered" + * registers with whatever garbage is in pt_regs -- that's OK because those + * registers are clobbered anyway and because the extra work is insignificant + * in the context of the extra work that _work_pending is doing. + +/* Once again, syscalls are special and only guarantee to preserve the + * same registers as a normal function call */ + +/* The assumption here is that the registers r14-r28 (even) are untouched and + * don't need to be restored... be sure that that's really the case! + */ + +/* This is still too much... we should only be restoring what we actually + * clobbered... we should even be using 'scratch' (odd) regs above so that + * we don't need to restore anything, hardly... + */ + + l.lwz r2,PT_GPR2(r1) + + /* Restore args */ + /* r3-r8 are technically clobbered, but syscall restart needs these + * to be restored... + */ + l.lwz r3,PT_GPR3(r1) + l.lwz r4,PT_GPR4(r1) + l.lwz r5,PT_GPR5(r1) + l.lwz r6,PT_GPR6(r1) + l.lwz r7,PT_GPR7(r1) + l.lwz r8,PT_GPR8(r1) + + l.lwz r9,PT_GPR9(r1) + l.lwz r10,PT_GPR10(r1) + l.lwz r11,PT_GPR11(r1) + + /* r30 is the only register we clobber in the fast path */ + l.lwz r30,PT_GPR30(r1) + + /* Here we use r13-r19 (odd) as scratch regs */ + l.lwz r13,PT_PC(r1) + l.lwz r15,PT_SR(r1) + l.lwz r1,PT_SP(r1) + /* Interrupts need to be disabled for setting EPCR and ESR + * so that another interrupt doesn't come in here and clobber + * them before we can use them for our l.rfe */ + DISABLE_INTERRUPTS(r17,r19) + l.mtspr r0,r13,SPR_EPCR_BASE + l.mtspr r0,r15,SPR_ESR_BASE + l.rfe + +/* End of hot path! + * Keep the below tracing and error handling out of the hot path... +*/ + +_syscall_trace_enter: + /* Here we pass pt_regs to do_syscall_trace_enter. Make sure + * that function is really getting all the info it needs as + * pt_regs isn't a complete set of userspace regs, just the + * ones relevant to the syscall... + * + * Note use of delay slot for setting argument. + */ + l.jal do_syscall_trace_enter + l.addi r3,r1,0 + + /* Restore arguments (not preserved across do_syscall_trace_enter) + * so that we can do the syscall for real and return to the syscall + * hot path. + */ + l.lwz r11,PT_SYSCALLNO(r1) + l.lwz r3,PT_GPR3(r1) + l.lwz r4,PT_GPR4(r1) + l.lwz r5,PT_GPR5(r1) + l.lwz r6,PT_GPR6(r1) + l.lwz r7,PT_GPR7(r1) + + l.j _syscall_check + l.lwz r8,PT_GPR8(r1) + +_syscall_trace_leave: + l.jal do_syscall_trace_leave + l.addi r3,r1,0 + + l.j _syscall_check_work + l.nop + +_syscall_badsys: + /* Here we effectively pretend to have executed an imaginary + * syscall that returns -ENOSYS and then return to the regular + * syscall hot path. + * Note that "return value" is set in the delay slot... + */ + l.j _syscall_return + l.addi r11,r0,-ENOSYS + +/******* END SYSCALL HANDLING *******/ + +/* ---[ 0xd00: Trap exception ]------------------------------------------ */ + +UNHANDLED_EXCEPTION(_vector_0xd00,0xd00) + +/* ---[ 0xe00: Trap exception ]------------------------------------------ */ + +EXCEPTION_ENTRY(_trap_handler) + /* r4: EA of fault (set by EXCEPTION_HANDLE) */ + l.jal do_trap + l.addi r3,r1,0 /* pt_regs */ + + l.j _ret_from_exception + l.nop + +/* ---[ 0xf00: Reserved exception ]-------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0xf00,0xf00) + +/* ---[ 0x1000: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1000,0x1000) + +/* ---[ 0x1100: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1100,0x1100) + +/* ---[ 0x1200: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1200,0x1200) + +/* ---[ 0x1300: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1300,0x1300) + +/* ---[ 0x1400: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1400,0x1400) + +/* ---[ 0x1500: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1500,0x1500) + +/* ---[ 0x1600: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1600,0x1600) + +/* ---[ 0x1700: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1700,0x1700) + +/* ---[ 0x1800: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1800,0x1800) + +/* ---[ 0x1900: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1900,0x1900) + +/* ---[ 0x1a00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1a00,0x1a00) + +/* ---[ 0x1b00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1b00,0x1b00) + +/* ---[ 0x1c00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1c00,0x1c00) + +/* ---[ 0x1d00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1d00,0x1d00) + +/* ---[ 0x1e00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1e00,0x1e00) + +/* ---[ 0x1f00: Reserved exception ]------------------------------------- */ + +UNHANDLED_EXCEPTION(_vector_0x1f00,0x1f00) + +/* ========================================================[ return ] === */ + +_work_pending: + /* + * if (current_thread_info->flags & _TIF_NEED_RESCHED) + * schedule(); + */ + l.lwz r5,TI_FLAGS(r10) + l.andi r3,r5,_TIF_NEED_RESCHED + l.sfnei r3,0 + l.bnf _work_notifysig + l.nop + l.jal schedule + l.nop + l.j _resume_userspace + l.nop + +/* Handle pending signals and notify-resume requests. + * do_notify_resume must be passed the latest pushed pt_regs, not + * necessarily the "userspace" ones. Also, pt_regs->syscallno + * must be set so that the syscall restart functionality works. + */ +_work_notifysig: + l.jal do_notify_resume + l.ori r3,r1,0 /* pt_regs */ + +_resume_userspace: + DISABLE_INTERRUPTS(r3,r4) + l.lwz r3,TI_FLAGS(r10) + l.andi r3,r3,_TIF_WORK_MASK + l.sfnei r3,0 + l.bf _work_pending + l.nop + +_restore_all: + RESTORE_ALL + /* This returns to userspace code */ + + +ENTRY(_ret_from_intr) +ENTRY(_ret_from_exception) + l.lwz r4,PT_SR(r1) + l.andi r3,r4,SPR_SR_SM + l.sfeqi r3,0 + l.bnf _restore_all + l.nop + l.j _resume_userspace + l.nop + +ENTRY(ret_from_fork) + l.jal schedule_tail + l.nop + + /* _syscall_returns expect r11 to contain return value */ + l.lwz r11,PT_GPR11(r1) + + /* The syscall fast path return expects call-saved registers + * r12-r28 to be untouched, so we restore them here as they + * will have been effectively clobbered when arriving here + * via the call to switch() + */ + l.lwz r12,PT_GPR12(r1) + l.lwz r14,PT_GPR14(r1) + l.lwz r16,PT_GPR16(r1) + l.lwz r18,PT_GPR18(r1) + l.lwz r20,PT_GPR20(r1) + l.lwz r22,PT_GPR22(r1) + l.lwz r24,PT_GPR24(r1) + l.lwz r26,PT_GPR26(r1) + l.lwz r28,PT_GPR28(r1) + + l.j _syscall_return + l.nop + +/* Since syscalls don't save call-clobbered registers, the args to + * kernel_thread_helper will need to be passed through callee-saved + * registers and copied to the parameter registers when the thread + * begins running. + * + * See arch/openrisc/kernel/process.c: + * The args are passed as follows: + * arg1 (r3) : passed in r20 + * arg2 (r4) : passed in r22 + */ + +ENTRY(_kernel_thread_helper) + l.or r3,r20,r0 + l.or r4,r22,r0 + l.movhi r31,hi(kernel_thread_helper) + l.ori r31,r31,lo(kernel_thread_helper) + l.jr r31 + l.nop + + +/* ========================================================[ switch ] === */ + +/* + * This routine switches between two different tasks. The process + * state of one is saved on its kernel stack. Then the state + * of the other is restored from its kernel stack. The memory + * management hardware is updated to the second process's state. + * Finally, we can return to the second process, via the 'return'. + * + * Note: there are two ways to get to the "going out" portion + * of this code; either by coming in via the entry (_switch) + * or via "fork" which must set up an environment equivalent + * to the "_switch" path. If you change this (or in particular, the + * SAVE_REGS macro), you'll have to change the fork code also. + */ + + +/* _switch MUST never lay on page boundry, cause it runs from + * effective addresses and beeing interrupted by iTLB miss would kill it. + * dTLB miss seams to never accour in the bad place since data accesses + * are from task structures which are always page aligned. + * + * The problem happens in RESTORE_ALL_NO_R11 where we first set the EPCR + * register, then load the previous register values and only at the end call + * the l.rfe instruction. If get TLB miss in beetwen the EPCR register gets + * garbled and we end up calling l.rfe with the wrong EPCR. (same probably + * holds for ESR) + * + * To avoid this problems it is sufficient to align _switch to + * some nice round number smaller than it's size... + */ + +/* ABI rules apply here... we either enter _switch via schedule() or via + * an imaginary call to which we shall return at return_from_fork. Either + * way, we are a function call and only need to preserve the callee-saved + * registers when we return. As such, we don't need to save the registers + * on the stack that we won't be returning as they were... + */ + + .align 0x400 +ENTRY(_switch) + /* We don't store SR as _switch only gets called in a context where + * the SR will be the same going in and coming out... */ + + /* Set up new pt_regs struct for saving task state */ + l.addi r1,r1,-(INT_FRAME_SIZE) + + /* No need to store r1/PT_SP as it goes into KSP below */ + l.sw PT_GPR2(r1),r2 + l.sw PT_GPR9(r1),r9 + /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being + * and expects r12 to be callee-saved... */ + l.sw PT_GPR12(r1),r12 + l.sw PT_GPR14(r1),r14 + l.sw PT_GPR16(r1),r16 + l.sw PT_GPR18(r1),r18 + l.sw PT_GPR20(r1),r20 + l.sw PT_GPR22(r1),r22 + l.sw PT_GPR24(r1),r24 + l.sw PT_GPR26(r1),r26 + l.sw PT_GPR28(r1),r28 + l.sw PT_GPR30(r1),r30 + + l.addi r11,r10,0 /* Save old 'current' to 'last' return value*/ + + /* We use thread_info->ksp for storing the address of the above + * structure so that we can get back to it later... we don't want + * to lose the value of thread_info->ksp, though, so store it as + * pt_regs->sp so that we can easily restore it when we are made + * live again... + */ + + /* Save the old value of thread_info->ksp as pt_regs->sp */ + l.lwz r29,TI_KSP(r10) + l.sw PT_SP(r1),r29 + + /* Swap kernel stack pointers */ + l.sw TI_KSP(r10),r1 /* Save old stack pointer */ + l.or r10,r4,r0 /* Set up new current_thread_info */ + l.lwz r1,TI_KSP(r10) /* Load new stack pointer */ + + /* Restore the old value of thread_info->ksp */ + l.lwz r29,PT_SP(r1) + l.sw TI_KSP(r10),r29 + + /* ...and restore the registers, except r11 because the return value + * has already been set above. + */ + l.lwz r2,PT_GPR2(r1) + l.lwz r9,PT_GPR9(r1) + /* No need to restore r10 */ + /* ...and do not restore r11 */ + + /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being + * and expects r12 to be callee-saved... */ + l.lwz r12,PT_GPR12(r1) + l.lwz r14,PT_GPR14(r1) + l.lwz r16,PT_GPR16(r1) + l.lwz r18,PT_GPR18(r1) + l.lwz r20,PT_GPR20(r1) + l.lwz r22,PT_GPR22(r1) + l.lwz r24,PT_GPR24(r1) + l.lwz r26,PT_GPR26(r1) + l.lwz r28,PT_GPR28(r1) + l.lwz r30,PT_GPR30(r1) + + /* Unwind stack to pre-switch state */ + l.addi r1,r1,(INT_FRAME_SIZE) + + /* Return via the link-register back to where we 'came from', where that can be + * either schedule() or return_from_fork()... */ + l.jr r9 + l.nop + +/* ==================================================================== */ + +/* These all use the delay slot for setting the argument register, so the + * jump is always happening after the l.addi instruction. + * + * These are all just wrappers that don't touch the link-register r9, so the + * return from the "real" syscall function will return back to the syscall + * code that did the l.jal that brought us here. + */ + +/* fork requires that we save all the callee-saved registers because they + * are all effectively clobbered by the call to _switch. Here we store + * all the registers that aren't touched by the syscall fast path and thus + * weren't saved there. + */ + +_fork_save_extra_regs_and_call: + l.sw PT_GPR14(r1),r14 + l.sw PT_GPR16(r1),r16 + l.sw PT_GPR18(r1),r18 + l.sw PT_GPR20(r1),r20 + l.sw PT_GPR22(r1),r22 + l.sw PT_GPR24(r1),r24 + l.sw PT_GPR26(r1),r26 + l.jr r29 + l.sw PT_GPR28(r1),r28 + +ENTRY(sys_clone) + l.movhi r29,hi(_sys_clone) + l.ori r29,r29,lo(_sys_clone) + l.j _fork_save_extra_regs_and_call + l.addi r7,r1,0 + +ENTRY(sys_fork) + l.movhi r29,hi(_sys_fork) + l.ori r29,r29,lo(_sys_fork) + l.j _fork_save_extra_regs_and_call + l.addi r3,r1,0 + +ENTRY(sys_vfork) + l.movhi r29,hi(_sys_vfork) + l.ori r29,r29,lo(_sys_vfork) + l.j _fork_save_extra_regs_and_call + l.addi r3,r1,0 + +ENTRY(sys_execve) + l.j _sys_execve + l.addi r6,r1,0 + +ENTRY(sys_sigaltstack) + l.j _sys_sigaltstack + l.addi r5,r1,0 + +ENTRY(sys_rt_sigreturn) + l.j _sys_rt_sigreturn + l.addi r3,r1,0 + +/* This is a catch-all syscall for atomic instructions for the OpenRISC 1000. + * The functions takes a variable number of parameters depending on which + * particular flavour of atomic you want... parameter 1 is a flag identifying + * the atomic in question. Currently, this function implements the + * following variants: + * + * XCHG: + * @flag: 1 + * @ptr1: + * @ptr2: + * Atomically exchange the values in pointers 1 and 2. + * + */ + +ENTRY(sys_or1k_atomic) + /* FIXME: This ignores r3 and always does an XCHG */ + DISABLE_INTERRUPTS(r17,r19) + l.lwz r30,0(r4) + l.lwz r28,0(r5) + l.sw 0(r4),r28 + l.sw 0(r5),r30 + ENABLE_INTERRUPTS(r17) + l.jr r9 + l.or r11,r0,r0 + +/* ============================================================[ EOF ]=== */
arch/openrisc/kernel/head.S new file +1607 -0
1,607 lines not on this page · raw message
arch/openrisc/kernel/init_task.c new file +41 -0
41 lines not on this page · raw message
arch/openrisc/kernel/setup.c new file +387 -0
218 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4.1
Part of the diff is not shown here. View the raw message.
Jonas Bonn
maintainerPATCH v2 2/19 OpenRISC: Device tree
In reply to Jonas BonnThe OpenRISC architecture uses the device tree infrastructure for the platform description. This is currently limited to having a device tree built into the kernel, but work is underway within the OpenRISC project to define how this device tree blob should be passed into the kernel from an external resource.
--- arch/openrisc/boot/dts/atlys.dts | 78 +++++++++++++++++++++++++ arch/openrisc/boot/dts/or1ksim.dts | 73 ++++++++++++++++++++++++ arch/openrisc/include/asm/prom.h | 92 ++++++++++++++++++++++++++++++ arch/openrisc/kernel/prom.c | 109 ++++++++++++++++++++++++++++++++++++ arch/openrisc/kernel/setup.c | 3 +- 5 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 arch/openrisc/boot/dts/atlys.dts create mode 100644 arch/openrisc/boot/dts/or1ksim.dts create mode 100644 arch/openrisc/include/asm/prom.h create mode 100644 arch/openrisc/kernel/prom.c
arch/openrisc/boot/dts/atlys.dts new file +78 -0
@@ -0,0 +1,78 @@ +/dts-v1/; +/ { + compatible = "digilent,atlys"; + #size-cells = <1>; + #address-cells = <1>; + + chosen { + bootargs = "console=tty0 console=uart,mmio,0x90000000,115200 debug video=ocfb:640x480-16@60"; + }; + + memory { + device_type = "memory"; + reg = <0x00000000 0x8000000>; + }; + + cpus { + cpu@0 { + compatible = "opencores,openrisc-1200"; + clock-frequency = <50000000>; + }; + }; + + /* The "soc" node */ + + soc { + /* Every node with children must specify address-cells and + size-cells; they are not inherited */ + #address-cells = <1>; + #size-cells = <1>; + device_type = "soc"; + + /* This is also a 1:1 mapping but limits size of mappable + region to 0x40000000 */ + ranges = <0x80000000 0x80000000 0x40000000>; + + /* An alternative is to specify an empty ranges here to + indicates 1:1 mapping of SOC addresses (device addresses) + to CPU addresses */ + /*ranges;*/ + + /* This SOC has only a single, implicit PIC, so define it + early and put the interrupt-parent property in the 'soc' + node so that it's inherited by all the children using + interrupts. + */ + interrupt-parent = <&pic>; + + /* Devices with interrupts need a 'parent', so we need to + define a controller */ + pic: pic@0 { + compatible = "opencores,or1k-pic"; + #interrupt-cells = <1>; + interrupt-controller; + }; + + serial0: serial@90000000 { + /* FIXME: device_type is still needed here... + should remove requirement from of_serial driver */ + device_type = "serial"; + compatible = "opencores,uart", "ns16550a"; + reg = <0x90000000 0x100>; + interrupts = <2>; + clock-frequency = <50000000>; + }; + + enet0: ethoc@92000000 { + compatible = "opencores,ethoc", "ethoc"; + reg = <0x92000000 0x53>; + interrupts = <4>; + local-mac-address = [02 de ad be ef 02]; + }; + + fb0: ocfb@97000000 { + compatible = "opencores,ocfb", "ocfb"; + reg = <0x97000000 0x1000>; + }; + }; +};
arch/openrisc/boot/dts/or1ksim.dts new file +73 -0
73 lines not on this page · raw message
arch/openrisc/include/asm/prom.h new file +92 -0
92 lines not on this page · raw message
arch/openrisc/kernel/prom.c new file +109 -0
109 lines not on this page · raw message
arch/openrisc/kernel/setup.c +1 -2
@@ -173,8 +173,7 @@ void __init setup_cpuinfo(void)unsigned long iccfgr,dccfgr;unsigned long cache_set_size, cache_ways;; - cpu = (struct device_node *)of_find_compatible_node (NULL , -NULL ,"opencores,openrisc-1200" ); + cpu =of_find_compatible_node (NULL ,NULL ,"opencores,openrisc-1200" );if (!cpu) {panic ("No compatible CPU found in device tree...\n" ); }
Signature · 1 line
1.7.4.1
Re: [PATCH v2 02/19] OpenRISC: Device tree
Quoted 2 lines
The OpenRISC architecture uses the device tree infrastructure for the platform description.
Hurray, world domination is one step closer ;-)
arch/openrisc/boot/dts/atlys.dts line 14
Quoted 4 lines
arch/openrisc/boot/dts/atlys.dts new file +4
-0+ memory { + device_type = "memory"; + reg = <0x00000000 0x8000000>; + };
Might want to write this as 0x08000000 (easier to read).
Review
Quoted 2 lines
(quoted diff) +2
-0+ cpus { + cpu@0 {
Any node with a textual unit address (@0) needs to have a "reg" property with the same address (and then the parent node, "cpus", should have #address-cells and #size-cells defined, probably to 1 and 0 resp. in this case).
You can just name the node "cpu" here.
arch/openrisc/boot/dts/atlys.dts line 54
Quoted 5 lines
arch/openrisc/boot/dts/atlys.dts new file +5
-0+ pic: pic@0 { + compatible = "opencores,or1k-pic"; + #interrupt-cells = <1>; + interrupt-controller; + };
Same thing here. Although, does your interrupt controller have any registers? You should describe them then.
arch/openrisc/boot/dts/atlys.dts line 60
Quoted 6 lines
arch/openrisc/boot/dts/atlys.dts new file +6
-0+ + serial0: serial@90000000 { + /* FIXME: device_type is still needed here... + should remove requirement from of_serial driver */ + device_type = "serial"; + compatible = "opencores,uart", "ns16550a";
Opencores has and always will have only one UART implementation? You should make the "compatible" name more specific ("opencores,uart-16550a" perhaps).
Review
Quoted 2 lines
(quoted diff) +2
-0+ enet0: ethoc@92000000 { + compatible = "opencores,ethoc", "ethoc";
Probably shouldn't have the "ethoc" there, way too generic a name.
Review
Quoted 1 line
(quoted diff) +1
-0+ reg = <0x92000000 0x53>;
0x53? Usually you write the size of the register block that is decoded, not just the size of the defined registers; so it would be 0x100 or something like that.
Segher
Re: [PATCH v2 02/19] OpenRISC: Device tree
In reply to Jonas BonnQuoted 28 lines · Jonas Bonn
The OpenRISC architecture uses the device tree infrastructure for the platform description. This is currently limited to having a device tree built into the kernel, but work is underway within the OpenRISC project to define how this device tree blob should be passed into the kernel from an external resource.
Signed-off-by Jonas Bonn <[email protected]>---
arch/openrisc/boot/dts/atlys.dts | 78 +++++++++++++++++++++++++arch/openrisc/boot/dts/or1ksim.dts| 73 ++++++++++++++++++++++++arch/openrisc/include/asm/prom.h| 92 ++++++++++++++++++++++++++++++arch/openrisc/kernel/prom.c| 109 ++++++++++++++++++++++++++++++++++++arch/openrisc/kernel/setup.c| 3 +-5 files changed, 353 insertions(+), 2 deletions(-)create mode 100644
arch/openrisc/boot/dts/atlys.dtscreate mode 100644arch/openrisc/boot/dts/or1ksim.dtscreate mode 100644arch/openrisc/include/asm/prom.hcreate mode 100644arch/openrisc/kernel/prom.carch/openrisc/boot/dts/atlys.dts new file +1
-0@@ -0,0 +1,78 @@ +/dts-v1/;
arch/openrisc/boot/dts/atlys.dts line 11
Quoted 10 lines
arch/openrisc/boot/dts/atlys.dts new file +10
-0+/ { + compatible = "digilent,atlys"; + #size-cells = <1>; + #address-cells = <1>; + + chosen { + bootargs = "console=tty0 console=uart,mmio,0x90000000,115200 debug video=ocfb:640x480-16@60"; + }; + + memory {
memory@0
arch/openrisc/boot/dts/atlys.dts line 19
Quoted 8 lines
arch/openrisc/boot/dts/atlys.dts new file +8
-0+ device_type = "memory"; + reg = <0x00000000 0x8000000>; + }; + + cpus { + cpu@0 { + compatible = "opencores,openrisc-1200"; + clock-frequency = <50000000>;
As Segher metioned, the cpus node should have #address/size-cells and the cpu@0 node should have "reg = <0>;".
arch/openrisc/boot/dts/atlys.dts line 30
Quoted 11 lines
arch/openrisc/boot/dts/atlys.dts new file +11
-0+ }; + }; + + /* The "soc" node */ + + soc { + /* Every node with children must specify address-cells and + size-cells; they are not inherited */ + #address-cells = <1>; + #size-cells = <1>; + device_type = "soc";
Drop device type. device_type only makes sense for systems with real OpenFirmware. Always use a 'compatible' property to identify a device. In this case you probably want the compatible list to include the name of the bus bridge plus "simple-bus".
Does it really make sense to have an SoC node for this board? I assume this is for a soft CPU system on a Diligent FPGA board. It is best if the device tree structure matches the actual bus layout of the chip and/or FPGA design. If the devices are directly on the CPU bus, then it is better to do without an soc node entirely and just put everything at the root.
arch/openrisc/boot/dts/atlys.dts line 39
Quoted 9 lines
arch/openrisc/boot/dts/atlys.dts new file +9
-0+ + /* This is also a 1:1 mapping but limits size of mappable + region to 0x40000000 */ + ranges = <0x80000000 0x80000000 0x40000000>; + + /* An alternative is to specify an empty ranges here to + indicates 1:1 mapping of SOC addresses (device addresses) + to CPU addresses */ + /*ranges;*/
ranges is a well documented property. You can drop the commented out empty ranges, and the comments attached to it.
arch/openrisc/boot/dts/atlys.dts line 46
Quoted 6 lines
arch/openrisc/boot/dts/atlys.dts new file +6
-0+ /* This SOC has only a single, implicit PIC, so define it + early and put the interrupt-parent property in the 'soc' + node so that it's inherited by all the children using + interrupts. + */ + interrupt-parent = <&pic>;
Put this at the root of the tree so that every node inherits it (unless explicitly overridden). You may very well end up with devices at the root of the tree which are not children of the SoC node.
arch/openrisc/boot/dts/atlys.dts line 59
Quoted 13 lines
arch/openrisc/boot/dts/atlys.dts new file +13
-0+ + /* Devices with interrupts need a 'parent', so we need to + define a controller */ + pic: pic@0 { + compatible = "opencores,or1k-pic"; + #interrupt-cells = <1>; + interrupt-controller; + }; + + serial0: serial@90000000 { + /* FIXME: device_type is still needed here... + should remove requirement from of_serial driver */ + device_type = "serial";
device_type should not be necessary at all any more in the current kernel. You can remove this now.
arch/openrisc/boot/dts/atlys.dts line 67
Quoted 8 lines
arch/openrisc/boot/dts/atlys.dts new file +8
-0+ compatible = "opencores,uart", "ns16550a"; + reg = <0x90000000 0x100>; + interrupts = <2>; + clock-frequency = <50000000>; + }; + + enet0: ethoc@92000000 { + compatible = "opencores,ethoc", "ethoc";
"ethoc" is too generic. Drop it. Also, since this represents a soft IP core, "opencores,ethoc" should probably include some indication of which version of the core is instantiated (same goes for the other "opencores,..." values in this file.
Finally, every new "compatible" value that is used in this device tree needs to be documented. Look in Documentation/devicetree/bindings. The documentation is used to guard against "binding drift" where the meaning of a compatible property is interpreted differently by different people.
arch/openrisc/boot/dts/atlys.dts line 70
Quoted 3 lines
arch/openrisc/boot/dts/atlys.dts new file +3
-0+ reg = <0x92000000 0x53>; + interrupts = <4>; + local-mac-address = [02 de ad be ef 02];
Don't do this. If you don't have a valid Ethernet address, it is probably better to leave the property out entirely, and let the kernel randomly generate one.
arch/openrisc/boot/dts/atlys.dts line 74
Quoted 4 lines
arch/openrisc/boot/dts/atlys.dts new file +4
-0+ }; + + fb0: ocfb@97000000 { + compatible = "opencores,ocfb", "ocfb";
"ocfb" too generic.
Quoted 30 lines
arch/openrisc/boot/dts/atlys.dts new file +4
-0+ reg = <0x97000000 0x1000>; + }; + }; +};arch/openrisc/boot/dts/or1ksim.dts new file +20
-0@@ -0,0 +1,73 @@ +/dts-v1/; +/ { + compatible = "opencores,or1ksim"; + #size-cells = <1>; + #address-cells = <1>; + + chosen { + bootargs = "console=uart,mmio,0x90000000,115200 debug"; + }; + + memory { + device_type = "memory"; + reg = <0x00000000 0x2000000>; + }; + + cpus { + cpu@0 { + compatible = "opencores,openrisc-1200"; + clock-frequency = <20000000>; + };
arch/openrisc/boot/dts/or1ksim.dts line 30
Quoted 10 lines
arch/openrisc/boot/dts/or1ksim.dts new file +10
-0+ }; + + /* The "soc" node */ + + soc { + /* Every node with children must specify address-cells and + size-cells; they are not inherited */ + #address-cells = <1>; + #size-cells = <1>; + device_type = "soc";
Drop device_type, blah blah blah... Most of my comments on the previous file apply here too.
Quoted 127 lines
arch/openrisc/boot/dts/or1ksim.dts new file +43
-0+ + /* This is also a 1:1 mapping but limits size of mappable + region to 0x40000000 */ + ranges = <0x80000000 0x80000000 0x40000000>; + + /* An alternative is to specify an empty ranges here to + indicates 1:1 mapping of SOC addresses (device addresses) + to CPU addresses */ + /*ranges;*/ + + /* This SOC has only a single, implicit PIC, so define it + early and put the interrupt-parent property in the 'soc' + node so that it's inherited by all the children using + interrupts. + */ + interrupt-parent = <&pic>; + + /* Devices with interrupts need a 'parent', so we need to + define a controller */ + pic: pic@0 { + compatible = "opencores,or1k-pic"; + #interrupt-cells = <1>; + interrupt-controller; + }; + + serial0: serial@90000000 { + /* FIXME: device_type is still needed here... + should remove requirement from of_serial driver */ + device_type = "serial"; + compatible = "opencores,uart", "ns16550a"; + reg = <0x90000000 0x100>; + interrupts = <2>; + clock-frequency = <20000000>; + }; + + enet0: ethoc@92000000 { + compatible = "opencores,ethoc", "ethoc"; + reg = <0x92000000 0x53>; + interrupts = <4>; + local-mac-address = [02 de ad be ef 02]; + }; + }; +};arch/openrisc/include/asm/prom.h new file +78
-0@@ -0,0 +1,92 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#include <linux/of.h> /* linux/of.h gets to determine #include ordering */ + +#ifndef _ASM_OPENRISC_PROM_H +#define _ASM_OPENRISC_PROM_H +#ifdef __KERNEL__ +#ifndef __ASSEMBLY__ + +#include <linux/types.h> +#include <asm/irq.h> +#include <asm/atomic.h> +#include <linux/of_irq.h> +#include <linux/of_fdt.h> +#include <linux/of_address.h> +#include <linux/proc_fs.h> +#include <linux/platform_device.h> +#define HAVE_ARCH_DEVTREE_FIXUPS + +/* Other Prototypes */ +extern int early_uartlite_console (void ); + +#ifdef CONFIG_PCI +/* +* PCI <-> OF matching functions +* (XXX should these be here?) +*/ +struct pci_bus ; +struct pci_dev ; +extern int pci_device_from_OF_node (struct device_node *node, + u8 *bus, u8 *devfn); +extern struct device_node *pci_busdev_to_OF_node (struct pci_bus *bus, + int devfn); +extern struct device_node *pci_device_to_OF_node (struct pci_dev *dev); +extern void pci_create_OF_bus_map (void ); +#endif + +/* Parse the ibm,dma-window property of an OF node into the busno, phys and +* size parameters. +*/ +void of_parse_dma_window (struct device_node *dn,const void *dma_window_prop, + unsigned long *busno, unsigned long *phys, unsigned long *size); + +extern void kdump_move_device_tree (void ); + +/* CPU OF node matching */ +struct device_node *of_get_cpu_node (int cpu,unsigned int *thread); + +/* Get the MAC address */ +extern const void *of_get_mac_address (struct device_node *np); + +/** +* of_irq_map_pci - Resolve the interrupt for a PCI device +* @pdev: the device whose interrupt is to be resolved +* @out_irq: structure of_irq filled by this function +* +* This function resolves the PCI interrupt for a given PCI device. If a +* device-node exists for a given pci_dev, it will use normal OF tree +* walking. If not, it will implement standard swizzling and walk up the +* PCI tree until an device-node is found, at which point it will finish +* resolving using the OF tree walking. +*/ +struct pci_dev ;
arch/openrisc/include/asm/prom.h line 88
Quoted 10 lines
arch/openrisc/include/asm/prom.h new file +10
-0+extern int of_irq_map_pci (struct pci_dev *pdev,struct of_irq *out_irq); + +/* This routine is here to provide compatibility with how powerpc +* handles IRQ mapping for OF device nodes. We precompute and permanently +* register them in the platform_device objects, whereas powerpc computes them +* on request. +*/ +static inline void irq_dispose_mapping (unsigned int virq) +{ +}
The need for this should hopefully go away in Linux v3.1 when I get the irq_domain stuff merged.
Quoted 85 lines
arch/openrisc/include/asm/prom.h new file +4
-0+ +#endif /* __ASSEMBLY__ */ +#endif /* __KERNEL__ */ +#endif /* _ASM_OPENRISC_PROM_H */ arch/openrisc/kernel/prom.c new file +75
-0@@ -0,0 +1,109 @@ +/* +* OpenRISC prom.c +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +* +* Architecture specific procedures for creating, accessing and +* interpreting the device tree. +* +*/ + +#include <stdarg.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/init.h> +#include <linux/threads.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/stringify.h> +#include <linux/delay.h> +#include <linux/initrd.h> +#include <linux/bitops.h> +#include <linux/module.h> +#include <linux/kexec.h> +#include <linux/debugfs.h> +#include <linux/irq.h> +#include <linux/memblock.h> +#include <linux/of_fdt.h> + +#include <asm/prom.h> +#include <asm/page.h> +#include <asm/processor.h> +#include <asm/irq.h> +#include <linux/io.h> +#include <asm/system.h> +#include <asm/mmu.h> +#include <asm/pgtable.h> +#include <asm/sections.h> +#include <asm/setup.h> + +extern char cmd_line[COMMAND_LINE_SIZE ]; + +void __init early_init_dt_add_memory_arch (u64 base,u64 size) +{ + size &= PAGE_MASK; + memblock_add(base, size); +} + +void *__init early_init_dt_alloc_memory_arch (u64 size,u64 align) +{ + return __va(memblock_alloc(size, align)); +} + +void __init early_init_devtree (void *params) +{ + u8 *alloc; + + /* Setup flat device-tree pointer */ + initial_boot_params = params; + + + /* Retrieve various informations from the /chosen node of the +* device-tree, including the platform type, initrd location and +* size, TCE reserve, and more ... +*/
arch/openrisc/kernel/prom.c line 85
Quoted 10 lines
arch/openrisc/kernel/prom.c new file +10
-0+ of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line); + + /* Scan memory nodes and rebuild MEMBLOCKs */ + memblock_init(); + of_scan_flat_dt(early_init_dt_scan_root, NULL); + of_scan_flat_dt(early_init_dt_scan_memory, NULL); + + /* Save command line for /proc/cmdline and then parse parameters */ + strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); +// parse_early_param();
This should just be removed?
arch/openrisc/kernel/prom.c line 98
Quoted 13 lines
arch/openrisc/kernel/prom.c new file +13
-0+ + memblock_analyze(); + + /* We must copy the flattend device tree from init memory to regular + * memory because the device tree references the strings in it + * directly. + */ + + alloc = __va(memblock_alloc(initial_boot_params->totalsize, PAGE_SIZE)); + + memcpy(alloc, initial_boot_params, initial_boot_params->totalsize); + + initial_boot_params = (void *) alloc;
If alloc gets declared as a 'void*', then this cast can be removed.
Quoted 16 lines
arch/openrisc/kernel/prom.c new file +11
-0+} + +#ifdef CONFIG_BLK_DEV_INITRD +void __init early_init_dt_setup_initrd_arch (unsigned long start, + unsigned long end) +{ + initrd_start = (unsigned long)__va(start); + initrd_end = (unsigned long)__va(end); + initrd_below_start_ok = 1; +} +#endif arch/openrisc/kernel/setup.c +0
-0
arch/openrisc/kernel/setup.c void __init setup_cpuinfo(void) · line 176
Quoted 6 lines
arch/openrisc/kernel/setup.c +1
-2@@ -173,8 +173,7 @@ void __init setup_cpuinfo(void) unsigned long iccfgr,dccfgr; unsigned long cache_set_size, cache_ways;; - cpu = (struct device_node *) of_find_compatible_node(NULL, - NULL, "opencores,openrisc-1200"); + cpu = of_find_compatible_node(NULL, NULL, "opencores,openrisc-1200");
This looks odd. Is it a stale hunk from a previous patch version?
Quoted 12 lines
arch/openrisc/kernel/setup.c +0
-1if (!cpu) { panic("No compatible CPU found in device tree...\n"); } --1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Re: [PATCH v2 02/19] OpenRISC: Device tree
Quoted 12 lines · Grant Likely
arch/openrisc/include/asm/prom.h
Quoted 11 lines
arch/openrisc/include/asm/prom.h new file +11
-0+ +#ifdef CONFIG_PCI +/* +* PCI <-> OF matching functions +* (XXX should these be here?) +*/ +struct pci_bus ; +struct pci_dev ; +extern int pci_device_from_OF_node (struct device_node *node, +u8 *bus,u8 *devfn); +extern struct device_node *pci_busdev_to_OF_node(struct pci_bus*bus,
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ int devfn); +extern struct device_node *pci_device_to_OF_node(struct pci_dev*dev);
arch/openrisc/include/asm/prom.h line 51
Quoted 2 lines
arch/openrisc/include/asm/prom.h new file +2
-0+extern void pci_create_OF_bus_map (void ); +#endif
Don't copy these from powermac or microblaze. the OF_bus_map is something that should not spread :-)
You get all you need of the above from generic code with my patches to PCI <-> OF matching, which should be in linux-next and are going to be merged in the next merge window.
Cheers,
Ben.
Jonas Bonn
maintainerRe: [PATCH v2 02/19] OpenRISC: Device tree
In reply to Grant LikelyQuoted 7 lines · Grant Likely
On Sat, Jul 2, 2011 at 3:15 PM, Jonas Bonn <[email protected]> wrote:
Does it really make sense to have an SoC node for this board? I assume this is for a soft CPU system on a Diligent FPGA board. It is best if the device tree structure matches the actual bus layout of the chip and/or FPGA design. If the devices are directly on the CPU bus, then it is better to do without an soc node entirely and just put everything at the root.
Not sure I quite understand the distinction here. Yes, it's a soft CPU, but conceptually it has an internal bus (Wishbone) comparable to the Avalon bus that the peripherals sit on. I'd say it's an SoC; but I need to ask: what constitutes a valid use of the "soc" node?
Quoted 8 lines
Quoted 8 lines
arch/openrisc/kernel/setup.c +0
-0@@ -173,8 +173,7 @@ void __init setup_cpuinfo(void)unsigned long iccfgr,dccfgr;unsigned long cache_set_size, cache_ways;;
Quoted 6 lines
arch/openrisc/kernel/setup.c void __init setup_cpuinfo(void) · line 176
Quoted 3 lines
arch/openrisc/kernel/setup.c +1
-2- cpu = (struct device_node *)of_find_compatible_node (NULL , -NULL ,"opencores,openrisc-1200" ); + cpu =of_find_compatible_node (NULL ,NULL ,"opencores,openrisc-1200" );This looks odd. Is it a stale hunk from a previous patch version?
Hmmm... no, it's a hunk that should have been in patch 01/19 of the series. That said, there's a bit of devicetree code in that patch too. Can I just say, "please have a look there, too", or do I need to pull those bits out into the devicetree patch?
I've pasted in just the relevant parts from patch 01/19 below for ease of review.
/Jonas
From arch/openrisc/kernel/setup.c:
+static inline unsigned int fcpu(struct device_node *cpu, char *n) +{
+ const int *val;
+ return (val = of_get_property(cpu, n, NULL)) ? *val : 0;
+}
+
+void __init setup_cpuinfo(void)
+{
+ struct device_node *cpu = NULL; + unsigned long iccfgr,dccfgr; + unsigned long cache_set_size, cache_ways;;
+
+ cpu = (struct device_node *) of_find_compatible_node(NULL,
+ NULL,
"opencores,openrisc-1200");
+ if (!cpu) {
+ panic("No compatible CPU found in device tree...\n");
+ }
+
+ iccfgr = mfspr(SPR_ICCFGR); + cache_ways = 1 << (iccfgr & SPR_ICCFGR_NCW); + cache_set_size = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); + cpuinfo.icache_block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >>
7);
+ cpuinfo.icache_size = cache_set_size * cache_ways *
cpuinfo.icache_block_size;
+
+ dccfgr = mfspr(SPR_DCCFGR); + cache_ways = 1 << (dccfgr & SPR_DCCFGR_NCW); + cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3); + cpuinfo.dcache_block_size = 16 << ((dccfgr & SPR_DCCFGR_CBS) >>
7);
+ cpuinfo.dcache_size = cache_set_size * cache_ways *
cpuinfo.dcache_block_size;
+
+ cpuinfo.clock_frequency = fcpu(cpu, "clock-frequency");
+
+ of_node_put(cpu);
+
+ print_cpuinfo();
+}
+
+/**
+ * or32_early_setup
+ *
+ * Handles the pointer to the device tree that this kernel is to use
+ * for establishing the available platform devices.
+ *
+ * For now, this is limited to using the built-in device tree. In the future,
+ * it is intended that this function will take a pointer to the device tree
+ * that is potentially built-in, but potentially also passed in by the
+ * bootloader, or discovered by some equally clever means...
+ */
+
+void __init or32_early_setup(void) {
+
+ early_init_devtree((void *) __dtb_start);
+
+ printk(KERN_INFO "Compiled-in FDT at 0x%08x\n",
+ (unsigned int) __dtb_start);
+}
+
+const struct of_device_id openrisc_bus_ids[] = {
+ { .type = "soc", },
+ { .compatible = "soc", },
+ {},+};
+
+static int __init openrisc_device_probe(void)
+{
+ of_platform_bus_probe(NULL, openrisc_bus_ids, NULL);
+ return 0;
+}
+device_initcall(openrisc_device_probe);
Re: [PATCH v2 02/19] OpenRISC: Device tree
Quoted 10 lines · Jonas Bonn
Quoted 7 lines · Grant Likely
On Sat, Jul 2, 2011 at 3:15 PM, Jonas Bonn <[email protected]> wrote:
Does it really make sense to have an SoC node for this board? I assume this is for a soft CPU system on a Diligent FPGA board. It is best if the device tree structure matches the actual bus layout of the chip and/or FPGA design. If the devices are directly on the CPU bus, then it is better to do without an soc node entirely and just put everything at the root.
Quoted 4 lines
Not sure I quite understand the distinction here. Yes, it's a soft CPU, but conceptually it has an internal bus (Wishbone) comparable to the Avalon bus that the peripherals sit on. I'd say it's an SoC; but I need to ask: what constitutes a valid use of the "soc" node?
An soc node is really just a convenient collection node for devices on an SoC. It can be used, or not, depending on the SoC and whoever is writing the bindings for it.
Regardless, the device tree hierarchy should reflect the actual layout of the buses, and devices on the same bus segment should be siblings in the tree. Often when I work on an FPGA system, I don't even bother with an soc node because it is kind of meaningless, and I just start with knowing that the root of the tree represents the CPU local bus, and then creating nodes for each bridge to another bus. If all the devices are on the same bus segment, then it looks pretty much like what you wrote except that the node name for the bridge would probably be something like "wishbone-bus".
Basically, I'm suggesting to make the DT model as representative of the FPGA design as possible.
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
arch/openrisc/kernel/setup.c +0
-0@@ -173,8 +173,7 @@ void __init setup_cpuinfo(void)unsigned long iccfgr,dccfgr;unsigned long cache_set_size, cache_ways;;Quoted 6 lines
arch/openrisc/kernel/setup.c void __init setup_cpuinfo(void) · line 176
Quoted 3 lines
arch/openrisc/kernel/setup.c +1
-2- cpu = (struct device_node *)of_find_compatible_node (NULL , -NULL ,"opencores,openrisc-1200" ); + cpu =of_find_compatible_node (NULL ,NULL ,"opencores,openrisc-1200" );This looks odd. Is it a stale hunk from a previous patch version?
Quoted 4 lines
Hmmm... no, it's a hunk that should have been in patch 01/19 of the series. That said, there's a bit of devicetree code in that patch too. Can I just say, "please have a look there, too", or do I need to pull those bits out into the devicetree patch?
No, you don't need to pull it out into this patch, but when you respin you should fix the series to not include this hunk in patch 2.
Review
Quoted 12 lines
I've pasted in just the relevant parts from patch 01/19 below for ease of review.
/Jonas
From
arch/openrisc/kernel/setup.c:(quoted diff) +4
-0+static inline unsigned int fcpu(struct device_node *cpu, char *n) +{ + const int *val; + return (val = of_get_property(cpu, n, NULL)) ? *val : 0;
be32_to_cpup(val) should be used here.
However, of_property_read_u32() is now available to be used with the correct data size checking.
arch/openrisc/kernel/prom.c
Quoted 5 lines
arch/openrisc/kernel/prom.c new file +5
-0+} + +void __init setup_cpuinfo (void ) +{ +struct device_node *cpu =NULL ;
No need to initialize this to NULL, it is immediately set at the start of the function.
Quoted 6 lines
(quoted diff) +5
-0+ unsigned long iccfgr,dccfgr; + unsigned long cache_set_size, cache_ways;; + + cpu = (struct device_node *) of_find_compatible_node(NULL, + NULL,"opencores,openrisc-1200");
Why the cast? I looks like it can be dropped.
Quoted 40 lines
(quoted diff) +8
-0+ if (!cpu) { + panic("No compatible CPU found in device tree...\n"); + } + + iccfgr = mfspr(SPR_ICCFGR); + cache_ways = 1 << (iccfgr & SPR_ICCFGR_NCW); + cache_set_size = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); + cpuinfo.icache_block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >>7);
+ cpuinfo.icache_size =cache_set_size*cache_ways*
cpuinfo.icache_block_size;(quoted diff) +5
-0+ + dccfgr = mfspr(SPR_DCCFGR); + cache_ways = 1 << (dccfgr & SPR_DCCFGR_NCW); + cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3); + cpuinfo.dcache_block_size = 16 << ((dccfgr & SPR_DCCFGR_CBS) >>7);
+ cpuinfo.dcache_size =cache_set_size*cache_ways*
cpuinfo.dcache_block_size;(quoted diff) +15
-0+ + cpuinfo.clock_frequency = fcpu(cpu, "clock-frequency"); + + of_node_put(cpu); + + print_cpuinfo(); +} + +/** + * or32_early_setup + * + * Handles the pointer to the device tree that this kernel is to use + * for establishing the available platform devices. + * + * For now, this is limited to using the built-in device tree. In thefuture,
+ * it is intended that this function will take a pointer to the device tree
+ * that is potentially built-in, but potentially also passed in by the
+ * bootloader, or discovered by some equally clever means...
+ */
arch/openrisc/boot/dts/atlys.dts
Quoted 4 lines
arch/openrisc/boot/dts/atlys.dts new file +4
-0+ +void __init or32_early_setup(void) { + + early_init_devtree((void *) __dtb_start);
Isn't __dtb_start already a void*?
Review
Quoted 2 lines
(quoted diff) +2
-0+ + printk(KERN_INFO "Compiled-in FDT at 0x%08x\n",
pr_info()
use %p for pointers.
Review
Quoted 5 lines
(quoted diff) +5
-0+ (unsigned int) __dtb_start); +} + +const struct of_device_id openrisc_bus_ids[] = { + { .type = "soc", },
Never use .type for new code. Only .compatible should be checked.
Quoted 1 line
+ { .compatible = "soc", },
Use "simple-bus". "soc" isn't defined to mean anything (see the ePAPR spec).
Review
Quoted 6 lines
(quoted diff) +6
-0+ {}, +}; + +static int __init openrisc_device_probe(void) +{ + of_platform_bus_probe(NULL, openrisc_bus_ids, NULL);
Use of_platform_populate() instead (in linux-next, or the devicetree/next branch at git://git.secretlab.ca/git/linux-2.6).of_platform_populate() is better at handling devices at the root of the device tree, and it properly ignores nodes that don't have a compatible property.
g.
Jonas Bonn
maintainerPATCH v2 3/19 OpenRISC: Memory management
In reply to Jonas Bonn--- arch/openrisc/include/asm/cache.h | 29 ++ arch/openrisc/include/asm/fixmap.h | 88 ++++++ arch/openrisc/include/asm/memblock.h | 24 ++ arch/openrisc/include/asm/mmu.h | 26 ++ arch/openrisc/include/asm/mmu_context.h | 43 +++ arch/openrisc/include/asm/page.h | 112 ++++++++ arch/openrisc/include/asm/pgalloc.h | 142 ++++++++++ arch/openrisc/include/asm/pgtable.h | 449 +++++++++++++++++++++++++++++++ arch/openrisc/include/asm/tlb.h | 34 +++ arch/openrisc/include/asm/tlbflush.h | 72 +++++ arch/openrisc/include/asm/uaccess.h | 385 ++++++++++++++++++++++++++ arch/openrisc/mm/fault.c | 338 +++++++++++++++++++++++ arch/openrisc/mm/init.c | 283 +++++++++++++++++++ arch/openrisc/mm/ioremap.c | 113 ++++++++ arch/openrisc/mm/tlb.c | 191 +++++++++++++ 15 files changed, 2329 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/cache.h create mode 100644 arch/openrisc/include/asm/fixmap.h create mode 100644 arch/openrisc/include/asm/memblock.h create mode 100644 arch/openrisc/include/asm/mmu.h create mode 100644 arch/openrisc/include/asm/mmu_context.h create mode 100644 arch/openrisc/include/asm/page.h create mode 100644 arch/openrisc/include/asm/pgalloc.h create mode 100644 arch/openrisc/include/asm/pgtable.h create mode 100644 arch/openrisc/include/asm/tlb.h create mode 100644 arch/openrisc/include/asm/tlbflush.h create mode 100644 arch/openrisc/include/asm/uaccess.h create mode 100644 arch/openrisc/mm/fault.c create mode 100644 arch/openrisc/mm/init.c create mode 100644 arch/openrisc/mm/ioremap.c create mode 100644 arch/openrisc/mm/tlb.c
arch/openrisc/include/asm/cache.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_CACHE_H +#define __ASM_OPENRISC_CACHE_H + +/* FIXME: How can we replace these with values from the CPU... +* they shouldn't be hard-coded! +*/ + +#define L1_CACHE_BYTES 16 +#define L1_CACHE_SHIFT 4 + +#endif /* __ASM_OPENRISC_CACHE_H */
arch/openrisc/include/asm/fixmap.h new file +88 -0
88 lines not on this page · raw message
arch/openrisc/include/asm/memblock.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_MEMBLOCK_H +#define __ASM_OPENRISC_MEMBLOCK_H + +/* empty */ + +#endif /* __ASM_OPENRISC_MEMBLOCK_H */
arch/openrisc/include/asm/mmu.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_MMU_H +#define __ASM_OPENRISC_MMU_H + +#ifndef __ASSEMBLY__ +typedef unsigned long mm_context_t ; +#endif + +#endif
arch/openrisc/include/asm/mmu_context.h new file +43 -0
43 lines not on this page · raw message
arch/openrisc/include/asm/page.h new file +112 -0
112 lines not on this page · raw message
arch/openrisc/include/asm/pgalloc.h new file +142 -0
142 lines not on this page · raw message
arch/openrisc/include/asm/pgtable.h new file +449 -0
449 lines not on this page · raw message
arch/openrisc/include/asm/tlb.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_TLB_H__ +#define __ASM_OPENRISC_TLB_H__ + +/* +* or32 doesn't need any special per-pte or +* per-vma handling.. +*/ +#define tlb_start_vma (tlb, vma) do { } while (0) +#define tlb_end_vma (tlb, vma) do { } while (0) +#define __tlb_remove_tlb_entry (tlb, ptep, address) do { } while (0) + +#define tlb_flush (tlb) flush_tlb_mm((tlb)->mm) +#include <linux/pagemap.h> +#include <asm-generic/tlb.h> + +#endif /* __ASM_OPENRISC_TLB_H__ */
arch/openrisc/include/asm/tlbflush.h new file +72 -0
72 lines not on this page · raw message
arch/openrisc/include/asm/uaccess.h new file +385 -0
385 lines not on this page · raw message
arch/openrisc/mm/fault.c new file +338 -0
338 lines not on this page · raw message
arch/openrisc/mm/init.c new file +283 -0
283 lines not on this page · raw message
arch/openrisc/mm/ioremap.c new file +113 -0
113 lines not on this page · raw message
arch/openrisc/mm/tlb.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 4/19 OpenRISC: Signal handling
In reply to Jonas Bonn--- arch/openrisc/include/asm/sigcontext.h | 38 +++ arch/openrisc/kernel/signal.c | 404 ++++++++++++++++++++++++++++++++ 2 files changed, 442 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/sigcontext.h create mode 100644 arch/openrisc/kernel/signal.c
arch/openrisc/include/asm/sigcontext.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SIGCONTEXT_H +#define __ASM_OPENRISC_SIGCONTEXT_H + +#include <asm/ptrace.h> + +/* This struct is saved by setup_frame in signal.c, to keep the current +context while a signal handler is executed. It's restored by sys_sigreturn. + +To keep things simple, we use pt_regs here even though normally you just +specify the list of regs to save. Then we can use copy_from_user on the +entire regs instead of a bunch of get_user's as well... +*/ + +struct sigcontext { +struct pt_regs regs;/* needs to be first */ +unsigned long oldmask; +unsigned long usp;/* usp before stacking this gunk on it */ +}; + +#endif /* __ASM_OPENRISC_SIGCONTEXT_H */
arch/openrisc/kernel/signal.c new file +404 -0
404 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 5/19 OpenRISC: Build infrastructure
In reply to Jonas Bonn--- arch/openrisc/Kconfig | 207 +++++++++++++++++++++++++++++++ arch/openrisc/Makefile | 66 ++++++++++ arch/openrisc/boot/Makefile | 15 +++ arch/openrisc/configs/or1ksim_defconfig | 67 ++++++++++ arch/openrisc/include/asm/Kbuild | 64 ++++++++++ arch/openrisc/kernel/Makefile | 14 ++ arch/openrisc/kernel/vmlinux.lds.S | 115 +++++++++++++++++ arch/openrisc/lib/Makefile | 5 + arch/openrisc/mm/Makefile | 5 + 9 files changed, 558 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/Kconfig create mode 100644 arch/openrisc/Makefile create mode 100644 arch/openrisc/boot/Makefile create mode 100644 arch/openrisc/configs/or1ksim_defconfig create mode 100644 arch/openrisc/include/asm/Kbuild create mode 100644 arch/openrisc/kernel/Makefile create mode 100644 arch/openrisc/kernel/vmlinux.lds.S create mode 100644 arch/openrisc/lib/Makefile create mode 100644 arch/openrisc/mm/Makefile
arch/openrisc/Kconfig new file +207 -0
@@ -0,0 +1,207 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/config-language.txt. +# + +config OPENRISC + def_bool y + select OF + select OF_EARLY_FLATTREE + select HAVE_MEMBLOCK + select ARCH_WANT_OPTIONAL_GPIOLIB + select HAVE_ARCH_TRACEHOOK + select HAVE_GENERIC_HARDIRQS + select GENERIC_IRQ_CHIP + select GENERIC_IRQ_PROBE + select GENERIC_IRQ_SHOW + select GENERIC_IOMAP + +config MMU + def_bool y + +config WISHBONE_BUS_BIG_ENDIAN + def_bool y + +config SYMBOL_PREFIX + string + default "" + +config HAVE_DMA_ATTRS + def_bool y + +config UID16 + def_bool y + +config RWSEM_GENERIC_SPINLOCK + def_bool y + +config RWSEM_XCHGADD_ALGORITHM + def_bool n + +config GENERIC_HWEIGHT + def_bool y + +config GENERIC_IOMAP + def_bool y + +config NO_IOPORT + def_bool y + +config GENERIC_GPIO + def_bool y + +config GENERIC_CLOCKEVENTS + def_bool y + +config TRACE_IRQFLAGS_SUPPORT + def_bool y + +# For now, use generic checksum functions +#These can be reimplemented in assembly later if so inclined +config GENERIC_CSUM + def_bool y + +config GENERIC_FIND_NEXT_BIT + def_bool y + +source "init/Kconfig" + + +menu "Processor type and features" + +choice + prompt "Subarchitecture" + default OR1K_1200 + +config OR1K_1200 + bool "OR1200" + help + Generic OpenRISC 1200 architecture + +endchoice + +config OPENRISC_BUILTIN_DTB + string "Builtin DTB" + default "" + +menu "Class II Instructions" + +config OPENRISC_HAVE_INST_FF1 + bool "Have instruction l.ff1" + default y + help + Select this if your implementation has the Class II instruction l.ff1 + +config OPENRISC_HAVE_INST_FL1 + bool "Have instruction l.fl1" + default y + help + Select this if your implementation has the Class II instruction l.fl1 + +config OPENRISC_HAVE_INST_MUL + bool "Have instruction l.mul for hardware multiply" + default y + help + Select this if your implementation has a hardware multiply instruction + +config OPENRISC_HAVE_INST_DIV + bool "Have instruction l.div for hardware divide" + default y + help + Select this if your implementation has a hardware divide instruction +endmenu + + +source "kernel/time/Kconfig" +source kernel/Kconfig.hz +source kernel/Kconfig.preempt +source "mm/Kconfig" + +config OPENRISC_NO_SPR_SR_DSX + bool "use SPR_SR_DSX software emulation" if OR1K_1200 + default y + help + SPR_SR_DSX bit is status register bit indicating whether + the last exception has happened in delay slot. + + OpenRISC architecture makes it optional to have it implemented + in hardware and the OR1200 does not have it. + + Say N here if you know that your OpenRISC processor has + SPR_SR_DSX bit implemented. Say Y if you are unsure. + +config CMDLINE + string "Default kernel command string" + default "" + help + On some architectures there is currently no way for the boot loader + to pass arguments to the kernel. For these architectures, you should + supply some command-line options at build time by entering them + here. + +menu "Debugging options" + +config DEBUG_STACKOVERFLOW + bool "Check for kernel stack overflow" + default y + help + Make extra checks for space avaliable on stack in some + critical functions. This will cause kernel to run a bit slower, + but will catch most of kernel stack overruns and exit gracefuly. + + Say Y if you are unsure. + +config JUMP_UPON_UNHANDLED_EXCEPTION + bool "Try to die gracefully" + default y + help + Now this puts kernel into infinite loop after first oops. Till + your kernel crashes this doesn't have any influence. + + Say Y if you are unsure. + +config OPENRISC_EXCEPTION_DEBUG + bool "Print processor state at each exception" + default n + help + This option will make your kernel unusable for all but kernel + debugging. + + Say N if you are unsure. + +config OPENRISC_ESR_EXCEPTION_BUG_CHECK + bool "Check for possible ESR exception bug" + default n + help + This option enables some checks that might expose some problems + in kernel. + + Say N if you are unsure. + +endmenu + +endmenu + +menu "Executable file formats" + +source "fs/Kconfig.binfmt" + +endmenu + +source "net/Kconfig" + +source "drivers/Kconfig" + +source "fs/Kconfig" + +source "security/Kconfig" + +source "crypto/Kconfig" + +source "lib/Kconfig" + +menu "Kernel hacking" + +source "lib/Kconfig.debug" + +endmenu
arch/openrisc/Makefile new file +66 -0
66 lines not on this page · raw message
arch/openrisc/boot/Makefile new file +15 -0
@@ -0,0 +1,15 @@ + + +ifneq '$(CONFIG_OPENRISC_BUILTIN_DTB)' '""' +BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_OPENRISC_BUILTIN_DTB)).dtb.o +else +BUILTIN_DTB := +endif +obj-y += $(BUILTIN_DTB) + +clean-files := *.dtb.S + +#DTC_FLAGS ?= -p 1024 + +$(obj)/%.dtb: $(src)/dts/%.dts + $(call cmd,dtc)
arch/openrisc/configs/or1ksim_defconfig new file +67 -0
67 lines not on this page · raw message
arch/openrisc/include/asm/Kbuild new file +64 -0
64 lines not on this page · raw message
arch/openrisc/kernel/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# +# Makefile for the linux kernel. +# + +extra-y := head.o vmlinux.lds init_task.o + +obj-y := setup.o idle.o or32_ksyms.o process.o dma.o \ + traps.o time.o irq.o entry.o ptrace.o signal.o sys_or32.o \ + sys_call_table.o + +obj-$(CONFIG_MODULES) += module.o +obj-$(CONFIG_OF) += prom.o + +clean:
arch/openrisc/kernel/vmlinux.lds.S new file +115 -0
115 lines not on this page · raw message
arch/openrisc/lib/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for or32 specific library files.. +# + +obj-y = string.o delay.o
arch/openrisc/mm/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the linux openrisc-specific parts of the memory manager. +# + +obj-y := fault.o tlb.o init.o ioremap.o
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 6/19 OpenRISC: PTrace
In reply to Jonas Bonn--- arch/openrisc/include/asm/ptrace.h | 124 ++++++++ arch/openrisc/kernel/ptrace.c | 574 ++++++++++++++++++++++++++++++++++++ arch/openrisc/kernel/ptrace.h | 37 +++ 3 files changed, 735 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/ptrace.h create mode 100644 arch/openrisc/kernel/ptrace.c create mode 100644 arch/openrisc/kernel/ptrace.h
arch/openrisc/include/asm/ptrace.h new file +124 -0
@@ -0,0 +1,124 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_PTRACE_H +#define __ASM_OPENRISC_PTRACE_H + +#include <asm/spr_defs.h> +/* +* This struct defines the way the registers are stored on the +* kernel stack during a system call or other kernel entry. +* +* this should only contain volatile regs +* since we can keep non-volatile in the thread_struct +* should set this up when only volatiles are saved +* by intr code. +* +* Since this is going on the stack, *CARE MUST BE TAKEN* to insure +* that the overall structure is a multiple of 16 bytes in length. +* +* Note that the offsets of the fields in this struct correspond with +* the values below. +*/ + +/* +* These are 'magic' values for PTRACE_PEEKUSR that return info about where a +* process is located in memory. +*/ +#define PT_TEXT_ADDR 0x10000 +#define PT_DATA_ADDR 0x10004 +#define PT_TEXT_END_ADDR 0x10008 + +#ifndef __ASSEMBLY__ + +struct pt_regs { +union { +struct { +/* Named registers */ +long sr;/* Stored in place of r0 */ +long sp;/* r1 */ + }; +struct { +/* Old style */ +long offset[2 ]; +long gprs[30 ]; + }; +struct { +/* New style */ +long gpr[32 ]; + }; + }; +long pc; +long orig_gpr11;/* Used for restarting system calls */ +long syscallno;/* Syscall no. (used by strace) */ +}; +#endif /* __ASSEMBLY__ */ + +#ifdef __KERNEL__ +#define STACK_FRAME_OVERHEAD 128/* size of minimum stack frame */ +//#define STACK_FRAME_OVERHEAD 0 /* size of minimum stack frame */ + +#define instruction_pointer (regs) ((regs)->pc) +#define user_mode (regs) (((regs)->sr & SPR_SR_SM) == 0) +#define user_stack_pointer (regs) ((unsigned long)(regs)->sp) +#define profile_pc (regs) instruction_pointer(regs) + +#define arch_has_single_step () (1) + +#endif /* __KERNEL__ */ + +/* +* Offsets used by 'ptrace' system call interface. +*/ +#define PT_SR 0 +#define PT_SP 4 +#define PT_GPR2 8 +#define PT_GPR3 12 +#define PT_GPR4 16 +#define PT_GPR5 20 +#define PT_GPR6 24 +#define PT_GPR7 28 +#define PT_GPR8 32 +#define PT_GPR9 36 +#define PT_GPR10 40 +#define PT_GPR11 44 +#define PT_GPR12 48 +#define PT_GPR13 52 +#define PT_GPR14 56 +#define PT_GPR15 60 +#define PT_GPR16 64 +#define PT_GPR17 68 +#define PT_GPR18 72 +#define PT_GPR19 76 +#define PT_GPR20 80 +#define PT_GPR21 84 +#define PT_GPR22 88 +#define PT_GPR23 92 +#define PT_GPR24 96 +#define PT_GPR25 100 +#define PT_GPR26 104 +#define PT_GPR27 108 +#define PT_GPR28 112 +#define PT_GPR29 116 +#define PT_GPR30 120 +#define PT_GPR31 124 +#define PT_PC 128 +#define PT_ORIG_GPR11 132 +#define PT_SYSCALLNO 136 + +#endif /* __ASM_OPENRISC_PTRACE_H */
arch/openrisc/kernel/ptrace.c new file +574 -0
574 lines not on this page · raw message
arch/openrisc/kernel/ptrace.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* linux/arch/openrisc/kernel/ptrace.h +* +* Copyright (C) 2000-2003 Russell King +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#include <linux/ptrace.h> + +extern void ptrace_cancel_bpt (struct task_struct *); +extern void ptrace_set_bpt (struct task_struct *); +extern void ptrace_break (struct task_struct *,struct pt_regs *); + +/* +* Send SIGTRAP if we're single-stepping +*/ +static inline void single_step_trap (struct task_struct *task) +{ +if (test_tsk_thread_flag (task,TIF_SINGLESTEP )){ +ptrace_cancel_bpt (task); +send_sig (SIGTRAP , task,1 ); + } +} + +static inline void single_step_clear (struct task_struct *task) +{ +if (test_tsk_thread_flag (task,TIF_SINGLESTEP )) +ptrace_cancel_bpt (task); +} + +static inline void single_step_set (struct task_struct *task) +{ +if (test_tsk_thread_flag (task,TIF_SINGLESTEP )) +ptrace_set_bpt (task); +}
Signature · 1 line
1.7.4.1
Re: [PATCH v2 06/19] OpenRISC: PTrace
arch/openrisc/kernel/ptrace.c line 198
Quoted 4 lines · Jonas Bonn
arch/openrisc/kernel/ptrace.c new file +4
-0+pr_debug (KERN_INFO +"ptrace get_next_address: pc 0x%.8lx insn. 0x%.8lx opc. 0x%.2x\n" , + pc, insn, opc); +
This evaluates to printk(KERN_DEBUG KERN_INFO "ptrace...", ...), which does not seem to be ok ;). This mistake is repeated several times in this patchset...
Marcin
Arnd Bergmann
maintainerRe: [PATCH v2 06/19] OpenRISC: PTrace
In reply to Jonas BonnQuoted 9 lines · Jonas Bonn
Signed-off-by Jonas Bonn <[email protected]>--- arch/openrisc/include/asm/ptrace.h | 124 ++++++++ arch/openrisc/kernel/ptrace.c | 574 ++++++++++++++++++++++++++++++++++++ arch/openrisc/kernel/ptrace.h | 37 +++ 3 files changed, 735 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/ptrace.h create mode 100644 arch/openrisc/kernel/ptrace.c create mode 100644 arch/openrisc/kernel/ptrace.h
This patch still contains a bunch of commented out code that wants to be cleaned up. I think you have done that in most other patches that needed the same cleanup.
Arnd
Jonas Bonn
maintainerRe: [PATCH v2 06/19] OpenRISC: PTrace
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Jonas Bonn
Signed-off-by Jonas Bonn <[email protected]>--- arch/openrisc/include/asm/ptrace.h | 124 ++++++++ arch/openrisc/kernel/ptrace.c | 574 ++++++++++++++++++++++++++++++++++++ arch/openrisc/kernel/ptrace.h | 37 +++ 3 files changed, 735 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/ptrace.h create mode 100644 arch/openrisc/kernel/ptrace.c create mode 100644 arch/openrisc/kernel/ptrace.h
Quoted 5 lines
This patch still contains a bunch of commented out code that wants to be cleaned up. I think you have done that in most other patches that needed the same cleanup.
Arnd
I've been looking a bit at the ptrace stuff the last couple of days. One question that occurred to me was: is it mandatory to export the "struct pt_regs" info in ptrace.h to userspace?
I'm not sure I like the layout of our struct pt_regs. It would be better to lay out the registers in a way that mirrors the order that they are saved during exception/syscall entry in order to make better use of the cache.
Since the registers can be exported via a regset to userspace anyway (which doesn't necessarily need to look like pt_regs), I don't see that userspace really needs how we lay out the registers on the stack. By not exporting pt_regs, I am free to change the layout... if it's exported, it becomes ABI.
Comments?
/Jonas
Arnd Bergmann
maintainerRe: [PATCH v2 06/19] OpenRISC: PTrace
Quoted 3 lines · Jonas Bonn
I've been looking a bit at the ptrace stuff the last couple of days. One question that occurred to me was: is it mandatory to export the "struct
pt_regs" info inptrace.hto userspace?
I don't know, it certainly has been the case traditionally, but as far as I can tell, this was mainly used by ancient gdb ports, while newer versions just hardcode the offsets for PTRACE_PEEKUSR.
Quoted 10 lines
I'm not sure I like the layout of our struct
pt_regs. It would be better to lay out the registers in a way that mirrors the order that they are saved during exception/syscall entry in order to make better use of the cache.Since the registers can be exported via a regset to userspace anyway (which doesn't necessarily need to look like
pt_regs), I don't see that userspace really needs how we lay out the registers on the stack. By not exportingpt_regs, I am free to change the layout... if it's exported, it becomes ABI.
Yes. I think you can just change your ptrace code to not export pt_regs through PEEKUSR but only through elf_gregset_t, which you can define independently.
Arnd
Jonas Bonn
maintainerPATCH v2 7/19 OpenRISC: DMA
In reply to Jonas BonnSimple DMA implementation. Allows for allocation of coherent memory (simply uncached) for DMA operations.
--- arch/openrisc/include/asm/dma-mapping.h | 62 ++++++++++++++++++++++ arch/openrisc/kernel/dma.c | 86 +++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/dma-mapping.h create mode 100644 arch/openrisc/kernel/dma.c
arch/openrisc/include/asm/dma-mapping.h new file +62 -0
@@ -0,0 +1,62 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_DMA_MAPPING_H +#define __ASM_OPENRISC_DMA_MAPPING_H + +/* +* See Documentation/PCI/PCI-DMA-mapping.txt and +* Documentation/DMA-API.txt for documentation. +*/ + +#include <linux/dma-debug.h> +#include <asm-generic/dma-coherent.h> + +#define DMA_ERROR_CODE (~(dma_addr_t)0x0) + +int dma_mapping_error (struct device *dev,dma_addr_t dma_addr); + +int dma_supported (struct device *dev,u64 mask); + +int dma_set_mask (struct device *dev,u64 mask); + +#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 *or1k_dma_alloc_coherent (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag); +void or1k_dma_free_coherent (struct device *dev,size_t size,void *vaddr, +dma_addr_t dma_handle); + +static inline void *dma_alloc_coherent (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag) +{ +void *memory; + + memory =or1k_dma_alloc_coherent (dev, size, dma_handle, flag); + +debug_dma_alloc_coherent (dev, size, *dma_handle, memory); +return memory; +} + +static inline void dma_free_coherent (struct device *dev,size_t size, +void *cpu_addr,dma_addr_t dma_handle) +{ +debug_dma_free_coherent (dev, size, cpu_addr, dma_handle); +or1k_dma_free_coherent (dev, size, cpu_addr, dma_handle); +} + +#endif /* __ASM_OPENRISC_DMA_MAPPING_H */
arch/openrisc/kernel/dma.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Arnd Bergmann
maintainerRe: [PATCH v2 07/19] OpenRISC: DMA
Quoted 27 lines · Jonas Bonn
arch/openrisc/kernel/dma.c new file +27
-0+void *or1k_dma_alloc_coherent (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag) +{ +int order; +unsigned long page, va; +pgprot_t prot; +struct vm_struct *area; + +/* Only allocate page size areas. */ + size =PAGE_ALIGN (size); + order =get_order (size); + + page =__get_free_pages (flag, order); +if (!page) +return NULL ; + +/* Allocate some common virtual space to map the new pages. */ + area =get_vm_area (size,VM_ALLOC ); +if (area ==NULL ) { +free_pages (page, order); +return NULL ; + } + va = (unsigned long )area->addr; + +/* This gives us the real physical address of the first page. */ + *dma_handle =__pa (page); +
arch/openrisc/kernel/dma.c line 68
Quoted 10 lines
arch/openrisc/kernel/dma.c new file +10
-0+ prot =PAGE_KERNEL_NOCACHE ; + +/* This isn't so much ioremap as just simply 'remap' */ +if (ioremap_page_range (va, va + size, *dma_handle, prot)) { +vfree (area->addr); +return NULL ; + } + +return (void *)va; +}
This will result in having conflicting mappings, one with and another without caching, which a lot of CPU architectures don't like. Are you sure that you can handle this with or1k?
I think at the very least you will need to flush the cache for the linear mapping, to avoid writing back dirty cache lines over the DMA buffer.
You can save a little memory by using alloc_pages_exact instead of get_free_pages, which always gives you a power-of-two size.
Also, isn't get_vm_area+ioremap_page_range the same as ioremap on or1k?
In the case that ioremap_page_ranges fails, I think you have a memory leak, or worse, because areas is not backed by the pages at that moment.
Arnd
Jonas Bonn
maintainerRe: [PATCH v2 07/19] OpenRISC: DMA
Quoted 5 lines · Arnd Bergmann
This will result in having conflicting mappings, one with and another without caching, which a lot of CPU architectures don't like. Are you sure that you can handle this with or1k?
Arnd
Hi Arnd,
I put a bit more thought into what we actually need for DMA and came up with the implementation in this patch. This is a lot simpler than what we had before, but it seems to fit nicely with the model that we have.
The jist of it is that allocation of coherent memory just needs to return pages with the cache-inhibit bit set so we now:
i) call __get_free_pages (via alloc_pages_exact)
ii) set the CI bit on those pages
iii) flush the pages from cache
This should mean that we don't have any conflicting page table entries for these pages anymore.
I'd appreciate if you could look over this implementation to make sure I haven't missed anything fundamental.
Thanks,
Jonas
PS: Having a bit of an issue with git send-email and in a bit of a hurry so I just pasted the patch into this mail... should be ok since it's just for review anyway; just hoping the mail client doesn't mess up the formatting.
-----------------------------------------------------------------
From b2dc6eb85a19b4601180c9dcec440364daf7d9db Mon Sep 17 00:00:00 2001
From: Jonas Bonn <[email protected]>
Date: Sat, 4 Jun 2011 21:56:48 +0300
Subject: [PATCH] OpenRISC: DMA
Simple DMA implementation. Allows for allocation of coherent memory (simply uncached) for DMA operations.
---
arch/openrisc/include/asm/dma-mapping.h | 62 +++++++++++++++ arch/openrisc/kernel/dma.c | 131 +++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/dma-mapping.h create mode 100644 arch/openrisc/kernel/dma.c
(quoted diff) +0 -0
b/arch/openrisc/include/asm/dma-mapping.h
new file mode 100644
index 0000000..3d68ed8
arch/openrisc/include/asm/dma-mapping.h new file +36 -0
@@ -0,0 +1,62 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_DMA_MAPPING_H +#define __ASM_OPENRISC_DMA_MAPPING_H + +/* +* See Documentation/PCI/PCI-DMA-mapping.txt and +* Documentation/DMA-API.txt for documentation. +*/ + +#include <linux/dma-debug.h> +#include <asm-generic/dma-coherent.h> + +#define DMA_ERROR_CODE (~(dma_addr_t)0x0) + +int dma_mapping_error (struct device *dev,dma_addr_t dma_addr); + +int dma_supported (struct device *dev,u64 mask); + +int dma_set_mask (struct device *dev,u64 mask); + +#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 *or1k_dma_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t flag);
+void or1k_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
+ dma_addr_t dma_handle);
+
+static inline void *dma_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t flag)
+{
+ void *memory;
+
+ memory = or1k_dma_alloc_coherent(dev, size, dma_handle, flag);
+
+ debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
+ return memory;
+}
+
+static inline void dma_free_coherent(struct device *dev, size_t size,
+ void *cpu_addr, dma_addr_t dma_handle)
+{
+ debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
+ or1k_dma_free_coherent(dev, size, cpu_addr, dma_handle);
+}
+
+#endif /* __ASM_OPENRISC_DMA_MAPPING_H */
arch/openrisc/kernel/dma.c new file +18 -0
@@ -0,0 +1,131 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[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. +* +* DMA mapping callbacks... +* As alloc_coherent is the only DMA callback being used currently,
that's
+ * the only thing implemented properly. The rest need looking into...
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/gfp.h>
+#include <linux/dma-debug.h>
+#include <linux/io.h>
+#include <linux/vmalloc.h>
+#include <linux/sched.h>
+
+#include <asm/cpuinfo.h>
+#include <asm/spr_defs.h>
+#include <asm/tlbflush.h>
+
+static int page_set_nocache(pte_t* pte, unsigned long addr,
+ unsigned long next, struct mm_walk* walk)
+{
+ unsigned long cl;
+
+ pte_val(*pte) |= _PAGE_CI;
+
+ /*
+ * Flush the page out of the TLB so that the new page flags get
+ * picked up next time there's an access
+ */
+ flush_tlb_page(NULL, addr);
+
+ /* Flush page out of dcache */
+ for (cl = __pa(addr); cl < __pa(next); cl +=
cpuinfo.dcache_block_size)
+ mtspr(SPR_DCBFR, cl);
+
+ return 0;
+}
+
+static int page_clear_nocache(pte_t* pte, unsigned long addr,
+ unsigned long next, struct mm_walk* walk)
+{
+ pte_val(*pte) &= ~_PAGE_CI;
+
+ /*
+ * Flush the page out of the TLB so that the new page flags get
+ * picked up next time there's an access
+ */
+ flush_tlb_page(NULL, addr);
+
+ return 0;
+}
+
+/*
+ * Alloc "coherent" memory, which for OpenRISC means simply uncached.
+ *
+ * This function effectively just calls __get_free_pages, sets the
+ * cache-inhibit bit on those pages, and makes sure that the pages are
+ * flushed out of the cache before they are used.
+ *
+ */
+void *or1k_dma_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t gfp)
+{
+ unsigned long va;
+ void* page;
+ struct mm_walk walk = {
+ .pte_entry = page_set_nocache,
+ .mm = &init_mm
+ };
+
+ page = alloc_pages_exact(size, gfp);
+ if (!page)
+ return NULL;
+
+ /* This gives us the real physical address of the first page. */
+ *dma_handle = __pa(page);
+
+ va = (unsigned long) page;
+
+ /*
+ * We need to iterate through the pages, clearing the dcache for
+ * them and setting the cache-inhibit bit.
+ */
+ if (walk_page_range(va, va+size, &walk)) {
+ free_pages_exact(page, size);
+ return NULL;
+ }
+
+ return (void*) va;
+}
+
+void or1k_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
+ dma_addr_t dma_handle)
+{
+ unsigned long va = (unsigned long) vaddr;
+ struct mm_walk walk = {
+ .pte_entry = page_clear_nocache,
+ .mm = &init_mm
+ };
+
+ /* walk_page_range shouldn't be able to fail here */
+ WARN_ON(walk_page_range(va, va+size, &walk));
+
+ free_pages_exact(vaddr, size);
+}
+
+/* Number of entries preallocated for DMA-API debugging */ +#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
+
+static int __init dma_init(void)
+{
+ dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
+
+ return 0;
+}
+fs_initcall(dma_init);
Signature · 1 line
1.7.1
Arnd Bergmann
maintainerRe: [PATCH v2 07/19] OpenRISC: DMA
Quoted 11 lines · On Friday 08 July 2011 09:36:19 Jonas Bonn wrote:
I put a bit more thought into what we actually need for DMA and came up with the implementation in this patch. This is a lot simpler than what we had before, but it seems to fit nicely with the model that we have.
The jist of it is that allocation of coherent memory just needs to return pages with the cache-inhibit bit set so we now:
i) call
__get_free_pages(viaalloc_pages_exact)
ii) set the CI bit on those pages
iii) flush the pages from cache
Quoted 5 lines
This should mean that we don't have any conflicting page table entries for these pages anymore.
I'd appreciate if you could look over this implementation to make sure I haven't missed anything fundamental.
Looks ok to me. A few more points for future optimization though:
* If your CPU can do different page sizes, you should make the kernel mapping use the largest possible page size. This will however make the dma mapping part much harder.
* If you ever want to map a frame buffer with this, you should add a write-combining mapping type, uncached accesses are really slow.
* Cache coherency is good. If you can make the hardware do cache-coherent DMA, then just use cacheable pages for alloc_coherent.
Arnd
Jonas Bonn
maintainerPATCH v2 8/19 OpenRISC: Timekeeping
In reply to Jonas BonnImplements support for the OpenRISC timer which is a 28 bit cycle counter that can be read out of a special purpose register. This counter is used as a both a clock event and clocksource device.
--- arch/openrisc/include/asm/timex.h | 36 ++++++++ arch/openrisc/kernel/time.c | 181 +++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/timex.h create mode 100644 arch/openrisc/kernel/time.c
arch/openrisc/include/asm/timex.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_TIMEX_H +#define __ASM_OPENRISC_TIMEX_H + +#define get_cycles get_cycles + +#include <asm-generic/timex.h> +#include <asm/spr.h> +#include <asm/spr_defs.h> + +static inline cycles_t get_cycles (void ) +{ +return mfspr (SPR_TTCR ); +} + +/* This isn't really used any more */ +#define CLOCK_TICK_RATE 1000 + +#define ARCH_HAS_READ_CURRENT_TIMER + +#endif
arch/openrisc/kernel/time.c new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 9/19 OpenRISC: IRQ
In reply to Jonas BonnThis patch adds support for the OpenRISC PIC.
--- arch/openrisc/include/asm/irq.h | 27 ++++++ arch/openrisc/include/asm/irqflags.h | 29 ++++++ arch/openrisc/kernel/irq.c | 172 ++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/irq.h create mode 100644 arch/openrisc/include/asm/irqflags.h create mode 100644 arch/openrisc/kernel/irq.c
arch/openrisc/include/asm/irq.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_IRQ_H__ +#define __ASM_OPENRISC_IRQ_H__ + +#define NR_IRQS 32 +#include <asm-generic/irq.h> + +#define NO_IRQ (-1) + +#endif /* __ASM_OPENRISC_IRQ_H__ */
arch/openrisc/include/asm/irqflags.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef ___ASM_OPENRISC_IRQFLAGS_H +#define ___ASM_OPENRISC_IRQFLAGS_H + +#include <asm/spr_defs.h> + +#define ARCH_IRQ_DISABLED 0x00 +#define ARCH_IRQ_ENABLED (SPR_SR_IEE|SPR_SR_TEE) + +#include <asm-generic/irqflags.h> + +#endif /* ___ASM_OPENRISC_IRQFLAGS_H */
arch/openrisc/kernel/irq.c new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 10/19 OpenRISC: System calls
In reply to Jonas BonnThe OpenRISC Linux kernel conforms to the "generic" syscall interface which contains only the reduced set of syscalls deemed necessary for new architectures. Unfortunately, the uClibc port for OpenRISC does not fully support this reduced set; as such, an additional patch available out-of-tree needs to be applied to the kernel in order to use the current uClibc. This is just a temporary measure until the libc port can be straightened out; it is likely that OpenRISC will make the transition to glibc shortly where the generic syscall interface is better supported.
--- arch/openrisc/include/asm/syscall.h | 77 ++++++++++++++++++++++++++++++ arch/openrisc/include/asm/syscalls.h | 27 +++++++++++ arch/openrisc/include/asm/unistd.h | 29 +++++++++++ arch/openrisc/kernel/sys_call_table.c | 28 +++++++++++ arch/openrisc/kernel/sys_or32.c | 83 +++++++++++++++++++++++++++++++++ 5 files changed, 244 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/syscall.h create mode 100644 arch/openrisc/include/asm/syscalls.h create mode 100644 arch/openrisc/include/asm/unistd.h create mode 100644 arch/openrisc/kernel/sys_call_table.c create mode 100644 arch/openrisc/kernel/sys_or32.c
arch/openrisc/include/asm/syscall.h new file +77 -0
@@ -0,0 +1,77 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SYSCALL_H__ +#define __ASM_OPENRISC_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->syscallno ? regs->syscallno :-1 ; +} + +static inline void +syscall_rollback (struct task_struct *task,struct pt_regs *regs) +{ + regs->gpr[11 ] = regs->orig_gpr11; +} + +static inline long +syscall_get_error (struct task_struct *task,struct pt_regs *regs) +{ +return IS_ERR_VALUE (regs->gpr[11 ]) ? regs->gpr[11 ] :0 ; +} + +static inline long +syscall_get_return_value (struct task_struct *task,struct pt_regs *regs) +{ +return regs->gpr[11 ]; +} + +static inline void +syscall_set_return_value (struct task_struct *task,struct pt_regs *regs, +int error,long val) +{ +if (error) + regs->gpr[11 ] = -error; +else + regs->gpr[11 ] = val; +} + +static inline void +syscall_get_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,unsigned long *args) +{ +BUG_ON (i + n >6 ); + +memcpy (args, ®s->gpr[3 + i], n *sizeof (args[0 ])); +} + +static inline void +syscall_set_arguments (struct task_struct *task,struct pt_regs *regs, +unsigned int i,unsigned int n,const unsigned long *args) +{ +BUG_ON (i + n >6 ); + +memcpy (®s->gpr[3 + i], args, n *sizeof (args[0 ])); +} + +#endif
arch/openrisc/include/asm/syscalls.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SYSCALLS_H +#define __ASM_OPENRISC_SYSCALLS_H + +asmlinkage long sys_or1k_atomic (unsigned long type,unsigned long *v1, +unsigned long *v2); + +#include <asm-generic/syscalls.h> + +#endif /* __ASM_OPENRISC_SYSCALLS_H */
arch/openrisc/include/asm/unistd.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#if !defined(__ASM_OPENRISC_UNISTD_H) || defined(__SYSCALL) +#define __ASM_OPENRISC_UNISTD_H + +#define __ARCH_HAVE_MMU + +#include <asm-generic/unistd.h> + +#define __NR_or1k_atomic __NR_arch_specific_syscall +__SYSCALL(__NR_or1k_atomic, sys_or1k_atomic) + +#endif /* __ASM_OPENRISC_UNISTD_H */
arch/openrisc/kernel/sys_call_table.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* OpenRISC sys_call_table.c +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#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> +};
arch/openrisc/kernel/sys_or32.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Arnd Bergmann
maintainerRe: [PATCH v2 10/19] OpenRISC: System calls
Quoted 7 lines · Jonas Bonn
arch/openrisc/kernel/sys_or32.c new file +7
-0+ +asmlinkage long sys_mmap2 (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff) +{ +return sys_mmap_pgoff (addr, len, prot, flags, fd, pgoff); +}
arch/openrisc/kernel/sys_or32.c line 44
Quoted 10 lines
arch/openrisc/kernel/sys_or32.c new file +10
-0+ +asmlinkage long sys_mmap (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,off_t pgoff) +{ +if (pgoff & ~PAGE_MASK ) +return -EINVAL ; + +return sys_mmap_pgoff (addr, len, prot, flags, fd, pgoff >>PAGE_SHIFT ); +}
You shouldn't really need these two. Either provide just sys_mmap2, or "#define sys_mmap2 sys_mmap_pgoff" and change your user implementation.
Arnd
Jonas Bonn
maintainerPATCH v2 11/19 OpenRISC: Idle/Power management
In reply to Jonas BonnMinimal functionality...
--- arch/openrisc/kernel/idle.c | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/kernel/idle.c
arch/openrisc/kernel/idle.c new file +77 -0
@@ -0,0 +1,77 @@ +/* +* OpenRISC idle.c +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[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. +* +* Idle daemon for or32. Idle daemon will handle any action +* that needs to be taken when the system becomes idle. +*/ + +#include <linux/errno.h> +#include <linux/sched.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/smp.h> +#include <linux/stddef.h> +#include <linux/unistd.h> +#include <linux/ptrace.h> +#include <linux/slab.h> +#include <linux/tick.h> + +#include <asm/pgtable.h> +#include <asm/uaccess.h> +#include <asm/system.h> +#include <asm/io.h> +#include <asm/processor.h> +#include <asm/mmu.h> +#include <asm/cache.h> +#include <asm/pgalloc.h> + +void (*powersave) (void ) =NULL ; + +static inline void pm_idle (void ) +{ +barrier (); +} + +void cpu_idle (void ) +{ +set_thread_flag (TIF_POLLING_NRFLAG ); + +/* endless idle loop with no priority at all */ +while (1 ) { +tick_nohz_stop_sched_tick (1 ); + +while (!need_resched ()) { +check_pgt_cache (); +rmb (); + +clear_thread_flag (TIF_POLLING_NRFLAG ); + +local_irq_disable (); +/* Don't trace irqs off for idle */ +stop_critical_timings (); +if (powersave !=NULL ) +powersave (); +start_critical_timings (); +local_irq_enable (); +set_thread_flag (TIF_POLLING_NRFLAG ); + } + +tick_nohz_restart_sched_tick (); +preempt_enable_no_resched (); +schedule (); +preempt_disable (); + } +}
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 12/19 OpenRISC: Scheduling/Process management
In reply to Jonas Bonn--- arch/openrisc/include/asm/thread_info.h | 149 +++++++++++++++ arch/openrisc/kernel/idle.c | 2 +- arch/openrisc/kernel/process.c | 305 +++++++++++++++++++++++++++++++ 3 files changed, 455 insertions(+), 1 deletions(-) create mode 100644 arch/openrisc/include/asm/thread_info.h create mode 100644 arch/openrisc/kernel/process.c
arch/openrisc/include/asm/thread_info.h new file +149 -0
@@ -0,0 +1,149 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef _ASM_THREAD_INFO_H +#define _ASM_THREAD_INFO_H + +#ifdef __KERNEL__ + +#ifndef __ASSEMBLY__ +#include <asm/types.h> +#include <asm/processor.h> +#endif + + +/* THREAD_SIZE is the size of the task_struct/kernel_stack combo. +* normally, the stack is found by doing something like p + THREAD_SIZE +* in or32, a page is 8192 bytes, which seems like a sane size +*/ + +#define THREAD_SIZE_ORDER 0 +#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) + +/* +* low level task data that entry.S needs immediate access to +* - this struct should fit entirely inside of one cache line +* - this struct shares the supervisor stack pages +* - if the contents of this structure are changed, the assembly constants +* must also be changed +*/ +#ifndef __ASSEMBLY__ + +typedef unsigned long mm_segment_t ; + +struct debug_entry { +unsigned long address;/* Address of breakpoint */ +unsigned long insn;/* Instruction replaced */ +unsigned long set;/* Is BP active? */ +unsigned long branch;/* BP is after a branch */ +unsigned long branch_target;/* Branch address */ +unsigned long branch_insn_address;/* PC of l.b/l.j */ +}; + +struct debug_info { +struct debug_entry bp; +}; + +struct thread_info { +struct task_struct *task;/* main task structure */ +struct exec_domain *exec_domain;/* execution domain */ +unsigned long flags;/* low level flags */ +__u32 cpu;/* current CPU */ +__s32 preempt_count;/* 0 => preemptable, <0 => BUG */ + +mm_segment_t addr_limit;/* thread address space: +0-0x7FFFFFFF for user-thead +0-0xFFFFFFFF for kernel-thread +*/ +struct restart_block restart_block; +__u8 supervisor_stack[0 ]; + +/* saved context data */ +unsigned long ksp; + +struct debug_info debug; +}; +#endif + +/* +* macros/functions for gaining access to the thread information structure +* +* preempt_count needs to be 1 initially, until the scheduler is functional. +*/ +#ifndef __ASSEMBLY__ +#define INIT_THREAD_INFO (tsk) \ +{ \ + .task = &tsk, \ + .exec_domain = &default_exec_domain, \ + .flags = 0, \ + .cpu = 0, \ + .preempt_count = 1, \ + .addr_limit = KERNEL_DS, \ + .restart_block = { \ + .fn = do_no_restart_syscall, \ + }, \ + .ksp = 0, \ +} + +#define init_thread_info (init_thread_union.thread_info) + +/* how to get the thread information struct from C */ +registerstruct thread_info *current_thread_info_reg asm("r10" ); +#define current_thread_info () (current_thread_info_reg) + +#define get_thread_info (ti) get_task_struct((ti)->task) +#define put_thread_info (ti) put_task_struct((ti)->task) + +#endif /* !__ASSEMBLY__ */ + +/* +* thread information flags +* these are process state flags that various assembly files may need to +* access +* - pending work-to-be-done flags are in LSW +* - other flags in MSW +*/ +#define TIF_SYSCALL_TRACE 0/* syscall trace active */ +#define TIF_NOTIFY_RESUME 1/* resumption notification requested */ +#define TIF_SIGPENDING 2/* signal pending */ +#define TIF_NEED_RESCHED 3/* rescheduling necessary */ +#define TIF_SINGLESTEP 4/* restore singlestep on return to user +* mode +*/ +#define TIF_SYSCALL_TRACEPOINT 8/* for ftrace syscall instrumentation */ +#define TIF_RESTORE_SIGMASK 9 +#define TIF_POLLING_NRFLAG 16/* true if poll_idle() is polling * TIF_NEED_RESCHED +*/ +#define TIF_MEMDIE 17 + +#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) +#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) +#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) +#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) +#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP) +#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) +#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) + + +/* Work to do when returning from interrupt/exception */ +/* For OpenRISC, this is anything in the LSW other than syscall trace */ +#define _TIF_WORK_MASK (0xff & ~(_TIF_SYSCALL_TRACE|_TIF_SINGLESTEP)) + +#endif /* __KERNEL__ */ + +#endif /* _ASM_THREAD_INFO_H */
arch/openrisc/kernel/idle.c +1 -1
@@ -62,7 +62,7 @@ void cpu_idle(void)local_irq_disable ();/* Don't trace irqs off for idle */ stop_critical_timings (); -if (powersave !=NULL ) +if (!need_resched () && powersave !=NULL )powersave ();start_critical_timings ();local_irq_enable ();
arch/openrisc/kernel/process.c new file +305 -0
305 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 13/19 OpenRISC: GPIO
In reply to Jonas Bonn--- arch/openrisc/include/asm/gpio.h | 65 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 65 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/gpio.h
arch/openrisc/include/asm/gpio.h new file +65 -0
@@ -0,0 +1,65 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_GPIO_H +#define __ASM_OPENRISC_GPIO_H + +#include <linux/errno.h> +#include <asm-generic/gpio.h> + +#ifdef CONFIG_GPIOLIB + +/* +* OpenRISC (or1k) does not have on-chip GPIO's so there is not really +* any standardized implementation that makes sense here. If passing +* through gpiolib becomes a bottleneck then it may make sense, on a +* case-by-case basis, to implement these inlined/rapid versions. +* +* Just call gpiolib. +*/ +static inline int gpio_get_value (unsigned int gpio) +{ +return __gpio_get_value (gpio); +} + +static inline void gpio_set_value (unsigned int gpio,int value) +{ +__gpio_set_value (gpio, value); +} + +static inline int gpio_cansleep (unsigned int gpio) +{ +return __gpio_cansleep (gpio); +} + +/* +* Not implemented, yet. +*/ +static inline int gpio_to_irq (unsigned int gpio) +{ +return -ENOSYS ; +} + +static inline int irq_to_gpio (unsigned int irq) +{ +return -EINVAL ; +} + +#endif /* CONFIG_GPIOLIB */ + +#endif /* __ASM_OPENRISC_GPIO_H */
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 14/19 OpenRISC: Module support
In reply to Jonas BonnThis is still our old module support implementation. There's a pending patch to move a lot of this functionality into default hooks that are available in core code to all arches; if that patch is accepted, this patch becomes significantly smaller.
--- arch/openrisc/kernel/module.c | 126 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/kernel/module.c
arch/openrisc/kernel/module.c new file +126 -0
@@ -0,0 +1,126 @@ +/* +* OpenRISC module.c +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#include <linux/moduleloader.h> +#include <linux/elf.h> +#include <linux/vmalloc.h> +#include <linux/fs.h> +#include <linux/string.h> +#include <linux/kernel.h> + +void *module_alloc (unsigned long size) +{ +pr_debug ("module_alloc size: %lu\n" , size); + +if (size ==0 ) +return NULL ; + +return vmalloc (size); +} + + +/* Free memory returned from module_alloc */ +void module_free (struct module *mod,void *module_region) +{ +vfree (module_region); +/* FIXME: If module_region == mod->init_region, trim exception +table entries. */ +} + +/* We don't need anything special. */ +int module_frob_arch_sections (Elf_Ehdr *hdr, +Elf_Shdr *sechdrs, +char *secstrings, +struct module *mod) +{ +return 0 ; +} + +int apply_relocate_add (Elf32_Shdr *sechdrs, +const char *strtab, +unsigned int symindex, +unsigned int relsec, +struct module *me) +{ +unsigned int i; +Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr; +Elf32_Sym *sym; +// Elf32_Addr relocation; +uint32_t *location; +uint32_t value; + +pr_debug ("Applying relocate section %u to %u\n" , relsec, + sechdrs[relsec].sh_info); +for (i =0 ; i < sechdrs[relsec].sh_size /sizeof (*rel); i++) { +/* This is where to make the change */ + location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + + rel[i].r_offset; + +/* This is the symbol it is referring to. Note that all +undefined symbols have been resolved. */ + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr + +ELF32_R_SYM (rel[i].r_info); + value = sym->st_value + rel[i].r_addend; + +switch (ELF32_R_TYPE (rel[i].r_info)) { +case R_OR32_32 : + *location = value; +break ; +case R_OR32_CONST : + location = (uint16_t *)location +1 ; + *((uint16_t *)location) = (uint16_t ) (value); +break ; +case R_OR32_CONSTH : + location = (uint16_t *)location +1 ; + *((uint16_t *)location) = (uint16_t ) (value >>16 ); +break ; +case R_OR32_JUMPTARG : + value -= (uint32_t )location; + value >>=2 ; + value &=0x03ffffff ; + value |= *location &0xfc000000 ; + *location = value; +break ; +default : +pr_err ("module %s: Unknown relocation: %u\n" , + me->name,ELF32_R_TYPE (rel[i].r_info)); +break ; + } + } + +return 0 ; +} + +int apply_relocate (Elf32_Shdr *sechdrs, +const char *strtab, +unsigned int symindex, +unsigned int relsec, +struct module *me) +{ +pr_err ("module %s: REL relocation unsupported\n" , me->name); +return -ENOEXEC ; +} + +int module_finalize (const Elf_Ehdr *hdr, +const Elf_Shdr *sechdrs, +struct module *me) +{ +return 0 ; +} + +void module_arch_cleanup (struct module *mod) +{ +}
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 15/19 OpenRISC: Traps
In reply to Jonas Bonn--- arch/openrisc/kernel/traps.c | 367 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 367 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/kernel/traps.c
arch/openrisc/kernel/traps.c new file +367 -0
@@ -0,0 +1,367 @@ +/* +* OpenRISC traps.c +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[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. +* +* Here we handle the break vectors not used by the system call +* mechanism, as well as some general stack/register dumping +* things. +* +*/ + +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/kmod.h> +#include <linux/string.h> +#include <linux/errno.h> +#include <linux/ptrace.h> +#include <linux/timer.h> +#include <linux/mm.h> +#include <linux/kallsyms.h> +#include <asm/uaccess.h> + +#include <asm/system.h> +#include <asm/segment.h> +#include <asm/io.h> +#include <asm/pgtable.h> + +extern char _etext, _stext; + +int kstack_depth_to_print =0x180 ; + +static inline int valid_stack_ptr (struct thread_info *tinfo,void *p) +{ +return p > (void *)tinfo && p < (void *)tinfo +THREAD_SIZE -3 ; +} + +void show_trace (struct task_struct *task,unsigned long *stack) +{ +struct thread_info *context; +unsigned long addr; + + context = (struct thread_info *) + ((unsigned long )stack & (~(THREAD_SIZE -1 ))); + +while (valid_stack_ptr (context, stack)) { + addr = *stack++; +if (__kernel_text_address (addr)) { +printk (" [<%08lx>]" , addr); +print_symbol (" %s" , addr); +printk ("\n" ); + } + } +printk (" =======================\n" ); +} + +/* displays a short stack trace */ +void show_stack (struct task_struct *task,unsigned long *esp) +{ +unsigned long addr, *stack; +int i; + +if (esp ==NULL ) + esp = (unsigned long *)&esp; + + stack = esp; + +printk ("Stack dump [0x%08lx]:\n" , (unsigned long )esp); +for (i =0 ; i < kstack_depth_to_print; i++) { +if (kstack_end (stack)) +break ; +if (__get_user (addr, stack)) { +/* This message matches "failing address" marked +s390 in ksymoops, so lines containing it will +not be filtered out by ksymoops. */ +printk ("Failing address 0x%lx\n" , (unsigned long )stack); +break ; + } + stack++; + +printk ("sp + %02d: 0x%08lx\n" , i *4 , addr); + } +printk ("\n" ); + +show_trace (task, esp); + +return ; +} + +void show_trace_task (struct task_struct *tsk) +{ +/* +* TODO: SysRq-T trace dump... +*/ +} + +/* +* The architecture-independent backtrace generator +*/ +void dump_stack (void ) +{ +unsigned long stack; + +show_stack (current, &stack); +} + +void show_registers (struct pt_regs *regs) +{ +int i; +int in_kernel =1 ; +unsigned long esp; + + esp = (unsigned long )(®s->sp); +if (user_mode (regs)) + in_kernel =0 ; + +printk ("CPU #: %d\n" +" PC: %08lx SR: %08lx SP: %08lx\n" , +smp_processor_id (), regs->pc, regs->sr, regs->sp); +printk ("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n" , +0L , regs->gpr[1 ], regs->gpr[2 ], regs->gpr[3 ]); +printk ("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n" , + regs->gpr[4 ], regs->gpr[5 ], regs->gpr[6 ], regs->gpr[7 ]); +printk ("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n" , + regs->gpr[8 ], regs->gpr[9 ], regs->gpr[10 ], regs->gpr[11 ]); +printk ("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n" , + regs->gpr[12 ], regs->gpr[13 ], regs->gpr[14 ], regs->gpr[15 ]); +printk ("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n" , + regs->gpr[16 ], regs->gpr[17 ], regs->gpr[18 ], regs->gpr[19 ]); +printk ("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n" , + regs->gpr[20 ], regs->gpr[21 ], regs->gpr[22 ], regs->gpr[23 ]); +printk ("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n" , + regs->gpr[24 ], regs->gpr[25 ], regs->gpr[26 ], regs->gpr[27 ]); +printk ("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n" , + regs->gpr[28 ], regs->gpr[29 ], regs->gpr[30 ], regs->gpr[31 ]); +printk (" RES: %08lx oGPR11: %08lx syscallno: %08lx\n" , + regs->gpr[11 ], regs->orig_gpr11, regs->syscallno); + +printk ("Process %s (pid: %d, stackpage=%08lx)\n" , + current->comm, current->pid, (unsigned long )current); +/* +* When in-kernel, we also print out the stack and code at the +* time of the fault.. +*/ +if (in_kernel) { + +printk ("\nStack: " ); +show_stack (NULL , (unsigned long *)esp); + +printk ("\nCode: " ); +if (regs->pc <PAGE_OFFSET ) + goto bad; + +for (i =-24 ; i <24 ; i++) { +unsigned char c; +if (__get_user (c, &((unsigned char *)regs->pc)[i])) { +bad: +printk (" Bad PC value." ); +break ; + } + +if (i ==0 ) +printk ("(%02x) " , c); +else +printk ("%02x " , c); + } + } +printk ("\n" ); +} + +void nommu_dump_state (struct pt_regs *regs, +unsigned long ea,unsigned long vector) +{ +int i; +unsigned long addr, stack = regs->sp; + +printk ("\n\r[nommu_dump_state] :: ea %lx, vector %lx\n\r" , ea, vector); + +printk ("CPU #: %d\n" +" PC: %08lx SR: %08lx SP: %08lx\n" , +0 , regs->pc, regs->sr, regs->sp); +printk ("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n" , +0L , regs->gpr[1 ], regs->gpr[2 ], regs->gpr[3 ]); +printk ("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n" , + regs->gpr[4 ], regs->gpr[5 ], regs->gpr[6 ], regs->gpr[7 ]); +printk ("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n" , + regs->gpr[8 ], regs->gpr[9 ], regs->gpr[10 ], regs->gpr[11 ]); +printk ("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n" , + regs->gpr[12 ], regs->gpr[13 ], regs->gpr[14 ], regs->gpr[15 ]); +printk ("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n" , + regs->gpr[16 ], regs->gpr[17 ], regs->gpr[18 ], regs->gpr[19 ]); +printk ("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n" , + regs->gpr[20 ], regs->gpr[21 ], regs->gpr[22 ], regs->gpr[23 ]); +printk ("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n" , + regs->gpr[24 ], regs->gpr[25 ], regs->gpr[26 ], regs->gpr[27 ]); +printk ("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n" , + regs->gpr[28 ], regs->gpr[29 ], regs->gpr[30 ], regs->gpr[31 ]); +printk (" RES: %08lx oGPR11: %08lx syscallno: %08lx\n" , + regs->gpr[11 ], regs->orig_gpr11, regs->syscallno); + +printk ("Process %s (pid: %d, stackpage=%08lx)\n" , + ((struct task_struct *)(__pa (current)))->comm, + ((struct task_struct *)(__pa (current)))->pid, + (unsigned long )current); + +printk ("\nStack: " ); +printk ("Stack dump [0x%08lx]:\n" , (unsigned long )stack); +for (i =0 ; i < kstack_depth_to_print; i++) { +if (((long )stack & (THREAD_SIZE -1 )) ==0 ) +break ; + stack++; + +printk ("%lx :: sp + %02d: 0x%08lx\n" , stack, i *4 , + *((unsigned long *)(__pa (stack)))); + } +printk ("\n" ); + +printk ("Call Trace: " ); + i =1 ; +while (((long )stack & (THREAD_SIZE -1 )) !=0 ) { + addr = *((unsigned long *)__pa (stack)); + stack++; + +if (kernel_text_address (addr)) { +if (i && ((i %6 ) ==0 )) +printk ("\n " ); +printk (" [<%08lx>]" , addr); + i++; + } + } +printk ("\n" ); + +printk ("\nCode: " ); + +for (i =-24 ; i <24 ; i++) { +unsigned char c; + c = ((unsigned char *)(__pa (regs->pc)))[i]; + +if (i ==0 ) +printk ("(%02x) " , c); +else +printk ("%02x " , c); + } +printk ("\n" ); +} + +/* This is normally the 'Oops' routine */ +void die (const char *str,struct pt_regs *regs,long err) +{ + +console_verbose (); +printk ("\n%s#: %04lx\n" , str, err &0xffff ); +show_registers (regs); +#ifdef CONFIG_JUMP_UPON_UNHANDLED_EXCEPTION +printk ("\n\nUNHANDLED_EXCEPTION: entering infinite loop\n" ); + +/* shut down interrupts */ +local_irq_disable (); + + __asm__ __volatile__("l.nop 1" ); +do {}while (1 ); +#endif +do_exit (SIGSEGV ); +} + +/* This is normally the 'Oops' routine */ +void die_if_kernel (const char *str,struct pt_regs *regs,long err) +{ +if (user_mode (regs)) +return ; + +die (str, regs, err); +} + +void unhandled_exception (struct pt_regs *regs,int ea,int vector) +{ +printk ("Unable to handle exception at EA =0x%x, vector 0x%x" , + ea, vector); +die ("Oops" , regs,9 ); +} + +void __init trap_init (void ) +{ +/* Nothing needs to be done */ +} + +asmlinkage void do_trap(struct pt_regs *regs, unsigned long address) +{ +siginfo_t info; +memset (&info,0 ,sizeof (info)); + info.si_signo =SIGTRAP ; + info.si_code =TRAP_TRACE ; + info.si_addr = (void *)address; +force_sig_info (SIGTRAP , &info, current); + +if (!(test_tsk_thread_flag (current,TIF_SINGLESTEP ))) + regs->pc +=4 ; +} + +asmlinkage void do_unaligned_access(struct pt_regs *regs, unsigned long address) +{ +siginfo_t info; + +if (user_mode (regs)) { +/* Send a SIGSEGV */ + info.si_signo =SIGSEGV ; + info.si_errno =0 ; +/* info.si_code has been set above */ + info.si_addr = (void *)address; +force_sig_info (SIGSEGV , &info, current); + }else { +printk ("KERNEL: Unaligned Access 0x%.8lx\n" , address); +show_registers (regs); +die ("Die:" , regs, address); + } + +} + +asmlinkage void do_bus_fault(struct pt_regs *regs, unsigned long address) +{ +siginfo_t info; + +if (user_mode (regs)) { +/* Send a SIGBUS */ + info.si_signo =SIGBUS ; + info.si_errno =0 ; + info.si_code =BUS_ADRERR ; + info.si_addr = (void *)address; +force_sig_info (SIGBUS , &info, current); + }else {/* Kernel mode */ +printk ("KERNEL: Bus error (SIGBUS) 0x%.8lx\n" , address); +show_registers (regs); +die ("Die:" , regs, address); + } +} + +asmlinkage void do_illegal_instruction(struct pt_regs *regs, +unsigned long address) +{ +siginfo_t info; + +if (user_mode (regs)) { +/* Send a SIGILL */ + info.si_signo =SIGILL ; + info.si_errno =0 ; + info.si_code =ILL_ILLOPC ; + info.si_addr = (void *)address; +force_sig_info (SIGBUS , &info, current); + }else {/* Kernel mode */ +printk ("KERNEL: Illegal instruction (SIGILL) 0x%.8lx\n" , + address); +show_registers (regs); +die ("Die:" , regs, address); + } +}
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 16/19 OpenRISC: Headers
In reply to Jonas Bonn--- arch/openrisc/include/asm/asm-offsets.h | 1 + arch/openrisc/include/asm/bitops.h | 59 +++ arch/openrisc/include/asm/bitops/__ffs.h | 33 ++ arch/openrisc/include/asm/bitops/__fls.h | 33 ++ arch/openrisc/include/asm/bitops/ffs.h | 32 ++ arch/openrisc/include/asm/bitops/fls.h | 33 ++ arch/openrisc/include/asm/byteorder.h | 1 + arch/openrisc/include/asm/cpuinfo.h | 34 ++ arch/openrisc/include/asm/delay.h | 24 ++ arch/openrisc/include/asm/elf.h | 109 ++++++ arch/openrisc/include/asm/io.h | 51 +++ arch/openrisc/include/asm/linkage.h | 25 ++ arch/openrisc/include/asm/mutex.h | 27 ++ arch/openrisc/include/asm/param.h | 26 ++ arch/openrisc/include/asm/processor.h | 112 ++++++ arch/openrisc/include/asm/serial.h | 36 ++ arch/openrisc/include/asm/spinlock.h | 24 ++ arch/openrisc/include/asm/spr.h | 42 ++ arch/openrisc/include/asm/spr_defs.h | 604 ++++++++++++++++++++++++++++++ arch/openrisc/include/asm/system.h | 35 ++ arch/openrisc/include/asm/unaligned.h | 51 +++ arch/openrisc/kernel/vmlinux.h | 12 + 22 files changed, 1404 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/include/asm/asm-offsets.h create mode 100644 arch/openrisc/include/asm/bitops.h create mode 100644 arch/openrisc/include/asm/bitops/__ffs.h create mode 100644 arch/openrisc/include/asm/bitops/__fls.h create mode 100644 arch/openrisc/include/asm/bitops/ffs.h create mode 100644 arch/openrisc/include/asm/bitops/fls.h create mode 100644 arch/openrisc/include/asm/byteorder.h create mode 100644 arch/openrisc/include/asm/cpuinfo.h create mode 100644 arch/openrisc/include/asm/delay.h create mode 100644 arch/openrisc/include/asm/elf.h create mode 100644 arch/openrisc/include/asm/io.h create mode 100644 arch/openrisc/include/asm/linkage.h create mode 100644 arch/openrisc/include/asm/mutex.h create mode 100644 arch/openrisc/include/asm/param.h create mode 100644 arch/openrisc/include/asm/processor.h create mode 100644 arch/openrisc/include/asm/serial.h create mode 100644 arch/openrisc/include/asm/spinlock.h create mode 100644 arch/openrisc/include/asm/spr.h create mode 100644 arch/openrisc/include/asm/spr_defs.h create mode 100644 arch/openrisc/include/asm/system.h create mode 100644 arch/openrisc/include/asm/unaligned.h create mode 100644 arch/openrisc/kernel/vmlinux.h
arch/openrisc/include/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include <generated/asm-offsets.h>
arch/openrisc/include/asm/bitops.h new file +59 -0
59 lines not on this page · raw message
arch/openrisc/include/asm/bitops/__ffs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* OpenRISC Linux +* +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC___FFS_H +#define __ASM_OPENRISC___FFS_H + + +#ifdef CONFIG_OPENRISC_HAVE_INST_FF1 + +static inline unsigned long __ffs (unsigned long x) +{ +int ret; + + __asm__ ("l.ff1 %0,%1" + :"=r" (ret) + :"r" (x)); + +return ret-1 ; +} + +#else +#include <asm-generic/bitops/__ffs.h> +#endif + +#endif /* __ASM_OPENRISC___FFS_H */
arch/openrisc/include/asm/bitops/__fls.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* OpenRISC Linux +* +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC___FLS_H +#define __ASM_OPENRISC___FLS_H + + +#ifdef CONFIG_OPENRISC_HAVE_INST_FL1 + +static inline unsigned long __fls (unsigned long x) +{ +int ret; + + __asm__ ("l.fl1 %0,%1" + :"=r" (ret) + :"r" (x)); + +return ret-1 ; +} + +#else +#include <asm-generic/bitops/__fls.h> +#endif + +#endif /* __ASM_OPENRISC___FLS_H */
arch/openrisc/include/asm/bitops/ffs.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* OpenRISC Linux +* +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_FFS_H +#define __ASM_OPENRISC_FFS_H + +#ifdef CONFIG_OPENRISC_HAVE_INST_FF1 + +static inline int ffs (int x) +{ +int ret; + + __asm__ ("l.ff1 %0,%1" + :"=r" (ret) + :"r" (x)); + +return ret; +} + +#else +#include <asm-generic/bitops/ffs.h> +#endif + +#endif /* __ASM_OPENRISC_FFS_H */
arch/openrisc/include/asm/bitops/fls.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* OpenRISC Linux +* +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_FLS_H +#define __ASM_OPENRISC_FLS_H + + +#ifdef CONFIG_OPENRISC_HAVE_INST_FL1 + +static inline int fls (int x) +{ +int ret; + + __asm__ ("l.fl1 %0,%1" + :"=r" (ret) + :"r" (x)); + +return ret; +} + +#else +#include <asm-generic/bitops/fls.h> +#endif + +#endif /* __ASM_OPENRISC_FLS_H */
arch/openrisc/include/asm/byteorder.h new file +1 -0
@@ -0,0 +1 @@ +#include <linux/byteorder/big_endian.h>
arch/openrisc/include/asm/cpuinfo.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_CPUINFO_H +#define __ASM_OPENRISC_CPUINFO_H + +struct cpuinfo { +u32 clock_frequency; + +u32 icache_size; +u32 icache_block_size; + +u32 dcache_size; +u32 dcache_block_size; +}; + +extern struct cpuinfo cpuinfo; + +#endif /* __ASM_OPENRISC_CPUINFO_H */
arch/openrisc/include/asm/delay.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2010-2011 Jonas Bonn <[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. +*/ + +#ifndef __ASM_OPENRISC_DELAY_H +#define __ASM_OPENRISC_DELAY_H + +#include <asm-generic/delay.h> + +extern unsigned long loops_per_jiffy; + +#endif
arch/openrisc/include/asm/elf.h new file +109 -0
109 lines not on this page · raw message
arch/openrisc/include/asm/io.h new file +51 -0
51 lines not on this page · raw message
arch/openrisc/include/asm/linkage.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_LINKAGE_H +#define __ASM_OPENRISC_LINKAGE_H + +#define __ALIGN .align 0 +#define __ALIGN_STR ".align 0" + +#endif /* __ASM_OPENRISC_LINKAGE_H */
arch/openrisc/include/asm/mutex.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +/* +* Pull in the generic implementation for the mutex fastpath. +* +* TODO: implement optimized primitives instead, or leave the generic +* implementation in place, or pick the atomic_xchg() based generic +* implementation. (see asm-generic/mutex-xchg.h for details) +*/ + +#include <asm-generic/mutex-dec.h>
arch/openrisc/include/asm/param.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_PARAM_H +#define __ASM_OPENRISC_PARAM_H + +#define EXEC_PAGESIZE 8192 + +#include <asm-generic/param.h> + +#endif /* __ASM_OPENRISC_PARAM_H */
arch/openrisc/include/asm/processor.h new file +112 -0
112 lines not on this page · raw message
arch/openrisc/include/asm/serial.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SERIAL_H +#define __ASM_OPENRISC_SERIAL_H + +#ifdef __KERNEL__ + +#include <asm/cpuinfo.h> + +/* There's a generic version of this file, but it assumes a 1.8MHz UART clk... +* this, on the other hand, assumes the UART clock is tied to the system +* clock... 8250_early.c (early 8250 serial console) actually uses this, so +* it needs to be correct to get the early console working. +*/ + +#define BASE_BAUD (cpuinfo.clock_frequency/16) + +#endif /* __KERNEL__ */ + +#endif /* __ASM_OPENRISC_SERIAL_H */
arch/openrisc/include/asm/spinlock.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SPINLOCK_H +#define __ASM_OPENRISC_SPINLOCK_H + +#error "or32 doesn't do SMP yet" + +#endif
arch/openrisc/include/asm/spr.h new file +42 -0
42 lines not on this page · raw message
arch/openrisc/include/asm/spr_defs.h new file +604 -0
604 lines not on this page · raw message
arch/openrisc/include/asm/system.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* OpenRISC implementation: +* Copyright (C) 2003 Matjaz Breskvar <[email protected]> +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* et al. +* +* 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. +*/ + +#ifndef __ASM_OPENRISC_SYSTEM_H +#define __ASM_OPENRISC_SYSTEM_H + +#ifdef __KERNEL__ +#ifndef __ASSEMBLY__ + +#include <asm/spr.h> +#include <asm-generic/system.h> + +/* We probably need this definition, but the generic system.h provides it +* and it's not used on our arch anyway... +*/ +/*#define nop() __asm__ __volatile__ ("l.nop"::)*/ + +#endif /* __ASSEMBLY__ */ +#endif /* __KERNEL__ */ +#endif /* __ASM_OPENRISC_SYSTEM_H */
arch/openrisc/include/asm/unaligned.h new file +51 -0
51 lines not on this page · raw message
arch/openrisc/kernel/vmlinux.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef __OPENRISC_VMLINUX_H_ +#define __OPENRISC_VMLINUX_H_ + +extern char _stext, _etext, _edata, _end; +#ifdef CONFIG_BLK_DEV_INITRD +extern char __initrd_start, __initrd_end; +extern char __initramfs_start; +#endif + +extern u32 __dtb_start[]; + +#endif
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 17/19 OpenRISC: Library routines
In reply to Jonas Bonn--- arch/openrisc/lib/delay.c | 60 +++++++++++++ arch/openrisc/lib/string.S | 204 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 264 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/lib/delay.c create mode 100644 arch/openrisc/lib/string.S
arch/openrisc/lib/delay.c new file +60 -0
@@ -0,0 +1,60 @@ +/* +* OpenRISC Linux +* +* Linux architectural port borrowing liberally from similar works of +* others. All original copyrights apply as per the original source +* declaration. +* +* Modifications for the OpenRISC architecture: +* Copyright (C) 2010-2011 Jonas Bonn <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation +* +* Precise Delay Loops +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <asm/delay.h> +#include <asm/timex.h> +#include <asm/processor.h> + +int __devinit read_current_timer (unsigned long *timer_value) +{ + *timer_value =mfspr (SPR_TTCR ); +return 0 ; +} + +void __delay (unsigned long cycles) +{ +cycles_t target =get_cycles () + cycles; + +while (get_cycles () < target) +cpu_relax (); +} +EXPORT_SYMBOL (__delay); + +inline void __const_udelay (unsigned long xloops) +{ +unsigned long long loops; + + loops = xloops * loops_per_jiffy *HZ ; + +__delay (loops >>32 ); +} +EXPORT_SYMBOL (__const_udelay); + +void __udelay (unsigned long usecs) +{ +__const_udelay (usecs *0x10C7UL );/* 2**32 / 1000000 (rounded up) */ +} +EXPORT_SYMBOL (__udelay); + +void __ndelay (unsigned long nsecs) +{ +__const_udelay (nsecs *0x5UL );/* 2**32 / 1000000000 (rounded up) */ +} +EXPORT_SYMBOL (__ndelay);
arch/openrisc/lib/string.S new file +204 -0
204 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 18/19 OpenRISC: Miscellaneous
In reply to Jonas BonnAdds README file, TODO list, config file for or1ksim simulator, and a couple of other pieces that didn't seem to fit into any other patch.
--- arch/openrisc/README.openrisc | 102 ++++ arch/openrisc/TODO.openrisc | 18 + arch/openrisc/kernel/asm-offsets.c | 70 +++ arch/openrisc/kernel/or32_ksyms.c | 46 ++ arch/openrisc/or1ksim.cfg | 888 ++++++++++++++++++++++++++++++++++++ 5 files changed, 1124 insertions(+), 0 deletions(-) create mode 100644 arch/openrisc/README.openrisc create mode 100644 arch/openrisc/TODO.openrisc create mode 100644 arch/openrisc/kernel/asm-offsets.c create mode 100644 arch/openrisc/kernel/or32_ksyms.c create mode 100644 arch/openrisc/or1ksim.cfg
arch/openrisc/README.openrisc new file +102 -0
@@ -0,0 +1,102 @@ +OpenRISC Linux +============== + +This is a port of Linux to the OpenRISC class of microprocessors; the initial +target architecture, specifically, is the 32-bit OpenRISC 1000 family (or1k). + +For more information about OpenRISC processors and ongoing development: + + website http://openrisc.net + +Additional information, though not kept up to date by the site maintainers, +can be found at http://opencores.org/openrisc + +For information about Linux on OpenRISC, please contact South Pole AB. + + email: [email protected] + + website: http://southpole.se + http://southpoleconsulting.com + +--------------------------------------------------------------------- + +Build instructions for OpenRISC toolchain and Linux +=================================================== + +In order to build and run Linux for OpenRISC, you'll need at least a basic +toolchain and, perhaps, the architectural simulator. Steps to get these bits +in place are outlined here. + +1) The toolchain can be obtained from openrisc.net. Instructions for building +a toolchain can be found at: + +http://openrisc.net/toolchain-build.html + +2) or1ksim (optional) + +or1ksim is the architectural simulator which will allow you to actually run +your OpenRISC Linux kernel if you don't have an OpenRISC processor at hand. + + git clone git://openrisc.net/jonas/or1ksim-svn + + cd or1ksim + ./configure --prefix=$OPENRISC_PREFIX + make + make install + +3) Linux kernel + +Build the kernel as usual + + make ARCH=openrisc defconfig + make ARCH=openrisc + +4) Run in architectural simulator + +There's a configuration file for the architectural simulator (or1ksim) in the +arch/openrisc directory, allowing you to run your kernel with the following +incantation: + + sim -f arch/openrisc/or1ksim.cfg vmlinux + +--------------------------------------------------------------------- + +Terminology +=========== + +In the code, the following particles are used on symbols to limit the scope +to more or less specific processor implementations: + +openrisc: the OpenRISC class of processors +or1k: the OpenRISC 1000 family of processors +or1200: the OpenRISC 1200 processor + +--------------------------------------------------------------------- + +History +======== + +18. 11. 2003 Matjaz Breskvar ([email protected]) + initial port of linux to OpenRISC/or32 architecture. + all the core stuff is implemented and seams usable. + +08. 12. 2003 Matjaz Breskvar ([email protected]) + complete change of TLB miss handling. + rewrite of exceptions handling. + fully functional sash-3.6 in default initrd. + a much improved version with changes all around. + +10. 04. 2004 Matjaz Breskvar ([email protected]) + alot of bugfixes all over. + ethernet support, functional http and telnet servers. + running many standard linux apps. + +26. 06. 2004 Matjaz Breskvar ([email protected]) + port to 2.6.x + +30. 11. 2004 Matjaz Breskvar ([email protected]) + lots of bugfixes and enhancments. + added opencores framebuffer driver. + +09. 10. 2010 Jonas Bonn ([email protected]) + major rewrite to bring up to par with upstream Linux 2.6.36
arch/openrisc/TODO.openrisc new file +18 -0
@@ -0,0 +1,18 @@ +The OpenRISC Linux port is fully functional and has been tracking upstream +since 2.6.35. There are, however, remaining items to be completed within +the coming months. Here's a list of known-to-be-less-than-stellar items +that are due for investigation shortly, i.e. our TODO list: + +Implement the rest of the DMA API... dma_map_sg, etc. + +Consolidate usage of memblock and bootmem... move everything over to memblock. + +Clean up defconfigs: +- remove initramfs, cross-compile, local version, etc. + +Finish the renaming cleanup... there are references to or32 in the code +which was an older name for the architecture. The name we've settled on is +or1k and this change is slowly trickling through the stack. For the time +being, or32 is equivalent to or1k. + +Implement optimized version of memcpy and memset
arch/openrisc/kernel/asm-offsets.c new file +70 -0
70 lines not on this page · raw message
arch/openrisc/kernel/or32_ksyms.c new file +46 -0
46 lines not on this page · raw message
arch/openrisc/or1ksim.cfg new file +888 -0
888 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Jonas Bonn
maintainerPATCH v2 19/19 OpenRISC: Add MAINTAINERS entry
In reply to Jonas Bonn--- MAINTAINERS | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
@@ -4668,6 +4668,14 @@ F: drivers/of F: include/linux/of*.h K: of_get_property +OPENRISC ARCHITECTURE +M: Jonas Bonn <[email protected]> +W: http://openrisc.net +L: [email protected] +S: Maintained +T: git git://openrisc.net/~jonas/linux +F: arch/openrisc + OPL4 DRIVER M: Clemens Ladisch <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
1.7.4.1
Arnd Bergmann
maintainerQuoted 13 lines · Jonas Bonn
This is version 2 of the OpenRISC architecture patch set. Changes since version 1 include:
- general cleanups, removing unused code and variables, taking care of compiler warnings, etc.
- cleanups for all the errors spotted by checkpatch.pl
- changes in response to the feedback received for version 1 of the patch set
- simplification of the fixmap code
- simplification of the DMA code
- calculateloops_per_jiffyfrom cpu frequency passed in via devicetree
- reworkio.hto use more generic code
- rework the delay code, making it more generic
Quoted 2 lines
- also, the module code has been reworked, making it more generic; this is not included in this patch as the generic parts are still pending review
I think this is basically ready for inclusion in 3.1. There are a few details that you can still improve, but I see no reason to hold up the merge into mainline. After you have addressed the comments that are still outstanding at this time, please add "Reviewed-by: Arnd Bergmann <[email protected]>" to all the patches.
The most important part to work out are the device tree bindings, as discussed for patch 2. Once you have a version of that patch that everyone is happy with, please post the entire series including the patches that address common code once more.
Quoted 3 lines
Once again, all this code can be found in the 'for-upstream' branch at:
git://openrisc.net/jonas/linux
IMO it would be best if Stephen added that branch to linux-next right away, so we get some test exposure on your common code changes before the merge window.
Arnd
Jonas Bonn
maintainerlinux-next inclusion request: OpenRISC architecture
Quoted 4 lines · Arnd Bergmann
IMO it would be best if Stephen added that branch to linux-next right away, so we get some test exposure on your common code changes before the merge window.
Hi Stephen,
I'd like to request the inclusion of the OpenRISC architecture kernel tree into the linux-next repository. The relevant branch is the 'for-upstream' branch of the repository at:
git://openrisc.net/jonas/linux
Thanks,
Jonas
Re: linux-next inclusion request: OpenRISC architecture
Hi Jonas,
Quoted 7 lines · On Wed, 06 Jul 2011 17:51:31 +0200 Jonas Bonn <[email protected]> wrote:
Quoted 4 lines · Arnd Bergmann
IMO it would be best if Stephen added that branch to linux-next right away, so we get some test exposure on your common code changes before the merge window.
Quoted 5 lines
I'd like to request the inclusion of the OpenRISC architecture kernel tree into the linux-next repository. The relevant branch is the 'for-upstream' branch of the repository at:
git://openrisc.net/jonas/linux
I will include that tree in the next linux-next release.
Thanks for adding your subsystem tree as a participant of linux-next. As you may know, this is not a judgment of your code. The purpose of linux-next is for integration testing and to lower the impact of conflicts between subsystems in the next merge window.
You will need to ensure that the patches/commits in your tree/series have been:
* submitted under GPL v2 (or later) and include the Contributor's Signed-off-by,
* posted to the relevant mailing list,
* reviewed by you (or another maintainer of your subsystem tree),
* successfully unit tested, and
* destined for the current or next Linux merge window.
Basically, this should be just what you would send to Linus (or ask him to fetch). It is allowed to be rebased if you deem it necessary.
Signature · 15 lines
Cheers, Stephen Rothwell [email protected] Legal Stuff: By participating in linux-next, your subsystem tree contributions are public and will be included in the linux-next trees. You may be sent e-mail messages indicating errors or other issues when the patches/commits from your subsystem tree are merged and tested in linux-next. These messages may also be cross-posted to the linux-next mailing list, the linux-kernel mailing list, etc. The linux-next tree project and IBM (my employer) make no warranties regarding the linux-next project, the testing procedures, the results, the e-mails, etc. If you don't agree to these ground rules, let me know and I'll remove your tree from participation in linux-next.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
arm-soc tree inclusion
Hi Arnd,
Quoted 10 lines · On Thu, 7 Jul 2011 13:05:01 +0200 Arnd Bergmann <[email protected]> wrote:
Ok, I guess that means you also won't be able to merge the arm-soc tree before the merge window, right?
I meant to ask you to include the master branch of
git://git.kernel.org/pub/scm/linux/kernel/git/arm/linux-arm-soc.gitbut we first had to move it into the right location. Can you add that when you get back?
I will add this tree in the next linux-next release.
Thanks for adding your subsystem tree as a participant of linux-next. As you may know, this is not a judgment of your code. The purpose of linux-next is for integration testing and to lower the impact of conflicts between subsystems in the next merge window.
You will need to ensure that the patches/commits in your tree/series have been:
* submitted under GPL v2 (or later) and include the Contributor's Signed-off-by,
* posted to the relevant mailing list,
* reviewed by you (or another maintainer of your subsystem tree),
* successfully unit tested, and
* destined for the current or next Linux merge window.
Basically, this should be just what you would send to Linus (or ask him to fetch). It is allowed to be rebased if you deem it necessary.
Signature · 15 lines
Cheers, Stephen Rothwell [email protected] Legal Stuff: By participating in linux-next, your subsystem tree contributions are public and will be included in the linux-next trees. You may be sent e-mail messages indicating errors or other issues when the patches/commits from your subsystem tree are merged and tested in linux-next. These messages may also be cross-posted to the linux-next mailing list, the linux-kernel mailing list, etc. The linux-next tree project and IBM (my employer) make no warranties regarding the linux-next project, the testing procedures, the results, the e-mails, etc. If you don't agree to these ground rules, let me know and I'll remove your tree from participation in linux-next.