]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Merge branch 'common/pinctrl' into sh-latest
authorPaul Mundt <lethal@linux-sh.org>
Fri, 20 Jul 2012 07:42:59 +0000 (16:42 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Fri, 20 Jul 2012 07:42:59 +0000 (16:42 +0900)
28 files changed:
arch/sh/Kconfig
arch/sh/boards/Kconfig
arch/sh/boards/mach-dreamcast/irq.c
arch/sh/boards/mach-se/7343/irq.c
arch/sh/boards/mach-se/7343/setup.c
arch/sh/boards/mach-se/7722/irq.c
arch/sh/boards/mach-se/7722/setup.c
arch/sh/boards/mach-se/7724/irq.c
arch/sh/boards/mach-x3proto/gpio.c
arch/sh/cchips/hd6446x/hd64461.c
arch/sh/include/asm/bug.h
arch/sh/include/asm/kdebug.h
arch/sh/include/mach-se/mach/se7343.h
arch/sh/include/mach-se/mach/se7722.h
arch/sh/kernel/cpu/sh5/unwind.c
arch/sh/kernel/dumpstack.c
arch/sh/kernel/irq.c
arch/sh/kernel/traps.c
arch/sh/kernel/traps_32.c
arch/sh/kernel/traps_64.c
arch/sh/lib64/Makefile
arch/sh/lib64/dbg.c [deleted file]
arch/sh/mm/tlb-sh5.c
drivers/sh/clk/cpg.c
drivers/sh/intc/Makefile
drivers/sh/intc/dynamic.c [deleted file]
drivers/sh/intc/virq.c
include/linux/sh_clk.h

index 31d9db7913e4352a10680f76f2aaa8a5e800eef5..a24595d83ad6c48c5685faed4d59ecb00d410c41 100644 (file)
@@ -60,6 +60,7 @@ config SUPERH32
 
 config SUPERH64
        def_bool ARCH = "sh64"
+       select KALLSYMS
 
 config ARCH_DEFCONFIG
        string
index 1f56b35d32481b04de59a7415b0f0abe73b58db0..7048c03490d9a06d48cff04ed6821db9a76e08d4 100644 (file)
@@ -44,6 +44,8 @@ config SH_7721_SOLUTION_ENGINE
 config SH_7722_SOLUTION_ENGINE
        bool "SolutionEngine7722"
        select SOLUTION_ENGINE
+       select GENERIC_IRQ_CHIP
+       select IRQ_DOMAIN
        depends on CPU_SUBTYPE_SH7722
        help
          Select 7722 SolutionEngine if configuring for a Hitachi SH772
@@ -80,6 +82,8 @@ config SH_7780_SOLUTION_ENGINE
 config SH_7343_SOLUTION_ENGINE
        bool "SolutionEngine7343"
        select SOLUTION_ENGINE
+       select GENERIC_IRQ_CHIP
+       select IRQ_DOMAIN
        depends on CPU_SUBTYPE_SH7343
        help
          Select 7343 SolutionEngine if configuring for a Hitachi
@@ -295,6 +299,7 @@ config SH_X3PROTO
        bool "SH-X3 Prototype board"
        depends on CPU_SUBTYPE_SHX3
        select NO_IOPORT if !PCI
+       select IRQ_DOMAIN
 
 config SH_MAGIC_PANEL_R2
        bool "Magic Panel R2"
index f63d323f411f5f32043e32f966be6e3a1289df41..2789647abebef2308a28f3260b6016410c078cab 100644 (file)
@@ -8,10 +8,11 @@
  * This file is part of the LinuxDC project (www.linuxdc.org)
  * Released under the terms of the GNU GPL v2.0
  */
-
 #include <linux/irq.h>
 #include <linux/io.h>
-#include <asm/irq.h>
+#include <linux/irq.h>
+#include <linux/export.h>
+#include <linux/err.h>
 #include <mach/sysasic.h>
 
 /*
@@ -141,26 +142,15 @@ int systemasic_irq_demux(int irq)
 
 void systemasic_irq_init(void)
 {
-       int i, nid = cpu_to_node(boot_cpu_data);
-
-       /* Assign all virtual IRQs to the System ASIC int. handler */
-       for (i = HW_EVENT_IRQ_BASE; i < HW_EVENT_IRQ_MAX; i++) {
-               unsigned int irq;
-
-               irq = create_irq_nr(i, nid);
-               if (unlikely(irq == 0)) {
-                       pr_err("%s: failed hooking irq %d for systemasic\n",
-                              __func__, i);
-                       return;
-               }
+       int irq_base, i;
 
-               if (unlikely(irq != i)) {
-                       pr_err("%s: got irq %d but wanted %d, bailing.\n",
-                              __func__, irq, i);
-                       destroy_irq(irq);
-                       return;
-               }
+       irq_base = irq_alloc_descs(HW_EVENT_IRQ_BASE, HW_EVENT_IRQ_BASE,
+                                  HW_EVENT_IRQ_MAX - HW_EVENT_IRQ_BASE, -1);
+       if (IS_ERR_VALUE(irq_base)) {
+               pr_err("%s: failed hooking irqs\n", __func__);
+               return;
+       }
 
+       for (i = HW_EVENT_IRQ_BASE; i < HW_EVENT_IRQ_MAX; i++)
                irq_set_chip_and_handler(i, &systemasic_int, handle_level_irq);
-       }
 }
index fd45ffc48340b898cac839d6be1d5e038693d52a..7646bf0486c2c9b17d60dff4c4b59ef9a50a1b7b 100644 (file)
 /*
- * linux/arch/sh/boards/se/7343/irq.c
+ * Hitachi UL SolutionEngine 7343 FPGA IRQ Support.
  *
  * Copyright (C) 2008  Yoshihiro Shimoda
+ * Copyright (C) 2012  Paul Mundt
  *
- * Based on linux/arch/sh/boards/se/7722/irq.c
+ * Based on linux/arch/sh/boards/se/7343/irq.c
  * Copyright (C) 2007  Nobuhiro Iwamatsu
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
+#define DRV_NAME "SE7343-FPGA"
+#define pr_fmt(fmt) DRV_NAME ": " fmt
+
+#define irq_reg_readl  ioread16
+#define irq_reg_writel iowrite16
+
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
+#include <linux/irqdomain.h>
 #include <linux/io.h>
+#include <asm/sizes.h>
 #include <mach-se/mach/se7343.h>
 
-unsigned int se7343_fpga_irq[SE7343_FPGA_IRQ_NR] = { 0, };
+#define PA_CPLD_BASE_ADDR      0x11400000
+#define PA_CPLD_ST_REG         0x08    /* CPLD Interrupt status register */
+#define PA_CPLD_IMSK_REG       0x0a    /* CPLD Interrupt mask register */
 
-static void disable_se7343_irq(struct irq_data *data)
-{
-       unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
-       __raw_writew(__raw_readw(PA_CPLD_IMSK) | 1 << bit, PA_CPLD_IMSK);
-}
+static void __iomem *se7343_irq_regs;
+struct irq_domain *se7343_irq_domain;
 
-static void enable_se7343_irq(struct irq_data *data)
+static void se7343_irq_demux(unsigned int irq, struct irq_desc *desc)
 {
-       unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
-       __raw_writew(__raw_readw(PA_CPLD_IMSK) & ~(1 << bit), PA_CPLD_IMSK);
-}
+       struct irq_data *data = irq_get_irq_data(irq);
+       struct irq_chip *chip = irq_data_get_irq_chip(data);
+       unsigned long mask;
+       int bit;
 
-static struct irq_chip se7343_irq_chip __read_mostly = {
-       .name           = "SE7343-FPGA",
-       .irq_mask       = disable_se7343_irq,
-       .irq_unmask     = enable_se7343_irq,
-};
+       chip->irq_mask_ack(data);
 
-static void se7343_irq_demux(unsigned int irq, struct irq_desc *desc)
+       mask = ioread16(se7343_irq_regs + PA_CPLD_ST_REG);
+
+       for_each_set_bit(bit, &mask, SE7343_FPGA_IRQ_NR)
+               generic_handle_irq(irq_linear_revmap(se7343_irq_domain, bit));
+
+       chip->irq_unmask(data);
+}
+
+static void __init se7343_domain_init(void)
 {
-       unsigned short intv = __raw_readw(PA_CPLD_ST);
-       unsigned int ext_irq = 0;
+       int i;
 
-       intv &= (1 << SE7343_FPGA_IRQ_NR) - 1;
+       se7343_irq_domain = irq_domain_add_linear(NULL, SE7343_FPGA_IRQ_NR,
+                                                 &irq_domain_simple_ops, NULL);
+       if (unlikely(!se7343_irq_domain)) {
+               printk("Failed to get IRQ domain\n");
+               return;
+       }
 
-       for (; intv; intv >>= 1, ext_irq++) {
-               if (!(intv & 1))
-                       continue;
+       for (i = 0; i < SE7343_FPGA_IRQ_NR; i++) {
+               int irq = irq_create_mapping(se7343_irq_domain, i);
 
-               generic_handle_irq(se7343_fpga_irq[ext_irq]);
+               if (unlikely(irq == 0)) {
+                       printk("Failed to allocate IRQ %d\n", i);
+                       return;
+               }
        }
 }
 
-/*
- * Initialize IRQ setting
- */
-void __init init_7343se_IRQ(void)
+static void __init se7343_gc_init(void)
 {
-       int i, irq;
+       struct irq_chip_generic *gc;
+       struct irq_chip_type *ct;
+       unsigned int irq_base;
 
-       __raw_writew(0, PA_CPLD_IMSK);  /* disable all irqs */
-       __raw_writew(0x2000, 0xb03fffec);       /* mrshpc irq enable */
+       irq_base = irq_linear_revmap(se7343_irq_domain, 0);
 
-       for (i = 0; i < SE7343_FPGA_IRQ_NR; i++) {
-               irq = create_irq();
-               if (irq < 0)
-                       return;
-               se7343_fpga_irq[i] = irq;
+       gc = irq_alloc_generic_chip(DRV_NAME, 1, irq_base, se7343_irq_regs,
+                                   handle_level_irq);
+       if (unlikely(!gc))
+               return;
 
-               irq_set_chip_and_handler_name(se7343_fpga_irq[i],
-                                             &se7343_irq_chip,
-                                             handle_level_irq,
-                                             "level");
+       ct = gc->chip_types;
+       ct->chip.irq_mask = irq_gc_mask_set_bit;
+       ct->chip.irq_unmask = irq_gc_mask_clr_bit;
 
-               irq_set_chip_data(se7343_fpga_irq[i], (void *)i);
-       }
+       ct->regs.mask = PA_CPLD_IMSK_REG;
+
+       irq_setup_generic_chip(gc, IRQ_MSK(SE7343_FPGA_IRQ_NR),
+                              IRQ_GC_INIT_MASK_CACHE,
+                              IRQ_NOREQUEST | IRQ_NOPROBE, 0);
 
        irq_set_chained_handler(IRQ0_IRQ, se7343_irq_demux);
        irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
+
        irq_set_chained_handler(IRQ1_IRQ, se7343_irq_demux);
        irq_set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
+
        irq_set_chained_handler(IRQ4_IRQ, se7343_irq_demux);
        irq_set_irq_type(IRQ4_IRQ, IRQ_TYPE_LEVEL_LOW);
+
        irq_set_chained_handler(IRQ5_IRQ, se7343_irq_demux);
        irq_set_irq_type(IRQ5_IRQ, IRQ_TYPE_LEVEL_LOW);
 }
+
+/*
+ * Initialize IRQ setting
+ */
+void __init init_7343se_IRQ(void)
+{
+       se7343_irq_regs = ioremap(PA_CPLD_BASE_ADDR, SZ_16);
+       if (unlikely(!se7343_irq_regs)) {
+               pr_err("Failed to remap CPLD\n");
+               return;
+       }
+
+       /*
+        * All FPGA IRQs disabled by default
+        */
+       iowrite16(0, se7343_irq_regs + PA_CPLD_IMSK_REG);
+
+       __raw_writew(0x2000, 0xb03fffec);       /* mrshpc irq enable */
+
+       se7343_domain_init();
+       se7343_gc_init();
+}
index d2370af56d772a83630d6dacdc5a02f846b799ea..8ce4f2a202a8c1885ee26014826041be35d149f7 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/serial_reg.h>
 #include <linux/usb/isp116x.h>
 #include <linux/delay.h>
+#include <linux/irqdomain.h>
 #include <asm/machvec.h>
 #include <mach-se/mach/se7343.h>
 #include <asm/heartbeat.h>
@@ -145,11 +146,12 @@ static struct platform_device *sh7343se_platform_devices[] __initdata = {
 static int __init sh7343se_devices_setup(void)
 {
        /* Wire-up dynamic vectors */
-       serial_platform_data[0].irq = se7343_fpga_irq[SE7343_FPGA_IRQ_UARTA];
-       serial_platform_data[1].irq = se7343_fpga_irq[SE7343_FPGA_IRQ_UARTB];
-
+       serial_platform_data[0].irq = irq_find_mapping(se7343_irq_domain,
+                                                      SE7343_FPGA_IRQ_UARTA);
+       serial_platform_data[1].irq = irq_find_mapping(se7343_irq_domain,
+                                                      SE7343_FPGA_IRQ_UARTB);
        usb_resources[2].start = usb_resources[2].end =
-               se7343_fpga_irq[SE7343_FPGA_IRQ_USB];
+               irq_find_mapping(se7343_irq_domain, SE7343_FPGA_IRQ_USB);
 
        return platform_add_devices(sh7343se_platform_devices,
                                    ARRAY_SIZE(sh7343se_platform_devices));
index aac92f21ebd23e945b680550eb90274ec622ca0d..f5e2af1bf040ff93dc415362e7ef3f2ac4e75753 100644 (file)
@@ -1,79 +1,96 @@
 /*
- * linux/arch/sh/boards/se/7722/irq.c
+ * Hitachi UL SolutionEngine 7722 FPGA IRQ Support.
  *
  * Copyright (C) 2007  Nobuhiro Iwamatsu
- *
- * Hitachi UL SolutionEngine 7722 Support.
+ * Copyright (C) 2012  Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
+#define DRV_NAME "SE7722-FPGA"
+#define pr_fmt(fmt) DRV_NAME ": " fmt
+
+#define irq_reg_readl  ioread16
+#define irq_reg_writel iowrite16
+
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
-#include <asm/irq.h>
-#include <asm/io.h>
+#include <linux/irqdomain.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <asm/sizes.h>
 #include <mach-se/mach/se7722.h>
 
-unsigned int se7722_fpga_irq[SE7722_FPGA_IRQ_NR] = { 0, };
+#define IRQ01_BASE_ADDR        0x11800000
+#define IRQ01_MODE_REG 0
+#define IRQ01_STS_REG  4
+#define IRQ01_MASK_REG 8
 
-static void disable_se7722_irq(struct irq_data *data)
-{
-       unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
-       __raw_writew(__raw_readw(IRQ01_MASK) | 1 << bit, IRQ01_MASK);
-}
+static void __iomem *se7722_irq_regs;
+struct irq_domain *se7722_irq_domain;
 
-static void enable_se7722_irq(struct irq_data *data)
+static void se7722_irq_demux(unsigned int irq, struct irq_desc *desc)
 {
-       unsigned int bit = (unsigned int)irq_data_get_irq_chip_data(data);
-       __raw_writew(__raw_readw(IRQ01_MASK) & ~(1 << bit), IRQ01_MASK);
-}
+       struct irq_data *data = irq_get_irq_data(irq);
+       struct irq_chip *chip = irq_data_get_irq_chip(data);
+       unsigned long mask;
+       int bit;
 
-static struct irq_chip se7722_irq_chip __read_mostly = {
-       .name           = "SE7722-FPGA",
-       .irq_mask       = disable_se7722_irq,
-       .irq_unmask     = enable_se7722_irq,
-};
+       chip->irq_mask_ack(data);
 
-static void se7722_irq_demux(unsigned int irq, struct irq_desc *desc)
+       mask = ioread16(se7722_irq_regs + IRQ01_STS_REG);
+
+       for_each_set_bit(bit, &mask, SE7722_FPGA_IRQ_NR)
+               generic_handle_irq(irq_linear_revmap(se7722_irq_domain, bit));
+
+       chip->irq_unmask(data);
+}
+
+static void __init se7722_domain_init(void)
 {
-       unsigned short intv = __raw_readw(IRQ01_STS);
-       unsigned int ext_irq = 0;
+       int i;
 
-       intv &= (1 << SE7722_FPGA_IRQ_NR) - 1;
+       se7722_irq_domain = irq_domain_add_linear(NULL, SE7722_FPGA_IRQ_NR,
+                                                 &irq_domain_simple_ops, NULL);
+       if (unlikely(!se7722_irq_domain)) {
+               printk("Failed to get IRQ domain\n");
+               return;
+       }
 
-       for (; intv; intv >>= 1, ext_irq++) {
-               if (!(intv & 1))
-                       continue;
+       for (i = 0; i < SE7722_FPGA_IRQ_NR; i++) {
+               int irq = irq_create_mapping(se7722_irq_domain, i);
 
-               generic_handle_irq(se7722_fpga_irq[ext_irq]);
+               if (unlikely(irq == 0)) {
+                       printk("Failed to allocate IRQ %d\n", i);
+                       return;
+               }
        }
 }
 
-/*
- * Initialize IRQ setting
- */
-void __init init_se7722_IRQ(void)
+static void __init se7722_gc_init(void)
 {
-       int i, irq;
+       struct irq_chip_generic *gc;
+       struct irq_chip_type *ct;
+       unsigned int irq_base;
 
-       __raw_writew(0, IRQ01_MASK);       /* disable all irqs */
-       __raw_writew(0x2000, 0xb03fffec);  /* mrshpc irq enable */
+       irq_base = irq_linear_revmap(se7722_irq_domain, 0);
 
-       for (i = 0; i < SE7722_FPGA_IRQ_NR; i++) {
-               irq = create_irq();
-               if (irq < 0)
-                       return;
-               se7722_fpga_irq[i] = irq;
+       gc = irq_alloc_generic_chip(DRV_NAME, 1, irq_base, se7722_irq_regs,
+                                   handle_level_irq);
+       if (unlikely(!gc))
+               return;
 
-               irq_set_chip_and_handler_name(se7722_fpga_irq[i],
-                                             &se7722_irq_chip,
-                                             handle_level_irq,
-                                             "level");
+       ct = gc->chip_types;
+       ct->chip.irq_mask = irq_gc_mask_set_bit;
+       ct->chip.irq_unmask = irq_gc_mask_clr_bit;
 
-               irq_set_chip_data(se7722_fpga_irq[i], (void *)i);
-       }
+       ct->regs.mask = IRQ01_MASK_REG;
+
+       irq_setup_generic_chip(gc, IRQ_MSK(SE7722_FPGA_IRQ_NR),
+                              IRQ_GC_INIT_MASK_CACHE,
+                              IRQ_NOREQUEST | IRQ_NOPROBE, 0);
 
        irq_set_chained_handler(IRQ0_IRQ, se7722_irq_demux);
        irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
@@ -81,3 +98,25 @@ void __init init_se7722_IRQ(void)
        irq_set_chained_handler(IRQ1_IRQ, se7722_irq_demux);
        irq_set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
 }
+
+/*
+ * Initialize FPGA IRQs
+ */
+void __init init_se7722_IRQ(void)
+{
+       se7722_irq_regs = ioremap(IRQ01_BASE_ADDR, SZ_16);
+       if (unlikely(!se7722_irq_regs)) {
+               printk("Failed to remap IRQ01 regs\n");
+               return;
+       }
+
+       /*
+        * All FPGA IRQs disabled by default
+        */
+       iowrite16(0, se7722_irq_regs + IRQ01_MASK_REG);
+
+       __raw_writew(0x2000, 0xb03fffec);  /* mrshpc irq enable */
+
+       se7722_domain_init();
+       se7722_gc_init();
+}
index 8f7f0550cfded7dcc2751db7e63e933d353bd510..e04e2bc4698481374b2e6c16f9580d70021e9382 100644 (file)
@@ -2,6 +2,7 @@
  * linux/arch/sh/boards/se/7722/setup.c
  *
  * Copyright (C) 2007 Nobuhiro Iwamatsu
+ * Copyright (C) 2012 Paul Mundt
  *
  * Hitachi UL SolutionEngine 7722 Support.
  *
@@ -15,6 +16,7 @@
 #include <linux/ata_platform.h>
 #include <linux/input.h>
 #include <linux/input/sh_keysc.h>
+#include <linux/irqdomain.h>
 #include <linux/smc91x.h>
 #include <linux/sh_intc.h>
 #include <mach-se/mach/se7722.h>
@@ -143,10 +145,10 @@ static int __init se7722_devices_setup(void)
 
        /* Wire-up dynamic vectors */
        cf_ide_resources[2].start = cf_ide_resources[2].end =
-               se7722_fpga_irq[SE7722_FPGA_IRQ_MRSHPC0];
+               irq_find_mapping(se7722_irq_domain, SE7722_FPGA_IRQ_MRSHPC0);
 
        smc91x_eth_resources[1].start = smc91x_eth_resources[1].end =
-               se7722_fpga_irq[SE7722_FPGA_IRQ_SMC];
+               irq_find_mapping(se7722_irq_domain, SE7722_FPGA_IRQ_SMC);
 
        return platform_add_devices(se7722_devices, ARRAY_SIZE(se7722_devices));
 }
index c6342ce7768df0432b4e67190a50cc808bb65da6..5d1d3ec9a6cdd26de792e3538020fb7c45a9f073 100644 (file)
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
-#include <asm/irq.h>
-#include <asm/io.h>
+#include <linux/export.h>
+#include <linux/topology.h>
+#include <linux/io.h>
+#include <linux/err.h>
 #include <mach-se/mach/se7724.h>
 
 struct fpga_irq {
@@ -111,7 +113,7 @@ static void se7724_irq_demux(unsigned int irq, struct irq_desc *desc)
  */
 void __init init_se7724_IRQ(void)
 {
-       int i, nid = cpu_to_node(boot_cpu_data);
+       int irq_base, i;
 
        __raw_writew(0xffff, IRQ0_MR);  /* mask all */
        __raw_writew(0xffff, IRQ1_MR);  /* mask all */
@@ -121,28 +123,16 @@ void __init init_se7724_IRQ(void)
        __raw_writew(0x0000, IRQ2_SR);  /* clear irq */
        __raw_writew(0x002a, IRQ_MODE); /* set irq type */
 
-       for (i = 0; i < SE7724_FPGA_IRQ_NR; i++) {
-               int irq, wanted;
-
-               wanted = SE7724_FPGA_IRQ_BASE + i;
-
-               irq = create_irq_nr(wanted, nid);
-               if (unlikely(irq == 0)) {
-                       pr_err("%s: failed hooking irq %d for FPGA\n",
-                              __func__, wanted);
-                       return;
-               }
-
-               if (unlikely(irq != wanted)) {
-                       pr_err("%s: got irq %d but wanted %d, bailing.\n",
-                              __func__, irq, wanted);
-                       destroy_irq(irq);
-                       return;
-               }
+       irq_base = irq_alloc_descs(SE7724_FPGA_IRQ_BASE, SE7724_FPGA_IRQ_BASE,
+                                  SE7724_FPGA_IRQ_NR, numa_node_id());
+       if (IS_ERR_VALUE(irq_base)) {
+               pr_err("%s: failed hooking irqs for FPGA\n", __func__);
+               return;
+       }
 
-               irq_set_chip_and_handler_name(irq, &se7724_irq_chip,
+       for (i = 0; i < SE7724_FPGA_IRQ_NR; i++)
+               irq_set_chip_and_handler_name(irq_base + i, &se7724_irq_chip,
                                              handle_level_irq, "level");
-       }
 
        irq_set_chained_handler(IRQ0_IRQ, se7724_irq_demux);
        irq_set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
index f33b2b57019c298dd9a6622085fe85ef107bf8d9..3ea65e9b56e80ed34e5aad1055ce31df6666acb3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Renesas SH-X3 Prototype Baseboard GPIO Support.
  *
- * Copyright (C) 2010  Paul Mundt
+ * Copyright (C) 2010 - 2012  Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
@@ -17,6 +17,7 @@
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
+#include <linux/irqdomain.h>
 #include <linux/io.h>
 #include <mach/ilsel.h>
 #include <mach/hardware.h>
@@ -26,7 +27,7 @@
 #define KEYDETR 0xb81c0004
 
 static DEFINE_SPINLOCK(x3proto_gpio_lock);
-static unsigned int x3proto_gpio_irq_map[NR_BASEBOARD_GPIOS] = { 0, };
+static struct irq_domain *x3proto_irq_domain;
 
 static int x3proto_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
 {
@@ -49,7 +50,14 @@ static int x3proto_gpio_get(struct gpio_chip *chip, unsigned gpio)
 
 static int x3proto_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
 {
-       return x3proto_gpio_irq_map[gpio];
+       int virq;
+
+       if (gpio < chip->ngpio)
+               virq = irq_create_mapping(x3proto_irq_domain, gpio);
+       else
+               virq = -ENXIO;
+
+       return virq;
 }
 
 static void x3proto_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
@@ -62,9 +70,8 @@ static void x3proto_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
        chip->irq_mask_ack(data);
 
        mask = __raw_readw(KEYDETR);
-
        for_each_set_bit(pin, &mask, NR_BASEBOARD_GPIOS)
-               generic_handle_irq(x3proto_gpio_to_irq(NULL, pin));
+               generic_handle_irq(irq_linear_revmap(x3proto_irq_domain, pin));
 
        chip->irq_unmask(data);
 }
@@ -78,10 +85,23 @@ struct gpio_chip x3proto_gpio_chip = {
        .ngpio                  = NR_BASEBOARD_GPIOS,
 };
 
+static int x3proto_gpio_irq_map(struct irq_domain *domain, unsigned int virq,
+                               irq_hw_number_t hwirq)
+{
+       irq_set_chip_and_handler_name(virq, &dummy_irq_chip, handle_simple_irq,
+                                     "gpio");
+
+       return 0;
+}
+
+static struct irq_domain_ops x3proto_gpio_irq_ops = {
+       .map    = x3proto_gpio_irq_map,
+       .xlate  = irq_domain_xlate_twocell,
+};
+
 int __init x3proto_gpio_setup(void)
 {
-       int ilsel;
-       int ret, i;
+       int ilsel, ret;
 
        ilsel = ilsel_enable(ILSEL_KEY);
        if (unlikely(ilsel < 0))
@@ -91,21 +111,10 @@ int __init x3proto_gpio_setup(void)
        if (unlikely(ret))
                goto err_gpio;
 
-       for (i = 0; i < NR_BASEBOARD_GPIOS; i++) {
-               unsigned long flags;
-               int irq = create_irq();
-
-               if (unlikely(irq < 0)) {
-                       ret = -EINVAL;
-                       goto err_irq;
-               }
-
-               spin_lock_irqsave(&x3proto_gpio_lock, flags);
-               x3proto_gpio_irq_map[i] = irq;
-               irq_set_chip_and_handler_name(irq, &dummy_irq_chip,
-                                             handle_simple_irq, "gpio");
-               spin_unlock_irqrestore(&x3proto_gpio_lock, flags);
-       }
+       x3proto_irq_domain = irq_domain_add_linear(NULL, NR_BASEBOARD_GPIOS,
+                                                  &x3proto_gpio_irq_ops, NULL);
+       if (unlikely(!x3proto_irq_domain))
+               goto err_irq;
 
        pr_info("registering '%s' support, handling GPIOs %u -> %u, "
                "bound to IRQ %u\n",
@@ -119,10 +128,6 @@ int __init x3proto_gpio_setup(void)
        return 0;
 
 err_irq:
-       for (; i >= 0; --i)
-               if (x3proto_gpio_irq_map[i])
-                       destroy_irq(x3proto_gpio_irq_map[i]);
-
        ret = gpiochip_remove(&x3proto_gpio_chip);
        if (unlikely(ret))
                pr_err("Failed deregistering GPIO\n");
index eb4ea4d44d59527c0cc4e691904b1c516deb24e7..e9735616bdc8ac96bb5fee14923ba53a0d5f12dd 100644 (file)
@@ -73,10 +73,7 @@ static void hd64461_irq_demux(unsigned int irq, struct irq_desc *desc)
 
 int __init setup_hd64461(void)
 {
-       int i, nid = cpu_to_node(boot_cpu_data);
-
-       if (!MACH_HD64461)
-               return 0;
+       int irq_base, i;
 
        printk(KERN_INFO
               "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
@@ -89,28 +86,16 @@ int __init setup_hd64461(void)
 #endif
        __raw_writew(0xffff, HD64461_NIMR);
 
-       /*  IRQ 80 -> 95 belongs to HD64461  */
-       for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
-               unsigned int irq;
-
-               irq = create_irq_nr(i, nid);
-               if (unlikely(irq == 0)) {
-                       pr_err("%s: failed hooking irq %d for HD64461\n",
-                              __func__, i);
-                       return -EBUSY;
-               }
-
-               if (unlikely(irq != i)) {
-                       pr_err("%s: got irq %d but wanted %d, bailing.\n",
-                              __func__, irq, i);
-                       destroy_irq(irq);
-                       return -EINVAL;
-               }
-
-               irq_set_chip_and_handler(i, &hd64461_irq_chip,
-                                        handle_level_irq);
+       irq_base = irq_alloc_descs(HD64461_IRQBASE, HD64461_IRQBASE, 16, -1);
+       if (IS_ERR_VALUE(irq_base)) {
+               pr_err("%s: failed hooking irqs for HD64461\n", __func__);
+               return irq_base;
        }
 
+       for (i = 0; i < 16; i++)
+               irq_set_chip_and_handler(irq_base + i, &hd64461_irq_chip,
+                                        handle_level_irq);
+
        irq_set_chained_handler(CONFIG_HD64461_IRQ, hd64461_irq_demux);
        irq_set_irq_type(CONFIG_HD64461_IRQ, IRQ_TYPE_LEVEL_LOW);
 
index 2b87d86bfc4169384ce529af620c5db9e5238acf..dcf278075429fcb2774cbfaeb586a7dc43bf10ab 100644 (file)
@@ -110,6 +110,10 @@ do {                                                       \
 #include <asm-generic/bug.h>
 
 struct pt_regs;
+
+/* arch/sh/kernel/traps.c */
 extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
+extern void die_if_kernel(const char *str, struct pt_regs *regs, long err);
+extern void die_if_no_fixup(const char *str, struct pt_regs *regs, long err);
 
 #endif /* __ASM_SH_BUG_H */
index a6201f10c2730878ae987cec8c01142f96569561..8d6a831e7ba1501a54ce9292e110720b7ce38ee6 100644 (file)
@@ -10,6 +10,8 @@ enum die_val {
        DIE_SSTEP,
 };
 
+/* arch/sh/kernel/dumpstack.c */
 extern void printk_address(unsigned long address, int reliable);
+extern void dump_mem(const char *str, unsigned long bottom, unsigned long top);
 
 #endif /* __ASM_SH_KDEBUG_H */
index 50b5d575dff090ccf0b081e3ab4b41fb98cd976c..542521c970c6ef4a0deee858c57c664c2155bd6d 100644 (file)
@@ -50,9 +50,6 @@
 #define PA_LED         0xb0C00000      /* LED */
 #define LED_SHIFT       0
 #define PA_DIPSW       0xb0900000      /* Dip switch 31 */
-#define PA_CPLD_MODESET        0xb1400004      /* CPLD Mode set register */
-#define PA_CPLD_ST     0xb1400008      /* CPLD Interrupt status register */
-#define PA_CPLD_IMSK   0xb140000a      /* CPLD Interrupt mask register */
 /* Area 5 */
 #define PA_EXT5                0x14000000
 #define PA_EXT5_SIZE   0x04000000
 
 #define SE7343_FPGA_IRQ_NR     12
 
+struct irq_domain;
+
 /* arch/sh/boards/se/7343/irq.c */
-extern unsigned int se7343_fpga_irq[];
+extern struct irq_domain *se7343_irq_domain;
 
 void init_7343se_IRQ(void);
 
index 201081ebdbce7f8ef881a591d23029f93777739e..637e7ac753f84c8187d7ef1800d673cd3050f071 100644 (file)
 #define IRQ0_IRQ        evt2irq(0x600)
 #define IRQ1_IRQ        evt2irq(0x620)
 
-#define IRQ01_MODE      0xb1800000
-#define IRQ01_STS       0xb1800004
-#define IRQ01_MASK      0xb1800008
-
-/* Bits in IRQ01_* registers */
-
 #define SE7722_FPGA_IRQ_USB    0 /* IRQ0 */
 #define SE7722_FPGA_IRQ_SMC    1 /* IRQ0 */
 #define SE7722_FPGA_IRQ_MRSHPC0        2 /* IRQ1 */
 #define SE7722_FPGA_IRQ_MRSHPC3        5 /* IRQ1 */
 #define SE7722_FPGA_IRQ_NR     6
 
+struct irq_domain;
+
 /* arch/sh/boards/se/7722/irq.c */
-extern unsigned int se7722_fpga_irq[];
+extern struct irq_domain *se7722_irq_domain;
 
 void init_se7722_IRQ(void);
 
index b205b25eaf45d6d6b0b791703ee83fe3f9e45f8b..10aed41757fc8247f9e1c271623907b31192607b 100644 (file)
@@ -16,6 +16,8 @@
 #include <asm/ptrace.h>
 #include <asm/processor.h>
 #include <asm/io.h>
+#include <asm/unwinder.h>
+#include <asm/stacktrace.h>
 
 static u8 regcache[63];
 
@@ -199,8 +201,11 @@ static int lookup_prev_stack_frame(unsigned long fp, unsigned long pc,
        return 0;
 }
 
-/* Don't put this on the stack since we'll want to call sh64_unwind
- * when we're close to underflowing the stack anyway. */
+/*
+ * Don't put this on the stack since we'll want to call in to
+ * sh64_unwinder_dump() when we're close to underflowing the stack
+ * anyway.
+ */
 static struct pt_regs here_regs;
 
 extern const char syscall_ret;
@@ -208,17 +213,19 @@ extern const char ret_from_syscall;
 extern const char ret_from_exception;
 extern const char ret_from_irq;
 
-static void sh64_unwind_inner(struct pt_regs *regs);
+static void sh64_unwind_inner(const struct stacktrace_ops *ops,
+                             void *data, struct pt_regs *regs);
 
-static void unwind_nested (unsigned long pc, unsigned long fp)
+static inline void unwind_nested(const struct stacktrace_ops *ops, void *data,
+                                unsigned long pc, unsigned long fp)
 {
        if ((fp >= __MEMORY_START) &&
-           ((fp & 7) == 0)) {
-               sh64_unwind_inner((struct pt_regs *) fp);
-       }
+           ((fp & 7) == 0))
+               sh64_unwind_inner(ops, data, (struct pt_regs *)fp);
 }
 
-static void sh64_unwind_inner(struct pt_regs *regs)
+static void sh64_unwind_inner(const struct stacktrace_ops *ops,
+                             void *data, struct pt_regs *regs)
 {
        unsigned long pc, fp;
        int ofs = 0;
@@ -232,29 +239,29 @@ static void sh64_unwind_inner(struct pt_regs *regs)
                int cond;
                unsigned long next_fp, next_pc;
 
-               if (pc == ((unsigned long) &syscall_ret & ~1)) {
+               if (pc == ((unsigned long)&syscall_ret & ~1)) {
                        printk("SYSCALL\n");
-                       unwind_nested(pc,fp);
+                       unwind_nested(ops, data, pc, fp);
                        return;
                }
 
-               if (pc == ((unsigned long) &ret_from_syscall & ~1)) {
+               if (pc == ((unsigned long)&ret_from_syscall & ~1)) {
                        printk("SYSCALL (PREEMPTED)\n");
-                       unwind_nested(pc,fp);
+                       unwind_nested(ops, data, pc, fp);
                        return;
                }
 
                /* In this case, the PC is discovered by lookup_prev_stack_frame but
                   it has 4 taken off it to look like the 'caller' */
-               if (pc == ((unsigned long) &ret_from_exception & ~1)) {
+               if (pc == ((unsigned long)&ret_from_exception & ~1)) {
                        printk("EXCEPTION\n");
-                       unwind_nested(pc,fp);
+                       unwind_nested(ops, data, pc, fp);
                        return;
                }
 
-               if (pc == ((unsigned long) &ret_from_irq & ~1)) {
+               if (pc == ((unsigned long)&ret_from_irq & ~1)) {
                        printk("IRQ\n");
-                       unwind_nested(pc,fp);
+                       unwind_nested(ops, data, pc, fp);
                        return;
                }
 
@@ -263,8 +270,7 @@ static void sh64_unwind_inner(struct pt_regs *regs)
 
                pc -= ofs;
 
-               printk("[<%08lx>] ", pc);
-               print_symbol("%s\n", pc);
+               ops->address(data, pc, 1);
 
                if (first_pass) {
                        /* If the innermost frame is a leaf function, it's
@@ -287,10 +293,13 @@ static void sh64_unwind_inner(struct pt_regs *regs)
        }
 
        printk("\n");
-
 }
 
-void sh64_unwind(struct pt_regs *regs)
+static void sh64_unwinder_dump(struct task_struct *task,
+                              struct pt_regs *regs,
+                              unsigned long *sp,
+                              const struct stacktrace_ops *ops,
+                              void *data)
 {
        if (!regs) {
                /*
@@ -320,7 +329,17 @@ void sh64_unwind(struct pt_regs *regs)
                );
        }
 
-       printk("\nCall Trace:\n");
-       sh64_unwind_inner(regs);
+       sh64_unwind_inner(ops, data, regs);
 }
 
+static struct unwinder sh64_unwinder = {
+       .name   = "sh64-unwinder",
+       .dump   = sh64_unwinder_dump,
+       .rating = 150,
+};
+
+static int __init sh64_unwinder_init(void)
+{
+       return unwinder_register(&sh64_unwinder);
+}
+early_initcall(sh64_unwinder_init);
index 694158b9a50f5655aba0c2bf50551261d13b554b..7617dc4129ac05acf7ade8e12f4791cda212d732 100644 (file)
@@ -2,13 +2,48 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *  Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  *  Copyright (C) 2009  Matt Fleming
+ *  Copyright (C) 2002 - 2012  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
  */
 #include <linux/kallsyms.h>
 #include <linux/ftrace.h>
 #include <linux/debug_locks.h>
+#include <linux/kdebug.h>
+#include <linux/export.h>
+#include <linux/uaccess.h>
 #include <asm/unwinder.h>
 #include <asm/stacktrace.h>
 
+void dump_mem(const char *str, unsigned long bottom, unsigned long top)
+{
+       unsigned long p;
+       int i;
+
+       printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
+
+       for (p = bottom & ~31; p < top; ) {
+               printk("%04lx: ", p & 0xffff);
+
+               for (i = 0; i < 8; i++, p += 4) {
+                       unsigned int val;
+
+                       if (p < bottom || p >= top)
+                               printk("         ");
+                       else {
+                               if (__get_user(val, (unsigned int __user *)p)) {
+                                       printk("\n");
+                                       return;
+                               }
+                               printk("%08x ", val);
+                       }
+               }
+               printk("\n");
+       }
+}
+
 void printk_address(unsigned long address, int reliable)
 {
        printk(" [<%p>] %s%pS\n", (void *) address,
@@ -106,3 +141,26 @@ void show_trace(struct task_struct *tsk, unsigned long *sp,
 
        debug_show_held_locks(tsk);
 }
+
+void show_stack(struct task_struct *tsk, unsigned long *sp)
+{
+       unsigned long stack;
+
+       if (!tsk)
+               tsk = current;
+       if (tsk == current)
+               sp = (unsigned long *)current_stack_pointer;
+       else
+               sp = (unsigned long *)tsk->thread.sp;
+
+       stack = (unsigned long)sp;
+       dump_mem("Stack: ", stack, THREAD_SIZE +
+                (unsigned long)task_stack_page(tsk));
+       show_trace(tsk, sp, NULL);
+}
+
+void dump_stack(void)
+{
+       show_stack(NULL, NULL);
+}
+EXPORT_SYMBOL(dump_stack);
index dadce735f7465ee449b83070bf10148303c1b3c8..063af10ff3c1eb9e76c4724d3977b6bd9421b9fe 100644 (file)
@@ -231,16 +231,6 @@ void __init init_IRQ(void)
        irq_ctx_init(smp_processor_id());
 }
 
-#ifdef CONFIG_SPARSE_IRQ
-int __init arch_probe_nr_irqs(void)
-{
-       /*
-        * No pre-allocated IRQs.
-        */
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_HOTPLUG_CPU
 static void route_irq(struct irq_data *data, unsigned int irq, unsigned int cpu)
 {
index a87e58a9e38fe17ffe37219d56d854ddf0be48b4..72246bc06884c8dee333544ee2c0161090b814db 100644 (file)
@@ -6,9 +6,80 @@
 #include <linux/sched.h>
 #include <linux/uaccess.h>
 #include <linux/hardirq.h>
+#include <linux/kernel.h>
+#include <linux/kexec.h>
+#include <linux/module.h>
 #include <asm/unwinder.h>
 #include <asm/traps.h>
 
+static DEFINE_SPINLOCK(die_lock);
+
+void die(const char *str, struct pt_regs *regs, long err)
+{
+       static int die_counter;
+
+       oops_enter();
+
+       spin_lock_irq(&die_lock);
+       console_verbose();
+       bust_spinlocks(1);
+
+       printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
+       print_modules();
+       show_regs(regs);
+
+       printk("Process: %s (pid: %d, stack limit = %p)\n", current->comm,
+                       task_pid_nr(current), task_stack_page(current) + 1);
+
+       if (!user_mode(regs) || in_interrupt())
+               dump_mem("Stack: ", regs->regs[15], THREAD_SIZE +
+                        (unsigned long)task_stack_page(current));
+
+       notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV);
+
+       bust_spinlocks(0);
+       add_taint(TAINT_DIE);
+       spin_unlock_irq(&die_lock);
+       oops_exit();
+
+       if (kexec_should_crash(current))
+               crash_kexec(regs);
+
+       if (in_interrupt())
+               panic("Fatal exception in interrupt");
+
+       if (panic_on_oops)
+               panic("Fatal exception");
+
+       do_exit(SIGSEGV);
+}
+
+void die_if_kernel(const char *str, struct pt_regs *regs, long err)
+{
+       if (!user_mode(regs))
+               die(str, regs, err);
+}
+
+/*
+ * try and fix up kernelspace address errors
+ * - userspace errors just cause EFAULT to be returned, resulting in SEGV
+ * - kernel/userspace interfaces cause a jump to an appropriate handler
+ * - other kernel errors are bad
+ */
+void die_if_no_fixup(const char *str, struct pt_regs *regs, long err)
+{
+       if (!user_mode(regs)) {
+               const struct exception_table_entry *fixup;
+               fixup = search_exception_tables(regs->pc);
+               if (fixup) {
+                       regs->pc = fixup->fixup;
+                       return;
+               }
+
+               die(str, regs, err);
+       }
+}
+
 #ifdef CONFIG_GENERIC_BUG
 static void handle_BUG(struct pt_regs *regs)
 {
index a37175deb73fdfa672c604ddab07297c41559981..5f513a64dedfc8f3afa1593a253505d3ce2254eb 100644 (file)
 #include <linux/hardirq.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
-#include <linux/module.h>
 #include <linux/kallsyms.h>
 #include <linux/io.h>
 #include <linux/bug.h>
 #include <linux/debug_locks.h>
 #include <linux/kdebug.h>
-#include <linux/kexec.h>
 #include <linux/limits.h>
 #include <linux/sysfs.h>
 #include <linux/uaccess.h>
 #define TRAP_ILLEGAL_SLOT_INST 13
 #endif
 
-static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
-{
-       unsigned long p;
-       int i;
-
-       printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
-
-       for (p = bottom & ~31; p < top; ) {
-               printk("%04lx: ", p & 0xffff);
-
-               for (i = 0; i < 8; i++, p += 4) {
-                       unsigned int val;
-
-                       if (p < bottom || p >= top)
-                               printk("         ");
-                       else {
-                               if (__get_user(val, (unsigned int __user *)p)) {
-                                       printk("\n");
-                                       return;
-                               }
-                               printk("%08x ", val);
-                       }
-               }
-               printk("\n");
-       }
-}
-
-static DEFINE_SPINLOCK(die_lock);
-
-void die(const char * str, struct pt_regs * regs, long err)
-{
-       static int die_counter;
-
-       oops_enter();
-
-       spin_lock_irq(&die_lock);
-       console_verbose();
-       bust_spinlocks(1);
-
-       printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
-       print_modules();
-       show_regs(regs);
-
-       printk("Process: %s (pid: %d, stack limit = %p)\n", current->comm,
-                       task_pid_nr(current), task_stack_page(current) + 1);
-
-       if (!user_mode(regs) || in_interrupt())
-               dump_mem("Stack: ", regs->regs[15], THREAD_SIZE +
-                        (unsigned long)task_stack_page(current));
-
-       notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV);
-
-       bust_spinlocks(0);
-       add_taint(TAINT_DIE);
-       spin_unlock_irq(&die_lock);
-       oops_exit();
-
-       if (kexec_should_crash(current))
-               crash_kexec(regs);
-
-       if (in_interrupt())
-               panic("Fatal exception in interrupt");
-
-       if (panic_on_oops)
-               panic("Fatal exception");
-
-       do_exit(SIGSEGV);
-}
-
-static inline void die_if_kernel(const char *str, struct pt_regs *regs,
-                                long err)
-{
-       if (!user_mode(regs))
-               die(str, regs, err);
-}
-
-/*
- * try and fix up kernelspace address errors
- * - userspace errors just cause EFAULT to be returned, resulting in SEGV
- * - kernel/userspace interfaces cause a jump to an appropriate handler
- * - other kernel errors are bad
- */
-static void die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
-{
-       if (!user_mode(regs)) {
-               const struct exception_table_entry *fixup;
-               fixup = search_exception_tables(regs->pc);
-               if (fixup) {
-                       regs->pc = fixup->fixup;
-                       return;
-               }
-
-               die(str, regs, err);
-       }
-}
-
 static inline void sign_extend(unsigned int count, unsigned char *dst)
 {
 #ifdef __LITTLE_ENDIAN__
@@ -900,26 +802,3 @@ void __init trap_init(void)
        set_exception_table_vec(TRAP_UBC, breakpoint_trap_handler);
 #endif
 }
-
-void show_stack(struct task_struct *tsk, unsigned long *sp)
-{
-       unsigned long stack;
-
-       if (!tsk)
-               tsk = current;
-       if (tsk == current)
-               sp = (unsigned long *)current_stack_pointer;
-       else
-               sp = (unsigned long *)tsk->thread.sp;
-
-       stack = (unsigned long)sp;
-       dump_mem("Stack: ", stack, THREAD_SIZE +
-                (unsigned long)task_stack_page(tsk));
-       show_trace(tsk, sp, NULL);
-}
-
-void dump_stack(void)
-{
-       show_stack(NULL, NULL);
-}
-EXPORT_SYMBOL(dump_stack);
index 8dae93ed8aff77586c50df0f6830e23f48f13c75..f87d20da17916cc0c3cf8c6cfb286cbbb0d50d5b 100644 (file)
 #include <linux/perf_event.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
-#include <linux/atomic.h>
+#include <asm/alignment.h>
 #include <asm/processor.h>
 #include <asm/pgtable.h>
 #include <asm/fpu.h>
 
-#undef DEBUG_EXCEPTION
-#ifdef DEBUG_EXCEPTION
-/* implemented in ../lib/dbg.c */
-extern void show_excp_regs(char *fname, int trapnr, int signr,
-                          struct pt_regs *regs);
-#else
-#define show_excp_regs(a, b, c, d)
-#endif
-
-static void do_unhandled_exception(int trapnr, int signr, char *str, char *fn_name,
-               unsigned long error_code, struct pt_regs *regs, struct task_struct *tsk);
-
-#define DO_ERROR(trapnr, signr, str, name, tsk) \
-asmlinkage void do_##name(unsigned long error_code, struct pt_regs *regs) \
-{ \
-       do_unhandled_exception(trapnr, signr, str, __stringify(name), error_code, regs, current); \
-}
-
-static DEFINE_SPINLOCK(die_lock);
-
-void die(const char * str, struct pt_regs * regs, long err)
-{
-       console_verbose();
-       spin_lock_irq(&die_lock);
-       printk("%s: %lx\n", str, (err & 0xffffff));
-       show_regs(regs);
-       spin_unlock_irq(&die_lock);
-       do_exit(SIGSEGV);
-}
-
-static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
-{
-       if (!user_mode(regs))
-               die(str, regs, err);
-}
-
-static void die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
-{
-       if (!user_mode(regs)) {
-               const struct exception_table_entry *fixup;
-               fixup = search_exception_tables(regs->pc);
-               if (fixup) {
-                       regs->pc = fixup->fixup;
-                       return;
-               }
-               die(str, regs, err);
-       }
-}
-
-DO_ERROR(13, SIGILL,  "illegal slot instruction", illegal_slot_inst, current)
-DO_ERROR(87, SIGSEGV, "address error (exec)", address_error_exec, current)
-
-
-/* Implement misaligned load/store handling for kernel (and optionally for user
-   mode too).  Limitation : only SHmedia mode code is handled - there is no
-   handling at all for misaligned accesses occurring in SHcompact code yet. */
-
-static int misaligned_fixup(struct pt_regs *regs);
-
-asmlinkage void do_address_error_load(unsigned long error_code, struct pt_regs *regs)
-{
-       if (misaligned_fixup(regs) < 0) {
-               do_unhandled_exception(7, SIGSEGV, "address error(load)",
-                               "do_address_error_load",
-                               error_code, regs, current);
-       }
-       return;
-}
-
-asmlinkage void do_address_error_store(unsigned long error_code, struct pt_regs *regs)
-{
-       if (misaligned_fixup(regs) < 0) {
-               do_unhandled_exception(8, SIGSEGV, "address error(store)",
-                               "do_address_error_store",
-                               error_code, regs, current);
-       }
-       return;
-}
-
-#if defined(CONFIG_SH64_ID2815_WORKAROUND)
-
-#define OPCODE_INVALID      0
-#define OPCODE_USER_VALID   1
-#define OPCODE_PRIV_VALID   2
-
-/* getcon/putcon - requires checking which control register is referenced. */
-#define OPCODE_CTRL_REG     3
-
-/* Table of valid opcodes for SHmedia mode.
-   Form a 10-bit value by concatenating the major/minor opcodes i.e.
-   opcode[31:26,20:16].  The 6 MSBs of this value index into the following
-   array.  The 4 LSBs select the bit-pair in the entry (bits 1:0 correspond to
-   LSBs==4'b0000 etc). */
-static unsigned long shmedia_opcode_table[64] = {
-       0x55554044,0x54445055,0x15141514,0x14541414,0x00000000,0x10001000,0x01110055,0x04050015,
-       0x00000444,0xc0000000,0x44545515,0x40405555,0x55550015,0x10005555,0x55555505,0x04050000,
-       0x00000555,0x00000404,0x00040445,0x15151414,0x00000000,0x00000000,0x00000000,0x00000000,
-       0x00000055,0x40404444,0x00000404,0xc0009495,0x00000000,0x00000000,0x00000000,0x00000000,
-       0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
-       0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
-       0x80005050,0x04005055,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
-       0x81055554,0x00000404,0x55555555,0x55555555,0x00000000,0x00000000,0x00000000,0x00000000
-};
-
-void do_reserved_inst(unsigned long error_code, struct pt_regs *regs)
-{
-       /* Workaround SH5-101 cut2 silicon defect #2815 :
-          in some situations, inter-mode branches from SHcompact -> SHmedia
-          which should take ITLBMISS or EXECPROT exceptions at the target
-          falsely take RESINST at the target instead. */
-
-       unsigned long opcode = 0x6ff4fff0; /* guaranteed reserved opcode */
-       unsigned long pc, aligned_pc;
-       int get_user_error;
-       int trapnr = 12;
-       int signr = SIGILL;
-       char *exception_name = "reserved_instruction";
-
-       pc = regs->pc;
-       if ((pc & 3) == 1) {
-               /* SHmedia : check for defect.  This requires executable vmas
-                  to be readable too. */
-               aligned_pc = pc & ~3;
-               if (!access_ok(VERIFY_READ, aligned_pc, sizeof(unsigned long))) {
-                       get_user_error = -EFAULT;
-               } else {
-                       get_user_error = __get_user(opcode, (unsigned long *)aligned_pc);
-               }
-               if (get_user_error >= 0) {
-                       unsigned long index, shift;
-                       unsigned long major, minor, combined;
-                       unsigned long reserved_field;
-                       reserved_field = opcode & 0xf; /* These bits are currently reserved as zero in all valid opcodes */
-                       major = (opcode >> 26) & 0x3f;
-                       minor = (opcode >> 16) & 0xf;
-                       combined = (major << 4) | minor;
-                       index = major;
-                       shift = minor << 1;
-                       if (reserved_field == 0) {
-                               int opcode_state = (shmedia_opcode_table[index] >> shift) & 0x3;
-                               switch (opcode_state) {
-                                       case OPCODE_INVALID:
-                                               /* Trap. */
-                                               break;
-                                       case OPCODE_USER_VALID:
-                                               /* Restart the instruction : the branch to the instruction will now be from an RTE
-                                                  not from SHcompact so the silicon defect won't be triggered. */
-                                               return;
-                                       case OPCODE_PRIV_VALID:
-                                               if (!user_mode(regs)) {
-                                                       /* Should only ever get here if a module has
-                                                          SHcompact code inside it.  If so, the same fix up is needed. */
-                                                       return; /* same reason */
-                                               }
-                                               /* Otherwise, user mode trying to execute a privileged instruction -
-                                                  fall through to trap. */
-                                               break;
-                                       case OPCODE_CTRL_REG:
-                                               /* If in privileged mode, return as above. */
-                                               if (!user_mode(regs)) return;
-                                               /* In user mode ... */
-                                               if (combined == 0x9f) { /* GETCON */
-                                                       unsigned long regno = (opcode >> 20) & 0x3f;
-                                                       if (regno >= 62) {
-                                                               return;
-                                                       }
-                                                       /* Otherwise, reserved or privileged control register, => trap */
-                                               } else if (combined == 0x1bf) { /* PUTCON */
-                                                       unsigned long regno = (opcode >> 4) & 0x3f;
-                                                       if (regno >= 62) {
-                                                               return;
-                                                       }
-                                                       /* Otherwise, reserved or privileged control register, => trap */
-                                               } else {
-                                                       /* Trap */
-                                               }
-                                               break;
-                                       default:
-                                               /* Fall through to trap. */
-                                               break;
-                               }
-                       }
-                       /* fall through to normal resinst processing */
-               } else {
-                       /* Error trying to read opcode.  This typically means a
-                          real fault, not a RESINST any more.  So change the
-                          codes. */
-                       trapnr = 87;
-                       exception_name = "address error (exec)";
-                       signr = SIGSEGV;
-               }
-       }
-
-       do_unhandled_exception(trapnr, signr, exception_name, "do_reserved_inst", error_code, regs, current);
-}
-
-#else /* CONFIG_SH64_ID2815_WORKAROUND */
-
-/* If the workaround isn't needed, this is just a straightforward reserved
-   instruction */
-DO_ERROR(12, SIGILL,  "reserved instruction", reserved_inst, current)
-
-#endif /* CONFIG_SH64_ID2815_WORKAROUND */
-
-/* Called with interrupts disabled */
-asmlinkage void do_exception_error(unsigned long ex, struct pt_regs *regs)
-{
-       show_excp_regs(__func__, -1, -1, regs);
-       die_if_kernel("exception", regs, ex);
-}
-
-int do_unknown_trapa(unsigned long scId, struct pt_regs *regs)
-{
-       /* Syscall debug */
-        printk("System call ID error: [0x1#args:8 #syscall:16  0x%lx]\n", scId);
-
-       die_if_kernel("unknown trapa", regs, scId);
-
-       return -ENOSYS;
-}
-
-void show_stack(struct task_struct *tsk, unsigned long *sp)
-{
-#ifdef CONFIG_KALLSYMS
-       extern void sh64_unwind(struct pt_regs *regs);
-       struct pt_regs *regs;
-
-       regs = tsk ? tsk->thread.kregs : NULL;
-
-       sh64_unwind(regs);
-#else
-       printk(KERN_ERR "Can't backtrace on sh64 without CONFIG_KALLSYMS\n");
-#endif
-}
-
-void show_task(unsigned long *sp)
-{
-       show_stack(NULL, sp);
-}
-
-void dump_stack(void)
-{
-       show_task(NULL);
-}
-/* Needed by any user of WARN_ON in view of the defn in include/asm-sh/bug.h */
-EXPORT_SYMBOL(dump_stack);
-
-static void do_unhandled_exception(int trapnr, int signr, char *str, char *fn_name,
-               unsigned long error_code, struct pt_regs *regs, struct task_struct *tsk)
-{
-       show_excp_regs(fn_name, trapnr, signr, regs);
-
-       if (user_mode(regs))
-               force_sig(signr, tsk);
-
-       die_if_no_fixup(str, regs, error_code);
-}
-
-static int read_opcode(unsigned long long pc, unsigned long *result_opcode, int from_user_mode)
+static int read_opcode(reg_size_t pc, insn_size_t *result_opcode, int from_user_mode)
 {
        int get_user_error;
        unsigned long aligned_pc;
-       unsigned long opcode;
+       insn_size_t opcode;
 
        if ((pc & 3) == 1) {
                /* SHmedia */
                aligned_pc = pc & ~3;
                if (from_user_mode) {
-                       if (!access_ok(VERIFY_READ, aligned_pc, sizeof(unsigned long))) {
+                       if (!access_ok(VERIFY_READ, aligned_pc, sizeof(insn_size_t))) {
                                get_user_error = -EFAULT;
                        } else {
-                               get_user_error = __get_user(opcode, (unsigned long *)aligned_pc);
+                               get_user_error = __get_user(opcode, (insn_size_t *)aligned_pc);
                                *result_opcode = opcode;
                        }
                        return get_user_error;
@@ -311,7 +53,7 @@ static int read_opcode(unsigned long long pc, unsigned long *result_opcode, int
                        /* If the fault was in the kernel, we can either read
                         * this directly, or if not, we fault.
                        */
-                       *result_opcode = *(unsigned long *) aligned_pc;
+                       *result_opcode = *(insn_size_t *)aligned_pc;
                        return 0;
                }
        } else if ((pc & 1) == 0) {
@@ -337,17 +79,23 @@ static int address_is_sign_extended(__u64 a)
 #endif
 }
 
+/* return -1 for fault, 0 for OK */
 static int generate_and_check_address(struct pt_regs *regs,
-                                     __u32 opcode,
+                                     insn_size_t opcode,
                                      int displacement_not_indexed,
                                      int width_shift,
                                      __u64 *address)
 {
-       /* return -1 for fault, 0 for OK */
-
        __u64 base_address, addr;
        int basereg;
 
+       switch (1 << width_shift) {
+       case 1: inc_unaligned_byte_access(); break;
+       case 2: inc_unaligned_word_access(); break;
+       case 4: inc_unaligned_dword_access(); break;
+       case 8: inc_unaligned_multi_access(); break;
+       }
+
        basereg = (opcode >> 20) & 0x3f;
        base_address = regs->regs[basereg];
        if (displacement_not_indexed) {
@@ -364,28 +112,28 @@ static int generate_and_check_address(struct pt_regs *regs,
        }
 
        /* Check sign extended */
-       if (!address_is_sign_extended(addr)) {
+       if (!address_is_sign_extended(addr))
                return -1;
-       }
 
        /* Check accessible.  For misaligned access in the kernel, assume the
           address is always accessible (and if not, just fault when the
           load/store gets done.) */
        if (user_mode(regs)) {
-               if (addr >= TASK_SIZE) {
+               inc_unaligned_user_access();
+
+               if (addr >= TASK_SIZE)
                        return -1;
-               }
-               /* Do access_ok check later - it depends on whether it's a load or a store. */
-       }
+       } else
+               inc_unaligned_kernel_access();
 
        *address = addr;
+
+       perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, addr);
+       unaligned_fixups_notify(current, opcode, regs);
+
        return 0;
 }
 
-static int user_mode_unaligned_fixup_count = 10;
-static int user_mode_unaligned_fixup_enable = 1;
-static int kernel_mode_unaligned_fixup_count = 32;
-
 static void misaligned_kernel_word_load(__u64 address, int do_sign_extend, __u64 *result)
 {
        unsigned short x;
@@ -415,7 +163,7 @@ static void misaligned_kernel_word_store(__u64 address, __u64 value)
 }
 
 static int misaligned_load(struct pt_regs *regs,
-                          __u32 opcode,
+                          insn_size_t opcode,
                           int displacement_not_indexed,
                           int width_shift,
                           int do_sign_extend)
@@ -427,11 +175,8 @@ static int misaligned_load(struct pt_regs *regs,
 
        error = generate_and_check_address(regs, opcode,
                        displacement_not_indexed, width_shift, &address);
-       if (error < 0) {
+       if (error < 0)
                return error;
-       }
-
-       perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, address);
 
        destreg = (opcode >> 4) & 0x3f;
        if (user_mode(regs)) {
@@ -490,11 +235,10 @@ static int misaligned_load(struct pt_regs *regs,
        }
 
        return 0;
-
 }
 
 static int misaligned_store(struct pt_regs *regs,
-                           __u32 opcode,
+                           insn_size_t opcode,
                            int displacement_not_indexed,
                            int width_shift)
 {
@@ -505,11 +249,8 @@ static int misaligned_store(struct pt_regs *regs,
 
        error = generate_and_check_address(regs, opcode,
                        displacement_not_indexed, width_shift, &address);
-       if (error < 0) {
+       if (error < 0)
                return error;
-       }
-
-       perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, address);
 
        srcreg = (opcode >> 4) & 0x3f;
        if (user_mode(regs)) {
@@ -563,13 +304,12 @@ static int misaligned_store(struct pt_regs *regs,
        }
 
        return 0;
-
 }
 
 /* Never need to fix up misaligned FPU accesses within the kernel since that's a real
    error. */
 static int misaligned_fpu_load(struct pt_regs *regs,
-                          __u32 opcode,
+                          insn_size_t opcode,
                           int displacement_not_indexed,
                           int width_shift,
                           int do_paired_load)
@@ -581,11 +321,8 @@ static int misaligned_fpu_load(struct pt_regs *regs,
 
        error = generate_and_check_address(regs, opcode,
                        displacement_not_indexed, width_shift, &address);
-       if (error < 0) {
+       if (error < 0)
                return error;
-       }
-
-       perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, address);
 
        destreg = (opcode >> 4) & 0x3f;
        if (user_mode(regs)) {
@@ -641,12 +378,10 @@ static int misaligned_fpu_load(struct pt_regs *regs,
                die ("Misaligned FPU load inside kernel", regs, 0);
                return -1;
        }
-
-
 }
 
 static int misaligned_fpu_store(struct pt_regs *regs,
-                          __u32 opcode,
+                          insn_size_t opcode,
                           int displacement_not_indexed,
                           int width_shift,
                           int do_paired_load)
@@ -658,11 +393,8 @@ static int misaligned_fpu_store(struct pt_regs *regs,
 
        error = generate_and_check_address(regs, opcode,
                        displacement_not_indexed, width_shift, &address);
-       if (error < 0) {
+       if (error < 0)
                return error;
-       }
-
-       perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, address);
 
        srcreg = (opcode >> 4) & 0x3f;
        if (user_mode(regs)) {
@@ -723,11 +455,13 @@ static int misaligned_fpu_store(struct pt_regs *regs,
 
 static int misaligned_fixup(struct pt_regs *regs)
 {
-       unsigned long opcode;
+       insn_size_t opcode;
        int error;
        int major, minor;
+       unsigned int user_action;
 
-       if (!user_mode_unaligned_fixup_enable)
+       user_action = unaligned_user_action();
+       if (!(user_action & UM_FIXUP))
                return -1;
 
        error = read_opcode(regs->pc, &opcode, user_mode(regs));
@@ -737,23 +471,6 @@ static int misaligned_fixup(struct pt_regs *regs)
        major = (opcode >> 26) & 0x3f;
        minor = (opcode >> 16) & 0xf;
 
-       if (user_mode(regs) && (user_mode_unaligned_fixup_count > 0)) {
-               --user_mode_unaligned_fixup_count;
-               /* Only do 'count' worth of these reports, to remove a potential DoS against syslog */
-               printk("Fixing up unaligned userspace access in \"%s\" pid=%d pc=0x%08x ins=0x%08lx\n",
-                      current->comm, task_pid_nr(current), (__u32)regs->pc, opcode);
-       } else if (!user_mode(regs) && (kernel_mode_unaligned_fixup_count > 0)) {
-               --kernel_mode_unaligned_fixup_count;
-               if (in_interrupt()) {
-                       printk("Fixing up unaligned kernelspace access in interrupt pc=0x%08x ins=0x%08lx\n",
-                              (__u32)regs->pc, opcode);
-               } else {
-                       printk("Fixing up unaligned kernelspace access in \"%s\" pid=%d pc=0x%08x ins=0x%08lx\n",
-                              current->comm, task_pid_nr(current), (__u32)regs->pc, opcode);
-               }
-       }
-
-
        switch (major) {
                case (0x84>>2): /* LD.W */
                        error = misaligned_load(regs, opcode, 1, 1, 1);
@@ -878,59 +595,202 @@ static int misaligned_fixup(struct pt_regs *regs)
                regs->pc += 4; /* Skip the instruction that's just been emulated */
                return 0;
        }
+}
+
+static void do_unhandled_exception(int signr, char *str, unsigned long error,
+                                  struct pt_regs *regs)
+{
+       if (user_mode(regs))
+               force_sig(signr, current);
 
+       die_if_no_fixup(str, regs, error);
 }
 
-static ctl_table unaligned_table[] = {
-       {
-               .procname       = "kernel_reports",
-               .data           = &kernel_mode_unaligned_fixup_count,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec
-       },
-       {
-               .procname       = "user_reports",
-               .data           = &user_mode_unaligned_fixup_count,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec
-       },
-       {
-               .procname       = "user_enable",
-               .data           = &user_mode_unaligned_fixup_enable,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec},
-       {}
-};
+#define DO_ERROR(signr, str, name) \
+asmlinkage void do_##name(unsigned long error_code, struct pt_regs *regs) \
+{ \
+       do_unhandled_exception(signr, str, error_code, regs); \
+}
 
-static ctl_table unaligned_root[] = {
-       {
-               .procname       = "unaligned_fixup",
-               .mode           = 0555,
-               .child          = unaligned_table
-       },
-       {}
-};
+DO_ERROR(SIGILL,  "illegal slot instruction", illegal_slot_inst)
+DO_ERROR(SIGSEGV, "address error (exec)", address_error_exec)
+
+#if defined(CONFIG_SH64_ID2815_WORKAROUND)
+
+#define OPCODE_INVALID      0
+#define OPCODE_USER_VALID   1
+#define OPCODE_PRIV_VALID   2
 
-static ctl_table sh64_root[] = {
-       {
-               .procname       = "sh64",
-               .mode           = 0555,
-               .child          = unaligned_root
-       },
-       {}
+/* getcon/putcon - requires checking which control register is referenced. */
+#define OPCODE_CTRL_REG     3
+
+/* Table of valid opcodes for SHmedia mode.
+   Form a 10-bit value by concatenating the major/minor opcodes i.e.
+   opcode[31:26,20:16].  The 6 MSBs of this value index into the following
+   array.  The 4 LSBs select the bit-pair in the entry (bits 1:0 correspond to
+   LSBs==4'b0000 etc). */
+static unsigned long shmedia_opcode_table[64] = {
+       0x55554044,0x54445055,0x15141514,0x14541414,0x00000000,0x10001000,0x01110055,0x04050015,
+       0x00000444,0xc0000000,0x44545515,0x40405555,0x55550015,0x10005555,0x55555505,0x04050000,
+       0x00000555,0x00000404,0x00040445,0x15151414,0x00000000,0x00000000,0x00000000,0x00000000,
+       0x00000055,0x40404444,0x00000404,0xc0009495,0x00000000,0x00000000,0x00000000,0x00000000,
+       0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
+       0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
+       0x80005050,0x04005055,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,0x55555555,
+       0x81055554,0x00000404,0x55555555,0x55555555,0x00000000,0x00000000,0x00000000,0x00000000
 };
-static struct ctl_table_header *sysctl_header;
-static int __init init_sysctl(void)
+
+/* Workaround SH5-101 cut2 silicon defect #2815 :
+   in some situations, inter-mode branches from SHcompact -> SHmedia
+   which should take ITLBMISS or EXECPROT exceptions at the target
+   falsely take RESINST at the target instead. */
+void do_reserved_inst(unsigned long error_code, struct pt_regs *regs)
 {
-       sysctl_header = register_sysctl_table(sh64_root);
-       return 0;
+       insn_size_t opcode = 0x6ff4fff0; /* guaranteed reserved opcode */
+       unsigned long pc, aligned_pc;
+       unsigned long index, shift;
+       unsigned long major, minor, combined;
+       unsigned long reserved_field;
+       int opcode_state;
+       int get_user_error;
+       int signr = SIGILL;
+       char *exception_name = "reserved_instruction";
+
+       pc = regs->pc;
+
+       /* SHcompact is not handled */
+       if (unlikely((pc & 3) == 0))
+               goto out;
+
+       /* SHmedia : check for defect.  This requires executable vmas
+          to be readable too. */
+       aligned_pc = pc & ~3;
+       if (!access_ok(VERIFY_READ, aligned_pc, sizeof(insn_size_t)))
+               get_user_error = -EFAULT;
+       else
+               get_user_error = __get_user(opcode, (insn_size_t *)aligned_pc);
+
+       if (get_user_error < 0) {
+               /*
+                * Error trying to read opcode.  This typically means a
+                * real fault, not a RESINST any more.  So change the
+                * codes.
+                */
+               exception_name = "address error (exec)";
+               signr = SIGSEGV;
+               goto out;
+       }
+
+       /* These bits are currently reserved as zero in all valid opcodes */
+       reserved_field = opcode & 0xf;
+       if (unlikely(reserved_field))
+               goto out;       /* invalid opcode */
+
+       major = (opcode >> 26) & 0x3f;
+       minor = (opcode >> 16) & 0xf;
+       combined = (major << 4) | minor;
+       index = major;
+       shift = minor << 1;
+       opcode_state = (shmedia_opcode_table[index] >> shift) & 0x3;
+       switch (opcode_state) {
+       case OPCODE_INVALID:
+               /* Trap. */
+               break;
+       case OPCODE_USER_VALID:
+               /*
+                * Restart the instruction: the branch to the instruction
+                * will now be from an RTE not from SHcompact so the
+                * silicon defect won't be triggered.
+                */
+               return;
+       case OPCODE_PRIV_VALID:
+               if (!user_mode(regs)) {
+                       /*
+                        * Should only ever get here if a module has
+                        * SHcompact code inside it. If so, the same fix
+                        * up is needed.
+                        */
+                       return; /* same reason */
+               }
+
+               /*
+                * Otherwise, user mode trying to execute a privileged
+                * instruction - fall through to trap.
+                */
+               break;
+       case OPCODE_CTRL_REG:
+               /* If in privileged mode, return as above. */
+               if (!user_mode(regs))
+                       return;
+
+               /* In user mode ... */
+               if (combined == 0x9f) { /* GETCON */
+                       unsigned long regno = (opcode >> 20) & 0x3f;
+
+                       if (regno >= 62)
+                               return;
+
+                       /* reserved/privileged control register => trap */
+               } else if (combined == 0x1bf) { /* PUTCON */
+                       unsigned long regno = (opcode >> 4) & 0x3f;
+
+                       if (regno >= 62)
+                               return;
+
+                       /* reserved/privileged control register => trap */
+               }
+
+               break;
+       default:
+               /* Fall through to trap. */
+               break;
+       }
+
+out:
+       do_unhandled_exception(signr, exception_name, error_code, regs);
 }
 
-__initcall(init_sysctl);
+#else /* CONFIG_SH64_ID2815_WORKAROUND */
 
+/* If the workaround isn't needed, this is just a straightforward reserved
+   instruction */
+DO_ERROR(SIGILL, "reserved instruction", reserved_inst)
+
+#endif /* CONFIG_SH64_ID2815_WORKAROUND */
+
+/* Called with interrupts disabled */
+asmlinkage void do_exception_error(unsigned long ex, struct pt_regs *regs)
+{
+       die_if_kernel("exception", regs, ex);
+}
+
+asmlinkage int do_unknown_trapa(unsigned long scId, struct pt_regs *regs)
+{
+       /* Syscall debug */
+       printk("System call ID error: [0x1#args:8 #syscall:16  0x%lx]\n", scId);
+
+       die_if_kernel("unknown trapa", regs, scId);
+
+       return -ENOSYS;
+}
+
+/* Implement misaligned load/store handling for kernel (and optionally for user
+   mode too).  Limitation : only SHmedia mode code is handled - there is no
+   handling at all for misaligned accesses occurring in SHcompact code yet. */
+
+asmlinkage void do_address_error_load(unsigned long error_code, struct pt_regs *regs)
+{
+       if (misaligned_fixup(regs) < 0)
+               do_unhandled_exception(SIGSEGV, "address error(load)",
+                                      error_code, regs);
+}
+
+asmlinkage void do_address_error_store(unsigned long error_code, struct pt_regs *regs)
+{
+       if (misaligned_fixup(regs) < 0)
+               do_unhandled_exception(SIGSEGV, "address error(store)",
+                               error_code, regs);
+}
 
 asmlinkage void do_debug_interrupt(unsigned long code, struct pt_regs *regs)
 {
@@ -942,10 +802,9 @@ asmlinkage void do_debug_interrupt(unsigned long code, struct pt_regs *regs)
           of access we make to them - just go direct to their physical
           addresses. */
        exp_cause = peek_real_address_q(DM_EXP_CAUSE_PHY);
-       if (exp_cause & ~4) {
+       if (exp_cause & ~4)
                printk("DM.EXP_CAUSE had unexpected bits set (=%08lx)\n",
                        (unsigned long)(exp_cause & 0xffffffff));
-       }
        show_state();
        /* Clear all DEBUGINT causes */
        poke_real_address_q(DM_EXP_CAUSE_PHY, 0x0);
index 1fee75aa1f989719ebd19298f7af2ae9f65aa9f8..69779ff741dfeb4c6e5f19ed3af6198d47ac06b2 100644 (file)
@@ -10,7 +10,7 @@
 #
 
 # Panic should really be compiled as PIC
-lib-y  := udelay.o dbg.o panic.o memcpy.o memset.o \
+lib-y  := udelay.o panic.o memcpy.o memset.o \
          copy_user_memcpy.o copy_page.o strcpy.o strlen.o
 
 # Extracted from libgcc
diff --git a/arch/sh/lib64/dbg.c b/arch/sh/lib64/dbg.c
deleted file mode 100644 (file)
index 6152a6a..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*--------------------------------------------------------------------------
---
--- Identity : Linux50 Debug Funcions
---
--- File     : arch/sh/lib64/dbg.c
---
--- Copyright 2000, 2001 STMicroelectronics Limited.
--- Copyright 2004 Richard Curnow (evt_debug etc)
---
---------------------------------------------------------------------------*/
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/fs.h>
-#include <asm/mmu_context.h>
-
-typedef u64 regType_t;
-
-static regType_t getConfigReg(u64 id)
-{
-       register u64 reg __asm__("r2");
-       asm volatile ("getcfg   %1, 0, %0":"=r" (reg):"r"(id));
-       return (reg);
-}
-
-/* ======================================================================= */
-
-static char *szTab[] = { "4k", "64k", "1M", "512M" };
-static char *protTab[] = { "----",
-       "---R",
-       "--X-",
-       "--XR",
-       "-W--",
-       "-W-R",
-       "-WX-",
-       "-WXR",
-       "U---",
-       "U--R",
-       "U-X-",
-       "U-XR",
-       "UW--",
-       "UW-R",
-       "UWX-",
-       "UWXR"
-};
-#define  ITLB_BASE     0x00000000
-#define  DTLB_BASE     0x00800000
-#define  MAX_TLBs              64
-/* PTE High */
-#define  GET_VALID(pte)        ((pte) & 0x1)
-#define  GET_SHARED(pte)       ((pte) & 0x2)
-#define  GET_ASID(pte)         ((pte >> 2) & 0x0ff)
-#define  GET_EPN(pte)          ((pte) & 0xfffff000)
-
-/* PTE Low */
-#define  GET_CBEHAVIOR(pte)    ((pte) & 0x3)
-#define  GET_PAGE_SIZE(pte)    szTab[((pte >> 3) & 0x3)]
-#define  GET_PROTECTION(pte)   protTab[((pte >> 6) & 0xf)]
-#define  GET_PPN(pte)          ((pte) & 0xfffff000)
-
-#define PAGE_1K_MASK           0x00000000
-#define PAGE_4K_MASK           0x00000010
-#define PAGE_64K_MASK          0x00000080
-#define MMU_PAGESIZE_MASK      (PAGE_64K_MASK | PAGE_4K_MASK)
-#define PAGE_1MB_MASK          MMU_PAGESIZE_MASK
-#define PAGE_1K                (1024)
-#define PAGE_4K                (1024 * 4)
-#define PAGE_64K               (1024 * 64)
-#define PAGE_1MB               (1024 * 1024)
-
-#define HOW_TO_READ_TLB_CONTENT  \
-       "[ ID]  PPN         EPN        ASID  Share  CB  P.Size   PROT.\n"
-
-void print_single_tlb(unsigned long tlb, int single_print)
-{
-       regType_t pteH;
-       regType_t pteL;
-       unsigned int valid, shared, asid, epn, cb, ppn;
-       char *pSize;
-       char *pProt;
-
-       /*
-          ** in case of single print <single_print> is true, this implies:
-          **   1) print the TLB in any case also if NOT VALID
-          **   2) print out the header
-        */
-
-       pteH = getConfigReg(tlb);
-       valid = GET_VALID(pteH);
-       if (single_print)
-               printk(HOW_TO_READ_TLB_CONTENT);
-       else if (!valid)
-               return;
-
-       pteL = getConfigReg(tlb + 1);
-
-       shared = GET_SHARED(pteH);
-       asid = GET_ASID(pteH);
-       epn = GET_EPN(pteH);
-       cb = GET_CBEHAVIOR(pteL);
-       pSize = GET_PAGE_SIZE(pteL);
-       pProt = GET_PROTECTION(pteL);
-       ppn = GET_PPN(pteL);
-       printk("[%c%2ld]  0x%08x  0x%08x  %03d   %02x    %02x   %4s    %s\n",
-              ((valid) ? ' ' : 'u'), ((tlb & 0x0ffff) / TLB_STEP),
-              ppn, epn, asid, shared, cb, pSize, pProt);
-}
-
-void print_dtlb(void)
-{
-       int count;
-       unsigned long tlb;
-
-       printk(" ================= SH-5 D-TLBs Status ===================\n");
-       printk(HOW_TO_READ_TLB_CONTENT);
-       tlb = DTLB_BASE;
-       for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
-               print_single_tlb(tlb, 0);
-       printk
-           (" =============================================================\n");
-}
-
-void print_itlb(void)
-{
-       int count;
-       unsigned long tlb;
-
-       printk(" ================= SH-5 I-TLBs Status ===================\n");
-       printk(HOW_TO_READ_TLB_CONTENT);
-       tlb = ITLB_BASE;
-       for (count = 0; count < MAX_TLBs; count++, tlb += TLB_STEP)
-               print_single_tlb(tlb, 0);
-       printk
-           (" =============================================================\n");
-}
-
-void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs)
-{
-
-       unsigned long long ah, al, bh, bl, ch, cl;
-
-       printk("\n");
-       printk("EXCEPTION - %s: task %d; Linux trap # %d; signal = %d\n",
-              ((from) ? from : "???"), current->pid, trapnr, signr);
-
-       asm volatile ("getcon   " __EXPEVT ", %0":"=r"(ah));
-       asm volatile ("getcon   " __EXPEVT ", %0":"=r"(al));
-       ah = (ah) >> 32;
-       al = (al) & 0xffffffff;
-       asm volatile ("getcon   " __KCR1 ", %0":"=r"(bh));
-       asm volatile ("getcon   " __KCR1 ", %0":"=r"(bl));
-       bh = (bh) >> 32;
-       bl = (bl) & 0xffffffff;
-       asm volatile ("getcon   " __INTEVT ", %0":"=r"(ch));
-       asm volatile ("getcon   " __INTEVT ", %0":"=r"(cl));
-       ch = (ch) >> 32;
-       cl = (cl) & 0xffffffff;
-       printk("EXPE: %08Lx%08Lx KCR1: %08Lx%08Lx INTE: %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       asm volatile ("getcon   " __PEXPEVT ", %0":"=r"(ah));
-       asm volatile ("getcon   " __PEXPEVT ", %0":"=r"(al));
-       ah = (ah) >> 32;
-       al = (al) & 0xffffffff;
-       asm volatile ("getcon   " __PSPC ", %0":"=r"(bh));
-       asm volatile ("getcon   " __PSPC ", %0":"=r"(bl));
-       bh = (bh) >> 32;
-       bl = (bl) & 0xffffffff;
-       asm volatile ("getcon   " __PSSR ", %0":"=r"(ch));
-       asm volatile ("getcon   " __PSSR ", %0":"=r"(cl));
-       ch = (ch) >> 32;
-       cl = (cl) & 0xffffffff;
-       printk("PEXP: %08Lx%08Lx PSPC: %08Lx%08Lx PSSR: %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->pc) >> 32;
-       al = (regs->pc) & 0xffffffff;
-       bh = (regs->regs[18]) >> 32;
-       bl = (regs->regs[18]) & 0xffffffff;
-       ch = (regs->regs[15]) >> 32;
-       cl = (regs->regs[15]) & 0xffffffff;
-       printk("PC  : %08Lx%08Lx LINK: %08Lx%08Lx SP  : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->sr) >> 32;
-       al = (regs->sr) & 0xffffffff;
-       asm volatile ("getcon   " __TEA ", %0":"=r"(bh));
-       asm volatile ("getcon   " __TEA ", %0":"=r"(bl));
-       bh = (bh) >> 32;
-       bl = (bl) & 0xffffffff;
-       asm volatile ("getcon   " __KCR0 ", %0":"=r"(ch));
-       asm volatile ("getcon   " __KCR0 ", %0":"=r"(cl));
-       ch = (ch) >> 32;
-       cl = (cl) & 0xffffffff;
-       printk("SR  : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->regs[0]) >> 32;
-       al = (regs->regs[0]) & 0xffffffff;
-       bh = (regs->regs[1]) >> 32;
-       bl = (regs->regs[1]) & 0xffffffff;
-       ch = (regs->regs[2]) >> 32;
-       cl = (regs->regs[2]) & 0xffffffff;
-       printk("R0  : %08Lx%08Lx R1  : %08Lx%08Lx R2  : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->regs[3]) >> 32;
-       al = (regs->regs[3]) & 0xffffffff;
-       bh = (regs->regs[4]) >> 32;
-       bl = (regs->regs[4]) & 0xffffffff;
-       ch = (regs->regs[5]) >> 32;
-       cl = (regs->regs[5]) & 0xffffffff;
-       printk("R3  : %08Lx%08Lx R4  : %08Lx%08Lx R5  : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->regs[6]) >> 32;
-       al = (regs->regs[6]) & 0xffffffff;
-       bh = (regs->regs[7]) >> 32;
-       bl = (regs->regs[7]) & 0xffffffff;
-       ch = (regs->regs[8]) >> 32;
-       cl = (regs->regs[8]) & 0xffffffff;
-       printk("R6  : %08Lx%08Lx R7  : %08Lx%08Lx R8  : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-
-       ah = (regs->regs[9]) >> 32;
-       al = (regs->regs[9]) & 0xffffffff;
-       bh = (regs->regs[10]) >> 32;
-       bl = (regs->regs[10]) & 0xffffffff;
-       ch = (regs->regs[11]) >> 32;
-       cl = (regs->regs[11]) & 0xffffffff;
-       printk("R9  : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-       printk("....\n");
-
-       ah = (regs->tregs[0]) >> 32;
-       al = (regs->tregs[0]) & 0xffffffff;
-       bh = (regs->tregs[1]) >> 32;
-       bl = (regs->tregs[1]) & 0xffffffff;
-       ch = (regs->tregs[2]) >> 32;
-       cl = (regs->tregs[2]) & 0xffffffff;
-       printk("T0  : %08Lx%08Lx T1  : %08Lx%08Lx T2  : %08Lx%08Lx\n",
-              ah, al, bh, bl, ch, cl);
-       printk("....\n");
-
-       print_dtlb();
-       print_itlb();
-}
index 3aea25dc431ae27e24547e3e8b2c9f455790e4f8..ff1c40a31cbc05ea888721f601f1ca581a2fbae4 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * sh64_tlb_init - Perform initial setup for the DTLB and ITLB.
  */
-int __init sh64_tlb_init(void)
+int __cpuinit sh64_tlb_init(void)
 {
        /* Assign some sane DTLB defaults */
        cpu_data->dtlb.entries  = 64;
index f0d015dd0fef20aa2795b7c4866e00e1e2e478a2..07e9fb4f8041d9d93371fab60aa50e61f23bbabb 100644 (file)
@@ -14,6 +14,8 @@
 #include <linux/io.h>
 #include <linux/sh_clk.h>
 
+#define CPG_CKSTP_BIT  BIT(8)
+
 static unsigned int sh_clk_read(struct clk *clk)
 {
        if (clk->flags & CLK_ENABLE_REG_8BIT)
@@ -66,71 +68,43 @@ int __init sh_clk_mstp_register(struct clk *clks, int nr)
        return ret;
 }
 
-static long sh_clk_div_round_rate(struct clk *clk, unsigned long rate)
+/*
+ * Div/mult table lookup helpers
+ */
+static inline struct clk_div_table *clk_to_div_table(struct clk *clk)
 {
-       return clk_rate_table_round(clk, clk->freq_table, rate);
+       return clk->priv;
 }
 
-static int sh_clk_div6_divisors[64] = {
-       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
-       33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
-       49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
-};
+static inline struct clk_div_mult_table *clk_to_div_mult_table(struct clk *clk)
+{
+       return clk_to_div_table(clk)->div_mult_table;
+}
 
-static struct clk_div_mult_table sh_clk_div6_table = {
-       .divisors = sh_clk_div6_divisors,
-       .nr_divisors = ARRAY_SIZE(sh_clk_div6_divisors),
-};
+/*
+ * Common div ops
+ */
+static long sh_clk_div_round_rate(struct clk *clk, unsigned long rate)
+{
+       return clk_rate_table_round(clk, clk->freq_table, rate);
+}
 
-static unsigned long sh_clk_div6_recalc(struct clk *clk)
+static unsigned long sh_clk_div_recalc(struct clk *clk)
 {
-       struct clk_div_mult_table *table = &sh_clk_div6_table;
+       struct clk_div_mult_table *table = clk_to_div_mult_table(clk);
        unsigned int idx;
 
        clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, NULL);
+                            table, clk->arch_flags ? &clk->arch_flags : NULL);
 
-       idx = sh_clk_read(clk) & 0x003f;
+       idx = (sh_clk_read(clk) >> clk->enable_bit) & clk->div_mask;
 
        return clk->freq_table[idx].frequency;
 }
 
-static int sh_clk_div6_set_parent(struct clk *clk, struct clk *parent)
-{
-       struct clk_div_mult_table *table = &sh_clk_div6_table;
-       u32 value;
-       int ret, i;
-
-       if (!clk->parent_table || !clk->parent_num)
-               return -EINVAL;
-
-       /* Search the parent */
-       for (i = 0; i < clk->parent_num; i++)
-               if (clk->parent_table[i] == parent)
-                       break;
-
-       if (i == clk->parent_num)
-               return -ENODEV;
-
-       ret = clk_reparent(clk, parent);
-       if (ret < 0)
-               return ret;
-
-       value = sh_clk_read(clk) &
-               ~(((1 << clk->src_width) - 1) << clk->src_shift);
-
-       sh_clk_write(value | (i << clk->src_shift), clk);
-
-       /* Rebuild the frequency table */
-       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, NULL);
-
-       return 0;
-}
-
-static int sh_clk_div6_set_rate(struct clk *clk, unsigned long rate)
+static int sh_clk_div_set_rate(struct clk *clk, unsigned long rate)
 {
+       struct clk_div_table *dt = clk_to_div_table(clk);
        unsigned long value;
        int idx;
 
@@ -139,51 +113,53 @@ static int sh_clk_div6_set_rate(struct clk *clk, unsigned long rate)
                return idx;
 
        value = sh_clk_read(clk);
-       value &= ~0x3f;
-       value |= idx;
+       value &= ~(clk->div_mask << clk->enable_bit);
+       value |= (idx << clk->enable_bit);
        sh_clk_write(value, clk);
+
+       /* XXX: Should use a post-change notifier */
+       if (dt->kick)
+               dt->kick(clk);
+
        return 0;
 }
 
-static int sh_clk_div6_enable(struct clk *clk)
+static int sh_clk_div_enable(struct clk *clk)
 {
-       unsigned long value;
-       int ret;
-
-       ret = sh_clk_div6_set_rate(clk, clk->rate);
-       if (ret == 0) {
-               value = sh_clk_read(clk);
-               value &= ~0x100; /* clear stop bit to enable clock */
-               sh_clk_write(value, clk);
-       }
-       return ret;
+       sh_clk_write(sh_clk_read(clk) & ~CPG_CKSTP_BIT, clk);
+       return 0;
 }
 
-static void sh_clk_div6_disable(struct clk *clk)
+static void sh_clk_div_disable(struct clk *clk)
 {
-       unsigned long value;
+       unsigned int val;
 
-       value = sh_clk_read(clk);
-       value |= 0x100; /* stop clock */
-       value |= 0x3f; /* VDIV bits must be non-zero, overwrite divider */
-       sh_clk_write(value, clk);
+       val = sh_clk_read(clk);
+       val |= CPG_CKSTP_BIT;
+
+       /*
+        * div6 clocks require the divisor field to be non-zero or the
+        * above CKSTP toggle silently fails. Ensure that the divisor
+        * array is reset to its initial state on disable.
+        */
+       if (clk->flags & CLK_MASK_DIV_ON_DISABLE)
+               val |= clk->div_mask;
+
+       sh_clk_write(val, clk);
 }
 
-static struct sh_clk_ops sh_clk_div6_clk_ops = {
-       .recalc         = sh_clk_div6_recalc,
+static struct sh_clk_ops sh_clk_div_clk_ops = {
+       .recalc         = sh_clk_div_recalc,
+       .set_rate       = sh_clk_div_set_rate,
        .round_rate     = sh_clk_div_round_rate,
-       .set_rate       = sh_clk_div6_set_rate,
-       .enable         = sh_clk_div6_enable,
-       .disable        = sh_clk_div6_disable,
 };
 
-static struct sh_clk_ops sh_clk_div6_reparent_clk_ops = {
-       .recalc         = sh_clk_div6_recalc,
+static struct sh_clk_ops sh_clk_div_enable_clk_ops = {
+       .recalc         = sh_clk_div_recalc,
+       .set_rate       = sh_clk_div_set_rate,
        .round_rate     = sh_clk_div_round_rate,
-       .set_rate       = sh_clk_div6_set_rate,
-       .enable         = sh_clk_div6_enable,
-       .disable        = sh_clk_div6_disable,
-       .set_parent     = sh_clk_div6_set_parent,
+       .enable         = sh_clk_div_enable,
+       .disable        = sh_clk_div_disable,
 };
 
 static int __init sh_clk_init_parent(struct clk *clk)
@@ -218,12 +194,12 @@ static int __init sh_clk_init_parent(struct clk *clk)
        return 0;
 }
 
-static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
-                                          struct sh_clk_ops *ops)
+static int __init sh_clk_div_register_ops(struct clk *clks, int nr,
+                       struct clk_div_table *table, struct sh_clk_ops *ops)
 {
        struct clk *clkp;
        void *freq_table;
-       int nr_divs = sh_clk_div6_table.nr_divisors;
+       int nr_divs = table->div_mult_table->nr_divisors;
        int freq_table_size = sizeof(struct cpufreq_frequency_table);
        int ret = 0;
        int k;
@@ -231,7 +207,7 @@ static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
        freq_table_size *= (nr_divs + 1);
        freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
        if (!freq_table) {
-               pr_err("sh_clk_div6_register: unable to alloc memory\n");
+               pr_err("%s: unable to alloc memory\n", __func__);
                return -ENOMEM;
        }
 
@@ -239,47 +215,98 @@ static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
                clkp = clks + k;
 
                clkp->ops = ops;
+               clkp->priv = table;
+
                clkp->freq_table = freq_table + (k * freq_table_size);
                clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
-               ret = clk_register(clkp);
-               if (ret < 0)
-                       break;
 
-               ret = sh_clk_init_parent(clkp);
+               ret = clk_register(clkp);
+               if (ret == 0)
+                       ret = sh_clk_init_parent(clkp);
        }
 
        return ret;
 }
 
-int __init sh_clk_div6_register(struct clk *clks, int nr)
-{
-       return sh_clk_div6_register_ops(clks, nr, &sh_clk_div6_clk_ops);
-}
+/*
+ * div6 support
+ */
+static int sh_clk_div6_divisors[64] = {
+       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+       33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+       49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
+};
 
-int __init sh_clk_div6_reparent_register(struct clk *clks, int nr)
-{
-       return sh_clk_div6_register_ops(clks, nr,
-                                       &sh_clk_div6_reparent_clk_ops);
-}
+static struct clk_div_mult_table div6_div_mult_table = {
+       .divisors = sh_clk_div6_divisors,
+       .nr_divisors = ARRAY_SIZE(sh_clk_div6_divisors),
+};
 
-static unsigned long sh_clk_div4_recalc(struct clk *clk)
+static struct clk_div_table sh_clk_div6_table = {
+       .div_mult_table = &div6_div_mult_table,
+};
+
+static int sh_clk_div6_set_parent(struct clk *clk, struct clk *parent)
 {
-       struct clk_div4_table *d4t = clk->priv;
-       struct clk_div_mult_table *table = d4t->div_mult_table;
-       unsigned int idx;
+       struct clk_div_mult_table *table = clk_to_div_mult_table(clk);
+       u32 value;
+       int ret, i;
 
+       if (!clk->parent_table || !clk->parent_num)
+               return -EINVAL;
+
+       /* Search the parent */
+       for (i = 0; i < clk->parent_num; i++)
+               if (clk->parent_table[i] == parent)
+                       break;
+
+       if (i == clk->parent_num)
+               return -ENODEV;
+
+       ret = clk_reparent(clk, parent);
+       if (ret < 0)
+               return ret;
+
+       value = sh_clk_read(clk) &
+               ~(((1 << clk->src_width) - 1) << clk->src_shift);
+
+       sh_clk_write(value | (i << clk->src_shift), clk);
+
+       /* Rebuild the frequency table */
        clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, &clk->arch_flags);
+                            table, NULL);
 
-       idx = (sh_clk_read(clk) >> clk->enable_bit) & 0x000f;
+       return 0;
+}
 
-       return clk->freq_table[idx].frequency;
+static struct sh_clk_ops sh_clk_div6_reparent_clk_ops = {
+       .recalc         = sh_clk_div_recalc,
+       .round_rate     = sh_clk_div_round_rate,
+       .set_rate       = sh_clk_div_set_rate,
+       .enable         = sh_clk_div_enable,
+       .disable        = sh_clk_div_disable,
+       .set_parent     = sh_clk_div6_set_parent,
+};
+
+int __init sh_clk_div6_register(struct clk *clks, int nr)
+{
+       return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table,
+                                      &sh_clk_div_enable_clk_ops);
+}
+
+int __init sh_clk_div6_reparent_register(struct clk *clks, int nr)
+{
+       return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table,
+                                      &sh_clk_div6_reparent_clk_ops);
 }
 
+/*
+ * div4 support
+ */
 static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
 {
-       struct clk_div4_table *d4t = clk->priv;
-       struct clk_div_mult_table *table = d4t->div_mult_table;
+       struct clk_div_mult_table *table = clk_to_div_mult_table(clk);
        u32 value;
        int ret;
 
@@ -306,107 +333,31 @@ static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
        return 0;
 }
 
-static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate)
-{
-       struct clk_div4_table *d4t = clk->priv;
-       unsigned long value;
-       int idx = clk_rate_table_find(clk, clk->freq_table, rate);
-       if (idx < 0)
-               return idx;
-
-       value = sh_clk_read(clk);
-       value &= ~(0xf << clk->enable_bit);
-       value |= (idx << clk->enable_bit);
-       sh_clk_write(value, clk);
-
-       if (d4t->kick)
-               d4t->kick(clk);
-
-       return 0;
-}
-
-static int sh_clk_div4_enable(struct clk *clk)
-{
-       sh_clk_write(sh_clk_read(clk) & ~(1 << 8), clk);
-       return 0;
-}
-
-static void sh_clk_div4_disable(struct clk *clk)
-{
-       sh_clk_write(sh_clk_read(clk) | (1 << 8), clk);
-}
-
-static struct sh_clk_ops sh_clk_div4_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
-       .round_rate     = sh_clk_div_round_rate,
-};
-
-static struct sh_clk_ops sh_clk_div4_enable_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
-       .round_rate     = sh_clk_div_round_rate,
-       .enable         = sh_clk_div4_enable,
-       .disable        = sh_clk_div4_disable,
-};
-
 static struct sh_clk_ops sh_clk_div4_reparent_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
+       .recalc         = sh_clk_div_recalc,
+       .set_rate       = sh_clk_div_set_rate,
        .round_rate     = sh_clk_div_round_rate,
-       .enable         = sh_clk_div4_enable,
-       .disable        = sh_clk_div4_disable,
+       .enable         = sh_clk_div_enable,
+       .disable        = sh_clk_div_disable,
        .set_parent     = sh_clk_div4_set_parent,
 };
 
-static int __init sh_clk_div4_register_ops(struct clk *clks, int nr,
-                       struct clk_div4_table *table, struct sh_clk_ops *ops)
-{
-       struct clk *clkp;
-       void *freq_table;
-       int nr_divs = table->div_mult_table->nr_divisors;
-       int freq_table_size = sizeof(struct cpufreq_frequency_table);
-       int ret = 0;
-       int k;
-
-       freq_table_size *= (nr_divs + 1);
-       freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
-       if (!freq_table) {
-               pr_err("sh_clk_div4_register: unable to alloc memory\n");
-               return -ENOMEM;
-       }
-
-       for (k = 0; !ret && (k < nr); k++) {
-               clkp = clks + k;
-
-               clkp->ops = ops;
-               clkp->priv = table;
-
-               clkp->freq_table = freq_table + (k * freq_table_size);
-               clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
-
-               ret = clk_register(clkp);
-       }
-
-       return ret;
-}
-
 int __init sh_clk_div4_register(struct clk *clks, int nr,
                                struct clk_div4_table *table)
 {
-       return sh_clk_div4_register_ops(clks, nr, table, &sh_clk_div4_clk_ops);
+       return sh_clk_div_register_ops(clks, nr, table, &sh_clk_div_clk_ops);
 }
 
 int __init sh_clk_div4_enable_register(struct clk *clks, int nr,
                                struct clk_div4_table *table)
 {
-       return sh_clk_div4_register_ops(clks, nr, table,
-                                       &sh_clk_div4_enable_clk_ops);
+       return sh_clk_div_register_ops(clks, nr, table,
+                                      &sh_clk_div_enable_clk_ops);
 }
 
 int __init sh_clk_div4_reparent_register(struct clk *clks, int nr,
                                struct clk_div4_table *table)
 {
-       return sh_clk_div4_register_ops(clks, nr, table,
-                                       &sh_clk_div4_reparent_clk_ops);
+       return sh_clk_div_register_ops(clks, nr, table,
+                                      &sh_clk_div4_reparent_clk_ops);
 }
index bb5df868d77ae8f1a05496c8130cafc0f926d505..44f006d09471cfce4fd204b88e1893928f0a1093 100644 (file)
@@ -1,4 +1,4 @@
-obj-y  := access.o chip.o core.o dynamic.o handle.o virq.o
+obj-y  := access.o chip.o core.o handle.o virq.o
 
 obj-$(CONFIG_INTC_BALANCING)           += balancing.o
 obj-$(CONFIG_INTC_USERIMASK)           += userimask.o
diff --git a/drivers/sh/intc/dynamic.c b/drivers/sh/intc/dynamic.c
deleted file mode 100644 (file)
index 14eb01e..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Dynamic IRQ management
- *
- * Copyright (C) 2010  Paul Mundt
- *
- * Modelled after arch/x86/kernel/apic/io_apic.c
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- */
-#define pr_fmt(fmt) "intc: " fmt
-
-#include <linux/irq.h>
-#include <linux/bitmap.h>
-#include <linux/spinlock.h>
-#include <linux/module.h>
-#include "internals.h" /* only for activate_irq() damage.. */
-
-/*
- * The IRQ bitmap provides a global map of bound IRQ vectors for a
- * given platform. Allocation of IRQs are either static through the CPU
- * vector map, or dynamic in the case of board mux vectors or MSI.
- *
- * As this is a central point for all IRQ controllers on the system,
- * each of the available sources are mapped out here. This combined with
- * sparseirq makes it quite trivial to keep the vector map tightly packed
- * when dynamically creating IRQs, as well as tying in to otherwise
- * unused irq_desc positions in the sparse array.
- */
-
-/*
- * Dynamic IRQ allocation and deallocation
- */
-unsigned int create_irq_nr(unsigned int irq_want, int node)
-{
-       int irq = irq_alloc_desc_at(irq_want, node);
-       if (irq < 0)
-               return 0;
-
-       activate_irq(irq);
-       return irq;
-}
-
-int create_irq(void)
-{
-       int irq = irq_alloc_desc(numa_node_id());
-       if (irq >= 0)
-               activate_irq(irq);
-
-       return irq;
-}
-
-void destroy_irq(unsigned int irq)
-{
-       irq_free_desc(irq);
-}
index 93cec21e788bdb7b4024fa5237b9d7a8801c1333..f30ac9354ff248f316fb96a26d534884faa8bf5d 100644 (file)
@@ -219,12 +219,14 @@ restart:
                if (radix_tree_deref_retry(entry))
                        goto restart;
 
-               irq = create_irq();
+               irq = irq_alloc_desc(numa_node_id());
                if (unlikely(irq < 0)) {
                        pr_err("no more free IRQs, bailing..\n");
                        break;
                }
 
+               activate_irq(irq);
+
                pr_info("Setting up a chained VIRQ from %d -> %d\n",
                        irq, entry->pirq);
 
index c513b73cd7cb8499a7ac61edb3789e7e24a8bfab..50910913b2687928bf59b4053b92beb21e569918 100644 (file)
@@ -18,7 +18,6 @@ struct clk_mapping {
        struct kref             ref;
 };
 
-
 struct sh_clk_ops {
 #ifdef CONFIG_SH_CLK_CPG_LEGACY
        void (*init)(struct clk *clk);
@@ -31,6 +30,10 @@ struct sh_clk_ops {
        long (*round_rate)(struct clk *clk, unsigned long rate);
 };
 
+#define SH_CLK_DIV_MSK(div)    ((1 << (div)) - 1)
+#define SH_CLK_DIV4_MSK                SH_CLK_DIV_MSK(4)
+#define SH_CLK_DIV6_MSK                SH_CLK_DIV_MSK(6)
+
 struct clk {
        struct list_head        node;
        struct clk              *parent;
@@ -52,6 +55,7 @@ struct clk {
        unsigned int            enable_bit;
        void __iomem            *mapped_reg;
 
+       unsigned int            div_mask;
        unsigned long           arch_flags;
        void                    *priv;
        struct clk_mapping      *mapping;
@@ -65,6 +69,8 @@ struct clk {
 #define CLK_ENABLE_REG_16BIT   BIT(2)
 #define CLK_ENABLE_REG_8BIT    BIT(3)
 
+#define CLK_MASK_DIV_ON_DISABLE        BIT(4)
+
 #define CLK_ENABLE_REG_MASK    (CLK_ENABLE_REG_32BIT | \
                                 CLK_ENABLE_REG_16BIT | \
                                 CLK_ENABLE_REG_8BIT)
@@ -146,14 +152,17 @@ static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr)
        .enable_reg = (void __iomem *)_reg,                     \
        .enable_bit = _shift,                                   \
        .arch_flags = _div_bitmap,                              \
+       .div_mask = SH_CLK_DIV4_MSK,                            \
        .flags = _flags,                                        \
 }
 
-struct clk_div4_table {
+struct clk_div_table {
        struct clk_div_mult_table *div_mult_table;
        void (*kick)(struct clk *clk);
 };
 
+#define clk_div4_table clk_div_table
+
 int sh_clk_div4_register(struct clk *clks, int nr,
                         struct clk_div4_table *table);
 int sh_clk_div4_enable_register(struct clk *clks, int nr,
@@ -165,7 +174,9 @@ int sh_clk_div4_reparent_register(struct clk *clks, int nr,
                        _num_parents, _src_shift, _src_width)   \
 {                                                              \
        .enable_reg = (void __iomem *)_reg,                     \
-       .flags = _flags,                                        \
+       .enable_bit = 0, /* unused */                           \
+       .flags = _flags | CLK_MASK_DIV_ON_DISABLE,              \
+       .div_mask = SH_CLK_DIV6_MSK,                            \
        .parent_table = _parents,                               \
        .parent_num = _num_parents,                             \
        .src_shift = _src_shift,                                \
@@ -176,7 +187,9 @@ int sh_clk_div4_reparent_register(struct clk *clks, int nr,
 {                                                              \
        .parent         = _parent,                              \
        .enable_reg     = (void __iomem *)_reg,                 \
-       .flags          = _flags,                               \
+       .enable_bit     = 0,    /* unused */                    \
+       .div_mask       = SH_CLK_DIV6_MSK,                      \
+       .flags          = _flags | CLK_MASK_DIV_ON_DISABLE,     \
 }
 
 int sh_clk_div6_register(struct clk *clks, int nr);