2
0

pvpanic-isa.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "sysemu/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 "standard-headers/linux/pvpanic.h"
  23. #include "hw/acpi/acpi_aml_interface.h"
  24. OBJECT_DECLARE_SIMPLE_TYPE(PVPanicISAState, PVPANIC_ISA_DEVICE)
  25. /*
  26. * PVPanicISAState for ISA device and
  27. * use ioport.
  28. */
  29. struct PVPanicISAState {
  30. ISADevice parent_obj;
  31. uint16_t ioport;
  32. PVPanicState pvpanic;
  33. };
  34. static void pvpanic_isa_initfn(Object *obj)
  35. {
  36. PVPanicISAState *s = PVPANIC_ISA_DEVICE(obj);
  37. pvpanic_setup_io(&s->pvpanic, DEVICE(s), 1);
  38. }
  39. static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
  40. {
  41. ISADevice *d = ISA_DEVICE(dev);
  42. PVPanicISAState *s = PVPANIC_ISA_DEVICE(dev);
  43. PVPanicState *ps = &s->pvpanic;
  44. FWCfgState *fw_cfg = fw_cfg_find();
  45. uint16_t *pvpanic_port;
  46. if (!fw_cfg) {
  47. return;
  48. }
  49. pvpanic_port = g_malloc(sizeof(*pvpanic_port));
  50. *pvpanic_port = cpu_to_le16(s->ioport);
  51. fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
  52. sizeof(*pvpanic_port));
  53. isa_register_ioport(d, &ps->mr, s->ioport);
  54. }
  55. static void build_pvpanic_isa_aml(AcpiDevAmlIf *adev, Aml *scope)
  56. {
  57. Aml *crs, *field, *method;
  58. PVPanicISAState *s = PVPANIC_ISA_DEVICE(adev);
  59. Aml *dev = aml_device("PEVT");
  60. aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0001")));
  61. crs = aml_resource_template();
  62. aml_append(crs,
  63. aml_io(AML_DECODE16, s->ioport, s->ioport, 1, 1)
  64. );
  65. aml_append(dev, aml_name_decl("_CRS", crs));
  66. aml_append(dev, aml_operation_region("PEOR", AML_SYSTEM_IO,
  67. aml_int(s->ioport), 1));
  68. field = aml_field("PEOR", AML_BYTE_ACC, AML_NOLOCK, AML_PRESERVE);
  69. aml_append(field, aml_named_field("PEPT", 8));
  70. aml_append(dev, field);
  71. /* device present, functioning, decoding, shown in UI */
  72. aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
  73. method = aml_method("RDPT", 0, AML_NOTSERIALIZED);
  74. aml_append(method, aml_store(aml_name("PEPT"), aml_local(0)));
  75. aml_append(method, aml_return(aml_local(0)));
  76. aml_append(dev, method);
  77. method = aml_method("WRPT", 1, AML_NOTSERIALIZED);
  78. aml_append(method, aml_store(aml_arg(0), aml_name("PEPT")));
  79. aml_append(dev, method);
  80. aml_append(scope, dev);
  81. }
  82. static Property pvpanic_isa_properties[] = {
  83. DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicISAState, ioport, 0x505),
  84. DEFINE_PROP_UINT8("events", PVPanicISAState, pvpanic.events,
  85. PVPANIC_PANICKED | PVPANIC_CRASH_LOADED),
  86. DEFINE_PROP_END_OF_LIST(),
  87. };
  88. static void pvpanic_isa_class_init(ObjectClass *klass, void *data)
  89. {
  90. DeviceClass *dc = DEVICE_CLASS(klass);
  91. AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
  92. dc->realize = pvpanic_isa_realizefn;
  93. device_class_set_props(dc, pvpanic_isa_properties);
  94. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  95. adevc->build_dev_aml = build_pvpanic_isa_aml;
  96. }
  97. static const TypeInfo pvpanic_isa_info = {
  98. .name = TYPE_PVPANIC_ISA_DEVICE,
  99. .parent = TYPE_ISA_DEVICE,
  100. .instance_size = sizeof(PVPanicISAState),
  101. .instance_init = pvpanic_isa_initfn,
  102. .class_init = pvpanic_isa_class_init,
  103. .interfaces = (InterfaceInfo[]) {
  104. { TYPE_ACPI_DEV_AML_IF },
  105. { },
  106. },
  107. };
  108. static void pvpanic_register_types(void)
  109. {
  110. type_register_static(&pvpanic_isa_info);
  111. }
  112. type_init(pvpanic_register_types)