2007-10-07 18:21:26 +04:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC 4xx embedded processors shared devices emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 18:58:45 +03:00
|
|
|
#include "cpu.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/ppc/ppc.h"
|
|
|
|
#include "hw/ppc/ppc4xx.h"
|
2014-07-10 16:01:03 +04:00
|
|
|
#include "hw/boards.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/log.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
#define DEBUG_UIC
|
|
|
|
|
2009-01-16 00:48:06 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG_UIC
|
2009-01-16 01:34:14 +03:00
|
|
|
# define LOG_UIC(...) qemu_log_mask(CPU_LOG_INT, ## __VA_ARGS__)
|
2009-01-16 00:48:06 +03:00
|
|
|
#else
|
|
|
|
# define LOG_UIC(...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 06:03:33 +04:00
|
|
|
static void ppc4xx_reset(void *opaque)
|
|
|
|
{
|
2012-05-04 19:22:20 +04:00
|
|
|
PowerPCCPU *cpu = opaque;
|
2012-02-08 06:03:33 +04:00
|
|
|
|
2012-05-04 19:22:20 +04:00
|
|
|
cpu_reset(CPU(cpu));
|
2012-02-08 06:03:33 +04:00
|
|
|
}
|
|
|
|
|
2007-10-07 18:21:26 +04:00
|
|
|
/*****************************************************************************/
|
2011-04-28 19:20:36 +04:00
|
|
|
/* Generic PowerPC 4xx processor instantiation */
|
2012-12-01 07:47:33 +04:00
|
|
|
PowerPCCPU *ppc4xx_init(const char *cpu_model,
|
|
|
|
clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
|
|
|
|
uint32_t sysclk)
|
2007-10-07 18:21:26 +04:00
|
|
|
{
|
2012-05-04 19:20:11 +04:00
|
|
|
PowerPCCPU *cpu;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *env;
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
/* init CPUs */
|
2017-08-24 19:31:48 +03:00
|
|
|
cpu = POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
|
2012-05-04 19:20:11 +04:00
|
|
|
if (cpu == NULL) {
|
2007-11-10 18:15:54 +03:00
|
|
|
fprintf(stderr, "Unable to find PowerPC %s CPU definition\n",
|
|
|
|
cpu_model);
|
|
|
|
exit(1);
|
2007-10-07 18:21:26 +04:00
|
|
|
}
|
2012-05-04 19:20:11 +04:00
|
|
|
env = &cpu->env;
|
|
|
|
|
2007-10-07 18:21:26 +04:00
|
|
|
cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */
|
|
|
|
cpu_clk->opaque = env;
|
|
|
|
/* Set time-base frequency to sysclk */
|
2011-09-13 08:00:32 +04:00
|
|
|
tb_clk->cb = ppc_40x_timers_init(env, sysclk, PPC_INTERRUPT_PIT);
|
2007-10-07 18:21:26 +04:00
|
|
|
tb_clk->opaque = env;
|
|
|
|
ppc_dcr_init(env, NULL, NULL);
|
|
|
|
/* Register qemu callbacks */
|
2012-05-04 19:22:20 +04:00
|
|
|
qemu_register_reset(ppc4xx_reset, cpu);
|
2007-10-07 18:21:26 +04:00
|
|
|
|
2012-12-01 07:47:33 +04:00
|
|
|
return cpu;
|
2007-10-07 18:21:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* "Universal" Interrupt controller */
|
|
|
|
enum {
|
|
|
|
DCR_UICSR = 0x000,
|
|
|
|
DCR_UICSRS = 0x001,
|
|
|
|
DCR_UICER = 0x002,
|
|
|
|
DCR_UICCR = 0x003,
|
|
|
|
DCR_UICPR = 0x004,
|
|
|
|
DCR_UICTR = 0x005,
|
|
|
|
DCR_UICMSR = 0x006,
|
|
|
|
DCR_UICVR = 0x007,
|
|
|
|
DCR_UICVCR = 0x008,
|
|
|
|
DCR_UICMAX = 0x009,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define UIC_MAX_IRQ 32
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppcuic_t ppcuic_t;
|
|
|
|
struct ppcuic_t {
|
2007-10-07 18:21:26 +04:00
|
|
|
uint32_t dcr_base;
|
|
|
|
int use_vectors;
|
2008-05-04 17:15:24 +04:00
|
|
|
uint32_t level; /* Remembers the state of level-triggered interrupts. */
|
2007-10-07 18:21:26 +04:00
|
|
|
uint32_t uicsr; /* Status register */
|
|
|
|
uint32_t uicer; /* Enable register */
|
|
|
|
uint32_t uiccr; /* Critical register */
|
|
|
|
uint32_t uicpr; /* Polarity register */
|
|
|
|
uint32_t uictr; /* Triggering register */
|
|
|
|
uint32_t uicvcr; /* Vector configuration register */
|
|
|
|
uint32_t uicvr;
|
|
|
|
qemu_irq *irqs;
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppcuic_trigger_irq (ppcuic_t *uic)
|
2007-10-07 18:21:26 +04:00
|
|
|
{
|
|
|
|
uint32_t ir, cr;
|
|
|
|
int start, end, inc, i;
|
|
|
|
|
|
|
|
/* Trigger interrupt if any is pending */
|
|
|
|
ir = uic->uicsr & uic->uicer & (~uic->uiccr);
|
|
|
|
cr = uic->uicsr & uic->uicer & uic->uiccr;
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("%s: uicsr %08" PRIx32 " uicer %08" PRIx32
|
2007-11-24 05:56:36 +03:00
|
|
|
" uiccr %08" PRIx32 "\n"
|
|
|
|
" %08" PRIx32 " ir %08" PRIx32 " cr %08" PRIx32 "\n",
|
|
|
|
__func__, uic->uicsr, uic->uicer, uic->uiccr,
|
2007-10-07 18:21:26 +04:00
|
|
|
uic->uicsr & uic->uicer, ir, cr);
|
|
|
|
if (ir != 0x0000000) {
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("Raise UIC interrupt\n");
|
2007-10-07 18:21:26 +04:00
|
|
|
qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_INT]);
|
|
|
|
} else {
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("Lower UIC interrupt\n");
|
2007-10-07 18:21:26 +04:00
|
|
|
qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_INT]);
|
|
|
|
}
|
|
|
|
/* Trigger critical interrupt if any is pending and update vector */
|
|
|
|
if (cr != 0x0000000) {
|
|
|
|
qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_CINT]);
|
|
|
|
if (uic->use_vectors) {
|
|
|
|
/* Compute critical IRQ vector */
|
|
|
|
if (uic->uicvcr & 1) {
|
|
|
|
start = 31;
|
|
|
|
end = 0;
|
|
|
|
inc = -1;
|
|
|
|
} else {
|
|
|
|
start = 0;
|
|
|
|
end = 31;
|
|
|
|
inc = 1;
|
|
|
|
}
|
|
|
|
uic->uicvr = uic->uicvcr & 0xFFFFFFFC;
|
|
|
|
for (i = start; i <= end; i += inc) {
|
|
|
|
if (cr & (1 << i)) {
|
|
|
|
uic->uicvr += (i - start) * 512 * inc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("Raise UIC critical interrupt - "
|
2007-11-24 05:56:36 +03:00
|
|
|
"vector %08" PRIx32 "\n", uic->uicvr);
|
2007-10-07 18:21:26 +04:00
|
|
|
} else {
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("Lower UIC critical interrupt\n");
|
2007-10-07 18:21:26 +04:00
|
|
|
qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_CINT]);
|
|
|
|
uic->uicvr = 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppcuic_set_irq (void *opaque, int irq_num, int level)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppcuic_t *uic;
|
2007-10-07 18:21:26 +04:00
|
|
|
uint32_t mask, sr;
|
|
|
|
|
|
|
|
uic = opaque;
|
2014-03-17 20:00:37 +04:00
|
|
|
mask = 1U << (31-irq_num);
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("%s: irq %d level %d uicsr %08" PRIx32
|
2007-11-24 05:56:36 +03:00
|
|
|
" mask %08" PRIx32 " => %08" PRIx32 " %08" PRIx32 "\n",
|
|
|
|
__func__, irq_num, level,
|
2007-10-07 18:21:26 +04:00
|
|
|
uic->uicsr, mask, uic->uicsr & mask, level << irq_num);
|
|
|
|
if (irq_num < 0 || irq_num > 31)
|
|
|
|
return;
|
|
|
|
sr = uic->uicsr;
|
2008-05-04 17:15:15 +04:00
|
|
|
|
2007-10-07 18:21:26 +04:00
|
|
|
/* Update status register */
|
|
|
|
if (uic->uictr & mask) {
|
|
|
|
/* Edge sensitive interrupt */
|
|
|
|
if (level == 1)
|
|
|
|
uic->uicsr |= mask;
|
|
|
|
} else {
|
|
|
|
/* Level sensitive interrupt */
|
2008-05-04 17:15:24 +04:00
|
|
|
if (level == 1) {
|
2007-10-07 18:21:26 +04:00
|
|
|
uic->uicsr |= mask;
|
2008-05-04 17:15:24 +04:00
|
|
|
uic->level |= mask;
|
|
|
|
} else {
|
2007-10-07 18:21:26 +04:00
|
|
|
uic->uicsr &= ~mask;
|
2008-05-04 17:15:24 +04:00
|
|
|
uic->level &= ~mask;
|
|
|
|
}
|
2007-10-07 18:21:26 +04:00
|
|
|
}
|
2009-01-16 00:48:06 +03:00
|
|
|
LOG_UIC("%s: irq %d level %d sr %" PRIx32 " => "
|
2007-11-24 05:56:36 +03:00
|
|
|
"%08" PRIx32 "\n", __func__, irq_num, level, uic->uicsr, sr);
|
2007-10-07 18:21:26 +04:00
|
|
|
if (sr != uic->uicsr)
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_uic (void *opaque, int dcrn)
|
2007-10-07 18:21:26 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppcuic_t *uic;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
uic = opaque;
|
|
|
|
dcrn -= uic->dcr_base;
|
|
|
|
switch (dcrn) {
|
|
|
|
case DCR_UICSR:
|
|
|
|
case DCR_UICSRS:
|
|
|
|
ret = uic->uicsr;
|
|
|
|
break;
|
|
|
|
case DCR_UICER:
|
|
|
|
ret = uic->uicer;
|
|
|
|
break;
|
|
|
|
case DCR_UICCR:
|
|
|
|
ret = uic->uiccr;
|
|
|
|
break;
|
|
|
|
case DCR_UICPR:
|
|
|
|
ret = uic->uicpr;
|
|
|
|
break;
|
|
|
|
case DCR_UICTR:
|
|
|
|
ret = uic->uictr;
|
|
|
|
break;
|
|
|
|
case DCR_UICMSR:
|
|
|
|
ret = uic->uicsr & uic->uicer;
|
|
|
|
break;
|
|
|
|
case DCR_UICVR:
|
|
|
|
if (!uic->use_vectors)
|
|
|
|
goto no_read;
|
|
|
|
ret = uic->uicvr;
|
|
|
|
break;
|
|
|
|
case DCR_UICVCR:
|
|
|
|
if (!uic->use_vectors)
|
|
|
|
goto no_read;
|
|
|
|
ret = uic->uicvcr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
no_read:
|
|
|
|
ret = 0x00000000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_uic (void *opaque, int dcrn, uint32_t val)
|
2007-10-07 18:21:26 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppcuic_t *uic;
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
uic = opaque;
|
|
|
|
dcrn -= uic->dcr_base;
|
2009-12-21 16:02:39 +03:00
|
|
|
LOG_UIC("%s: dcr %d val 0x%x\n", __func__, dcrn, val);
|
2007-10-07 18:21:26 +04:00
|
|
|
switch (dcrn) {
|
|
|
|
case DCR_UICSR:
|
|
|
|
uic->uicsr &= ~val;
|
2008-05-04 17:15:24 +04:00
|
|
|
uic->uicsr |= uic->level;
|
2007-10-07 18:21:26 +04:00
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
case DCR_UICSRS:
|
|
|
|
uic->uicsr |= val;
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
case DCR_UICER:
|
|
|
|
uic->uicer = val;
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
case DCR_UICCR:
|
|
|
|
uic->uiccr = val;
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
case DCR_UICPR:
|
|
|
|
uic->uicpr = val;
|
|
|
|
break;
|
|
|
|
case DCR_UICTR:
|
|
|
|
uic->uictr = val;
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
case DCR_UICMSR:
|
|
|
|
break;
|
|
|
|
case DCR_UICVR:
|
|
|
|
break;
|
|
|
|
case DCR_UICVCR:
|
|
|
|
uic->uicvcr = val & 0xFFFFFFFD;
|
|
|
|
ppcuic_trigger_irq(uic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppcuic_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppcuic_t *uic;
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
uic = opaque;
|
|
|
|
uic->uiccr = 0x00000000;
|
|
|
|
uic->uicer = 0x00000000;
|
|
|
|
uic->uicpr = 0x00000000;
|
|
|
|
uic->uicsr = 0x00000000;
|
|
|
|
uic->uictr = 0x00000000;
|
|
|
|
if (uic->use_vectors) {
|
|
|
|
uic->uicvcr = 0x00000000;
|
|
|
|
uic->uicvr = 0x0000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
qemu_irq *ppcuic_init (CPUPPCState *env, qemu_irq *irqs,
|
2007-10-07 18:21:26 +04:00
|
|
|
uint32_t dcr_base, int has_ssr, int has_vr)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppcuic_t *uic;
|
2007-10-07 18:21:26 +04:00
|
|
|
int i;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
uic = g_malloc0(sizeof(ppcuic_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
uic->dcr_base = dcr_base;
|
|
|
|
uic->irqs = irqs;
|
|
|
|
if (has_vr)
|
|
|
|
uic->use_vectors = 1;
|
|
|
|
for (i = 0; i < DCR_UICMAX; i++) {
|
|
|
|
ppc_dcr_register(env, dcr_base + i, uic,
|
|
|
|
&dcr_read_uic, &dcr_write_uic);
|
2007-10-07 18:21:26 +04:00
|
|
|
}
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(ppcuic_reset, uic);
|
2007-10-07 18:21:26 +04:00
|
|
|
|
|
|
|
return qemu_allocate_irqs(&ppcuic_set_irq, uic, UIC_MAX_IRQ);
|
|
|
|
}
|
2008-12-16 01:59:34 +03:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* SDRAM controller */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_sdram_t ppc4xx_sdram_t;
|
|
|
|
struct ppc4xx_sdram_t {
|
2008-12-16 01:59:34 +03:00
|
|
|
uint32_t addr;
|
|
|
|
int nbanks;
|
2011-08-15 18:17:27 +04:00
|
|
|
MemoryRegion containers[4]; /* used for clipping */
|
|
|
|
MemoryRegion *ram_memories;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr ram_bases[4];
|
|
|
|
hwaddr ram_sizes[4];
|
2008-12-16 01:59:34 +03:00
|
|
|
uint32_t besr0;
|
|
|
|
uint32_t besr1;
|
|
|
|
uint32_t bear;
|
|
|
|
uint32_t cfg;
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t rtr;
|
|
|
|
uint32_t pmit;
|
|
|
|
uint32_t bcr[4];
|
|
|
|
uint32_t tr;
|
|
|
|
uint32_t ecccfg;
|
|
|
|
uint32_t eccesr;
|
|
|
|
qemu_irq irq;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SDRAM0_CFGADDR = 0x010,
|
|
|
|
SDRAM0_CFGDATA = 0x011,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* XXX: TOFIX: some patches have made this code become inconsistent:
|
2012-10-23 14:30:10 +04:00
|
|
|
* there are type inconsistencies, mixing hwaddr, target_ulong
|
2008-12-16 01:59:34 +03:00
|
|
|
* and uint32_t
|
|
|
|
*/
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t sdram_bcr (hwaddr ram_base,
|
|
|
|
hwaddr ram_size)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
|
|
|
uint32_t bcr;
|
|
|
|
|
|
|
|
switch (ram_size) {
|
|
|
|
case (4 * 1024 * 1024):
|
|
|
|
bcr = 0x00000000;
|
|
|
|
break;
|
|
|
|
case (8 * 1024 * 1024):
|
|
|
|
bcr = 0x00020000;
|
|
|
|
break;
|
|
|
|
case (16 * 1024 * 1024):
|
|
|
|
bcr = 0x00040000;
|
|
|
|
break;
|
|
|
|
case (32 * 1024 * 1024):
|
|
|
|
bcr = 0x00060000;
|
|
|
|
break;
|
|
|
|
case (64 * 1024 * 1024):
|
|
|
|
bcr = 0x00080000;
|
|
|
|
break;
|
|
|
|
case (128 * 1024 * 1024):
|
|
|
|
bcr = 0x000A0000;
|
|
|
|
break;
|
|
|
|
case (256 * 1024 * 1024):
|
|
|
|
bcr = 0x000C0000;
|
|
|
|
break;
|
|
|
|
default:
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: invalid RAM size " TARGET_FMT_plx "\n", __func__,
|
|
|
|
ram_size);
|
2008-12-16 01:59:34 +03:00
|
|
|
return 0x00000000;
|
|
|
|
}
|
|
|
|
bcr |= ram_base & 0xFF800000;
|
|
|
|
bcr |= 1;
|
|
|
|
|
|
|
|
return bcr;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static inline hwaddr sdram_base(uint32_t bcr)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
|
|
|
return bcr & 0xFF800000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static target_ulong sdram_size (uint32_t bcr)
|
|
|
|
{
|
|
|
|
target_ulong size;
|
|
|
|
int sh;
|
|
|
|
|
|
|
|
sh = (bcr >> 17) & 0x7;
|
|
|
|
if (sh == 7)
|
|
|
|
size = -1;
|
|
|
|
else
|
|
|
|
size = (4 * 1024 * 1024) << sh;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:27 +04:00
|
|
|
static void sdram_set_bcr(ppc4xx_sdram_t *sdram,
|
|
|
|
uint32_t *bcrp, uint32_t bcr, int enabled)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
2011-08-15 18:17:27 +04:00
|
|
|
unsigned n = bcrp - sdram->bcr;
|
|
|
|
|
2008-12-16 01:59:34 +03:00
|
|
|
if (*bcrp & 0x00000001) {
|
|
|
|
/* Unmap RAM */
|
|
|
|
#ifdef DEBUG_SDRAM
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
|
2008-12-16 01:59:34 +03:00
|
|
|
__func__, sdram_base(*bcrp), sdram_size(*bcrp));
|
|
|
|
#endif
|
2011-08-15 18:17:27 +04:00
|
|
|
memory_region_del_subregion(get_system_memory(),
|
|
|
|
&sdram->containers[n]);
|
|
|
|
memory_region_del_subregion(&sdram->containers[n],
|
|
|
|
&sdram->ram_memories[n]);
|
2014-06-11 14:42:01 +04:00
|
|
|
object_unparent(OBJECT(&sdram->containers[n]));
|
2008-12-16 01:59:34 +03:00
|
|
|
}
|
|
|
|
*bcrp = bcr & 0xFFDEE001;
|
|
|
|
if (enabled && (bcr & 0x00000001)) {
|
|
|
|
#ifdef DEBUG_SDRAM
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: Map RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
|
2008-12-16 01:59:34 +03:00
|
|
|
__func__, sdram_base(bcr), sdram_size(bcr));
|
|
|
|
#endif
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init(&sdram->containers[n], NULL, "sdram-containers",
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_size(bcr));
|
|
|
|
memory_region_add_subregion(&sdram->containers[n], 0,
|
|
|
|
&sdram->ram_memories[n]);
|
|
|
|
memory_region_add_subregion(get_system_memory(),
|
|
|
|
sdram_base(bcr),
|
|
|
|
&sdram->containers[n]);
|
2008-12-16 01:59:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void sdram_map_bcr (ppc4xx_sdram_t *sdram)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sdram->nbanks; i++) {
|
|
|
|
if (sdram->ram_sizes[i] != 0) {
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram,
|
|
|
|
&sdram->bcr[i],
|
2008-12-16 01:59:34 +03:00
|
|
|
sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]),
|
|
|
|
1);
|
|
|
|
} else {
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram, &sdram->bcr[i], 0x00000000, 0);
|
2008-12-16 01:59:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void sdram_unmap_bcr (ppc4xx_sdram_t *sdram)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sdram->nbanks; i++) {
|
|
|
|
#ifdef DEBUG_SDRAM
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: Unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
|
2008-12-16 01:59:34 +03:00
|
|
|
__func__, sdram_base(sdram->bcr[i]), sdram_size(sdram->bcr[i]));
|
|
|
|
#endif
|
2011-08-15 18:17:27 +04:00
|
|
|
memory_region_del_subregion(get_system_memory(),
|
|
|
|
&sdram->ram_memories[i]);
|
2008-12-16 01:59:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_sdram (void *opaque, int dcrn)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_sdram_t *sdram;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2008-12-16 01:59:34 +03:00
|
|
|
|
|
|
|
sdram = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case SDRAM0_CFGADDR:
|
|
|
|
ret = sdram->addr;
|
|
|
|
break;
|
|
|
|
case SDRAM0_CFGDATA:
|
|
|
|
switch (sdram->addr) {
|
|
|
|
case 0x00: /* SDRAM_BESR0 */
|
|
|
|
ret = sdram->besr0;
|
|
|
|
break;
|
|
|
|
case 0x08: /* SDRAM_BESR1 */
|
|
|
|
ret = sdram->besr1;
|
|
|
|
break;
|
|
|
|
case 0x10: /* SDRAM_BEAR */
|
|
|
|
ret = sdram->bear;
|
|
|
|
break;
|
|
|
|
case 0x20: /* SDRAM_CFG */
|
|
|
|
ret = sdram->cfg;
|
|
|
|
break;
|
|
|
|
case 0x24: /* SDRAM_STATUS */
|
|
|
|
ret = sdram->status;
|
|
|
|
break;
|
|
|
|
case 0x30: /* SDRAM_RTR */
|
|
|
|
ret = sdram->rtr;
|
|
|
|
break;
|
|
|
|
case 0x34: /* SDRAM_PMIT */
|
|
|
|
ret = sdram->pmit;
|
|
|
|
break;
|
|
|
|
case 0x40: /* SDRAM_B0CR */
|
|
|
|
ret = sdram->bcr[0];
|
|
|
|
break;
|
|
|
|
case 0x44: /* SDRAM_B1CR */
|
|
|
|
ret = sdram->bcr[1];
|
|
|
|
break;
|
|
|
|
case 0x48: /* SDRAM_B2CR */
|
|
|
|
ret = sdram->bcr[2];
|
|
|
|
break;
|
|
|
|
case 0x4C: /* SDRAM_B3CR */
|
|
|
|
ret = sdram->bcr[3];
|
|
|
|
break;
|
|
|
|
case 0x80: /* SDRAM_TR */
|
|
|
|
ret = -1; /* ? */
|
|
|
|
break;
|
|
|
|
case 0x94: /* SDRAM_ECCCFG */
|
|
|
|
ret = sdram->ecccfg;
|
|
|
|
break;
|
|
|
|
case 0x98: /* SDRAM_ECCESR */
|
|
|
|
ret = sdram->eccesr;
|
|
|
|
break;
|
|
|
|
default: /* Error */
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Avoid gcc warning */
|
|
|
|
ret = 0x00000000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_sdram (void *opaque, int dcrn, uint32_t val)
|
2008-12-16 01:59:34 +03:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_sdram_t *sdram;
|
2008-12-16 01:59:34 +03:00
|
|
|
|
|
|
|
sdram = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case SDRAM0_CFGADDR:
|
|
|
|
sdram->addr = val;
|
|
|
|
break;
|
|
|
|
case SDRAM0_CFGDATA:
|
|
|
|
switch (sdram->addr) {
|
|
|
|
case 0x00: /* SDRAM_BESR0 */
|
|
|
|
sdram->besr0 &= ~val;
|
|
|
|
break;
|
|
|
|
case 0x08: /* SDRAM_BESR1 */
|
|
|
|
sdram->besr1 &= ~val;
|
|
|
|
break;
|
|
|
|
case 0x10: /* SDRAM_BEAR */
|
|
|
|
sdram->bear = val;
|
|
|
|
break;
|
|
|
|
case 0x20: /* SDRAM_CFG */
|
|
|
|
val &= 0xFFE00000;
|
|
|
|
if (!(sdram->cfg & 0x80000000) && (val & 0x80000000)) {
|
|
|
|
#ifdef DEBUG_SDRAM
|
|
|
|
printf("%s: enable SDRAM controller\n", __func__);
|
|
|
|
#endif
|
|
|
|
/* validate all RAM mappings */
|
|
|
|
sdram_map_bcr(sdram);
|
|
|
|
sdram->status &= ~0x80000000;
|
|
|
|
} else if ((sdram->cfg & 0x80000000) && !(val & 0x80000000)) {
|
|
|
|
#ifdef DEBUG_SDRAM
|
|
|
|
printf("%s: disable SDRAM controller\n", __func__);
|
|
|
|
#endif
|
|
|
|
/* invalidate all RAM mappings */
|
|
|
|
sdram_unmap_bcr(sdram);
|
|
|
|
sdram->status |= 0x80000000;
|
|
|
|
}
|
|
|
|
if (!(sdram->cfg & 0x40000000) && (val & 0x40000000))
|
|
|
|
sdram->status |= 0x40000000;
|
|
|
|
else if ((sdram->cfg & 0x40000000) && !(val & 0x40000000))
|
|
|
|
sdram->status &= ~0x40000000;
|
|
|
|
sdram->cfg = val;
|
|
|
|
break;
|
|
|
|
case 0x24: /* SDRAM_STATUS */
|
|
|
|
/* Read-only register */
|
|
|
|
break;
|
|
|
|
case 0x30: /* SDRAM_RTR */
|
|
|
|
sdram->rtr = val & 0x3FF80000;
|
|
|
|
break;
|
|
|
|
case 0x34: /* SDRAM_PMIT */
|
|
|
|
sdram->pmit = (val & 0xF8000000) | 0x07C00000;
|
|
|
|
break;
|
|
|
|
case 0x40: /* SDRAM_B0CR */
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram, &sdram->bcr[0], val, sdram->cfg & 0x80000000);
|
2008-12-16 01:59:34 +03:00
|
|
|
break;
|
|
|
|
case 0x44: /* SDRAM_B1CR */
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram, &sdram->bcr[1], val, sdram->cfg & 0x80000000);
|
2008-12-16 01:59:34 +03:00
|
|
|
break;
|
|
|
|
case 0x48: /* SDRAM_B2CR */
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram, &sdram->bcr[2], val, sdram->cfg & 0x80000000);
|
2008-12-16 01:59:34 +03:00
|
|
|
break;
|
|
|
|
case 0x4C: /* SDRAM_B3CR */
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram_set_bcr(sdram, &sdram->bcr[3], val, sdram->cfg & 0x80000000);
|
2008-12-16 01:59:34 +03:00
|
|
|
break;
|
|
|
|
case 0x80: /* SDRAM_TR */
|
|
|
|
sdram->tr = val & 0x018FC01F;
|
|
|
|
break;
|
|
|
|
case 0x94: /* SDRAM_ECCCFG */
|
|
|
|
sdram->ecccfg = val & 0x00F00000;
|
|
|
|
break;
|
|
|
|
case 0x98: /* SDRAM_ECCESR */
|
|
|
|
val &= 0xFFF0F000;
|
|
|
|
if (sdram->eccesr == 0 && val != 0)
|
|
|
|
qemu_irq_raise(sdram->irq);
|
|
|
|
else if (sdram->eccesr != 0 && val == 0)
|
|
|
|
qemu_irq_lower(sdram->irq);
|
|
|
|
sdram->eccesr = val;
|
|
|
|
break;
|
|
|
|
default: /* Error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdram_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_sdram_t *sdram;
|
2008-12-16 01:59:34 +03:00
|
|
|
|
|
|
|
sdram = opaque;
|
|
|
|
sdram->addr = 0x00000000;
|
|
|
|
sdram->bear = 0x00000000;
|
|
|
|
sdram->besr0 = 0x00000000; /* No error */
|
|
|
|
sdram->besr1 = 0x00000000; /* No error */
|
|
|
|
sdram->cfg = 0x00000000;
|
|
|
|
sdram->ecccfg = 0x00000000; /* No ECC */
|
|
|
|
sdram->eccesr = 0x00000000; /* No error */
|
|
|
|
sdram->pmit = 0x07C00000;
|
|
|
|
sdram->rtr = 0x05F00000;
|
|
|
|
sdram->tr = 0x00854009;
|
|
|
|
/* We pre-initialize RAM banks */
|
|
|
|
sdram->status = 0x00000000;
|
|
|
|
sdram->cfg = 0x00800000;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,
|
2011-08-15 18:17:27 +04:00
|
|
|
MemoryRegion *ram_memories,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr *ram_bases,
|
|
|
|
hwaddr *ram_sizes,
|
2008-12-16 01:59:34 +03:00
|
|
|
int do_init)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_sdram_t *sdram;
|
2008-12-16 01:59:34 +03:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
sdram = g_malloc0(sizeof(ppc4xx_sdram_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
sdram->irq = irq;
|
|
|
|
sdram->nbanks = nbanks;
|
2011-08-15 18:17:27 +04:00
|
|
|
sdram->ram_memories = ram_memories;
|
2012-10-23 14:30:10 +04:00
|
|
|
memset(sdram->ram_bases, 0, 4 * sizeof(hwaddr));
|
2009-02-06 01:06:05 +03:00
|
|
|
memcpy(sdram->ram_bases, ram_bases,
|
2012-10-23 14:30:10 +04:00
|
|
|
nbanks * sizeof(hwaddr));
|
|
|
|
memset(sdram->ram_sizes, 0, 4 * sizeof(hwaddr));
|
2009-02-06 01:06:05 +03:00
|
|
|
memcpy(sdram->ram_sizes, ram_sizes,
|
2012-10-23 14:30:10 +04:00
|
|
|
nbanks * sizeof(hwaddr));
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(&sdram_reset, sdram);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, SDRAM0_CFGADDR,
|
|
|
|
sdram, &dcr_read_sdram, &dcr_write_sdram);
|
|
|
|
ppc_dcr_register(env, SDRAM0_CFGDATA,
|
|
|
|
sdram, &dcr_read_sdram, &dcr_write_sdram);
|
|
|
|
if (do_init)
|
|
|
|
sdram_map_bcr(sdram);
|
2008-12-16 01:59:34 +03:00
|
|
|
}
|
2008-12-16 02:15:56 +03:00
|
|
|
|
|
|
|
/* Fill in consecutive SDRAM banks with 'ram_size' bytes of memory.
|
|
|
|
*
|
|
|
|
* sdram_bank_sizes[] must be 0-terminated.
|
|
|
|
*
|
|
|
|
* The 4xx SDRAM controller supports a small number of banks, and each bank
|
|
|
|
* must be one of a small set of sizes. The number of banks and the supported
|
|
|
|
* sizes varies by SoC. */
|
2009-10-02 01:12:16 +04:00
|
|
|
ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,
|
2011-08-15 18:17:27 +04:00
|
|
|
MemoryRegion ram_memories[],
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr ram_bases[],
|
|
|
|
hwaddr ram_sizes[],
|
2008-12-16 02:15:56 +03:00
|
|
|
const unsigned int sdram_bank_sizes[])
|
|
|
|
{
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
MemoryRegion *ram = g_malloc0(sizeof(*ram));
|
2009-10-02 01:12:16 +04:00
|
|
|
ram_addr_t size_left = ram_size;
|
2011-08-15 18:17:27 +04:00
|
|
|
ram_addr_t base = 0;
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
unsigned int bank_size;
|
2008-12-16 02:15:56 +03:00
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_banks; i++) {
|
|
|
|
for (j = 0; sdram_bank_sizes[j] != 0; j++) {
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
bank_size = sdram_bank_sizes[j];
|
2009-04-10 18:29:45 +04:00
|
|
|
if (bank_size <= size_left) {
|
|
|
|
size_left -= bank_size;
|
2008-12-16 02:15:56 +03:00
|
|
|
}
|
|
|
|
}
|
2009-04-10 18:29:45 +04:00
|
|
|
if (!size_left) {
|
2008-12-16 02:15:56 +03:00
|
|
|
/* No need to use the remaining banks. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 18:29:45 +04:00
|
|
|
ram_size -= size_left;
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
if (size_left) {
|
2008-12-16 02:15:56 +03:00
|
|
|
printf("Truncating memory to %d MiB to fit SDRAM controller limits.\n",
|
2009-04-10 18:29:45 +04:00
|
|
|
(int)(ram_size >> 20));
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
memory_region_allocate_system_memory(ram, NULL, "ppc4xx.sdram", ram_size);
|
|
|
|
|
|
|
|
size_left = ram_size;
|
|
|
|
for (i = 0; i < nr_banks && size_left; i++) {
|
|
|
|
for (j = 0; sdram_bank_sizes[j] != 0; j++) {
|
|
|
|
bank_size = sdram_bank_sizes[j];
|
|
|
|
|
|
|
|
if (bank_size <= size_left) {
|
|
|
|
char name[32];
|
|
|
|
snprintf(name, sizeof(name), "ppc4xx.sdram%d", i);
|
|
|
|
memory_region_init_alias(&ram_memories[i], NULL, name, ram,
|
|
|
|
base, bank_size);
|
|
|
|
ram_bases[i] = base;
|
|
|
|
ram_sizes[i] = bank_size;
|
|
|
|
base += bank_size;
|
|
|
|
size_left -= bank_size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-16 02:15:56 +03:00
|
|
|
|
2009-04-10 18:29:45 +04:00
|
|
|
return ram_size;
|
2008-12-16 02:15:56 +03:00
|
|
|
}
|