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