Line data Source code
1 1 : /*
2 : * Copyright (c) 2020 Antony Pavlov <antonynpavlov@gmail.com>
3 : *
4 : * based on include/arch/sparc/arch.h
5 : *
6 : * SPDX-License-Identifier: Apache-2.0
7 : */
8 :
9 : /**
10 : * @file
11 : * @brief MIPS specific kernel interface header
12 : *
13 : * This header contains the MIPS specific kernel interface. It is
14 : * included by the kernel interface architecture-abstraction header
15 : * (include/zephyr/arch/cpu.h).
16 : */
17 :
18 : #ifndef ZEPHYR_INCLUDE_ARCH_MIPS_ARCH_H_
19 : #define ZEPHYR_INCLUDE_ARCH_MIPS_ARCH_H_
20 :
21 : #include <zephyr/arch/mips/thread.h>
22 : #include <zephyr/arch/exception.h>
23 : #include <zephyr/arch/common/sys_bitops.h>
24 : #include <zephyr/arch/common/sys_io.h>
25 : #include <zephyr/arch/common/ffs.h>
26 :
27 : #include <zephyr/irq.h>
28 : #include <zephyr/sw_isr_table.h>
29 : #include <zephyr/devicetree.h>
30 : #include <mips/mipsregs.h>
31 :
32 0 : #define ARCH_STACK_PTR_ALIGN 16
33 :
34 0 : #define OP_LOADREG lw
35 0 : #define OP_STOREREG sw
36 :
37 0 : #define CP0_STATUS_DEF_RESTORE (ST0_EXL | ST0_IE)
38 :
39 : #ifndef _ASMLANGUAGE
40 : #include <zephyr/sys/util.h>
41 :
42 : #ifdef __cplusplus
43 : extern "C" {
44 : #endif
45 :
46 0 : #define STACK_ROUND_UP(x) ROUND_UP(x, ARCH_STACK_PTR_ALIGN)
47 :
48 0 : void arch_irq_enable(unsigned int irq);
49 0 : void arch_irq_disable(unsigned int irq);
50 0 : int arch_irq_is_enabled(unsigned int irq);
51 : void z_irq_spurious(const void *unused);
52 :
53 : /**
54 : * Configure a static interrupt.
55 : *
56 : * All arguments must be computable by the compiler at build time.
57 : *
58 : * @param irq_p IRQ line number
59 : * @param priority_p Interrupt priority
60 : * @param isr_p Interrupt service routine
61 : * @param isr_param_p ISR parameter
62 : * @param flags_p IRQ options
63 : *
64 : * @return The vector assigned to this interrupt
65 : */
66 :
67 1 : #define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
68 : { \
69 : Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
70 : }
71 :
72 0 : static ALWAYS_INLINE unsigned int arch_irq_lock(void)
73 : {
74 : uint32_t status = read_c0_status();
75 :
76 : if (status & ST0_IE) {
77 : write_c0_status(status & ~ST0_IE);
78 : return 1;
79 : }
80 : return 0;
81 : }
82 :
83 0 : static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
84 : {
85 : uint32_t status = read_c0_status();
86 :
87 : if (key) {
88 : status |= ST0_IE;
89 : } else {
90 : status &= ~ST0_IE;
91 : }
92 :
93 : write_c0_status(status);
94 : }
95 :
96 0 : static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
97 : {
98 : return key != 0;
99 : }
100 :
101 0 : static ALWAYS_INLINE void arch_nop(void)
102 : {
103 : __asm__ volatile ("nop");
104 : }
105 :
106 0 : extern uint32_t sys_clock_cycle_get_32(void);
107 :
108 0 : static inline uint32_t arch_k_cycle_get_32(void)
109 : {
110 : return sys_clock_cycle_get_32();
111 : }
112 :
113 0 : extern uint64_t sys_clock_cycle_get_64(void);
114 :
115 0 : static inline uint64_t arch_k_cycle_get_64(void)
116 : {
117 : return sys_clock_cycle_get_64();
118 : }
119 :
120 : #ifdef __cplusplus
121 : }
122 : #endif
123 :
124 : #endif /* _ASMLANGUAGE */
125 :
126 : #endif /* ZEPHYR_INCLUDE_ARCH_MIPS_ARCH_H_ */
|