m48t59-isa.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * QEMU M48T59 and M48T08 NVRAM emulation (ISA bus interface)
  3. *
  4. * Copyright (c) 2003-2005, 2007 Jocelyn Mayer
  5. * Copyright (c) 2013 Hervé Poussineau
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #include "qemu/osdep.h"
  26. #include "hw/isa/isa.h"
  27. #include "hw/qdev-properties.h"
  28. #include "hw/rtc/m48t59.h"
  29. #include "m48t59-internal.h"
  30. #include "qapi/error.h"
  31. #include "qemu/module.h"
  32. #include "qom/object.h"
  33. #define TYPE_M48TXX_ISA "isa-m48txx"
  34. typedef struct M48txxISADeviceClass M48txxISADeviceClass;
  35. typedef struct M48txxISAState M48txxISAState;
  36. DECLARE_OBJ_CHECKERS(M48txxISAState, M48txxISADeviceClass,
  37. M48TXX_ISA, TYPE_M48TXX_ISA)
  38. struct M48txxISAState {
  39. ISADevice parent_obj;
  40. M48t59State state;
  41. uint32_t io_base;
  42. uint8_t isairq;
  43. MemoryRegion io;
  44. };
  45. struct M48txxISADeviceClass {
  46. DeviceClass parent_class;
  47. M48txxInfo info;
  48. };
  49. static M48txxInfo m48txx_isa_info[] = {
  50. {
  51. .bus_name = "isa-m48t59",
  52. .model = 59,
  53. .size = 0x2000,
  54. }
  55. };
  56. static uint32_t m48txx_isa_read(Nvram *obj, uint32_t addr)
  57. {
  58. M48txxISAState *d = M48TXX_ISA(obj);
  59. return m48t59_read(&d->state, addr);
  60. }
  61. static void m48txx_isa_write(Nvram *obj, uint32_t addr, uint32_t val)
  62. {
  63. M48txxISAState *d = M48TXX_ISA(obj);
  64. m48t59_write(&d->state, addr, val);
  65. }
  66. static void m48txx_isa_toggle_lock(Nvram *obj, int lock)
  67. {
  68. M48txxISAState *d = M48TXX_ISA(obj);
  69. m48t59_toggle_lock(&d->state, lock);
  70. }
  71. static const Property m48t59_isa_properties[] = {
  72. DEFINE_PROP_INT32("base-year", M48txxISAState, state.base_year, 0),
  73. DEFINE_PROP_UINT32("iobase", M48txxISAState, io_base, 0x74),
  74. DEFINE_PROP_UINT8("irq", M48txxISAState, isairq, 8),
  75. };
  76. static void m48t59_reset_isa(DeviceState *d)
  77. {
  78. M48txxISAState *isa = M48TXX_ISA(d);
  79. M48t59State *NVRAM = &isa->state;
  80. m48t59_reset_common(NVRAM);
  81. }
  82. static void m48t59_isa_realize(DeviceState *dev, Error **errp)
  83. {
  84. M48txxISADeviceClass *u = M48TXX_ISA_GET_CLASS(dev);
  85. ISADevice *isadev = ISA_DEVICE(dev);
  86. M48txxISAState *d = M48TXX_ISA(dev);
  87. M48t59State *s = &d->state;
  88. if (d->isairq >= ISA_NUM_IRQS) {
  89. error_setg(errp, "Maximum value for \"irq\" is: %u", ISA_NUM_IRQS - 1);
  90. return;
  91. }
  92. s->model = u->info.model;
  93. s->size = u->info.size;
  94. s->IRQ = isa_get_irq(isadev, d->isairq);
  95. m48t59_realize_common(s, errp);
  96. memory_region_init_io(&d->io, OBJECT(dev), &m48t59_io_ops, s, "m48t59", 4);
  97. if (d->io_base != 0) {
  98. isa_register_ioport(isadev, &d->io, d->io_base);
  99. }
  100. }
  101. static void m48txx_isa_class_init(ObjectClass *klass, void *data)
  102. {
  103. DeviceClass *dc = DEVICE_CLASS(klass);
  104. NvramClass *nc = NVRAM_CLASS(klass);
  105. dc->realize = m48t59_isa_realize;
  106. device_class_set_legacy_reset(dc, m48t59_reset_isa);
  107. device_class_set_props(dc, m48t59_isa_properties);
  108. nc->read = m48txx_isa_read;
  109. nc->write = m48txx_isa_write;
  110. nc->toggle_lock = m48txx_isa_toggle_lock;
  111. }
  112. static void m48txx_isa_concrete_class_init(ObjectClass *klass, void *data)
  113. {
  114. M48txxISADeviceClass *u = M48TXX_ISA_CLASS(klass);
  115. const M48txxInfo *info = data;
  116. u->info = *info;
  117. }
  118. static const TypeInfo m48txx_isa_type_info = {
  119. .name = TYPE_M48TXX_ISA,
  120. .parent = TYPE_ISA_DEVICE,
  121. .instance_size = sizeof(M48txxISAState),
  122. .abstract = true,
  123. .class_init = m48txx_isa_class_init,
  124. .interfaces = (InterfaceInfo[]) {
  125. { TYPE_NVRAM },
  126. { }
  127. }
  128. };
  129. static void m48t59_isa_register_types(void)
  130. {
  131. TypeInfo isa_type_info = {
  132. .parent = TYPE_M48TXX_ISA,
  133. .class_size = sizeof(M48txxISADeviceClass),
  134. .class_init = m48txx_isa_concrete_class_init,
  135. };
  136. int i;
  137. type_register_static(&m48txx_isa_type_info);
  138. for (i = 0; i < ARRAY_SIZE(m48txx_isa_info); i++) {
  139. isa_type_info.name = m48txx_isa_info[i].bus_name;
  140. isa_type_info.class_data = &m48txx_isa_info[i];
  141. type_register_static(&isa_type_info);
  142. }
  143. }
  144. type_init(m48t59_isa_register_types)