From f47706099bdb8c0e6300d6f5ba8e542861aa3ac5 Mon Sep 17 00:00:00 2001 From: Stefan Kristiansson Date: Sat, 11 Jan 2014 00:17:38 +0200 Subject: [PATCH 01/10] openrisc: fix PTRS_PER_PGD define On OpenRISC, with its 8k pages, PAGE_SHIFT is defined to be 13. That makes the expression (1UL << (PAGE_SHIFT-2)) evaluate to 2048. The correct value for PTRS_PER_PGD should be 256. Correcting the PTRS_PER_PGD define unveiled a bug in map_ram(), where PTRS_PER_PGD was used when the intent was to iterate over a set of page table entries. This patch corrects that issue as well. Signed-off-by: Stefan Kristiansson Acked-by: Jonas Bonn Tested-by: Guenter Roeck Signed-off-by: Stafford Horne --- arch/openrisc/include/asm/pgtable.h | 2 +- arch/openrisc/mm/init.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h index 69c7df0e1420..3567aa7be555 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -69,7 +69,7 @@ extern void paging_init(void); */ #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-2)) -#define PTRS_PER_PGD (1UL << (PAGE_SHIFT-2)) +#define PTRS_PER_PGD (1UL << (32-PGDIR_SHIFT)) /* calculate how many PGD entries a user-level program can use * the first mappable virtual address is 0 diff --git a/arch/openrisc/mm/init.c b/arch/openrisc/mm/init.c index 7f94652311d7..b782ce9ccad9 100644 --- a/arch/openrisc/mm/init.c +++ b/arch/openrisc/mm/init.c @@ -110,7 +110,7 @@ static void __init map_ram(void) set_pmd(pme, __pmd(_KERNPG_TABLE + __pa(pte))); /* Fill the newly allocated page with PTE'S */ - for (j = 0; p < e && j < PTRS_PER_PGD; + for (j = 0; p < e && j < PTRS_PER_PTE; v += PAGE_SIZE, p += PAGE_SIZE, j++, pte++) { if (v >= (u32) _e_kernel_ro || v < (u32) _s_kernel_ro) From c79902190f7e61fcae7c3f4b613c75062f385678 Mon Sep 17 00:00:00 2001 From: Jonas Bonn Date: Mon, 23 Sep 2013 12:04:20 +0200 Subject: [PATCH 02/10] openrisc: restore all regs on rt_sigreturn Fix signal handling for when signals are handled as the result of timers or exceptions, previous code assumed syscalls. This was noticeable with X crashing where it uses SIGALRM. This patch restores all regs before returning to userspace via _resume_userspace instead of via syscall return path. The rt_sigreturn syscall is more like a context switch than a function call; it entails a return from one context (the signal handler) to another (the process in question). For a context switch like this there are effectively no call-saved regs that remain constant across the transition. Reported-by: Sebastian Macke Signed-off-by: Jonas Bonn Tested-by: Guenter Roeck [shorne@gmail.com: Updated comment better reflect change and issue] Signed-off-by: Stafford Horne --- arch/openrisc/kernel/entry.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/openrisc/kernel/entry.S b/arch/openrisc/kernel/entry.S index fec8bf97d806..572d223dbd26 100644 --- a/arch/openrisc/kernel/entry.S +++ b/arch/openrisc/kernel/entry.S @@ -1101,8 +1101,16 @@ ENTRY(__sys_fork) l.addi r3,r1,0 ENTRY(sys_rt_sigreturn) - l.j _sys_rt_sigreturn + l.jal _sys_rt_sigreturn l.addi r3,r1,0 + l.sfne r30,r0 + l.bnf _no_syscall_trace + l.nop + l.jal do_syscall_trace_leave + l.addi r3,r1,0 +_no_syscall_trace: + l.j _resume_userspace + l.nop /* This is a catch-all syscall for atomic instructions for the OpenRISC 1000. * The functions takes a variable number of parameters depending on which From e60aa2fba4678d4e7e2d28ef4f2110084d0b150a Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 25 Jan 2014 15:48:54 +0000 Subject: [PATCH 03/10] openrisc: Add thread-local storage (TLS) support Historically OpenRISC GCC has reserved r10 which we now use to hold the thread pointer for thread-local storage (TLS). Signed-off-by: Christian Svensson Signed-off-by: Stefan Kristiansson Tested-by: Guenter Roeck Signed-off-by: Stafford Horne --- arch/openrisc/kernel/process.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c index 7095dfe7666b..277123bb4bf8 100644 --- a/arch/openrisc/kernel/process.c +++ b/arch/openrisc/kernel/process.c @@ -173,6 +173,19 @@ copy_thread(unsigned long clone_flags, unsigned long usp, if (usp) userregs->sp = usp; + + /* + * For CLONE_SETTLS set "tp" (r10) to the TLS pointer passed to sys_clone. + * + * The kernel entry is: + * int clone (long flags, void *child_stack, int *parent_tid, + * int *child_tid, struct void *tls) + * + * This makes the source r7 in the kernel registers. + */ + if (clone_flags & CLONE_SETTLS) + userregs->gpr[10] = userregs->gpr[7]; + userregs->gpr[11] = 0; /* Result from fork() */ kregs->gpr[20] = 0; /* Userspace thread */ From 1f43e235dfc44be335e484dae88928e997036026 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 20 Jul 2014 00:39:08 +0300 Subject: [PATCH 04/10] openrisc: Support both old (or32) and new (or1k) toolchain The output file format for or1k has changed from "elf32-or32" to "elf32-or1k". Select the correct output format automatically to be able to compile the kernel with both toolchain variants. Signed-off-by: Guenter Roeck Tested-by: Guenter Roeck Signed-off-by: Stafford Horne --- arch/openrisc/kernel/vmlinux.lds.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S index d68b9ede8423..ef31fc24344e 100644 --- a/arch/openrisc/kernel/vmlinux.lds.S +++ b/arch/openrisc/kernel/vmlinux.lds.S @@ -30,7 +30,13 @@ #include #include -OUTPUT_FORMAT("elf32-or32", "elf32-or32", "elf32-or32") +#ifdef __OR1K__ +#define __OUTPUT_FORMAT "elf32-or1k" +#else +#define __OUTPUT_FORMAT "elf32-or32" +#endif + +OUTPUT_FORMAT(__OUTPUT_FORMAT, __OUTPUT_FORMAT, __OUTPUT_FORMAT) jiffies = jiffies_64 + 4; SECTIONS From 34bbdcdcda88a24ef4d0f58ea84a9fdf14aea7af Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sat, 24 Sep 2016 22:20:42 +0900 Subject: [PATCH 05/10] openrisc: add NR_CPUS Kconfig default value The build system now expects that NR_CPUS is defined. Follow 4cbbbb4 ("microblaze: Fix missing NR_CPUS in menuconfig") Signed-off-by: Stafford Horne --- arch/openrisc/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 489e7f909286..691e1af22b99 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -98,6 +98,9 @@ config OPENRISC_HAVE_INST_DIV Select this if your implementation has a hardware divide instruction endmenu +config NR_CPUS + int + default "1" source kernel/Kconfig.hz source kernel/Kconfig.preempt From 994894c3f710f5d8ca89d22988fe715db57bbc87 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 31 Aug 2016 00:10:59 +0900 Subject: [PATCH 06/10] openrisc: remove the redundant of_platform_populate The of_platform_populate call in the openrisc arch code is now redundant as the DT core provides a default call. Openrisc has a NULL match table which means only top level nodes with compatible strings will have devices creates. The default version will also descend nodes in the match table such as "simple-bus" which should be fine as openrisc doesn't have any of these (though it is preferred that memory-mapped peripherals be grouped under a bus node(s)). Signed-off-by: Rob Herring Cc: Jonas Bonn Tested-by: Guenter Roeck Signed-off-by: Stafford Horne --- arch/openrisc/kernel/setup.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index b4ed8b36e078..d2f78cf79b4b 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -219,15 +218,6 @@ void __init or32_early_setup(void *fdt) early_init_devtree(fdt); } -static int __init openrisc_device_probe(void) -{ - of_platform_populate(NULL, NULL, NULL, NULL); - - return 0; -} - -device_initcall(openrisc_device_probe); - static inline unsigned long extract_value_bits(unsigned long reg, short bit_nr, short width) { From 266c7fad157265bb54d17db1c9545f2aaa488643 Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Sun, 3 Apr 2016 19:14:49 +0900 Subject: [PATCH 07/10] openrisc: Consolidate setup to use memblock instead of bootmem Clearing out one todo item. Use the memblock boot time memory which is the current standard. Tested-by: Guenter Roeck Acked-by: Jonas Signed-off-by: Stafford Horne --- arch/openrisc/Kconfig | 1 + arch/openrisc/TODO.openrisc | 3 --- arch/openrisc/include/asm/pgalloc.h | 1 - arch/openrisc/kernel/setup.c | 34 ++++++++++------------------- arch/openrisc/mm/init.c | 2 +- arch/openrisc/mm/ioremap.c | 4 ---- 6 files changed, 13 insertions(+), 32 deletions(-) diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 691e1af22b99..8d22015fde3e 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -26,6 +26,7 @@ config OPENRISC select HAVE_DEBUG_STACKOVERFLOW select OR1K_PIC select CPU_NO_EFFICIENT_FFS if !OPENRISC_HAVE_INST_FF1 + select NO_BOOTMEM config MMU def_bool y diff --git a/arch/openrisc/TODO.openrisc b/arch/openrisc/TODO.openrisc index acfeef9c58e3..0eb04c8240f9 100644 --- a/arch/openrisc/TODO.openrisc +++ b/arch/openrisc/TODO.openrisc @@ -5,9 +5,6 @@ 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. - -- 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 diff --git a/arch/openrisc/include/asm/pgalloc.h b/arch/openrisc/include/asm/pgalloc.h index 87eebd185089..3e1a46615120 100644 --- a/arch/openrisc/include/asm/pgalloc.h +++ b/arch/openrisc/include/asm/pgalloc.h @@ -23,7 +23,6 @@ #include #include #include -#include extern int mem_init_done; diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index d2f78cf79b4b..6329d7a493ff 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -50,18 +50,16 @@ #include "vmlinux.h" -static unsigned long __init setup_memory(void) +static void __init setup_memory(void) { - unsigned long bootmap_size; unsigned long ram_start_pfn; - unsigned long free_ram_start_pfn; unsigned long ram_end_pfn; phys_addr_t memory_start, memory_end; struct memblock_region *region; memory_end = memory_start = 0; - /* Find main memory where is the kernel */ + /* Find main memory where is the kernel, we assume its the only one */ for_each_memblock(memory, region) { memory_start = region->base; memory_end = region->base + region->size; @@ -74,10 +72,11 @@ static unsigned long __init setup_memory(void) } ram_start_pfn = PFN_UP(memory_start); - /* free_ram_start_pfn is first page after kernel */ - free_ram_start_pfn = PFN_UP(__pa(_end)); ram_end_pfn = PFN_DOWN(memblock_end_of_DRAM()); + /* setup bootmem globals (we use no_bootmem, but mm still depends on this) */ + min_low_pfn = ram_start_pfn; + max_low_pfn = ram_end_pfn; max_pfn = ram_end_pfn; /* @@ -85,22 +84,13 @@ static unsigned long __init setup_memory(void) * * This makes the memory from the end of the kernel to the end of * RAM usable. - * init_bootmem sets the global values min_low_pfn, max_low_pfn. */ - bootmap_size = init_bootmem(free_ram_start_pfn, - ram_end_pfn - ram_start_pfn); - free_bootmem(PFN_PHYS(free_ram_start_pfn), - (ram_end_pfn - free_ram_start_pfn) << PAGE_SHIFT); - reserve_bootmem(PFN_PHYS(free_ram_start_pfn), bootmap_size, - BOOTMEM_DEFAULT); + memblock_reserve(__pa(_stext), _end - _stext); - for_each_memblock(reserved, region) { - printk(KERN_INFO "Reserved - 0x%08x-0x%08x\n", - (u32) region->base, (u32) region->size); - reserve_bootmem(region->base, region->size, BOOTMEM_DEFAULT); - } + early_init_fdt_reserve_self(); + early_init_fdt_scan_reserved_mem(); - return ram_end_pfn; + memblock_dump_all(); } struct cpuinfo cpuinfo; @@ -272,8 +262,6 @@ void calibrate_delay(void) void __init setup_arch(char **cmdline_p) { - unsigned long max_low_pfn; - unflatten_and_copy_device_tree(); setup_cpuinfo(); @@ -294,8 +282,8 @@ void __init setup_arch(char **cmdline_p) initrd_below_start_ok = 1; #endif - /* setup bootmem allocator */ - max_low_pfn = setup_memory(); + /* setup memblock allocator */ + setup_memory(); /* paging_init() sets up the MMU and marks all pages as reserved */ paging_init(); diff --git a/arch/openrisc/mm/init.c b/arch/openrisc/mm/init.c index b782ce9ccad9..f67d82b9d22f 100644 --- a/arch/openrisc/mm/init.c +++ b/arch/openrisc/mm/init.c @@ -106,7 +106,7 @@ static void __init map_ram(void) } /* Alloc one page for holding PTE's... */ - pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); + pte = (pte_t *) __va(memblock_alloc(PAGE_SIZE, PAGE_SIZE)); set_pmd(pme, __pmd(_KERNPG_TABLE + __pa(pte))); /* Fill the newly allocated page with PTE'S */ diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c index fa60b81aee3e..8705a46218f9 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -124,11 +124,7 @@ pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm, if (likely(mem_init_done)) { pte = (pte_t *) __get_free_page(GFP_KERNEL); } else { - pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); -#if 0 - /* FIXME: use memblock... */ pte = (pte_t *) __va(memblock_alloc(PAGE_SIZE, PAGE_SIZE)); -#endif } if (pte) From d01e1f35fee54fd7131e161956e609dfd47c1056 Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Mon, 21 Mar 2016 17:11:10 +0900 Subject: [PATCH 08/10] openrisc: Updates after openrisc.net has been lost The openrisc.net domain expired and was taken over by squatters. These updates point documentation to the new domain, mailing lists and git repos. Also, Jonas is not the main maintainer anylonger, he reviews changes but does not maintain a repo or sent pull requests. Updating this to add Stafford and Stefan who are the active maintainers. Acked-by: Olof Kindgren Signed-off-by: Stafford Horne --- MAINTAINERS | 6 ++++-- arch/openrisc/README.openrisc | 8 ++++---- arch/openrisc/kernel/setup.c | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 63cefa62324c..3b1b8e4fa7fe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8968,9 +8968,11 @@ F: drivers/of/resolver.c OPENRISC ARCHITECTURE M: Jonas Bonn -W: http://openrisc.net +M: Stefan Kristiansson +M: Stafford Horne +L: openrisc@lists.librecores.org +W: http://openrisc.io S: Maintained -T: git git://openrisc.net/~jonas/linux F: arch/openrisc/ OPENVSWITCH diff --git a/arch/openrisc/README.openrisc b/arch/openrisc/README.openrisc index c9f7edf2b9a2..072069ab5100 100644 --- a/arch/openrisc/README.openrisc +++ b/arch/openrisc/README.openrisc @@ -6,7 +6,7 @@ target architecture, specifically, is the 32-bit OpenRISC 1000 family (or1k). For information about OpenRISC processors and ongoing development: - website http://openrisc.net + website http://openrisc.io For more information about Linux on OpenRISC, please contact South Pole AB. @@ -24,17 +24,17 @@ 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 +1) The toolchain can be obtained from openrisc.io. Instructions for building a toolchain can be found at: -http://openrisc.net/toolchain-build.html +https://github.com/openrisc/tutorials 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 + git clone https://github.com/openrisc/or1ksim.git cd or1ksim ./configure --prefix=$OPENRISC_PREFIX diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index 6329d7a493ff..cb797a3beb47 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -295,7 +295,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line; - printk(KERN_INFO "OpenRISC Linux -- http://openrisc.net\n"); + printk(KERN_INFO "OpenRISC Linux -- http://openrisc.io\n"); } static int show_cpuinfo(struct seq_file *m, void *v) From cdb75442fedff8cc3ddedbe6e41d00b471634e17 Mon Sep 17 00:00:00 2001 From: Stefan Kristiansson Date: Thu, 3 Jul 2014 20:46:40 +0300 Subject: [PATCH 09/10] openrisc: include l.swa in check for write data pagefault During page fault handling we check the last instruction to understand if the fault was for a read or for a write. By default we fall back to read. New instructions were added to the openrisc 1.1 spec for an atomic load/store pair (l.lwa/l.swa). This patch adds the opcode for l.swa (0x33) allowing it to be treated as a write operation. Signed-off-by: Stefan Kristiansson [shorne@gmail.com: expanded a bit on the comment] Signed-off-by: Stafford Horne --- arch/openrisc/kernel/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/openrisc/kernel/entry.S b/arch/openrisc/kernel/entry.S index 572d223dbd26..aac0bde3330c 100644 --- a/arch/openrisc/kernel/entry.S +++ b/arch/openrisc/kernel/entry.S @@ -264,7 +264,7 @@ EXCEPTION_ENTRY(_data_page_fault_handler) l.srli r6,r6,26 // check opcode for write access #endif - l.sfgeui r6,0x34 // check opcode for write access + l.sfgeui r6,0x33 // check opcode for write access l.bnf 1f l.sfleui r6,0x37 l.bnf 1f From 7c7808ce107d63e158dbbc3af085980985a0c3c4 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Mon, 21 Nov 2016 08:40:32 +0900 Subject: [PATCH 10/10] openrisc: prevent VGA console, fix builds OpenRISC does not support VGA console, so prevent that kconfig symbol from being enabled for OpenRISC, thus fixing these build errors: drivers/built-in.o: In function `vgacon_save_screen': vgacon.c:(.text+0x20e0): undefined reference to `screen_info' vgacon.c:(.text+0x20e8): undefined reference to `screen_info' drivers/built-in.o: In function `vgacon_init': vgacon.c:(.text+0x284c): undefined reference to `screen_info' vgacon.c:(.text+0x2850): undefined reference to `screen_info' drivers/built-in.o: In function `vgacon_startup': vgacon.c:(.text+0x28d8): undefined reference to `screen_info' drivers/built-in.o:vgacon.c:(.text+0x28f0): more undefined references to `screen_info' follow Signed-off-by: Randy Dunlap Reported-by: kbuild test robot Cc: Chen Gang Cc: Jonas Bonn Signed-off-by: Stafford Horne --- drivers/video/console/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig index 38da6e299149..c3f1fb9ee820 100644 --- a/drivers/video/console/Kconfig +++ b/drivers/video/console/Kconfig @@ -9,7 +9,7 @@ config VGA_CONSOLE depends on !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && \ !SUPERH && !BLACKFIN && !AVR32 && !MN10300 && !CRIS && \ (!ARM || ARCH_FOOTBRIDGE || ARCH_INTEGRATOR || ARCH_NETWINDER) && \ - !ARM64 && !ARC && !MICROBLAZE + !ARM64 && !ARC && !MICROBLAZE && !OPENRISC default y help Saying Y here will allow you to use Linux in text mode through a