2016-11-08 09:00:35 +03:00
|
|
|
/*
|
2019-10-04 02:03:54 +03:00
|
|
|
* QEMU M48T59 and M48T08 NVRAM emulation (ISA bus interface)
|
2016-11-08 09:00:35 +03:00
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005, 2007 Jocelyn Mayer
|
|
|
|
* Copyright (c) 2013 Hervé Poussineau
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2016-11-08 09:00:35 +03:00
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-10-04 02:03:54 +03:00
|
|
|
#include "hw/rtc/m48t59.h"
|
2016-11-08 09:00:35 +03:00
|
|
|
#include "m48t59-internal.h"
|
isa: Convert uses of isa_create() with Coccinelle
Replace
dev = isa_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = isa_new(type_name);
...
isa_realize_and_unref(dev, bus, &error_fatal);
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = isa_create(bus, args);
+ dev = isa_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ isa_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(isa_create(bus, args));
+ ISADevice *isa_dev; // TODO move
+ isa_dev = isa_new(args);
+ dev = DEVICE(isa_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ isa_realize_and_unref(isa_dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-20-armbru@redhat.com>
2020-06-10 08:32:08 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2016-11-08 09:00:35 +03:00
|
|
|
|
|
|
|
#define TYPE_M48TXX_ISA "isa-m48txx"
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct M48txxISADeviceClass M48txxISADeviceClass;
|
|
|
|
typedef struct M48txxISAState M48txxISAState;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_OBJ_CHECKERS(M48txxISAState, M48txxISADeviceClass,
|
|
|
|
M48TXX_ISA, TYPE_M48TXX_ISA)
|
2016-11-08 09:00:35 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct M48txxISAState {
|
2016-11-08 09:00:35 +03:00
|
|
|
ISADevice parent_obj;
|
|
|
|
M48t59State state;
|
|
|
|
uint32_t io_base;
|
2022-03-02 01:00:32 +03:00
|
|
|
uint8_t isairq;
|
2016-11-08 09:00:35 +03:00
|
|
|
MemoryRegion io;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2016-11-08 09:00:35 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct M48txxISADeviceClass {
|
2023-02-14 14:48:15 +03:00
|
|
|
DeviceClass parent_class;
|
2016-11-08 09:00:35 +03:00
|
|
|
M48txxInfo info;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2016-11-08 09:00:35 +03:00
|
|
|
|
|
|
|
static M48txxInfo m48txx_isa_info[] = {
|
|
|
|
{
|
|
|
|
.bus_name = "isa-m48t59",
|
|
|
|
.model = 59,
|
|
|
|
.size = 0x2000,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t m48txx_isa_read(Nvram *obj, uint32_t addr)
|
|
|
|
{
|
|
|
|
M48txxISAState *d = M48TXX_ISA(obj);
|
|
|
|
return m48t59_read(&d->state, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m48txx_isa_write(Nvram *obj, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
M48txxISAState *d = M48TXX_ISA(obj);
|
|
|
|
m48t59_write(&d->state, addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m48txx_isa_toggle_lock(Nvram *obj, int lock)
|
|
|
|
{
|
|
|
|
M48txxISAState *d = M48TXX_ISA(obj);
|
|
|
|
m48t59_toggle_lock(&d->state, lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property m48t59_isa_properties[] = {
|
|
|
|
DEFINE_PROP_INT32("base-year", M48txxISAState, state.base_year, 0),
|
|
|
|
DEFINE_PROP_UINT32("iobase", M48txxISAState, io_base, 0x74),
|
2022-03-02 01:00:32 +03:00
|
|
|
DEFINE_PROP_UINT8("irq", M48txxISAState, isairq, 8),
|
2016-11-08 09:00:35 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void m48t59_reset_isa(DeviceState *d)
|
|
|
|
{
|
|
|
|
M48txxISAState *isa = M48TXX_ISA(d);
|
|
|
|
M48t59State *NVRAM = &isa->state;
|
|
|
|
|
|
|
|
m48t59_reset_common(NVRAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m48t59_isa_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
M48txxISADeviceClass *u = M48TXX_ISA_GET_CLASS(dev);
|
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
|
|
|
M48txxISAState *d = M48TXX_ISA(dev);
|
|
|
|
M48t59State *s = &d->state;
|
|
|
|
|
2022-03-02 01:00:32 +03:00
|
|
|
if (d->isairq >= ISA_NUM_IRQS) {
|
|
|
|
error_setg(errp, "Maximum value for \"irq\" is: %u", ISA_NUM_IRQS - 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-08 09:00:35 +03:00
|
|
|
s->model = u->info.model;
|
|
|
|
s->size = u->info.size;
|
2022-03-02 01:00:37 +03:00
|
|
|
s->IRQ = isa_get_irq(isadev, d->isairq);
|
2016-11-08 09:00:35 +03:00
|
|
|
m48t59_realize_common(s, errp);
|
|
|
|
memory_region_init_io(&d->io, OBJECT(dev), &m48t59_io_ops, s, "m48t59", 4);
|
|
|
|
if (d->io_base != 0) {
|
|
|
|
isa_register_ioport(isadev, &d->io, d->io_base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m48txx_isa_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
NvramClass *nc = NVRAM_CLASS(klass);
|
|
|
|
|
|
|
|
dc->realize = m48t59_isa_realize;
|
|
|
|
dc->reset = m48t59_reset_isa;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, m48t59_isa_properties);
|
2016-11-08 09:00:35 +03:00
|
|
|
nc->read = m48txx_isa_read;
|
|
|
|
nc->write = m48txx_isa_write;
|
|
|
|
nc->toggle_lock = m48txx_isa_toggle_lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m48txx_isa_concrete_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
M48txxISADeviceClass *u = M48TXX_ISA_CLASS(klass);
|
|
|
|
M48txxInfo *info = data;
|
|
|
|
|
|
|
|
u->info = *info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo m48txx_isa_type_info = {
|
|
|
|
.name = TYPE_M48TXX_ISA,
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(M48txxISAState),
|
|
|
|
.abstract = true,
|
|
|
|
.class_init = m48txx_isa_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_NVRAM },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void m48t59_isa_register_types(void)
|
|
|
|
{
|
|
|
|
TypeInfo isa_type_info = {
|
|
|
|
.parent = TYPE_M48TXX_ISA,
|
|
|
|
.class_size = sizeof(M48txxISADeviceClass),
|
|
|
|
.class_init = m48txx_isa_concrete_class_init,
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
type_register_static(&m48txx_isa_type_info);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(m48txx_isa_info); i++) {
|
|
|
|
isa_type_info.name = m48txx_isa_info[i].bus_name;
|
|
|
|
isa_type_info.class_data = &m48txx_isa_info[i];
|
|
|
|
type_register(&isa_type_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(m48t59_isa_register_types)
|