2007-04-17 00:09:45 +04:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC 405 embedded processors emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-04-17 00:09:45 +04:00
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-04-17 00:09:45 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2019-08-12 08:23:38 +03:00
|
|
|
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-25 15:42:24 +03:00
|
|
|
#include "qemu/units.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2021-12-17 19:57:17 +03:00
|
|
|
#include "qemu/log.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/ppc/ppc.h"
|
2017-08-20 20:23:05 +03:00
|
|
|
#include "hw/i2c/ppc4xx_i2c.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2022-08-09 18:38:45 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "ppc405.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/char/serial.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2019-08-12 08:23:38 +03:00
|
|
|
#include "sysemu/reset.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2021-01-08 20:12:11 +03:00
|
|
|
#include "hw/intc/ppc-uic.h"
|
|
|
|
#include "hw/qdev-properties.h"
|
|
|
|
#include "qapi/error.h"
|
2021-12-17 19:57:17 +03:00
|
|
|
#include "trace.h"
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Shared peripherals */
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* PLB to OPB bridge */
|
|
|
|
enum {
|
|
|
|
POB0_BESR0 = 0x0A0,
|
|
|
|
POB0_BESR1 = 0x0A2,
|
|
|
|
POB0_BEAR = 0x0A4,
|
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:27 +03:00
|
|
|
static uint32_t dcr_read_pob(void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:27 +03:00
|
|
|
Ppc405PobState *pob = opaque;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
switch (dcrn) {
|
|
|
|
case POB0_BEAR:
|
|
|
|
ret = pob->bear;
|
|
|
|
break;
|
|
|
|
case POB0_BESR0:
|
2012-09-01 00:21:21 +04:00
|
|
|
ret = pob->besr0;
|
|
|
|
break;
|
2007-04-17 00:09:45 +04:00
|
|
|
case POB0_BESR1:
|
2012-09-01 00:21:21 +04:00
|
|
|
ret = pob->besr1;
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Avoid gcc warning */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:27 +03:00
|
|
|
static void dcr_write_pob(void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:27 +03:00
|
|
|
Ppc405PobState *pob = opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
switch (dcrn) {
|
|
|
|
case POB0_BEAR:
|
|
|
|
/* Read only */
|
|
|
|
break;
|
|
|
|
case POB0_BESR0:
|
2012-09-01 00:21:21 +04:00
|
|
|
/* Write-clear */
|
|
|
|
pob->besr0 &= ~val;
|
|
|
|
break;
|
2007-04-17 00:09:45 +04:00
|
|
|
case POB0_BESR1:
|
|
|
|
/* Write-clear */
|
2012-09-01 00:21:21 +04:00
|
|
|
pob->besr1 &= ~val;
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:27 +03:00
|
|
|
static void ppc405_pob_reset(DeviceState *dev)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:27 +03:00
|
|
|
Ppc405PobState *pob = PPC405_POB(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
/* No error */
|
|
|
|
pob->bear = 0x00000000;
|
2012-09-01 00:21:21 +04:00
|
|
|
pob->besr0 = 0x0000000;
|
|
|
|
pob->besr1 = 0x0000000;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:27 +03:00
|
|
|
static void ppc405_pob_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
Ppc405PobState *pob = PPC405_POB(dev);
|
|
|
|
Ppc4xxDcrDeviceState *dcr = PPC4xx_DCR_DEVICE(dev);
|
|
|
|
|
|
|
|
ppc4xx_dcr_register(dcr, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
|
|
|
|
ppc4xx_dcr_register(dcr, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
|
|
|
|
ppc4xx_dcr_register(dcr, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_pob_class_init(ObjectClass *oc, void *data)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:27 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2022-08-17 18:08:27 +03:00
|
|
|
dc->realize = ppc405_pob_realize;
|
|
|
|
dc->reset = ppc405_pob_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* OPB arbitrer */
|
2018-08-02 17:44:30 +03:00
|
|
|
static uint64_t opba_readb(void *opaque, hwaddr addr, unsigned size)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:26 +03:00
|
|
|
Ppc405OpbaState *opba = opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t ret;
|
|
|
|
|
2009-08-15 18:27:05 +04:00
|
|
|
switch (addr) {
|
2007-04-17 00:09:45 +04:00
|
|
|
case 0x00:
|
|
|
|
ret = opba->cr;
|
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
ret = opba->pr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0x00;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_opba_readb(addr, ret);
|
2007-04-17 00:09:45 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:44:30 +03:00
|
|
|
static void opba_writeb(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:26 +03:00
|
|
|
Ppc405OpbaState *opba = opaque;
|
2021-12-17 19:57:17 +03:00
|
|
|
|
|
|
|
trace_opba_writeb(addr, value);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2009-08-15 18:27:05 +04:00
|
|
|
switch (addr) {
|
2007-04-17 00:09:45 +04:00
|
|
|
case 0x00:
|
|
|
|
opba->cr = value & 0xF8;
|
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
opba->pr = value & 0xFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 18:17:26 +04:00
|
|
|
static const MemoryRegionOps opba_ops = {
|
2018-08-02 17:44:30 +03:00
|
|
|
.read = opba_readb,
|
|
|
|
.write = opba_writeb,
|
|
|
|
.impl.min_access_size = 1,
|
|
|
|
.impl.max_access_size = 1,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:26 +03:00
|
|
|
static void ppc405_opba_reset(DeviceState *dev)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:26 +03:00
|
|
|
Ppc405OpbaState *opba = PPC405_OPBA(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
opba->cr = 0x00; /* No dynamic priorities - park disabled */
|
|
|
|
opba->pr = 0x11;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:26 +03:00
|
|
|
static void ppc405_opba_realize(DeviceState *dev, Error **errp)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:26 +03:00
|
|
|
Ppc405OpbaState *s = PPC405_OPBA(dev);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->io, OBJECT(s), &opba_ops, s, "opba", 2);
|
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io);
|
|
|
|
}
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2022-08-17 18:08:26 +03:00
|
|
|
static void ppc405_opba_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2022-08-17 18:08:26 +03:00
|
|
|
dc->realize = ppc405_opba_realize;
|
|
|
|
dc->reset = ppc405_opba_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code decompression controller */
|
|
|
|
/* XXX: TODO */
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* DMA controller */
|
|
|
|
enum {
|
|
|
|
DMA0_CR0 = 0x100,
|
|
|
|
DMA0_CT0 = 0x101,
|
|
|
|
DMA0_DA0 = 0x102,
|
|
|
|
DMA0_SA0 = 0x103,
|
|
|
|
DMA0_SG0 = 0x104,
|
|
|
|
DMA0_CR1 = 0x108,
|
|
|
|
DMA0_CT1 = 0x109,
|
|
|
|
DMA0_DA1 = 0x10A,
|
|
|
|
DMA0_SA1 = 0x10B,
|
|
|
|
DMA0_SG1 = 0x10C,
|
|
|
|
DMA0_CR2 = 0x110,
|
|
|
|
DMA0_CT2 = 0x111,
|
|
|
|
DMA0_DA2 = 0x112,
|
|
|
|
DMA0_SA2 = 0x113,
|
|
|
|
DMA0_SG2 = 0x114,
|
|
|
|
DMA0_CR3 = 0x118,
|
|
|
|
DMA0_CT3 = 0x119,
|
|
|
|
DMA0_DA3 = 0x11A,
|
|
|
|
DMA0_SA3 = 0x11B,
|
|
|
|
DMA0_SG3 = 0x11C,
|
|
|
|
DMA0_SR = 0x120,
|
|
|
|
DMA0_SGC = 0x123,
|
|
|
|
DMA0_SLP = 0x125,
|
|
|
|
DMA0_POL = 0x126,
|
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:24 +03:00
|
|
|
static uint32_t dcr_read_dma(void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:24 +03:00
|
|
|
static void dcr_write_dma(void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:24 +03:00
|
|
|
static void ppc405_dma_reset(DeviceState *dev)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:24 +03:00
|
|
|
Ppc405DmaState *dma = PPC405_DMA(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
dma->cr[i] = 0x00000000;
|
|
|
|
dma->ct[i] = 0x00000000;
|
|
|
|
dma->da[i] = 0x00000000;
|
|
|
|
dma->sa[i] = 0x00000000;
|
|
|
|
dma->sg[i] = 0x00000000;
|
|
|
|
}
|
|
|
|
dma->sr = 0x00000000;
|
|
|
|
dma->sgc = 0x00000000;
|
|
|
|
dma->slp = 0x7C000000;
|
|
|
|
dma->pol = 0x00000000;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:24 +03:00
|
|
|
static void ppc405_dma_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
Ppc405DmaState *dma = PPC405_DMA(dev);
|
|
|
|
Ppc4xxDcrDeviceState *dcr = PPC4xx_DCR_DEVICE(dev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dma->irqs); i++) {
|
|
|
|
sysbus_init_irq(SYS_BUS_DEVICE(dma), &dma->irqs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CR0, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CT0, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_DA0, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SA0, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SG0, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CR1, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CT1, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_DA1, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SA1, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SG1, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CR2, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CT2, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_DA2, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SA2, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SG2, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CR3, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_CT3, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_DA3, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SA3, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SG3, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SR, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SGC, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_SLP, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc4xx_dcr_register(dcr, DMA0_POL, dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_dma_class_init(ObjectClass *oc, void *data)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:24 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ppc405_dma_realize;
|
|
|
|
dc->reset = ppc405_dma_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* GPIO */
|
2018-08-02 17:44:30 +03:00
|
|
|
static uint64_t ppc405_gpio_read(void *opaque, hwaddr addr, unsigned size)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405_gpio_read(addr, size);
|
2007-04-17 00:09:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:44:30 +03:00
|
|
|
static void ppc405_gpio_write(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405_gpio_write(addr, size, value);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:26 +04:00
|
|
|
static const MemoryRegionOps ppc405_gpio_ops = {
|
2018-08-02 17:44:30 +03:00
|
|
|
.read = ppc405_gpio_read,
|
|
|
|
.write = ppc405_gpio_write,
|
2011-08-15 18:17:26 +04:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:23 +03:00
|
|
|
static void ppc405_gpio_realize(DeviceState *dev, Error **errp)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:23 +03:00
|
|
|
Ppc405GpioState *s = PPC405_GPIO(dev);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->io, OBJECT(s), &ppc405_gpio_ops, s, "gpio",
|
|
|
|
0x38);
|
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:23 +03:00
|
|
|
static void ppc405_gpio_class_init(ObjectClass *oc, void *data)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:23 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2022-08-17 18:08:23 +03:00
|
|
|
dc->realize = ppc405_gpio_realize;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* On Chip Memory */
|
|
|
|
enum {
|
|
|
|
OCM0_ISARC = 0x018,
|
|
|
|
OCM0_ISACNTL = 0x019,
|
|
|
|
OCM0_DSARC = 0x01A,
|
|
|
|
OCM0_DSACNTL = 0x01B,
|
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:22 +03:00
|
|
|
static void ocm_update_mappings(Ppc405OcmState *ocm,
|
|
|
|
uint32_t isarc, uint32_t isacntl,
|
|
|
|
uint32_t dsarc, uint32_t dsacntl)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ocm_update_mappings(isarc, isacntl, dsarc, dsacntl, ocm->isarc,
|
|
|
|
ocm->isacntl, ocm->dsarc, ocm->dsacntl);
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
if (ocm->isarc != isarc ||
|
|
|
|
(ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) {
|
|
|
|
if (ocm->isacntl & 0x80000000) {
|
|
|
|
/* Unmap previously assigned memory region */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ocm_unmap("ISA", ocm->isarc);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_del_subregion(get_system_memory(), &ocm->isarc_ram);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
if (isacntl & 0x80000000) {
|
|
|
|
/* Map new instruction memory region */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ocm_map("ISA", isarc);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), isarc,
|
|
|
|
&ocm->isarc_ram);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ocm->dsarc != dsarc ||
|
|
|
|
(ocm->dsacntl & 0x80000000) != (dsacntl & 0x80000000)) {
|
|
|
|
if (ocm->dsacntl & 0x80000000) {
|
|
|
|
/* Beware not to unmap the region we just mapped */
|
|
|
|
if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) {
|
|
|
|
/* Unmap previously assigned memory region */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ocm_unmap("DSA", ocm->dsarc);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_del_subregion(get_system_memory(),
|
|
|
|
&ocm->dsarc_ram);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dsacntl & 0x80000000) {
|
|
|
|
/* Beware not to remap the region we just mapped */
|
|
|
|
if (!(isacntl & 0x80000000) || dsarc != isarc) {
|
|
|
|
/* Map new data memory region */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ocm_map("DSA", dsarc);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), dsarc,
|
|
|
|
&ocm->dsarc_ram);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:22 +03:00
|
|
|
static uint32_t dcr_read_ocm(void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:22 +03:00
|
|
|
Ppc405OcmState *ocm = opaque;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
switch (dcrn) {
|
|
|
|
case OCM0_ISARC:
|
|
|
|
ret = ocm->isarc;
|
|
|
|
break;
|
|
|
|
case OCM0_ISACNTL:
|
|
|
|
ret = ocm->isacntl;
|
|
|
|
break;
|
|
|
|
case OCM0_DSARC:
|
|
|
|
ret = ocm->dsarc;
|
|
|
|
break;
|
|
|
|
case OCM0_DSACNTL:
|
|
|
|
ret = ocm->dsacntl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:22 +03:00
|
|
|
static void dcr_write_ocm(void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:22 +03:00
|
|
|
Ppc405OcmState *ocm = opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc, dsarc, isacntl, dsacntl;
|
|
|
|
|
|
|
|
isarc = ocm->isarc;
|
|
|
|
dsarc = ocm->dsarc;
|
|
|
|
isacntl = ocm->isacntl;
|
|
|
|
dsacntl = ocm->dsacntl;
|
|
|
|
switch (dcrn) {
|
|
|
|
case OCM0_ISARC:
|
|
|
|
isarc = val & 0xFC000000;
|
|
|
|
break;
|
|
|
|
case OCM0_ISACNTL:
|
|
|
|
isacntl = val & 0xC0000000;
|
|
|
|
break;
|
|
|
|
case OCM0_DSARC:
|
|
|
|
isarc = val & 0xFC000000;
|
|
|
|
break;
|
|
|
|
case OCM0_DSACNTL:
|
|
|
|
isacntl = val & 0xC0000000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl);
|
|
|
|
ocm->isarc = isarc;
|
|
|
|
ocm->dsarc = dsarc;
|
|
|
|
ocm->isacntl = isacntl;
|
|
|
|
ocm->dsacntl = dsacntl;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:22 +03:00
|
|
|
static void ppc405_ocm_reset(DeviceState *dev)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:22 +03:00
|
|
|
Ppc405OcmState *ocm = PPC405_OCM(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc, dsarc, isacntl, dsacntl;
|
|
|
|
|
|
|
|
isarc = 0x00000000;
|
|
|
|
isacntl = 0x00000000;
|
|
|
|
dsarc = 0x00000000;
|
|
|
|
dsacntl = 0x00000000;
|
|
|
|
ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl);
|
|
|
|
ocm->isarc = isarc;
|
|
|
|
ocm->dsarc = dsarc;
|
|
|
|
ocm->isacntl = isacntl;
|
|
|
|
ocm->dsacntl = dsacntl;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:22 +03:00
|
|
|
static void ppc405_ocm_realize(DeviceState *dev, Error **errp)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:22 +03:00
|
|
|
Ppc405OcmState *ocm = PPC405_OCM(dev);
|
|
|
|
Ppc4xxDcrDeviceState *dcr = PPC4xx_DCR_DEVICE(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-15 18:17:26 +04:00
|
|
|
/* XXX: Size is 4096 or 0x04000000 */
|
2022-08-17 18:08:22 +03:00
|
|
|
memory_region_init_ram(&ocm->isarc_ram, OBJECT(ocm), "ppc405.ocm", 4 * KiB,
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 17:51:43 +03:00
|
|
|
&error_fatal);
|
2022-08-17 18:08:22 +03:00
|
|
|
memory_region_init_alias(&ocm->dsarc_ram, OBJECT(ocm), "ppc405.dsarc",
|
2018-06-25 15:42:24 +03:00
|
|
|
&ocm->isarc_ram, 0, 4 * KiB);
|
2022-08-17 18:08:22 +03:00
|
|
|
|
|
|
|
ppc4xx_dcr_register(dcr, OCM0_ISARC, ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc4xx_dcr_register(dcr, OCM0_ISACNTL, ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc4xx_dcr_register(dcr, OCM0_DSARC, ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc4xx_dcr_register(dcr, OCM0_DSACNTL, ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_ocm_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ppc405_ocm_realize;
|
|
|
|
dc->reset = ppc405_ocm_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2007-04-24 10:37:21 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* General purpose timers */
|
2022-08-17 18:08:21 +03:00
|
|
|
static int ppc4xx_gpt_compare(Ppc405GptState *gpt, int n)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc4xx_gpt_set_output(Ppc405GptState *gpt, int n, int level)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc4xx_gpt_set_outputs(Ppc405GptState *gpt)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
uint32_t mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mask = 0x80000000;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (gpt->oe & mask) {
|
|
|
|
/* Output is enabled */
|
|
|
|
if (ppc4xx_gpt_compare(gpt, i)) {
|
|
|
|
/* Comparison is OK */
|
|
|
|
ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask);
|
|
|
|
} else {
|
|
|
|
/* Comparison is KO */
|
|
|
|
ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mask = mask >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc4xx_gpt_set_irqs(Ppc405GptState *gpt)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
uint32_t mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mask = 0x00008000;
|
|
|
|
for (i = 0; i < 5; i++) {
|
2022-08-17 18:08:43 +03:00
|
|
|
if (gpt->is & gpt->im & mask) {
|
2007-04-24 10:37:21 +04:00
|
|
|
qemu_irq_raise(gpt->irqs[i]);
|
2022-08-17 18:08:43 +03:00
|
|
|
} else {
|
2007-04-24 10:37:21 +04:00
|
|
|
qemu_irq_lower(gpt->irqs[i]);
|
2022-08-17 18:08:43 +03:00
|
|
|
}
|
2007-04-24 10:37:21 +04:00
|
|
|
mask = mask >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc4xx_gpt_compute_timer(Ppc405GptState *gpt)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:44:30 +03:00
|
|
|
static uint64_t ppc4xx_gpt_read(void *opaque, hwaddr addr, unsigned size)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2022-08-17 18:08:21 +03:00
|
|
|
Ppc405GptState *gpt = opaque;
|
2007-04-24 10:37:21 +04:00
|
|
|
uint32_t ret;
|
|
|
|
int idx;
|
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc4xx_gpt_read(addr, size);
|
|
|
|
|
2009-08-15 18:27:05 +04:00
|
|
|
switch (addr) {
|
2007-04-24 10:37:21 +04:00
|
|
|
case 0x00:
|
|
|
|
/* Time base counter */
|
2013-08-21 19:03:08 +04:00
|
|
|
ret = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + gpt->tb_offset,
|
2016-03-21 19:02:30 +03:00
|
|
|
gpt->tb_freq, NANOSECONDS_PER_SECOND);
|
2007-04-24 10:37:21 +04:00
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
/* Output enable */
|
|
|
|
ret = gpt->oe;
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
/* Output level */
|
|
|
|
ret = gpt->ol;
|
|
|
|
break;
|
|
|
|
case 0x18:
|
|
|
|
/* Interrupt mask */
|
|
|
|
ret = gpt->im;
|
|
|
|
break;
|
|
|
|
case 0x1C:
|
|
|
|
case 0x20:
|
|
|
|
/* Interrupt status */
|
|
|
|
ret = gpt->is;
|
|
|
|
break;
|
|
|
|
case 0x24:
|
|
|
|
/* Interrupt enable */
|
|
|
|
ret = gpt->ie;
|
|
|
|
break;
|
|
|
|
case 0x80 ... 0x90:
|
|
|
|
/* Compare timer */
|
2009-08-15 18:27:05 +04:00
|
|
|
idx = (addr - 0x80) >> 2;
|
2007-04-24 10:37:21 +04:00
|
|
|
ret = gpt->comp[idx];
|
|
|
|
break;
|
|
|
|
case 0xC0 ... 0xD0:
|
|
|
|
/* Compare mask */
|
2009-08-15 18:27:05 +04:00
|
|
|
idx = (addr - 0xC0) >> 2;
|
2007-04-24 10:37:21 +04:00
|
|
|
ret = gpt->mask[idx];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:44:30 +03:00
|
|
|
static void ppc4xx_gpt_write(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2022-08-17 18:08:21 +03:00
|
|
|
Ppc405GptState *gpt = opaque;
|
2007-04-24 10:37:21 +04:00
|
|
|
int idx;
|
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc4xx_gpt_write(addr, size, value);
|
|
|
|
|
2009-08-15 18:27:05 +04:00
|
|
|
switch (addr) {
|
2007-04-24 10:37:21 +04:00
|
|
|
case 0x00:
|
|
|
|
/* Time base counter */
|
2016-03-21 19:02:30 +03:00
|
|
|
gpt->tb_offset = muldiv64(value, NANOSECONDS_PER_SECOND, gpt->tb_freq)
|
2013-08-21 19:03:08 +04:00
|
|
|
- qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
2007-04-24 10:37:21 +04:00
|
|
|
ppc4xx_gpt_compute_timer(gpt);
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
/* Output enable */
|
|
|
|
gpt->oe = value & 0xF8000000;
|
|
|
|
ppc4xx_gpt_set_outputs(gpt);
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
/* Output level */
|
|
|
|
gpt->ol = value & 0xF8000000;
|
|
|
|
ppc4xx_gpt_set_outputs(gpt);
|
|
|
|
break;
|
|
|
|
case 0x18:
|
|
|
|
/* Interrupt mask */
|
|
|
|
gpt->im = value & 0x0000F800;
|
|
|
|
break;
|
|
|
|
case 0x1C:
|
|
|
|
/* Interrupt status set */
|
|
|
|
gpt->is |= value & 0x0000F800;
|
|
|
|
ppc4xx_gpt_set_irqs(gpt);
|
|
|
|
break;
|
|
|
|
case 0x20:
|
|
|
|
/* Interrupt status clear */
|
|
|
|
gpt->is &= ~(value & 0x0000F800);
|
|
|
|
ppc4xx_gpt_set_irqs(gpt);
|
|
|
|
break;
|
|
|
|
case 0x24:
|
|
|
|
/* Interrupt enable */
|
|
|
|
gpt->ie = value & 0x0000F800;
|
|
|
|
ppc4xx_gpt_set_irqs(gpt);
|
|
|
|
break;
|
|
|
|
case 0x80 ... 0x90:
|
|
|
|
/* Compare timer */
|
2009-08-15 18:27:05 +04:00
|
|
|
idx = (addr - 0x80) >> 2;
|
2007-04-24 10:37:21 +04:00
|
|
|
gpt->comp[idx] = value & 0xF8000000;
|
|
|
|
ppc4xx_gpt_compute_timer(gpt);
|
|
|
|
break;
|
|
|
|
case 0xC0 ... 0xD0:
|
|
|
|
/* Compare mask */
|
2009-08-15 18:27:05 +04:00
|
|
|
idx = (addr - 0xC0) >> 2;
|
2007-04-24 10:37:21 +04:00
|
|
|
gpt->mask[idx] = value & 0xF8000000;
|
|
|
|
ppc4xx_gpt_compute_timer(gpt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:26 +04:00
|
|
|
static const MemoryRegionOps gpt_ops = {
|
2018-08-02 17:44:30 +03:00
|
|
|
.read = ppc4xx_gpt_read,
|
|
|
|
.write = ppc4xx_gpt_write,
|
|
|
|
.valid.min_access_size = 4,
|
|
|
|
.valid.max_access_size = 4,
|
2011-08-15 18:17:26 +04:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-24 10:37:21 +04:00
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc4xx_gpt_cb(void *opaque)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2022-08-17 18:08:21 +03:00
|
|
|
Ppc405GptState *gpt = opaque;
|
2007-04-24 10:37:21 +04:00
|
|
|
|
|
|
|
ppc4xx_gpt_set_irqs(gpt);
|
|
|
|
ppc4xx_gpt_set_outputs(gpt);
|
|
|
|
ppc4xx_gpt_compute_timer(gpt);
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc405_gpt_reset(DeviceState *dev)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2022-08-17 18:08:21 +03:00
|
|
|
Ppc405GptState *gpt = PPC405_GPT(dev);
|
2007-04-24 10:37:21 +04:00
|
|
|
int i;
|
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(gpt->timer);
|
2007-04-24 10:37:21 +04:00
|
|
|
gpt->oe = 0x00000000;
|
|
|
|
gpt->ol = 0x00000000;
|
|
|
|
gpt->im = 0x00000000;
|
|
|
|
gpt->is = 0x00000000;
|
|
|
|
gpt->ie = 0x00000000;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
gpt->comp[i] = 0x00000000;
|
|
|
|
gpt->mask[i] = 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
static void ppc405_gpt_realize(DeviceState *dev, Error **errp)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2022-08-17 18:08:21 +03:00
|
|
|
Ppc405GptState *s = PPC405_GPT(dev);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2007-04-24 10:37:21 +04:00
|
|
|
int i;
|
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ppc4xx_gpt_cb, s);
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &gpt_ops, s, "gpt", 0xd4);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2022-08-17 18:08:21 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(s->irqs); i++) {
|
|
|
|
sysbus_init_irq(sbd, &s->irqs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_gpt_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
/* timer will be NULL if the GPT wasn't realized */
|
|
|
|
if (PPC405_GPT(obj)->timer) {
|
|
|
|
timer_del(PPC405_GPT(obj)->timer);
|
2009-08-15 18:27:05 +04:00
|
|
|
}
|
2022-08-17 18:08:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_gpt_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ppc405_gpt_realize;
|
|
|
|
dc->reset = ppc405_gpt_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
2007-04-24 10:37:21 +04:00
|
|
|
}
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* PowerPC 405EP */
|
|
|
|
/* CPU control */
|
|
|
|
enum {
|
|
|
|
PPC405EP_CPC0_PLLMR0 = 0x0F0,
|
|
|
|
PPC405EP_CPC0_BOOT = 0x0F1,
|
|
|
|
PPC405EP_CPC0_EPCTL = 0x0F3,
|
|
|
|
PPC405EP_CPC0_PLLMR1 = 0x0F4,
|
|
|
|
PPC405EP_CPC0_UCR = 0x0F5,
|
|
|
|
PPC405EP_CPC0_SRR = 0x0F6,
|
|
|
|
PPC405EP_CPC0_JTAGID = 0x0F7,
|
|
|
|
PPC405EP_CPC0_PCI = 0x0F9,
|
2007-04-24 10:37:21 +04:00
|
|
|
#if 0
|
|
|
|
PPC405EP_CPC0_ER = xxx,
|
|
|
|
PPC405EP_CPC0_FR = xxx,
|
|
|
|
PPC405EP_CPC0_SR = xxx,
|
|
|
|
#endif
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
static void ppc405ep_compute_clocks(Ppc405CpcState *cpc)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk;
|
|
|
|
uint32_t UART0_clk, UART1_clk;
|
|
|
|
uint64_t VCO_out, PLL_out;
|
|
|
|
int M, D;
|
|
|
|
|
|
|
|
VCO_out = 0;
|
|
|
|
if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) {
|
|
|
|
M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("FBMUL", (cpc->pllmr[1] >> 20) & 0xF, M);
|
2007-04-17 00:09:45 +04:00
|
|
|
D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("FWDA", (cpc->pllmr[1] >> 16) & 0x7, D);
|
2017-02-21 16:33:41 +03:00
|
|
|
VCO_out = (uint64_t)cpc->sysclk * M * D;
|
2007-04-17 00:09:45 +04:00
|
|
|
if (VCO_out < 500000000UL || VCO_out > 1000000000UL) {
|
|
|
|
/* Error - unlock the PLL */
|
2021-12-17 19:57:17 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "VCO out of range %" PRIu64 "\n",
|
|
|
|
VCO_out);
|
2007-04-17 00:09:45 +04:00
|
|
|
#if 0
|
|
|
|
cpc->pllmr[1] &= ~0x80000000;
|
|
|
|
goto pll_bypass;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
PLL_out = VCO_out / D;
|
2007-04-24 10:37:21 +04:00
|
|
|
/* Pretend the PLL is locked */
|
|
|
|
cpc->boot |= 0x00000001;
|
2007-04-17 00:09:45 +04:00
|
|
|
} else {
|
|
|
|
#if 0
|
|
|
|
pll_bypass:
|
|
|
|
#endif
|
|
|
|
PLL_out = cpc->sysclk;
|
2007-04-24 10:37:21 +04:00
|
|
|
if (cpc->pllmr[1] & 0x40000000) {
|
|
|
|
/* Pretend the PLL is not locked */
|
|
|
|
cpc->boot &= ~0x00000001;
|
|
|
|
}
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
/* Now, compute all other clocks */
|
|
|
|
D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("CCDV", (cpc->pllmr[0] >> 20) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
CPU_clk = PLL_out / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("CBDV", (cpc->pllmr[0] >> 16) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
PLB_clk = CPU_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("OPDV", (cpc->pllmr[0] >> 12) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
OPB_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("EPDV", (cpc->pllmr[0] >> 8) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
EBC_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("MPDV", (cpc->pllmr[0] >> 4) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
MAL_clk = PLB_clk / D;
|
|
|
|
D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("PPDV", cpc->pllmr[0] & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
PCI_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("U0DIV", cpc->ucr & 0x7F, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
UART0_clk = PLL_out / D;
|
|
|
|
D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */
|
2021-12-17 19:57:17 +03:00
|
|
|
trace_ppc405ep_clocks_compute("U1DIV", (cpc->ucr >> 8) & 0x7F, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
UART1_clk = PLL_out / D;
|
2021-12-17 19:57:17 +03:00
|
|
|
|
|
|
|
if (trace_event_get_state_backends(TRACE_PPC405EP_CLOCKS_SETUP)) {
|
|
|
|
g_autofree char *trace = g_strdup_printf(
|
|
|
|
"Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64
|
|
|
|
" PLL out %" PRIu64 " Hz\n"
|
|
|
|
"CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32
|
|
|
|
" MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32
|
|
|
|
" UART1 %" PRIu32 "\n",
|
|
|
|
cpc->sysclk, VCO_out, PLL_out,
|
|
|
|
CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk,
|
|
|
|
UART0_clk, UART1_clk);
|
|
|
|
trace_ppc405ep_clocks_setup(trace);
|
|
|
|
}
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup CPU clocks */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup PLB clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_PLB_CLK], PLB_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup OPB clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_OPB_CLK], OPB_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup external clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_EBC_CLK], EBC_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup MAL clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_MAL_CLK], MAL_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup PCI clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_PCI_CLK], PCI_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup UART0 clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_UART0_CLK], UART0_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup UART1 clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405EP_UART1_CLK], UART1_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
static uint32_t dcr_read_epcpc(void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:20 +03:00
|
|
|
Ppc405CpcState *cpc = opaque;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
switch (dcrn) {
|
|
|
|
case PPC405EP_CPC0_BOOT:
|
|
|
|
ret = cpc->boot;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_EPCTL:
|
|
|
|
ret = cpc->epctl;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PLLMR0:
|
|
|
|
ret = cpc->pllmr[0];
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PLLMR1:
|
|
|
|
ret = cpc->pllmr[1];
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_UCR:
|
|
|
|
ret = cpc->ucr;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_SRR:
|
|
|
|
ret = cpc->srr;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_JTAGID:
|
|
|
|
ret = cpc->jtagid;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PCI:
|
|
|
|
ret = cpc->pci;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Avoid gcc warning */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
static void dcr_write_epcpc(void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:20 +03:00
|
|
|
Ppc405CpcState *cpc = opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
switch (dcrn) {
|
|
|
|
case PPC405EP_CPC0_BOOT:
|
|
|
|
/* Read-only register */
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_EPCTL:
|
|
|
|
/* Don't care for now */
|
|
|
|
cpc->epctl = val & 0xC00000F3;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PLLMR0:
|
|
|
|
cpc->pllmr[0] = val & 0x00633333;
|
|
|
|
ppc405ep_compute_clocks(cpc);
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PLLMR1:
|
|
|
|
cpc->pllmr[1] = val & 0xC0F73FFF;
|
|
|
|
ppc405ep_compute_clocks(cpc);
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_UCR:
|
|
|
|
/* UART control - don't care for now */
|
|
|
|
cpc->ucr = val & 0x003F7F7F;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_SRR:
|
|
|
|
cpc->srr = val;
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_JTAGID:
|
|
|
|
/* Read-only */
|
|
|
|
break;
|
|
|
|
case PPC405EP_CPC0_PCI:
|
|
|
|
cpc->pci = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
static void ppc405_cpc_reset(DeviceState *dev)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:20 +03:00
|
|
|
Ppc405CpcState *cpc = PPC405_CPC(dev);
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
|
|
|
|
cpc->epctl = 0x00000000;
|
2021-12-17 19:57:17 +03:00
|
|
|
cpc->pllmr[0] = 0x00021002;
|
|
|
|
cpc->pllmr[1] = 0x80a552be;
|
|
|
|
cpc->ucr = 0x00004646;
|
2007-04-17 00:09:45 +04:00
|
|
|
cpc->srr = 0x00040000;
|
|
|
|
cpc->pci = 0x00000000;
|
2007-04-24 10:37:21 +04:00
|
|
|
cpc->er = 0x00000000;
|
|
|
|
cpc->fr = 0x00000000;
|
|
|
|
cpc->sr = 0x00000000;
|
2022-08-17 18:08:20 +03:00
|
|
|
cpc->jtagid = 0x20267049;
|
2007-04-17 00:09:45 +04:00
|
|
|
ppc405ep_compute_clocks(cpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: sysclk should be between 25 and 100 MHz */
|
2022-08-17 18:08:20 +03:00
|
|
|
static void ppc405_cpc_realize(DeviceState *dev, Error **errp)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-17 18:08:20 +03:00
|
|
|
Ppc405CpcState *cpc = PPC405_CPC(dev);
|
|
|
|
Ppc4xxDcrDeviceState *dcr = PPC4xx_DCR_DEVICE(dev);
|
|
|
|
|
|
|
|
assert(dcr->cpu);
|
|
|
|
cpc->clk_setup[PPC405EP_CPU_CLK].cb =
|
|
|
|
ppc_40x_timers_init(&dcr->cpu->env, cpc->sysclk, PPC_INTERRUPT_PIT);
|
|
|
|
cpc->clk_setup[PPC405EP_CPU_CLK].opaque = &dcr->cpu->env;
|
|
|
|
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_BOOT, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_EPCTL, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_PLLMR0, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_PLLMR1, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_UCR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_SRR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_JTAGID, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc4xx_dcr_register(dcr, PPC405EP_CPC0_PCI, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
}
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
static Property ppc405_cpc_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("sys-clk", Ppc405CpcState, sysclk, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ppc405_cpc_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ppc405_cpc_realize;
|
|
|
|
dc->reset = ppc405_cpc_reset;
|
|
|
|
/* Reason: only works as function of a ppc4xx SoC */
|
|
|
|
dc->user_creatable = false;
|
|
|
|
device_class_set_props(dc, ppc405_cpc_properties);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
/* PPC405_SOC */
|
|
|
|
|
2022-08-09 18:38:47 +03:00
|
|
|
static void ppc405_soc_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
Ppc405SoCState *s = PPC405_SOC(obj);
|
|
|
|
|
|
|
|
object_initialize_child(obj, "cpu", &s->cpu,
|
|
|
|
POWERPC_CPU_TYPE_NAME("405ep"));
|
2022-08-17 18:08:20 +03:00
|
|
|
|
2022-08-17 18:08:34 +03:00
|
|
|
object_initialize_child(obj, "uic", &s->uic, TYPE_PPC_UIC);
|
|
|
|
|
2022-08-17 18:08:20 +03:00
|
|
|
object_initialize_child(obj, "cpc", &s->cpc, TYPE_PPC405_CPC);
|
|
|
|
object_property_add_alias(obj, "sys-clk", OBJECT(&s->cpc), "sys-clk");
|
2022-08-17 18:08:21 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "gpt", &s->gpt, TYPE_PPC405_GPT);
|
2022-08-17 18:08:22 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "ocm", &s->ocm, TYPE_PPC405_OCM);
|
2022-08-17 18:08:23 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "gpio", &s->gpio, TYPE_PPC405_GPIO);
|
2022-08-17 18:08:24 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "dma", &s->dma, TYPE_PPC405_DMA);
|
2022-08-17 18:08:25 +03:00
|
|
|
|
2022-08-17 18:08:36 +03:00
|
|
|
object_initialize_child(obj, "i2c", &s->i2c, TYPE_PPC4xx_I2C);
|
|
|
|
|
2022-08-17 18:08:33 +03:00
|
|
|
object_initialize_child(obj, "ebc", &s->ebc, TYPE_PPC4xx_EBC);
|
2022-08-17 18:08:26 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "opba", &s->opba, TYPE_PPC405_OPBA);
|
2022-08-17 18:08:27 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "pob", &s->pob, TYPE_PPC405_POB);
|
2022-08-17 18:08:28 +03:00
|
|
|
|
2022-08-17 18:08:31 +03:00
|
|
|
object_initialize_child(obj, "plb", &s->plb, TYPE_PPC4xx_PLB);
|
2022-08-17 18:08:29 +03:00
|
|
|
|
|
|
|
object_initialize_child(obj, "mal", &s->mal, TYPE_PPC4xx_MAL);
|
2022-08-09 18:38:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_reset(void *opaque)
|
|
|
|
{
|
|
|
|
cpu_reset(CPU(opaque));
|
|
|
|
}
|
|
|
|
|
2022-08-09 18:38:46 +03:00
|
|
|
static void ppc405_soc_realize(DeviceState *dev, Error **errp)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2022-08-09 18:38:46 +03:00
|
|
|
Ppc405SoCState *s = PPC405_SOC(dev);
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *env;
|
2022-08-17 18:08:21 +03:00
|
|
|
SysBusDevice *sbd;
|
|
|
|
int i;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
/* init CPUs */
|
2022-08-09 18:38:47 +03:00
|
|
|
if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qemu_register_reset(ppc405_reset, &s->cpu);
|
|
|
|
|
|
|
|
env = &s->cpu.env;
|
|
|
|
|
|
|
|
ppc_dcr_init(env, NULL, NULL);
|
2022-08-09 18:38:46 +03:00
|
|
|
|
|
|
|
/* CPU control */
|
2022-08-17 18:08:20 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->cpc), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* PLB arbitrer */
|
2022-08-17 18:08:28 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->plb), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* PLB to OPB bridge */
|
2022-08-17 18:08:27 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->pob), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* OBP arbitrer */
|
2022-08-17 18:08:26 +03:00
|
|
|
sbd = SYS_BUS_DEVICE(&s->opba);
|
|
|
|
if (!sysbus_realize(sbd, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_mmio_map(sbd, 0, 0xef600600);
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Universal interrupt controller */
|
2022-08-17 18:08:35 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->uic), &s->cpu, errp)) {
|
2022-08-09 18:38:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2022-08-17 18:08:35 +03:00
|
|
|
sbd = SYS_BUS_DEVICE(&s->uic);
|
2022-08-17 18:08:34 +03:00
|
|
|
sysbus_connect_irq(sbd, PPCUIC_OUTPUT_INT,
|
2022-08-09 18:38:47 +03:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_INT));
|
2022-08-17 18:08:34 +03:00
|
|
|
sysbus_connect_irq(sbd, PPCUIC_OUTPUT_CINT,
|
2022-08-09 18:38:47 +03:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpu), PPC40x_INPUT_CINT));
|
2021-01-08 20:12:11 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* SDRAM controller */
|
2018-12-14 01:37:37 +03:00
|
|
|
/* XXX 405EP has no ECC interrupt */
|
2022-08-09 18:38:46 +03:00
|
|
|
s->ram_bases[0] = 0;
|
|
|
|
s->ram_sizes[0] = s->ram_size;
|
|
|
|
memory_region_init_alias(&s->ram_banks[0], OBJECT(s),
|
|
|
|
"ppc405.sdram0", s->dram_mr,
|
|
|
|
s->ram_bases[0], s->ram_sizes[0]);
|
|
|
|
|
2022-08-17 18:08:34 +03:00
|
|
|
ppc4xx_sdram_init(env, qdev_get_gpio_in(DEVICE(&s->uic), 17), 1,
|
2022-08-09 18:38:46 +03:00
|
|
|
s->ram_banks, s->ram_bases, s->ram_sizes,
|
|
|
|
s->do_dram_init);
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* External bus controller */
|
2022-08-17 18:08:25 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->ebc), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* DMA controller */
|
2022-08-17 18:08:24 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->dma), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sbd = SYS_BUS_DEVICE(&s->dma);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->dma.irqs); i++) {
|
2022-08-17 18:08:34 +03:00
|
|
|
sysbus_connect_irq(sbd, i, qdev_get_gpio_in(DEVICE(&s->uic), 5 + i));
|
2022-08-17 18:08:24 +03:00
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
|
|
|
/* I2C controller */
|
2022-08-17 18:08:36 +03:00
|
|
|
sbd = SYS_BUS_DEVICE(&s->i2c);
|
|
|
|
if (!sysbus_realize(sbd, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_mmio_map(sbd, 0, 0xef600500);
|
|
|
|
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(DEVICE(&s->uic), 2));
|
2022-08-17 18:08:23 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* GPIO */
|
2022-08-17 18:08:23 +03:00
|
|
|
sbd = SYS_BUS_DEVICE(&s->gpio);
|
|
|
|
if (!sysbus_realize(sbd, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_mmio_map(sbd, 0, 0xef600700);
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Serial ports */
|
2018-04-20 17:52:43 +03:00
|
|
|
if (serial_hd(0) != NULL) {
|
2022-08-09 18:38:46 +03:00
|
|
|
serial_mm_init(get_system_memory(), 0xef600300, 0,
|
2022-08-17 18:08:34 +03:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->uic), 0),
|
2018-04-20 17:52:43 +03:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
|
2011-08-12 03:07:16 +04:00
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
2018-04-20 17:52:43 +03:00
|
|
|
if (serial_hd(1) != NULL) {
|
2022-08-09 18:38:46 +03:00
|
|
|
serial_mm_init(get_system_memory(), 0xef600400, 0,
|
2022-08-17 18:08:34 +03:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->uic), 1),
|
2018-04-20 17:52:43 +03:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
|
2011-08-12 03:07:16 +04:00
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/* OCM */
|
2022-08-17 18:08:22 +03:00
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->ocm), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-24 10:37:21 +04:00
|
|
|
/* GPT */
|
2022-08-17 18:08:21 +03:00
|
|
|
sbd = SYS_BUS_DEVICE(&s->gpt);
|
|
|
|
if (!sysbus_realize(sbd, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysbus_mmio_map(sbd, 0, 0xef600000);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->gpt.irqs); i++) {
|
2022-08-17 18:08:34 +03:00
|
|
|
sysbus_connect_irq(sbd, i, qdev_get_gpio_in(DEVICE(&s->uic), 19 + i));
|
2022-08-17 18:08:21 +03:00
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-24 10:37:21 +04:00
|
|
|
/* MAL */
|
2022-08-17 18:08:29 +03:00
|
|
|
object_property_set_int(OBJECT(&s->mal), "txc-num", 4, &error_abort);
|
|
|
|
object_property_set_int(OBJECT(&s->mal), "rxc-num", 2, &error_abort);
|
|
|
|
if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->mal), &s->cpu, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sbd = SYS_BUS_DEVICE(&s->mal);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->mal.irqs); i++) {
|
2022-08-17 18:08:34 +03:00
|
|
|
sysbus_connect_irq(sbd, i, qdev_get_gpio_in(DEVICE(&s->uic), 11 + i));
|
2022-08-17 18:08:29 +03:00
|
|
|
}
|
2022-08-09 18:38:46 +03:00
|
|
|
|
2007-04-24 10:37:21 +04:00
|
|
|
/* Ethernet */
|
2021-01-08 20:12:11 +03:00
|
|
|
/* Uses UIC IRQs 9, 15, 17 */
|
2022-08-09 18:38:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Property ppc405_soc_properties[] = {
|
|
|
|
DEFINE_PROP_LINK("dram", Ppc405SoCState, dram_mr, TYPE_MEMORY_REGION,
|
|
|
|
MemoryRegion *),
|
2022-08-09 18:38:46 +03:00
|
|
|
DEFINE_PROP_BOOL("dram-init", Ppc405SoCState, do_dram_init, 0),
|
2022-08-09 18:38:45 +03:00
|
|
|
DEFINE_PROP_UINT64("ram-size", Ppc405SoCState, ram_size, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ppc405_soc_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ppc405_soc_realize;
|
2022-08-09 18:38:46 +03:00
|
|
|
/* Reason: only works as part of a ppc405 board/machine */
|
2022-08-09 18:38:45 +03:00
|
|
|
dc->user_creatable = false;
|
|
|
|
device_class_set_props(dc, ppc405_soc_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ppc405_types[] = {
|
|
|
|
{
|
2022-08-17 18:08:27 +03:00
|
|
|
.name = TYPE_PPC405_POB,
|
|
|
|
.parent = TYPE_PPC4xx_DCR_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405PobState),
|
|
|
|
.class_init = ppc405_pob_class_init,
|
|
|
|
}, {
|
2022-08-17 18:08:26 +03:00
|
|
|
.name = TYPE_PPC405_OPBA,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405OpbaState),
|
|
|
|
.class_init = ppc405_opba_class_init,
|
2022-08-17 18:08:25 +03:00
|
|
|
}, {
|
2022-08-17 18:08:24 +03:00
|
|
|
.name = TYPE_PPC405_DMA,
|
|
|
|
.parent = TYPE_PPC4xx_DCR_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405DmaState),
|
|
|
|
.class_init = ppc405_dma_class_init,
|
|
|
|
}, {
|
2022-08-17 18:08:23 +03:00
|
|
|
.name = TYPE_PPC405_GPIO,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405GpioState),
|
|
|
|
.class_init = ppc405_gpio_class_init,
|
|
|
|
}, {
|
2022-08-17 18:08:22 +03:00
|
|
|
.name = TYPE_PPC405_OCM,
|
|
|
|
.parent = TYPE_PPC4xx_DCR_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405OcmState),
|
|
|
|
.class_init = ppc405_ocm_class_init,
|
|
|
|
}, {
|
2022-08-17 18:08:21 +03:00
|
|
|
.name = TYPE_PPC405_GPT,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405GptState),
|
|
|
|
.instance_finalize = ppc405_gpt_finalize,
|
|
|
|
.class_init = ppc405_gpt_class_init,
|
|
|
|
}, {
|
2022-08-17 18:08:20 +03:00
|
|
|
.name = TYPE_PPC405_CPC,
|
|
|
|
.parent = TYPE_PPC4xx_DCR_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405CpcState),
|
|
|
|
.class_init = ppc405_cpc_class_init,
|
|
|
|
}, {
|
2022-08-09 18:38:45 +03:00
|
|
|
.name = TYPE_PPC405_SOC,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(Ppc405SoCState),
|
2022-08-09 18:38:47 +03:00
|
|
|
.instance_init = ppc405_soc_instance_init,
|
2022-08-09 18:38:45 +03:00
|
|
|
.class_init = ppc405_soc_class_init,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TYPES(ppc405_types)
|