]> git.proxmox.com Git - qemu.git/blobdiff - hw/pxa2xx_mmci.c
cpu: Move halted and interrupt_request fields to CPUState
[qemu.git] / hw / pxa2xx_mmci.c
index 2081b54db83c12a4b8ade9a80e658c521f530a08..0df83cc1df8ad3f4e5a0f358f66be168526dec38 100644 (file)
@@ -5,15 +5,21 @@
  * Written by Andrzej Zaborowski <balrog@zabor.org>
  *
  * This code is licensed under the GPLv2.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
  */
 
-#include "vl.h"
-#include "sd.h"
+#include "hw/hw.h"
+#include "hw/pxa.h"
+#include "hw/sd.h"
+#include "hw/qdev.h"
 
-struct pxa2xx_mmci_s {
-    target_phys_addr_t base;
+struct PXA2xxMMCIState {
+    MemoryRegion iomem;
     qemu_irq irq;
-    void *dma;
+    qemu_irq rx_dma;
+    qemu_irq tx_dma;
 
     SDState *card;
 
@@ -96,22 +102,20 @@ struct pxa2xx_mmci_s {
 #define PRTBUF_PRT_BUF (1 << 0)
 
 /* Route internal interrupt lines to the global IC and DMA */
-static void pxa2xx_mmci_int_update(struct pxa2xx_mmci_s *s)
+static void pxa2xx_mmci_int_update(PXA2xxMMCIState *s)
 {
     uint32_t mask = s->intmask;
     if (s->cmdat & CMDAT_DMA_EN) {
         mask |= INT_RXFIFO_REQ | INT_TXFIFO_REQ;
 
-        pxa2xx_dma_request((struct pxa2xx_dma_state_s *) s->dma,
-                        PXA2XX_RX_RQ_MMCI, !!(s->intreq & INT_RXFIFO_REQ));
-        pxa2xx_dma_request((struct pxa2xx_dma_state_s *) s->dma,
-                        PXA2XX_TX_RQ_MMCI, !!(s->intreq & INT_TXFIFO_REQ));
+        qemu_set_irq(s->rx_dma, !!(s->intreq & INT_RXFIFO_REQ));
+        qemu_set_irq(s->tx_dma, !!(s->intreq & INT_TXFIFO_REQ));
     }
 
     qemu_set_irq(s->irq, !!(s->intreq & ~mask));
 }
 
-static void pxa2xx_mmci_fifo_update(struct pxa2xx_mmci_s *s)
+static void pxa2xx_mmci_fifo_update(PXA2xxMMCIState *s)
 {
     if (!s->active)
         return;
@@ -147,10 +151,10 @@ static void pxa2xx_mmci_fifo_update(struct pxa2xx_mmci_s *s)
     pxa2xx_mmci_int_update(s);
 }
 
-static void pxa2xx_mmci_wakequeues(struct pxa2xx_mmci_s *s)
+static void pxa2xx_mmci_wakequeues(PXA2xxMMCIState *s)
 {
     int rsplen, i;
-    struct sd_request_s request;
+    SDRequest request;
     uint8_t response[16];
 
     s->active = 1;
@@ -211,11 +215,10 @@ static void pxa2xx_mmci_wakequeues(struct pxa2xx_mmci_s *s)
     pxa2xx_mmci_fifo_update(s);
 }
 
-static uint32_t pxa2xx_mmci_read(void *opaque, target_phys_addr_t offset)
+static uint32_t pxa2xx_mmci_read(void *opaque, hwaddr offset)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     uint32_t ret;
-    offset -= s->base;
 
     switch (offset) {
     case MMC_STRPCL:
@@ -267,18 +270,16 @@ static uint32_t pxa2xx_mmci_read(void *opaque, target_phys_addr_t offset)
     case MMC_BLKS_REM:
         return s->numblk;
     default:
-        cpu_abort(cpu_single_env, "%s: Bad offset " REG_FMT "\n",
-                        __FUNCTION__, offset);
+        hw_error("%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
     }
 
     return 0;
 }
 
 static void pxa2xx_mmci_write(void *opaque,
-                target_phys_addr_t offset, uint32_t value)
+                hwaddr offset, uint32_t value)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
-    offset -= s->base;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
 
     switch (offset) {
     case MMC_STRPCL:
@@ -381,71 +382,70 @@ static void pxa2xx_mmci_write(void *opaque,
         break;
 
     default:
-        cpu_abort(cpu_single_env, "%s: Bad offset " REG_FMT "\n",
-                        __FUNCTION__, offset);
+        hw_error("%s: Bad offset " REG_FMT "\n", __FUNCTION__, offset);
     }
 }
 
-static uint32_t pxa2xx_mmci_readb(void *opaque, target_phys_addr_t offset)
+static uint32_t pxa2xx_mmci_readb(void *opaque, hwaddr offset)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 1;
     return pxa2xx_mmci_read(opaque, offset);
 }
 
-static uint32_t pxa2xx_mmci_readh(void *opaque, target_phys_addr_t offset)
+static uint32_t pxa2xx_mmci_readh(void *opaque, hwaddr offset)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 2;
     return pxa2xx_mmci_read(opaque, offset);
 }
 
-static uint32_t pxa2xx_mmci_readw(void *opaque, target_phys_addr_t offset)
+static uint32_t pxa2xx_mmci_readw(void *opaque, hwaddr offset)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 4;
     return pxa2xx_mmci_read(opaque, offset);
 }
 
-static CPUReadMemoryFunc *pxa2xx_mmci_readfn[] = {
-    pxa2xx_mmci_readb,
-    pxa2xx_mmci_readh,
-    pxa2xx_mmci_readw
-};
-
 static void pxa2xx_mmci_writeb(void *opaque,
-                target_phys_addr_t offset, uint32_t value)
+                hwaddr offset, uint32_t value)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 1;
     pxa2xx_mmci_write(opaque, offset, value);
 }
 
 static void pxa2xx_mmci_writeh(void *opaque,
-                target_phys_addr_t offset, uint32_t value)
+                hwaddr offset, uint32_t value)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 2;
     pxa2xx_mmci_write(opaque, offset, value);
 }
 
 static void pxa2xx_mmci_writew(void *opaque,
-                target_phys_addr_t offset, uint32_t value)
+                hwaddr offset, uint32_t value)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     s->ac_width = 4;
     pxa2xx_mmci_write(opaque, offset, value);
 }
 
-static CPUWriteMemoryFunc *pxa2xx_mmci_writefn[] = {
-    pxa2xx_mmci_writeb,
-    pxa2xx_mmci_writeh,
-    pxa2xx_mmci_writew
+static const MemoryRegionOps pxa2xx_mmci_ops = {
+    .old_mmio = {
+        .read = { pxa2xx_mmci_readb,
+                  pxa2xx_mmci_readh,
+                  pxa2xx_mmci_readw, },
+        .write = { pxa2xx_mmci_writeb,
+                   pxa2xx_mmci_writeh,
+                   pxa2xx_mmci_writew, },
+    },
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static void pxa2xx_mmci_save(QEMUFile *f, void *opaque)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     int i;
 
     qemu_put_be32s(f, &s->status);
@@ -479,7 +479,7 @@ static void pxa2xx_mmci_save(QEMUFile *f, void *opaque)
 
 static int pxa2xx_mmci_load(QEMUFile *f, void *opaque, int version_id)
 {
-    struct pxa2xx_mmci_s *s = (struct pxa2xx_mmci_s *) opaque;
+    PXA2xxMMCIState *s = (PXA2xxMMCIState *) opaque;
     int i;
 
     qemu_get_be32s(f, &s->status);
@@ -521,33 +521,33 @@ static int pxa2xx_mmci_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-struct pxa2xx_mmci_s *pxa2xx_mmci_init(target_phys_addr_t base,
-                qemu_irq irq, void *dma)
+PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
+                hwaddr base,
+                BlockDriverState *bd, qemu_irq irq,
+                qemu_irq rx_dma, qemu_irq tx_dma)
 {
-    int iomemtype;
-    struct pxa2xx_mmci_s *s;
+    PXA2xxMMCIState *s;
 
-    s = (struct pxa2xx_mmci_s *) qemu_mallocz(sizeof(struct pxa2xx_mmci_s));
-    s->base = base;
+    s = (PXA2xxMMCIState *) g_malloc0(sizeof(PXA2xxMMCIState));
     s->irq = irq;
-    s->dma = dma;
+    s->rx_dma = rx_dma;
+    s->tx_dma = tx_dma;
 
-    iomemtype = cpu_register_io_memory(0, pxa2xx_mmci_readfn,
-                    pxa2xx_mmci_writefn, s);
-    cpu_register_physical_memory(base, 0x000fffff, iomemtype);
+    memory_region_init_io(&s->iomem, &pxa2xx_mmci_ops, s,
+                          "pxa2xx-mmci", 0x00100000);
+    memory_region_add_subregion(sysmem, base, &s->iomem);
 
     /* Instantiate the actual storage */
-    s->card = sd_init(sd_bdrv);
+    s->card = sd_init(bd, 0);
 
-    register_savevm("pxa2xx_mmci", 0, 0,
+    register_savevm(NULL, "pxa2xx_mmci", 0, 0,
                     pxa2xx_mmci_save, pxa2xx_mmci_load, s);
 
     return s;
 }
 
-void pxa2xx_mmci_handlers(struct pxa2xx_mmci_s *s, void *opaque,
-                void (*readonly_cb)(void *, int),
-                void (*coverswitch_cb)(void *, int))
+void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
+                qemu_irq coverswitch)
 {
-    sd_set_cb(s->card, opaque, readonly_cb, coverswitch_cb);
+    sd_set_cb(s->card, readonly, coverswitch);
 }