xref: /qemu/hw/net/ne2000-isa.c (revision dcb117bfda5af6f6ceb7231778d36d8bce4aee93)
19453c5bcSGerd Hoffmann /*
29453c5bcSGerd Hoffmann  * QEMU NE2000 emulation -- isa bus windup
39453c5bcSGerd Hoffmann  *
49453c5bcSGerd Hoffmann  * Copyright (c) 2003-2004 Fabrice Bellard
59453c5bcSGerd Hoffmann  *
69453c5bcSGerd Hoffmann  * Permission is hereby granted, free of charge, to any person obtaining a copy
79453c5bcSGerd Hoffmann  * of this software and associated documentation files (the "Software"), to deal
89453c5bcSGerd Hoffmann  * in the Software without restriction, including without limitation the rights
99453c5bcSGerd Hoffmann  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
109453c5bcSGerd Hoffmann  * copies of the Software, and to permit persons to whom the Software is
119453c5bcSGerd Hoffmann  * furnished to do so, subject to the following conditions:
129453c5bcSGerd Hoffmann  *
139453c5bcSGerd Hoffmann  * The above copyright notice and this permission notice shall be included in
149453c5bcSGerd Hoffmann  * all copies or substantial portions of the Software.
159453c5bcSGerd Hoffmann  *
169453c5bcSGerd Hoffmann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
179453c5bcSGerd Hoffmann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
189453c5bcSGerd Hoffmann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
199453c5bcSGerd Hoffmann  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
209453c5bcSGerd Hoffmann  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
219453c5bcSGerd Hoffmann  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
229453c5bcSGerd Hoffmann  * THE SOFTWARE.
239453c5bcSGerd Hoffmann  */
2483c9f4caSPaolo Bonzini #include "hw/hw.h"
250d09e41aSPaolo Bonzini #include "hw/i386/pc.h"
260d09e41aSPaolo Bonzini #include "hw/isa/isa.h"
2783c9f4caSPaolo Bonzini #include "hw/qdev.h"
281422e32dSPaolo Bonzini #include "net/net.h"
2947b43a1fSPaolo Bonzini #include "ne2000.h"
30022c62cbSPaolo Bonzini #include "exec/address-spaces.h"
319453c5bcSGerd Hoffmann 
32fe6f5debSAndreas Färber #define TYPE_ISA_NE2000 "ne2k_isa"
33fe6f5debSAndreas Färber #define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
34fe6f5debSAndreas Färber 
359453c5bcSGerd Hoffmann typedef struct ISANE2000State {
36fe6f5debSAndreas Färber     ISADevice parent_obj;
37fe6f5debSAndreas Färber 
389453c5bcSGerd Hoffmann     uint32_t iobase;
399453c5bcSGerd Hoffmann     uint32_t isairq;
409453c5bcSGerd Hoffmann     NE2000State ne2000;
419453c5bcSGerd Hoffmann } ISANE2000State;
429453c5bcSGerd Hoffmann 
434e68f7a0SStefan Hajnoczi static void isa_ne2000_cleanup(NetClientState *nc)
449453c5bcSGerd Hoffmann {
45cc1f0f45SJason Wang     NE2000State *s = qemu_get_nic_opaque(nc);
469453c5bcSGerd Hoffmann 
471c2045b5SMark McLoughlin     s->nic = NULL;
489453c5bcSGerd Hoffmann }
499453c5bcSGerd Hoffmann 
501c2045b5SMark McLoughlin static NetClientInfo net_ne2000_isa_info = {
512be64a68SLaszlo Ersek     .type = NET_CLIENT_OPTIONS_KIND_NIC,
521c2045b5SMark McLoughlin     .size = sizeof(NICState),
531c2045b5SMark McLoughlin     .can_receive = ne2000_can_receive,
541c2045b5SMark McLoughlin     .receive = ne2000_receive,
551c2045b5SMark McLoughlin     .cleanup = isa_ne2000_cleanup,
561c2045b5SMark McLoughlin };
571c2045b5SMark McLoughlin 
58d05ac8faSBlue Swirl static const VMStateDescription vmstate_isa_ne2000 = {
59be73cfe2SJuan Quintela     .name = "ne2000",
60be73cfe2SJuan Quintela     .version_id = 2,
61be73cfe2SJuan Quintela     .minimum_version_id = 0,
62be73cfe2SJuan Quintela     .minimum_version_id_old = 0,
63be73cfe2SJuan Quintela     .fields      = (VMStateField []) {
64be73cfe2SJuan Quintela         VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
65be73cfe2SJuan Quintela         VMSTATE_END_OF_LIST()
66be73cfe2SJuan Quintela     }
67be73cfe2SJuan Quintela };
68be73cfe2SJuan Quintela 
69db895a1eSAndreas Färber static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
709453c5bcSGerd Hoffmann {
71db895a1eSAndreas Färber     ISADevice *isadev = ISA_DEVICE(dev);
72fe6f5debSAndreas Färber     ISANE2000State *isa = ISA_NE2000(dev);
739453c5bcSGerd Hoffmann     NE2000State *s = &isa->ne2000;
749453c5bcSGerd Hoffmann 
75*dcb117bfSPaolo Bonzini     ne2000_setup_io(s, DEVICE(isadev), 0x20);
76db895a1eSAndreas Färber     isa_register_ioport(isadev, &s->io, isa->iobase);
779453c5bcSGerd Hoffmann 
78db895a1eSAndreas Färber     isa_init_irq(isadev, &s->irq, isa->isairq);
799453c5bcSGerd Hoffmann 
8093db6685SGerd Hoffmann     qemu_macaddr_default_if_unset(&s->c.macaddr);
819453c5bcSGerd Hoffmann     ne2000_reset(s);
829453c5bcSGerd Hoffmann 
831c2045b5SMark McLoughlin     s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
84db895a1eSAndreas Färber                           object_get_typename(OBJECT(dev)), dev->id, s);
85b356f76dSJason Wang     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
869453c5bcSGerd Hoffmann }
879453c5bcSGerd Hoffmann 
8839bffca2SAnthony Liguori static Property ne2000_isa_properties[] = {
899453c5bcSGerd Hoffmann     DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
909453c5bcSGerd Hoffmann     DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
9193db6685SGerd Hoffmann     DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
929453c5bcSGerd Hoffmann     DEFINE_PROP_END_OF_LIST(),
9339bffca2SAnthony Liguori };
9439bffca2SAnthony Liguori 
9539bffca2SAnthony Liguori static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
9639bffca2SAnthony Liguori {
9739bffca2SAnthony Liguori     DeviceClass *dc = DEVICE_CLASS(klass);
98db895a1eSAndreas Färber 
99db895a1eSAndreas Färber     dc->realize = isa_ne2000_realizefn;
10039bffca2SAnthony Liguori     dc->props = ne2000_isa_properties;
10139bffca2SAnthony Liguori }
10239bffca2SAnthony Liguori 
1038c43a6f0SAndreas Färber static const TypeInfo ne2000_isa_info = {
104fe6f5debSAndreas Färber     .name          = TYPE_ISA_NE2000,
10539bffca2SAnthony Liguori     .parent        = TYPE_ISA_DEVICE,
10639bffca2SAnthony Liguori     .instance_size = sizeof(ISANE2000State),
10739bffca2SAnthony Liguori     .class_init    = isa_ne2000_class_initfn,
1089453c5bcSGerd Hoffmann };
1099453c5bcSGerd Hoffmann 
11083f7d43aSAndreas Färber static void ne2000_isa_register_types(void)
1119453c5bcSGerd Hoffmann {
11239bffca2SAnthony Liguori     type_register_static(&ne2000_isa_info);
1139453c5bcSGerd Hoffmann }
1149453c5bcSGerd Hoffmann 
11583f7d43aSAndreas Färber type_init(ne2000_isa_register_types)
116