mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-16 08:26:53 +07: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>
368 lines
8.5 KiB
C
368 lines
8.5 KiB
C
/*
|
|
* General Purpose functions for the global management of the
|
|
* 8260 Communication Processor Module.
|
|
* Copyright (c) 1999-2001 Dan Malek <dan@embeddedalley.com>
|
|
* Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
|
|
* 2.3.99 Updates
|
|
*
|
|
* 2006 (c) MontaVista Software, Inc.
|
|
* Vitaly Bordug <vbordug@ru.mvista.com>
|
|
* Merged to arch/powerpc from arch/ppc/syslib/cpm2_common.c
|
|
*
|
|
* This file is licensed under the terms of the GNU General Public License
|
|
* version 2. This program is licensed "as is" without any warranty of any
|
|
* kind, whether express or implied.
|
|
*/
|
|
|
|
/*
|
|
*
|
|
* In addition to the individual control of the communication
|
|
* channels, there are a few functions that globally affect the
|
|
* communication processor.
|
|
*
|
|
* Buffer descriptors must be allocated from the dual ported memory
|
|
* space. The allocator for that is here. When the communication
|
|
* process is reset, we reclaim the memory available. There is
|
|
* currently no deallocator for this memory.
|
|
*/
|
|
#include <linux/errno.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/param.h>
|
|
#include <linux/string.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
|
|
#include <asm/io.h>
|
|
#include <asm/irq.h>
|
|
#include <asm/mpc8260.h>
|
|
#include <asm/page.h>
|
|
#include <asm/pgtable.h>
|
|
#include <asm/cpm2.h>
|
|
#include <asm/rheap.h>
|
|
#include <asm/fs_pd.h>
|
|
|
|
#include <sysdev/fsl_soc.h>
|
|
|
|
cpm_cpm2_t __iomem *cpmp; /* Pointer to comm processor space */
|
|
|
|
/* We allocate this here because it is used almost exclusively for
|
|
* the communication processor devices.
|
|
*/
|
|
cpm2_map_t __iomem *cpm2_immr;
|
|
EXPORT_SYMBOL(cpm2_immr);
|
|
|
|
#define CPM_MAP_SIZE (0x40000) /* 256k - the PQ3 reserve this amount
|
|
of space for CPM as it is larger
|
|
than on PQ2 */
|
|
|
|
void __init cpm2_reset(void)
|
|
{
|
|
#ifdef CONFIG_PPC_85xx
|
|
cpm2_immr = ioremap(get_immrbase() + 0x80000, CPM_MAP_SIZE);
|
|
#else
|
|
cpm2_immr = ioremap(get_immrbase(), CPM_MAP_SIZE);
|
|
#endif
|
|
|
|
/* Tell everyone where the comm processor resides.
|
|
*/
|
|
cpmp = &cpm2_immr->im_cpm;
|
|
|
|
#ifndef CONFIG_PPC_EARLY_DEBUG_CPM
|
|
/* Reset the CPM.
|
|
*/
|
|
cpm_command(CPM_CR_RST, 0);
|
|
#endif
|
|
}
|
|
|
|
static DEFINE_SPINLOCK(cmd_lock);
|
|
|
|
#define MAX_CR_CMD_LOOPS 10000
|
|
|
|
int cpm_command(u32 command, u8 opcode)
|
|
{
|
|
int i, ret;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&cmd_lock, flags);
|
|
|
|
ret = 0;
|
|
out_be32(&cpmp->cp_cpcr, command | opcode | CPM_CR_FLG);
|
|
for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
|
|
if ((in_be32(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
|
|
goto out;
|
|
|
|
printk(KERN_ERR "%s(): Not able to issue CPM command\n", __func__);
|
|
ret = -EIO;
|
|
out:
|
|
spin_unlock_irqrestore(&cmd_lock, flags);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(cpm_command);
|
|
|
|
/* Set a baud rate generator. This needs lots of work. There are
|
|
* eight BRGs, which can be connected to the CPM channels or output
|
|
* as clocks. The BRGs are in two different block of internal
|
|
* memory mapped space.
|
|
* The baud rate clock is the system clock divided by something.
|
|
* It was set up long ago during the initial boot phase and is
|
|
* is given to us.
|
|
* Baud rate clocks are zero-based in the driver code (as that maps
|
|
* to port numbers). Documentation uses 1-based numbering.
|
|
*/
|
|
void __cpm2_setbrg(uint brg, uint rate, uint clk, int div16, int src)
|
|
{
|
|
u32 __iomem *bp;
|
|
u32 val;
|
|
|
|
/* This is good enough to get SMCs running.....
|
|
*/
|
|
if (brg < 4) {
|
|
bp = cpm2_map_size(im_brgc1, 16);
|
|
} else {
|
|
bp = cpm2_map_size(im_brgc5, 16);
|
|
brg -= 4;
|
|
}
|
|
bp += brg;
|
|
/* Round the clock divider to the nearest integer. */
|
|
val = (((clk * 2 / rate) - 1) & ~1) | CPM_BRG_EN | src;
|
|
if (div16)
|
|
val |= CPM_BRG_DIV16;
|
|
|
|
out_be32(bp, val);
|
|
cpm2_unmap(bp);
|
|
}
|
|
EXPORT_SYMBOL(__cpm2_setbrg);
|
|
|
|
int cpm2_clk_setup(enum cpm_clk_target target, int clock, int mode)
|
|
{
|
|
int ret = 0;
|
|
int shift;
|
|
int i, bits = 0;
|
|
cpmux_t __iomem *im_cpmux;
|
|
u32 __iomem *reg;
|
|
u32 m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{CPM_CLK_SCC2, CPM_BRG1, 0},
|
|
{CPM_CLK_SCC2, CPM_BRG2, 1},
|
|
{CPM_CLK_SCC2, CPM_BRG3, 2},
|
|
{CPM_CLK_SCC2, CPM_BRG4, 3},
|
|
{CPM_CLK_SCC2, CPM_CLK11, 4},
|
|
{CPM_CLK_SCC2, CPM_CLK12, 5},
|
|
{CPM_CLK_SCC2, CPM_CLK3, 6},
|
|
{CPM_CLK_SCC2, CPM_CLK4, 7},
|
|
{CPM_CLK_SCC3, CPM_BRG1, 0},
|
|
{CPM_CLK_SCC3, CPM_BRG2, 1},
|
|
{CPM_CLK_SCC3, CPM_BRG3, 2},
|
|
{CPM_CLK_SCC3, CPM_BRG4, 3},
|
|
{CPM_CLK_SCC3, CPM_CLK5, 4},
|
|
{CPM_CLK_SCC3, CPM_CLK6, 5},
|
|
{CPM_CLK_SCC3, CPM_CLK7, 6},
|
|
{CPM_CLK_SCC3, CPM_CLK8, 7},
|
|
{CPM_CLK_SCC4, CPM_BRG1, 0},
|
|
{CPM_CLK_SCC4, CPM_BRG2, 1},
|
|
{CPM_CLK_SCC4, CPM_BRG3, 2},
|
|
{CPM_CLK_SCC4, CPM_BRG4, 3},
|
|
{CPM_CLK_SCC4, CPM_CLK5, 4},
|
|
{CPM_CLK_SCC4, CPM_CLK6, 5},
|
|
{CPM_CLK_SCC4, CPM_CLK7, 6},
|
|
{CPM_CLK_SCC4, CPM_CLK8, 7},
|
|
};
|
|
|
|
im_cpmux = cpm2_map(im_cpmux);
|
|
|
|
switch (target) {
|
|
case CPM_CLK_SCC1:
|
|
reg = &im_cpmux->cmx_scr;
|
|
shift = 24;
|
|
break;
|
|
case CPM_CLK_SCC2:
|
|
reg = &im_cpmux->cmx_scr;
|
|
shift = 16;
|
|
break;
|
|
case CPM_CLK_SCC3:
|
|
reg = &im_cpmux->cmx_scr;
|
|
shift = 8;
|
|
break;
|
|
case CPM_CLK_SCC4:
|
|
reg = &im_cpmux->cmx_scr;
|
|
shift = 0;
|
|
break;
|
|
case CPM_CLK_FCC1:
|
|
reg = &im_cpmux->cmx_fcr;
|
|
shift = 24;
|
|
break;
|
|
case CPM_CLK_FCC2:
|
|
reg = &im_cpmux->cmx_fcr;
|
|
shift = 16;
|
|
break;
|
|
case CPM_CLK_FCC3:
|
|
reg = &im_cpmux->cmx_fcr;
|
|
shift = 8;
|
|
break;
|
|
default:
|
|
printk(KERN_ERR "cpm2_clock_setup: invalid clock target\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
for (i = 0; i < ARRAY_SIZE(clk_map); i++) {
|
|
if (clk_map[i][0] == target && clk_map[i][1] == clock) {
|
|
bits = clk_map[i][2];
|
|
break;
|
|
}
|
|
}
|
|
if (i == ARRAY_SIZE(clk_map))
|
|
ret = -EINVAL;
|
|
|
|
bits <<= shift;
|
|
mask <<= shift;
|
|
|
|
if (mode == CPM_CLK_RTX) {
|
|
bits |= bits << 3;
|
|
mask |= mask << 3;
|
|
} else if (mode == CPM_CLK_RX) {
|
|
bits <<= 3;
|
|
mask <<= 3;
|
|
}
|
|
|
|
out_be32(reg, (in_be32(reg) & ~mask) | bits);
|
|
|
|
cpm2_unmap(im_cpmux);
|
|
return ret;
|
|
}
|
|
|
|
int cpm2_smc_clk_setup(enum cpm_clk_target target, int clock)
|
|
{
|
|
int ret = 0;
|
|
int shift;
|
|
int i, bits = 0;
|
|
cpmux_t __iomem *im_cpmux;
|
|
u8 __iomem *reg;
|
|
u8 mask = 3;
|
|
|
|
u8 clk_map[][3] = {
|
|
{CPM_CLK_SMC1, CPM_BRG1, 0},
|
|
{CPM_CLK_SMC1, CPM_BRG7, 1},
|
|
{CPM_CLK_SMC1, CPM_CLK7, 2},
|
|
{CPM_CLK_SMC1, CPM_CLK9, 3},
|
|
{CPM_CLK_SMC2, CPM_BRG2, 0},
|
|
{CPM_CLK_SMC2, CPM_BRG8, 1},
|
|
{CPM_CLK_SMC2, CPM_CLK4, 2},
|
|
{CPM_CLK_SMC2, CPM_CLK15, 3},
|
|
};
|
|
|
|
im_cpmux = cpm2_map(im_cpmux);
|
|
|
|
switch (target) {
|
|
case CPM_CLK_SMC1:
|
|
reg = &im_cpmux->cmx_smr;
|
|
mask = 3;
|
|
shift = 4;
|
|
break;
|
|
case CPM_CLK_SMC2:
|
|
reg = &im_cpmux->cmx_smr;
|
|
mask = 3;
|
|
shift = 0;
|
|
break;
|
|
default:
|
|
printk(KERN_ERR "cpm2_smc_clock_setup: invalid clock target\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
for (i = 0; i < ARRAY_SIZE(clk_map); i++) {
|
|
if (clk_map[i][0] == target && clk_map[i][1] == clock) {
|
|
bits = clk_map[i][2];
|
|
break;
|
|
}
|
|
}
|
|
if (i == ARRAY_SIZE(clk_map))
|
|
ret = -EINVAL;
|
|
|
|
bits <<= shift;
|
|
mask <<= shift;
|
|
|
|
out_8(reg, (in_8(reg) & ~mask) | bits);
|
|
|
|
cpm2_unmap(im_cpmux);
|
|
return ret;
|
|
}
|
|
|
|
struct cpm2_ioports {
|
|
u32 dir, par, sor, odr, dat;
|
|
u32 res[3];
|
|
};
|
|
|
|
void cpm2_set_pin(int port, int pin, int flags)
|
|
{
|
|
struct cpm2_ioports __iomem *iop =
|
|
(struct cpm2_ioports __iomem *)&cpm2_immr->im_ioport;
|
|
|
|
pin = 1 << (31 - pin);
|
|
|
|
if (flags & CPM_PIN_OUTPUT)
|
|
setbits32(&iop[port].dir, pin);
|
|
else
|
|
clrbits32(&iop[port].dir, pin);
|
|
|
|
if (!(flags & CPM_PIN_GPIO))
|
|
setbits32(&iop[port].par, pin);
|
|
else
|
|
clrbits32(&iop[port].par, pin);
|
|
|
|
if (flags & CPM_PIN_SECONDARY)
|
|
setbits32(&iop[port].sor, pin);
|
|
else
|
|
clrbits32(&iop[port].sor, pin);
|
|
|
|
if (flags & CPM_PIN_OPENDRAIN)
|
|
setbits32(&iop[port].odr, pin);
|
|
else
|
|
clrbits32(&iop[port].odr, pin);
|
|
}
|
|
|
|
static int cpm_init_par_io(void)
|
|
{
|
|
struct device_node *np;
|
|
|
|
for_each_compatible_node(np, NULL, "fsl,cpm2-pario-bank")
|
|
cpm2_gpiochip_add32(np);
|
|
return 0;
|
|
}
|
|
arch_initcall(cpm_init_par_io);
|
|
|