mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-16 23:45:31 +08:00
4d486e0083
Commit0e6e01ff69
("CPM/QE: use genalloc to manage CPM/QE muram") has changed the way muram is managed. genalloc uses kmalloc(), hence requires the SLAB to be up and running. On powerpc 8xx, cpm_reset() is called early during startup. cpm_reset() then calls cpm_muram_init() before SLAB is available, hence the following Oops. cpm_reset() cannot be called during initcalls because the CPM is needed for console. This patch removes the call to cpm_muram_init() from cpm_reset(). cpm_muram_init() will be called from a new function called cpm_init() which is declared as subsys_initcall, unless cpm_muram_alloc() is called earlier for the serial console in which case cpm_muram_init() will be called from there. The reason for calling it from two places is that some drivers (e.g. i2c-cpm) need some of the initialisations done by cpm_muram_init() but don't call cpm_muram_alloc(). The console driver calls cpm_muram_alloc() but some platforms might not use the CPM serial ports for console. [ 0.000000] Unable to handle kernel paging request for data at address 0x00000008 [ 0.000000] Faulting instruction address: 0xc01acce0 [ 0.000000] Oops: Kernel access of bad area, sig: 11 [#1] [ 0.000000] PREEMPT CMPC885 [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.4.14-g0886ed8 #5 [ 0.000000] task: c05183e0 ti: c0536000 task.ti: c0536000 [ 0.000000] NIP: c01acce0 LR: c0011068 CTR: 00000000 [ 0.000000] REGS: c0537e50 TRAP: 0300 Not tainted (4.4.14-s3k-dev-g0886ed8-svn) [ 0.000000] MSR: 00001032 <ME,IR,DR,RI> CR: 28044428 XER: 00000000 [ 0.000000] DAR: 00000008 DSISR: c0000000 GPR00: c0011068 c0537f00 c05183e0 00000000 00009000 ffffffff 00000bc0 ffffffff GPR08: ff003000 ff00b000 ff003bbf 00000000 22044422 100d43a8 00000000 07ff94e8 GPR16: 00000000 07bb5d70 00000000 07ff81f4 07ff81f4 07ff81f4 00000000 00000000 GPR24: 07ffb3a0 07fe7628 c0550000 c7ffa190 c0540000 ff003bbf 00000000 00000001 [ 0.000000] NIP [c01acce0] gen_pool_add_virt+0x14/0xdc [ 0.000000] LR [c0011068] cpm_muram_init+0xd4/0x18c [ 0.000000] Call Trace: [ 0.000000] [c0537f00] [00000200] 0x200 (unreliable) [ 0.000000] [c0537f20] [c0011068] cpm_muram_init+0xd4/0x18c [ 0.000000] [c0537f70] [c0494684] cpm_reset+0xb4/0xc8 [ 0.000000] [c0537f90] [c0494c64] cmpc885_setup_arch+0x10/0x30 [ 0.000000] [c0537fa0] [c0493cd4] setup_arch+0x130/0x168 [ 0.000000] [c0537fb0] [c04906bc] start_kernel+0x88/0x380 [ 0.000000] [c0537ff0] [c0002224] start_here+0x38/0x98 [ 0.000000] Instruction dump: [ 0.000000] 91430010 91430014 80010014 83e1000c 7c0803a6 38210010 4e800020 7c0802a6 [ 0.000000] 9421ffe0 bf61000c 90010024 7c7e1b78 <80630008> 7c9c2378 7cc31c30 3863001f [ 0.000000] ---[ end trace dc8fa200cb88537f ]--- fixes:0e6e01ff69
("CPM/QE: use genalloc to manage CPM/QE muram") Cc: stable@vger.linux.org Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> [scottwood: Removed some string changes unrelated to bugfix] Signed-off-by: Scott Wood <oss@buserror.net>
218 lines
5.2 KiB
C
218 lines
5.2 KiB
C
/*
|
|
* Common CPM code
|
|
*
|
|
* Author: Scott Wood <scottwood@freescale.com>
|
|
*
|
|
* Copyright 2007-2008,2010 Freescale Semiconductor, Inc.
|
|
*
|
|
* Some parts derived from commproc.c/cpm2_common.c, which is:
|
|
* Copyright (c) 1997 Dan error_act (dmalek@jlc.net)
|
|
* Copyright (c) 1999-2001 Dan Malek <dan@embeddedalley.com>
|
|
* Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
|
|
* 2006 (c) MontaVista Software, Inc.
|
|
* Vitaly Bordug <vbordug@ru.mvista.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/export.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <asm/udbg.h>
|
|
#include <asm/io.h>
|
|
#include <asm/cpm.h>
|
|
#include <asm/fixmap.h>
|
|
#include <soc/fsl/qe/qe.h>
|
|
|
|
#include <mm/mmu_decl.h>
|
|
|
|
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
|
#include <linux/of_gpio.h>
|
|
#endif
|
|
|
|
static int __init cpm_init(void)
|
|
{
|
|
struct device_node *np;
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,cpm1");
|
|
if (!np)
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,cpm2");
|
|
if (!np)
|
|
return -ENODEV;
|
|
cpm_muram_init();
|
|
of_node_put(np);
|
|
return 0;
|
|
}
|
|
subsys_initcall(cpm_init);
|
|
|
|
#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
|
|
static u32 __iomem *cpm_udbg_txdesc;
|
|
static u8 __iomem *cpm_udbg_txbuf;
|
|
|
|
static void udbg_putc_cpm(char c)
|
|
{
|
|
if (c == '\n')
|
|
udbg_putc_cpm('\r');
|
|
|
|
while (in_be32(&cpm_udbg_txdesc[0]) & 0x80000000)
|
|
;
|
|
|
|
out_8(cpm_udbg_txbuf, c);
|
|
out_be32(&cpm_udbg_txdesc[0], 0xa0000001);
|
|
}
|
|
|
|
void __init udbg_init_cpm(void)
|
|
{
|
|
#ifdef CONFIG_PPC_8xx
|
|
cpm_udbg_txdesc = (u32 __iomem __force *)
|
|
(CONFIG_PPC_EARLY_DEBUG_CPM_ADDR - PHYS_IMMR_BASE +
|
|
VIRT_IMMR_BASE);
|
|
cpm_udbg_txbuf = (u8 __iomem __force *)
|
|
(in_be32(&cpm_udbg_txdesc[1]) - PHYS_IMMR_BASE +
|
|
VIRT_IMMR_BASE);
|
|
#else
|
|
cpm_udbg_txdesc = (u32 __iomem __force *)
|
|
CONFIG_PPC_EARLY_DEBUG_CPM_ADDR;
|
|
cpm_udbg_txbuf = (u8 __iomem __force *)in_be32(&cpm_udbg_txdesc[1]);
|
|
#endif
|
|
|
|
if (cpm_udbg_txdesc) {
|
|
#ifdef CONFIG_CPM2
|
|
setbat(1, 0xf0000000, 0xf0000000, 1024*1024, PAGE_KERNEL_NCG);
|
|
#endif
|
|
udbg_putc = udbg_putc_cpm;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
|
|
|
struct cpm2_ioports {
|
|
u32 dir, par, sor, odr, dat;
|
|
u32 res[3];
|
|
};
|
|
|
|
struct cpm2_gpio32_chip {
|
|
struct of_mm_gpio_chip mm_gc;
|
|
spinlock_t lock;
|
|
|
|
/* shadowed data register to clear/set bits safely */
|
|
u32 cpdata;
|
|
};
|
|
|
|
static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc)
|
|
{
|
|
struct cpm2_gpio32_chip *cpm2_gc =
|
|
container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc);
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
|
|
cpm2_gc->cpdata = in_be32(&iop->dat);
|
|
}
|
|
|
|
static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
u32 pin_mask;
|
|
|
|
pin_mask = 1 << (31 - gpio);
|
|
|
|
return !!(in_be32(&iop->dat) & pin_mask);
|
|
}
|
|
|
|
static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask,
|
|
int value)
|
|
{
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(&mm_gc->gc);
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
|
|
if (value)
|
|
cpm2_gc->cpdata |= pin_mask;
|
|
else
|
|
cpm2_gc->cpdata &= ~pin_mask;
|
|
|
|
out_be32(&iop->dat, cpm2_gc->cpdata);
|
|
}
|
|
|
|
static void cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
|
unsigned long flags;
|
|
u32 pin_mask = 1 << (31 - gpio);
|
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
|
|
|
__cpm2_gpio32_set(mm_gc, pin_mask, value);
|
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
}
|
|
|
|
static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
unsigned long flags;
|
|
u32 pin_mask = 1 << (31 - gpio);
|
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
|
|
|
setbits32(&iop->dir, pin_mask);
|
|
__cpm2_gpio32_set(mm_gc, pin_mask, val);
|
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
unsigned long flags;
|
|
u32 pin_mask = 1 << (31 - gpio);
|
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
|
|
|
clrbits32(&iop->dir, pin_mask);
|
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int cpm2_gpiochip_add32(struct device_node *np)
|
|
{
|
|
struct cpm2_gpio32_chip *cpm2_gc;
|
|
struct of_mm_gpio_chip *mm_gc;
|
|
struct gpio_chip *gc;
|
|
|
|
cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
|
|
if (!cpm2_gc)
|
|
return -ENOMEM;
|
|
|
|
spin_lock_init(&cpm2_gc->lock);
|
|
|
|
mm_gc = &cpm2_gc->mm_gc;
|
|
gc = &mm_gc->gc;
|
|
|
|
mm_gc->save_regs = cpm2_gpio32_save_regs;
|
|
gc->ngpio = 32;
|
|
gc->direction_input = cpm2_gpio32_dir_in;
|
|
gc->direction_output = cpm2_gpio32_dir_out;
|
|
gc->get = cpm2_gpio32_get;
|
|
gc->set = cpm2_gpio32_set;
|
|
|
|
return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
|
|
}
|
|
#endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */
|