]> Git Repo - qemu.git/blame - hw/net/ne2000-isa.c
hw/misc/edu: add msi_uninit() for pci_edu_uninit()
[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 */
e8d40465 24#include "qemu/osdep.h"
0d09e41a 25#include "hw/isa/isa.h"
489983d6 26#include "hw/net/ne2000-isa.h"
83c9f4ca 27#include "hw/qdev.h"
47b43a1f 28#include "ne2000.h"
489983d6 29#include "sysemu/sysemu.h"
da34e65c 30#include "qapi/error.h"
6cb0851d 31#include "qapi/visitor.h"
9453c5bc 32
fe6f5deb
AF
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
1c2045b5 43static NetClientInfo net_ne2000_isa_info = {
f394b2e2 44 .type = NET_CLIENT_DRIVER_NIC,
1c2045b5 45 .size = sizeof(NICState),
1c2045b5 46 .receive = ne2000_receive,
1c2045b5
MM
47};
48
d05ac8fa 49static const VMStateDescription vmstate_isa_ne2000 = {
be73cfe2
JQ
50 .name = "ne2000",
51 .version_id = 2,
52 .minimum_version_id = 0,
d49805ae 53 .fields = (VMStateField[]) {
be73cfe2
JQ
54 VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
55 VMSTATE_END_OF_LIST()
56 }
57};
58
db895a1e 59static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
9453c5bc 60{
db895a1e 61 ISADevice *isadev = ISA_DEVICE(dev);
fe6f5deb 62 ISANE2000State *isa = ISA_NE2000(dev);
9453c5bc
GH
63 NE2000State *s = &isa->ne2000;
64
dcb117bf 65 ne2000_setup_io(s, DEVICE(isadev), 0x20);
db895a1e 66 isa_register_ioport(isadev, &s->io, isa->iobase);
9453c5bc 67
db895a1e 68 isa_init_irq(isadev, &s->irq, isa->isairq);
9453c5bc 69
93db6685 70 qemu_macaddr_default_if_unset(&s->c.macaddr);
9453c5bc
GH
71 ne2000_reset(s);
72
1c2045b5 73 s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
db895a1e 74 object_get_typename(OBJECT(dev)), dev->id, s);
b356f76d 75 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
9453c5bc
GH
76}
77
39bffca2 78static Property ne2000_isa_properties[] = {
c7bcc85d 79 DEFINE_PROP_UINT32("iobase", ISANE2000State, iobase, 0x300),
39bffca2
AL
80 DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
81 DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
82 DEFINE_PROP_END_OF_LIST(),
83};
84
8f04ee08
AL
85static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
86{
39bffca2 87 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
88
89 dc->realize = isa_ne2000_realizefn;
39bffca2 90 dc->props = ne2000_isa_properties;
89218c21 91 dc->vmsd = &vmstate_isa_ne2000;
125ee0ed 92 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
8f04ee08
AL
93}
94
d7bce999
EB
95static void isa_ne2000_get_bootindex(Object *obj, Visitor *v,
96 const char *name, void *opaque,
97 Error **errp)
6cb0851d
GA
98{
99 ISANE2000State *isa = ISA_NE2000(obj);
100 NE2000State *s = &isa->ne2000;
101
51e72bc1 102 visit_type_int32(v, name, &s->c.bootindex, errp);
6cb0851d
GA
103}
104
d7bce999
EB
105static void isa_ne2000_set_bootindex(Object *obj, Visitor *v,
106 const char *name, void *opaque,
107 Error **errp)
6cb0851d
GA
108{
109 ISANE2000State *isa = ISA_NE2000(obj);
110 NE2000State *s = &isa->ne2000;
111 int32_t boot_index;
112 Error *local_err = NULL;
113
51e72bc1 114 visit_type_int32(v, name, &boot_index, &local_err);
6cb0851d
GA
115 if (local_err) {
116 goto out;
117 }
118 /* check whether bootindex is present in fw_boot_order list */
119 check_boot_index(boot_index, &local_err);
120 if (local_err) {
121 goto out;
122 }
123 /* change bootindex to a new one */
124 s->c.bootindex = boot_index;
125
126out:
621ff94d 127 error_propagate(errp, local_err);
6cb0851d
GA
128}
129
130static void isa_ne2000_instance_init(Object *obj)
131{
132 object_property_add(obj, "bootindex", "int32",
133 isa_ne2000_get_bootindex,
134 isa_ne2000_set_bootindex, NULL, NULL, NULL);
135 object_property_set_int(obj, -1, "bootindex", NULL);
136}
8c43a6f0 137static const TypeInfo ne2000_isa_info = {
fe6f5deb 138 .name = TYPE_ISA_NE2000,
39bffca2
AL
139 .parent = TYPE_ISA_DEVICE,
140 .instance_size = sizeof(ISANE2000State),
141 .class_init = isa_ne2000_class_initfn,
6cb0851d 142 .instance_init = isa_ne2000_instance_init,
9453c5bc
GH
143};
144
83f7d43a 145static void ne2000_isa_register_types(void)
9453c5bc 146{
39bffca2 147 type_register_static(&ne2000_isa_info);
9453c5bc
GH
148}
149
83f7d43a 150type_init(ne2000_isa_register_types)
This page took 0.689843 seconds and 4 git commands to generate.