ne2000-isa.c 3.5 KB
Newer Older
G
Gerd Hoffmann 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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.
 */
24
#include "hw/hw.h"
P
Paolo Bonzini 已提交
25 26
#include "hw/i386/pc.h"
#include "hw/isa/isa.h"
27
#include "hw/qdev.h"
P
Paolo Bonzini 已提交
28
#include "net/net.h"
29
#include "hw/ne2000.h"
30
#include "exec/address-spaces.h"
G
Gerd Hoffmann 已提交
31 32 33 34 35 36 37 38

typedef struct ISANE2000State {
    ISADevice dev;
    uint32_t iobase;
    uint32_t isairq;
    NE2000State ne2000;
} ISANE2000State;

39
static void isa_ne2000_cleanup(NetClientState *nc)
G
Gerd Hoffmann 已提交
40
{
J
Jason Wang 已提交
41
    NE2000State *s = qemu_get_nic_opaque(nc);
G
Gerd Hoffmann 已提交
42

M
Mark McLoughlin 已提交
43
    s->nic = NULL;
G
Gerd Hoffmann 已提交
44 45
}

M
Mark McLoughlin 已提交
46
static NetClientInfo net_ne2000_isa_info = {
47
    .type = NET_CLIENT_OPTIONS_KIND_NIC,
M
Mark McLoughlin 已提交
48 49 50 51 52 53
    .size = sizeof(NICState),
    .can_receive = ne2000_can_receive,
    .receive = ne2000_receive,
    .cleanup = isa_ne2000_cleanup,
};

B
Blue Swirl 已提交
54
static const VMStateDescription vmstate_isa_ne2000 = {
55 56 57 58 59 60 61 62 63 64
    .name = "ne2000",
    .version_id = 2,
    .minimum_version_id = 0,
    .minimum_version_id_old = 0,
    .fields      = (VMStateField []) {
        VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
        VMSTATE_END_OF_LIST()
    }
};

G
Gerd Hoffmann 已提交
65 66 67 68 69
static int isa_ne2000_initfn(ISADevice *dev)
{
    ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
    NE2000State *s = &isa->ne2000;

A
Avi Kivity 已提交
70
    ne2000_setup_io(s, 0x20);
71
    isa_register_ioport(dev, &s->io, isa->iobase);
G
Gerd Hoffmann 已提交
72 73 74

    isa_init_irq(dev, &s->irq, isa->isairq);

75
    qemu_macaddr_default_if_unset(&s->c.macaddr);
G
Gerd Hoffmann 已提交
76 77
    ne2000_reset(s);

M
Mark McLoughlin 已提交
78
    s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
79
                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
J
Jason Wang 已提交
80
    qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
G
Gerd Hoffmann 已提交
81 82 83 84

    return 0;
}

85 86 87 88 89 90 91
static Property ne2000_isa_properties[] = {
    DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
    DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
    DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
    DEFINE_PROP_END_OF_LIST(),
};

92 93
static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
{
94
    DeviceClass *dc = DEVICE_CLASS(klass);
95 96
    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
    ic->init = isa_ne2000_initfn;
97
    dc->props = ne2000_isa_properties;
98 99
}

100
static const TypeInfo ne2000_isa_info = {
101 102 103 104
    .name          = "ne2k_isa",
    .parent        = TYPE_ISA_DEVICE,
    .instance_size = sizeof(ISANE2000State),
    .class_init    = isa_ne2000_class_initfn,
G
Gerd Hoffmann 已提交
105 106
};

A
Andreas Färber 已提交
107
static void ne2000_isa_register_types(void)
G
Gerd Hoffmann 已提交
108
{
109
    type_register_static(&ne2000_isa_info);
G
Gerd Hoffmann 已提交
110 111
}

A
Andreas Färber 已提交
112
type_init(ne2000_isa_register_types)