2 * QEMU NE2000 emulation -- isa bus windup
4 * Copyright (c) 2003-2004 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu/osdep.h"
26 #include "hw/i386/pc.h"
27 #include "hw/isa/isa.h"
31 #include "exec/address-spaces.h"
32 #include "qapi/error.h"
33 #include "qapi/visitor.h"
35 #define TYPE_ISA_NE2000 "ne2k_isa"
36 #define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
38 typedef struct ISANE2000State
{
46 static NetClientInfo net_ne2000_isa_info
= {
47 .type
= NET_CLIENT_DRIVER_NIC
,
48 .size
= sizeof(NICState
),
49 .receive
= ne2000_receive
,
52 static const VMStateDescription vmstate_isa_ne2000
= {
55 .minimum_version_id
= 0,
56 .fields
= (VMStateField
[]) {
57 VMSTATE_STRUCT(ne2000
, ISANE2000State
, 0, vmstate_ne2000
, NE2000State
),
62 static void isa_ne2000_realizefn(DeviceState
*dev
, Error
**errp
)
64 ISADevice
*isadev
= ISA_DEVICE(dev
);
65 ISANE2000State
*isa
= ISA_NE2000(dev
);
66 NE2000State
*s
= &isa
->ne2000
;
68 ne2000_setup_io(s
, DEVICE(isadev
), 0x20);
69 isa_register_ioport(isadev
, &s
->io
, isa
->iobase
);
71 isa_init_irq(isadev
, &s
->irq
, isa
->isairq
);
73 qemu_macaddr_default_if_unset(&s
->c
.macaddr
);
76 s
->nic
= qemu_new_nic(&net_ne2000_isa_info
, &s
->c
,
77 object_get_typename(OBJECT(dev
)), dev
->id
, s
);
78 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->c
.macaddr
.a
);
81 static Property ne2000_isa_properties
[] = {
82 DEFINE_PROP_UINT32("iobase", ISANE2000State
, iobase
, 0x300),
83 DEFINE_PROP_UINT32("irq", ISANE2000State
, isairq
, 9),
84 DEFINE_NIC_PROPERTIES(ISANE2000State
, ne2000
.c
),
85 DEFINE_PROP_END_OF_LIST(),
88 static void isa_ne2000_class_initfn(ObjectClass
*klass
, void *data
)
90 DeviceClass
*dc
= DEVICE_CLASS(klass
);
92 dc
->realize
= isa_ne2000_realizefn
;
93 dc
->props
= ne2000_isa_properties
;
94 dc
->vmsd
= &vmstate_isa_ne2000
;
95 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
98 static void isa_ne2000_get_bootindex(Object
*obj
, Visitor
*v
,
99 const char *name
, void *opaque
,
102 ISANE2000State
*isa
= ISA_NE2000(obj
);
103 NE2000State
*s
= &isa
->ne2000
;
105 visit_type_int32(v
, name
, &s
->c
.bootindex
, errp
);
108 static void isa_ne2000_set_bootindex(Object
*obj
, Visitor
*v
,
109 const char *name
, void *opaque
,
112 ISANE2000State
*isa
= ISA_NE2000(obj
);
113 NE2000State
*s
= &isa
->ne2000
;
115 Error
*local_err
= NULL
;
117 visit_type_int32(v
, name
, &boot_index
, &local_err
);
121 /* check whether bootindex is present in fw_boot_order list */
122 check_boot_index(boot_index
, &local_err
);
126 /* change bootindex to a new one */
127 s
->c
.bootindex
= boot_index
;
130 error_propagate(errp
, local_err
);
133 static void isa_ne2000_instance_init(Object
*obj
)
135 object_property_add(obj
, "bootindex", "int32",
136 isa_ne2000_get_bootindex
,
137 isa_ne2000_set_bootindex
, NULL
, NULL
, NULL
);
138 object_property_set_int(obj
, -1, "bootindex", NULL
);
140 static const TypeInfo ne2000_isa_info
= {
141 .name
= TYPE_ISA_NE2000
,
142 .parent
= TYPE_ISA_DEVICE
,
143 .instance_size
= sizeof(ISANE2000State
),
144 .class_init
= isa_ne2000_class_initfn
,
145 .instance_init
= isa_ne2000_instance_init
,
148 static void ne2000_isa_register_types(void)
150 type_register_static(&ne2000_isa_info
);
153 type_init(ne2000_isa_register_types
)