|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Advanced Micro Devices, Inc. (AMD) |
| 3 | + * Copyright (c) 2023 Alp Sayin <[email protected]> |
| 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_ */ |
0 commit comments