Path: blob/master/arch/powerpc/platforms/86xx/gef_pic.c
10818 views
/*1* Interrupt handling for GE FPGA based PIC2*3* Author: Martyn Welch <[email protected]>4*5* 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.6*7* This file is licensed under the terms of the GNU General Public License8* version 2. This program is licensed "as is" without any warranty of any9* kind, whether express or implied.10*/1112#include <linux/stddef.h>13#include <linux/kernel.h>14#include <linux/init.h>15#include <linux/irq.h>16#include <linux/interrupt.h>17#include <linux/spinlock.h>1819#include <asm/byteorder.h>20#include <asm/io.h>21#include <asm/prom.h>22#include <asm/irq.h>2324#include "gef_pic.h"2526#define DEBUG27#undef DEBUG2829#ifdef DEBUG30#define DBG(fmt...) do { printk(KERN_DEBUG "gef_pic: " fmt); } while (0)31#else32#define DBG(fmt...) do { } while (0)33#endif3435#define GEF_PIC_NUM_IRQS 323637/* Interrupt Controller Interface Registers */38#define GEF_PIC_INTR_STATUS 0x00003940#define GEF_PIC_INTR_MASK(cpu) (0x0010 + (0x4 * cpu))41#define GEF_PIC_CPU0_INTR_MASK GEF_PIC_INTR_MASK(0)42#define GEF_PIC_CPU1_INTR_MASK GEF_PIC_INTR_MASK(1)4344#define GEF_PIC_MCP_MASK(cpu) (0x0018 + (0x4 * cpu))45#define GEF_PIC_CPU0_MCP_MASK GEF_PIC_MCP_MASK(0)46#define GEF_PIC_CPU1_MCP_MASK GEF_PIC_MCP_MASK(1)474849static DEFINE_RAW_SPINLOCK(gef_pic_lock);5051static void __iomem *gef_pic_irq_reg_base;52static struct irq_host *gef_pic_irq_host;53static int gef_pic_cascade_irq;5455/*56* Interrupt Controller Handling57*58* The interrupt controller handles interrupts for most on board interrupts,59* apart from PCI interrupts. For example on SBC610:60*61* 17:31 RO Reserved62* 16 RO PCI Express Doorbell 3 Status63* 15 RO PCI Express Doorbell 2 Status64* 14 RO PCI Express Doorbell 1 Status65* 13 RO PCI Express Doorbell 0 Status66* 12 RO Real Time Clock Interrupt Status67* 11 RO Temperature Interrupt Status68* 10 RO Temperature Critical Interrupt Status69* 9 RO Ethernet PHY1 Interrupt Status70* 8 RO Ethernet PHY3 Interrupt Status71* 7 RO PEX8548 Interrupt Status72* 6 RO Reserved73* 5 RO Watchdog 0 Interrupt Status74* 4 RO Watchdog 1 Interrupt Status75* 3 RO AXIS Message FIFO A Interrupt Status76* 2 RO AXIS Message FIFO B Interrupt Status77* 1 RO AXIS Message FIFO C Interrupt Status78* 0 RO AXIS Message FIFO D Interrupt Status79*80* Interrupts can be forwarded to one of two output lines. Nothing81* clever is done, so if the masks are incorrectly set, a single input82* interrupt could generate interrupts on both output lines!83*84* The dual lines are there to allow the chained interrupts to be easily85* passed into two different cores. We currently do not use this functionality86* in this driver.87*88* Controller can also be configured to generate Machine checks (MCP), again on89* two lines, to be attached to two different cores. It is suggested that these90* should be masked out.91*/9293void gef_pic_cascade(unsigned int irq, struct irq_desc *desc)94{95struct irq_chip *chip = irq_desc_get_chip(desc);96unsigned int cascade_irq;9798/*99* See if we actually have an interrupt, call generic handling code if100* we do.101*/102cascade_irq = gef_pic_get_irq();103104if (cascade_irq != NO_IRQ)105generic_handle_irq(cascade_irq);106107chip->irq_eoi(&desc->irq_data);108}109110static void gef_pic_mask(struct irq_data *d)111{112unsigned long flags;113unsigned int hwirq = irqd_to_hwirq(d);114u32 mask;115116raw_spin_lock_irqsave(&gef_pic_lock, flags);117mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));118mask &= ~(1 << hwirq);119out_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0), mask);120raw_spin_unlock_irqrestore(&gef_pic_lock, flags);121}122123static void gef_pic_mask_ack(struct irq_data *d)124{125/* Don't think we actually have to do anything to ack an interrupt,126* we just need to clear down the devices interrupt and it will go away127*/128gef_pic_mask(d);129}130131static void gef_pic_unmask(struct irq_data *d)132{133unsigned long flags;134unsigned int hwirq = irqd_to_hwirq(d);135u32 mask;136137raw_spin_lock_irqsave(&gef_pic_lock, flags);138mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));139mask |= (1 << hwirq);140out_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0), mask);141raw_spin_unlock_irqrestore(&gef_pic_lock, flags);142}143144static struct irq_chip gef_pic_chip = {145.name = "gefp",146.irq_mask = gef_pic_mask,147.irq_mask_ack = gef_pic_mask_ack,148.irq_unmask = gef_pic_unmask,149};150151152/* When an interrupt is being configured, this call allows some flexibilty153* in deciding which irq_chip structure is used154*/155static int gef_pic_host_map(struct irq_host *h, unsigned int virq,156irq_hw_number_t hwirq)157{158/* All interrupts are LEVEL sensitive */159irq_set_status_flags(virq, IRQ_LEVEL);160irq_set_chip_and_handler(virq, &gef_pic_chip, handle_level_irq);161162return 0;163}164165static int gef_pic_host_xlate(struct irq_host *h, struct device_node *ct,166const u32 *intspec, unsigned int intsize,167irq_hw_number_t *out_hwirq, unsigned int *out_flags)168{169170*out_hwirq = intspec[0];171if (intsize > 1)172*out_flags = intspec[1];173else174*out_flags = IRQ_TYPE_LEVEL_HIGH;175176return 0;177}178179static struct irq_host_ops gef_pic_host_ops = {180.map = gef_pic_host_map,181.xlate = gef_pic_host_xlate,182};183184185/*186* Initialisation of PIC, this should be called in BSP187*/188void __init gef_pic_init(struct device_node *np)189{190unsigned long flags;191192/* Map the devices registers into memory */193gef_pic_irq_reg_base = of_iomap(np, 0);194195raw_spin_lock_irqsave(&gef_pic_lock, flags);196197/* Initialise everything as masked. */198out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU0_INTR_MASK, 0);199out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU1_INTR_MASK, 0);200201out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU0_MCP_MASK, 0);202out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU1_MCP_MASK, 0);203204raw_spin_unlock_irqrestore(&gef_pic_lock, flags);205206/* Map controller */207gef_pic_cascade_irq = irq_of_parse_and_map(np, 0);208if (gef_pic_cascade_irq == NO_IRQ) {209printk(KERN_ERR "SBC610: failed to map cascade interrupt");210return;211}212213/* Setup an irq_host structure */214gef_pic_irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR,215GEF_PIC_NUM_IRQS,216&gef_pic_host_ops, NO_IRQ);217if (gef_pic_irq_host == NULL)218return;219220/* Chain with parent controller */221irq_set_chained_handler(gef_pic_cascade_irq, gef_pic_cascade);222}223224/*225* This is called when we receive an interrupt with apparently comes from this226* chip - check, returning the highest interrupt generated or return NO_IRQ227*/228unsigned int gef_pic_get_irq(void)229{230u32 cause, mask, active;231unsigned int virq = NO_IRQ;232int hwirq;233234cause = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_STATUS);235236mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));237238active = cause & mask;239240if (active) {241for (hwirq = GEF_PIC_NUM_IRQS - 1; hwirq > -1; hwirq--) {242if (active & (0x1 << hwirq))243break;244}245virq = irq_linear_revmap(gef_pic_irq_host,246(irq_hw_number_t)hwirq);247}248249return virq;250}251252253254