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.
|
|
|
|
*/
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.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"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#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"
|
2014-07-10 16:01:03 +04:00
|
|
|
#include "hw/boards.h"
|
2017-08-20 20:23:05 +03:00
|
|
|
#include "hw/i2c/ppc4xx_i2c.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"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.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-04-17 00:09:45 +04:00
|
|
|
|
2013-08-05 17:27:22 +04:00
|
|
|
//#define DEBUG_OPBA
|
|
|
|
//#define DEBUG_SDRAM
|
|
|
|
//#define DEBUG_GPIO
|
|
|
|
//#define DEBUG_SERIAL
|
|
|
|
//#define DEBUG_OCM
|
|
|
|
//#define DEBUG_GPT
|
|
|
|
//#define DEBUG_CLOCKS
|
2007-11-24 05:56:36 +03:00
|
|
|
//#define DEBUG_CLOCKS_LL
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, ppc4xx_bd_info_t *bd,
|
2007-09-27 03:55:31 +04:00
|
|
|
uint32_t flags)
|
2007-04-17 06:50:56 +04:00
|
|
|
{
|
2014-03-09 22:29:41 +04:00
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
2009-10-02 01:12:16 +04:00
|
|
|
ram_addr_t bdloc;
|
2007-04-17 06:50:56 +04:00
|
|
|
int i, n;
|
|
|
|
|
|
|
|
/* We put the bd structure at the top of memory */
|
2007-09-19 01:47:18 +04:00
|
|
|
if (bd->bi_memsize >= 0x01000000UL)
|
2009-10-02 01:12:16 +04:00
|
|
|
bdloc = 0x01000000UL - sizeof(struct ppc4xx_bd_info_t);
|
2007-09-19 01:47:18 +04:00
|
|
|
else
|
2009-10-02 01:12:16 +04:00
|
|
|
bdloc = bd->bi_memsize - sizeof(struct ppc4xx_bd_info_t);
|
2013-12-17 09:07:29 +04:00
|
|
|
stl_be_phys(cs->as, bdloc + 0x00, bd->bi_memstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x04, bd->bi_memsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x08, bd->bi_flashstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x0C, bd->bi_flashsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x10, bd->bi_flashoffset);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x14, bd->bi_sramstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x18, bd->bi_sramsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x1C, bd->bi_bootflags);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x20, bd->bi_ipaddr);
|
2011-07-05 20:28:08 +04:00
|
|
|
for (i = 0; i < 6; i++) {
|
2013-12-17 09:29:06 +04:00
|
|
|
stb_phys(cs->as, bdloc + 0x24 + i, bd->bi_enetaddr[i]);
|
2011-07-05 20:28:08 +04:00
|
|
|
}
|
2013-12-17 09:22:06 +04:00
|
|
|
stw_be_phys(cs->as, bdloc + 0x2A, bd->bi_ethspeed);
|
2013-12-17 09:07:29 +04:00
|
|
|
stl_be_phys(cs->as, bdloc + 0x2C, bd->bi_intfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x30, bd->bi_busfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x34, bd->bi_baudrate);
|
2011-07-05 20:28:08 +04:00
|
|
|
for (i = 0; i < 4; i++) {
|
2013-12-17 09:29:06 +04:00
|
|
|
stb_phys(cs->as, bdloc + 0x38 + i, bd->bi_s_version[i]);
|
2011-07-05 20:28:08 +04:00
|
|
|
}
|
2011-01-13 00:12:31 +03:00
|
|
|
for (i = 0; i < 32; i++) {
|
2013-12-17 09:29:06 +04:00
|
|
|
stb_phys(cs->as, bdloc + 0x3C + i, bd->bi_r_version[i]);
|
2011-01-13 00:12:31 +03:00
|
|
|
}
|
2013-12-17 09:07:29 +04:00
|
|
|
stl_be_phys(cs->as, bdloc + 0x5C, bd->bi_plb_busfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x60, bd->bi_pci_busfreq);
|
2011-07-05 20:28:08 +04:00
|
|
|
for (i = 0; i < 6; i++) {
|
2013-12-17 09:29:06 +04:00
|
|
|
stb_phys(cs->as, bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]);
|
2011-07-05 20:28:08 +04:00
|
|
|
}
|
2007-04-17 06:50:56 +04:00
|
|
|
n = 0x6A;
|
2007-09-27 03:55:31 +04:00
|
|
|
if (flags & 0x00000001) {
|
2007-04-17 06:50:56 +04:00
|
|
|
for (i = 0; i < 6; i++)
|
2013-12-17 09:29:06 +04:00
|
|
|
stb_phys(cs->as, bdloc + n++, bd->bi_pci_enetaddr2[i]);
|
2007-04-17 06:50:56 +04:00
|
|
|
}
|
2013-12-17 09:07:29 +04:00
|
|
|
stl_be_phys(cs->as, bdloc + n, bd->bi_opbfreq);
|
2007-04-17 06:50:56 +04:00
|
|
|
n += 4;
|
|
|
|
for (i = 0; i < 2; i++) {
|
2013-12-17 09:07:29 +04:00
|
|
|
stl_be_phys(cs->as, bdloc + n, bd->bi_iic_fast[i]);
|
2007-04-17 06:50:56 +04:00
|
|
|
n += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bdloc;
|
|
|
|
}
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Shared peripherals */
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Peripheral local bus arbitrer */
|
|
|
|
enum {
|
2017-09-16 17:02:41 +03:00
|
|
|
PLB3A0_ACR = 0x077,
|
|
|
|
PLB4A0_ACR = 0x081,
|
|
|
|
PLB0_BESR = 0x084,
|
|
|
|
PLB0_BEAR = 0x086,
|
|
|
|
PLB0_ACR = 0x087,
|
|
|
|
PLB4A1_ACR = 0x089,
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_plb_t ppc4xx_plb_t;
|
|
|
|
struct ppc4xx_plb_t {
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t acr;
|
|
|
|
uint32_t bear;
|
|
|
|
uint32_t besr;
|
|
|
|
};
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_plb (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_plb_t *plb;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
plb = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case PLB0_ACR:
|
|
|
|
ret = plb->acr;
|
|
|
|
break;
|
|
|
|
case PLB0_BEAR:
|
|
|
|
ret = plb->bear;
|
|
|
|
break;
|
|
|
|
case PLB0_BESR:
|
|
|
|
ret = plb->besr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Avoid gcc warning */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_plb (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_plb_t *plb;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
plb = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case PLB0_ACR:
|
2007-04-24 10:37:21 +04:00
|
|
|
/* We don't care about the actual parameters written as
|
|
|
|
* we don't manage any priorities on the bus
|
|
|
|
*/
|
|
|
|
plb->acr = val & 0xF8000000;
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
case PLB0_BEAR:
|
|
|
|
/* Read only */
|
|
|
|
break;
|
|
|
|
case PLB0_BESR:
|
|
|
|
/* Write-clear */
|
|
|
|
plb->besr &= ~val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_plb_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_plb_t *plb;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
plb = opaque;
|
|
|
|
plb->acr = 0x00000000;
|
|
|
|
plb->bear = 0x00000000;
|
|
|
|
plb->besr = 0x00000000;
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:23:05 +03:00
|
|
|
void ppc4xx_plb_init(CPUPPCState *env)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_plb_t *plb;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
plb = g_malloc0(sizeof(ppc4xx_plb_t));
|
2017-09-16 17:02:41 +03:00
|
|
|
ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
|
|
|
|
ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
|
|
|
|
ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb);
|
|
|
|
ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb);
|
2017-09-16 17:02:41 +03:00
|
|
|
ppc_dcr_register(env, PLB4A1_ACR, plb, &dcr_read_plb, &dcr_write_plb);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(ppc4xx_plb_reset, plb);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* PLB to OPB bridge */
|
|
|
|
enum {
|
|
|
|
POB0_BESR0 = 0x0A0,
|
|
|
|
POB0_BESR1 = 0x0A2,
|
|
|
|
POB0_BEAR = 0x0A4,
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_pob_t ppc4xx_pob_t;
|
|
|
|
struct ppc4xx_pob_t {
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t bear;
|
2012-09-01 00:21:21 +04:00
|
|
|
uint32_t besr0;
|
|
|
|
uint32_t besr1;
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_pob (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_pob_t *pob;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
pob = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_pob (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_pob_t *pob;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
pob = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_pob_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_pob_t *pob;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
pob = opaque;
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static void ppc4xx_pob_init(CPUPPCState *env)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_pob_t *pob;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
pob = g_malloc0(sizeof(ppc4xx_pob_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
|
|
|
|
ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
|
|
|
|
ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(ppc4xx_pob_reset, pob);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* OPB arbitrer */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_opba_t ppc4xx_opba_t;
|
|
|
|
struct ppc4xx_opba_t {
|
2011-08-15 18:17:26 +04:00
|
|
|
MemoryRegion io;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint8_t cr;
|
|
|
|
uint8_t pr;
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t opba_readb (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_opba_t *opba;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
opba = opaque;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opba_writeb (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_opba_t *opba;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
opba = opaque;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t opba_readw (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
ret = opba_readb(opaque, addr) << 8;
|
|
|
|
ret |= opba_readb(opaque, addr + 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opba_writew (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
opba_writeb(opaque, addr, value >> 8);
|
|
|
|
opba_writeb(opaque, addr + 1, value);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t opba_readl (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
ret = opba_readb(opaque, addr) << 24;
|
|
|
|
ret |= opba_readb(opaque, addr + 1) << 16;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opba_writel (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
opba_writeb(opaque, addr, value >> 24);
|
|
|
|
opba_writeb(opaque, addr + 1, value >> 16);
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:26 +04:00
|
|
|
static const MemoryRegionOps opba_ops = {
|
|
|
|
.old_mmio = {
|
|
|
|
.read = { opba_readb, opba_readw, opba_readl, },
|
|
|
|
.write = { opba_writeb, opba_writew, opba_writel, },
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ppc4xx_opba_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_opba_t *opba;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
opba = opaque;
|
|
|
|
opba->cr = 0x00; /* No dynamic priorities - park disabled */
|
|
|
|
opba->pr = 0x11;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void ppc4xx_opba_init(hwaddr base)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_opba_t *opba;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
opba = g_malloc0(sizeof(ppc4xx_opba_t));
|
2007-04-17 00:09:45 +04:00
|
|
|
#ifdef DEBUG_OPBA
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&opba->io, NULL, &opba_ops, opba, "opba", 0x002);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), base, &opba->io);
|
2009-08-15 18:27:05 +04:00
|
|
|
qemu_register_reset(ppc4xx_opba_reset, opba);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code decompression controller */
|
|
|
|
/* XXX: TODO */
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Peripheral controller */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_ebc_t ppc4xx_ebc_t;
|
|
|
|
struct ppc4xx_ebc_t {
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t addr;
|
|
|
|
uint32_t bcr[8];
|
|
|
|
uint32_t bap[8];
|
|
|
|
uint32_t bear;
|
|
|
|
uint32_t besr0;
|
|
|
|
uint32_t besr1;
|
|
|
|
uint32_t cfg;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
EBC0_CFGADDR = 0x012,
|
|
|
|
EBC0_CFGDATA = 0x013,
|
|
|
|
};
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_ebc (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_ebc_t *ebc;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
ebc = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case EBC0_CFGADDR:
|
|
|
|
ret = ebc->addr;
|
|
|
|
break;
|
|
|
|
case EBC0_CFGDATA:
|
|
|
|
switch (ebc->addr) {
|
|
|
|
case 0x00: /* B0CR */
|
|
|
|
ret = ebc->bcr[0];
|
|
|
|
break;
|
|
|
|
case 0x01: /* B1CR */
|
|
|
|
ret = ebc->bcr[1];
|
|
|
|
break;
|
|
|
|
case 0x02: /* B2CR */
|
|
|
|
ret = ebc->bcr[2];
|
|
|
|
break;
|
|
|
|
case 0x03: /* B3CR */
|
|
|
|
ret = ebc->bcr[3];
|
|
|
|
break;
|
|
|
|
case 0x04: /* B4CR */
|
|
|
|
ret = ebc->bcr[4];
|
|
|
|
break;
|
|
|
|
case 0x05: /* B5CR */
|
|
|
|
ret = ebc->bcr[5];
|
|
|
|
break;
|
|
|
|
case 0x06: /* B6CR */
|
|
|
|
ret = ebc->bcr[6];
|
|
|
|
break;
|
|
|
|
case 0x07: /* B7CR */
|
|
|
|
ret = ebc->bcr[7];
|
|
|
|
break;
|
|
|
|
case 0x10: /* B0AP */
|
|
|
|
ret = ebc->bap[0];
|
|
|
|
break;
|
|
|
|
case 0x11: /* B1AP */
|
|
|
|
ret = ebc->bap[1];
|
|
|
|
break;
|
|
|
|
case 0x12: /* B2AP */
|
|
|
|
ret = ebc->bap[2];
|
|
|
|
break;
|
|
|
|
case 0x13: /* B3AP */
|
|
|
|
ret = ebc->bap[3];
|
|
|
|
break;
|
|
|
|
case 0x14: /* B4AP */
|
|
|
|
ret = ebc->bap[4];
|
|
|
|
break;
|
|
|
|
case 0x15: /* B5AP */
|
|
|
|
ret = ebc->bap[5];
|
|
|
|
break;
|
|
|
|
case 0x16: /* B6AP */
|
|
|
|
ret = ebc->bap[6];
|
|
|
|
break;
|
|
|
|
case 0x17: /* B7AP */
|
|
|
|
ret = ebc->bap[7];
|
|
|
|
break;
|
|
|
|
case 0x20: /* BEAR */
|
|
|
|
ret = ebc->bear;
|
|
|
|
break;
|
|
|
|
case 0x21: /* BESR0 */
|
|
|
|
ret = ebc->besr0;
|
|
|
|
break;
|
|
|
|
case 0x22: /* BESR1 */
|
|
|
|
ret = ebc->besr1;
|
|
|
|
break;
|
|
|
|
case 0x23: /* CFG */
|
|
|
|
ret = ebc->cfg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0x00000000;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-26 00:33:43 +04:00
|
|
|
break;
|
2007-04-17 00:09:45 +04:00
|
|
|
default:
|
|
|
|
ret = 0x00000000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_ebc (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_ebc_t *ebc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
ebc = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case EBC0_CFGADDR:
|
|
|
|
ebc->addr = val;
|
|
|
|
break;
|
|
|
|
case EBC0_CFGDATA:
|
|
|
|
switch (ebc->addr) {
|
|
|
|
case 0x00: /* B0CR */
|
|
|
|
break;
|
|
|
|
case 0x01: /* B1CR */
|
|
|
|
break;
|
|
|
|
case 0x02: /* B2CR */
|
|
|
|
break;
|
|
|
|
case 0x03: /* B3CR */
|
|
|
|
break;
|
|
|
|
case 0x04: /* B4CR */
|
|
|
|
break;
|
|
|
|
case 0x05: /* B5CR */
|
|
|
|
break;
|
|
|
|
case 0x06: /* B6CR */
|
|
|
|
break;
|
|
|
|
case 0x07: /* B7CR */
|
|
|
|
break;
|
|
|
|
case 0x10: /* B0AP */
|
|
|
|
break;
|
|
|
|
case 0x11: /* B1AP */
|
|
|
|
break;
|
|
|
|
case 0x12: /* B2AP */
|
|
|
|
break;
|
|
|
|
case 0x13: /* B3AP */
|
|
|
|
break;
|
|
|
|
case 0x14: /* B4AP */
|
|
|
|
break;
|
|
|
|
case 0x15: /* B5AP */
|
|
|
|
break;
|
|
|
|
case 0x16: /* B6AP */
|
|
|
|
break;
|
|
|
|
case 0x17: /* B7AP */
|
|
|
|
break;
|
|
|
|
case 0x20: /* BEAR */
|
|
|
|
break;
|
|
|
|
case 0x21: /* BESR0 */
|
|
|
|
break;
|
|
|
|
case 0x22: /* BESR1 */
|
|
|
|
break;
|
|
|
|
case 0x23: /* CFG */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ebc_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_ebc_t *ebc;
|
2007-04-17 00:09:45 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
ebc = opaque;
|
|
|
|
ebc->addr = 0x00000000;
|
|
|
|
ebc->bap[0] = 0x7F8FFE80;
|
|
|
|
ebc->bcr[0] = 0xFFE28000;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
ebc->bap[i] = 0x00000000;
|
|
|
|
ebc->bcr[i] = 0x00000000;
|
|
|
|
}
|
|
|
|
ebc->besr0 = 0x00000000;
|
|
|
|
ebc->besr1 = 0x00000000;
|
2007-04-24 10:37:21 +04:00
|
|
|
ebc->cfg = 0x80400000;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2017-08-20 20:23:05 +03:00
|
|
|
void ppc405_ebc_init(CPUPPCState *env)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_ebc_t *ebc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(&ebc_reset, ebc);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, EBC0_CFGADDR,
|
|
|
|
ebc, &dcr_read_ebc, &dcr_write_ebc);
|
|
|
|
ppc_dcr_register(env, EBC0_CFGDATA,
|
|
|
|
ebc, &dcr_read_ebc, &dcr_write_ebc);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* 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,
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc405_dma_t ppc405_dma_t;
|
|
|
|
struct ppc405_dma_t {
|
2007-04-17 00:09:45 +04:00
|
|
|
qemu_irq irqs[4];
|
|
|
|
uint32_t cr[4];
|
|
|
|
uint32_t ct[4];
|
|
|
|
uint32_t da[4];
|
|
|
|
uint32_t sa[4];
|
|
|
|
uint32_t sg[4];
|
|
|
|
uint32_t sr;
|
|
|
|
uint32_t sgc;
|
|
|
|
uint32_t slp;
|
|
|
|
uint32_t pol;
|
|
|
|
};
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_dma (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_dma (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_dma_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_dma_t *dma;
|
2007-04-17 00:09:45 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
dma = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4])
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_dma_t *dma;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
dma = g_malloc0(sizeof(ppc405_dma_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(&ppc405_dma_reset, dma);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, DMA0_CR0,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CT0,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_DA0,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SA0,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SG0,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CR1,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CT1,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_DA1,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SA1,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SG1,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CR2,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CT2,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_DA2,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SA2,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SG2,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CR3,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_CT3,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_DA3,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SA3,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SG3,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SR,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SGC,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_SLP,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
|
|
|
ppc_dcr_register(env, DMA0_POL,
|
|
|
|
dma, &dcr_read_dma, &dcr_write_dma);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* GPIO */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc405_gpio_t ppc405_gpio_t;
|
|
|
|
struct ppc405_gpio_t {
|
2011-08-15 18:17:26 +04:00
|
|
|
MemoryRegion io;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t or;
|
|
|
|
uint32_t tcr;
|
|
|
|
uint32_t osrh;
|
|
|
|
uint32_t osrl;
|
|
|
|
uint32_t tsrh;
|
|
|
|
uint32_t tsrl;
|
|
|
|
uint32_t odr;
|
|
|
|
uint32_t ir;
|
|
|
|
uint32_t rr1;
|
|
|
|
uint32_t isr1h;
|
|
|
|
uint32_t isr1l;
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc405_gpio_readb (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_gpio_writeb (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc405_gpio_readw (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_gpio_writew (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc405_gpio_readl (void *opaque, hwaddr addr)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405_gpio_writel (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:26 +04:00
|
|
|
static const MemoryRegionOps ppc405_gpio_ops = {
|
|
|
|
.old_mmio = {
|
|
|
|
.read = { ppc405_gpio_readb, ppc405_gpio_readw, ppc405_gpio_readl, },
|
|
|
|
.write = { ppc405_gpio_writeb, ppc405_gpio_writew, ppc405_gpio_writel, },
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ppc405_gpio_reset (void *opaque)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void ppc405_gpio_init(hwaddr base)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_gpio_t *gpio;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
gpio = g_malloc0(sizeof(ppc405_gpio_t));
|
2007-04-17 00:09:45 +04:00
|
|
|
#ifdef DEBUG_GPIO
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio", 0x038);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), base, &gpio->io);
|
2009-08-15 18:27:05 +04:00
|
|
|
qemu_register_reset(&ppc405_gpio_reset, gpio);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* On Chip Memory */
|
|
|
|
enum {
|
|
|
|
OCM0_ISARC = 0x018,
|
|
|
|
OCM0_ISACNTL = 0x019,
|
|
|
|
OCM0_DSARC = 0x01A,
|
|
|
|
OCM0_DSACNTL = 0x01B,
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc405_ocm_t ppc405_ocm_t;
|
|
|
|
struct ppc405_ocm_t {
|
2011-08-15 18:17:26 +04:00
|
|
|
MemoryRegion ram;
|
|
|
|
MemoryRegion isarc_ram;
|
|
|
|
MemoryRegion dsarc_ram;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc;
|
|
|
|
uint32_t isacntl;
|
|
|
|
uint32_t dsarc;
|
|
|
|
uint32_t dsacntl;
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ocm_update_mappings (ppc405_ocm_t *ocm,
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc, uint32_t isacntl,
|
|
|
|
uint32_t dsarc, uint32_t dsacntl)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OCM
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32
|
|
|
|
" %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32
|
|
|
|
" (%08" PRIx32 " %08" PRIx32 ")\n",
|
2007-04-17 00:09:45 +04:00
|
|
|
isarc, isacntl, dsarc, dsacntl,
|
|
|
|
ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl);
|
|
|
|
#endif
|
|
|
|
if (ocm->isarc != isarc ||
|
|
|
|
(ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) {
|
|
|
|
if (ocm->isacntl & 0x80000000) {
|
|
|
|
/* Unmap previously assigned memory region */
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("OCM unmap ISA %08" PRIx32 "\n", 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 */
|
|
|
|
#ifdef DEBUG_OCM
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("OCM map ISA %08" PRIx32 "\n", isarc);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
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 */
|
|
|
|
#ifdef DEBUG_OCM
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
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 */
|
|
|
|
#ifdef DEBUG_OCM
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("OCM map DSA %08" PRIx32 "\n", dsarc);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_ocm (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_ocm_t *ocm;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
ocm = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_ocm (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_ocm_t *ocm;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc, dsarc, isacntl, dsacntl;
|
|
|
|
|
|
|
|
ocm = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocm_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_ocm_t *ocm;
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t isarc, dsarc, isacntl, dsacntl;
|
|
|
|
|
|
|
|
ocm = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static void ppc405_ocm_init(CPUPPCState *env)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405_ocm_t *ocm;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
ocm = g_malloc0(sizeof(ppc405_ocm_t));
|
2011-08-15 18:17:26 +04:00
|
|
|
/* XXX: Size is 4096 or 0x04000000 */
|
2017-07-07 17:42:53 +03:00
|
|
|
memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4096,
|
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);
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_alias(&ocm->dsarc_ram, NULL, "ppc405.dsarc", &ocm->isarc_ram,
|
2011-08-15 18:17:26 +04:00
|
|
|
0, 4096);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(&ocm_reset, ocm);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, OCM0_ISARC,
|
|
|
|
ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc_dcr_register(env, OCM0_ISACNTL,
|
|
|
|
ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc_dcr_register(env, OCM0_DSARC,
|
|
|
|
ocm, &dcr_read_ocm, &dcr_write_ocm);
|
|
|
|
ppc_dcr_register(env, OCM0_DSACNTL,
|
|
|
|
ocm, &dcr_read_ocm, &dcr_write_ocm);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2007-04-24 10:37:21 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* General purpose timers */
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc4xx_gpt_t ppc4xx_gpt_t;
|
|
|
|
struct ppc4xx_gpt_t {
|
2011-08-15 18:17:26 +04:00
|
|
|
MemoryRegion iomem;
|
2007-04-24 10:37:21 +04:00
|
|
|
int64_t tb_offset;
|
|
|
|
uint32_t tb_freq;
|
2013-12-01 11:49:47 +04:00
|
|
|
QEMUTimer *timer;
|
2007-04-24 10:37:21 +04:00
|
|
|
qemu_irq irqs[5];
|
|
|
|
uint32_t oe;
|
|
|
|
uint32_t ol;
|
|
|
|
uint32_t im;
|
|
|
|
uint32_t is;
|
|
|
|
uint32_t ie;
|
|
|
|
uint32_t comp[5];
|
|
|
|
uint32_t mask[5];
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc4xx_gpt_readb (void *opaque, hwaddr addr)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPT
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
/* XXX: generate a bus fault */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_gpt_writeb (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_I2C
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
/* XXX: generate a bus fault */
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc4xx_gpt_readw (void *opaque, hwaddr addr)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_GPT
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
/* XXX: generate a bus fault */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_gpt_writew (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_I2C
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
/* XXX: generate a bus fault */
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt, int n)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt, int n, int level)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
uint32_t mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mask = 0x00008000;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (gpt->is & gpt->im & mask)
|
|
|
|
qemu_irq_raise(gpt->irqs[i]);
|
|
|
|
else
|
|
|
|
qemu_irq_lower(gpt->irqs[i]);
|
|
|
|
mask = mask >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
|
|
|
/* XXX: TODO */
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t ppc4xx_gpt_readl (void *opaque, hwaddr addr)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_gpt_t *gpt;
|
2007-04-24 10:37:21 +04:00
|
|
|
uint32_t ret;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
#ifdef DEBUG_GPT
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
gpt = opaque;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_gpt_writel (void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, uint32_t value)
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_gpt_t *gpt;
|
2007-04-24 10:37:21 +04:00
|
|
|
int idx;
|
|
|
|
|
|
|
|
#ifdef DEBUG_I2C
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr,
|
|
|
|
value);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
|
|
|
gpt = opaque;
|
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 = {
|
|
|
|
.old_mmio = {
|
|
|
|
.read = { ppc4xx_gpt_readb, ppc4xx_gpt_readw, ppc4xx_gpt_readl, },
|
|
|
|
.write = { ppc4xx_gpt_writeb, ppc4xx_gpt_writew, ppc4xx_gpt_writel, },
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-24 10:37:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ppc4xx_gpt_cb (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_gpt_t *gpt;
|
2007-04-24 10:37:21 +04:00
|
|
|
|
|
|
|
gpt = opaque;
|
|
|
|
ppc4xx_gpt_set_irqs(gpt);
|
|
|
|
ppc4xx_gpt_set_outputs(gpt);
|
|
|
|
ppc4xx_gpt_compute_timer(gpt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc4xx_gpt_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_gpt_t *gpt;
|
2007-04-24 10:37:21 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
gpt = opaque;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])
|
2007-04-24 10:37:21 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc4xx_gpt_t *gpt;
|
2007-04-24 10:37:21 +04:00
|
|
|
int i;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
|
2009-08-15 18:27:05 +04:00
|
|
|
for (i = 0; i < 5; i++) {
|
2009-02-06 01:06:05 +03:00
|
|
|
gpt->irqs[i] = irqs[i];
|
2009-08-15 18:27:05 +04:00
|
|
|
}
|
2013-08-21 19:03:08 +04:00
|
|
|
gpt->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ppc4xx_gpt_cb, gpt);
|
2007-04-24 10:37:21 +04:00
|
|
|
#ifdef DEBUG_GPT
|
2009-08-16 15:13:18 +04:00
|
|
|
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&gpt->iomem, NULL, &gpt_ops, gpt, "gpt", 0x0d4);
|
2011-08-15 18:17:26 +04:00
|
|
|
memory_region_add_subregion(get_system_memory(), base, &gpt->iomem);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(ppc4xx_gpt_reset, gpt);
|
2007-04-24 10:37:21 +04:00
|
|
|
}
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* SPR */
|
2013-01-18 18:57:51 +04:00
|
|
|
void ppc40x_core_reset(PowerPCCPU *cpu)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2013-01-18 18:57:51 +04:00
|
|
|
CPUPPCState *env = &cpu->env;
|
2007-04-17 00:09:45 +04:00
|
|
|
target_ulong dbsr;
|
|
|
|
|
|
|
|
printf("Reset PowerPC core\n");
|
2013-01-18 18:03:43 +04:00
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_RESET);
|
2007-04-17 00:09:45 +04:00
|
|
|
dbsr = env->spr[SPR_40x_DBSR];
|
|
|
|
dbsr &= ~0x00000300;
|
|
|
|
dbsr |= 0x00000100;
|
|
|
|
env->spr[SPR_40x_DBSR] = dbsr;
|
|
|
|
}
|
|
|
|
|
2013-01-18 18:57:51 +04:00
|
|
|
void ppc40x_chip_reset(PowerPCCPU *cpu)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2013-01-18 18:57:51 +04:00
|
|
|
CPUPPCState *env = &cpu->env;
|
2007-04-17 00:09:45 +04:00
|
|
|
target_ulong dbsr;
|
|
|
|
|
|
|
|
printf("Reset PowerPC chip\n");
|
2013-01-18 18:03:43 +04:00
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_RESET);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* XXX: TODO reset all internal peripherals */
|
|
|
|
dbsr = env->spr[SPR_40x_DBSR];
|
|
|
|
dbsr &= ~0x00000300;
|
2007-04-17 06:50:56 +04:00
|
|
|
dbsr |= 0x00000200;
|
2007-04-17 00:09:45 +04:00
|
|
|
env->spr[SPR_40x_DBSR] = dbsr;
|
|
|
|
}
|
|
|
|
|
2013-01-18 18:57:51 +04:00
|
|
|
void ppc40x_system_reset(PowerPCCPU *cpu)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
printf("Reset PowerPC system\n");
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
void store_40x_dbcr0 (CPUPPCState *env, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2013-01-18 18:57:51 +04:00
|
|
|
PowerPCCPU *cpu = ppc_env_get_cpu(env);
|
|
|
|
|
2007-04-17 00:09:45 +04:00
|
|
|
switch ((val >> 28) & 0x3) {
|
|
|
|
case 0x0:
|
|
|
|
/* No action */
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
/* Core reset */
|
2013-01-18 18:57:51 +04:00
|
|
|
ppc40x_core_reset(cpu);
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
/* Chip reset */
|
2013-01-18 18:57:51 +04:00
|
|
|
ppc40x_chip_reset(cpu);
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
/* System reset */
|
2013-01-18 18:57:51 +04:00
|
|
|
ppc40x_system_reset(cpu);
|
2007-04-17 00:09:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* PowerPC 405CR */
|
|
|
|
enum {
|
|
|
|
PPC405CR_CPC0_PLLMR = 0x0B0,
|
|
|
|
PPC405CR_CPC0_CR0 = 0x0B1,
|
|
|
|
PPC405CR_CPC0_CR1 = 0x0B2,
|
|
|
|
PPC405CR_CPC0_PSR = 0x0B4,
|
|
|
|
PPC405CR_CPC0_JTAGID = 0x0B5,
|
|
|
|
PPC405CR_CPC0_ER = 0x0B9,
|
|
|
|
PPC405CR_CPC0_FR = 0x0BA,
|
|
|
|
PPC405CR_CPC0_SR = 0x0BB,
|
|
|
|
};
|
|
|
|
|
2007-04-17 06:50:56 +04:00
|
|
|
enum {
|
|
|
|
PPC405CR_CPU_CLK = 0,
|
|
|
|
PPC405CR_TMR_CLK = 1,
|
|
|
|
PPC405CR_PLB_CLK = 2,
|
|
|
|
PPC405CR_SDRAM_CLK = 3,
|
|
|
|
PPC405CR_OPB_CLK = 4,
|
|
|
|
PPC405CR_EXT_CLK = 5,
|
|
|
|
PPC405CR_UART_CLK = 6,
|
|
|
|
PPC405CR_CLK_NB = 7,
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc405cr_cpc_t ppc405cr_cpc_t;
|
|
|
|
struct ppc405cr_cpc_t {
|
|
|
|
clk_setup_t clk_setup[PPC405CR_CLK_NB];
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t sysclk;
|
|
|
|
uint32_t psr;
|
|
|
|
uint32_t cr0;
|
|
|
|
uint32_t cr1;
|
|
|
|
uint32_t jtagid;
|
|
|
|
uint32_t pllmr;
|
|
|
|
uint32_t er;
|
|
|
|
uint32_t fr;
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
uint64_t VCO_out, PLL_out;
|
|
|
|
uint32_t CPU_clk, TMR_clk, SDRAM_clk, PLB_clk, OPB_clk, EXT_clk, UART_clk;
|
|
|
|
int M, D0, D1, D2;
|
|
|
|
|
|
|
|
D0 = ((cpc->pllmr >> 26) & 0x3) + 1; /* CBDV */
|
|
|
|
if (cpc->pllmr & 0x80000000) {
|
|
|
|
D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */
|
|
|
|
D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */
|
|
|
|
M = D0 * D1 * D2;
|
2017-02-21 16:33:41 +03:00
|
|
|
VCO_out = (uint64_t)cpc->sysclk * M;
|
2007-04-17 00:09:45 +04:00
|
|
|
if (VCO_out < 400000000 || VCO_out > 800000000) {
|
|
|
|
/* PLL cannot lock */
|
|
|
|
cpc->pllmr &= ~0x80000000;
|
|
|
|
goto bypass_pll;
|
|
|
|
}
|
|
|
|
PLL_out = VCO_out / D2;
|
|
|
|
} else {
|
|
|
|
/* Bypass PLL */
|
|
|
|
bypass_pll:
|
|
|
|
M = D0;
|
2017-02-21 16:33:41 +03:00
|
|
|
PLL_out = (uint64_t)cpc->sysclk * M;
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
CPU_clk = PLL_out;
|
|
|
|
if (cpc->cr1 & 0x00800000)
|
|
|
|
TMR_clk = cpc->sysclk; /* Should have a separate clock */
|
|
|
|
else
|
|
|
|
TMR_clk = CPU_clk;
|
|
|
|
PLB_clk = CPU_clk / D0;
|
|
|
|
SDRAM_clk = PLB_clk;
|
|
|
|
D0 = ((cpc->pllmr >> 10) & 0x3) + 1;
|
|
|
|
OPB_clk = PLB_clk / D0;
|
|
|
|
D0 = ((cpc->pllmr >> 24) & 0x3) + 2;
|
|
|
|
EXT_clk = PLB_clk / D0;
|
|
|
|
D0 = ((cpc->cr0 >> 1) & 0x1F) + 1;
|
|
|
|
UART_clk = CPU_clk / D0;
|
|
|
|
/* Setup CPU clocks */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405CR_CPU_CLK], CPU_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup time-base clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405CR_TMR_CLK], TMR_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[PPC405CR_PLB_CLK], PLB_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup SDRAM clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405CR_SDRAM_CLK], SDRAM_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[PPC405CR_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[PPC405CR_EXT_CLK], EXT_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Setup UART clock */
|
2007-04-17 06:50:56 +04:00
|
|
|
clk_setup(&cpc->clk_setup[PPC405CR_UART_CLK], UART_clk);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_crcpc (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405cr_cpc_t *cpc;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case PPC405CR_CPC0_PLLMR:
|
|
|
|
ret = cpc->pllmr;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_CR0:
|
|
|
|
ret = cpc->cr0;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_CR1:
|
|
|
|
ret = cpc->cr1;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_PSR:
|
|
|
|
ret = cpc->psr;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_JTAGID:
|
|
|
|
ret = cpc->jtagid;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_ER:
|
|
|
|
ret = cpc->er;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_FR:
|
|
|
|
ret = cpc->fr;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_SR:
|
|
|
|
ret = ~(cpc->er | cpc->fr) & 0xFFFF0000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Avoid gcc warning */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_crcpc (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405cr_cpc_t *cpc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc = opaque;
|
|
|
|
switch (dcrn) {
|
|
|
|
case PPC405CR_CPC0_PLLMR:
|
|
|
|
cpc->pllmr = val & 0xFFF77C3F;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_CR0:
|
|
|
|
cpc->cr0 = val & 0x0FFFFFFE;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_CR1:
|
|
|
|
cpc->cr1 = val & 0x00800000;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_PSR:
|
|
|
|
/* Read-only */
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_JTAGID:
|
|
|
|
/* Read-only */
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_ER:
|
|
|
|
cpc->er = val & 0xBFFC0000;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_FR:
|
|
|
|
cpc->fr = val & 0xBFFC0000;
|
|
|
|
break;
|
|
|
|
case PPC405CR_CPC0_SR:
|
|
|
|
/* Read-only */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405cr_cpc_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405cr_cpc_t *cpc;
|
2007-04-17 00:09:45 +04:00
|
|
|
int D;
|
|
|
|
|
|
|
|
cpc = opaque;
|
|
|
|
/* Compute PLLMR value from PSR settings */
|
|
|
|
cpc->pllmr = 0x80000000;
|
|
|
|
/* PFWD */
|
|
|
|
switch ((cpc->psr >> 30) & 3) {
|
|
|
|
case 0:
|
|
|
|
/* Bypass */
|
|
|
|
cpc->pllmr &= ~0x80000000;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Divide by 3 */
|
|
|
|
cpc->pllmr |= 5 << 16;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* Divide by 4 */
|
|
|
|
cpc->pllmr |= 4 << 16;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* Divide by 6 */
|
|
|
|
cpc->pllmr |= 2 << 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* PFBD */
|
|
|
|
D = (cpc->psr >> 28) & 3;
|
|
|
|
cpc->pllmr |= (D + 1) << 20;
|
|
|
|
/* PT */
|
|
|
|
D = (cpc->psr >> 25) & 7;
|
|
|
|
switch (D) {
|
|
|
|
case 0x2:
|
|
|
|
cpc->pllmr |= 0x13;
|
|
|
|
break;
|
|
|
|
case 0x4:
|
|
|
|
cpc->pllmr |= 0x15;
|
|
|
|
break;
|
|
|
|
case 0x5:
|
|
|
|
cpc->pllmr |= 0x16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* PDC */
|
|
|
|
D = (cpc->psr >> 23) & 3;
|
|
|
|
cpc->pllmr |= D << 26;
|
|
|
|
/* ODP */
|
|
|
|
D = (cpc->psr >> 21) & 3;
|
|
|
|
cpc->pllmr |= D << 10;
|
|
|
|
/* EBPD */
|
|
|
|
D = (cpc->psr >> 17) & 3;
|
|
|
|
cpc->pllmr |= D << 24;
|
|
|
|
cpc->cr0 = 0x0000003C;
|
|
|
|
cpc->cr1 = 0x2B0D8800;
|
|
|
|
cpc->er = 0x00000000;
|
|
|
|
cpc->fr = 0x00000000;
|
|
|
|
ppc405cr_clk_setup(cpc);
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc405cr_clk_init (ppc405cr_cpc_t *cpc)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
|
|
|
int D;
|
|
|
|
|
|
|
|
/* XXX: this should be read from IO pins */
|
|
|
|
cpc->psr = 0x00000000; /* 8 bits ROM */
|
|
|
|
/* PFWD */
|
|
|
|
D = 0x2; /* Divide by 4 */
|
|
|
|
cpc->psr |= D << 30;
|
|
|
|
/* PFBD */
|
|
|
|
D = 0x1; /* Divide by 2 */
|
|
|
|
cpc->psr |= D << 28;
|
|
|
|
/* PDC */
|
|
|
|
D = 0x1; /* Divide by 2 */
|
|
|
|
cpc->psr |= D << 23;
|
|
|
|
/* PT */
|
|
|
|
D = 0x5; /* M = 16 */
|
|
|
|
cpc->psr |= D << 25;
|
|
|
|
/* ODP */
|
|
|
|
D = 0x1; /* Divide by 2 */
|
|
|
|
cpc->psr |= D << 21;
|
|
|
|
/* EBDP */
|
|
|
|
D = 0x2; /* Divide by 4 */
|
|
|
|
cpc->psr |= D << 17;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static void ppc405cr_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[7],
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t sysclk)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405cr_cpc_t *cpc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
memcpy(cpc->clk_setup, clk_setup,
|
2009-10-02 01:12:16 +04:00
|
|
|
PPC405CR_CLK_NB * sizeof(clk_setup_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
cpc->sysclk = sysclk;
|
|
|
|
cpc->jtagid = 0x42051049;
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc,
|
|
|
|
&dcr_read_crcpc, &dcr_write_crcpc);
|
|
|
|
ppc405cr_clk_init(cpc);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(ppc405cr_cpc_reset, cpc);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem,
|
2011-08-12 03:07:17 +04:00
|
|
|
MemoryRegion ram_memories[4],
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr ram_bases[4],
|
|
|
|
hwaddr ram_sizes[4],
|
2011-08-12 03:07:17 +04:00
|
|
|
uint32_t sysclk, qemu_irq **picp,
|
|
|
|
int do_init)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
clk_setup_t clk_setup[PPC405CR_CLK_NB];
|
2007-04-17 00:09:45 +04:00
|
|
|
qemu_irq dma_irqs[4];
|
2012-12-01 07:47:33 +04:00
|
|
|
PowerPCCPU *cpu;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *env;
|
2007-04-17 00:09:45 +04:00
|
|
|
qemu_irq *pic, *irqs;
|
|
|
|
|
|
|
|
memset(clk_setup, 0, sizeof(clk_setup));
|
2017-10-09 22:50:55 +03:00
|
|
|
cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405crc"),
|
|
|
|
&clk_setup[PPC405CR_CPU_CLK],
|
2007-04-17 06:50:56 +04:00
|
|
|
&clk_setup[PPC405CR_TMR_CLK], sysclk);
|
2012-12-01 07:47:33 +04:00
|
|
|
env = &cpu->env;
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Memory mapped devices registers */
|
|
|
|
/* PLB arbitrer */
|
|
|
|
ppc4xx_plb_init(env);
|
|
|
|
/* PLB to OPB bridge */
|
|
|
|
ppc4xx_pob_init(env);
|
|
|
|
/* OBP arbitrer */
|
2009-08-15 18:27:05 +04:00
|
|
|
ppc4xx_opba_init(0xef600600);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Universal interrupt controller */
|
2011-08-21 07:09:37 +04:00
|
|
|
irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
|
2007-04-17 00:09:45 +04:00
|
|
|
irqs[PPCUIC_OUTPUT_INT] =
|
2007-10-01 06:55:07 +04:00
|
|
|
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
|
2007-04-17 00:09:45 +04:00
|
|
|
irqs[PPCUIC_OUTPUT_CINT] =
|
2007-10-01 06:55:07 +04:00
|
|
|
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
|
2007-04-17 00:09:45 +04:00
|
|
|
pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
|
|
|
|
*picp = pic;
|
|
|
|
/* SDRAM controller */
|
2011-08-15 18:17:27 +04:00
|
|
|
ppc4xx_sdram_init(env, pic[14], 1, ram_memories,
|
|
|
|
ram_bases, ram_sizes, do_init);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* External bus controller */
|
|
|
|
ppc405_ebc_init(env);
|
|
|
|
/* DMA controller */
|
2007-04-17 06:50:56 +04:00
|
|
|
dma_irqs[0] = pic[26];
|
|
|
|
dma_irqs[1] = pic[25];
|
|
|
|
dma_irqs[2] = pic[24];
|
|
|
|
dma_irqs[3] = pic[23];
|
2007-04-17 00:09:45 +04:00
|
|
|
ppc405_dma_init(env, dma_irqs);
|
|
|
|
/* Serial ports */
|
|
|
|
if (serial_hds[0] != NULL) {
|
2011-08-12 03:07:17 +04:00
|
|
|
serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
|
2011-08-12 03:07:16 +04:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
if (serial_hds[1] != NULL) {
|
2011-08-12 03:07:17 +04:00
|
|
|
serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
|
2011-08-12 03:07:16 +04:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
/* IIC controller */
|
2017-08-20 20:23:05 +03:00
|
|
|
sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, pic[2]);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* GPIO */
|
2009-08-15 18:27:05 +04:00
|
|
|
ppc405_gpio_init(0xef600700);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* CPU control */
|
|
|
|
ppc405cr_cpc_init(env, clk_setup, sysclk);
|
|
|
|
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* 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
|
|
|
};
|
|
|
|
|
2007-04-17 06:50:56 +04:00
|
|
|
enum {
|
|
|
|
PPC405EP_CPU_CLK = 0,
|
|
|
|
PPC405EP_PLB_CLK = 1,
|
|
|
|
PPC405EP_OPB_CLK = 2,
|
|
|
|
PPC405EP_EBC_CLK = 3,
|
|
|
|
PPC405EP_MAL_CLK = 4,
|
|
|
|
PPC405EP_PCI_CLK = 5,
|
|
|
|
PPC405EP_UART0_CLK = 6,
|
|
|
|
PPC405EP_UART1_CLK = 7,
|
|
|
|
PPC405EP_CLK_NB = 8,
|
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
typedef struct ppc405ep_cpc_t ppc405ep_cpc_t;
|
|
|
|
struct ppc405ep_cpc_t {
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t sysclk;
|
2009-10-02 01:12:16 +04:00
|
|
|
clk_setup_t clk_setup[PPC405EP_CLK_NB];
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t boot;
|
|
|
|
uint32_t epctl;
|
|
|
|
uint32_t pllmr[2];
|
|
|
|
uint32_t ucr;
|
|
|
|
uint32_t srr;
|
|
|
|
uint32_t jtagid;
|
|
|
|
uint32_t pci;
|
2007-04-24 10:37:21 +04:00
|
|
|
/* Clock and power management */
|
|
|
|
uint32_t er;
|
|
|
|
uint32_t fr;
|
|
|
|
uint32_t sr;
|
2007-04-17 00:09:45 +04:00
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
static void ppc405ep_compute_clocks (ppc405ep_cpc_t *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 */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M);
|
|
|
|
#endif
|
2007-04-17 00:09:45 +04:00
|
|
|
D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D);
|
|
|
|
#endif
|
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 */
|
|
|
|
printf("VCO out of range %" PRIu64 "\n", VCO_out);
|
|
|
|
#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 */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
CPU_clk = PLL_out / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
PLB_clk = CPU_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
OPB_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
EBC_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
MAL_clk = PLB_clk / D;
|
|
|
|
D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
PCI_clk = PLB_clk / D;
|
|
|
|
D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
UART0_clk = PLL_out / D;
|
|
|
|
D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */
|
2007-11-24 05:56:36 +03:00
|
|
|
#ifdef DEBUG_CLOCKS_LL
|
|
|
|
printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D);
|
2007-04-17 00:09:45 +04:00
|
|
|
#endif
|
|
|
|
UART1_clk = PLL_out / D;
|
|
|
|
#ifdef DEBUG_CLOCKS
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64
|
2007-04-17 00:09:45 +04:00
|
|
|
" PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out);
|
2007-11-24 05:56:36 +03:00
|
|
|
printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32
|
|
|
|
" MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32
|
|
|
|
" UART1 %" PRIu32 "\n",
|
2007-04-17 00:09:45 +04:00
|
|
|
CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk,
|
|
|
|
UART0_clk, UART1_clk);
|
|
|
|
#endif
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static uint32_t dcr_read_epcpc (void *opaque, int dcrn)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405ep_cpc_t *cpc;
|
2009-12-21 16:02:39 +03:00
|
|
|
uint32_t ret;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:02:39 +03:00
|
|
|
static void dcr_write_epcpc (void *opaque, int dcrn, uint32_t val)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405ep_cpc_t *cpc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc = opaque;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ppc405ep_cpc_reset (void *opaque)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405ep_cpc_t *cpc = opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
|
|
|
cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
|
|
|
|
cpc->epctl = 0x00000000;
|
|
|
|
cpc->pllmr[0] = 0x00011010;
|
|
|
|
cpc->pllmr[1] = 0x40000000;
|
|
|
|
cpc->ucr = 0x00000000;
|
|
|
|
cpc->srr = 0x00040000;
|
|
|
|
cpc->pci = 0x00000000;
|
2007-04-24 10:37:21 +04:00
|
|
|
cpc->er = 0x00000000;
|
|
|
|
cpc->fr = 0x00000000;
|
|
|
|
cpc->sr = 0x00000000;
|
2007-04-17 00:09:45 +04:00
|
|
|
ppc405ep_compute_clocks(cpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: sysclk should be between 25 and 100 MHz */
|
2012-03-14 04:38:23 +04:00
|
|
|
static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],
|
2007-04-17 00:09:45 +04:00
|
|
|
uint32_t sysclk)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
ppc405ep_cpc_t *cpc;
|
2007-04-17 00:09:45 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
cpc = g_malloc0(sizeof(ppc405ep_cpc_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
memcpy(cpc->clk_setup, clk_setup,
|
2009-10-02 01:12:16 +04:00
|
|
|
PPC405EP_CLK_NB * sizeof(clk_setup_t));
|
2009-02-06 01:06:05 +03:00
|
|
|
cpc->jtagid = 0x20267049;
|
|
|
|
cpc->sysclk = sysclk;
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(&ppc405ep_cpc_reset, cpc);
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
2007-04-24 10:37:21 +04:00
|
|
|
#if 0
|
2009-02-06 01:06:05 +03:00
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
|
|
|
ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc,
|
|
|
|
&dcr_read_epcpc, &dcr_write_epcpc);
|
2007-04-24 10:37:21 +04:00
|
|
|
#endif
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
|
2011-08-12 03:07:17 +04:00
|
|
|
MemoryRegion ram_memories[2],
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr ram_bases[2],
|
|
|
|
hwaddr ram_sizes[2],
|
2011-08-12 03:07:17 +04:00
|
|
|
uint32_t sysclk, qemu_irq **picp,
|
|
|
|
int do_init)
|
2007-04-17 00:09:45 +04:00
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup;
|
2007-04-24 10:37:21 +04:00
|
|
|
qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4];
|
2012-12-01 07:47:33 +04:00
|
|
|
PowerPCCPU *cpu;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPUPPCState *env;
|
2007-04-17 00:09:45 +04:00
|
|
|
qemu_irq *pic, *irqs;
|
|
|
|
|
|
|
|
memset(clk_setup, 0, sizeof(clk_setup));
|
|
|
|
/* init CPUs */
|
2017-10-09 22:50:55 +03:00
|
|
|
cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"),
|
|
|
|
&clk_setup[PPC405EP_CPU_CLK],
|
2007-04-24 10:37:21 +04:00
|
|
|
&tlb_clk_setup, sysclk);
|
2012-12-01 07:47:33 +04:00
|
|
|
env = &cpu->env;
|
2007-04-24 10:37:21 +04:00
|
|
|
clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb;
|
|
|
|
clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque;
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Internal devices init */
|
|
|
|
/* Memory mapped devices registers */
|
|
|
|
/* PLB arbitrer */
|
|
|
|
ppc4xx_plb_init(env);
|
|
|
|
/* PLB to OPB bridge */
|
|
|
|
ppc4xx_pob_init(env);
|
|
|
|
/* OBP arbitrer */
|
2009-08-15 18:27:05 +04:00
|
|
|
ppc4xx_opba_init(0xef600600);
|
2012-02-21 22:01:11 +04:00
|
|
|
/* Initialize timers */
|
2012-12-01 07:43:18 +04:00
|
|
|
ppc_booke_timers_init(cpu, sysclk, 0);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Universal interrupt controller */
|
2011-08-21 07:09:37 +04:00
|
|
|
irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
|
2007-04-17 00:09:45 +04:00
|
|
|
irqs[PPCUIC_OUTPUT_INT] =
|
2007-10-01 06:55:07 +04:00
|
|
|
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
|
2007-04-17 00:09:45 +04:00
|
|
|
irqs[PPCUIC_OUTPUT_CINT] =
|
2007-10-01 06:55:07 +04:00
|
|
|
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
|
2007-04-17 00:09:45 +04:00
|
|
|
pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
|
|
|
|
*picp = pic;
|
|
|
|
/* SDRAM controller */
|
2008-04-28 04:00:24 +04:00
|
|
|
/* XXX 405EP has no ECC interrupt */
|
2011-08-15 18:17:27 +04:00
|
|
|
ppc4xx_sdram_init(env, pic[17], 2, ram_memories,
|
|
|
|
ram_bases, ram_sizes, do_init);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* External bus controller */
|
|
|
|
ppc405_ebc_init(env);
|
|
|
|
/* DMA controller */
|
2008-04-28 04:00:24 +04:00
|
|
|
dma_irqs[0] = pic[5];
|
|
|
|
dma_irqs[1] = pic[6];
|
|
|
|
dma_irqs[2] = pic[7];
|
|
|
|
dma_irqs[3] = pic[8];
|
2007-04-17 00:09:45 +04:00
|
|
|
ppc405_dma_init(env, dma_irqs);
|
|
|
|
/* IIC controller */
|
2017-08-20 20:23:05 +03:00
|
|
|
sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, pic[2]);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* GPIO */
|
2009-08-15 18:27:05 +04:00
|
|
|
ppc405_gpio_init(0xef600700);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* Serial ports */
|
|
|
|
if (serial_hds[0] != NULL) {
|
2011-08-12 03:07:17 +04:00
|
|
|
serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
|
2011-08-12 03:07:16 +04:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
if (serial_hds[1] != NULL) {
|
2011-08-12 03:07:17 +04:00
|
|
|
serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
|
2011-08-12 03:07:16 +04:00
|
|
|
PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
|
|
|
|
DEVICE_BIG_ENDIAN);
|
2007-04-17 00:09:45 +04:00
|
|
|
}
|
|
|
|
/* OCM */
|
2009-04-10 18:29:45 +04:00
|
|
|
ppc405_ocm_init(env);
|
2007-04-24 10:37:21 +04:00
|
|
|
/* GPT */
|
2008-04-28 04:00:24 +04:00
|
|
|
gpt_irqs[0] = pic[19];
|
|
|
|
gpt_irqs[1] = pic[20];
|
|
|
|
gpt_irqs[2] = pic[21];
|
|
|
|
gpt_irqs[3] = pic[22];
|
|
|
|
gpt_irqs[4] = pic[23];
|
2009-08-15 18:27:05 +04:00
|
|
|
ppc4xx_gpt_init(0xef600000, gpt_irqs);
|
2007-04-17 00:09:45 +04:00
|
|
|
/* PCI */
|
2008-04-28 04:00:24 +04:00
|
|
|
/* Uses pic[3], pic[16], pic[18] */
|
2007-04-24 10:37:21 +04:00
|
|
|
/* MAL */
|
2008-04-28 04:00:24 +04:00
|
|
|
mal_irqs[0] = pic[11];
|
|
|
|
mal_irqs[1] = pic[12];
|
|
|
|
mal_irqs[2] = pic[13];
|
|
|
|
mal_irqs[3] = pic[14];
|
2017-08-20 20:23:05 +03:00
|
|
|
ppc4xx_mal_init(env, 4, 2, mal_irqs);
|
2007-04-24 10:37:21 +04:00
|
|
|
/* Ethernet */
|
2008-04-28 04:00:24 +04:00
|
|
|
/* Uses pic[9], pic[15], pic[17] */
|
2007-04-17 00:09:45 +04:00
|
|
|
/* CPU control */
|
|
|
|
ppc405ep_cpc_init(env, clk_setup, sysclk);
|
|
|
|
|
|
|
|
return env;
|
|
|
|
}
|