From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Hervé Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH 18/20] [MIPS] qdev: convert ds1225y nvram to sysbus device
Date: Sun, 1 Aug 2010 19:37:20 +0200 [thread overview]
Message-ID: <1280684242-19611-18-git-send-email-hpoussin@reactos.org> (raw)
In-Reply-To: <4C5579DA.8050508@reactos.org>
Use it in Jazz emulation
Remove protection stuff, which doesn't belong to this device
Remove ds1225y_init() and ds1225y_set_protection() functions, which are not used anymore
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
hw/ds1225y.c | 137 ++++++++++++++++++++++++++++++--------------------------
hw/mips.h | 4 --
hw/mips_jazz.c | 5 +-
3 files changed, 76 insertions(+), 70 deletions(-)
diff --git a/hw/ds1225y.c b/hw/ds1225y.c
index 009d127..afbfcb0 100644
--- a/hw/ds1225y.c
+++ b/hw/ds1225y.c
@@ -25,15 +25,20 @@
#include "hw.h"
#include "mips.h"
#include "nvram.h"
+#include "sysbus.h"
+#include "qdev-addr.h"
//#define DEBUG_NVRAM
typedef struct ds1225y_t
{
- uint32_t chip_size;
+ SysBusDevice busdev;
+
+ target_phys_addr_t iobase;
+ uint32_t size;
+ char *filename;
QEMUFile *file;
uint8_t *contents;
- uint8_t protection;
} ds1225y_t;
@@ -98,34 +103,6 @@ static void nvram_writel (void *opaque, target_phys_addr_t addr, uint32_t val)
nvram_writeb(opaque, addr + 3, (val >> 24) & 0xff);
}
-static void nvram_writeb_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
-{
- ds1225y_t *s = opaque;
-
- if (s->protection != 7) {
-#ifdef DEBUG_NVRAM
- printf("nvram: prevent write of 0x%x at " TARGET_FMT_lx "\n", val, addr);
-#endif
- return;
- }
-
- nvram_writeb(opaque, addr, val);
-}
-
-static void nvram_writew_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
-{
- nvram_writeb_protected(opaque, addr, val & 0xff);
- nvram_writeb_protected(opaque, addr + 1, (val >> 8) & 0xff);
-}
-
-static void nvram_writel_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
-{
- nvram_writeb_protected(opaque, addr, val & 0xff);
- nvram_writeb_protected(opaque, addr + 1, (val >> 8) & 0xff);
- nvram_writeb_protected(opaque, addr + 2, (val >> 16) & 0xff);
- nvram_writeb_protected(opaque, addr + 3, (val >> 24) & 0xff);
-}
-
static CPUReadMemoryFunc * const nvram_read[] = {
&nvram_readb,
&nvram_readw,
@@ -138,43 +115,75 @@ static CPUWriteMemoryFunc * const nvram_write[] = {
&nvram_writel,
};
-static CPUWriteMemoryFunc * const nvram_write_protected[] = {
- &nvram_writeb_protected,
- &nvram_writew_protected,
- &nvram_writel_protected,
-};
-
-/* Initialisation routine */
-void *ds1225y_init(target_phys_addr_t mem_base, const char *filename)
+static int ds1225y_init(SysBusDevice *dev)
{
- ds1225y_t *s;
- int mem_indexRW, mem_indexRP;
+ ds1225y_t *s = FROM_SYSBUS(ds1225y_t, dev);
+ int mem_index;
QEMUFile *file;
- s = qemu_mallocz(sizeof(ds1225y_t));
- s->chip_size = 0x2000; /* Fixed for ds1225y chip: 8 KiB */
- s->contents = qemu_mallocz(s->chip_size);
- s->protection = 7;
-
- /* Read current file */
- file = qemu_fopen(filename, "rb");
- if (file) {
- /* Read nvram contents */
- qemu_get_buffer(file, s->contents, s->chip_size);
- qemu_fclose(file);
- }
- s->file = qemu_fopen(filename, "wb");
- if (s->file) {
- /* Write back contents, as 'wb' mode cleaned the file */
- qemu_put_buffer(s->file, s->contents, s->chip_size);
- qemu_fflush(s->file);
+ if (s->iobase == -1)
+ return -1;
+
+ s->contents = qemu_mallocz(s->size);
+
+ if (s->filename) {
+ /* Read current file */
+ file = qemu_fopen(s->filename, "rb");
+ if (file) {
+ /* Read nvram contents */
+ qemu_get_buffer(file, s->contents, s->size);
+ qemu_fclose(file);
+ }
+ s->file = qemu_fopen(s->filename, "wb");
+ if (s->file) {
+ /* Write back contents, as 'wb' mode cleaned the file */
+ qemu_put_buffer(s->file, s->contents, s->size);
+ qemu_fflush(s->file);
+ }
}
- /* Read/write memory */
- mem_indexRW = cpu_register_io_memory(nvram_read, nvram_write, s);
- cpu_register_physical_memory(mem_base, s->chip_size, mem_indexRW);
- /* Read/write protected memory */
- mem_indexRP = cpu_register_io_memory(nvram_read, nvram_write_protected, s);
- cpu_register_physical_memory(mem_base + s->chip_size, s->chip_size, mem_indexRP);
- return s;
+ mem_index = cpu_register_io_memory(nvram_read, nvram_write, s);
+ cpu_register_physical_memory(s->iobase, s->size, mem_index);
+
+ return 0;
+}
+
+static int ds1225y_init_nvram(SysBusDevice *dev)
+{
+ ds1225y_t *s = FROM_SYSBUS(ds1225y_t, dev);
+ s->filename = (char*)"nvram";
+ return ds1225y_init(dev);
+}
+
+static SysBusDeviceInfo ds1225y_device_info = {
+ .qdev.name = "ds1225y",
+ .qdev.size = sizeof(ds1225y_t),
+ .init = ds1225y_init,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_TADDR("iobase", ds1225y_t, iobase, -1),
+ DEFINE_PROP_HEX32("size", ds1225y_t, size, 0x2000),
+ DEFINE_PROP_STRING("filename", ds1225y_t, filename),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static SysBusDeviceInfo ds1225y_device_info_nvram = {
+ .qdev.name = "ds1225y,filename=nvram",
+ .qdev.size = sizeof(ds1225y_t),
+ .qdev.no_user = 1,
+ .init = ds1225y_init_nvram,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_TADDR("iobase", ds1225y_t, iobase, 0x80009000),
+ DEFINE_PROP_HEX32("size", ds1225y_t, size, 0x2000),
+ DEFINE_PROP_STRING("filename", ds1225y_t, filename),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static void ds1225y_register_devices(void)
+{
+ sysbus_register_withprop(&ds1225y_device_info);
+ sysbus_register_withprop(&ds1225y_device_info_nvram);
}
+
+device_init(ds1225y_register_devices)
diff --git a/hw/mips.h b/hw/mips.h
index d8e4954..5d59b1e 100644
--- a/hw/mips.h
+++ b/hw/mips.h
@@ -8,10 +8,6 @@ PCIBus *pci_gt64120_init(qemu_irq *pic);
/* bonito.c */
PCIBus *bonito_init(qemu_irq *pic);
-/* ds1225y.c */
-void *ds1225y_init(target_phys_addr_t mem_base, const char *filename);
-void ds1225y_set_protection(void *opaque, int protection);
-
/* mipsnet.c */
void mipsnet_init(int base, qemu_irq irq, NICInfo *nd);
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 08175ab..6daf76e 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -247,8 +247,9 @@ void mips_jazz_init (ram_addr_t ram_size,
/* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
audio_init(i8259);
- /* NVRAM: Unprotected at 0x9000, Protected at 0xa000, Read only at 0xb000 */
- ds1225y_init(0x80009000, "nvram");
+ /* NVRAM */
+ dev = qdev_create(NULL, "ds1225y,filename=nvram");
+ qdev_init_nofail(dev);
/* LED indicator */
dev = qdev_create(NULL, "jazz-led");
--
1.7.1.GIT
next prev parent reply other threads:[~2010-08-01 18:11 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-01 13:42 [Qemu-devel] [PATCH 00/20] MIPS Magnum conversion to qdev Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 01/20] [MIPS] cpu: add a init inplace method Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 02/20] [MIPS] cpu: convert to qdev Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 03/20] [MIPS] Jazz emulation: create a qdev cpu Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 04/20] [MIPS] rc4030: convert to qdev Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 05/20] Add a stub for some rc4030 functions, if rc4030 support is not compiled in Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 06/20] [MIPS] qdev: convert i8042 to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 07/20] [MIPS] qdev: convert parallel port " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 08/20] [MIPS] qdev: convert serial " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 09/20] [MIPS] qdev: convert jazz-led to sysbus device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 10/20] [MIPS] Jazz emulation: make video card optional Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 11/20] [MIPS] qdev: convert vga-isa-mm to ISA device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 12/20] [MIPS] qdev: convert g364fb to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 13/20] [MIPS] qdev: add a rtc forwarder device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 14/20] [MIPS] qdev: add an isa bus device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 15/20] [MIPS] qdev: convert dp83932 network card to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 16/20] [MIPS] qdev: convert floppy disk controller " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 17/20] [MIPS] qdev: convert esp scsi adapter " Hervé Poussineau
2010-08-02 14:51 ` Artyom Tarasenko
2010-08-01 17:37 ` Hervé Poussineau [this message]
2010-08-01 17:37 ` [Qemu-devel] [PATCH 19/20] [MIPS] qdev: add a mips board device, which initializes the ram and the rom Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 20/20] [MIPS] qdev: Complete rc4030 conversion, by removing legacy stuff Hervé Poussineau
2010-08-02 16:06 ` [Qemu-devel] [PATCH 00/20] MIPS Magnum conversion to qdev Blue Swirl
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=1280684242-19611-18-git-send-email-hpoussin@reactos.org \
--to=hpoussin@reactos.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 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.