2
0

pvpanic-isa.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * QEMU simulated pvpanic device.
  3. *
  4. * Copyright Fujitsu, Corp. 2013
  5. *
  6. * Authors:
  7. * Wen Congyang <wency@cn.fujitsu.com>
  8. * Hu Tao <hutao@cn.fujitsu.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  11. * See the COPYING file in the top-level directory.
  12. *
  13. */
  14. #include "qemu/osdep.h"
  15. #include "qemu/module.h"
  16. #include "system/runstate.h"
  17. #include "hw/nvram/fw_cfg.h"
  18. #include "hw/qdev-properties.h"
  19. #include "hw/misc/pvpanic.h"
  20. #include "qom/object.h"
  21. #include "hw/isa/isa.h"
  22. #include "hw/acpi/acpi_aml_interface.h"
  23. OBJECT_DECLARE_SIMPLE_TYPE(PVPanicISAState, PVPANIC_ISA_DEVICE)
  24. /*
  25. * PVPanicISAState for ISA device and
  26. * use ioport.
  27. */
  28. struct PVPanicISAState {
  29. ISADevice parent_obj;
  30. uint16_t ioport;
  31. PVPanicState pvpanic;
  32. };
  33. static void pvpanic_isa_initfn(Object *obj)
  34. {
  35. PVPanicISAState *s = PVPANIC_ISA_DEVICE(obj);
  36. pvpanic_setup_io(&s->pvpanic, DEVICE(s), 1);
  37. }
  38. static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
  39. {
  40. ISADevice *d = ISA_DEVICE(dev);
  41. PVPanicISAState *s = PVPANIC_ISA_DEVICE(dev);
  42. PVPanicState *ps = &s->pvpanic;
  43. FWCfgState *fw_cfg = fw_cfg_find();
  44. uint16_t *pvpanic_port;
  45. if (!fw_cfg) {
  46. return;
  47. }
  48. pvpanic_port = g_malloc(sizeof(*pvpanic_port));
  49. *pvpanic_port = cpu_to_le16(s->ioport);
  50. fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
  51. sizeof(*pvpanic_port));
  52. isa_register_ioport(d, &ps->mr, s->ioport);
  53. }
  54. static void build_pvpanic_isa_aml(AcpiDevAmlIf *adev, Aml *scope)
  55. {
  56. Aml *crs, *field, *method;
  57. PVPanicISAState *s = PVPANIC_ISA_DEVICE(adev);
  58. Aml *dev = aml_device("PEVT");
  59. aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0001")));
  60. crs = aml_resource_template();
  61. aml_append(crs,
  62. aml_io(AML_DECODE16, s->ioport, s->ioport, 1, 1)
  63. );
  64. aml_append(dev, aml_name_decl("_CRS", crs));
  65. aml_append(dev, aml_operation_region("PEOR", AML_SYSTEM_IO,
  66. aml_int(s->ioport), 1));
  67. field = aml_field("PEOR", AML_BYTE_ACC, AML_NOLOCK, AML_PRESERVE);
  68. aml_append(field, aml_named_field("PEPT", 8));
  69. aml_append(dev, field);
  70. /* device present, functioning, decoding, shown in UI */
  71. aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
  72. method = aml_method("RDPT", 0, AML_NOTSERIALIZED);
  73. aml_append(method, aml_store(aml_name("PEPT"), aml_local(0)));
  74. aml_append(method, aml_return(aml_local(0)));
  75. aml_append(dev, method);
  76. method = aml_method("WRPT", 1, AML_NOTSERIALIZED);
  77. aml_append(method, aml_store(aml_arg(0), aml_name("PEPT")));
  78. aml_append(dev, method);
  79. aml_append(scope, dev);
  80. }
  81. static const Property pvpanic_isa_properties[] = {
  82. DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicISAState, ioport, 0x505),
  83. DEFINE_PROP_UINT8("events", PVPanicISAState, pvpanic.events,
  84. PVPANIC_EVENTS),
  85. };
  86. static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
  87. {
  88. DeviceClass *dc = DEVICE_CLASS(klass);
  89. AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
  90. dc->realize = pvpanic_isa_realizefn;
  91. device_class_set_props(dc, pvpanic_isa_properties);
  92. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  93. adevc->build_dev_aml = build_pvpanic_isa_aml;
  94. }
  95. static const TypeInfo pvpanic_isa_info = {
  96. .name = TYPE_PVPANIC_ISA_DEVICE,
  97. .parent = TYPE_ISA_DEVICE,
  98. .instance_size = sizeof(PVPanicISAState),
  99. .instance_init = pvpanic_isa_initfn,
  100. .class_init = pvpanic_isa_class_init,
  101. .interfaces = (InterfaceInfo[]) {
  102. { TYPE_ACPI_DEV_AML_IF },
  103. { },
  104. },
  105. };
  106. static void pvpanic_register_types(void)
  107. {
  108. type_register_static(&pvpanic_isa_info);
  109. }
  110. type_init(pvpanic_register_types)