]> git.proxmox.com Git - qemu.git/blame - hw/net/ne2000-isa.c
Merge git://github.com/hw-claudio/qemu-aarch64-queue into tcg-next
[qemu.git] / hw / net / ne2000-isa.c
CommitLineData
9453c5bc
GH
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 */
83c9f4ca 24#include "hw/hw.h"
0d09e41a
PB
25#include "hw/i386/pc.h"
26#include "hw/isa/isa.h"
83c9f4ca 27#include "hw/qdev.h"
1422e32d 28#include "net/net.h"
47b43a1f 29#include "ne2000.h"
022c62cb 30#include "exec/address-spaces.h"
9453c5bc 31
fe6f5deb
AF
32#define TYPE_ISA_NE2000 "ne2k_isa"
33#define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
34
9453c5bc 35typedef struct ISANE2000State {
fe6f5deb
AF
36 ISADevice parent_obj;
37
9453c5bc
GH
38 uint32_t iobase;
39 uint32_t isairq;
40 NE2000State ne2000;
41} ISANE2000State;
42
4e68f7a0 43static void isa_ne2000_cleanup(NetClientState *nc)
9453c5bc 44{
cc1f0f45 45 NE2000State *s = qemu_get_nic_opaque(nc);
9453c5bc 46
1c2045b5 47 s->nic = NULL;
9453c5bc
GH
48}
49
1c2045b5 50static NetClientInfo net_ne2000_isa_info = {
2be64a68 51 .type = NET_CLIENT_OPTIONS_KIND_NIC,
1c2045b5
MM
52 .size = sizeof(NICState),
53 .can_receive = ne2000_can_receive,
54 .receive = ne2000_receive,
55 .cleanup = isa_ne2000_cleanup,
56};
57
d05ac8fa 58static const VMStateDescription vmstate_isa_ne2000 = {
be73cfe2
JQ
59 .name = "ne2000",
60 .version_id = 2,
61 .minimum_version_id = 0,
62 .minimum_version_id_old = 0,
63 .fields = (VMStateField []) {
64 VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
65 VMSTATE_END_OF_LIST()
66 }
67};
68
db895a1e 69static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
9453c5bc 70{
db895a1e 71 ISADevice *isadev = ISA_DEVICE(dev);
fe6f5deb 72 ISANE2000State *isa = ISA_NE2000(dev);
9453c5bc
GH
73 NE2000State *s = &isa->ne2000;
74
dcb117bf 75 ne2000_setup_io(s, DEVICE(isadev), 0x20);
db895a1e 76 isa_register_ioport(isadev, &s->io, isa->iobase);
9453c5bc 77
db895a1e 78 isa_init_irq(isadev, &s->irq, isa->isairq);
9453c5bc 79
93db6685 80 qemu_macaddr_default_if_unset(&s->c.macaddr);
9453c5bc
GH
81 ne2000_reset(s);
82
1c2045b5 83 s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
db895a1e 84 object_get_typename(OBJECT(dev)), dev->id, s);
b356f76d 85 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
9453c5bc
GH
86}
87
39bffca2
AL
88static Property ne2000_isa_properties[] = {
89 DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
90 DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
91 DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
92 DEFINE_PROP_END_OF_LIST(),
93};
94
8f04ee08
AL
95static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
96{
39bffca2 97 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
98
99 dc->realize = isa_ne2000_realizefn;
39bffca2 100 dc->props = ne2000_isa_properties;
8f04ee08
AL
101}
102
8c43a6f0 103static const TypeInfo ne2000_isa_info = {
fe6f5deb 104 .name = TYPE_ISA_NE2000,
39bffca2
AL
105 .parent = TYPE_ISA_DEVICE,
106 .instance_size = sizeof(ISANE2000State),
107 .class_init = isa_ne2000_class_initfn,
9453c5bc
GH
108};
109
83f7d43a 110static void ne2000_isa_register_types(void)
9453c5bc 111{
39bffca2 112 type_register_static(&ne2000_isa_info);
9453c5bc
GH
113}
114
83f7d43a 115type_init(ne2000_isa_register_types)