mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
Drivers: Support Open Firmware API and model of PIC
We support OFW API to replace fdt old API, and add IRQ, IO, Platform-Bus, CPUs ... OFW node contorl. To support work with Device Tree or ACPI in drivers that use IRQ, we make a programmable interrupt controller driver's model. Signed-off-by: GuEe-GUI <GuEe-GUI@github.com>
This commit is contained in:
1 parent
950d71e1ac
commit
8aa4366cb2
76 files changed
+12204
-5
No files matched your search
@@ -347,6 +347,7 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -219,6 +219,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -275,6 +275,7 @@ CONFIG_RT_USING_POSIX_PIPE_SIZE=512
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -266,6 +266,7 @@ CONFIG_RT_USING_POSIX_PIPE_SIZE=512
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
CONFIG_RT_USING_RESOURCE_ID=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
#define RT_USING_RESOURCE_ID
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
@@ -256,6 +256,7 @@ CONFIG_RT_USING_POSIX_TIMER=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
CONFIG_RT_USING_RESOURCE_ID=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
@@ -140,6 +140,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
#define RT_USING_RESOURCE_ID
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
@@ -364,6 +364,7 @@ CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@
|
||||
#define ULOG_OUTPUT_TAG
|
||||
#define ULOG_BACKEND_USING_CONSOLE
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -414,6 +414,7 @@ CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
#define ULOG_OUTPUT_TAG
|
||||
#define ULOG_BACKEND_USING_CONSOLE
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -228,6 +228,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -398,6 +398,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -386,6 +386,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -404,6 +404,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -398,6 +398,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -399,6 +399,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -272,6 +272,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@
|
||||
#define UTEST_THR_STACK_SIZE 4096
|
||||
#define UTEST_THR_PRIORITY 20
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -252,6 +252,7 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
#define RT_USING_RYM
|
||||
#define YMODEM_USING_FILE_TRANSFER
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -289,6 +289,7 @@ CONFIG_RT_USING_POSIX_MESSAGE_SEMAPHORE=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -277,6 +277,7 @@ CONFIG_RT_USING_POSIX_PIPE_SIZE=512
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -171,6 +171,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -349,6 +349,7 @@ CONFIG_UTEST_THR_STACK_SIZE=4096
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -223,6 +223,7 @@
|
||||
#define UTEST_THR_STACK_SIZE 4096
|
||||
#define UTEST_THR_PRIORITY 20
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -218,6 +218,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -260,6 +260,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -138,6 +138,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -265,6 +265,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -350,6 +350,7 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -204,6 +204,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -357,6 +357,7 @@ CONFIG_UTEST_THR_STACK_SIZE=8192
|
||||
CONFIG_UTEST_THR_PRIORITY=20
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -227,6 +227,7 @@
|
||||
#define UTEST_THR_STACK_SIZE 8192
|
||||
#define UTEST_THR_PRIORITY 20
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -216,6 +216,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
# CONFIG_RT_USING_VAR_EXPORT is not set
|
||||
CONFIG_RT_USING_ADT=y
|
||||
CONFIG_RT_USING_ADT_AVL=y
|
||||
# CONFIG_RT_USING_RT_LINK is not set
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
/* Utilities */
|
||||
|
||||
#define RT_USING_ADT
|
||||
#define RT_USING_ADT_AVL
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
@@ -773,6 +773,9 @@ menuconfig RT_USING_VIRTIO
|
||||
default y
|
||||
endif
|
||||
|
||||
source "$RTT_DIR/components/drivers/ofw/Kconfig"
|
||||
source "$RTT_DIR/components/drivers/pic/Kconfig"
|
||||
|
||||
menu "Using USB"
|
||||
config RT_USING_USB
|
||||
bool
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Executable
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-25 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __OFW_FDT_H__
|
||||
#define __OFW_FDT_H__
|
||||
|
||||
#include <mm_page.h>
|
||||
#include <drivers/ofw.h>
|
||||
|
||||
struct rt_fdt_earlycon
|
||||
{
|
||||
union { rt_ubase_t mmio, port; };
|
||||
union { rt_ubase_t size, width; };
|
||||
|
||||
void *fdt;
|
||||
long nodeoffset;
|
||||
|
||||
void *data;
|
||||
void (*console_putc)(void *data, char c);
|
||||
|
||||
#define FDT_EARLYCON_KICK_UPDATE 0
|
||||
#define FDT_EARLYCON_KICK_COMPLETED 1
|
||||
void (*console_kick)(struct rt_fdt_earlycon *earlycon, int why);
|
||||
|
||||
long msg_idx;
|
||||
char msg[RT_FDT_EARLYCON_MSG_SIZE * 1024];
|
||||
};
|
||||
|
||||
struct rt_fdt_earlycon_id
|
||||
{
|
||||
char *name;
|
||||
char *type;
|
||||
char *compatible;
|
||||
rt_err_t (*setup)(struct rt_fdt_earlycon *earlycon, const char *options);
|
||||
};
|
||||
|
||||
#define RT_FDT_EARLYCON_OPTION_SIGNATURE '\n'
|
||||
|
||||
#define RT_FDT_EARLYCON_EXPORT(_name, _type, _compatible, _setup) \
|
||||
static const struct rt_fdt_earlycon_id __rt_fdt_##_name##_earlycon \
|
||||
rt_used RT_OFW_SYMBOL(earlycon, _) = \
|
||||
{ \
|
||||
.name = #_name, \
|
||||
.type = _type, \
|
||||
.compatible = _compatible, \
|
||||
.setup = _setup, \
|
||||
}
|
||||
|
||||
const char *rt_fdt_node_name(const char *full_name);
|
||||
rt_uint64_t rt_fdt_read_number(const fdt32_t *cell, int size);
|
||||
rt_uint64_t rt_fdt_next_cell(const fdt32_t **cellptr, int size);
|
||||
rt_uint64_t rt_fdt_translate_address(void *fdt, int nodeoffset, rt_uint64_t address);
|
||||
rt_bool_t rt_fdt_device_is_available(void *fdt, int nodeoffset);
|
||||
|
||||
rt_err_t rt_fdt_commit_memregion_early(rt_region_t *region, rt_bool_t is_reserved);
|
||||
rt_err_t rt_fdt_commit_memregion_request(rt_region_t **out_region, rt_size_t *out_nr, rt_bool_t is_reserved);
|
||||
|
||||
rt_err_t rt_fdt_prefetch(void *fdt);
|
||||
rt_err_t rt_fdt_scan_root(void);
|
||||
rt_err_t rt_fdt_scan_memory(void);
|
||||
rt_err_t rt_fdt_scan_initrd(rt_uint64_t *ranges);
|
||||
rt_err_t rt_fdt_model_dump(void);
|
||||
rt_err_t rt_fdt_boot_dump(void);
|
||||
void rt_fdt_earlycon_output(const char *str);
|
||||
void rt_fdt_earlycon_kick(int why);
|
||||
rt_err_t rt_fdt_scan_chosen_stdout(void);
|
||||
rt_err_t rt_fdt_unflatten(void);
|
||||
|
||||
struct rt_ofw_node *rt_fdt_unflatten_single(void *fdt);
|
||||
|
||||
#endif /* __OFW_FDT_H__ */
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-25 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __OFW_IO_H__
|
||||
#define __OFW_IO_H__
|
||||
|
||||
#include <drivers/ofw.h>
|
||||
|
||||
int rt_ofw_bus_addr_cells(struct rt_ofw_node *np);
|
||||
int rt_ofw_bus_size_cells(struct rt_ofw_node *np);
|
||||
int rt_ofw_io_addr_cells(struct rt_ofw_node *np);
|
||||
int rt_ofw_io_size_cells(struct rt_ofw_node *np);
|
||||
|
||||
int rt_ofw_get_address_count(struct rt_ofw_node *np);
|
||||
rt_err_t rt_ofw_get_address(struct rt_ofw_node *np, int index, rt_uint64_t *out_address, rt_uint64_t *out_size);
|
||||
rt_err_t rt_ofw_get_address_by_name(struct rt_ofw_node *np, const char *name,
|
||||
rt_uint64_t *out_address, rt_uint64_t *out_size);
|
||||
int rt_ofw_get_address_array(struct rt_ofw_node *np, int nr, rt_uint64_t *out_regs);
|
||||
|
||||
rt_uint64_t rt_ofw_translate_address(struct rt_ofw_node *np, const char *range_type, rt_uint64_t address);
|
||||
|
||||
void *rt_ofw_iomap(struct rt_ofw_node *np, int index);
|
||||
void *rt_ofw_iomap_by_name(struct rt_ofw_node *np, const char *name);
|
||||
|
||||
#endif /* __OFW_IO_H__ */
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-25 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __OFW_IRQ_H__
|
||||
#define __OFW_IRQ_H__
|
||||
|
||||
#include <drivers/ofw.h>
|
||||
|
||||
int rt_ofw_irq_cells(struct rt_ofw_node *np);
|
||||
|
||||
rt_err_t rt_ofw_parse_irq_map(struct rt_ofw_node *np, struct rt_ofw_cell_args *irq_args);
|
||||
rt_err_t rt_ofw_parse_irq_cells(struct rt_ofw_node *np, int index, struct rt_ofw_cell_args *out_irq_args);
|
||||
|
||||
struct rt_ofw_node *rt_ofw_find_irq_parent(struct rt_ofw_node *np, int *out_interrupt_cells);
|
||||
int rt_ofw_map_irq(struct rt_ofw_cell_args *irq_args);
|
||||
|
||||
int rt_ofw_get_irq_count(struct rt_ofw_node *np);
|
||||
int rt_ofw_get_irq(struct rt_ofw_node *np, int index);
|
||||
int rt_ofw_get_irq_by_name(struct rt_ofw_node *np, const char *name);
|
||||
|
||||
#endif /* __OFW_IRQ_H__ */
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-25 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __OFW_RAW_H__
|
||||
#define __OFW_RAW_H__
|
||||
|
||||
#include <libfdt/libfdt.h>
|
||||
|
||||
#define FDT_SIZE_KB 1024
|
||||
#define FDT_SIZE_MB (1024 * FDT_SIZE_KB)
|
||||
|
||||
#define FDT_SIZE_MAX (2 * FDT_SIZE_MB)
|
||||
#define FDT_PADDING_SIZE (1 * FDT_SIZE_KB)
|
||||
|
||||
typedef uint8_t fdt8_t;
|
||||
|
||||
static inline uint8_t fdt8_to_cpu(fdt8_t x)
|
||||
{
|
||||
return (uint8_t)x;
|
||||
}
|
||||
|
||||
int fdt_add_subnode_possible(void *fdt, int parentoffset, const char *name);
|
||||
int fdt_add_mem_rsv_possible(void *fdt, size_t addr, size_t size);
|
||||
|
||||
#define fdt_setprop_cstring(fdt, nodeoffset, name, str) \
|
||||
fdt_setprop((fdt), (nodeoffset), (name), (str), sizeof(str))
|
||||
|
||||
#define fdt_prop_cells_ops(ops, fdt, nodeoffset, prop, ...) \
|
||||
({ \
|
||||
int ret = 0; \
|
||||
uint32_t tmp[] = { __VA_ARGS__ }; \
|
||||
for (int i = 0; i < sizeof(tmp) / sizeof(tmp[0]); ++i) \
|
||||
{ \
|
||||
tmp[i] = cpu_to_fdt32(tmp[i]); \
|
||||
} \
|
||||
ret += ops(fdt, nodeoffset, prop, tmp, sizeof(tmp)); \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#define fdt_setprop_cells(fdt, nodeoffset, prop, ...) \
|
||||
fdt_prop_cells_ops(fdt_setprop, fdt, nodeoffset, prop, __VA_ARGS__)
|
||||
|
||||
#define fdt_appendprop_cells(fdt, nodeoffset, prop, ...) \
|
||||
fdt_prop_cells_ops(fdt_appendprop, fdt, nodeoffset, prop, __VA_ARGS__)
|
||||
|
||||
int fdt_setprop_uxx(void *fdt, int nodeoffset, const char *name, uint64_t val, bool is_u64);
|
||||
int fdt_getprop_u8(void *fdt, int nodeoffset, const char *name, uint8_t *out_value, int *lenp);
|
||||
int fdt_getprop_s8(void *fdt, int nodeoffset, const char *name, int8_t *out_value, int *lenp);
|
||||
int fdt_getprop_u16(void *fdt, int nodeoffset, const char *name, uint16_t *out_value, int *lenp);
|
||||
int fdt_getprop_s16(void *fdt, int nodeoffset, const char *name, int16_t *out_value, int *lenp);
|
||||
int fdt_getprop_u32(void *fdt, int nodeoffset, const char *name, uint32_t *out_value, int *lenp);
|
||||
int fdt_getprop_s32(void *fdt, int nodeoffset, const char *name, int32_t *out_value, int *lenp);
|
||||
|
||||
int fdt_io_addr_cells(void *fdt, int nodeoffset);
|
||||
int fdt_io_size_cells(void *fdt, int nodeoffset);
|
||||
|
||||
int fdt_install_initrd(void *fdt, char *os_name, size_t initrd_addr, size_t initrd_size);
|
||||
|
||||
#endif /* __OFW_RAW_H__ */
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-24 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __PIC_H__
|
||||
#define __PIC_H__
|
||||
|
||||
#include <rthw.h>
|
||||
|
||||
#include <bitmap.h>
|
||||
#include <drivers/ofw.h>
|
||||
#include <drivers/core/rtdm.h>
|
||||
|
||||
struct rt_pci_msi_desc;
|
||||
struct rt_pci_msi_msg;
|
||||
|
||||
struct rt_pic_ops;
|
||||
struct rt_pic_irq;
|
||||
|
||||
struct rt_pic
|
||||
{
|
||||
rt_list_t list;
|
||||
|
||||
struct rt_pic_ops *ops;
|
||||
|
||||
void *priv_data;
|
||||
void *user_data;
|
||||
|
||||
struct rt_pic *parent;
|
||||
|
||||
int irq_start;
|
||||
rt_size_t irq_nr;
|
||||
struct rt_pic_irq *pirqs;
|
||||
};
|
||||
|
||||
struct rt_pic_ops
|
||||
{
|
||||
const char *name;
|
||||
|
||||
rt_err_t (*irq_init)(struct rt_pic *pic);
|
||||
rt_err_t (*irq_finit)(struct rt_pic *pic);
|
||||
|
||||
void (*irq_enable)(struct rt_pic_irq *pirq);
|
||||
void (*irq_disable)(struct rt_pic_irq *pirq);
|
||||
void (*irq_ack)(struct rt_pic_irq *pirq);
|
||||
void (*irq_mask)(struct rt_pic_irq *pirq);
|
||||
void (*irq_unmask)(struct rt_pic_irq *pirq);
|
||||
void (*irq_eoi)(struct rt_pic_irq *pirq);
|
||||
|
||||
rt_err_t (*irq_set_priority)(struct rt_pic_irq *pirq, rt_uint32_t priority);
|
||||
rt_err_t (*irq_set_affinity)(struct rt_pic_irq *pirq, rt_bitmap_t *affinity);
|
||||
rt_err_t (*irq_set_triger_mode)(struct rt_pic_irq *pirq, rt_uint32_t mode);
|
||||
|
||||
void (*irq_send_ipi)(struct rt_pic_irq *pirq, rt_bitmap_t *cpumask);
|
||||
|
||||
void (*irq_compose_msi_msg)(struct rt_pic_irq *pirq, struct rt_pci_msi_msg *msg);
|
||||
void (*irq_write_msi_msg)(struct rt_pic_irq *pirq, struct rt_pci_msi_msg *msg);
|
||||
int (*irq_alloc_msi)(struct rt_pic *pic, struct rt_pci_msi_desc *msi_desc);
|
||||
void (*irq_free_msi)(struct rt_pic *pic, int irq);
|
||||
|
||||
int (*irq_map)(struct rt_pic *pic, int hwirq, rt_uint32_t mode);
|
||||
rt_err_t (*irq_parse)(struct rt_pic *pic, struct rt_ofw_cell_args *args, struct rt_pic_irq *out_pirq);
|
||||
};
|
||||
|
||||
struct rt_pic_isr
|
||||
{
|
||||
rt_list_t list;
|
||||
|
||||
#define RT_IRQ_F_NONE 0
|
||||
int flags;
|
||||
struct rt_irq_desc action;
|
||||
};
|
||||
|
||||
struct rt_pic_irq
|
||||
{
|
||||
int irq;
|
||||
int hwirq;
|
||||
|
||||
#define RT_IRQ_MODE_NONE 0
|
||||
#define RT_IRQ_MODE_EDGE_RISING 1
|
||||
#define RT_IRQ_MODE_EDGE_FALLING 2
|
||||
#define RT_IRQ_MODE_EDGE_BOTH (RT_IRQ_MODE_EDGE_FALLING | RT_IRQ_MODE_EDGE_RISING)
|
||||
#define RT_IRQ_MODE_LEVEL_HIGH 4
|
||||
#define RT_IRQ_MODE_LEVEL_LOW 8
|
||||
#define RT_IRQ_MODE_LEVEL_MASK (RT_IRQ_MODE_LEVEL_LOW | RT_IRQ_MODE_LEVEL_HIGH)
|
||||
#define RT_IRQ_MODE_MASK 0xf
|
||||
rt_uint32_t mode;
|
||||
|
||||
rt_uint32_t priority;
|
||||
RT_DECLARE_BITMAP(affinity, RT_CPUS_NR);
|
||||
|
||||
struct rt_pci_msi_desc *msi_desc;
|
||||
|
||||
struct rt_pic_isr isr;
|
||||
|
||||
struct rt_spinlock rw_lock;
|
||||
|
||||
struct rt_pic *pic;
|
||||
};
|
||||
|
||||
rt_err_t rt_pic_linear_irq(struct rt_pic *pic, rt_size_t irq_nr);
|
||||
|
||||
int rt_pic_config_ipi(struct rt_pic *pic, int ipi_index, int hwirq);
|
||||
int rt_pic_config_irq(struct rt_pic *pic, int irq_index, int hwirq);
|
||||
|
||||
rt_inline struct rt_pic_irq *rt_pic_find_irq(struct rt_pic *pic, int irq_index)
|
||||
{
|
||||
/* This is a quickly interface */
|
||||
RT_ASSERT(pic != RT_NULL);
|
||||
RT_ASSERT(pic->pirqs != RT_NULL);
|
||||
RT_ASSERT(irq_index < pic->irq_nr);
|
||||
|
||||
return &pic->pirqs[irq_index];
|
||||
}
|
||||
|
||||
struct rt_pic_irq *rt_pic_find_ipi(struct rt_pic *pic, int ipi_index);
|
||||
|
||||
int rt_pic_cascade(struct rt_pic *pic, struct rt_pic *parent_pic, int hwirq, rt_uint32_t mode);
|
||||
void rt_pic_uncascade(struct rt_pic *pic, int irq);
|
||||
|
||||
rt_err_t rt_pic_attach_irq(int irq, rt_isr_handler_t handler, void *uid, const char *name, int flags);
|
||||
rt_err_t rt_pic_detach_irq(int irq, void *uid);
|
||||
|
||||
rt_err_t rt_pic_add_traps(rt_bool_t (*handler)(void *), void *data);
|
||||
rt_err_t rt_pic_do_traps(void);
|
||||
rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq);
|
||||
|
||||
/* User-implemented extensions */
|
||||
rt_err_t rt_pic_user_extends(struct rt_pic *pic);
|
||||
|
||||
rt_err_t rt_pic_irq_init(void);
|
||||
rt_err_t rt_pic_irq_finit(void);
|
||||
void rt_pic_irq_enable(int irq);
|
||||
void rt_pic_irq_disable(int irq);
|
||||
void rt_pic_irq_ack(int irq);
|
||||
void rt_pic_irq_mask(int irq);
|
||||
void rt_pic_irq_unmask(int irq);
|
||||
void rt_pic_irq_eoi(int irq);
|
||||
rt_err_t rt_pic_irq_set_priority(int irq, rt_uint32_t priority);
|
||||
rt_uint32_t rt_pic_irq_get_priority(int irq);
|
||||
rt_err_t rt_pic_irq_set_affinity(int irq, rt_bitmap_t *affinity);
|
||||
rt_err_t rt_pic_irq_get_affinity(int irq, rt_bitmap_t *out_affinity);
|
||||
rt_err_t rt_pic_irq_set_triger_mode(int irq, rt_uint32_t mode);
|
||||
rt_uint32_t rt_pic_irq_get_triger_mode(int irq);
|
||||
void rt_pic_irq_send_ipi(int irq, rt_bitmap_t *cpumask);
|
||||
|
||||
void rt_pic_irq_parent_enable(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
void rt_pic_irq_parent_disable(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
void rt_pic_irq_parent_ack(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
void rt_pic_irq_parent_mask(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
void rt_pic_irq_parent_unmask(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
void rt_pic_irq_parent_eoi(struct rt_pic *ppic, struct rt_pic_irq *pirq);
|
||||
rt_err_t rt_pic_irq_parent_set_priority(struct rt_pic *ppic, struct rt_pic_irq *pirq, rt_uint32_t priority);
|
||||
rt_err_t rt_pic_irq_parent_set_affinity(struct rt_pic *ppic, struct rt_pic_irq *pirq, rt_bitmap_t *affinity);
|
||||
rt_err_t rt_pic_irq_parent_set_triger_mode(struct rt_pic *ppic, struct rt_pic_irq *pirq, rt_uint32_t mode);
|
||||
|
||||
#define RT_PIC_OFW_DECLARE(name, ids, handler) RT_OFW_STUB_EXPORT(name, ids, pic, handler)
|
||||
|
||||
rt_err_t rt_pic_init(void);
|
||||
|
||||
#endif /* __PIC_H__ */
|
||||
@@ -171,6 +171,18 @@ extern "C" {
|
||||
|
||||
#ifdef RT_USING_DM
|
||||
#include "drivers/core/rtdm.h"
|
||||
|
||||
#ifdef RT_USING_OFW
|
||||
#include "drivers/ofw.h"
|
||||
#include "drivers/ofw_fdt.h"
|
||||
#include "drivers/ofw_io.h"
|
||||
#include "drivers/ofw_irq.h"
|
||||
#include "drivers/ofw_raw.h"
|
||||
#endif /* RT_USING_OFW */
|
||||
|
||||
#ifdef RT_USING_PIC
|
||||
#include "drivers/pic.h"
|
||||
#endif
|
||||
#endif /* RT_USING_DM */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
menuconfig RT_USING_OFW
|
||||
bool "Using Open Firmware (OFW)"
|
||||
select RT_USING_ADT
|
||||
select RT_USING_ADT_REF
|
||||
select RT_USING_ADT_BITMAP
|
||||
depends on RT_USING_DM
|
||||
default n
|
||||
|
||||
config RT_USING_BUILTIN_FDT
|
||||
bool "Using builtin fdt in kernel"
|
||||
depends on RT_USING_OFW
|
||||
default n
|
||||
|
||||
config RT_BUILTIN_FDT_PATH
|
||||
string "Builtin fdt path, will rebuild if have dts"
|
||||
depends on RT_USING_BUILTIN_FDT
|
||||
default "rtthread.dtb"
|
||||
|
||||
config RT_FDT_EARLYCON_MSG_SIZE
|
||||
int "Earlycon message buffer size (KB)"
|
||||
depends on RT_USING_OFW
|
||||
default 128
|
||||
@@ -0,0 +1,22 @@
|
||||
from building import *
|
||||
|
||||
objs = []
|
||||
|
||||
if not GetDepend(['RT_USING_OFW']):
|
||||
Return('objs')
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
list = os.listdir(cwd)
|
||||
CPPPATH = [cwd, cwd + '/../include']
|
||||
|
||||
src = Glob('*.c')
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
objs = objs + group
|
||||
|
||||
Return('objs')
|
||||
File diff suppressed because it is too large.
Load diff
Executable
+1108
File diff suppressed because it is too large.
Load diff
Executable
+421
File diff suppressed because it is too large.
Load diff
Executable
+648
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,10 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,66 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef FDT_H
|
||||
#define FDT_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
struct fdt_header {
|
||||
fdt32_t magic; /* magic word FDT_MAGIC */
|
||||
fdt32_t totalsize; /* total size of DT block */
|
||||
fdt32_t off_dt_struct; /* offset to structure */
|
||||
fdt32_t off_dt_strings; /* offset to strings */
|
||||
fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
|
||||
fdt32_t version; /* format version */
|
||||
fdt32_t last_comp_version; /* last compatible version */
|
||||
|
||||
/* version 2 fields below */
|
||||
fdt32_t boot_cpuid_phys; /* Which physical CPU id we're
|
||||
booting on */
|
||||
/* version 3 fields below */
|
||||
fdt32_t size_dt_strings; /* size of the strings block */
|
||||
|
||||
/* version 17 fields below */
|
||||
fdt32_t size_dt_struct; /* size of the structure block */
|
||||
};
|
||||
|
||||
struct fdt_reserve_entry {
|
||||
fdt64_t address;
|
||||
fdt64_t size;
|
||||
};
|
||||
|
||||
struct fdt_node_header {
|
||||
fdt32_t tag;
|
||||
char name[];
|
||||
};
|
||||
|
||||
struct fdt_property {
|
||||
fdt32_t tag;
|
||||
fdt32_t len;
|
||||
fdt32_t nameoff;
|
||||
char data[];
|
||||
};
|
||||
|
||||
#endif /* !__ASSEMBLY */
|
||||
|
||||
#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
|
||||
#define FDT_TAGSIZE sizeof(fdt32_t)
|
||||
|
||||
#define FDT_BEGIN_NODE 0x1 /* Start node: full name */
|
||||
#define FDT_END_NODE 0x2 /* End node */
|
||||
#define FDT_PROP 0x3 /* Property: name off,
|
||||
size, content */
|
||||
#define FDT_NOP 0x4 /* nop */
|
||||
#define FDT_END 0x9
|
||||
|
||||
#define FDT_V1_SIZE (7*sizeof(fdt32_t))
|
||||
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
|
||||
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
|
||||
#define FDT_V16_SIZE FDT_V3_SIZE
|
||||
#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t))
|
||||
|
||||
#endif /* FDT_H */
|
||||
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
|
||||
* Copyright (C) 2018 embedded brains GmbH
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
|
||||
{
|
||||
const fdt32_t *c;
|
||||
uint32_t val;
|
||||
int len;
|
||||
|
||||
c = fdt_getprop(fdt, nodeoffset, name, &len);
|
||||
if (!c)
|
||||
return len;
|
||||
|
||||
if (len != sizeof(*c))
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
val = fdt32_to_cpu(*c);
|
||||
if (val > FDT_MAX_NCELLS)
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
return (int)val;
|
||||
}
|
||||
|
||||
int fdt_address_cells(const void *fdt, int nodeoffset)
|
||||
{
|
||||
int val;
|
||||
|
||||
val = fdt_cells(fdt, nodeoffset, "#address-cells");
|
||||
if (val == 0)
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
if (val == -FDT_ERR_NOTFOUND)
|
||||
return 2;
|
||||
return val;
|
||||
}
|
||||
|
||||
int fdt_size_cells(const void *fdt, int nodeoffset)
|
||||
{
|
||||
int val;
|
||||
|
||||
val = fdt_cells(fdt, nodeoffset, "#size-cells");
|
||||
if (val == -FDT_ERR_NOTFOUND)
|
||||
return 1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/* This function assumes that [address|size]_cells is 1 or 2 */
|
||||
int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
|
||||
const char *name, uint64_t addr, uint64_t size)
|
||||
{
|
||||
int addr_cells, size_cells, ret;
|
||||
uint8_t data[sizeof(fdt64_t) * 2], *prop;
|
||||
|
||||
ret = fdt_address_cells(fdt, parent);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
addr_cells = ret;
|
||||
|
||||
ret = fdt_size_cells(fdt, parent);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
size_cells = ret;
|
||||
|
||||
/* check validity of address */
|
||||
prop = data;
|
||||
if (addr_cells == 1) {
|
||||
if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size))
|
||||
return -FDT_ERR_BADVALUE;
|
||||
|
||||
fdt32_st(prop, (uint32_t)addr);
|
||||
} else if (addr_cells == 2) {
|
||||
fdt64_st(prop, addr);
|
||||
} else {
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
}
|
||||
|
||||
/* check validity of size */
|
||||
prop += addr_cells * sizeof(fdt32_t);
|
||||
if (size_cells == 1) {
|
||||
if (size > UINT32_MAX)
|
||||
return -FDT_ERR_BADVALUE;
|
||||
|
||||
fdt32_st(prop, (uint32_t)size);
|
||||
} else if (size_cells == 2) {
|
||||
fdt64_st(prop, size);
|
||||
} else {
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
}
|
||||
|
||||
return fdt_appendprop(fdt, nodeoffset, name, data,
|
||||
(addr_cells + size_cells) * sizeof(fdt32_t));
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2012 David Gibson, IBM Corporation.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
int fdt_create_empty_tree(void *buf, int bufsize)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = fdt_create(buf, bufsize);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = fdt_finish_reservemap(buf);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = fdt_begin_node(buf, "");
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = fdt_end_node(buf);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = fdt_finish(buf);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return fdt_open_into(buf, buf, bufsize);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
struct fdt_errtabent {
|
||||
const char *str;
|
||||
};
|
||||
|
||||
#define FDT_ERRTABENT(val) \
|
||||
[(val)] = { .str = #val, }
|
||||
|
||||
static struct fdt_errtabent fdt_errtable[] = {
|
||||
FDT_ERRTABENT(FDT_ERR_NOTFOUND),
|
||||
FDT_ERRTABENT(FDT_ERR_EXISTS),
|
||||
FDT_ERRTABENT(FDT_ERR_NOSPACE),
|
||||
|
||||
FDT_ERRTABENT(FDT_ERR_BADOFFSET),
|
||||
FDT_ERRTABENT(FDT_ERR_BADPATH),
|
||||
FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
|
||||
FDT_ERRTABENT(FDT_ERR_BADSTATE),
|
||||
|
||||
FDT_ERRTABENT(FDT_ERR_TRUNCATED),
|
||||
FDT_ERRTABENT(FDT_ERR_BADMAGIC),
|
||||
FDT_ERRTABENT(FDT_ERR_BADVERSION),
|
||||
FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
|
||||
FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
|
||||
FDT_ERRTABENT(FDT_ERR_INTERNAL),
|
||||
FDT_ERRTABENT(FDT_ERR_BADNCELLS),
|
||||
FDT_ERRTABENT(FDT_ERR_BADVALUE),
|
||||
FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
|
||||
FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
|
||||
FDT_ERRTABENT(FDT_ERR_BADFLAGS),
|
||||
FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
|
||||
};
|
||||
#define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
|
||||
|
||||
const char *fdt_strerror(int errval)
|
||||
{
|
||||
if (errval > 0)
|
||||
return "<valid offset/length>";
|
||||
else if (errval == 0)
|
||||
return "<no error>";
|
||||
else if (-errval < FDT_ERRTABSIZE) {
|
||||
const char *s = fdt_errtable[-errval].str;
|
||||
|
||||
if (s)
|
||||
return s;
|
||||
}
|
||||
|
||||
return "<unknown error>";
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,94 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
||||
const char *name, int namelen,
|
||||
uint32_t idx, const void *val,
|
||||
int len)
|
||||
{
|
||||
void *propval;
|
||||
int proplen;
|
||||
|
||||
propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
|
||||
&proplen);
|
||||
if (!propval)
|
||||
return proplen;
|
||||
|
||||
if ((unsigned)proplen < (len + idx))
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
memcpy((char *)propval + idx, val, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
|
||||
const void *val, int len)
|
||||
{
|
||||
const void *propval;
|
||||
int proplen;
|
||||
|
||||
propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
|
||||
if (!propval)
|
||||
return proplen;
|
||||
|
||||
if (proplen != len)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
|
||||
strlen(name), 0,
|
||||
val, len);
|
||||
}
|
||||
|
||||
static void fdt_nop_region_(void *start, int len)
|
||||
{
|
||||
fdt32_t *p;
|
||||
|
||||
for (p = start; (char *)p < ((char *)start + len); p++)
|
||||
*p = cpu_to_fdt32(FDT_NOP);
|
||||
}
|
||||
|
||||
int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
|
||||
{
|
||||
struct fdt_property *prop;
|
||||
int len;
|
||||
|
||||
prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
|
||||
if (!prop)
|
||||
return len;
|
||||
|
||||
fdt_nop_region_(prop, len + sizeof(*prop));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_node_end_offset_(void *fdt, int offset)
|
||||
{
|
||||
int depth = 0;
|
||||
|
||||
while ((offset >= 0) && (depth >= 0))
|
||||
offset = fdt_next_node(fdt, offset, &depth);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
int fdt_nop_node(void *fdt, int nodeoffset)
|
||||
{
|
||||
int endoffset;
|
||||
|
||||
endoffset = fdt_node_end_offset_(fdt, nodeoffset);
|
||||
if (endoffset < 0)
|
||||
return endoffset;
|
||||
|
||||
fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
|
||||
endoffset - nodeoffset);
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,100 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef LIBFDT_ENV_H
|
||||
#define LIBFDT_ENV_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __CHECKER__
|
||||
#define FDT_FORCE __attribute__((force))
|
||||
#define FDT_BITWISE __attribute__((bitwise))
|
||||
#else
|
||||
#define FDT_FORCE
|
||||
#define FDT_BITWISE
|
||||
#endif
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define strnlen rt_strnlen
|
||||
|
||||
typedef uint16_t FDT_BITWISE fdt16_t;
|
||||
typedef uint32_t FDT_BITWISE fdt32_t;
|
||||
typedef uint64_t FDT_BITWISE fdt64_t;
|
||||
|
||||
#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
|
||||
#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
|
||||
#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
|
||||
(EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
|
||||
#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
|
||||
(EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
|
||||
(EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
|
||||
(EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
|
||||
|
||||
static inline uint16_t fdt16_to_cpu(fdt16_t x)
|
||||
{
|
||||
return (FDT_FORCE uint16_t)CPU_TO_FDT16(x);
|
||||
}
|
||||
static inline fdt16_t cpu_to_fdt16(uint16_t x)
|
||||
{
|
||||
return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x);
|
||||
}
|
||||
|
||||
static inline uint32_t fdt32_to_cpu(fdt32_t x)
|
||||
{
|
||||
return (FDT_FORCE uint32_t)CPU_TO_FDT32(x);
|
||||
}
|
||||
static inline fdt32_t cpu_to_fdt32(uint32_t x)
|
||||
{
|
||||
return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x);
|
||||
}
|
||||
|
||||
static inline uint64_t fdt64_to_cpu(fdt64_t x)
|
||||
{
|
||||
return (FDT_FORCE uint64_t)CPU_TO_FDT64(x);
|
||||
}
|
||||
static inline fdt64_t cpu_to_fdt64(uint64_t x)
|
||||
{
|
||||
return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x);
|
||||
}
|
||||
#undef CPU_TO_FDT64
|
||||
#undef CPU_TO_FDT32
|
||||
#undef CPU_TO_FDT16
|
||||
#undef EXTRACT_BYTE
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
/* strnlen() is not available on Mac OS < 10.7 */
|
||||
# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \
|
||||
MAC_OS_X_VERSION_10_7)
|
||||
|
||||
#define strnlen fdt_strnlen
|
||||
|
||||
/*
|
||||
* fdt_strnlen: returns the length of a string or max_count - which ever is
|
||||
* smallest.
|
||||
* Input 1 string: the string whose size is to be determined
|
||||
* Input 2 max_count: the maximum value returned by this function
|
||||
* Output: length of the string or max_count (the smallest of the two)
|
||||
*/
|
||||
static inline size_t fdt_strnlen(const char *string, size_t max_count)
|
||||
{
|
||||
const char *p = memchr(string, 0, max_count);
|
||||
return p ? p - string : max_count;
|
||||
}
|
||||
|
||||
#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED <
|
||||
MAC_OS_X_VERSION_10_7) */
|
||||
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#endif /* LIBFDT_ENV_H */
|
||||
@@ -0,0 +1,192 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef LIBFDT_INTERNAL_H
|
||||
#define LIBFDT_INTERNAL_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*/
|
||||
#include <fdt.h>
|
||||
|
||||
#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
|
||||
|
||||
int32_t fdt_ro_probe_(const void *fdt);
|
||||
#define FDT_RO_PROBE(fdt) \
|
||||
{ \
|
||||
int32_t totalsize_; \
|
||||
if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \
|
||||
return totalsize_; \
|
||||
}
|
||||
|
||||
int fdt_check_node_offset_(const void *fdt, int offset);
|
||||
int fdt_check_prop_offset_(const void *fdt, int offset);
|
||||
const char *fdt_find_string_(const char *strtab, int tabsize, const char *s);
|
||||
int fdt_node_end_offset_(void *fdt, int nodeoffset);
|
||||
|
||||
static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
|
||||
{
|
||||
return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
|
||||
}
|
||||
|
||||
static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
|
||||
{
|
||||
return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
|
||||
}
|
||||
|
||||
static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
|
||||
{
|
||||
const struct fdt_reserve_entry *rsv_table =
|
||||
(const struct fdt_reserve_entry *)
|
||||
((const char *)fdt + fdt_off_mem_rsvmap(fdt));
|
||||
|
||||
return rsv_table + n;
|
||||
}
|
||||
static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
|
||||
{
|
||||
return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal helpers to access tructural elements of the device tree
|
||||
* blob (rather than for exaple reading integers from within property
|
||||
* values). We assume that we are either given a naturally aligned
|
||||
* address for the platform or if we are not, we are on a platform
|
||||
* where unaligned memory reads will be handled in a graceful manner.
|
||||
* If not the external helpers fdtXX_ld() from libfdt.h can be used
|
||||
* instead.
|
||||
*/
|
||||
static inline uint32_t fdt32_ld_(const fdt32_t *p)
|
||||
{
|
||||
return fdt32_to_cpu(*p);
|
||||
}
|
||||
|
||||
static inline uint64_t fdt64_ld_(const fdt64_t *p)
|
||||
{
|
||||
return fdt64_to_cpu(*p);
|
||||
}
|
||||
|
||||
#define FDT_SW_MAGIC (~FDT_MAGIC)
|
||||
|
||||
/**********************************************************************/
|
||||
/* Checking controls */
|
||||
/**********************************************************************/
|
||||
|
||||
#ifndef FDT_ASSUME_MASK
|
||||
#define FDT_ASSUME_MASK 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defines assumptions which can be enabled. Each of these can be enabled
|
||||
* individually. For maximum safety, don't enable any assumptions!
|
||||
*
|
||||
* For minimal code size and no safety, use ASSUME_PERFECT at your own risk.
|
||||
* You should have another method of validating the device tree, such as a
|
||||
* signature or hash check before using libfdt.
|
||||
*
|
||||
* For situations where security is not a concern it may be safe to enable
|
||||
* ASSUME_SANE.
|
||||
*/
|
||||
enum {
|
||||
/*
|
||||
* This does essentially no checks. Only the latest device-tree
|
||||
* version is correctly handled. Inconsistencies or errors in the device
|
||||
* tree may cause undefined behaviour or crashes. Invalid parameters
|
||||
* passed to libfdt may do the same.
|
||||
*
|
||||
* If an error occurs when modifying the tree it may leave the tree in
|
||||
* an intermediate (but valid) state. As an example, adding a property
|
||||
* where there is insufficient space may result in the property name
|
||||
* being added to the string table even though the property itself is
|
||||
* not added to the struct section.
|
||||
*
|
||||
* Only use this if you have a fully validated device tree with
|
||||
* the latest supported version and wish to minimise code size.
|
||||
*/
|
||||
ASSUME_PERFECT = 0xff,
|
||||
|
||||
/*
|
||||
* This assumes that the device tree is sane. i.e. header metadata
|
||||
* and basic hierarchy are correct.
|
||||
*
|
||||
* With this assumption enabled, normal device trees produced by libfdt
|
||||
* and the compiler should be handled safely. Malicious device trees and
|
||||
* complete garbage may cause libfdt to behave badly or crash. Truncated
|
||||
* device trees (e.g. those only partially loaded) can also cause
|
||||
* problems.
|
||||
*
|
||||
* Note: Only checks that relate exclusively to the device tree itself
|
||||
* (not the parameters passed to libfdt) are disabled by this
|
||||
* assumption. This includes checking headers, tags and the like.
|
||||
*/
|
||||
ASSUME_VALID_DTB = 1 << 0,
|
||||
|
||||
/*
|
||||
* This builds on ASSUME_VALID_DTB and further assumes that libfdt
|
||||
* functions are called with valid parameters, i.e. not trigger
|
||||
* FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any
|
||||
* extensive checking of parameters and the device tree, making various
|
||||
* assumptions about correctness.
|
||||
*
|
||||
* It doesn't make sense to enable this assumption unless
|
||||
* ASSUME_VALID_DTB is also enabled.
|
||||
*/
|
||||
ASSUME_VALID_INPUT = 1 << 1,
|
||||
|
||||
/*
|
||||
* This disables checks for device-tree version and removes all code
|
||||
* which handles older versions.
|
||||
*
|
||||
* Only enable this if you know you have a device tree with the latest
|
||||
* version.
|
||||
*/
|
||||
ASSUME_LATEST = 1 << 2,
|
||||
|
||||
/*
|
||||
* This assumes that it is OK for a failed addition to the device tree,
|
||||
* due to lack of space or some other problem, to skip any rollback
|
||||
* steps (such as dropping the property name from the string table).
|
||||
* This is safe to enable in most circumstances, even though it may
|
||||
* leave the tree in a sub-optimal state.
|
||||
*/
|
||||
ASSUME_NO_ROLLBACK = 1 << 3,
|
||||
|
||||
/*
|
||||
* This assumes that the device tree components appear in a 'convenient'
|
||||
* order, i.e. the memory reservation block first, then the structure
|
||||
* block and finally the string block.
|
||||
*
|
||||
* This order is not specified by the device-tree specification,
|
||||
* but is expected by libfdt. The device-tree compiler always created
|
||||
* device trees with this order.
|
||||
*
|
||||
* This assumption disables a check in fdt_open_into() and removes the
|
||||
* ability to fix the problem there. This is safe if you know that the
|
||||
* device tree is correctly ordered. See fdt_blocks_misordered_().
|
||||
*/
|
||||
ASSUME_LIBFDT_ORDER = 1 << 4,
|
||||
|
||||
/*
|
||||
* This assumes that libfdt itself does not have any internal bugs. It
|
||||
* drops certain checks that should never be needed unless libfdt has an
|
||||
* undiscovered bug.
|
||||
*
|
||||
* This can generally be considered safe to enable.
|
||||
*/
|
||||
ASSUME_LIBFDT_FLAWLESS = 1 << 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* can_assume_() - check if a particular assumption is enabled
|
||||
*
|
||||
* @mask: Mask to check (ASSUME_...)
|
||||
* @return true if that assumption is enabled, else false
|
||||
*/
|
||||
static inline bool can_assume_(int mask)
|
||||
{
|
||||
return FDT_ASSUME_MASK & mask;
|
||||
}
|
||||
|
||||
/** helper macros for checking assumptions */
|
||||
#define can_assume(_assume) can_assume_(ASSUME_ ## _assume)
|
||||
|
||||
#endif /* LIBFDT_INTERNAL_H */
|
||||
Executable
+573
File diff suppressed because it is too large.
Load diff
Executable
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-25 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#ifndef __OFW_INTERNAL_H__
|
||||
#define __OFW_INTERNAL_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <drivers/ofw.h>
|
||||
|
||||
#define OFW_PHANDLE_MIN 1
|
||||
#define OFW_PHANDLE_MAX FDT_MAX_PHANDLE
|
||||
|
||||
#define OFW_NODE_MAX_DEPTH 64
|
||||
#define OFW_NODE_MIN_HASH 128
|
||||
|
||||
#define OFW_ROOT_NODE_ADDR_CELLS_DEFAULT 1
|
||||
#define OFW_ROOT_NODE_SIZE_CELLS_DEFAULT 1
|
||||
|
||||
struct fdt_info
|
||||
{
|
||||
/* Always "/", because we save "ofw" information in root node. */
|
||||
char name[sizeof("/")];
|
||||
|
||||
/* Information start */
|
||||
void *fdt;
|
||||
|
||||
/* Only root can use */
|
||||
struct fdt_reserve_entry *rsvmap;
|
||||
rt_size_t rsvmap_nr;
|
||||
};
|
||||
|
||||
struct alias_info
|
||||
{
|
||||
rt_list_t list;
|
||||
|
||||
int id;
|
||||
const char *tag;
|
||||
rt_size_t tag_len;
|
||||
|
||||
struct rt_ofw_node *np;
|
||||
};
|
||||
|
||||
struct bus_ranges
|
||||
{
|
||||
rt_size_t nr;
|
||||
|
||||
rt_uint64_t *child_addr;
|
||||
rt_uint64_t *parent_addr;
|
||||
rt_uint64_t *child_size;
|
||||
};
|
||||
|
||||
extern struct rt_ofw_node *ofw_node_root;
|
||||
extern struct rt_ofw_node *ofw_node_cpus;
|
||||
extern struct rt_ofw_node *ofw_node_chosen;
|
||||
extern struct rt_ofw_node *ofw_node_aliases;
|
||||
extern struct rt_ofw_node *ofw_node_reserved_memory;
|
||||
|
||||
extern struct rt_fdt_earlycon fdt_earlycon;
|
||||
|
||||
#define ofw_static_cast(to_type, value) \
|
||||
(to_type)(((value) >> ((sizeof(value) - sizeof(to_type)) * 8)))
|
||||
|
||||
rt_err_t ofw_alias_scan(void);
|
||||
rt_err_t ofw_phandle_hash_reset(rt_phandle min, rt_phandle max);
|
||||
|
||||
#endif /* __OFW_INTERNAL_H__ */
|
||||
Executable
+197
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-10-19 GuEe-GUI first version
|
||||
*/
|
||||
|
||||
#include <drivers/ofw_raw.h>
|
||||
|
||||
int fdt_add_subnode_possible(void *fdt, int parentoffset, const char *name)
|
||||
{
|
||||
int nodeoffset;
|
||||
|
||||
if ((nodeoffset = fdt_add_subnode(fdt, parentoffset, name)) < 0)
|
||||
{
|
||||
fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + FDT_PADDING_SIZE);
|
||||
nodeoffset = fdt_add_subnode(fdt, parentoffset, name);
|
||||
}
|
||||
|
||||
return nodeoffset;
|
||||
}
|
||||
|
||||
int fdt_add_mem_rsv_possible(void *fdt, size_t addr, size_t size)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (fdt_add_mem_rsv(fdt, addr, size) < 0)
|
||||
{
|
||||
fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + FDT_PADDING_SIZE);
|
||||
err = fdt_add_mem_rsv(fdt, addr, size);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int fdt_setprop_uxx(void *fdt, int nodeoffset, const char *name, uint64_t val, bool is_u64)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (is_u64)
|
||||
{
|
||||
err = fdt_setprop_u64(fdt, nodeoffset, name, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = fdt_setprop_u32(fdt, nodeoffset, name, (uint32_t)val);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#define FDT_RAW_GET_VAL_FLAG(std_type, s, sz) \
|
||||
int fdt_getprop_##std_type##sz(void *fdt, int nodeoffset, \
|
||||
const char *name, s##int##sz##_t *out_value, int *lenp) \
|
||||
{ \
|
||||
int err = -FDT_ERR_NOTFOUND; \
|
||||
if (fdt && nodeoffset >= 0 && name && out_value) \
|
||||
{ \
|
||||
const fdt##sz##_t *ptr; \
|
||||
if ((ptr = fdt_getprop(fdt, nodeoffset, name, lenp))) \
|
||||
{ \
|
||||
*out_value = fdt##sz##_to_cpu(*ptr); \
|
||||
err = 0; \
|
||||
} \
|
||||
} \
|
||||
return err; \
|
||||
}
|
||||
|
||||
#define FDT_RAW_GET_VAL(size) \
|
||||
FDT_RAW_GET_VAL_FLAG(u, u, size) \
|
||||
FDT_RAW_GET_VAL_FLAG(s, , size)
|
||||
|
||||
FDT_RAW_GET_VAL(64)
|
||||
FDT_RAW_GET_VAL(32)
|
||||
FDT_RAW_GET_VAL(16)
|
||||
FDT_RAW_GET_VAL(8)
|
||||
|
||||
#undef FDT_RAW_GET_VAL
|
||||
#undef FDT_RAW_GET_VAL_FLAG
|
||||
|
||||
int fdt_io_addr_cells(void *fdt, int nodeoffset)
|
||||
{
|
||||
int cells = -1;
|
||||
int parentoffset = fdt_parent_offset(fdt, nodeoffset);
|
||||
|
||||
for (; parentoffset >= 0 ; parentoffset = fdt_parent_offset(fdt, parentoffset))
|
||||
{
|
||||
const fdt32_t *cells_tmp = fdt_getprop(fdt, parentoffset, "#address-cells", NULL);
|
||||
|
||||
if (cells_tmp)
|
||||
{
|
||||
cells = fdt32_to_cpu(*cells_tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (cells < 0)
|
||||
{
|
||||
cells = fdt_address_cells(fdt, nodeoffset);
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
int fdt_io_size_cells(void *fdt, int nodeoffset)
|
||||
{
|
||||
int cells = -1;
|
||||
int parentoffset = fdt_parent_offset(fdt, nodeoffset);
|
||||
|
||||
for (; parentoffset >= 0 ; parentoffset = fdt_parent_offset(fdt, parentoffset))
|
||||
{
|
||||
const fdt32_t *cells_tmp = fdt_getprop(fdt, parentoffset, "#size-cells", NULL);
|
||||
|
||||
if (cells_tmp)
|
||||
{
|
||||
cells = fdt32_to_cpu(*cells_tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (cells < 0)
|
||||
{
|
||||
cells = fdt_size_cells(fdt, nodeoffset);
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
int fdt_install_initrd(void *fdt, char *os_name, size_t initrd_addr, size_t initrd_size)
|
||||
{
|
||||
int err = -FDT_ERR_NOTFOUND;
|
||||
int chosen_offset = -1, root_off = fdt_path_offset(fdt, "/");
|
||||
|
||||
if (root_off >= 0)
|
||||
{
|
||||
chosen_offset = fdt_subnode_offset(fdt, root_off, "chosen");
|
||||
|
||||
if (chosen_offset == -FDT_ERR_NOTFOUND)
|
||||
{
|
||||
chosen_offset = fdt_add_subnode_possible(fdt, root_off, "chosen");
|
||||
}
|
||||
}
|
||||
|
||||
if (chosen_offset >= 0)
|
||||
{
|
||||
uint64_t addr, size;
|
||||
|
||||
err = 0;
|
||||
|
||||
/* Update the entry */
|
||||
for (int i = fdt_num_mem_rsv(fdt) - 1; i >= 0; --i)
|
||||
{
|
||||
fdt_get_mem_rsv(fdt, i, &addr, &size);
|
||||
|
||||
if (addr == initrd_addr)
|
||||
{
|
||||
fdt_del_mem_rsv(fdt, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the memory */
|
||||
if (fdt_add_mem_rsv(fdt, initrd_addr, initrd_size) < 0)
|
||||
{
|
||||
/* Move the memory */
|
||||
fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + FDT_PADDING_SIZE);
|
||||
|
||||
if (fdt_add_mem_rsv(fdt, initrd_addr, initrd_size) < 0)
|
||||
{
|
||||
err = -FDT_ERR_NOSPACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!err)
|
||||
{
|
||||
size_t name_len;
|
||||
char initrd_name[64];
|
||||
bool is_u64 = (fdt_io_addr_cells(fdt, root_off) == 2);
|
||||
|
||||
if (!os_name)
|
||||
{
|
||||
os_name = "rt-thread";
|
||||
}
|
||||
|
||||
name_len = strlen(initrd_name);
|
||||
|
||||
strncpy(&initrd_name[name_len], ",initrd-start", sizeof(initrd_name) - name_len);
|
||||
fdt_setprop_uxx(fdt, chosen_offset, initrd_name, initrd_addr, is_u64);
|
||||
|
||||
strncpy(&initrd_name[name_len], ",initrd-end", sizeof(initrd_name) - name_len);
|
||||
fdt_setprop_uxx(fdt, chosen_offset, initrd_name, initrd_addr + initrd_size, is_u64);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
menuconfig RT_USING_PIC
|
||||
bool "Using Programmable Interrupt Controller (PIC)"
|
||||
select RT_USING_BITMAP
|
||||
depends on RT_USING_DM
|
||||
default n
|
||||
|
||||
config MAX_HANDLERS
|
||||
int "IRQ max handlers"
|
||||
depends on RT_USING_PIC
|
||||
range 1 4294967294
|
||||
default 256
|
||||
@@ -0,0 +1,15 @@
|
||||
from building import *
|
||||
|
||||
group = []
|
||||
|
||||
if not GetDepend(['RT_USING_PIC']):
|
||||
Return('group')
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd + '/../include']
|
||||
|
||||
src = ['pic.c']
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -216,15 +216,11 @@ config RT_USING_VAR_EXPORT
|
||||
bool "Enable Var Export"
|
||||
default n
|
||||
|
||||
config RT_USING_ADT
|
||||
bool "Enable ADT(abstract data type), such as AVL tree"
|
||||
default y if ARCH_MM_MMU
|
||||
default n
|
||||
|
||||
config RT_USING_RESOURCE_ID
|
||||
bool "Enable resource id"
|
||||
default n
|
||||
|
||||
source "$RTT_DIR/components/utilities/libadt/Kconfig"
|
||||
source "$RTT_DIR/components/utilities/rt-link/Kconfig"
|
||||
|
||||
endmenu
|
||||
Reference in new issue
Block a user