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