|
| 1 | +/* |
| 2 | + * QEMU Chihiro emulation |
| 3 | + * |
| 4 | + * Copyright (c) 2013 espes |
| 5 | + * Copyright (c) 2018-2021 Matt Borgerson |
| 6 | + * |
| 7 | + * This library is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU Lesser General Public |
| 9 | + * License as published by the Free Software Foundation; either |
| 10 | + * version 2 of the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This library is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public |
| 18 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +#include "qemu/osdep.h" |
| 22 | +#include "hw/qdev-properties.h" |
| 23 | +#include "hw/qdev-properties-system.h" |
| 24 | +#include "migration/vmstate.h" |
| 25 | +#include "sysemu/sysemu.h" |
| 26 | +#include "hw/char/serial.h" |
| 27 | +#include "hw/isa/isa.h" |
| 28 | +#include "qapi/error.h" |
| 29 | + |
| 30 | +#define SEGA_CHIP_REVISION 0xF0 |
| 31 | +# define SEGA_CHIP_REVISION_CHIP_ID 0xFF00 |
| 32 | +# define SEGA_CHIP_REVISION_FPGA_CHIP_ID 0x0000 |
| 33 | +# define SEGA_CHIP_REVISION_ASIC_CHIP_ID 0x0100 |
| 34 | +# define SEGA_CHIP_REVISION_REVISION_ID_MASK 0x00FF |
| 35 | +#define SEGA_DIMM_SIZE 0xF4 |
| 36 | +# define SEGA_DIMM_SIZE_128M 0 |
| 37 | +# define SEGA_DIMM_SIZE_256M 1 |
| 38 | +# define SEGA_DIMM_SIZE_512M 2 |
| 39 | +# define SEGA_DIMM_SIZE_1024M 3 |
| 40 | + |
| 41 | +#define TYPE_ISA_LPCSEGA_DEVICE "lpcsega" |
| 42 | +#define ISA_LPCSEGA_DEVICE(obj) \ |
| 43 | + OBJECT_CHECK(ISALPCSEGAState, (obj), TYPE_ISA_LPCSEGA_DEVICE) |
| 44 | + |
| 45 | +// #define DEBUG |
| 46 | +#ifdef DEBUG |
| 47 | +# define DPRINTF(format, ...) printf(format, ## __VA_ARGS__) |
| 48 | +#else |
| 49 | +# define DPRINTF(format, ...) do { } while (0) |
| 50 | +#endif |
| 51 | + |
| 52 | +typedef struct LPCSEGAState { |
| 53 | + MemoryRegion io; |
| 54 | +} LPCSEGAState; |
| 55 | + |
| 56 | +typedef struct ISALPCSEGAState { |
| 57 | + ISADevice parent_obj; |
| 58 | + |
| 59 | + bool sysopt; |
| 60 | + uint16_t iobase; |
| 61 | + LPCSEGAState state; |
| 62 | +} ISALPCSEGAState; |
| 63 | + |
| 64 | +static void lpcsega_io_write(void *opaque, hwaddr addr, uint64_t val, |
| 65 | + unsigned int size) |
| 66 | +{ |
| 67 | + DPRINTF("lpcsega io write 0x%02" HWADDR_PRIx " = 0x%02" PRIx64 "\n", addr, val); |
| 68 | +} |
| 69 | + |
| 70 | +static uint64_t lpcsega_io_read(void *opaque, hwaddr addr, unsigned int size) |
| 71 | +{ |
| 72 | + uint32_t val = 0; |
| 73 | + |
| 74 | + switch (addr) { |
| 75 | + case SEGA_CHIP_REVISION: |
| 76 | + val = SEGA_CHIP_REVISION_ASIC_CHIP_ID; |
| 77 | + break; |
| 78 | + case SEGA_DIMM_SIZE: |
| 79 | + val = SEGA_DIMM_SIZE_128M; |
| 80 | + break; |
| 81 | + } |
| 82 | + |
| 83 | + DPRINTF("lpcsega io read 0x%02" HWADDR_PRIx " -> 0x%02x\n", addr, val); |
| 84 | + |
| 85 | + return val; |
| 86 | +} |
| 87 | + |
| 88 | +static const MemoryRegionOps lpcsega_io_ops = { |
| 89 | + .read = lpcsega_io_read, |
| 90 | + .write = lpcsega_io_write, |
| 91 | + .valid = { |
| 92 | + .min_access_size = 2, |
| 93 | + .max_access_size = 2, |
| 94 | + }, |
| 95 | +}; |
| 96 | + |
| 97 | +static void lpcsega_realize(DeviceState *dev, Error **errp) |
| 98 | +{ |
| 99 | + ISADevice *isadev = ISA_DEVICE(dev); |
| 100 | + ISALPCSEGAState *isa = ISA_LPCSEGA_DEVICE(isadev); |
| 101 | + LPCSEGAState *s = &isa->state; |
| 102 | + |
| 103 | + memory_region_init_io(&s->io, OBJECT(dev), &lpcsega_io_ops, s, |
| 104 | + "lpcsega-io", 0x100); |
| 105 | + isa_register_ioport(isadev, &s->io, 0x4000); |
| 106 | +} |
| 107 | + |
| 108 | +static Property lpcsega_properties[] = { |
| 109 | + DEFINE_PROP_BOOL("sysopt", ISALPCSEGAState, sysopt, false), |
| 110 | + DEFINE_PROP_END_OF_LIST(), |
| 111 | +}; |
| 112 | + |
| 113 | +static void lpcsega_class_init(ObjectClass *klass, void *data) |
| 114 | +{ |
| 115 | + DeviceClass *dc = DEVICE_CLASS(klass); |
| 116 | + |
| 117 | + dc->realize = lpcsega_realize; |
| 118 | + device_class_set_props(dc, lpcsega_properties); |
| 119 | +} |
| 120 | + |
| 121 | +static void lpcsega_initfn(Object *o) |
| 122 | +{ |
| 123 | +} |
| 124 | + |
| 125 | +static const TypeInfo lpcsega_type_info = { |
| 126 | + .name = TYPE_ISA_LPCSEGA_DEVICE, |
| 127 | + .parent = TYPE_ISA_DEVICE, |
| 128 | + .instance_init = lpcsega_initfn, |
| 129 | + .instance_size = sizeof(ISALPCSEGAState), |
| 130 | + .class_init = lpcsega_class_init, |
| 131 | +}; |
| 132 | + |
| 133 | +static void lpcsega_register_types(void) |
| 134 | +{ |
| 135 | + type_register_static(&lpcsega_type_info); |
| 136 | +} |
| 137 | + |
| 138 | +type_init(lpcsega_register_types) |
0 commit comments