Updates to Freedom SoCs
This commit is contained in:
committed by
Yunsup Lee
parent
f4375c2266
commit
ec70d85cbc
36
bootrom/sdboot/include/bits.h
Normal file
36
bootrom/sdboot/include/bits.h
Normal file
@ -0,0 +1,36 @@
|
||||
// See LICENSE for license details.
|
||||
#ifndef _RISCV_BITS_H
|
||||
#define _RISCV_BITS_H
|
||||
|
||||
#define likely(x) __builtin_expect((x), 1)
|
||||
#define unlikely(x) __builtin_expect((x), 0)
|
||||
|
||||
#define ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b))
|
||||
#define ROUNDDOWN(a, b) ((a)/(b)*(b))
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
|
||||
|
||||
#define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
|
||||
#define INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
|
||||
|
||||
#define STR(x) XSTR(x)
|
||||
#define XSTR(x) #x
|
||||
|
||||
#if __riscv_xlen == 64
|
||||
# define SLL32 sllw
|
||||
# define STORE sd
|
||||
# define LOAD ld
|
||||
# define LWU lwu
|
||||
# define LOG_REGBYTES 3
|
||||
#else
|
||||
# define SLL32 sll
|
||||
# define STORE sw
|
||||
# define LOAD lw
|
||||
# define LWU lw
|
||||
# define LOG_REGBYTES 2
|
||||
#endif
|
||||
#define REGBYTES (1 << LOG_REGBYTES)
|
||||
|
||||
#endif
|
18
bootrom/sdboot/include/const.h
Normal file
18
bootrom/sdboot/include/const.h
Normal file
@ -0,0 +1,18 @@
|
||||
// See LICENSE for license details.
|
||||
/* Derived from <linux/const.h> */
|
||||
|
||||
#ifndef _SIFIVE_CONST_H
|
||||
#define _SIFIVE_CONST_H
|
||||
|
||||
#ifdef __ASSEMBLER__
|
||||
#define _AC(X,Y) X
|
||||
#define _AT(T,X) X
|
||||
#else
|
||||
#define _AC(X,Y) (X##Y)
|
||||
#define _AT(T,X) ((T)(X))
|
||||
#endif /* !__ASSEMBLER__*/
|
||||
|
||||
#define _BITUL(x) (_AC(1,UL) << (x))
|
||||
#define _BITULL(x) (_AC(1,ULL) << (x))
|
||||
|
||||
#endif /* _SIFIVE_CONST_H */
|
14
bootrom/sdboot/include/devices/clint.h
Normal file
14
bootrom/sdboot/include/devices/clint.h
Normal file
@ -0,0 +1,14 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef _SIFIVE_CLINT_H
|
||||
#define _SIFIVE_CLINT_H
|
||||
|
||||
|
||||
#define CLINT_MSIP 0x0000
|
||||
#define CLINT_MSIP_size 0x4
|
||||
#define CLINT_MTIMECMP 0x4000
|
||||
#define CLINT_MTIMECMP_size 0x8
|
||||
#define CLINT_MTIME 0xBFF8
|
||||
#define CLINT_MTIME_size 0x8
|
||||
|
||||
#endif /* _SIFIVE_CLINT_H */
|
24
bootrom/sdboot/include/devices/gpio.h
Normal file
24
bootrom/sdboot/include/devices/gpio.h
Normal file
@ -0,0 +1,24 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef _SIFIVE_GPIO_H
|
||||
#define _SIFIVE_GPIO_H
|
||||
|
||||
#define GPIO_INPUT_VAL (0x00)
|
||||
#define GPIO_INPUT_EN (0x04)
|
||||
#define GPIO_OUTPUT_EN (0x08)
|
||||
#define GPIO_OUTPUT_VAL (0x0C)
|
||||
#define GPIO_PULLUP_EN (0x10)
|
||||
#define GPIO_DRIVE (0x14)
|
||||
#define GPIO_RISE_IE (0x18)
|
||||
#define GPIO_RISE_IP (0x1C)
|
||||
#define GPIO_FALL_IE (0x20)
|
||||
#define GPIO_FALL_IP (0x24)
|
||||
#define GPIO_HIGH_IE (0x28)
|
||||
#define GPIO_HIGH_IP (0x2C)
|
||||
#define GPIO_LOW_IE (0x30)
|
||||
#define GPIO_LOW_IP (0x34)
|
||||
#define GPIO_IOF_EN (0x38)
|
||||
#define GPIO_IOF_SEL (0x3C)
|
||||
#define GPIO_OUTPUT_XOR (0x40)
|
||||
|
||||
#endif /* _SIFIVE_GPIO_H */
|
31
bootrom/sdboot/include/devices/plic.h
Normal file
31
bootrom/sdboot/include/devices/plic.h
Normal file
@ -0,0 +1,31 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef PLIC_H
|
||||
#define PLIC_H
|
||||
|
||||
#include <const.h>
|
||||
|
||||
// 32 bits per source
|
||||
#define PLIC_PRIORITY_OFFSET _AC(0x0000,UL)
|
||||
#define PLIC_PRIORITY_SHIFT_PER_SOURCE 2
|
||||
// 1 bit per source (1 address)
|
||||
#define PLIC_PENDING_OFFSET _AC(0x1000,UL)
|
||||
#define PLIC_PENDING_SHIFT_PER_SOURCE 0
|
||||
|
||||
//0x80 per target
|
||||
#define PLIC_ENABLE_OFFSET _AC(0x2000,UL)
|
||||
#define PLIC_ENABLE_SHIFT_PER_TARGET 7
|
||||
|
||||
|
||||
#define PLIC_THRESHOLD_OFFSET _AC(0x200000,UL)
|
||||
#define PLIC_CLAIM_OFFSET _AC(0x200004,UL)
|
||||
#define PLIC_THRESHOLD_SHIFT_PER_TARGET 12
|
||||
#define PLIC_CLAIM_SHIFT_PER_TARGET 12
|
||||
|
||||
#define PLIC_MAX_SOURCE 1023
|
||||
#define PLIC_SOURCE_MASK 0x3FF
|
||||
|
||||
#define PLIC_MAX_TARGET 15871
|
||||
#define PLIC_TARGET_MASK 0x3FFF
|
||||
|
||||
#endif /* PLIC_H */
|
79
bootrom/sdboot/include/devices/spi.h
Normal file
79
bootrom/sdboot/include/devices/spi.h
Normal file
@ -0,0 +1,79 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef _SIFIVE_SPI_H
|
||||
#define _SIFIVE_SPI_H
|
||||
|
||||
/* Register offsets */
|
||||
|
||||
#define SPI_REG_SCKDIV 0x00
|
||||
#define SPI_REG_SCKMODE 0x04
|
||||
#define SPI_REG_CSID 0x10
|
||||
#define SPI_REG_CSDEF 0x14
|
||||
#define SPI_REG_CSMODE 0x18
|
||||
|
||||
#define SPI_REG_DCSSCK 0x28
|
||||
#define SPI_REG_DSCKCS 0x2a
|
||||
#define SPI_REG_DINTERCS 0x2c
|
||||
#define SPI_REG_DINTERXFR 0x2e
|
||||
|
||||
#define SPI_REG_FMT 0x40
|
||||
#define SPI_REG_TXFIFO 0x48
|
||||
#define SPI_REG_RXFIFO 0x4c
|
||||
#define SPI_REG_TXCTRL 0x50
|
||||
#define SPI_REG_RXCTRL 0x54
|
||||
|
||||
#define SPI_REG_FCTRL 0x60
|
||||
#define SPI_REG_FFMT 0x64
|
||||
|
||||
#define SPI_REG_IE 0x70
|
||||
#define SPI_REG_IP 0x74
|
||||
|
||||
/* Fields */
|
||||
|
||||
#define SPI_SCK_POL 0x1
|
||||
#define SPI_SCK_PHA 0x2
|
||||
|
||||
#define SPI_FMT_PROTO(x) ((x) & 0x3)
|
||||
#define SPI_FMT_ENDIAN(x) (((x) & 0x1) << 2)
|
||||
#define SPI_FMT_DIR(x) (((x) & 0x1) << 3)
|
||||
#define SPI_FMT_LEN(x) (((x) & 0xf) << 16)
|
||||
|
||||
/* TXCTRL register */
|
||||
#define SPI_TXWM(x) ((x) & 0xffff)
|
||||
/* RXCTRL register */
|
||||
#define SPI_RXWM(x) ((x) & 0xffff)
|
||||
|
||||
#define SPI_IP_TXWM 0x1
|
||||
#define SPI_IP_RXWM 0x2
|
||||
|
||||
#define SPI_FCTRL_EN 0x1
|
||||
|
||||
#define SPI_INSN_CMD_EN 0x1
|
||||
#define SPI_INSN_ADDR_LEN(x) (((x) & 0x7) << 1)
|
||||
#define SPI_INSN_PAD_CNT(x) (((x) & 0xf) << 4)
|
||||
#define SPI_INSN_CMD_PROTO(x) (((x) & 0x3) << 8)
|
||||
#define SPI_INSN_ADDR_PROTO(x) (((x) & 0x3) << 10)
|
||||
#define SPI_INSN_DATA_PROTO(x) (((x) & 0x3) << 12)
|
||||
#define SPI_INSN_CMD_CODE(x) (((x) & 0xff) << 16)
|
||||
#define SPI_INSN_PAD_CODE(x) (((x) & 0xff) << 24)
|
||||
|
||||
#define SPI_TXFIFO_FULL (1 << 31)
|
||||
#define SPI_RXFIFO_EMPTY (1 << 31)
|
||||
|
||||
/* Values */
|
||||
|
||||
#define SPI_CSMODE_AUTO 0
|
||||
#define SPI_CSMODE_HOLD 2
|
||||
#define SPI_CSMODE_OFF 3
|
||||
|
||||
#define SPI_DIR_RX 0
|
||||
#define SPI_DIR_TX 1
|
||||
|
||||
#define SPI_PROTO_S 0
|
||||
#define SPI_PROTO_D 1
|
||||
#define SPI_PROTO_Q 2
|
||||
|
||||
#define SPI_ENDIAN_MSB 0
|
||||
#define SPI_ENDIAN_LSB 1
|
||||
|
||||
#endif /* _SIFIVE_SPI_H */
|
28
bootrom/sdboot/include/devices/uart.h
Normal file
28
bootrom/sdboot/include/devices/uart.h
Normal file
@ -0,0 +1,28 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef _SIFIVE_UART_H
|
||||
#define _SIFIVE_UART_H
|
||||
|
||||
/* Register offsets */
|
||||
#define UART_REG_TXFIFO 0x00
|
||||
#define UART_REG_RXFIFO 0x04
|
||||
#define UART_REG_TXCTRL 0x08
|
||||
#define UART_REG_RXCTRL 0x0c
|
||||
#define UART_REG_IE 0x10
|
||||
#define UART_REG_IP 0x14
|
||||
#define UART_REG_DIV 0x18
|
||||
|
||||
/* TXCTRL register */
|
||||
#define UART_TXEN 0x1
|
||||
#define UART_TXNSTOP 0x2
|
||||
#define UART_TXWM(x) (((x) & 0xffff) << 16)
|
||||
|
||||
/* RXCTRL register */
|
||||
#define UART_RXEN 0x1
|
||||
#define UART_RXWM(x) (((x) & 0xffff) << 16)
|
||||
|
||||
/* IP register */
|
||||
#define UART_IP_TXWM 0x1
|
||||
#define UART_IP_RXWM 0x2
|
||||
|
||||
#endif /* _SIFIVE_UART_H */
|
99
bootrom/sdboot/include/platform.h
Normal file
99
bootrom/sdboot/include/platform.h
Normal file
@ -0,0 +1,99 @@
|
||||
// See LICENSE for license details.
|
||||
|
||||
#ifndef _SIFIVE_PLATFORM_H
|
||||
#define _SIFIVE_PLATFORM_H
|
||||
|
||||
#include "const.h"
|
||||
#include "riscv_test_defaults.h"
|
||||
#include "devices/clint.h"
|
||||
#include "devices/gpio.h"
|
||||
#include "devices/plic.h"
|
||||
#include "devices/spi.h"
|
||||
#include "devices/uart.h"
|
||||
|
||||
// Some things missing from the official encoding.h
|
||||
#if __riscv_xlen == 32
|
||||
#define MCAUSE_INT 0x80000000UL
|
||||
#define MCAUSE_CAUSE 0x7FFFFFFFUL
|
||||
#else
|
||||
#define MCAUSE_INT 0x8000000000000000UL
|
||||
#define MCAUSE_CAUSE 0x7FFFFFFFFFFFFFFFUL
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Platform definitions
|
||||
*****************************************************************************/
|
||||
|
||||
// CPU info
|
||||
#define NUM_CORES 1
|
||||
#define GLOBAL_INT_SIZE 15
|
||||
#define GLOBAL_INT_MAX_PRIORITY 7
|
||||
|
||||
// Memory map
|
||||
#define AXI_PCIE_HOST_1_00_A_CTRL_ADDR _AC(0x50000000,UL)
|
||||
#define AXI_PCIE_HOST_1_00_A_CTRL_SIZE _AC(0x4000000,UL)
|
||||
#define CLINT_CTRL_ADDR _AC(0x2000000,UL)
|
||||
#define CLINT_CTRL_SIZE _AC(0x10000,UL)
|
||||
#define DEBUG_CTRL_ADDR _AC(0x0,UL)
|
||||
#define DEBUG_CTRL_SIZE _AC(0x1000,UL)
|
||||
#define ERROR_MEM_ADDR _AC(0x3000,UL)
|
||||
#define ERROR_MEM_SIZE _AC(0x1000,UL)
|
||||
#define GPIO_CTRL_ADDR _AC(0x54002000,UL)
|
||||
#define GPIO_CTRL_SIZE _AC(0x1000,UL)
|
||||
#define MASKROM_MEM_ADDR _AC(0x10000,UL)
|
||||
#define MASKROM_MEM_SIZE _AC(0x2000,UL)
|
||||
#define MEMORY_MEM_ADDR _AC(0x80000000,UL)
|
||||
#define MEMORY_MEM_SIZE _AC(0x40000000,UL)
|
||||
#define PLIC_CTRL_ADDR _AC(0xc000000,UL)
|
||||
#define PLIC_CTRL_SIZE _AC(0x4000000,UL)
|
||||
#define SPI_CTRL_ADDR _AC(0x54001000,UL)
|
||||
#define SPI_CTRL_SIZE _AC(0x1000,UL)
|
||||
#define TEST_CTRL_ADDR _AC(0x4000,UL)
|
||||
#define TEST_CTRL_SIZE _AC(0x1000,UL)
|
||||
#define UART_CTRL_ADDR _AC(0x54000000,UL)
|
||||
#define UART_CTRL_SIZE _AC(0x1000,UL)
|
||||
|
||||
// IOF masks
|
||||
|
||||
|
||||
// Interrupt numbers
|
||||
#define UART_INT_BASE 1
|
||||
#define SPI_INT_BASE 2
|
||||
#define GPIO_INT_BASE 3
|
||||
#define AXI_PCIE_HOST_1_00_A_INT_BASE 7
|
||||
|
||||
// Helper functions
|
||||
#define _REG64(p, i) (*(volatile uint64_t *)((p) + (i)))
|
||||
#define _REG32(p, i) (*(volatile uint32_t *)((p) + (i)))
|
||||
#define _REG16(p, i) (*(volatile uint16_t *)((p) + (i)))
|
||||
// Bulk set bits in `reg` to either 0 or 1.
|
||||
// E.g. SET_BITS(MY_REG, 0x00000007, 0) would generate MY_REG &= ~0x7
|
||||
// E.g. SET_BITS(MY_REG, 0x00000007, 1) would generate MY_REG |= 0x7
|
||||
#define SET_BITS(reg, mask, value) if ((value) == 0) { (reg) &= ~(mask); } else { (reg) |= (mask); }
|
||||
#define AXI_PCIE_HOST_1_00_A_REG(offset) _REG32(AXI_PCIE_HOST_1_00_A_CTRL_ADDR, offset)
|
||||
#define CLINT_REG(offset) _REG32(CLINT_CTRL_ADDR, offset)
|
||||
#define DEBUG_REG(offset) _REG32(DEBUG_CTRL_ADDR, offset)
|
||||
#define ERROR_REG(offset) _REG32(ERROR_CTRL_ADDR, offset)
|
||||
#define GPIO_REG(offset) _REG32(GPIO_CTRL_ADDR, offset)
|
||||
#define MASKROM_REG(offset) _REG32(MASKROM_CTRL_ADDR, offset)
|
||||
#define MEMORY_REG(offset) _REG32(MEMORY_CTRL_ADDR, offset)
|
||||
#define PLIC_REG(offset) _REG32(PLIC_CTRL_ADDR, offset)
|
||||
#define SPI_REG(offset) _REG32(SPI_CTRL_ADDR, offset)
|
||||
#define TEST_REG(offset) _REG32(TEST_CTRL_ADDR, offset)
|
||||
#define UART_REG(offset) _REG32(UART_CTRL_ADDR, offset)
|
||||
#define AXI_PCIE_HOST_1_00_A_REG64(offset) _REG64(AXI_PCIE_HOST_1_00_A_CTRL_ADDR, offset)
|
||||
#define CLINT_REG64(offset) _REG64(CLINT_CTRL_ADDR, offset)
|
||||
#define DEBUG_REG64(offset) _REG64(DEBUG_CTRL_ADDR, offset)
|
||||
#define ERROR_REG64(offset) _REG64(ERROR_CTRL_ADDR, offset)
|
||||
#define GPIO_REG64(offset) _REG64(GPIO_CTRL_ADDR, offset)
|
||||
#define MASKROM_REG64(offset) _REG64(MASKROM_CTRL_ADDR, offset)
|
||||
#define MEMORY_REG64(offset) _REG64(MEMORY_CTRL_ADDR, offset)
|
||||
#define PLIC_REG64(offset) _REG64(PLIC_CTRL_ADDR, offset)
|
||||
#define SPI_REG64(offset) _REG64(SPI_CTRL_ADDR, offset)
|
||||
#define TEST_REG64(offset) _REG64(TEST_CTRL_ADDR, offset)
|
||||
#define UART_REG64(offset) _REG64(UART_CTRL_ADDR, offset)
|
||||
|
||||
// Misc
|
||||
|
||||
|
||||
#endif /* _SIFIVE_PLATFORM_H */
|
81
bootrom/sdboot/include/riscv_test_defaults.h
Normal file
81
bootrom/sdboot/include/riscv_test_defaults.h
Normal file
@ -0,0 +1,81 @@
|
||||
// See LICENSE for license details.
|
||||
#ifndef _RISCV_TEST_DEFAULTS_H
|
||||
#define _RISCV_TEST_DEFAULTS_H
|
||||
|
||||
#define TESTNUM x28
|
||||
#define TESTBASE 0x4000
|
||||
|
||||
#define RVTEST_RV32U \
|
||||
.macro init; \
|
||||
.endm
|
||||
|
||||
#define RVTEST_RV64U \
|
||||
.macro init; \
|
||||
.endm
|
||||
|
||||
#define RVTEST_RV32UF \
|
||||
.macro init; \
|
||||
/* If FPU exists, initialize FCSR. */ \
|
||||
csrr t0, misa; \
|
||||
andi t0, t0, 1 << ('F' - 'A'); \
|
||||
beqz t0, 1f; \
|
||||
/* Enable FPU if it exists. */ \
|
||||
li t0, MSTATUS_FS; \
|
||||
csrs mstatus, t0; \
|
||||
fssr x0; \
|
||||
1: ; \
|
||||
.endm
|
||||
|
||||
#define RVTEST_RV64UF \
|
||||
.macro init; \
|
||||
/* If FPU exists, initialize FCSR. */ \
|
||||
csrr t0, misa; \
|
||||
andi t0, t0, 1 << ('F' - 'A'); \
|
||||
beqz t0, 1f; \
|
||||
/* Enable FPU if it exists. */ \
|
||||
li t0, MSTATUS_FS; \
|
||||
csrs mstatus, t0; \
|
||||
fssr x0; \
|
||||
1: ; \
|
||||
.endm
|
||||
|
||||
#define RVTEST_CODE_BEGIN \
|
||||
.section .text.init; \
|
||||
.globl _prog_start; \
|
||||
_prog_start: \
|
||||
init;
|
||||
|
||||
#define RVTEST_CODE_END \
|
||||
unimp
|
||||
|
||||
#define RVTEST_PASS \
|
||||
fence; \
|
||||
li t0, TESTBASE; \
|
||||
li t1, 0x5555; \
|
||||
sw t1, 0(t0); \
|
||||
1: \
|
||||
j 1b;
|
||||
|
||||
#define RVTEST_FAIL \
|
||||
li t0, TESTBASE; \
|
||||
li t1, 0x3333; \
|
||||
slli a0, a0, 16; \
|
||||
add a0, a0, t1; \
|
||||
sw a0, 0(t0); \
|
||||
1: \
|
||||
j 1b;
|
||||
|
||||
#define EXTRA_DATA
|
||||
|
||||
#define RVTEST_DATA_BEGIN \
|
||||
EXTRA_DATA \
|
||||
.align 4; .global begin_signature; begin_signature:
|
||||
|
||||
#define RVTEST_DATA_END \
|
||||
_msg_init: .asciz "RUN\r\n"; \
|
||||
_msg_pass: .asciz "PASS"; \
|
||||
_msg_fail: .asciz "FAIL "; \
|
||||
_msg_end: .asciz "\r\n"; \
|
||||
.align 4; .global end_signature; end_signature:
|
||||
|
||||
#endif /* _RISCV_TEST_DEFAULTS_H */
|
17
bootrom/sdboot/include/sections.h
Normal file
17
bootrom/sdboot/include/sections.h
Normal file
@ -0,0 +1,17 @@
|
||||
// See LICENSE for license details.
|
||||
#ifndef _SECTIONS_H
|
||||
#define _SECTIONS_H
|
||||
|
||||
extern unsigned char _rom[];
|
||||
extern unsigned char _rom_end[];
|
||||
|
||||
extern unsigned char _ram[];
|
||||
extern unsigned char _ram_end[];
|
||||
|
||||
extern unsigned char _ftext[];
|
||||
extern unsigned char _etext[];
|
||||
extern unsigned char _fbss[];
|
||||
extern unsigned char _ebss[];
|
||||
extern unsigned char _end[];
|
||||
|
||||
#endif /* _SECTIONS_H */
|
Reference in New Issue
Block a user