All of lore.kernel.org
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: clg@kaod.org, Daniel Henrique Barboza <danielhb413@gmail.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: [PATCH 04/22] ppc/ppc405: QOM'ify OCM
Date: Sat, 13 Aug 2022 17:34:31 +0200 (CEST)	[thread overview]
Message-ID: <945147317f98dd64e0dfa7a91a9786f3c111e903.1660402839.git.balaton@eik.bme.hu> (raw)
In-Reply-To: <cover.1660402839.git.balaton@eik.bme.hu>

From: Cédric Le Goater <clg@kaod.org>

The OCM controller is currently modeled as a simple DCR device with
a couple of memory regions.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/ppc/ppc405.h    | 16 ++++++++++
 hw/ppc/ppc405_uc.c | 77 +++++++++++++++++++++++-----------------------
 2 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/hw/ppc/ppc405.h b/hw/ppc/ppc405.h
index bcf55e4f6b..a5b493d3e7 100644
--- a/hw/ppc/ppc405.h
+++ b/hw/ppc/ppc405.h
@@ -63,6 +63,21 @@ struct ppc4xx_bd_info_t {
     uint32_t bi_iic_fast[2];
 };
 
+/* On Chip Memory */
+#define TYPE_PPC405_OCM "ppc405-ocm"
+OBJECT_DECLARE_SIMPLE_TYPE(Ppc405OcmState, PPC405_OCM);
+struct Ppc405OcmState {
+    Ppc4xxDcrDeviceState parent_obj;
+
+    MemoryRegion ram;
+    MemoryRegion isarc_ram;
+    MemoryRegion dsarc_ram;
+    uint32_t isarc;
+    uint32_t isacntl;
+    uint32_t dsarc;
+    uint32_t dsacntl;
+};
+
 /* General purpose timers */
 #define TYPE_PPC405_GPT "ppc405-gpt"
 OBJECT_DECLARE_SIMPLE_TYPE(Ppc405GptState, PPC405_GPT);
@@ -136,6 +151,7 @@ struct Ppc405SoCState {
     DeviceState *uic;
     Ppc405CpcState cpc;
     Ppc405GptState gpt;
+    Ppc405OcmState ocm;
 };
 
 /* PowerPC 405 core */
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index bf95fabdc0..2282cfcd18 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -773,20 +773,9 @@ enum {
     OCM0_DSACNTL = 0x01B,
 };
 
-typedef struct ppc405_ocm_t ppc405_ocm_t;
-struct ppc405_ocm_t {
-    MemoryRegion ram;
-    MemoryRegion isarc_ram;
-    MemoryRegion dsarc_ram;
-    uint32_t isarc;
-    uint32_t isacntl;
-    uint32_t dsarc;
-    uint32_t dsacntl;
-};
-
-static void ocm_update_mappings (ppc405_ocm_t *ocm,
-                                 uint32_t isarc, uint32_t isacntl,
-                                 uint32_t dsarc, uint32_t dsacntl)
+static void ocm_update_mappings(Ppc405OcmState *ocm,
+                                uint32_t isarc, uint32_t isacntl,
+                                uint32_t dsarc, uint32_t dsacntl)
 {
     trace_ocm_update_mappings(isarc, isacntl, dsarc, dsacntl, ocm->isarc,
                               ocm->isacntl, ocm->dsarc, ocm->dsacntl);
@@ -828,12 +817,11 @@ static void ocm_update_mappings (ppc405_ocm_t *ocm,
     }
 }
 
-static uint32_t dcr_read_ocm (void *opaque, int dcrn)
+static uint32_t dcr_read_ocm(void *opaque, int dcrn)
 {
-    ppc405_ocm_t *ocm;
+    Ppc405OcmState *ocm = opaque;
     uint32_t ret;
 
-    ocm = opaque;
     switch (dcrn) {
     case OCM0_ISARC:
         ret = ocm->isarc;
@@ -855,12 +843,11 @@ static uint32_t dcr_read_ocm (void *opaque, int dcrn)
     return ret;
 }
 
-static void dcr_write_ocm (void *opaque, int dcrn, uint32_t val)
+static void dcr_write_ocm(void *opaque, int dcrn, uint32_t val)
 {
-    ppc405_ocm_t *ocm;
+    Ppc405OcmState *ocm = opaque;
     uint32_t isarc, dsarc, isacntl, dsacntl;
 
-    ocm = opaque;
     isarc = ocm->isarc;
     dsarc = ocm->dsarc;
     isacntl = ocm->isacntl;
@@ -886,12 +873,11 @@ static void dcr_write_ocm (void *opaque, int dcrn, uint32_t val)
     ocm->dsacntl = dsacntl;
 }
 
-static void ocm_reset (void *opaque)
+static void ppc405_ocm_reset(DeviceState *dev)
 {
-    ppc405_ocm_t *ocm;
+    Ppc405OcmState *ocm = PPC405_OCM(dev);
     uint32_t isarc, dsarc, isacntl, dsacntl;
 
-    ocm = opaque;
     isarc = 0x00000000;
     isacntl = 0x00000000;
     dsarc = 0x00000000;
@@ -903,25 +889,31 @@ static void ocm_reset (void *opaque)
     ocm->dsacntl = dsacntl;
 }
 
-static void ppc405_ocm_init(CPUPPCState *env)
+static void ppc405_ocm_realize(DeviceState *dev, Error **errp)
 {
-    ppc405_ocm_t *ocm;
+    Ppc405OcmState *ocm = PPC405_OCM(dev);
+    Ppc4xxDcrDeviceState *dcr = PPC4xx_DCR_DEVICE(dev);
 
-    ocm = g_new0(ppc405_ocm_t, 1);
     /* XXX: Size is 4096 or 0x04000000 */
-    memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4 * KiB,
+    memory_region_init_ram(&ocm->isarc_ram, OBJECT(ocm), "ppc405.ocm", 4 * KiB,
                            &error_fatal);
-    memory_region_init_alias(&ocm->dsarc_ram, NULL, "ppc405.dsarc",
+    memory_region_init_alias(&ocm->dsarc_ram, OBJECT(ocm), "ppc405.dsarc",
                              &ocm->isarc_ram, 0, 4 * KiB);
-    qemu_register_reset(&ocm_reset, ocm);
-    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);
+
+    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;
 }
 
 /*****************************************************************************/
@@ -1417,6 +1409,8 @@ static void ppc405_soc_instance_init(Object *obj)
     object_property_add_alias(obj, "sys-clk", OBJECT(&s->cpc), "sys-clk");
 
     object_initialize_child(obj, "gpt", &s->gpt, TYPE_PPC405_GPT);
+
+    object_initialize_child(obj, "ocm", &s->ocm, TYPE_PPC405_OCM);
 }
 
 static void ppc405_reset(void *opaque)
@@ -1513,7 +1507,9 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
     }
 
     /* OCM */
-    ppc405_ocm_init(env);
+    if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->ocm), &s->cpu, errp)) {
+        return;
+    }
 
     /* GPT */
     sbd = SYS_BUS_DEVICE(&s->gpt);
@@ -1556,6 +1552,11 @@ static void ppc405_soc_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo ppc405_types[] = {
     {
+        .name           = TYPE_PPC405_OCM,
+        .parent         = TYPE_PPC4xx_DCR_DEVICE,
+        .instance_size  = sizeof(Ppc405OcmState),
+        .class_init     = ppc405_ocm_class_init,
+    }, {
         .name           = TYPE_PPC405_GPT,
         .parent         = TYPE_SYS_BUS_DEVICE,
         .instance_size  = sizeof(Ppc405GptState),
-- 
2.30.4



  parent reply	other threads:[~2022-08-13 15:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13 15:34 [PATCH 00/22] QOMify PPC4xx devices and minor clean ups BALATON Zoltan
2022-08-13 15:34 ` [PATCH 01/22] ppc/ppc4xx: Introduce a DCR device model BALATON Zoltan
2022-08-16  7:32   ` Cédric Le Goater
2022-08-16  9:33     ` BALATON Zoltan
2022-08-16 11:13       ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 02/22] ppc/ppc405: QOM'ify CPC BALATON Zoltan
2022-08-13 15:34 ` [PATCH 03/22] ppc/ppc405: QOM'ify GPT BALATON Zoltan
2022-08-13 15:34 ` BALATON Zoltan [this message]
2022-08-13 15:34 ` [PATCH 05/22] ppc/ppc405: QOM'ify GPIO BALATON Zoltan
2022-08-13 15:34 ` [PATCH 06/22] ppc/ppc405: QOM'ify DMA BALATON Zoltan
2022-08-13 15:34 ` [PATCH 07/22] ppc/ppc405: QOM'ify EBC BALATON Zoltan
2022-08-13 15:34 ` [PATCH 08/22] ppc/ppc405: QOM'ify OPBA BALATON Zoltan
2022-08-13 15:34 ` [PATCH 09/22] ppc/ppc405: QOM'ify POB BALATON Zoltan
2022-08-13 15:34 ` [PATCH 10/22] ppc/ppc405: QOM'ify PLB BALATON Zoltan
2022-08-13 15:34 ` [PATCH 11/22] ppc/ppc405: QOM'ify MAL BALATON Zoltan
2022-08-13 15:34 ` [PATCH 12/22] ppc4xx: Move PLB model to ppc4xx_devs.c BALATON Zoltan
2022-08-16  7:34   ` Cédric Le Goater
2022-08-16  9:35     ` BALATON Zoltan
2022-08-13 15:34 ` [PATCH 13/22] ppc4xx: Move EBC " BALATON Zoltan
2022-08-16  7:35   ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 14/22] ppc/ppc405: Use an embedded PPCUIC model in SoC state BALATON Zoltan
2022-08-13 15:34 ` [PATCH 15/22] hw/intc/ppc-uic: Convert ppc-uic to a PPC4xx DCR device BALATON Zoltan
2022-08-16  7:36   ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 16/22] ppc/ppc405: Use an explicit I2C object BALATON Zoltan
2022-08-13 15:34 ` [PATCH 17/22] ppc/ppc405: QOM'ify FPGA BALATON Zoltan
2022-08-13 15:34 ` [PATCH 18/22] ppc405: Move machine specific code to ppc405_boards.c BALATON Zoltan
2022-08-16  7:46   ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 19/22] hw/ppc/Kconfig: Remove PPC405 dependency from sam460ex BALATON Zoltan
2022-08-16  7:39   ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 20/22] hw/ppc/Kconfig: Move imply before select BALATON Zoltan
2022-08-16  7:39   ` Cédric Le Goater
2022-08-13 15:34 ` [PATCH 21/22] ppc4xx: Drop empty default cases BALATON Zoltan
2022-08-16 11:18   ` Cédric Le Goater
2022-08-16 11:59     ` BALATON Zoltan
2022-08-13 15:34 ` [PATCH 22/22] ppc/ppc4xx: Fix sdram trace events BALATON Zoltan
2022-08-16 11:19 ` [PATCH 00/22] QOMify PPC4xx devices and minor clean ups Cédric Le Goater
2022-08-17 15:13   ` BALATON Zoltan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=945147317f98dd64e0dfa7a91a9786f3c111e903.1660402839.git.balaton@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.