[coreboot-gerrit] Patch set updated for coreboot: RISCV: add real hardware! This is the lowrisc bitstream on nexys4ddr.

Ronald G. Minnich (rminnich@gmail.com) gerrit at coreboot.org
Mon Oct 17 23:49:08 CEST 2016


Ronald G. Minnich (rminnich at gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16938

-gerrit

commit d82e26a7dfcc046d762ae9ee990605efae90b416
Author: Ronald G. Minnich <rminnich at gmail.com>
Date:   Sat Oct 8 07:46:00 2016 -0700

    RISCV: add real hardware! This is the lowrisc bitstream on nexys4ddr.
    
    It gets us into supervisor and includes the uart support, albeit
    not quite right. Linux dies trying to zero BSS but this is
    due to 1.7/1.9 bitstream and spike differences.
    
    Change-Id: Ib1a45c829c879bb20de0831d9eef019be7b98146
    Signed-off-by: Ronald G. Minnich <rminnich at gmail.com>
---
 src/arch/riscv/Makefile.inc                    |   1 +
 src/arch/riscv/boot.c                          |   4 +
 src/arch/riscv/include/vm.h                    |  10 ---
 src/arch/riscv/payload.S                       |  33 ++++++++
 src/arch/riscv/trap_handler.c                  |   1 +
 src/arch/riscv/virtual_memory.c                |  42 +++++++---
 src/mainboard/lowrisc/Kconfig                  |  16 ++++
 src/mainboard/lowrisc/Kconfig.name             |   2 +
 src/mainboard/lowrisc/nexys4ddr/Kconfig        |  38 +++++++++
 src/mainboard/lowrisc/nexys4ddr/Kconfig.name   |   2 +
 src/mainboard/lowrisc/nexys4ddr/Makefile.inc   |  29 +++++++
 src/mainboard/lowrisc/nexys4ddr/board_info.txt |   3 +
 src/mainboard/lowrisc/nexys4ddr/devicetree.cb  |  20 +++++
 src/mainboard/lowrisc/nexys4ddr/mainboard.c    |  37 +++++++++
 src/mainboard/lowrisc/nexys4ddr/memlayout.ld   |  30 +++++++
 src/mainboard/lowrisc/nexys4ddr/rom_media.c    |  29 +++++++
 src/mainboard/lowrisc/nexys4ddr/romstage.c     |  23 ++++++
 src/mainboard/lowrisc/nexys4ddr/uart.c         |  40 ++++++++++
 src/mainboard/lowrisc/nexys4ddr/util.c         | 103 +++++++++++++++++++++++++
 src/soc/lowrisc/lowrisc/Kconfig                |  14 ++++
 src/soc/lowrisc/lowrisc/Makefile.inc           |   6 ++
 src/soc/lowrisc/lowrisc/cbmem.c                |  22 ++++++
 22 files changed, 483 insertions(+), 22 deletions(-)

diff --git a/src/arch/riscv/Makefile.inc b/src/arch/riscv/Makefile.inc
index 4bab459..cf6ce99 100644
--- a/src/arch/riscv/Makefile.inc
+++ b/src/arch/riscv/Makefile.inc
@@ -96,6 +96,7 @@ ramstage-y += misc.c
 ramstage-y += boot.c
 ramstage-y += tables.c
 ramstage-y += sbi.S
+ramstage-y += payload.S
 ramstage-y += \
 	$(top)/src/lib/memchr.c \
 	$(top)/src/lib/memcmp.c \
diff --git a/src/arch/riscv/boot.c b/src/arch/riscv/boot.c
index 7435490..35a9123 100644
--- a/src/arch/riscv/boot.c
+++ b/src/arch/riscv/boot.c
@@ -13,6 +13,7 @@
  * GNU General Public License for more details.
  */
 
+#include <lib.h>
 #include <program_loading.h>
 #include <vm.h>
 #include <arch/encoding.h>
@@ -21,9 +22,12 @@
 void arch_prog_run(struct prog *prog)
 {
 	void (*doit)(void *) = prog_entry(prog);
+	void riscvpayload(void);
 
 	if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
+		hexdump((void *)0x81000000, 128);
 		initVirtualMemory();
+		riscvpayload();
 	}
 
 	doit(prog_entry_arg(prog));
diff --git a/src/arch/riscv/include/vm.h b/src/arch/riscv/include/vm.h
index bee2ed4..6472cad 100644
--- a/src/arch/riscv/include/vm.h
+++ b/src/arch/riscv/include/vm.h
@@ -37,16 +37,6 @@
 #define VA_BITS 39
 #define MEGAPAGE_SIZE (SUPERPAGE_SIZE << RISCV_PGLEVEL_BITS)
 
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-
-#define MAP_PRIVATE 0x2
-#define MAP_FIXED 0x10
-#define MAP_ANONYMOUS 0x20
-#define MAP_POPULATE 0x8000
-#define MREMAP_FIXED 0x2
-
 #define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
 #define INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
 
diff --git a/src/arch/riscv/payload.S b/src/arch/riscv/payload.S
new file mode 100644
index 0000000..e1a7c63
--- /dev/null
+++ b/src/arch/riscv/payload.S
@@ -0,0 +1,33 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+	.global riscvpayload
+riscvpayload:
+	/* Jump to 0xffffffff81000000 in S-mode */
+	li t0, 0xffffffff81000000
+	csrw mepc, t0
+	csrr t0, mstatus
+	li t1, ~(3<<11)
+	and t0, t0, t1
+	li t2,  (1<<11)
+	or t0, t0, t2
+	csrw mstatus, t0
+
+#if 0 // remove for testing.
+.L2:
+	li	a5,1107296256
+	li	a4,48
+	sw	a4,0(a5)
+	j	.L2
+#endif
+	mret
diff --git a/src/arch/riscv/trap_handler.c b/src/arch/riscv/trap_handler.c
index 59aa221..ba7c555 100644
--- a/src/arch/riscv/trap_handler.c
+++ b/src/arch/riscv/trap_handler.c
@@ -163,6 +163,7 @@ void trap_handler(trapframe *tf) {
 			break;
 	}
 
+	//print_page_table();
 	die("Can't recover from trap. Halting.\n");
 }
 
diff --git a/src/arch/riscv/virtual_memory.c b/src/arch/riscv/virtual_memory.c
index be8b488..6865e39 100644
--- a/src/arch/riscv/virtual_memory.c
+++ b/src/arch/riscv/virtual_memory.c
@@ -94,7 +94,7 @@ static void print_page_table_at(pte_t *pt, intptr_t virt_addr, int level)
 
 /* Print the page table structures to the console */
 void print_page_table(void) {
-	print_page_table_at(root_page_table, 0, 0);
+	print_page_table_at((void *)(read_csr(sptbr)<<12), 0, 0);
 }
 
 void flush_tlb(void)
@@ -115,13 +115,13 @@ pte_t ptd_create(uintptr_t ppn)
 pte_t pte_create(uintptr_t ppn, int prot, int user)
 {
 	pte_t pte = (ppn << PTE_PPN_SHIFT) | PTE_R | PTE_V;
-	if (prot & PROT_WRITE)
+	if (prot & PTE_W)
 		pte |= PTE_W;
-	if (prot & PROT_EXEC)
+	if (prot & PTE_X)
 		pte |= PTE_X;
 	if (user)
 		pte |= PTE_U;
-	return pte;
+	return pte | 0x1f;
 }
 
 void init_vm(uintptr_t virtMemStart, uintptr_t physMemStart, uintptr_t pageTableStart) {
@@ -147,21 +147,31 @@ void init_vm(uintptr_t virtMemStart, uintptr_t physMemStart, uintptr_t pageTable
 		int l2_shift = RISCV_PGLEVEL_BITS + RISCV_PGSHIFT;
 		size_t l2_idx = (virtMemStart >> l2_shift) & ((1 << RISCV_PGLEVEL_BITS)-1);
 		l2_idx += ((vaddr - virtMemStart) >> l2_shift);
-		middle_pt[l2_idx] = pte_create(paddr >> RISCV_PGSHIFT, PROT_READ|PROT_WRITE|PROT_EXEC, 0);
+		middle_pt[l2_idx] = pte_create(paddr >> RISCV_PGSHIFT,
+					       PTE_R|PTE_W|PTE_X, 0);
 	}
 
 	// map SBI at top of vaddr space
-	uintptr_t num_sbi_pages = 1; // only need to map a single page for sbi interface
+	// only need to map a single page for sbi interface
+	uintptr_t num_sbi_pages = 1;
 	uintptr_t sbiStartAddress = (uintptr_t) &sbi_page;
 	uintptr_t sbiAddr = sbiStartAddress;
 	for (uintptr_t i = 0; i < num_sbi_pages; i++) {
 		uintptr_t idx = (1 << RISCV_PGLEVEL_BITS) - num_sbi_pages + i;
-		sbi_pt[idx] = pte_create(sbiAddr >> RISCV_PGSHIFT, PROT_READ|PROT_EXEC, 0);
+		sbi_pt[idx] = pte_create(sbiAddr >> RISCV_PGSHIFT,
+					 PTE_W|PTE_R|PTE_X, 0);
 		sbiAddr += RISCV_PGSIZE;
 	}
 	pte_t* sbi_pte = middle_pt + ((num_middle_pts << RISCV_PGLEVEL_BITS)-1);
 	*sbi_pte = ptd_create((uintptr_t)sbi_pt >> RISCV_PGSHIFT);
 
+	// IO space.
+
+	root_pt[0] = pte_create(0, PTE_W|PTE_R|PTE_X, 0);
+	root_pt[1] = pte_create(0x40000000>>RISCV_PGSHIFT,
+				PTE_W|PTE_R|PTE_X, 0);
+	root_pt[2] = pte_create(0x80000000>>RISCV_PGSHIFT,
+				PTE_W|PTE_R|PTE_X, 0);
 	mb();
 	root_page_table = root_pt;
 	uintptr_t ptbr = ((uintptr_t) root_pt) >> RISCV_PGSHIFT;
@@ -185,12 +195,14 @@ void initVirtualMemory(void) {
 		printk(BIOS_DEBUG, "-----------------------------\n");
 	}
 
+	// TODO: Figure out how to grab this from cbfs
 	printk(BIOS_DEBUG, "Initializing virtual memory...\n");
-	uintptr_t physicalStart = 0x90000000; // TODO: Figure out how to grab this from cbfs
-	uintptr_t virtualStart = 0xffffffff80000000;
-	uintptr_t pageTableStart = 0x91400000;
+	uintptr_t physicalStart = 0x81000000;
+	uintptr_t virtualStart = 0xffffffff81000000;
+	uintptr_t pageTableStart = 0x80800000;
 	init_vm(virtualStart, physicalStart, pageTableStart);
 	mb();
+	flush_tlb();
 
 #if IS_ENABLED(CONFIG_DEBUG_PRINT_PAGE_TABLES)
 	printk(BIOS_DEBUG, "Finished initializing virtual memory, starting walk...\n");
@@ -211,6 +223,7 @@ void mstatus_init(void)
 	set_csr(mie, MIP_MSIP);
 
 	/* Configure which exception causes are delegated to supervisor mode */
+/*
 	set_csr(medeleg,  (1 << CAUSE_MISALIGNED_FETCH)
 			| (1 << CAUSE_FAULT_FETCH)
 			| (1 << CAUSE_ILLEGAL_INSTRUCTION)
@@ -220,7 +233,12 @@ void mstatus_init(void)
 			| (1 << CAUSE_USER_ECALL)
 	);
 
+*/
 	/* Enable all user/supervisor-mode counters */
-	write_csr(mscounteren, 0b111);
-	write_csr(mucounteren, 0b111);
+	/* We'll turn these on once lowrisc gets their bitstream up to
+	 * 1.9. Right now there's no agreement on the values for these
+	 * architectural registers.
+	 */
+	//write_csr(mscounteren, 0b111);
+	//write_csr(mucounteren, 0b111);
 }
diff --git a/src/mainboard/lowrisc/Kconfig b/src/mainboard/lowrisc/Kconfig
new file mode 100644
index 0000000..ba0fbe7
--- /dev/null
+++ b/src/mainboard/lowrisc/Kconfig
@@ -0,0 +1,16 @@
+if VENDOR_LOWRISC
+
+choice
+	prompt "Mainboard model"
+
+source "src/mainboard/lowrisc/*/Kconfig.name"
+
+endchoice
+
+source "src/mainboard/lowrisc/*/Kconfig"
+
+config MAINBOARD_VENDOR
+	string
+	default "lowrisc"
+
+endif # VENDOR_LOWRISC
diff --git a/src/mainboard/lowrisc/Kconfig.name b/src/mainboard/lowrisc/Kconfig.name
new file mode 100644
index 0000000..4c992fc
--- /dev/null
+++ b/src/mainboard/lowrisc/Kconfig.name
@@ -0,0 +1,2 @@
+config VENDOR_LOWRISC
+	bool "lowrisc"
diff --git a/src/mainboard/lowrisc/nexys4ddr/Kconfig b/src/mainboard/lowrisc/nexys4ddr/Kconfig
new file mode 100644
index 0000000..f0a3637
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/Kconfig
@@ -0,0 +1,38 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2016 Google Inc.
+##
+## This software is licensed under the terms of the GNU General Public
+## License version 2, as published by the Free Software Foundation, and
+## may be copied, distributed, and modified under those terms.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+
+if BOARD_LOWRISC_NEXYS4DDR
+
+config BOARD_SPECIFIC_OPTIONS # dummy
+	def_bool y
+	select SOC_LOWRISC_LOWRISC
+	select BOARD_ROMSIZE_KB_4096
+	select DRIVERS_UART_8250MEM
+	select BOOT_DEVICE_NOT_SPI_FLASH
+	select UART_OVERRIDE_REFCLK
+	select UART_OVERRIDE_INPUT_CLOCK_DIVIDER
+
+config MAINBOARD_DIR
+	string
+	default lowrisc/nexys4ddr
+
+config MAINBOARD_PART_NUMBER
+	string
+	default "LOWRISC NEXYS4DDR"
+
+config MAX_CPUS
+	int
+	default 1
+
+endif #  BOARD_LOWRISC_NEXYS4DDR
diff --git a/src/mainboard/lowrisc/nexys4ddr/Kconfig.name b/src/mainboard/lowrisc/nexys4ddr/Kconfig.name
new file mode 100644
index 0000000..f99b3cc
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/Kconfig.name
@@ -0,0 +1,2 @@
+config BOARD_LOWRISC_NEXYS4DDR
+	bool "nexys4ddr"
diff --git a/src/mainboard/lowrisc/nexys4ddr/Makefile.inc b/src/mainboard/lowrisc/nexys4ddr/Makefile.inc
new file mode 100644
index 0000000..de78786
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/Makefile.inc
@@ -0,0 +1,29 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2013 Google Inc.
+##
+## This software is licensed under the terms of the GNU General Public
+## License version 2, as published by the Free Software Foundation, and
+## may be copied, distributed, and modified under those terms.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+
+bootblock-y += bootblock.c
+bootblock-y += uart.c
+bootblock-y += util.c
+bootblock-y += rom_media.c
+romstage-y += romstage.c
+romstage-y += uart.c
+romstage-y += util.c
+romstage-y += rom_media.c
+ramstage-y += uart.c
+ramstage-y += util.c
+ramstage-y += rom_media.c
+
+bootblock-y += memlayout.ld
+romstage-y += memlayout.ld
+ramstage-y += memlayout.ld
diff --git a/src/mainboard/lowrisc/nexys4ddr/board_info.txt b/src/mainboard/lowrisc/nexys4ddr/board_info.txt
new file mode 100644
index 0000000..391509e
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/board_info.txt
@@ -0,0 +1,3 @@
+Board name: lowrisc nexys4ddr
+Category: eval
+Board URL: http://lowrisc.org/docs/debug-v0.3/
diff --git a/src/mainboard/lowrisc/nexys4ddr/devicetree.cb b/src/mainboard/lowrisc/nexys4ddr/devicetree.cb
new file mode 100644
index 0000000..e3ce088
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/devicetree.cb
@@ -0,0 +1,20 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2014 Google, Inc.
+##
+## This software is licensed under the terms of the GNU General Public
+## License version 2, as published by the Free Software Foundation, and
+## may be copied, distributed, and modified under those terms.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+
+chip soc/ucb/riscv
+	device cpu_cluster 0 on end
+	chip drivers/generic/generic # I2C0 controller
+		device i2c 6 on end # Fake component for testing
+	end
+end
diff --git a/src/mainboard/lowrisc/nexys4ddr/mainboard.c b/src/mainboard/lowrisc/nexys4ddr/mainboard.c
new file mode 100644
index 0000000..3b883ce
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/mainboard.c
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2014 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <console/console.h>
+#include <device/device.h>
+#include <cbmem.h>
+
+static void mainboard_enable(device_t dev)
+{
+	/*
+	 * TODO: Get this size from the hardware-supplied configuration string.
+	 */
+	const size_t ram_size = 1*GiB;
+
+	if (!dev)
+		die("No dev0; die\n");
+
+	ram_resource(dev, 0, 0x80000000/KiB, ram_size/KiB);
+
+	cbmem_recovery(0);
+}
+
+struct chip_operations mainboard_ops = {
+	.enable_dev = mainboard_enable,
+};
diff --git a/src/mainboard/lowrisc/nexys4ddr/memlayout.ld b/src/mainboard/lowrisc/nexys4ddr/memlayout.ld
new file mode 100644
index 0000000..8d35a64
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/memlayout.ld
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2014 Google Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <memlayout.h>
+
+#include <arch/header.ld>
+
+#define START 0x80000000
+
+SECTIONS
+{
+	DRAM_START(START)
+	BOOTBLOCK(START, 64K)
+	STACK(START + 8M, 64K)
+	ROMSTAGE(START + 8M + 64K, 128K)
+	PRERAM_CBMEM_CONSOLE(START + 8M + 192k, 8K)
+	RAMSTAGE(START + 8M + 200K, 256K)
+}
diff --git a/src/mainboard/lowrisc/nexys4ddr/rom_media.c b/src/mainboard/lowrisc/nexys4ddr/rom_media.c
new file mode 100644
index 0000000..26a3b02
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/rom_media.c
@@ -0,0 +1,29 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google Inc.
+ * Copyright 2016 Jonathan Neuschäfer <j.neuschaefer at gmx.net>
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <boot_device.h>
+
+/*
+ * 0x80000000 is this start of RAM. We currently need to load coreboot.rom into
+ * RAM. The actual "rom" code on the FPGAs is in a block ram.
+ */
+static const struct mem_region_device boot_dev =
+	MEM_REGION_DEV_RO_INIT(0x80000000, CONFIG_ROM_SIZE);
+
+const struct region_device *boot_device_ro(void)
+{
+	return &boot_dev.rdev;
+}
diff --git a/src/mainboard/lowrisc/nexys4ddr/romstage.c b/src/mainboard/lowrisc/nexys4ddr/romstage.c
new file mode 100644
index 0000000..b6314ccd
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/romstage.c
@@ -0,0 +1,23 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2013 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <console/console.h>
+#include <program_loading.h>
+
+void main(void)
+{
+	console_init();
+	run_ramstage();
+}
diff --git a/src/mainboard/lowrisc/nexys4ddr/uart.c b/src/mainboard/lowrisc/nexys4ddr/uart.c
new file mode 100644
index 0000000..128c736
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/uart.c
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <types.h>
+#include <console/uart.h>
+#include <arch/io.h>
+#include <boot/coreboot_tables.h>
+#include <spike_util.h>
+
+uintptr_t uart_platform_base(int idx)
+{
+	return (uintptr_t) 0x42000000;
+}
+
+/* these are currently not quite right but they are here for reference
+ * and will be fixed soon. */
+// divisor = clk_freq / (16 * Baud)
+unsigned int uart_input_clock_divider(void)
+{
+	return (25*1000*1000u / (16u * 115200u)) % 0x100;
+}
+
+// System clock 25 MHz, 115200 baud rate
+unsigned int uart_platform_refclk(void)
+{
+	return (25*1000*1000u / (16u * 115200u)) >> 8;
+}
+
diff --git a/src/mainboard/lowrisc/nexys4ddr/util.c b/src/mainboard/lowrisc/nexys4ddr/util.c
new file mode 100644
index 0000000..32cdb6d
--- /dev/null
+++ b/src/mainboard/lowrisc/nexys4ddr/util.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2013, The Regents of the University of California (Regents).
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Regents nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
+ * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
+ * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
+ * DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
+ * DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
+ * IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
+ * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ */
+
+#include <arch/barrier.h>
+#include <arch/errno.h>
+#include <atomic.h>
+#include <console/console.h>
+#include <spike_util.h>
+#include <string.h>
+#include <vm.h>
+
+uintptr_t mcall_query_memory(uintptr_t id, memory_block_info *info)
+{
+	if (id == 0) {
+		mprv_write_ulong(&info->base, 2U*GiB);
+
+		/* TODO: Return the correct value */
+		mprv_write_ulong(&info->size, 1*GiB);
+		return 0;
+	}
+
+	return -1;
+}
+
+uintptr_t mcall_send_ipi(uintptr_t recipient)
+{
+	die("mcall_send_ipi is currently not implemented");
+	return 0;
+}
+
+uintptr_t mcall_clear_ipi(void)
+{
+	// only clear SSIP if no other events are pending
+	if (HLS()->device_response_queue_head == NULL) {
+		clear_csr(mip, MIP_SSIP);
+		/* Ensure the other hart sees it. */
+		mb();
+	}
+
+	return atomic_swap(&HLS()->ipi_pending, 0);
+}
+
+uintptr_t mcall_shutdown(void)
+{
+	die("mcall_shutdown is currently not implemented");
+	return 0;
+}
+
+uintptr_t mcall_set_timer(unsigned long long when)
+{
+	printk(BIOS_DEBUG, "mcall_set_timer is currently not implemented, ignoring\n");
+	return 0;
+}
+
+uintptr_t mcall_dev_req(sbi_device_message *m)
+{
+	die("mcall_dev_req is currently not implemented");
+	return 0;
+}
+
+uintptr_t mcall_dev_resp(void)
+{
+	die("mcall_dev_resp is currently not implemented");
+	return 0;
+}
+
+void hls_init(uint32_t hart_id)
+{
+	memset(HLS(), 0, sizeof(*HLS()));
+	HLS()->hart_id = hart_id;
+}
+
+uintptr_t mcall_console_putchar(uint8_t ch)
+{
+	do_putchar(ch);
+	return 0;
+}
diff --git a/src/soc/lowrisc/lowrisc/Kconfig b/src/soc/lowrisc/lowrisc/Kconfig
new file mode 100644
index 0000000..528e744
--- /dev/null
+++ b/src/soc/lowrisc/lowrisc/Kconfig
@@ -0,0 +1,14 @@
+config SOC_LOWRISC_LOWRISC
+	select ARCH_RISCV
+	select ARCH_BOOTBLOCK_RISCV
+	select ARCH_VERSTAGE_RISCV
+	select ARCH_ROMSTAGE_RISCV
+	select ARCH_RAMSTAGE_RISCV
+	select BOOTBLOCK_CONSOLE
+	select DRIVERS_UART_8250MEM_32
+	bool
+	default n
+
+if SOC_LOWRISC_LOWRISC
+
+endif
diff --git a/src/soc/lowrisc/lowrisc/Makefile.inc b/src/soc/lowrisc/lowrisc/Makefile.inc
new file mode 100644
index 0000000..343c909
--- /dev/null
+++ b/src/soc/lowrisc/lowrisc/Makefile.inc
@@ -0,0 +1,6 @@
+ifeq ($(CONFIG_SOC_LOWRISC_LOWRISC),y)
+
+romstage-y += cbmem.c
+ramstage-y += cbmem.c
+
+endif
diff --git a/src/soc/lowrisc/lowrisc/cbmem.c b/src/soc/lowrisc/lowrisc/cbmem.c
new file mode 100644
index 0000000..7beab9f
--- /dev/null
+++ b/src/soc/lowrisc/lowrisc/cbmem.c
@@ -0,0 +1,22 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <console/console.h>
+#include <cbmem.h>
+
+void *cbmem_top(void)
+{
+	// TODO: find out how RISCV stores this.
+	printk(BIOS_SPEW, "Returning hard-coded 128M; fix me\n");
+	return (void *)((uintptr_t)(2ULL*GiB+128*MiB));
+}



More information about the coreboot-gerrit mailing list