diff options
Diffstat (limited to 'roms/opensbi/include/sbi_utils')
-rw-r--r-- | roms/opensbi/include/sbi_utils/fdt/fdt_domain.h | 73 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/fdt/fdt_fixup.h | 78 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/fdt/fdt_helper.h | 68 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/ipi/fdt_ipi.h | 32 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/irqchip/fdt_irqchip.h | 26 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/irqchip/plic.h | 29 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/reset/fdt_reset.h | 28 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/serial/fdt_serial.h | 28 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/serial/shakti-uart.h | 18 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/serial/sifive-uart.h | 21 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/serial/uart8250.h | 22 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/sys/clint.h | 51 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/sys/htif.h | 21 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/sys/sifive_test.h | 21 | ||||
-rw-r--r-- | roms/opensbi/include/sbi_utils/timer/fdt_timer.h | 35 |
15 files changed, 551 insertions, 0 deletions
diff --git a/roms/opensbi/include/sbi_utils/fdt/fdt_domain.h b/roms/opensbi/include/sbi_utils/fdt/fdt_domain.h new file mode 100644 index 000000000..5448eb4d9 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/fdt/fdt_domain.h @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_domain.c - Flat Device Tree Domain helper routines + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_DOMAIN_H__ +#define __FDT_DOMAIN_H__ + +#include <sbi/sbi_types.h> + +struct sbi_domain; + +/** + * Iterate over each domains in device tree + * + * @param fdt device tree blob + * @param opaque private pointer for each iteration + * @param fn callback function for each iteration + * + * @return 0 on success and negative error code on failure + */ +int fdt_iterate_each_domain(void *fdt, void *opaque, + int (*fn)(void *fdt, int domain_offset, + void *opaque)); + +/** + * Iterate over each memregion of a domain in device tree + * + * @param fdt device tree blob + * @param domain_offset domain DT node offset + * @param opaque private pointer for each iteration + * @param fn callback function for each iteration + * + * @return 0 on success and negative error code on failure + */ +int fdt_iterate_each_memregion(void *fdt, int domain_offset, void *opaque, + int (*fn)(void *fdt, int domain_offset, + int region_offset, u32 region_access, + void *opaque)); + +/** + * Fix up the domain configuration in the device tree + * + * This routine: + * 1. Disables MMIO devices not accessible to the coldboot HART domain + * 2. Removes "opensbi-domain" DT property from CPU DT nodes + * 3. Removes domain configuration DT node under /chosen DT node + * + * It is recommended that platform support call this function in + * their final_init() platform operation. + * + * @param fdt device tree blob + */ +void fdt_domain_fixup(void *fdt); + +/** + * Populate domains from device tree + * + * It is recommended that platform support call this function in + * their domains_init() platform operation. + * + * @param fdt device tree blob + * + * @return 0 on success and negative error code on failure + */ +int fdt_domains_populate(void *fdt); + +#endif /* __FDT_DOMAIN_H__ */ diff --git a/roms/opensbi/include/sbi_utils/fdt/fdt_fixup.h b/roms/opensbi/include/sbi_utils/fdt/fdt_fixup.h new file mode 100644 index 000000000..0697a18ee --- /dev/null +++ b/roms/opensbi/include/sbi_utils/fdt/fdt_fixup.h @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_fixup.h - Flat Device Tree manipulation helper routines + * Implement platform specific DT fixups on top of libfdt. + * + * Copyright (C) 2020 Bin Meng <bmeng.cn@gmail.com> + */ + +#ifndef __FDT_FIXUP_H__ +#define __FDT_FIXUP_H__ + +/** + * Fix up the CPU node in the device tree + * + * This routine updates the "status" property of a CPU node in the device tree + * to "disabled" if that hart is in disabled state in OpenSBI. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + */ +void fdt_cpu_fixup(void *fdt); + +/** + * Fix up the PLIC node in the device tree + * + * This routine updates the "interrupt-extended" property of the PLIC node in + * the device tree to hide the M-mode external interrupt from CPUs. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + * @param compat: PLIC node compatible string + */ +void fdt_plic_fixup(void *fdt, const char *compat); + +/** + * Fix up the reserved memory node in the device tree + * + * This routine inserts a child node of the reserved memory node in the device + * tree that describes the protected memory region done by OpenSBI via PMP. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + * @return zero on success and -ve on failure + */ +int fdt_reserved_memory_fixup(void *fdt); + +/** + * Fix up the reserved memory subnodes in the device tree + * + * This routine adds the no-map property to the reserved memory subnodes so + * that the OS does not map those PMP protected memory regions. + * + * Platform codes must call this helper in their final_init() after fdt_fixups() + * if the OS should not map the PMP protected reserved regions. + * + * @param fdt: device tree blob + * @return zero on success and -ve on failure + */ +int fdt_reserved_memory_nomap_fixup(void *fdt); + +/** + * General device tree fix-up + * + * This routine do all required device tree fix-ups for a typical platform. + * It fixes up the PLIC node and the reserved memory node in the device tree + * by calling the corresponding helper routines to accomplish the task. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + */ +void fdt_fixups(void *fdt); + +#endif /* __FDT_FIXUP_H__ */ + diff --git a/roms/opensbi/include/sbi_utils/fdt/fdt_helper.h b/roms/opensbi/include/sbi_utils/fdt/fdt_helper.h new file mode 100644 index 000000000..f5222deb4 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/fdt/fdt_helper.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_helper.h - Flat Device Tree parsing helper routines + * Implement helper routines to parse FDT nodes on top of + * libfdt for OpenSBI usage + * + * Copyright (C) 2020 Bin Meng <bmeng.cn@gmail.com> + */ + +#ifndef __FDT_HELPER_H__ +#define __FDT_HELPER_H__ + +#include <sbi/sbi_types.h> + +struct fdt_match { + const char *compatible; + void *data; +}; + +struct platform_uart_data { + unsigned long addr; + unsigned long freq; + unsigned long baud; + unsigned long reg_shift; + unsigned long reg_io_width; +}; + +const struct fdt_match *fdt_match_node(void *fdt, int nodeoff, + const struct fdt_match *match_table); + +int fdt_find_match(void *fdt, int startoff, + const struct fdt_match *match_table, + const struct fdt_match **out_match); + +int fdt_get_node_addr_size(void *fdt, int node, unsigned long *addr, + unsigned long *size); + +int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid); + +int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid); + +int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset, + struct platform_uart_data *uart); + +int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset, + struct platform_uart_data *uart); + +int fdt_parse_uart8250_node(void *fdt, int nodeoffset, + struct platform_uart_data *uart); + +int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, + const char *compatible); + +struct plic_data; + +int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic); + +int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat); + +struct clint_data; + +int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, + struct clint_data *clint); + +int fdt_parse_compat_addr(void *fdt, unsigned long *addr, + const char *compatible); + +#endif /* __FDT_HELPER_H__ */ diff --git a/roms/opensbi/include/sbi_utils/ipi/fdt_ipi.h b/roms/opensbi/include/sbi_utils/ipi/fdt_ipi.h new file mode 100644 index 000000000..e817141ac --- /dev/null +++ b/roms/opensbi/include/sbi_utils/ipi/fdt_ipi.h @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_IPI_H__ +#define __FDT_IPI_H__ + +#include <sbi/sbi_types.h> + +struct fdt_ipi { + const struct fdt_match *match_table; + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); + void (*send)(u32 target_hart); + void (*clear)(u32 target_hart); +}; + +void fdt_ipi_send(u32 target_hart); + +void fdt_ipi_clear(u32 target_hart); + +void fdt_ipi_exit(void); + +int fdt_ipi_init(bool cold_boot); + +#endif diff --git a/roms/opensbi/include/sbi_utils/irqchip/fdt_irqchip.h b/roms/opensbi/include/sbi_utils/irqchip/fdt_irqchip.h new file mode 100644 index 000000000..13ef6f711 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/irqchip/fdt_irqchip.h @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_IRQCHIP_H__ +#define __FDT_IRQCHIP_H__ + +#include <sbi/sbi_types.h> + +struct fdt_irqchip { + const struct fdt_match *match_table; + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); +}; + +void fdt_irqchip_exit(void); + +int fdt_irqchip_init(bool cold_boot); + +#endif diff --git a/roms/opensbi/include/sbi_utils/irqchip/plic.h b/roms/opensbi/include/sbi_utils/irqchip/plic.h new file mode 100644 index 000000000..0e56d801e --- /dev/null +++ b/roms/opensbi/include/sbi_utils/irqchip/plic.h @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __IRQCHIP_PLIC_H__ +#define __IRQCHIP_PLIC_H__ + +#include <sbi/sbi_types.h> + +struct plic_data { + unsigned long addr; + unsigned long num_src; +}; + +int plic_warm_irqchip_init(struct plic_data *plic, + int m_cntx_id, int s_cntx_id); + +int plic_cold_irqchip_init(struct plic_data *plic); + +void plic_set_thresh(struct plic_data *plic, u32 cntxid, u32 val); + +void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val); + +#endif diff --git a/roms/opensbi/include/sbi_utils/reset/fdt_reset.h b/roms/opensbi/include/sbi_utils/reset/fdt_reset.h new file mode 100644 index 000000000..cce441a84 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/reset/fdt_reset.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_RESET_H__ +#define __FDT_RESET_H__ + +#include <sbi/sbi_types.h> + +struct fdt_reset { + const struct fdt_match *match_table; + int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*system_reset_check)(u32 reset_type, u32 reset_reason); + void (*system_reset)(u32 reset_type, u32 reset_reason); +}; + +int fdt_system_reset_check(u32 reset_type, u32 reset_reason); + +void fdt_system_reset(u32 reset_type, u32 reset_reason); + +int fdt_reset_init(void); + +#endif diff --git a/roms/opensbi/include/sbi_utils/serial/fdt_serial.h b/roms/opensbi/include/sbi_utils/serial/fdt_serial.h new file mode 100644 index 000000000..08f97996f --- /dev/null +++ b/roms/opensbi/include/sbi_utils/serial/fdt_serial.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_SERIAL_H__ +#define __FDT_SERIAL_H__ + +#include <sbi/sbi_types.h> + +struct fdt_serial { + const struct fdt_match *match_table; + int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); + void (*putc)(char ch); + int (*getc)(void); +}; + +void fdt_serial_putc(char ch); + +int fdt_serial_getc(void); + +int fdt_serial_init(void); + +#endif diff --git a/roms/opensbi/include/sbi_utils/serial/shakti-uart.h b/roms/opensbi/include/sbi_utils/serial/shakti-uart.h new file mode 100644 index 000000000..08043be11 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/serial/shakti-uart.h @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Vijai Kumar K <vijai@behindbytes.com> + */ + +#ifndef __SERIAL_SHAKTI_UART_H__ +#define __SERIAL_SHAKTI_UART_H__ + +#include <sbi/sbi_types.h> + +void shakti_uart_putc(char ch); + +int shakti_uart_getc(void); + +int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate); + +#endif diff --git a/roms/opensbi/include/sbi_utils/serial/sifive-uart.h b/roms/opensbi/include/sbi_utils/serial/sifive-uart.h new file mode 100644 index 000000000..f3233921f --- /dev/null +++ b/roms/opensbi/include/sbi_utils/serial/sifive-uart.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __SERIAL_SIFIVE_UART_H__ +#define __SERIAL_SIFIVE_UART_H__ + +#include <sbi/sbi_types.h> + +void sifive_uart_putc(char ch); + +int sifive_uart_getc(void); + +int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate); + +#endif diff --git a/roms/opensbi/include/sbi_utils/serial/uart8250.h b/roms/opensbi/include/sbi_utils/serial/uart8250.h new file mode 100644 index 000000000..0a1b5d368 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/serial/uart8250.h @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __SERIAL_UART8250_H__ +#define __SERIAL_UART8250_H__ + +#include <sbi/sbi_types.h> + +void uart8250_putc(char ch); + +int uart8250_getc(void); + +int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, + u32 reg_width); + +#endif diff --git a/roms/opensbi/include/sbi_utils/sys/clint.h b/roms/opensbi/include/sbi_utils/sys/clint.h new file mode 100644 index 000000000..b07cf62ef --- /dev/null +++ b/roms/opensbi/include/sbi_utils/sys/clint.h @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __SYS_CLINT_H__ +#define __SYS_CLINT_H__ + +#include <sbi/sbi_types.h> + +struct clint_data { + /* Public details */ + unsigned long addr; + u32 first_hartid; + u32 hart_count; + bool has_64bit_mmio; + /* Private details (initialized and used by CLINT library)*/ + u32 *ipi; + struct clint_data *time_delta_reference; + unsigned long time_delta_computed; + u64 time_delta; + u64 *time_val; + u64 *time_cmp; + u64 (*time_rd)(volatile u64 *addr); + void (*time_wr)(u64 value, volatile u64 *addr); +}; + +void clint_ipi_send(u32 target_hart); + +void clint_ipi_clear(u32 target_hart); + +int clint_warm_ipi_init(void); + +int clint_cold_ipi_init(struct clint_data *clint); + +u64 clint_timer_value(void); + +void clint_timer_event_stop(void); + +void clint_timer_event_start(u64 next_event); + +int clint_warm_timer_init(void); + +int clint_cold_timer_init(struct clint_data *clint, + struct clint_data *reference); + +#endif diff --git a/roms/opensbi/include/sbi_utils/sys/htif.h b/roms/opensbi/include/sbi_utils/sys/htif.h new file mode 100644 index 000000000..a43172348 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/sys/htif.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2010-2020, The Regents of the University of California + * (Regents). All Rights Reserved. + */ + +#ifndef __SYS_HTIF_H__ +#define __SYS_HTIF_H__ + +#include <sbi/sbi_types.h> + +void htif_putc(char ch); + +int htif_getc(void); + +int htif_system_reset_check(u32 type, u32 reason); + +void htif_system_reset(u32 type, u32 reason); + +#endif diff --git a/roms/opensbi/include/sbi_utils/sys/sifive_test.h b/roms/opensbi/include/sbi_utils/sys/sifive_test.h new file mode 100644 index 000000000..958622e6a --- /dev/null +++ b/roms/opensbi/include/sbi_utils/sys/sifive_test.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __SYS_SIFIVE_TEST_H__ +#define __SYS_SIFIVE_TEST_H__ + +#include <sbi/sbi_types.h> + +int sifive_test_system_reset_check(u32 type, u32 reason); + +void sifive_test_system_reset(u32 type, u32 reason); + +int sifive_test_init(unsigned long base); + +#endif diff --git a/roms/opensbi/include/sbi_utils/timer/fdt_timer.h b/roms/opensbi/include/sbi_utils/timer/fdt_timer.h new file mode 100644 index 000000000..770a0f3c5 --- /dev/null +++ b/roms/opensbi/include/sbi_utils/timer/fdt_timer.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <anup.patel@wdc.com> + */ + +#ifndef __FDT_TIMER_H__ +#define __FDT_TIMER_H__ + +#include <sbi/sbi_types.h> + +struct fdt_timer { + const struct fdt_match *match_table; + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); + u64 (*value)(void); + void (*event_stop)(void); + void (*event_start)(u64 next_event); +}; + +u64 fdt_timer_value(void); + +void fdt_timer_event_stop(void); + +void fdt_timer_event_start(u64 next_event); + +void fdt_timer_exit(void); + +int fdt_timer_init(bool cold_boot); + +#endif |