Commit 0ba1c195 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'nios2-v4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/lftan/nios2

Pull nios2 updates from Ley Foon Tan:
 "nios2 fixes/enhancements and adding nios2 R2 support"

* tag 'nios2-v4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/lftan/nios2:
  nios2: remove custom early console implementation
  nios2: use generic strncpy_from_user() and strnlen_user()
  nios2: Add CDX support
  nios2: Add BMX support
  nios2: Add NIOS2_ARCH_REVISION to select between R1 and R2
  nios2: implement flush_dcache_mmap_lock/unlock
  nios2: enable earlycon support
  nios2: constify irq_domain_ops
  nios2: remove wrapper header for cmpxchg.h
  nios2: add .gitignore entries for auto-generated files
parents 09d79d10 e118c3fe
......@@ -6,6 +6,8 @@ config NIOS2
select GENERIC_CPU_DEVICES
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_STRNCPY_FROM_USER
select GENERIC_STRNLEN_USER
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_KGDB
select IRQ_DOMAIN
......
......@@ -18,7 +18,6 @@ config EARLY_PRINTK
bool "Activate early kernel debugging"
default y
select SERIAL_CORE_CONSOLE
depends on SERIAL_ALTERA_JTAGUART_CONSOLE || SERIAL_ALTERA_UART_CONSOLE
help
Enable early printk on console
This is useful for kernel debugging when your machine crashes very
......
......@@ -22,10 +22,15 @@ export MMU
LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) $(KCFLAGS) -print-libgcc-file-name)
KBUILD_AFLAGS += -march=r$(CONFIG_NIOS2_ARCH_REVISION)
KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__
KBUILD_CFLAGS += -march=r$(CONFIG_NIOS2_ARCH_REVISION)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MULX_SUPPORT),-mhw-mulx,-mno-hw-mulx)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_DIV_SUPPORT),-mhw-div,-mno-hw-div)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_BMX_SUPPORT),-mbmx,-mno-bmx)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_CDX_SUPPORT),-mcdx,-mno-cdx)
KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_FPU_SUPPORT),-mcustom-fpu-cfg=60-1,)
KBUILD_CFLAGS += -fno-optimize-sibling-calls
......
......@@ -244,6 +244,7 @@ led_fpga3: fpga3 {
};
chosen {
bootargs = "debug console=ttyS0,115200";
bootargs = "debug earlycon console=ttyS0,115200";
stdout-path = &a_16550_uart_0;
};
};
......@@ -6,6 +6,7 @@ generic-y += bitsperlong.h
generic-y += bug.h
generic-y += bugs.h
generic-y += clkdev.h
generic-y += cmpxchg.h
generic-y += current.h
generic-y += device.h
generic-y += div64.h
......
......@@ -46,7 +46,9 @@ extern void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
extern void flush_dcache_range(unsigned long start, unsigned long end);
extern void invalidate_dcache_range(unsigned long start, unsigned long end);
#define flush_dcache_mmap_lock(mapping) do { } while (0)
#define flush_dcache_mmap_unlock(mapping) do { } while (0)
#define flush_dcache_mmap_lock(mapping) \
spin_lock_irq(&(mapping)->tree_lock)
#define flush_dcache_mmap_unlock(mapping) \
spin_unlock_irq(&(mapping)->tree_lock)
#endif /* _ASM_NIOS2_CACHEFLUSH_H */
/*
* Copyright (C) 2004 Microtronix Datacom Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#ifndef _ASM_NIOS2_CMPXCHG_H
#define _ASM_NIOS2_CMPXCHG_H
#include <asm-generic/cmpxchg.h>
#endif /* _ASM_NIOS2_CMPXCHG_H */
......@@ -29,6 +29,8 @@ struct cpuinfo {
bool has_div;
bool has_mul;
bool has_mulx;
bool has_bmx;
bool has_cdx;
/* CPU caches */
u32 icache_line_size;
......
/*
* Copyright Altera Corporation (C) <2015>. All rights reserved
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ASM_NIOS2_PROM_H__
#define __ASM_NIOS2_PROM_H__
extern unsigned long __init of_early_console(void);
#endif
......@@ -30,8 +30,6 @@ extern char fast_handler_end[];
extern void pagetable_init(void);
extern void setup_early_printk(void);
#endif/* __KERNEL__ */
#endif /* __ASSEMBLY__ */
......
......@@ -42,6 +42,8 @@
# define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n"
#define user_addr_max() (uaccess_kernel() ? ~0UL : TASK_SIZE)
/*
* Zero Userspace
*/
......@@ -81,8 +83,9 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n);
#define INLINE_COPY_TO_USER
extern long strncpy_from_user(char *__to, const char __user *__from,
long __len);
extern long strnlen_user(const char __user *s, long n);
long __len);
extern __must_check long strlen_user(const char __user *str);
extern __must_check long strnlen_user(const char __user *s, long n);
/* Optimized macros */
#define __get_user_asm(val, insn, addr, err) \
......
......@@ -20,7 +20,6 @@ obj-y += syscall_table.o
obj-y += time.o
obj-y += traps.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_KGDB) += kgdb.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_NIOS2_ALIGNMENT_TRAP) += misaligned.o
......@@ -67,6 +67,8 @@ void __init setup_cpuinfo(void)
cpuinfo.has_div = of_property_read_bool(cpu, "altr,has-div");
cpuinfo.has_mul = of_property_read_bool(cpu, "altr,has-mul");
cpuinfo.has_mulx = of_property_read_bool(cpu, "altr,has-mulx");
cpuinfo.has_bmx = of_property_read_bool(cpu, "altr,has-bmx");
cpuinfo.has_cdx = of_property_read_bool(cpu, "altr,has-cdx");
cpuinfo.mmu = of_property_read_bool(cpu, "altr,has-mmu");
if (IS_ENABLED(CONFIG_NIOS2_HW_DIV_SUPPORT) && !cpuinfo.has_div)
......@@ -78,6 +80,12 @@ void __init setup_cpuinfo(void)
if (IS_ENABLED(CONFIG_NIOS2_HW_MULX_SUPPORT) && !cpuinfo.has_mulx)
err_cpu("MULX");
if (IS_ENABLED(CONFIG_NIOS2_BMX_SUPPORT) && !cpuinfo.has_bmx)
err_cpu("BMX");
if (IS_ENABLED(CONFIG_NIOS2_CDX_SUPPORT) && !cpuinfo.has_cdx)
err_cpu("CDX");
cpuinfo.tlb_num_ways = fcpu(cpu, "altr,tlb-num-ways");
if (!cpuinfo.tlb_num_ways)
panic("altr,tlb-num-ways can't be 0. Please check your hardware "
......@@ -125,12 +133,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
seq_printf(m,
"CPU:\t\tNios II/%s\n"
"REV:\t\t%i\n"
"MMU:\t\t%s\n"
"FPU:\t\tnone\n"
"Clocking:\t%u.%02u MHz\n"
"BogoMips:\t%lu.%02lu\n"
"Calibration:\t%lu loops\n",
cpuinfo.cpu_impl,
CONFIG_NIOS2_ARCH_REVISION,
cpuinfo.mmu ? "present" : "none",
clockfreq / 1000000, (clockfreq / 100000) % 10,
(loops_per_jiffy * HZ) / 500000,
......@@ -141,10 +151,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
"HW:\n"
" MUL:\t\t%s\n"
" MULX:\t\t%s\n"
" DIV:\t\t%s\n",
" DIV:\t\t%s\n"
" BMX:\t\t%s\n"
" CDX:\t\t%s\n",
cpuinfo.has_mul ? "yes" : "no",
cpuinfo.has_mulx ? "yes" : "no",
cpuinfo.has_div ? "yes" : "no");
cpuinfo.has_div ? "yes" : "no",
cpuinfo.has_bmx ? "yes" : "no",
cpuinfo.has_cdx ? "yes" : "no");
seq_printf(m,
"Icache:\t\t%ukB, line length: %u\n",
......
/*
* Early printk for Nios2.
*
* Copyright (C) 2015, Altera Corporation
* Copyright (C) 2010, Tobias Klauser <tklauser@distanz.ch>
* Copyright (C) 2009, Wind River Systems Inc
* Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/console.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <asm/prom.h>
static unsigned long base_addr;
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE)
#define ALTERA_JTAGUART_DATA_REG 0
#define ALTERA_JTAGUART_CONTROL_REG 4
#define ALTERA_JTAGUART_CONTROL_WSPACE_MSK 0xFFFF0000
#define ALTERA_JTAGUART_CONTROL_AC_MSK 0x00000400
#define JUART_GET_CR() \
__builtin_ldwio((void *)(base_addr + ALTERA_JTAGUART_CONTROL_REG))
#define JUART_SET_CR(v) \
__builtin_stwio((void *)(base_addr + ALTERA_JTAGUART_CONTROL_REG), v)
#define JUART_SET_TX(v) \
__builtin_stwio((void *)(base_addr + ALTERA_JTAGUART_DATA_REG), v)
static void early_console_write(struct console *con, const char *s, unsigned n)
{
unsigned long status;
while (n-- && *s) {
while (((status = JUART_GET_CR())
& ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0) {
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) == 0)
return; /* no connection activity */
#endif
}
JUART_SET_TX(*s);
s++;
}
}
#elif defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
#define ALTERA_UART_TXDATA_REG 4
#define ALTERA_UART_STATUS_REG 8
#define ALTERA_UART_STATUS_TRDY 0x0040
#define UART_GET_SR() \
__builtin_ldwio((void *)(base_addr + ALTERA_UART_STATUS_REG))
#define UART_SET_TX(v) \
__builtin_stwio((void *)(base_addr + ALTERA_UART_TXDATA_REG), v)
static void early_console_putc(char c)
{
while (!(UART_GET_SR() & ALTERA_UART_STATUS_TRDY))
;
UART_SET_TX(c);
}
static void early_console_write(struct console *con, const char *s, unsigned n)
{
while (n-- && *s) {
early_console_putc(*s);
if (*s == '\n')
early_console_putc('\r');
s++;
}
}
#else
# error Neither SERIAL_ALTERA_JTAGUART_CONSOLE nor SERIAL_ALTERA_UART_CONSOLE \
selected
#endif
static struct console early_console_prom = {
.name = "early",
.write = early_console_write,
.flags = CON_PRINTBUFFER | CON_BOOT,
.index = -1
};
void __init setup_early_printk(void)
{
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE) || \
defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
base_addr = of_early_console();
#else
base_addr = 0;
#endif
if (!base_addr)
return;
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
/* Clear activity bit so BYPASS doesn't stall if we've used JTAG for
* downloading the kernel. This might cause early data to be lost even
* if the JTAG terminal is running.
*/
JUART_SET_CR(JUART_GET_CR() | ALTERA_JTAGUART_CONTROL_AC_MSK);
#endif
early_console = &early_console_prom;
register_console(early_console);
pr_info("early_console initialized at 0x%08lx\n", base_addr);
}
......@@ -67,7 +67,7 @@ static int irq_map(struct irq_domain *h, unsigned int virq,
return 0;
}
static struct irq_domain_ops irq_ops = {
static const struct irq_domain_ops irq_ops = {
.map = irq_map,
.xlate = irq_domain_xlate_onecell,
};
......
......@@ -30,7 +30,6 @@
#include <linux/of_fdt.h>
#include <linux/io.h>
#include <asm/prom.h>
#include <asm/sections.h>
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
......@@ -71,51 +70,3 @@ void __init early_init_devtree(void *params)
early_init_dt_scan(params);
}
#ifdef CONFIG_EARLY_PRINTK
static int __init early_init_dt_scan_serial(unsigned long node,
const char *uname, int depth, void *data)
{
u64 *addr64 = (u64 *) data;
const char *p;
/* only consider serial nodes */
if (strncmp(uname, "serial", 6) != 0)
return 0;
p = of_get_flat_dt_prop(node, "compatible", NULL);
if (!p)
return 0;
/*
* We found an altera_jtaguart but it wasn't configured for console, so
* skip it.
*/
#ifndef CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE
if (strncmp(p, "altr,juart", 10) == 0)
return 0;
#endif
/*
* Same for altera_uart.
*/
#ifndef CONFIG_SERIAL_ALTERA_UART_CONSOLE
if (strncmp(p, "altr,uart", 9) == 0)
return 0;
#endif
*addr64 = of_flat_dt_translate_address(node);
return *addr64 == OF_BAD_ADDR ? 0 : 1;
}
unsigned long __init of_early_console(void)
{
u64 base = 0;
if (of_scan_flat_dt(early_init_dt_scan_serial, &base))
return (u32)ioremap(base, 32);
else
return 0;
}
#endif /* CONFIG_EARLY_PRINTK */
......@@ -137,6 +137,8 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#endif
#endif
parse_early_param();
}
void __init setup_arch(char **cmdline_p)
......@@ -145,10 +147,6 @@ void __init setup_arch(char **cmdline_p)
console_verbose();
#ifdef CONFIG_EARLY_PRINTK
setup_early_printk();
#endif
memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
......
......@@ -128,36 +128,3 @@ asm(
".word 12b,13b\n"
".previous\n");
EXPORT_SYMBOL(raw_copy_to_user);
long strncpy_from_user(char *__to, const char __user *__from, long __len)
{
int l = strnlen_user(__from, __len);
int is_zt = 1;
if (l > __len) {
is_zt = 0;
l = __len;
}
if (l == 0 || copy_from_user(__to, __from, l))
return -EFAULT;
if (is_zt)
l--;
return l;
}
long strnlen_user(const char __user *s, long n)
{
long i;
for (i = 0; i < n; i++) {
char c;
if (get_user(c, s + i) == -EFAULT)
return 0;
if (c == 0)
return i + 1;
}
return n + 1;
}
......@@ -52,6 +52,14 @@ config NIOS2_DTB_SOURCE
comment "Nios II instructions"
config NIOS2_ARCH_REVISION
int "Select Nios II architecture revision"
range 1 2
default 1
help
Select between Nios II R1 and Nios II R2 . The architectures
are binary incompatible. Default is R1 .
config NIOS2_HW_MUL_SUPPORT
bool "Enable MUL instruction"
default n
......@@ -73,6 +81,24 @@ config NIOS2_HW_DIV_SUPPORT
Set to true if you configured the Nios II to include the DIV
instruction. Enables the -mhw-div compiler flag.
config NIOS2_BMX_SUPPORT
bool "Enable BMX instructions"
depends on NIOS2_ARCH_REVISION = 2
default n
help
Set to true if you configured the Nios II R2 to include
the BMX Bit Manipulation Extension instructions. Enables
the -mbmx compiler flag.
config NIOS2_CDX_SUPPORT
bool "Enable CDX instructions"
depends on NIOS2_ARCH_REVISION = 2
default n
help
Set to true if you configured the Nios II R2 to include
the CDX Bit Manipulation Extension instructions. Enables
the -mcdx compiler flag.
config NIOS2_FPU_SUPPORT
bool "Custom floating point instr support"
default n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment