2009-09-10 13:43:33 +04:00
|
|
|
/*
|
|
|
|
* QEMU NE2000 emulation -- isa bus windup
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/i386/pc.h"
|
|
|
|
#include "hw/isa/isa.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/qdev.h"
|
2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "ne2000.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2009-09-10 13:43:33 +04:00
|
|
|
|
2013-04-28 00:18:44 +04:00
|
|
|
#define TYPE_ISA_NE2000 "ne2k_isa"
|
|
|
|
#define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
|
|
|
|
|
2009-09-10 13:43:33 +04:00
|
|
|
typedef struct ISANE2000State {
|
2013-04-28 00:18:44 +04:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2009-09-10 13:43:33 +04:00
|
|
|
uint32_t iobase;
|
|
|
|
uint32_t isairq;
|
|
|
|
NE2000State ne2000;
|
|
|
|
} ISANE2000State;
|
|
|
|
|
2012-07-24 19:35:13 +04:00
|
|
|
static void isa_ne2000_cleanup(NetClientState *nc)
|
2009-09-10 13:43:33 +04:00
|
|
|
{
|
2013-01-30 15:12:23 +04:00
|
|
|
NE2000State *s = qemu_get_nic_opaque(nc);
|
2009-09-10 13:43:33 +04:00
|
|
|
|
2009-11-25 21:49:14 +03:00
|
|
|
s->nic = NULL;
|
2009-09-10 13:43:33 +04:00
|
|
|
}
|
|
|
|
|
2009-11-25 21:49:14 +03:00
|
|
|
static NetClientInfo net_ne2000_isa_info = {
|
2012-07-17 18:17:12 +04:00
|
|
|
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
2009-11-25 21:49:14 +03:00
|
|
|
.size = sizeof(NICState),
|
|
|
|
.can_receive = ne2000_can_receive,
|
|
|
|
.receive = ne2000_receive,
|
|
|
|
.cleanup = isa_ne2000_cleanup,
|
|
|
|
};
|
|
|
|
|
2009-12-04 23:44:44 +03:00
|
|
|
static const VMStateDescription vmstate_isa_ne2000 = {
|
2009-12-02 14:36:46 +03:00
|
|
|
.name = "ne2000",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 0,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-12-02 14:36:46 +03:00
|
|
|
VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-25 05:37:14 +04:00
|
|
|
static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
|
2009-09-10 13:43:33 +04:00
|
|
|
{
|
2012-11-25 05:37:14 +04:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
2013-04-28 00:18:44 +04:00
|
|
|
ISANE2000State *isa = ISA_NE2000(dev);
|
2009-09-10 13:43:33 +04:00
|
|
|
NE2000State *s = &isa->ne2000;
|
|
|
|
|
2013-06-25 17:04:35 +04:00
|
|
|
ne2000_setup_io(s, DEVICE(isadev), 0x20);
|
2012-11-25 05:37:14 +04:00
|
|
|
isa_register_ioport(isadev, &s->io, isa->iobase);
|
2009-09-10 13:43:33 +04:00
|
|
|
|
2012-11-25 05:37:14 +04:00
|
|
|
isa_init_irq(isadev, &s->irq, isa->isairq);
|
2009-09-10 13:43:33 +04:00
|
|
|
|
2009-10-21 17:25:27 +04:00
|
|
|
qemu_macaddr_default_if_unset(&s->c.macaddr);
|
2009-09-10 13:43:33 +04:00
|
|
|
ne2000_reset(s);
|
|
|
|
|
2009-11-25 21:49:14 +03:00
|
|
|
s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
|
2012-11-25 05:37:14 +04:00
|
|
|
object_get_typename(OBJECT(dev)), dev->id, s);
|
2013-01-30 15:12:22 +04:00
|
|
|
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
|
2009-09-10 13:43:33 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static Property ne2000_isa_properties[] = {
|
2014-02-08 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT32("iobase", ISANE2000State, iobase, 0x300),
|
2011-12-08 07:34:16 +04:00
|
|
|
DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
|
|
|
|
DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-04 21:52:49 +04:00
|
|
|
static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-11-25 05:37:14 +04:00
|
|
|
|
|
|
|
dc->realize = isa_ne2000_realizefn;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->props = ne2000_isa_properties;
|
2014-06-07 20:53:11 +04:00
|
|
|
dc->vmsd = &vmstate_isa_ne2000;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
|
2011-12-04 21:52:49 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ne2000_isa_info = {
|
2013-04-28 00:18:44 +04:00
|
|
|
.name = TYPE_ISA_NE2000,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(ISANE2000State),
|
|
|
|
.class_init = isa_ne2000_class_initfn,
|
2009-09-10 13:43:33 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void ne2000_isa_register_types(void)
|
2009-09-10 13:43:33 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&ne2000_isa_info);
|
2009-09-10 13:43:33 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(ne2000_isa_register_types)
|