-add support for the bcm2835 family (-36 variant in this case) -add target and project for raspberry pi 2
239 lines
7.2 KiB
C
239 lines
7.2 KiB
C
/*
|
|
* Copyright (c) 2015 Travis Geiselbrecht
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
#include <trace.h>
|
|
#include <assert.h>
|
|
#include <err.h>
|
|
#include <bits.h>
|
|
#include <arch/arm.h>
|
|
#include <kernel/spinlock.h>
|
|
#include <kernel/thread.h>
|
|
#include <platform/interrupts.h>
|
|
#include <platform/bcm2835.h>
|
|
|
|
#define LOCAL_TRACE 0
|
|
|
|
/* global interrupt controller */
|
|
#define INTC_PEND0 (ARMCTRL_INTC_BASE + 0x0)
|
|
#define INTC_PEND1 (ARMCTRL_INTC_BASE + 0x4)
|
|
#define INTC_PEND2 (ARMCTRL_INTC_BASE + 0x8)
|
|
#define INTC_FAST (ARMCTRL_INTC_BASE + 0xc)
|
|
#define INTC_ENABLE1 (ARMCTRL_INTC_BASE + 0x10)
|
|
#define INTC_ENABLE2 (ARMCTRL_INTC_BASE + 0x14)
|
|
#define INTC_ENABLE3 (ARMCTRL_INTC_BASE + 0x18)
|
|
#define INTC_DISABLE1 (ARMCTRL_INTC_BASE + 0x1c)
|
|
#define INTC_DISABLE2 (ARMCTRL_INTC_BASE + 0x20)
|
|
#define INTC_DISABLE3 (ARMCTRL_INTC_BASE + 0x24)
|
|
|
|
/* per-cpu local interrupt controller bits.
|
|
* each is repeated 4 times, one per cpu.
|
|
*/
|
|
#define INTC_LOCAL_TIMER_INT_CONTROL0 (ARM_LOCAL_BASE + 0x40)
|
|
#define INTC_LOCAL_TIMER_INT_CONTROL1 (ARM_LOCAL_BASE + 0x44)
|
|
#define INTC_LOCAL_TIMER_INT_CONTROL2 (ARM_LOCAL_BASE + 0x48)
|
|
#define INTC_LOCAL_TIMER_INT_CONTROL3 (ARM_LOCAL_BASE + 0x4c)
|
|
|
|
#define INTC_LOCAL_MAILBOX_INT_CONTROL0 (ARM_LOCAL_BASE + 0x40)
|
|
#define INTC_LOCAL_MAILBOX_INT_CONTROL1 (ARM_LOCAL_BASE + 0x44)
|
|
#define INTC_LOCAL_MAILBOX_INT_CONTROL2 (ARM_LOCAL_BASE + 0x48)
|
|
#define INTC_LOCAL_MAILBOX_INT_CONTROL3 (ARM_LOCAL_BASE + 0x4c)
|
|
|
|
#define INTC_LOCAL_IRQ_PEND0 (ARM_LOCAL_BASE + 0x60)
|
|
#define INTC_LOCAL_IRQ_PEND1 (ARM_LOCAL_BASE + 0x64)
|
|
#define INTC_LOCAL_IRQ_PEND2 (ARM_LOCAL_BASE + 0x68)
|
|
#define INTC_LOCAL_IRQ_PEND3 (ARM_LOCAL_BASE + 0x6c)
|
|
|
|
#define INTC_LOCAL_FIQ_PEND0 (ARM_LOCAL_BASE + 0x70)
|
|
#define INTC_LOCAL_FIQ_PEND1 (ARM_LOCAL_BASE + 0x74)
|
|
#define INTC_LOCAL_FIQ_PEND2 (ARM_LOCAL_BASE + 0x78)
|
|
#define INTC_LOCAL_FIQ_PEND3 (ARM_LOCAL_BASE + 0x7c)
|
|
|
|
struct int_handler_struct {
|
|
int_handler handler;
|
|
void *arg;
|
|
};
|
|
|
|
static struct int_handler_struct int_handler_table[MAX_INT][SMP_MAX_CPUS];
|
|
|
|
static spin_lock_t lock = SPIN_LOCK_INITIAL_VALUE;
|
|
|
|
status_t mask_interrupt(unsigned int vector)
|
|
{
|
|
LTRACEF("vector %u\n", vector);
|
|
|
|
spin_lock_saved_state_t state;
|
|
spin_lock_irqsave(&lock, state);
|
|
|
|
if (vector >= INTERRUPT_ARM_LOCAL_CNTPSIRQ && vector <= INTERRUPT_ARM_LOCAL_CNTVIRQ) {
|
|
// local timer interrupts
|
|
uint cpu = arch_curr_cpu_num();
|
|
uintptr_t reg = INTC_LOCAL_TIMER_INT_CONTROL0 + cpu * 4;
|
|
|
|
*REG32(reg) &= (1 << (vector - INTERRUPT_ARM_LOCAL_CNTPSIRQ));
|
|
} else if (/* vector >= ARM_IRQ1_BASE && */ vector < (ARM_IRQ0_BASE + 32)) {
|
|
uintptr_t reg;
|
|
if (vector >= ARM_IRQ0_BASE)
|
|
reg = INTC_DISABLE3;
|
|
else if (vector >= ARM_IRQ2_BASE)
|
|
reg = INTC_DISABLE2;
|
|
else
|
|
reg = INTC_DISABLE1;
|
|
|
|
*REG32(reg) = 1 << (vector % 32);
|
|
} else {
|
|
PANIC_UNIMPLEMENTED;
|
|
}
|
|
|
|
spin_unlock_irqrestore(&lock, state);
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
status_t unmask_interrupt(unsigned int vector)
|
|
{
|
|
LTRACEF("vector %u\n", vector);
|
|
|
|
spin_lock_saved_state_t state;
|
|
spin_lock_irqsave(&lock, state);
|
|
|
|
if (vector >= INTERRUPT_ARM_LOCAL_CNTPSIRQ && vector <= INTERRUPT_ARM_LOCAL_CNTVIRQ) {
|
|
// local timer interrupts
|
|
uint cpu = arch_curr_cpu_num();
|
|
uintptr_t reg = INTC_LOCAL_TIMER_INT_CONTROL0 + cpu * 4;
|
|
|
|
*REG32(reg) |= (1 << (vector - INTERRUPT_ARM_LOCAL_CNTPSIRQ));
|
|
} else if (/* vector >= ARM_IRQ1_BASE && */ vector < (ARM_IRQ0_BASE + 32)) {
|
|
uintptr_t reg;
|
|
if (vector >= ARM_IRQ0_BASE)
|
|
reg = INTC_ENABLE3;
|
|
else if (vector >= ARM_IRQ2_BASE)
|
|
reg = INTC_ENABLE2;
|
|
else
|
|
reg = INTC_ENABLE1;
|
|
|
|
*REG32(reg) = 1 << (vector % 32);
|
|
} else {
|
|
PANIC_UNIMPLEMENTED;
|
|
}
|
|
|
|
spin_unlock_irqrestore(&lock, state);
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
void register_int_handler(unsigned int vector, int_handler handler, void *arg)
|
|
{
|
|
uint cpu = arch_curr_cpu_num();
|
|
|
|
if (vector >= MAX_INT)
|
|
panic("register_int_handler: vector out of range %d\n", vector);
|
|
|
|
spin_lock_saved_state_t state;
|
|
spin_lock_irqsave(&lock, state);
|
|
|
|
int_handler_table[vector][cpu].handler = handler;
|
|
int_handler_table[vector][cpu].arg = arg;
|
|
|
|
spin_unlock_irqrestore(&lock, state);
|
|
}
|
|
|
|
enum handler_return platform_irq(struct arm_iframe *frame)
|
|
{
|
|
uint vector;
|
|
uint cpu = arch_curr_cpu_num();
|
|
|
|
THREAD_STATS_INC(interrupts);
|
|
|
|
// see what kind of irq it is
|
|
uint32_t pend = *REG32(INTC_LOCAL_IRQ_PEND0 + cpu * 4);
|
|
|
|
pend &= ~(1 << (INTERRUPT_ARM_LOCAL_GPU_FAST % 32)); // mask out gpu interrupts
|
|
|
|
if (pend != 0) {
|
|
// it's a local interrupt
|
|
LTRACEF("local pend 0x%x\n", pend);
|
|
vector = ARM_IRQ_LOCAL_BASE + ctz(pend);
|
|
goto decoded;
|
|
}
|
|
|
|
// XXX disable for now, since all of the interesting irqs are mirrored into the other banks
|
|
#if 0
|
|
// look in bank 0 (ARM interrupts)
|
|
pend = *REG32(INTC_PEND0);
|
|
LTRACEF("pend0 0x%x\n", pend);
|
|
pend &= ~((1<<8)|(1<<9)); // mask out bit 8 and 9
|
|
if (pend != 0) {
|
|
// it's a bank 0 interrupt
|
|
vector = ARM_IRQ0_BASE + ctz(pend);
|
|
goto decoded;
|
|
}
|
|
#endif
|
|
|
|
// look for VC interrupt bank 1
|
|
pend = *REG32(INTC_PEND1);
|
|
LTRACEF("pend1 0x%x\n", pend);
|
|
if (pend != 0) {
|
|
// it's a bank 1 interrupt
|
|
vector = ARM_IRQ1_BASE + ctz(pend);
|
|
goto decoded;
|
|
}
|
|
|
|
// look for VC interrupt bank 2
|
|
pend = *REG32(INTC_PEND2);
|
|
LTRACEF("pend2 0x%x\n", pend);
|
|
if (pend != 0) {
|
|
// it's a bank 2 interrupt
|
|
vector = ARM_IRQ2_BASE + ctz(pend);
|
|
goto decoded;
|
|
}
|
|
|
|
vector = 0xffffffff;
|
|
|
|
decoded:
|
|
LTRACEF("vector %u\n", vector);
|
|
|
|
// dispatch the irq
|
|
enum handler_return ret = INT_NO_RESCHEDULE;
|
|
if (int_handler_table[vector][cpu].handler) {
|
|
ret = int_handler_table[vector][cpu].handler(int_handler_table[vector][cpu].arg);
|
|
} else {
|
|
panic("irq %u fired on cpu %u but no handler set!\n", vector, cpu);
|
|
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
enum handler_return platform_fiq(struct arm_iframe *frame)
|
|
{
|
|
PANIC_UNIMPLEMENTED;
|
|
}
|
|
|
|
void intc_init(void)
|
|
{
|
|
// mask everything
|
|
*REG32(INTC_DISABLE1) = 0xffffffff;
|
|
*REG32(INTC_DISABLE2) = 0xffffffff;
|
|
*REG32(INTC_DISABLE3) = 0xffffffff;
|
|
}
|
|
|