osd-contiki/cpu/x86/drivers/legacy_pc/shared-isr.c
Michael LeMay c815fa4511 x86: Use shared ISR for I2C and GPIO
This patch permits interrupts to be generated by both the I2C and GPIO
controllers for simultaneously-executing applications. The controllers
share a single interrupt pin, INTC. Prior to this patch,
quarkX1000_gpio_init() routed INTA to PIRQC and IRQ 10 (due to an
incorrect assumption that INTA is connected to the GPIO controller),
and quarkX1000_i2c_init() routed INTC to PIRQC and IRQ 9. The I2C
controller initialization is a prerequisite for GPIO initialization,
so the final configuration was that INTA and INTC were both routed to
PIRQC and IRQ 10. Thus, only the GPIO ISR was being invoked, even if
the I2C controller was actually responsible for the interrupt.

This patch refactors the I2C and GPIO ISR setup and handler code so
that the shared portions are combined in
cpu/x86/drivers/legacy_pc/shared-isr.[ch].  The I2C and GPIO drivers
communicate their interrupt information to the shared component by
placing structures in a specific section of the binary.
2016-02-16 21:19:44 -08:00

108 lines
3.6 KiB
C

/*
* Copyright (C) 2016, 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 copyright holder 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
* COPYRIGHT HOLDER 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 <assert.h>
#include "idt.h"
#include "interrupt.h"
#include "pic.h"
#include "shared-isr.h"
/* Defined in linker script */
extern shared_isr_client_t _sdata_shared_isr, _edata_shared_isr;
static void __attribute__((used))
shared_handler(void)
{
shared_isr_client_t *client;
for(client = &_sdata_shared_isr; client < &_edata_shared_isr; client++) {
if(client->handler()) {
pic_eoi(client->irq);
return;
}
}
}
/**
* \brief Initialize shared ISR by iterating through all of its clients and
* configuring their interrupts to route to the shared ISR.
*/
void
shared_isr_init(void)
{
shared_isr_client_t *client = &_sdata_shared_isr;
shared_isr_client_t *consistency_check_client;
bool prev_conf;
void shared_isr_stub(void);
__asm__ __volatile__ (
ISR_STUB("shared_isr_stub", 0, "shared_handler")
);
while(client < &_edata_shared_isr) {
consistency_check_client = &_sdata_shared_isr;
prev_conf = false;
while(consistency_check_client < client) {
if((client->irq == consistency_check_client->irq) ||
(client->pin == consistency_check_client->pin) ||
(client->pirq == consistency_check_client->pirq)) {
prev_conf = true;
/* This interrupt was previously configured. */
break;
}
consistency_check_client++;
}
if(prev_conf) {
/* The requested configurations for each IRQ must be consistent. */
assert((client->irq == consistency_check_client->irq) &&
(client->agent == consistency_check_client->agent) &&
(client->pin == consistency_check_client->pin) &&
(client->pirq == consistency_check_client->pirq));
} else {
idt_set_intr_gate_desc(PIC_INT(client->irq), (uint32_t)shared_isr_stub);
assert(pci_irq_agent_set_pirq(client->agent,
client->pin,
client->pirq) == 0);
pci_pirq_set_irq(client->pirq, client->irq, 1);
pic_unmask_irq(client->irq);
}
client++;
}
}