2
0

ne2000-isa.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * QEMU NE2000 emulation -- isa bus windup
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "hw/isa/isa.h"
  26. #include "hw/net/ne2000-isa.h"
  27. #include "migration/vmstate.h"
  28. #include "ne2000.h"
  29. #include "sysemu/sysemu.h"
  30. #include "qapi/error.h"
  31. #include "qapi/visitor.h"
  32. #include "qemu/module.h"
  33. #define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
  34. typedef struct ISANE2000State {
  35. ISADevice parent_obj;
  36. uint32_t iobase;
  37. uint32_t isairq;
  38. NE2000State ne2000;
  39. } ISANE2000State;
  40. static NetClientInfo net_ne2000_isa_info = {
  41. .type = NET_CLIENT_DRIVER_NIC,
  42. .size = sizeof(NICState),
  43. .receive = ne2000_receive,
  44. };
  45. static const VMStateDescription vmstate_isa_ne2000 = {
  46. .name = "ne2000",
  47. .version_id = 2,
  48. .minimum_version_id = 0,
  49. .fields = (VMStateField[]) {
  50. VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
  51. VMSTATE_END_OF_LIST()
  52. }
  53. };
  54. static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
  55. {
  56. ISADevice *isadev = ISA_DEVICE(dev);
  57. ISANE2000State *isa = ISA_NE2000(dev);
  58. NE2000State *s = &isa->ne2000;
  59. ne2000_setup_io(s, DEVICE(isadev), 0x20);
  60. isa_register_ioport(isadev, &s->io, isa->iobase);
  61. isa_init_irq(isadev, &s->irq, isa->isairq);
  62. qemu_macaddr_default_if_unset(&s->c.macaddr);
  63. ne2000_reset(s);
  64. s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
  65. object_get_typename(OBJECT(dev)), dev->id, s);
  66. qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
  67. }
  68. static Property ne2000_isa_properties[] = {
  69. DEFINE_PROP_UINT32("iobase", ISANE2000State, iobase, 0x300),
  70. DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
  71. DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
  72. DEFINE_PROP_END_OF_LIST(),
  73. };
  74. static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
  75. {
  76. DeviceClass *dc = DEVICE_CLASS(klass);
  77. dc->realize = isa_ne2000_realizefn;
  78. dc->props = ne2000_isa_properties;
  79. dc->vmsd = &vmstate_isa_ne2000;
  80. set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
  81. }
  82. static void isa_ne2000_get_bootindex(Object *obj, Visitor *v,
  83. const char *name, void *opaque,
  84. Error **errp)
  85. {
  86. ISANE2000State *isa = ISA_NE2000(obj);
  87. NE2000State *s = &isa->ne2000;
  88. visit_type_int32(v, name, &s->c.bootindex, errp);
  89. }
  90. static void isa_ne2000_set_bootindex(Object *obj, Visitor *v,
  91. const char *name, void *opaque,
  92. Error **errp)
  93. {
  94. ISANE2000State *isa = ISA_NE2000(obj);
  95. NE2000State *s = &isa->ne2000;
  96. int32_t boot_index;
  97. Error *local_err = NULL;
  98. visit_type_int32(v, name, &boot_index, &local_err);
  99. if (local_err) {
  100. goto out;
  101. }
  102. /* check whether bootindex is present in fw_boot_order list */
  103. check_boot_index(boot_index, &local_err);
  104. if (local_err) {
  105. goto out;
  106. }
  107. /* change bootindex to a new one */
  108. s->c.bootindex = boot_index;
  109. out:
  110. error_propagate(errp, local_err);
  111. }
  112. static void isa_ne2000_instance_init(Object *obj)
  113. {
  114. object_property_add(obj, "bootindex", "int32",
  115. isa_ne2000_get_bootindex,
  116. isa_ne2000_set_bootindex, NULL, NULL, NULL);
  117. object_property_set_int(obj, -1, "bootindex", NULL);
  118. }
  119. static const TypeInfo ne2000_isa_info = {
  120. .name = TYPE_ISA_NE2000,
  121. .parent = TYPE_ISA_DEVICE,
  122. .instance_size = sizeof(ISANE2000State),
  123. .class_init = isa_ne2000_class_initfn,
  124. .instance_init = isa_ne2000_instance_init,
  125. };
  126. static void ne2000_isa_register_types(void)
  127. {
  128. type_register_static(&ne2000_isa_info);
  129. }
  130. type_init(ne2000_isa_register_types)