Commit 9542611a66227ceca062eec86d49e17aa79cbf90

Authored by ths
1 parent c5be9f08

DS1225Y nvram device, by Herve Poussineau.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2460 c046a42c-6fe2-441c-8c8c-71466251a162
Makefile.target
... ... @@ -383,7 +383,7 @@ CPPFLAGS += -DHAS_AUDIO
383 383 endif
384 384 ifeq ($(TARGET_ARCH), mips)
385 385 VL_OBJS+= mips_r4k.o mips_malta.o mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o
386   -VL_OBJS+= ide.o gt64xxx.o pckbd.o ps2.o fdc.o mc146818rtc.o usb-uhci.o acpi.o
  386 +VL_OBJS+= ide.o gt64xxx.o pckbd.o ps2.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
387 387 VL_OBJS+= piix_pci.o parallel.o mixeng.o cirrus_vga.o $(SOUND_HW) $(AUDIODRV)
388 388 DEFINES += -DHAS_AUDIO
389 389 endif
... ...
hw/ds1225y.c 0 → 100644
  1 +/*
  2 + * QEMU NVRAM emulation for DS1225Y chip
  3 + *
  4 + * Copyright (c) 2007 Hervé Poussineau
  5 + *
  6 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  7 + * of this software and associated documentation files (the "Software"), to deal
  8 + * in the Software without restriction, including without limitation the rights
  9 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10 + * copies of the Software, and to permit persons to whom the Software is
  11 + * furnished to do so, subject to the following conditions:
  12 + *
  13 + * The above copyright notice and this permission notice shall be included in
  14 + * all copies or substantial portions of the Software.
  15 + *
  16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22 + * THE SOFTWARE.
  23 + */
  24 +
  25 +#include "vl.h"
  26 +
  27 +typedef enum
  28 +{
  29 + none = 0,
  30 + readmode,
  31 + writemode,
  32 +} nvram_open_mode;
  33 +
  34 +struct ds1225y_t
  35 +{
  36 + target_ulong mem_base;
  37 + uint32_t capacity;
  38 + const char *filename;
  39 + QEMUFile *file;
  40 + nvram_open_mode open_mode;
  41 +};
  42 +
  43 +static int ds1225y_set_to_mode(ds1225y_t *NVRAM, nvram_open_mode mode, const char *filemode)
  44 +{
  45 + if (NVRAM->open_mode != mode)
  46 + {
  47 + if (NVRAM->file)
  48 + qemu_fclose(NVRAM->file);
  49 + NVRAM->file = qemu_fopen(NVRAM->filename, filemode);
  50 + NVRAM->open_mode = mode;
  51 + }
  52 + return (NVRAM->file != NULL);
  53 +}
  54 +
  55 +static uint32_t nvram_readb (void *opaque, target_phys_addr_t addr)
  56 +{
  57 + ds1225y_t *NVRAM = opaque;
  58 + int64_t pos;
  59 +
  60 + pos = addr - NVRAM->mem_base;
  61 + if (addr >= NVRAM->capacity)
  62 + addr -= NVRAM->capacity;
  63 +
  64 + if (!ds1225y_set_to_mode(NVRAM, readmode, "rb"))
  65 + return 0;
  66 + qemu_fseek(NVRAM->file, pos, SEEK_SET);
  67 + return (uint32_t)qemu_get_byte(NVRAM->file);
  68 +}
  69 +
  70 +static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
  71 +{
  72 + ds1225y_t *NVRAM = opaque;
  73 + int64_t pos;
  74 +
  75 + pos = addr - NVRAM->mem_base;
  76 + if (ds1225y_set_to_mode(NVRAM, writemode, "wb"))
  77 + {
  78 + qemu_fseek(NVRAM->file, pos, SEEK_SET);
  79 + qemu_put_byte(NVRAM->file, (int)value);
  80 + }
  81 +}
  82 +
  83 +static CPUReadMemoryFunc *nvram_read[] = {
  84 + &nvram_readb,
  85 + NULL,
  86 + NULL,
  87 +};
  88 +
  89 +static CPUWriteMemoryFunc *nvram_write[] = {
  90 + &nvram_writeb,
  91 + NULL,
  92 + NULL,
  93 +};
  94 +
  95 +static CPUWriteMemoryFunc *nvram_none[] = {
  96 + NULL,
  97 + NULL,
  98 + NULL,
  99 +};
  100 +
  101 +/* Initialisation routine */
  102 +ds1225y_t *ds1225y_init(target_ulong mem_base, const char *filename)
  103 +{
  104 + ds1225y_t *s;
  105 + int mem_index1, mem_index2;
  106 +
  107 + s = qemu_mallocz(sizeof(ds1225y_t));
  108 + if (!s)
  109 + return NULL;
  110 + s->mem_base = mem_base;
  111 + s->capacity = 0x2000; /* Fixed for ds1225y chip: 8K */
  112 + s->filename = filename;
  113 +
  114 + /* Read/write memory */
  115 + mem_index1 = cpu_register_io_memory(0, nvram_read, nvram_write, s);
  116 + cpu_register_physical_memory(mem_base, s->capacity, mem_index1);
  117 + /* Read-only memory */
  118 + mem_index2 = cpu_register_io_memory(0, nvram_read, nvram_none, s);
  119 + cpu_register_physical_memory(mem_base + s->capacity, s->capacity, mem_index2);
  120 + return s;
  121 +}
... ...
hw/mips_r4k.c
... ... @@ -215,6 +215,7 @@ void mips_r4k_init (int ram_size, int vga_ram_size, int boot_device,
215 215 bs_table[2 * i], bs_table[2 * i + 1]);
216 216  
217 217 kbd_init();
  218 + ds1225y_init(0x9000, "nvram");
218 219 }
219 220  
220 221 QEMUMachine mips_machine = {
... ...
... ... @@ -941,6 +941,10 @@ int pmac_ide_init (BlockDriverState **hd_table,
941 941 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
942 942 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
943 943  
  944 +/* ds1225y.c */
  945 +typedef struct ds1225y_t ds1225y_t;
  946 +ds1225y_t *ds1225y_init(target_ulong mem_base, const char *filename);
  947 +
944 948 /* es1370.c */
945 949 int es1370_init (PCIBus *bus, AudioState *s);
946 950  
... ...