root / hw / ne2000-isa.c @ 91011d4f
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 | 9453c5bc | Gerd Hoffmann | #include "hw.h" |
25 | 9453c5bc | Gerd Hoffmann | #include "pc.h" |
26 | 9453c5bc | Gerd Hoffmann | #include "isa.h" |
27 | 9453c5bc | Gerd Hoffmann | #include "qdev.h" |
28 | 9453c5bc | Gerd Hoffmann | #include "net.h" |
29 | 9453c5bc | Gerd Hoffmann | #include "ne2000.h" |
30 | 9453c5bc | Gerd Hoffmann | |
31 | 9453c5bc | Gerd Hoffmann | typedef struct ISANE2000State { |
32 | 9453c5bc | Gerd Hoffmann | ISADevice dev; |
33 | 9453c5bc | Gerd Hoffmann | uint32_t iobase; |
34 | 9453c5bc | Gerd Hoffmann | uint32_t isairq; |
35 | 9453c5bc | Gerd Hoffmann | NE2000State ne2000; |
36 | 9453c5bc | Gerd Hoffmann | } ISANE2000State; |
37 | 9453c5bc | Gerd Hoffmann | |
38 | 9453c5bc | Gerd Hoffmann | static void isa_ne2000_cleanup(VLANClientState *vc) |
39 | 9453c5bc | Gerd Hoffmann | { |
40 | 9453c5bc | Gerd Hoffmann | NE2000State *s = vc->opaque; |
41 | 9453c5bc | Gerd Hoffmann | |
42 | 93db6685 | Gerd Hoffmann | s->vc = NULL;
|
43 | 9453c5bc | Gerd Hoffmann | } |
44 | 9453c5bc | Gerd Hoffmann | |
45 | 9453c5bc | Gerd Hoffmann | static int isa_ne2000_initfn(ISADevice *dev) |
46 | 9453c5bc | Gerd Hoffmann | { |
47 | 9453c5bc | Gerd Hoffmann | ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev); |
48 | 9453c5bc | Gerd Hoffmann | NE2000State *s = &isa->ne2000; |
49 | 9453c5bc | Gerd Hoffmann | |
50 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase, 16, 1, ne2000_ioport_write, s); |
51 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase, 16, 1, ne2000_ioport_read, s); |
52 | 9453c5bc | Gerd Hoffmann | |
53 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_write, s); |
54 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_read, s); |
55 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_write, s); |
56 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_read, s); |
57 | 9453c5bc | Gerd Hoffmann | |
58 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_write, s); |
59 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_read, s); |
60 | 9453c5bc | Gerd Hoffmann | |
61 | 9453c5bc | Gerd Hoffmann | isa_init_irq(dev, &s->irq, isa->isairq); |
62 | 9453c5bc | Gerd Hoffmann | |
63 | 93db6685 | Gerd Hoffmann | qemu_macaddr_default_if_unset(&s->c.macaddr); |
64 | 9453c5bc | Gerd Hoffmann | ne2000_reset(s); |
65 | 9453c5bc | Gerd Hoffmann | |
66 | 93db6685 | Gerd Hoffmann | s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer, |
67 | 93db6685 | Gerd Hoffmann | dev->qdev.info->name, dev->qdev.id, |
68 | 9453c5bc | Gerd Hoffmann | ne2000_can_receive, ne2000_receive, NULL,
|
69 | 93db6685 | Gerd Hoffmann | NULL, isa_ne2000_cleanup, s);
|
70 | 93db6685 | Gerd Hoffmann | qemu_format_nic_info_str(s->vc, s->c.macaddr.a); |
71 | 9453c5bc | Gerd Hoffmann | |
72 | 7c131dd5 | Juan Quintela | vmstate_register(-1, &vmstate_ne2000, s);
|
73 | 9453c5bc | Gerd Hoffmann | return 0; |
74 | 9453c5bc | Gerd Hoffmann | } |
75 | 9453c5bc | Gerd Hoffmann | |
76 | 9453c5bc | Gerd Hoffmann | void isa_ne2000_init(int base, int irq, NICInfo *nd) |
77 | 9453c5bc | Gerd Hoffmann | { |
78 | 9453c5bc | Gerd Hoffmann | ISADevice *dev; |
79 | 9453c5bc | Gerd Hoffmann | |
80 | 9453c5bc | Gerd Hoffmann | qemu_check_nic_model(nd, "ne2k_isa");
|
81 | 9453c5bc | Gerd Hoffmann | |
82 | 9453c5bc | Gerd Hoffmann | dev = isa_create("ne2k_isa");
|
83 | 9453c5bc | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "iobase", base);
|
84 | 9453c5bc | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "irq", irq);
|
85 | 93db6685 | Gerd Hoffmann | qdev_set_nic_properties(&dev->qdev, nd); |
86 | e23a1b33 | Markus Armbruster | qdev_init_nofail(&dev->qdev); |
87 | 9453c5bc | Gerd Hoffmann | } |
88 | 9453c5bc | Gerd Hoffmann | |
89 | 9453c5bc | Gerd Hoffmann | static ISADeviceInfo ne2000_isa_info = {
|
90 | 9453c5bc | Gerd Hoffmann | .qdev.name = "ne2k_isa",
|
91 | 9453c5bc | Gerd Hoffmann | .qdev.size = sizeof(ISANE2000State),
|
92 | 9453c5bc | Gerd Hoffmann | .init = isa_ne2000_initfn, |
93 | 9453c5bc | Gerd Hoffmann | .qdev.props = (Property[]) { |
94 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300), |
95 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9), |
96 | 93db6685 | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c), |
97 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
98 | 9453c5bc | Gerd Hoffmann | }, |
99 | 9453c5bc | Gerd Hoffmann | }; |
100 | 9453c5bc | Gerd Hoffmann | |
101 | 9453c5bc | Gerd Hoffmann | static void ne2000_isa_register_devices(void) |
102 | 9453c5bc | Gerd Hoffmann | { |
103 | 9453c5bc | Gerd Hoffmann | isa_qdev_register(&ne2000_isa_info); |
104 | 9453c5bc | Gerd Hoffmann | } |
105 | 9453c5bc | Gerd Hoffmann | |
106 | 9453c5bc | Gerd Hoffmann | device_init(ne2000_isa_register_devices) |