From 6eaffed22e9b36ae505570588cfcec5f2eeab1a2 Mon Sep 17 00:00:00 2001 From: wusongjie Date: Mon, 31 Jul 2023 09:40:44 +0800 Subject: [PATCH 1/4] Fixup:Arch Kconfig empty in MCU Only x86, ARM, ARM64, RISC-V SoC have Arch Kconfig. Clear the title default. Link: https://github.com/RT-Thread/rt-thread/pull/7831 Signed-off-by: GuEe-GUI --- libcpu/Kconfig | 8 +++----- libcpu/aarch64/Kconfig | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libcpu/Kconfig b/libcpu/Kconfig index 897ce605553..35a3d080377 100644 --- a/libcpu/Kconfig +++ b/libcpu/Kconfig @@ -1,5 +1,3 @@ -menu "RT-Thread Architecture" - config ARCH_CPU_64BIT bool @@ -234,6 +232,6 @@ config ARCH_CPU_STACK_GROWS_UPWARD bool default n -source "$RTT_DIR/libcpu/aarch64/Kconfig" - -endmenu +if ARCH_ARMV8 && ARCH_CPU_64BIT + source "$RTT_DIR/libcpu/aarch64/Kconfig" +endif diff --git a/libcpu/aarch64/Kconfig b/libcpu/aarch64/Kconfig index 4bb9f1ffe7c..ac280832b45 100644 --- a/libcpu/aarch64/Kconfig +++ b/libcpu/aarch64/Kconfig @@ -1,4 +1,4 @@ -if ARCH_ARMV8 && ARCH_CPU_64BIT +menu "AArch64 Architecture Configuration" config ARCH_TEXT_OFFSET hex "Text offset" @@ -16,4 +16,4 @@ config ARCH_HAVE_EFFICIENT_UNALIGNED_ACCESS bool default y -endif +endmenu From 918951a172549965f1cb5ba0b5ea6c15a8c40a3e Mon Sep 17 00:00:00 2001 From: wusongjie Date: Mon, 31 Jul 2023 10:28:40 +0800 Subject: [PATCH 2/4] AArch64:cpuport:replace rt_inline with macros rt_inline is not GNU's attribute `always_inline`, but macros could do it, we defined `rt_hw_barrier` and add cpu_releax api for memory access polling in device drivers. Signed-off-by: GuEe-GUI --- libcpu/aarch64/common/cpuport.h | 38 ++++++++++++--------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/libcpu/aarch64/common/cpuport.h b/libcpu/aarch64/common/cpuport.h index 12719c4531c..2fe6afb2b97 100644 --- a/libcpu/aarch64/common/cpuport.h +++ b/libcpu/aarch64/common/cpuport.h @@ -23,30 +23,20 @@ typedef union { } rt_hw_spinlock_t; #endif -rt_inline void rt_hw_isb(void) -{ - __asm__ volatile ("isb":::"memory"); -} - -rt_inline void rt_hw_dmb(void) -{ - __asm__ volatile ("dmb ish":::"memory"); -} - -rt_inline void rt_hw_wmb(void) -{ - __asm__ volatile ("dmb ishst":::"memory"); -} - -rt_inline void rt_hw_rmb(void) -{ - __asm__ volatile ("dmb ishld":::"memory"); -} - -rt_inline void rt_hw_dsb(void) -{ - __asm__ volatile ("dsb ish":::"memory"); -} +#define rt_hw_barrier(cmd, ...) \ + __asm__ volatile (RT_STRINGIFY(cmd) " "RT_STRINGIFY(__VA_ARGS__):::"memory") + +#define rt_hw_isb() rt_hw_barrier(isb) +#define rt_hw_dmb() rt_hw_barrier(dmb, ish) +#define rt_hw_wmb() rt_hw_barrier(dmb, ishst) +#define rt_hw_rmb() rt_hw_barrier(dmb, ishld) +#define rt_hw_dsb() rt_hw_barrier(dsb, ish) + +#define rt_hw_wfi() rt_hw_barrier(wfi) +#define rt_hw_wfe() rt_hw_barrier(wfe) +#define rt_hw_sev() rt_hw_barrier(sev) + +#define rt_hw_cpu_relax() rt_hw_barrier(yield) void _thread_start(void); #endif /*CPUPORT_H__*/ From 1268f9ef82a8e21bbb0092224ca3af1b849edfad Mon Sep 17 00:00:00 2001 From: wusongjie Date: Mon, 31 Jul 2023 10:49:49 +0800 Subject: [PATCH 3/4] Components:MM:add early map api 1.The earlycon in dm needs ioremap in early initialization such as uart mmio. 2.Add name member in rt_region_t that user could know what's mean of a memory region. Signed-off-by: GuEe-GUI --- components/mm/ioremap.c | 10 ++++++++++ components/mm/ioremap.h | 1 + components/mm/mm_page.h | 2 ++ libcpu/aarch64/common/mmu.c | 25 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/components/mm/ioremap.c b/components/mm/ioremap.c index 04f09fdbaf9..5d31185e578 100644 --- a/components/mm/ioremap.c +++ b/components/mm/ioremap.c @@ -76,6 +76,16 @@ static void *_ioremap_type(void *paddr, size_t size, enum ioremap_type type) return v_addr; } +rt_weak void *rt_ioremap_early(void *paddr, size_t size) +{ + if (!size) + { + return RT_NULL; + } + + return paddr; +} + void *rt_ioremap(void *paddr, size_t size) { return _ioremap_type(paddr, size, MM_AREA_TYPE_PHY); diff --git a/components/mm/ioremap.h b/components/mm/ioremap.h index 7ac9d196a9c..f17b5d5fff7 100644 --- a/components/mm/ioremap.h +++ b/components/mm/ioremap.h @@ -30,6 +30,7 @@ extern "C" { * | Currently as non-cacheable */ +void *rt_ioremap_early(void *paddr, size_t size); void *rt_ioremap(void *paddr, size_t size); void *rt_ioremap_nocache(void *paddr, size_t size); void *rt_ioremap_cached(void *paddr, size_t size); diff --git a/components/mm/mm_page.h b/components/mm/mm_page.h index 99cb5a804ed..a0171d6672d 100644 --- a/components/mm/mm_page.h +++ b/components/mm/mm_page.h @@ -63,6 +63,8 @@ typedef struct tag_region { rt_size_t start; rt_size_t end; + + const char *name; } rt_region_t; extern const rt_size_t rt_mpr_size; diff --git a/libcpu/aarch64/common/mmu.c b/libcpu/aarch64/common/mmu.c index 88df1f89ffb..cd38d74ef3a 100644 --- a/libcpu/aarch64/common/mmu.c +++ b/libcpu/aarch64/common/mmu.c @@ -590,6 +590,31 @@ static int _map_single_page_2M(unsigned long *lv0_tbl, unsigned long va, return 0; } +void *rt_ioremap_early(void *paddr, size_t size) +{ + size_t count; + static void *tbl = RT_NULL; + + if (!size) + { + return RT_NULL; + } + + if (!tbl) + { + tbl = rt_hw_mmu_tbl_get(); + } + + count = (size + ARCH_SECTION_MASK) >> ARCH_SECTION_SHIFT; + + while (count --> 0) + { + _map_single_page_2M(tbl, (unsigned long)paddr, (unsigned long)paddr, MMU_MAP_K_DEVICE); + } + + return paddr; +} + static int _init_map_2M(unsigned long *lv0_tbl, unsigned long va, unsigned long pa, unsigned long count, unsigned long attr) From aad6f0612bb030ba609e1f0cd3f1f06e82280e60 Mon Sep 17 00:00:00 2001 From: wusongjie Date: Tue, 1 Aug 2023 08:41:08 +0800 Subject: [PATCH 4/4] Drivers:OFW:replace new rt_str* to string.h Now, we only use STD string if possible. Signed-off-by: GuEe-GUI --- components/drivers/ofw/base.c | 7 ++++--- components/drivers/ofw/fdt.c | 9 +++++---- components/drivers/ofw/irq.c | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/drivers/ofw/base.c b/components/drivers/ofw/base.c index 63f6d2702e1..6f8f20e806a 100644 --- a/components/drivers/ofw/base.c +++ b/components/drivers/ofw/base.c @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -249,7 +250,7 @@ rt_bool_t rt_ofw_node_tag_equ(const struct rt_ofw_node *np, const char *tag) if (np && tag) { const char *node_name = rt_fdt_node_name(np->full_name); - rt_size_t tag_len = rt_strchrnul(node_name, '@') - node_name; + rt_size_t tag_len = strchrnul(node_name, '@') - node_name; ret = (rt_strlen(tag) == tag_len && !rt_strncmp(node_name, tag, tag_len)); } @@ -569,7 +570,7 @@ struct rt_ofw_node *rt_ofw_find_node_by_ids_r(struct rt_ofw_node *from, const st struct rt_ofw_node *rt_ofw_find_node_by_path(const char *path) { - struct rt_ofw_node *np, *parent, *tmp; + struct rt_ofw_node *np = RT_NULL, *parent, *tmp = RT_NULL; if (path) { @@ -584,7 +585,7 @@ struct rt_ofw_node *rt_ofw_find_node_by_path(const char *path) while (*path) { - const char *next = rt_strchrnul(path, '/'); + const char *next = strchrnul(path, '/'); rt_size_t len = next - path; tmp = RT_NULL; diff --git a/components/drivers/ofw/fdt.c b/components/drivers/ofw/fdt.c index 1d3388e79d5..d64feec9cd2 100755 --- a/components/drivers/ofw/fdt.c +++ b/components/drivers/ofw/fdt.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,7 @@ static rt_size_t _root_addr_cells; const char *rt_fdt_node_name(const char *full_name) { - const char *node_name = rt_strrchr(full_name, '/'); + const char *node_name = strrchr(full_name, '/'); return node_name ? node_name + 1 : full_name; } @@ -701,7 +702,7 @@ rt_err_t rt_fdt_scan_chosen_stdout(void) if (stdout_path && len) { - const char *path_split = rt_strchrnul(stdout_path, ':'); + const char *path_split = strchrnul(stdout_path, ':'); if (*path_split != '\0') { @@ -780,13 +781,13 @@ rt_err_t rt_fdt_scan_chosen_stdout(void) if (*options) { - type_len = rt_strchrnul(options, ',') - options; + type_len = strchrnul(options, ',') - options; } } if (options && *options && *options != ' ') { - options_len = rt_strchrnul(options, ' ') - options; + options_len = strchrnul(options, ' ') - options; } /* console > stdout-path */ diff --git a/components/drivers/ofw/irq.c b/components/drivers/ofw/irq.c index 69ac3b3d5e1..97483d8a5ea 100755 --- a/components/drivers/ofw/irq.c +++ b/components/drivers/ofw/irq.c @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -130,7 +131,7 @@ static rt_err_t ofw_parse_irq_map(struct rt_ofw_node *np, struct rt_ofw_cell_arg * <0x1800 0 0 4 &gic 0 0 GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>; // INTD * }; * - * In fact, basically no SoC will be use multi ic to implemented INTx. + * In fact, almost no SoC will be use multi IC to implement INTx. * before call ofw_parse_irq_map(np, &args): * * args.data = addr;