blob: 6089e453405d6905bfa18f771f511f0ef369f37f [file] [log] [blame]
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -07001/*
2 * Copyright (c) 2013-2015, Wind River Systems, Inc.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -07005 */
6
Anas Nashif275ca602015-12-04 10:09:39 -05007/**
Anas Nashif476a8232015-09-07 08:22:55 -04008 * @file
9 * @brief system module for variants with LOAPIC
10 *
Anas Nashifea0d0b22015-07-01 17:22:39 -040011 */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070012
Gerard Marull-Paretasfb60aab2022-05-06 10:25:46 +020013#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-Gonzalez8ddf82c2015-04-10 16:44:37 -070021
frei tychocaf332e2024-05-16 14:21:16 +000022#define IS_IOAPIC_IRQ(irq) ((irq) < z_loapic_irq_base())
Tomasz Bursztyka915f4ac2021-03-09 19:54:42 +010023#define HARDWARE_IRQ_LIMIT ((z_loapic_irq_base() + LOAPIC_IRQ_COUNT) - 1)
Anas Nashif7625b092015-07-02 18:59:02 -040024
Anas Nashifea0d0b22015-07-01 17:22:39 -040025/**
Anas Nashiff367f072015-07-01 17:51:40 -040026 * @brief Program interrupt controller
Anas Nashifea0d0b22015-07-01 17:22:39 -040027 *
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040028 * This routine programs the interrupt controller with the given vector
29 * based on the given IRQ parameter.
Anas Nashifea0d0b22015-07-01 17:22:39 -040030 *
Andrew Boie897ffae2016-01-27 10:07:31 -080031 * Drivers call this routine instead of IRQ_CONNECT() when interrupts are
Anas Nashifea0d0b22015-07-01 17:22:39 -040032 * configured statically.
33 *
Dmitriy Korovkinf1420512015-11-02 18:06:08 -050034 * The Galileo board virtualizes IRQs as follows:
Anas Nashifea0d0b22015-07-01 17:22:39 -040035 *
Tomasz Bursztyka915f4ac2021-03-09 19:54:42 +010036 * - The first z_ioapic_num_rtes() IRQs are provided by the IOAPIC so the
Peter Mitsisdbaa4a42015-07-28 14:39:12 -040037 * IOAPIC is programmed for these IRQs
Anas Nashiff367f072015-07-01 17:51:40 -040038 * - The remaining IRQs are provided by the LOAPIC and hence the LOAPIC is
Anas Nashifea0d0b22015-07-01 17:22:39 -040039 * programmed.
Dan Kalowsky3a109b12015-10-20 09:42:33 -070040 *
41 * @param vector the vector number
42 * @param irq the virtualized IRQ
Dmitriy Korovkinf1420512015-11-02 18:06:08 -050043 * @param flags interrupt flags
Anas Nashifea0d0b22015-07-01 17:22:39 -040044 */
Daniel Leung08d63862021-03-17 13:49:39 -070045__boot_func
Charles E. Youse0325a3d2019-06-28 13:06:37 -070046void z_irq_controller_irq_config(unsigned int vector, unsigned int irq,
Kumar Galaa1b77fd2020-05-27 11:26:57 -050047 uint32_t flags)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070048{
Leandro Pereirad9538ec2018-02-16 17:20:32 -080049 __ASSERT(irq <= HARDWARE_IRQ_LIMIT, "invalid irq line");
Andrew Boiee98ac232016-08-02 12:05:08 -070050
Anas Nashif7625b092015-07-02 18:59:02 -040051 if (IS_IOAPIC_IRQ(irq)) {
Patrik Flykt4344e272019-03-08 14:19:05 -070052 z_ioapic_irq_set(irq, vector, flags);
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070053 } else {
Tomasz Bursztyka915f4ac2021-03-09 19:54:42 +010054 z_loapic_int_vec_set(irq - z_loapic_irq_base(), vector);
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070055 }
56}
57
Anas Nashifea0d0b22015-07-01 17:22:39 -040058/**
Anas Nashiff367f072015-07-01 17:51:40 -040059 * @brief Enable an individual interrupt (IRQ)
Anas Nashifea0d0b22015-07-01 17:22:39 -040060 *
61 * The public interface for enabling/disabling a specific IRQ for the IA-32
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040062 * architecture is defined as follows in include/arch/x86/arch.h
Anas Nashifea0d0b22015-07-01 17:22:39 -040063 *
64 * extern void irq_enable (unsigned int irq);
65 * extern void irq_disable (unsigned int irq);
66 *
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040067 * 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 Boiee98ac232016-08-02 12:05:08 -070069 * comments in _interrupt_vector_allocate() for more information regarding IRQ
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040070 * virtualization.
Anas Nashifea0d0b22015-07-01 17:22:39 -040071 */
Daniel Leung08d63862021-03-17 13:49:39 -070072__pinned_func
Andrew Boie4f77c2a2019-11-07 12:43:29 -080073void arch_irq_enable(unsigned int irq)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070074{
Anas Nashif7625b092015-07-02 18:59:02 -040075 if (IS_IOAPIC_IRQ(irq)) {
Patrik Flykt4344e272019-03-08 14:19:05 -070076 z_ioapic_irq_enable(irq);
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070077 } else {
Tomasz Bursztyka915f4ac2021-03-09 19:54:42 +010078 z_loapic_irq_enable(irq - z_loapic_irq_base());
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070079 }
80}
81
Anas Nashifea0d0b22015-07-01 17:22:39 -040082/**
Anas Nashiff367f072015-07-01 17:51:40 -040083 * @brief Disable an individual interrupt (IRQ)
Anas Nashifea0d0b22015-07-01 17:22:39 -040084 *
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040085 * 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 Boiee98ac232016-08-02 12:05:08 -070087 * comments in _interrupt_vector_allocate() for more information regarding IRQ
Peter Mitsis2a4a6cf2015-07-27 11:02:41 -040088 * virtualization.
Anas Nashifea0d0b22015-07-01 17:22:39 -040089 */
Daniel Leung08d63862021-03-17 13:49:39 -070090__pinned_func
Andrew Boie4f77c2a2019-11-07 12:43:29 -080091void arch_irq_disable(unsigned int irq)
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070092{
Anas Nashif7625b092015-07-02 18:59:02 -040093 if (IS_IOAPIC_IRQ(irq)) {
Patrik Flykt4344e272019-03-08 14:19:05 -070094 z_ioapic_irq_disable(irq);
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070095 } else {
Tomasz Bursztyka915f4ac2021-03-09 19:54:42 +010096 z_loapic_irq_disable(irq - z_loapic_irq_base());
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070097 }
98}