2010-05-31 19:54:18 +04:00
|
|
|
/*
|
|
|
|
* TI OMAP SDRAM controller emulation.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Nokia Corporation
|
|
|
|
* Written by Andrzej Zaborowski <andrew@openedhand.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) any later version of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-01-26 21:17:17 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/arm/omap.h"
|
2010-05-31 19:54:18 +04:00
|
|
|
|
|
|
|
/* SDRAM Controller Subsystem */
|
|
|
|
struct omap_sdrc_s {
|
2011-11-24 16:32:34 +04:00
|
|
|
MemoryRegion iomem;
|
2010-05-31 19:54:18 +04:00
|
|
|
uint8_t config;
|
|
|
|
};
|
|
|
|
|
|
|
|
void omap_sdrc_reset(struct omap_sdrc_s *s)
|
|
|
|
{
|
|
|
|
s->config = 0x10;
|
|
|
|
}
|
|
|
|
|
2023-01-09 17:02:55 +03:00
|
|
|
static uint64_t omap_sdrc_read(void *opaque, hwaddr addr, unsigned size)
|
2010-05-31 19:54:18 +04:00
|
|
|
{
|
2023-01-09 17:02:55 +03:00
|
|
|
struct omap_sdrc_s *s = opaque;
|
2010-05-31 19:54:18 +04:00
|
|
|
|
2011-11-24 16:32:34 +04:00
|
|
|
if (size != 4) {
|
|
|
|
return omap_badwidth_read32(opaque, addr);
|
|
|
|
}
|
|
|
|
|
2010-05-31 19:54:18 +04:00
|
|
|
switch (addr) {
|
|
|
|
case 0x00: /* SDRC_REVISION */
|
|
|
|
return 0x20;
|
|
|
|
|
|
|
|
case 0x10: /* SDRC_SYSCONFIG */
|
|
|
|
return s->config;
|
|
|
|
|
|
|
|
case 0x14: /* SDRC_SYSSTATUS */
|
|
|
|
return 1; /* RESETDONE */
|
|
|
|
|
|
|
|
case 0x40: /* SDRC_CS_CFG */
|
|
|
|
case 0x44: /* SDRC_SHARING */
|
|
|
|
case 0x48: /* SDRC_ERR_ADDR */
|
|
|
|
case 0x4c: /* SDRC_ERR_TYPE */
|
|
|
|
case 0x60: /* SDRC_DLLA_SCTRL */
|
|
|
|
case 0x64: /* SDRC_DLLA_STATUS */
|
|
|
|
case 0x68: /* SDRC_DLLB_CTRL */
|
|
|
|
case 0x6c: /* SDRC_DLLB_STATUS */
|
|
|
|
case 0x70: /* SDRC_POWER */
|
|
|
|
case 0x80: /* SDRC_MCFG_0 */
|
|
|
|
case 0x84: /* SDRC_MR_0 */
|
|
|
|
case 0x88: /* SDRC_EMR1_0 */
|
|
|
|
case 0x8c: /* SDRC_EMR2_0 */
|
|
|
|
case 0x90: /* SDRC_EMR3_0 */
|
|
|
|
case 0x94: /* SDRC_DCDL1_CTRL */
|
|
|
|
case 0x98: /* SDRC_DCDL2_CTRL */
|
|
|
|
case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
|
|
|
|
case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
|
|
|
|
case 0xa4: /* SDRC_RFR_CTRL_0 */
|
|
|
|
case 0xa8: /* SDRC_MANUAL_0 */
|
|
|
|
case 0xb0: /* SDRC_MCFG_1 */
|
|
|
|
case 0xb4: /* SDRC_MR_1 */
|
|
|
|
case 0xb8: /* SDRC_EMR1_1 */
|
|
|
|
case 0xbc: /* SDRC_EMR2_1 */
|
|
|
|
case 0xc0: /* SDRC_EMR3_1 */
|
|
|
|
case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
|
|
|
|
case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
|
|
|
|
case 0xd4: /* SDRC_RFR_CTRL_1 */
|
|
|
|
case 0xd8: /* SDRC_MANUAL_1 */
|
|
|
|
return 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMAP_BAD_REG(addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void omap_sdrc_write(void *opaque, hwaddr addr,
|
2011-11-24 16:32:34 +04:00
|
|
|
uint64_t value, unsigned size)
|
2010-05-31 19:54:18 +04:00
|
|
|
{
|
2023-01-09 17:02:55 +03:00
|
|
|
struct omap_sdrc_s *s = opaque;
|
2010-05-31 19:54:18 +04:00
|
|
|
|
2011-11-24 16:32:34 +04:00
|
|
|
if (size != 4) {
|
2015-03-08 21:21:13 +03:00
|
|
|
omap_badwidth_write32(opaque, addr, value);
|
|
|
|
return;
|
2011-11-24 16:32:34 +04:00
|
|
|
}
|
|
|
|
|
2010-05-31 19:54:18 +04:00
|
|
|
switch (addr) {
|
|
|
|
case 0x00: /* SDRC_REVISION */
|
|
|
|
case 0x14: /* SDRC_SYSSTATUS */
|
|
|
|
case 0x48: /* SDRC_ERR_ADDR */
|
|
|
|
case 0x64: /* SDRC_DLLA_STATUS */
|
|
|
|
case 0x6c: /* SDRC_DLLB_STATUS */
|
|
|
|
OMAP_RO_REG(addr);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x10: /* SDRC_SYSCONFIG */
|
|
|
|
if ((value >> 3) != 0x2)
|
|
|
|
fprintf(stderr, "%s: bad SDRAM idle mode %i\n",
|
2017-11-09 01:56:31 +03:00
|
|
|
__func__, (unsigned)value >> 3);
|
2010-05-31 19:54:18 +04:00
|
|
|
if (value & 2)
|
|
|
|
omap_sdrc_reset(s);
|
|
|
|
s->config = value & 0x18;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x40: /* SDRC_CS_CFG */
|
|
|
|
case 0x44: /* SDRC_SHARING */
|
|
|
|
case 0x4c: /* SDRC_ERR_TYPE */
|
|
|
|
case 0x60: /* SDRC_DLLA_SCTRL */
|
|
|
|
case 0x68: /* SDRC_DLLB_CTRL */
|
|
|
|
case 0x70: /* SDRC_POWER */
|
|
|
|
case 0x80: /* SDRC_MCFG_0 */
|
|
|
|
case 0x84: /* SDRC_MR_0 */
|
|
|
|
case 0x88: /* SDRC_EMR1_0 */
|
|
|
|
case 0x8c: /* SDRC_EMR2_0 */
|
|
|
|
case 0x90: /* SDRC_EMR3_0 */
|
|
|
|
case 0x94: /* SDRC_DCDL1_CTRL */
|
|
|
|
case 0x98: /* SDRC_DCDL2_CTRL */
|
|
|
|
case 0x9c: /* SDRC_ACTIM_CTRLA_0 */
|
|
|
|
case 0xa0: /* SDRC_ACTIM_CTRLB_0 */
|
|
|
|
case 0xa4: /* SDRC_RFR_CTRL_0 */
|
|
|
|
case 0xa8: /* SDRC_MANUAL_0 */
|
|
|
|
case 0xb0: /* SDRC_MCFG_1 */
|
|
|
|
case 0xb4: /* SDRC_MR_1 */
|
|
|
|
case 0xb8: /* SDRC_EMR1_1 */
|
|
|
|
case 0xbc: /* SDRC_EMR2_1 */
|
|
|
|
case 0xc0: /* SDRC_EMR3_1 */
|
|
|
|
case 0xc4: /* SDRC_ACTIM_CTRLA_1 */
|
|
|
|
case 0xc8: /* SDRC_ACTIM_CTRLB_1 */
|
|
|
|
case 0xd4: /* SDRC_RFR_CTRL_1 */
|
|
|
|
case 0xd8: /* SDRC_MANUAL_1 */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OMAP_BAD_REG(addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 16:32:34 +04:00
|
|
|
static const MemoryRegionOps omap_sdrc_ops = {
|
|
|
|
.read = omap_sdrc_read,
|
|
|
|
.write = omap_sdrc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2010-05-31 19:54:18 +04:00
|
|
|
};
|
|
|
|
|
2011-11-24 16:32:34 +04:00
|
|
|
struct omap_sdrc_s *omap_sdrc_init(MemoryRegion *sysmem,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr base)
|
2010-05-31 19:54:18 +04:00
|
|
|
{
|
arm: Use g_new() & friends where that makes obvious sense
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer,
for two reasons. One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.
This commit only touches allocations with size arguments of the form
sizeof(T).
Coccinelle semantic patch:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_try_malloc(sizeof(T))
+g_try_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
@@
-g_try_malloc0(sizeof(T))
+g_try_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_try_malloc(sizeof(T) * (n))
+g_try_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression n;
@@
-g_try_malloc0(sizeof(T) * (n))
+g_try_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression p, n;
@@
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
@@
type T;
expression n;
@@
-(T *)g_new(T, n)
+g_new(T, n)
@@
type T;
expression n;
@@
-(T *)g_new0(T, n)
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2015-09-07 12:39:27 +03:00
|
|
|
struct omap_sdrc_s *s = g_new0(struct omap_sdrc_s, 1);
|
2010-05-31 19:54:18 +04:00
|
|
|
|
|
|
|
omap_sdrc_reset(s);
|
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&s->iomem, NULL, &omap_sdrc_ops, s, "omap.sdrc", 0x1000);
|
2011-11-24 16:32:34 +04:00
|
|
|
memory_region_add_subregion(sysmem, base, &s->iomem);
|
2010-05-31 19:54:18 +04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|