ne2000-isa.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "hw.h"
  25. #include "pc.h"
  26. #include "isa.h"
  27. #include "qdev.h"
  28. #include "net/net.h"
  29. #include "ne2000.h"
  30. #include "exec/address-spaces.h"
  31. typedef struct ISANE2000State {
  32. ISADevice dev;
  33. uint32_t iobase;
  34. uint32_t isairq;
  35. NE2000State ne2000;
  36. } ISANE2000State;
  37. static void isa_ne2000_cleanup(NetClientState *nc)
  38. {
  39. NE2000State *s = qemu_get_nic_opaque(nc);
  40. s->nic = NULL;
  41. }
  42. static NetClientInfo net_ne2000_isa_info = {
  43. .type = NET_CLIENT_OPTIONS_KIND_NIC,
  44. .size = sizeof(NICState),
  45. .can_receive = ne2000_can_receive,
  46. .receive = ne2000_receive,
  47. .cleanup = isa_ne2000_cleanup,
  48. };
  49. static const VMStateDescription vmstate_isa_ne2000 = {
  50. .name = "ne2000",
  51. .version_id = 2,
  52. .minimum_version_id = 0,
  53. .minimum_version_id_old = 0,
  54. .fields = (VMStateField []) {
  55. VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
  56. VMSTATE_END_OF_LIST()
  57. }
  58. };
  59. static int isa_ne2000_initfn(ISADevice *dev)
  60. {
  61. ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
  62. NE2000State *s = &isa->ne2000;
  63. ne2000_setup_io(s, 0x20);
  64. isa_register_ioport(dev, &s->io, isa->iobase);
  65. isa_init_irq(dev, &s->irq, isa->isairq);
  66. qemu_macaddr_default_if_unset(&s->c.macaddr);
  67. ne2000_reset(s);
  68. s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
  69. object_get_typename(OBJECT(dev)), dev->qdev.id, s);
  70. qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
  71. return 0;
  72. }
  73. static Property ne2000_isa_properties[] = {
  74. DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
  75. DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
  76. DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
  77. DEFINE_PROP_END_OF_LIST(),
  78. };
  79. static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
  80. {
  81. DeviceClass *dc = DEVICE_CLASS(klass);
  82. ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
  83. ic->init = isa_ne2000_initfn;
  84. dc->props = ne2000_isa_properties;
  85. }
  86. static const TypeInfo ne2000_isa_info = {
  87. .name = "ne2k_isa",
  88. .parent = TYPE_ISA_DEVICE,
  89. .instance_size = sizeof(ISANE2000State),
  90. .class_init = isa_ne2000_class_initfn,
  91. };
  92. static void ne2000_isa_register_types(void)
  93. {
  94. type_register_static(&ne2000_isa_info);
  95. }
  96. type_init(ne2000_isa_register_types)