1 | /*
|
---|
2 | * TOPPERS/SSP Kernel
|
---|
3 | * Smallest Set Profile Kernel
|
---|
4 | *
|
---|
5 | * Copyright (C) 2013-2015 by Embedded and Real-Time Systems Laboratory
|
---|
6 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
7 | * Copyright (C) 2018 by Naoki Saito
|
---|
8 | * Nagoya Municipal Industrial Research Institute, JAPAN
|
---|
9 | *
|
---|
10 | * ä¸è¨èä½æ¨©è
|
---|
11 | ã¯ï¼ä»¥ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
12 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
13 | * å¤ã»åé
|
---|
14 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
28 | * ã¨ï¼
|
---|
29 | * (a) åé
|
---|
30 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
31 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
32 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
33 | * (b) åé
|
---|
34 | å¸ã®å½¢æ
|
---|
35 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
36 | * å ±åãããã¨ï¼
|
---|
37 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
38 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
39 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
40 | 責ãããã¨ï¼
|
---|
41 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
42 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
43 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
44 | * å
|
---|
45 | 責ãããã¨ï¼
|
---|
46 | *
|
---|
47 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
48 | ã
|
---|
49 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
50 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
51 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
52 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
53 | *
|
---|
54 | * $Id$
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * ã¿ã¤ããã©ã¤ãï¼Generic Timerï¼
|
---|
59 | */
|
---|
60 | #include "kernel_impl.h"
|
---|
61 | #include "time_event.h"
|
---|
62 | #include "target_timer.h"
|
---|
63 | #include <sil.h>
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * ä»®æ³ã¿ã¤ãã®å¶å¾¡ã¬ã¸ã¹ã¿ããã®èªã¿åºã
|
---|
67 | */
|
---|
68 | Inline uint64_t
|
---|
69 | clock_read_ctrl(void) {
|
---|
70 | uint64_t cntv_ctrl;
|
---|
71 |
|
---|
72 | Asm ("isb; mrs %0, cntv_ctl_el0; isb;"
|
---|
73 | : "=r"(cntv_ctrl) :: "memory");
|
---|
74 |
|
---|
75 | return cntv_ctrl;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * ä»®æ³ã¿ã¤ãã®å¶å¾¡ã¬ã¸ã¹ã¿ã¸ã®æ¸ãè¾¼ã¿
|
---|
80 | */
|
---|
81 | Inline void
|
---|
82 | clock_write_ctrl(uint64_t cntv_ctrl) {
|
---|
83 |
|
---|
84 | Asm ("isb; msr cntv_ctl_el0, %0; isb;"
|
---|
85 | :: "r"(cntv_ctrl) : "memory");
|
---|
86 | return ;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * ä»®æ³ã¿ã¤ã(ããªã¼ã«ã¦ã³ã¿)ã®ã«ã¦ã³ãå¤ã®èªã¿åºã
|
---|
91 | */
|
---|
92 | Inline uint64_t
|
---|
93 | clock_read_counter(void){
|
---|
94 | uint64_t cval;
|
---|
95 |
|
---|
96 | Asm ("mrs %0, cntvct_el0" : "=r" (cval));
|
---|
97 |
|
---|
98 | return cval;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * ä»®æ³ã¿ã¤ãã®å¤ã®èªã¿åºã
|
---|
103 | */
|
---|
104 | Inline uint64_t
|
---|
105 | clock_read_tval(void){
|
---|
106 | uint64_t cntv_tval;
|
---|
107 |
|
---|
108 | Asm ("isb; mrs %0, cntv_tval_el0; isb;" : "=r"(cntv_tval)
|
---|
109 | :: "memory");
|
---|
110 | return cntv_tval;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * ä»®æ³ã¿ã¤ãã®å¤ã®æ¸ãè¾¼ã¿
|
---|
115 | */
|
---|
116 | Inline void
|
---|
117 | clock_write_tval(uint64_t cntv_tval){
|
---|
118 |
|
---|
119 | Asm ("isb; msr cntv_tval_el0, %0; isb;" :: "r"(cntv_tval)
|
---|
120 | : "memory");
|
---|
121 | }
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * ã·ã¹ãã ã«ã¦ã³ã¿ã®ã¯ããã¯å¨æ³¢æ°ã®åå¾
|
---|
125 | */
|
---|
126 | Inline uint64_t
|
---|
127 | get_timer_freq(void) {
|
---|
128 | uint64_t freq_hz;
|
---|
129 |
|
---|
130 | Asm ("mrs %0, cntfrq_el0; isb; " : "=r"(freq_hz) :: "memory");
|
---|
131 | return freq_hz;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /*
|
---|
135 | * ã¿ã¤ãã®éå§
|
---|
136 | */
|
---|
137 | static void
|
---|
138 | target_timer_start(void)
|
---|
139 | {
|
---|
140 | uint64_t cntv_ctl;
|
---|
141 |
|
---|
142 | cntv_ctl = clock_read_ctrl();
|
---|
143 | cntv_ctl |= ( CNTV_CTL_ENABLE | CNTV_CTL_START );
|
---|
144 | cntv_ctl &= ~CNTV_CTL_MASK; //mask
|
---|
145 | clock_write_ctrl(cntv_ctl);
|
---|
146 | }
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * ã¿ã¤ãã®åæ¢
|
---|
150 | */
|
---|
151 | static void
|
---|
152 | target_timer_stop(void)
|
---|
153 | {
|
---|
154 | uint64_t cntv_ctl;
|
---|
155 |
|
---|
156 | cntv_ctl = clock_read_ctrl();
|
---|
157 | cntv_ctl &= ~( CNTV_CTL_ENABLE | CNTV_CTL_START );
|
---|
158 | cntv_ctl |= CNTV_CTL_MASK;
|
---|
159 | clock_write_ctrl(cntv_ctl);
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * ã¿ã¤ãå²è¾¼ã¿è¦æ±ã®ã¯ãªã¢
|
---|
164 | */
|
---|
165 | static void
|
---|
166 | target_timer_int_clear(void){
|
---|
167 |
|
---|
168 | gicd_clear_pending(INTNO_TIMER);
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * 次ã®ã¿ã¤ãå²è¾¼ã¿çºçã¾ã§ã®ãªãã»ãã
|
---|
173 | */
|
---|
174 | static uint64_t next_tval;
|
---|
175 |
|
---|
176 | /*
|
---|
177 | * ã¿ã¤ãã®èµ·åå¦ç
|
---|
178 | */
|
---|
179 | void
|
---|
180 | target_timer_initialize(intptr_t exinf)
|
---|
181 | {
|
---|
182 | target_timer_stop();
|
---|
183 | target_timer_int_clear();
|
---|
184 |
|
---|
185 | // 次åã®ã¿ã¤ãå²è¾¼ã¿çºçã¾ã§ã®ãªãã»ããç®åº
|
---|
186 | next_tval = get_timer_freq() * 1000 / 1000000UL; /* 1ms */
|
---|
187 | clock_write_tval(next_tval);
|
---|
188 |
|
---|
189 | target_timer_start();
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * ã¿ã¤ãã®åæ¢å¦ç
|
---|
194 | */
|
---|
195 | void
|
---|
196 | target_timer_terminate(intptr_t exinf)
|
---|
197 | {
|
---|
198 | target_timer_stop();
|
---|
199 | }
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * ã¿ã¤ãå²è¾¼ã¿ãã³ãã©
|
---|
203 | */
|
---|
204 | void
|
---|
205 | target_timer_handler(void)
|
---|
206 | {
|
---|
207 | target_timer_stop();
|
---|
208 | target_timer_int_clear();
|
---|
209 | clock_write_tval(next_tval); // 次åã®å²è¾¼ã¿
|
---|
210 | target_timer_start();
|
---|
211 |
|
---|
212 | i_begin_int(INTNO_TIMER);
|
---|
213 | signal_time();
|
---|
214 | i_end_int(INTNO_TIMER);
|
---|
215 | }
|
---|