Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | /* * Copyright (c) 2017, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL CORPORATION OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "qm_common.h" #include "qm_interrupt.h" #include "idt.h" #if (HAS_APIC) #include "apic.h" #elif(HAS_MVIC) #include "mvic.h" #elif(QM_SENSOR) #include "qm_ss_interrupt.h" #include "qm_sensor_regs.h" extern qm_ss_isr_t __ivt_vect_table[]; static void ss_register_irq(unsigned int vector); #else #error "Unsupported / unspecified processor detected." #endif /* x86 CPU FLAGS.IF register field (Interrupt enable Flag, bit 9), indicating * whether or not CPU interrupts are enabled. */ #define X86_FLAGS_IF BIT(9) void qm_irq_disable(void) { #if (QM_SENSOR) qm_ss_irq_disable(); #else __asm__ __volatile__("cli"); #endif } void qm_irq_enable(void) { #if (QM_SENSOR) qm_ss_irq_enable(); #else __asm__ __volatile__("sti"); #endif } #if (QM_SENSOR) unsigned int qm_irq_lock(void) { unsigned int key = 0; /* * Store the ARC STATUS32 register fields relating to interrupts into * the variable `key' and disable interrupt delivery to the core. */ __asm__ __volatile__("clri %0" : "=r"(key)); return key; } void qm_irq_unlock(unsigned int key) { /* * Restore the ARC STATUS32 register fields relating to interrupts based * on the variable `key' populated by qm_irq_lock(). */ __asm__ __volatile__("seti %0" : : "ir"(key)); } #else /* x86 */ unsigned int qm_irq_lock(void) { unsigned int key = 0; /* * Store the CPU FLAGS register into the variable `key' and disable * interrupt delivery to the core. */ __asm__ __volatile__("pushfl;\n\t" "cli;\n\t" "popl %0;\n\t" : "=g"(key) : : "memory"); return key; } void qm_irq_unlock(unsigned int key) { /* * `key' holds the CPU FLAGS register content at the time when * qm_irq_lock() was called. */ if (!(key & X86_FLAGS_IF)) { /* * Interrupts were disabled when qm_irq_lock() was invoked: * do not re-enable interrupts. */ return; } /* Enable interrupts */ __asm__ __volatile__("sti;\n\t" : :); } #endif /* QM_SENSOR */ void qm_irq_mask(uint32_t irq) { #if (HAS_APIC) ioapic_mask_irq(irq); #elif(HAS_MVIC) mvic_mask_irq(irq); #elif(QM_SENSOR) qm_ss_irq_mask(irq); #endif } void qm_irq_unmask(uint32_t irq) { #if (HAS_APIC) ioapic_unmask_irq(irq); #elif(HAS_MVIC) mvic_unmask_irq(irq); #elif(QM_SENSOR) qm_ss_irq_unmask(irq); #endif } #if (ENABLE_RESTORE_CONTEXT) #if (HAS_APIC) int qm_irq_save_context(qm_irq_context_t *const ctx) { uint32_t rte_low; uint8_t irq; QM_CHECK(ctx != NULL, -EINVAL); for (irq = 0; irq < QM_IOAPIC_NUM_RTES; irq++) { rte_low = _ioapic_get_redtbl_entry_lo(irq); ctx->redtbl_entries[irq] = rte_low; } return 0; } int qm_irq_restore_context(const qm_irq_context_t *const ctx) { uint32_t rte_low; uint8_t irq; QM_CHECK(ctx != NULL, -EINVAL); apic_init(); for (irq = 0; irq < QM_IOAPIC_NUM_RTES; irq++) { rte_low = ctx->redtbl_entries[irq]; _ioapic_set_redtbl_entry_lo(irq, rte_low); } return 0; } #elif(QM_SENSOR) /* HAS_APIC */ int qm_irq_save_context(qm_irq_context_t *const ctx) { uint8_t i; uint32_t status32; QM_CHECK(ctx != NULL, -EINVAL); /* Interrupts from 0 to 15 are exceptions and they are ignored * by IRQ auxiliary registers. For that reason we skip those * values in this loop. */ for (i = 0; i < (QM_SS_INT_VECTOR_NUM - QM_SS_EXCEPTION_NUM); i++) { __builtin_arc_sr(i + QM_SS_EXCEPTION_NUM, QM_SS_AUX_IRQ_SELECT); ctx->irq_config[i] = __builtin_arc_lr(QM_SS_AUX_IRQ_PRIORITY) << 2; ctx->irq_config[i] |= __builtin_arc_lr(QM_SS_AUX_IRQ_TRIGGER) << 1; ctx->irq_config[i] |= __builtin_arc_lr(QM_SS_AUX_IRQ_ENABLE); } status32 = __builtin_arc_lr(QM_SS_AUX_STATUS32); ctx->status32_irq_threshold = status32 & QM_SS_STATUS32_E_MASK; ctx->status32_irq_enable = status32 & QM_SS_STATUS32_IE_MASK; ctx->irq_ctrl = __builtin_arc_lr(QM_SS_AUX_IRQ_CTRL); return 0; } int qm_irq_restore_context(const qm_irq_context_t *const ctx) { uint8_t i; uint32_t reg; QM_CHECK(ctx != NULL, -EINVAL); for (i = 0; i < (QM_SS_INT_VECTOR_NUM - QM_SS_EXCEPTION_NUM); i++) { __builtin_arc_sr(i + QM_SS_EXCEPTION_NUM, QM_SS_AUX_IRQ_SELECT); __builtin_arc_sr(ctx->irq_config[i] >> 2, QM_SS_AUX_IRQ_PRIORITY); __builtin_arc_sr((ctx->irq_config[i] >> 1) & BIT(0), QM_SS_AUX_IRQ_TRIGGER); __builtin_arc_sr(ctx->irq_config[i] & BIT(0), QM_SS_AUX_IRQ_ENABLE); } __builtin_arc_sr(ctx->irq_ctrl, QM_SS_AUX_IRQ_CTRL); /* Setting an interrupt priority threshold. */ reg = __builtin_arc_lr(QM_SS_AUX_STATUS32); reg |= (ctx->status32_irq_threshold & QM_SS_STATUS32_E_MASK); reg |= (ctx->status32_irq_enable & QM_SS_STATUS32_IE_MASK); /* This one has to be a kernel operation. */ __builtin_arc_kflag(reg); return 0; } #endif /* QM_SENSOR */ #else /* !ENABLE_RESTORE_CONTEXT */ int qm_irq_save_context(qm_irq_context_t *const ctx) { (void)ctx; return 0; } int qm_irq_restore_context(const qm_irq_context_t *const ctx) { (void)ctx; return 0; } #endif /* ENABLE_RESTORE_CONTEXT */ void _qm_irq_setup(uint32_t irq) { #if (HAS_APIC) /* * Quark SE SOC has an APIC. Other SoCs uses a simple, fixed-vector * non-8259 PIC that requires no configuration. */ ioapic_register_irq(irq, QM_IRQ_TO_VECTOR(irq)); ioapic_unmask_irq(irq); #elif(HAS_MVIC) mvic_register_irq(irq); mvic_unmask_irq(irq); #elif(QM_SENSOR) ss_register_irq(QM_IRQ_TO_VECTOR(irq)); qm_ss_irq_unmask(QM_IRQ_TO_VECTOR(irq)); #endif } /* * Register an Interrupt Service Routine to a given interrupt vector. * * @param[in] vector Interrupt Vector number. * @param[in] isr ISR to register to given vector. Must be a valid x86 ISR. * If this can't be provided, QM_IRQ_REQUEST() or * qm_int_vector_request() should be used instead. */ void _qm_register_isr(uint32_t vector, qm_isr_t isr) { #if (QM_SENSOR) /* Invalidate the i-cache line which contains the IRQ vector. This * will bypass i-cache and set vector with the good ISR. */ __builtin_arc_sr((uint32_t)&__ivt_vect_table[0] + (vector * 4), QM_SS_AUX_IC_IVIL); /* All SR accesses to the IC_IVIL register must be followed by three * NOP instructions, see chapter 3.3.59 in the datasheet * "ARC_V2_ProgrammersReference.pdf" */ __builtin_arc_nop(); __builtin_arc_nop(); __builtin_arc_nop(); __ivt_vect_table[vector] = isr; #else idt_set_intr_gate_desc(vector, (uint32_t)isr); #endif } #if (QM_SENSOR) static void ss_register_irq(unsigned int vector) { /* * By hardware power-on default, SS interrupts are level triggered. * The following switch statement sets some of the peripherals to edge * triggered. */ switch (vector) { case QM_SS_IRQ_ADC_0_PWR_INT_VECTOR: case QM_IRQ_RTC_0_INT_VECTOR: case QM_IRQ_AONPT_0_INT_VECTOR: case QM_IRQ_WDT_0_INT_VECTOR: /* Edge sensitive. */ __builtin_arc_sr(vector, QM_SS_AUX_IRQ_SELECT); __builtin_arc_sr(QM_SS_IRQ_EDGE_SENSITIVE, QM_SS_AUX_IRQ_TRIGGER); } } #endif |