Statistics
| Branch: | Revision:

root / hw / net / ne2000-isa.c @ 5ce5944d

History | View | Annotate | Download (3.6 kB)

1 9453c5bc Gerd Hoffmann
/*
2 9453c5bc Gerd Hoffmann
 * QEMU NE2000 emulation -- isa bus windup
3 9453c5bc Gerd Hoffmann
 *
4 9453c5bc Gerd Hoffmann
 * Copyright (c) 2003-2004 Fabrice Bellard
5 9453c5bc Gerd Hoffmann
 *
6 9453c5bc Gerd Hoffmann
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 9453c5bc Gerd Hoffmann
 * of this software and associated documentation files (the "Software"), to deal
8 9453c5bc Gerd Hoffmann
 * in the Software without restriction, including without limitation the rights
9 9453c5bc Gerd Hoffmann
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 9453c5bc Gerd Hoffmann
 * copies of the Software, and to permit persons to whom the Software is
11 9453c5bc Gerd Hoffmann
 * furnished to do so, subject to the following conditions:
12 9453c5bc Gerd Hoffmann
 *
13 9453c5bc Gerd Hoffmann
 * The above copyright notice and this permission notice shall be included in
14 9453c5bc Gerd Hoffmann
 * all copies or substantial portions of the Software.
15 9453c5bc Gerd Hoffmann
 *
16 9453c5bc Gerd Hoffmann
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 9453c5bc Gerd Hoffmann
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 9453c5bc Gerd Hoffmann
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 9453c5bc Gerd Hoffmann
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 9453c5bc Gerd Hoffmann
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 9453c5bc Gerd Hoffmann
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 9453c5bc Gerd Hoffmann
 * THE SOFTWARE.
23 9453c5bc Gerd Hoffmann
 */
24 83c9f4ca Paolo Bonzini
#include "hw/hw.h"
25 0d09e41a Paolo Bonzini
#include "hw/i386/pc.h"
26 0d09e41a Paolo Bonzini
#include "hw/isa/isa.h"
27 83c9f4ca Paolo Bonzini
#include "hw/qdev.h"
28 1422e32d Paolo Bonzini
#include "net/net.h"
29 47b43a1f Paolo Bonzini
#include "ne2000.h"
30 022c62cb Paolo Bonzini
#include "exec/address-spaces.h"
31 9453c5bc Gerd Hoffmann
32 fe6f5deb Andreas Färber
#define TYPE_ISA_NE2000 "ne2k_isa"
33 fe6f5deb Andreas Färber
#define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
34 fe6f5deb Andreas Färber
35 9453c5bc Gerd Hoffmann
typedef struct ISANE2000State {
36 fe6f5deb Andreas Färber
    ISADevice parent_obj;
37 fe6f5deb Andreas Färber
38 9453c5bc Gerd Hoffmann
    uint32_t iobase;
39 9453c5bc Gerd Hoffmann
    uint32_t isairq;
40 9453c5bc Gerd Hoffmann
    NE2000State ne2000;
41 9453c5bc Gerd Hoffmann
} ISANE2000State;
42 9453c5bc Gerd Hoffmann
43 4e68f7a0 Stefan Hajnoczi
static void isa_ne2000_cleanup(NetClientState *nc)
44 9453c5bc Gerd Hoffmann
{
45 cc1f0f45 Jason Wang
    NE2000State *s = qemu_get_nic_opaque(nc);
46 9453c5bc Gerd Hoffmann
47 1c2045b5 Mark McLoughlin
    s->nic = NULL;
48 9453c5bc Gerd Hoffmann
}
49 9453c5bc Gerd Hoffmann
50 1c2045b5 Mark McLoughlin
static NetClientInfo net_ne2000_isa_info = {
51 2be64a68 Laszlo Ersek
    .type = NET_CLIENT_OPTIONS_KIND_NIC,
52 1c2045b5 Mark McLoughlin
    .size = sizeof(NICState),
53 1c2045b5 Mark McLoughlin
    .can_receive = ne2000_can_receive,
54 1c2045b5 Mark McLoughlin
    .receive = ne2000_receive,
55 1c2045b5 Mark McLoughlin
    .cleanup = isa_ne2000_cleanup,
56 1c2045b5 Mark McLoughlin
};
57 1c2045b5 Mark McLoughlin
58 d05ac8fa Blue Swirl
static const VMStateDescription vmstate_isa_ne2000 = {
59 be73cfe2 Juan Quintela
    .name = "ne2000",
60 be73cfe2 Juan Quintela
    .version_id = 2,
61 be73cfe2 Juan Quintela
    .minimum_version_id = 0,
62 be73cfe2 Juan Quintela
    .minimum_version_id_old = 0,
63 be73cfe2 Juan Quintela
    .fields      = (VMStateField []) {
64 be73cfe2 Juan Quintela
        VMSTATE_STRUCT(ne2000, ISANE2000State, 0, vmstate_ne2000, NE2000State),
65 be73cfe2 Juan Quintela
        VMSTATE_END_OF_LIST()
66 be73cfe2 Juan Quintela
    }
67 be73cfe2 Juan Quintela
};
68 be73cfe2 Juan Quintela
69 db895a1e Andreas Färber
static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)
70 9453c5bc Gerd Hoffmann
{
71 db895a1e Andreas Färber
    ISADevice *isadev = ISA_DEVICE(dev);
72 fe6f5deb Andreas Färber
    ISANE2000State *isa = ISA_NE2000(dev);
73 9453c5bc Gerd Hoffmann
    NE2000State *s = &isa->ne2000;
74 9453c5bc Gerd Hoffmann
75 dcb117bf Paolo Bonzini
    ne2000_setup_io(s, DEVICE(isadev), 0x20);
76 db895a1e Andreas Färber
    isa_register_ioport(isadev, &s->io, isa->iobase);
77 9453c5bc Gerd Hoffmann
78 db895a1e Andreas Färber
    isa_init_irq(isadev, &s->irq, isa->isairq);
79 9453c5bc Gerd Hoffmann
80 93db6685 Gerd Hoffmann
    qemu_macaddr_default_if_unset(&s->c.macaddr);
81 9453c5bc Gerd Hoffmann
    ne2000_reset(s);
82 9453c5bc Gerd Hoffmann
83 1c2045b5 Mark McLoughlin
    s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
84 db895a1e Andreas Färber
                          object_get_typename(OBJECT(dev)), dev->id, s);
85 b356f76d Jason Wang
    qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
86 9453c5bc Gerd Hoffmann
}
87 9453c5bc Gerd Hoffmann
88 39bffca2 Anthony Liguori
static Property ne2000_isa_properties[] = {
89 39bffca2 Anthony Liguori
    DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
90 39bffca2 Anthony Liguori
    DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
91 39bffca2 Anthony Liguori
    DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
92 39bffca2 Anthony Liguori
    DEFINE_PROP_END_OF_LIST(),
93 39bffca2 Anthony Liguori
};
94 39bffca2 Anthony Liguori
95 8f04ee08 Anthony Liguori
static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
96 8f04ee08 Anthony Liguori
{
97 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
98 db895a1e Andreas Färber
99 db895a1e Andreas Färber
    dc->realize = isa_ne2000_realizefn;
100 39bffca2 Anthony Liguori
    dc->props = ne2000_isa_properties;
101 125ee0ed Marcel Apfelbaum
    set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
102 8f04ee08 Anthony Liguori
}
103 8f04ee08 Anthony Liguori
104 8c43a6f0 Andreas Färber
static const TypeInfo ne2000_isa_info = {
105 fe6f5deb Andreas Färber
    .name          = TYPE_ISA_NE2000,
106 39bffca2 Anthony Liguori
    .parent        = TYPE_ISA_DEVICE,
107 39bffca2 Anthony Liguori
    .instance_size = sizeof(ISANE2000State),
108 39bffca2 Anthony Liguori
    .class_init    = isa_ne2000_class_initfn,
109 9453c5bc Gerd Hoffmann
};
110 9453c5bc Gerd Hoffmann
111 83f7d43a Andreas Färber
static void ne2000_isa_register_types(void)
112 9453c5bc Gerd Hoffmann
{
113 39bffca2 Anthony Liguori
    type_register_static(&ne2000_isa_info);
114 9453c5bc Gerd Hoffmann
}
115 9453c5bc Gerd Hoffmann
116 83f7d43a Andreas Färber
type_init(ne2000_isa_register_types)