Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2015, Wind River Systems, Inc. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Anas Nashif | 275ca60 | 2015-12-04 10:09:39 -0500 | [diff] [blame] | 7 | /** |
Anas Nashif | 476a823 | 2015-09-07 08:22:55 -0400 | [diff] [blame] | 8 | * @file |
| 9 | * @brief system module for variants with LOAPIC |
| 10 | * |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 11 | */ |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 12 | |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame] | 13 | #include <zephyr/sys/__assert.h> |
| 14 | #include <zephyr/kernel.h> |
| 15 | #include <zephyr/arch/cpu.h> |
| 16 | #include <zephyr/drivers/interrupt_controller/ioapic.h> |
| 17 | #include <zephyr/drivers/interrupt_controller/loapic.h> |
| 18 | #include <zephyr/drivers/interrupt_controller/sysapic.h> |
| 19 | #include <zephyr/irq.h> |
| 20 | #include <zephyr/linker/sections.h> |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 21 | |
frei tycho | caf332e | 2024-05-16 14:21:16 +0000 | [diff] [blame] | 22 | #define IS_IOAPIC_IRQ(irq) ((irq) < z_loapic_irq_base()) |
Tomasz Bursztyka | 915f4ac | 2021-03-09 19:54:42 +0100 | [diff] [blame] | 23 | #define HARDWARE_IRQ_LIMIT ((z_loapic_irq_base() + LOAPIC_IRQ_COUNT) - 1) |
Anas Nashif | 7625b09 | 2015-07-02 18:59:02 -0400 | [diff] [blame] | 24 | |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 25 | /** |
Anas Nashif | f367f07 | 2015-07-01 17:51:40 -0400 | [diff] [blame] | 26 | * @brief Program interrupt controller |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 27 | * |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 28 | * This routine programs the interrupt controller with the given vector |
| 29 | * based on the given IRQ parameter. |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 30 | * |
Andrew Boie | 897ffae | 2016-01-27 10:07:31 -0800 | [diff] [blame] | 31 | * Drivers call this routine instead of IRQ_CONNECT() when interrupts are |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 32 | * configured statically. |
| 33 | * |
Dmitriy Korovkin | f142051 | 2015-11-02 18:06:08 -0500 | [diff] [blame] | 34 | * The Galileo board virtualizes IRQs as follows: |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 35 | * |
Tomasz Bursztyka | 915f4ac | 2021-03-09 19:54:42 +0100 | [diff] [blame] | 36 | * - The first z_ioapic_num_rtes() IRQs are provided by the IOAPIC so the |
Peter Mitsis | dbaa4a4 | 2015-07-28 14:39:12 -0400 | [diff] [blame] | 37 | * IOAPIC is programmed for these IRQs |
Anas Nashif | f367f07 | 2015-07-01 17:51:40 -0400 | [diff] [blame] | 38 | * - The remaining IRQs are provided by the LOAPIC and hence the LOAPIC is |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 39 | * programmed. |
Dan Kalowsky | 3a109b1 | 2015-10-20 09:42:33 -0700 | [diff] [blame] | 40 | * |
| 41 | * @param vector the vector number |
| 42 | * @param irq the virtualized IRQ |
Dmitriy Korovkin | f142051 | 2015-11-02 18:06:08 -0500 | [diff] [blame] | 43 | * @param flags interrupt flags |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 44 | */ |
Daniel Leung | 08d6386 | 2021-03-17 13:49:39 -0700 | [diff] [blame] | 45 | __boot_func |
Charles E. Youse | 0325a3d | 2019-06-28 13:06:37 -0700 | [diff] [blame] | 46 | void z_irq_controller_irq_config(unsigned int vector, unsigned int irq, |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 47 | uint32_t flags) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 48 | { |
Leandro Pereira | d9538ec | 2018-02-16 17:20:32 -0800 | [diff] [blame] | 49 | __ASSERT(irq <= HARDWARE_IRQ_LIMIT, "invalid irq line"); |
Andrew Boie | e98ac23 | 2016-08-02 12:05:08 -0700 | [diff] [blame] | 50 | |
Anas Nashif | 7625b09 | 2015-07-02 18:59:02 -0400 | [diff] [blame] | 51 | if (IS_IOAPIC_IRQ(irq)) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 52 | z_ioapic_irq_set(irq, vector, flags); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 53 | } else { |
Tomasz Bursztyka | 915f4ac | 2021-03-09 19:54:42 +0100 | [diff] [blame] | 54 | z_loapic_int_vec_set(irq - z_loapic_irq_base(), vector); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 58 | /** |
Anas Nashif | f367f07 | 2015-07-01 17:51:40 -0400 | [diff] [blame] | 59 | * @brief Enable an individual interrupt (IRQ) |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 60 | * |
| 61 | * The public interface for enabling/disabling a specific IRQ for the IA-32 |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 62 | * architecture is defined as follows in include/arch/x86/arch.h |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 63 | * |
| 64 | * extern void irq_enable (unsigned int irq); |
| 65 | * extern void irq_disable (unsigned int irq); |
| 66 | * |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 67 | * The irq_enable() routine is provided by the interrupt controller driver due |
| 68 | * to the IRQ virtualization that is performed by this platform. See the |
Andrew Boie | e98ac23 | 2016-08-02 12:05:08 -0700 | [diff] [blame] | 69 | * comments in _interrupt_vector_allocate() for more information regarding IRQ |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 70 | * virtualization. |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 71 | */ |
Daniel Leung | 08d6386 | 2021-03-17 13:49:39 -0700 | [diff] [blame] | 72 | __pinned_func |
Andrew Boie | 4f77c2a | 2019-11-07 12:43:29 -0800 | [diff] [blame] | 73 | void arch_irq_enable(unsigned int irq) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 74 | { |
Anas Nashif | 7625b09 | 2015-07-02 18:59:02 -0400 | [diff] [blame] | 75 | if (IS_IOAPIC_IRQ(irq)) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 76 | z_ioapic_irq_enable(irq); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 77 | } else { |
Tomasz Bursztyka | 915f4ac | 2021-03-09 19:54:42 +0100 | [diff] [blame] | 78 | z_loapic_irq_enable(irq - z_loapic_irq_base()); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 82 | /** |
Anas Nashif | f367f07 | 2015-07-01 17:51:40 -0400 | [diff] [blame] | 83 | * @brief Disable an individual interrupt (IRQ) |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 84 | * |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 85 | * The irq_disable() routine is provided by the interrupt controller driver due |
| 86 | * to the IRQ virtualization that is performed by this platform. See the |
Andrew Boie | e98ac23 | 2016-08-02 12:05:08 -0700 | [diff] [blame] | 87 | * comments in _interrupt_vector_allocate() for more information regarding IRQ |
Peter Mitsis | 2a4a6cf | 2015-07-27 11:02:41 -0400 | [diff] [blame] | 88 | * virtualization. |
Anas Nashif | ea0d0b2 | 2015-07-01 17:22:39 -0400 | [diff] [blame] | 89 | */ |
Daniel Leung | 08d6386 | 2021-03-17 13:49:39 -0700 | [diff] [blame] | 90 | __pinned_func |
Andrew Boie | 4f77c2a | 2019-11-07 12:43:29 -0800 | [diff] [blame] | 91 | void arch_irq_disable(unsigned int irq) |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 92 | { |
Anas Nashif | 7625b09 | 2015-07-02 18:59:02 -0400 | [diff] [blame] | 93 | if (IS_IOAPIC_IRQ(irq)) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 94 | z_ioapic_irq_disable(irq); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 95 | } else { |
Tomasz Bursztyka | 915f4ac | 2021-03-09 19:54:42 +0100 | [diff] [blame] | 96 | z_loapic_irq_disable(irq - z_loapic_irq_base()); |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 97 | } |
| 98 | } |