qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, patches@linaro.org
Subject: [Qemu-devel] [PATCH v2 05/18] omap_gpmc: Clean up omap_gpmc_attach MemoryRegion conversion
Date: Sun, 28 Aug 2011 17:56:55 +0100	[thread overview]
Message-ID: <1314550628-26869-7-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1314550628-26869-1-git-send-email-peter.maydell@linaro.org>

Now that all callers of omap_gpmc_attach pass in a MemoryRegion*,
we can remove the base_update and unmap function pointer arguments,
and the opaque pointer that was passed into these callbacks.

We can also remove the base and size fields from omap_gpmc_cs_file_s
as these are no longer necessary (you don't need the base/size
to unmap a MemoryRegion the way you did to undo a mapping made
with cpu_register_physical_memory()).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/nseries.c   |   10 ++------
 hw/omap.h      |    4 +--
 hw/omap_gpmc.c |   59 ++++++++++++++++++++-----------------------------------
 3 files changed, 26 insertions(+), 47 deletions(-)

diff --git a/hw/nseries.c b/hw/nseries.c
index 7e1ad34..f7ace99 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -182,9 +182,7 @@ static void n8x0_nand_setup(struct n800_s *s)
     sysbus_connect_irq(sysbus_from_qdev(s->nand), 0,
                        qdev_get_gpio_in(s->cpu->gpio, N8X0_ONENAND_GPIO));
     omap_gpmc_attach(s->cpu->gpmc, N8X0_ONENAND_CS,
-                     sysbus_mmio_get_region(sysbus_from_qdev(s->nand), 0),
-                     NULL, NULL,
-                     s->nand);
+                     sysbus_mmio_get_region(sysbus_from_qdev(s->nand), 0));
     otp_region = onenand_raw_otp(s->nand);
 
     memcpy(otp_region + 0x000, n8x0_cal_wlan_mac, sizeof(n8x0_cal_wlan_mac));
@@ -781,10 +779,8 @@ static void n8x0_usb_setup(struct n800_s *s)
     TUSBState *tusb = tusb6010_init(tusb_irq);
 
     /* Using the NOR interface */
-    omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_ASYNC_CS,
-                    tusb6010_async_io(tusb), NULL, NULL, tusb);
-    omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_SYNC_CS,
-                    tusb6010_sync_io(tusb), NULL, NULL, tusb);
+    omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_ASYNC_CS, tusb6010_async_io(tusb));
+    omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_SYNC_CS, tusb6010_sync_io(tusb));
 
     s->usb = tusb;
     qdev_connect_gpio_out(s->cpu->gpio, N8X0_TUSB_ENABLE_GPIO, tusb_pwr);
diff --git a/hw/omap.h b/hw/omap.h
index db101c6..47c8629 100644
--- a/hw/omap.h
+++ b/hw/omap.h
@@ -120,9 +120,7 @@ void omap_sdrc_reset(struct omap_sdrc_s *s);
 struct omap_gpmc_s;
 struct omap_gpmc_s *omap_gpmc_init(target_phys_addr_t base, qemu_irq irq);
 void omap_gpmc_reset(struct omap_gpmc_s *s);
-void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem,
-                void (*base_upd)(void *opaque, target_phys_addr_t new),
-                void (*unmap)(void *opaque), void *opaque);
+void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem);
 
 /*
  * Common IRQ numbers for level 1 interrupt handler
diff --git a/hw/omap_gpmc.c b/hw/omap_gpmc.c
index 673dddd..19f246c 100644
--- a/hw/omap_gpmc.c
+++ b/hw/omap_gpmc.c
@@ -40,13 +40,8 @@ struct omap_gpmc_s {
     int prefcount;
     struct omap_gpmc_cs_file_s {
         uint32_t config[7];
-        target_phys_addr_t base;
-        size_t size;
         MemoryRegion *iomem;
         MemoryRegion container;
-        void (*base_update)(void *opaque, target_phys_addr_t new);
-        void (*unmap)(void *opaque);
-        void *opaque;
     } cs_file[8];
     int ecc_cs;
     int ecc_ptr;
@@ -61,6 +56,12 @@ static void omap_gpmc_int_update(struct omap_gpmc_s *s)
 
 static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask)
 {
+    uint32_t size;
+
+    if (!f->iomem) {
+        return;
+    }
+
     /* TODO: check for overlapping regions and report access errors */
     if ((mask != 0x8 && mask != 0xc && mask != 0xe && mask != 0xf) ||
                     (base < 0 || base >= 0x40) ||
@@ -70,39 +71,27 @@ static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask)
         return;
     }
 
-    if (!f->opaque)
-        return;
-
-    f->base = base << 24;
-    f->size = (0x0fffffff & ~(mask << 24)) + 1;
+    base <<= 24;
+    size = (0x0fffffff & ~(mask << 24)) + 1;
     /* TODO: rather than setting the size of the mapping (which should be
      * constant), the mask should cause wrapping of the address space, so
      * that the same memory becomes accessible at every <i>size</i> bytes
      * starting from <i>base</i>.  */
-    if (f->iomem) {
-        memory_region_init(&f->container, "omap-gpmc-file", f->size);
-        memory_region_add_subregion(&f->container, 0, f->iomem);
-        memory_region_add_subregion(get_system_memory(), f->base,
-                                    &f->container);
-    }
-
-    if (f->base_update)
-        f->base_update(f->opaque, f->base);
+    memory_region_init(&f->container, "omap-gpmc-file", size);
+    memory_region_add_subregion(&f->container, 0, f->iomem);
+    memory_region_add_subregion(get_system_memory(), base,
+                                &f->container);
 }
 
 static void omap_gpmc_cs_unmap(struct omap_gpmc_cs_file_s *f)
 {
-    if (f->size) {
-        if (f->unmap)
-            f->unmap(f->opaque);
-        if (f->iomem) {
-            memory_region_del_subregion(get_system_memory(), &f->container);
-            memory_region_del_subregion(&f->container, f->iomem);
-            memory_region_destroy(&f->container);
-        }
-        f->base = 0;
-        f->size = 0;
+    if (!f->iomem) {
+        return;
     }
+
+    memory_region_del_subregion(get_system_memory(), &f->container);
+    memory_region_del_subregion(&f->container, f->iomem);
+    memory_region_destroy(&f->container);
 }
 
 void omap_gpmc_reset(struct omap_gpmc_s *s)
@@ -399,19 +388,18 @@ struct omap_gpmc_s *omap_gpmc_init(target_phys_addr_t base, qemu_irq irq)
     struct omap_gpmc_s *s = (struct omap_gpmc_s *)
             g_malloc0(sizeof(struct omap_gpmc_s));
 
-    omap_gpmc_reset(s);
-
     memory_region_init_io(&s->iomem, &omap_gpmc_ops, s, "omap-gpmc", 0x1000);
     memory_region_add_subregion(get_system_memory(), base, &s->iomem);
 
+    omap_gpmc_reset(s);
+
     return s;
 }
 
-void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem,
-                void (*base_upd)(void *opaque, target_phys_addr_t new),
-                void (*unmap)(void *opaque), void *opaque)
+void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem)
 {
     struct omap_gpmc_cs_file_s *f;
+    assert(iomem);
 
     if (cs < 0 || cs >= 8) {
         fprintf(stderr, "%s: bad chip-select %i\n", __FUNCTION__, cs);
@@ -420,9 +408,6 @@ void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem,
     f = &s->cs_file[cs];
 
     f->iomem = iomem;
-    f->base_update = base_upd;
-    f->unmap = unmap;
-    f->opaque = opaque;
 
     if (f->config[6] & (1 << 6))				/* CSVALID */
         omap_gpmc_cs_map(f, f->config[6] & 0x1f,		/* MASKADDR */
-- 
1.7.1

  parent reply	other threads:[~2011-08-28 16:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-28 16:56 [Qemu-devel] [PATCH v2 00/18] onenand, omap_gpmc fixes, features Peter Maydell
2011-08-28 16:56 ` Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 01/18] hw/sysbus: Add sysbus_mmio_get_region() Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 02/18] hw/onenand: Remove unnecessary argument from onenand_command() Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 03/18] hw/onenand: Qdevify Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 04/18] hw/onenand: Minor spacing fixes Peter Maydell
2011-08-28 16:56 ` Peter Maydell [this message]
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 06/18] omap_gpmc: Refactor omap_gpmc_cs_map and omap_gpmc_cs_unmap Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 07/18] omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear Peter Maydell
2011-09-17  1:08   ` andrzej zaborowski
2011-09-17 15:47     ` Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 08/18] omap_gpmc: Wire up the GPMC IRQ correctly Peter Maydell
2011-08-28 16:56 ` [Qemu-devel] [PATCH v2 09/18] omap_gpmc: Fix handling of FIFOTHRESHOLDSTATUS bit Peter Maydell
2011-09-17  1:22   ` andrzej zaborowski
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 10/18] omap_gpmc: Take omap_mpu_state* in omap_gpmc_init Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 11/18] omap_gpmc: Calculate revision from OMAP model Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 12/18] omap_gpmc: Reindent misindented switch statements Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 13/18] omap_gpmc: Support NAND devices Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 14/18] hw/omap.h: Add OMAP 3630 to omap_mpu_model enumeration Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 15/18] omap_gpmc: Accept a zero mask field on omap3630 Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 16/18] omap_gpmc: Pull prefetch engine data into sub-struct Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 17/18] omap: Wire up the DMA request line to the GPMC Peter Maydell
2011-08-28 16:57 ` [Qemu-devel] [PATCH v2 18/18] omap_gpmc: Implement prefetch engine Peter Maydell
2011-08-30  6:27 ` [Qemu-devel] [PATCH v2 00/18] onenand, omap_gpmc fixes, features Edgar E. Iglesias

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=1314550628-26869-7-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=patches@linaro.org \
    --cc=qemu-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).