Skip to content

Commit b823dfc

Browse files
committed
arch: microblaze: add MicroBlaze arch headers
Internal references: FWRIVERHD-4554 Signed-off-by: Alp Sayin <alpsayin@gmail.com>
1 parent 97c2e33 commit b823dfc

File tree

6 files changed

+457
-0
lines changed

6 files changed

+457
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD)
3+
* Copyright (c) 2023 Alp Sayin <alpsayin@gmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
9+
10+
/**
11+
* @file
12+
* @brief Private kernel definitions
13+
*
14+
* This file contains private kernel structures definitions and various
15+
* other definitions for the MIPS processor architecture.
16+
*/
17+
18+
#ifndef ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_DATA_H_
19+
#define ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_DATA_H_
20+
21+
#include <zephyr/arch/cpu.h>
22+
#include <zephyr/toolchain.h>
23+
24+
#ifndef _ASMLANGUAGE
25+
#include <zephyr/kernel.h>
26+
#include <zephyr/sys/dlist.h>
27+
#include <zephyr/sys/util.h>
28+
#include <zephyr/types.h>
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif /* _ASMLANGUAGE */
39+
40+
#endif /* ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_DATA_H_ */
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD)
3+
* Copyright (c) 2023 Alp Sayin <alpsayin@gmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
9+
/**
10+
* @file
11+
* @brief Private kernel definitions
12+
*
13+
* This file contains private kernel function/macro definitions and various
14+
* other definitions for the MIPS processor architecture.
15+
*/
16+
17+
#ifndef ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_FUNC_H_
18+
#define ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_FUNC_H_
19+
20+
#include <kernel_arch_data.h>
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
#ifndef _ASMLANGUAGE
27+
static ALWAYS_INLINE void arch_kernel_init(void)
28+
{
29+
}
30+
31+
static ALWAYS_INLINE void arch_thread_return_value_set(struct k_thread *thread, unsigned int value)
32+
{
33+
thread->callee_saved.retval = value;
34+
}
35+
36+
FUNC_NORETURN void z_microblaze_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
37+
38+
static inline bool arch_is_in_isr(void)
39+
{
40+
return _kernel.cpus[0].nested != 0U;
41+
}
42+
43+
#ifdef CONFIG_IRQ_OFFLOAD
44+
void z_irq_do_offload(void);
45+
#endif
46+
47+
#endif /* _ASMLANGUAGE */
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#endif /* ZEPHYR_ARCH_MICROBLAZE_INCLUDE_KERNEL_ARCH_FUNC_H_ */

include/zephyr/arch/microblaze/arch.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD)
3+
* Copyright (c) 2023 Alp Sayin <alpsayin@gmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
9+
10+
#ifndef ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_H_
11+
#define ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_H_
12+
13+
#include <zephyr/arch/common/ffs.h>
14+
#include <zephyr/arch/microblaze/exp.h>
15+
#include <zephyr/arch/microblaze/sys_bitops.h>
16+
#include <zephyr/arch/microblaze/sys_io.h>
17+
#include <zephyr/arch/microblaze/thread.h>
18+
#include <zephyr/devicetree.h>
19+
#include <zephyr/irq.h>
20+
#include <zephyr/sw_isr_table.h>
21+
22+
#include <microblaze/emulate_isr.h>
23+
#include <microblaze/mb_interface.h>
24+
#include <microblaze/microblaze_asm.h>
25+
#include <microblaze/microblaze_regs.h>
26+
27+
#define ARCH_STACK_PTR_ALIGN 16
28+
29+
#ifndef _ASMLANGUAGE
30+
#include <zephyr/sys/util.h>
31+
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
35+
36+
#define STACK_ROUND_UP(x) ROUND_UP(x, ARCH_STACK_PTR_ALIGN)
37+
38+
uint32_t arch_irq_pending(void);
39+
void arch_irq_enable(unsigned int irq);
40+
void arch_irq_disable(unsigned int irq);
41+
int arch_irq_is_enabled(unsigned int irq);
42+
uint32_t arch_irq_set_emulated_pending(uint32_t irq);
43+
uint32_t arch_irq_pending_vector(uint32_t irq_pending);
44+
void z_irq_spurious(const void *unused);
45+
46+
/**
47+
* Normally used to configure a static interrupt.
48+
* Barebones microblaze has 1 interrupt to offer so we connect
49+
* whatever isr & param supplied to that. SoCs should use this
50+
* macro to connect a single device (can be the AXI interrupt controller)
51+
* to the microblaze's only ISR to eventually make it call XIntc_DeviceInterruptHandler.
52+
*
53+
* @param irq_p IRQ line number
54+
* @param priority_p Interrupt priority
55+
* @param isr_p Interrupt service routine
56+
* @param isr_param_p ISR parameter
57+
* @param flags_p IRQ options
58+
*
59+
* @return The vector assigned to this interrupt
60+
*/
61+
#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
62+
{ \
63+
Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
64+
}
65+
66+
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
67+
{
68+
const uint32_t unshifted_msr_ie_status = mfmsr() & MSR_IE_MASK;
69+
70+
if (unshifted_msr_ie_status) {
71+
extern void microblaze_disable_interrupts(void);
72+
microblaze_disable_interrupts();
73+
return 1;
74+
}
75+
return 0;
76+
}
77+
78+
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
79+
{
80+
if (key) {
81+
extern void microblaze_enable_interrupts(void);
82+
microblaze_enable_interrupts();
83+
}
84+
}
85+
86+
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
87+
{
88+
return key != 0;
89+
}
90+
91+
static ALWAYS_INLINE void arch_nop(void)
92+
{
93+
__asm__ volatile("nop");
94+
}
95+
96+
extern uint32_t sys_clock_cycle_get_32(void);
97+
98+
static inline uint32_t arch_k_cycle_get_32(void)
99+
{
100+
return sys_clock_cycle_get_32();
101+
}
102+
103+
extern uint64_t sys_clock_cycle_get_64(void);
104+
105+
static inline uint64_t arch_k_cycle_get_64(void)
106+
{
107+
return sys_clock_cycle_get_64();
108+
}
109+
110+
#ifdef __cplusplus
111+
}
112+
#endif
113+
114+
#endif /* _ASMLANGUAGE */
115+
116+
#endif /* ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_H_ */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD)
3+
* Copyright (c) 2023 Alp Sayin <alpsayin@gmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
9+
#ifndef ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_INLINES_H
10+
#define ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_INLINES_H
11+
12+
#include <zephyr/kernel_structs.h>
13+
#include <zephyr/devicetree.h>
14+
15+
#define _CPU DT_PATH(cpus, cpu_0)
16+
17+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
18+
{
19+
return CONFIG_MP_MAX_NUM_CPUS;
20+
}
21+
22+
static inline uint32_t arch_get_cpu_clock_frequency(void)
23+
{
24+
return DT_PROP_OR(_CPU, clock_frequency, 0);
25+
}
26+
27+
#endif /* ZEPHYR_INCLUDE_ARCH_MICROBLAZE_ARCH_INLINES_H */
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD)
3+
* Copyright (c) 2023 Alp Sayin <alpsayin@gmail.com>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
9+
/* Memory bits manipulation functions in non-arch-specific C code */
10+
11+
#ifndef ZEPHYR_INCLUDE_ARCH_MICROBLAZE_SYS_BITOPS_H_
12+
#define ZEPHYR_INCLUDE_ARCH_MICROBLAZE_SYS_BITOPS_H_
13+
14+
#ifndef _ASMLANGUAGE
15+
16+
#include <zephyr/sys/sys_io.h>
17+
#include <zephyr/toolchain.h>
18+
#include <zephyr/types.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit)
25+
{
26+
compiler_barrier();
27+
uint32_t temp = *(volatile uint32_t *)addr;
28+
*(volatile uint32_t *)addr = temp | (1 << bit);
29+
compiler_barrier();
30+
}
31+
32+
static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit)
33+
{
34+
compiler_barrier();
35+
uint32_t temp = *(volatile uint32_t *)addr;
36+
*(volatile uint32_t *)addr = temp & ~(1 << bit);
37+
compiler_barrier();
38+
}
39+
40+
static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
41+
{
42+
uint32_t temp;
43+
44+
compiler_barrier();
45+
temp = *(volatile uint32_t *)addr;
46+
compiler_barrier();
47+
48+
return temp & (1 << bit);
49+
}
50+
51+
static ALWAYS_INLINE void sys_set_bits(mem_addr_t addr, unsigned int mask)
52+
{
53+
compiler_barrier();
54+
uint32_t temp = *(volatile uint32_t *)addr;
55+
*(volatile uint32_t *)addr = temp | mask;
56+
compiler_barrier();
57+
}
58+
59+
static ALWAYS_INLINE void sys_clear_bits(mem_addr_t addr, unsigned int mask)
60+
{
61+
compiler_barrier();
62+
uint32_t temp = *(volatile uint32_t *)addr;
63+
*(volatile uint32_t *)addr = temp & ~mask;
64+
compiler_barrier();
65+
}
66+
67+
static ALWAYS_INLINE void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
68+
{
69+
/* Doing memory offsets in terms of 32-bit values to prevent
70+
* alignment issues
71+
*/
72+
sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
73+
}
74+
75+
static ALWAYS_INLINE void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
76+
{
77+
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
78+
}
79+
80+
static ALWAYS_INLINE int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
81+
{
82+
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
83+
}
84+
85+
static ALWAYS_INLINE int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
86+
{
87+
int ret;
88+
89+
ret = sys_test_bit(addr, bit);
90+
sys_set_bit(addr, bit);
91+
92+
return ret;
93+
}
94+
95+
static ALWAYS_INLINE int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
96+
{
97+
int ret;
98+
99+
ret = sys_test_bit(addr, bit);
100+
sys_clear_bit(addr, bit);
101+
102+
return ret;
103+
}
104+
105+
static ALWAYS_INLINE int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
106+
{
107+
int ret;
108+
109+
ret = sys_bitfield_test_bit(addr, bit);
110+
sys_bitfield_set_bit(addr, bit);
111+
112+
return ret;
113+
}
114+
115+
static ALWAYS_INLINE int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
116+
{
117+
int ret;
118+
119+
ret = sys_bitfield_test_bit(addr, bit);
120+
sys_bitfield_clear_bit(addr, bit);
121+
122+
return ret;
123+
}
124+
125+
#ifdef __cplusplus
126+
}
127+
#endif
128+
129+
#endif /* _ASMLANGUAGE */
130+
131+
#endif /* ZEPHYR_INCLUDE_ARCH_MICROBLAZE_SYS_BITOPS_H_ */

0 commit comments

Comments
 (0)