root / hw / ne2000-isa.c @ c0b1905b
History | View | Annotate | Download (3.7 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 | ISANE2000State *isa = container_of(s, ISANE2000State, ne2000); |
42 | 9453c5bc | Gerd Hoffmann | |
43 | 9453c5bc | Gerd Hoffmann | unregister_savevm("ne2000", s);
|
44 | 9453c5bc | Gerd Hoffmann | |
45 | 9453c5bc | Gerd Hoffmann | isa_unassign_ioport(isa->iobase, 16);
|
46 | 9453c5bc | Gerd Hoffmann | isa_unassign_ioport(isa->iobase + 0x10, 2); |
47 | 9453c5bc | Gerd Hoffmann | isa_unassign_ioport(isa->iobase + 0x1f, 1); |
48 | 9453c5bc | Gerd Hoffmann | } |
49 | 9453c5bc | Gerd Hoffmann | |
50 | 9453c5bc | Gerd Hoffmann | static int isa_ne2000_initfn(ISADevice *dev) |
51 | 9453c5bc | Gerd Hoffmann | { |
52 | 9453c5bc | Gerd Hoffmann | ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev); |
53 | 9453c5bc | Gerd Hoffmann | NE2000State *s = &isa->ne2000; |
54 | 9453c5bc | Gerd Hoffmann | |
55 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase, 16, 1, ne2000_ioport_write, s); |
56 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase, 16, 1, ne2000_ioport_read, s); |
57 | 9453c5bc | Gerd Hoffmann | |
58 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_write, s); |
59 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_read, s); |
60 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_write, s); |
61 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_read, s); |
62 | 9453c5bc | Gerd Hoffmann | |
63 | 9453c5bc | Gerd Hoffmann | register_ioport_write(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_write, s); |
64 | 9453c5bc | Gerd Hoffmann | register_ioport_read(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_read, s); |
65 | 9453c5bc | Gerd Hoffmann | |
66 | 9453c5bc | Gerd Hoffmann | isa_init_irq(dev, &s->irq, isa->isairq); |
67 | 9453c5bc | Gerd Hoffmann | |
68 | 9453c5bc | Gerd Hoffmann | qdev_get_macaddr(&dev->qdev, s->macaddr); |
69 | 9453c5bc | Gerd Hoffmann | ne2000_reset(s); |
70 | 9453c5bc | Gerd Hoffmann | |
71 | 9453c5bc | Gerd Hoffmann | s->vc = qdev_get_vlan_client(&dev->qdev, |
72 | 9453c5bc | Gerd Hoffmann | ne2000_can_receive, ne2000_receive, NULL,
|
73 | 9453c5bc | Gerd Hoffmann | isa_ne2000_cleanup, s); |
74 | 9453c5bc | Gerd Hoffmann | qemu_format_nic_info_str(s->vc, s->macaddr); |
75 | 9453c5bc | Gerd Hoffmann | |
76 | 9453c5bc | Gerd Hoffmann | register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s); |
77 | 9453c5bc | Gerd Hoffmann | return 0; |
78 | 9453c5bc | Gerd Hoffmann | } |
79 | 9453c5bc | Gerd Hoffmann | |
80 | 9453c5bc | Gerd Hoffmann | void isa_ne2000_init(int base, int irq, NICInfo *nd) |
81 | 9453c5bc | Gerd Hoffmann | { |
82 | 9453c5bc | Gerd Hoffmann | ISADevice *dev; |
83 | 9453c5bc | Gerd Hoffmann | |
84 | 9453c5bc | Gerd Hoffmann | qemu_check_nic_model(nd, "ne2k_isa");
|
85 | 9453c5bc | Gerd Hoffmann | |
86 | 9453c5bc | Gerd Hoffmann | dev = isa_create("ne2k_isa");
|
87 | 9453c5bc | Gerd Hoffmann | dev->qdev.nd = nd; /* hack alert */
|
88 | 9453c5bc | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "iobase", base);
|
89 | 9453c5bc | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "irq", irq);
|
90 | 9453c5bc | Gerd Hoffmann | qdev_init(&dev->qdev); |
91 | 9453c5bc | Gerd Hoffmann | } |
92 | 9453c5bc | Gerd Hoffmann | |
93 | 9453c5bc | Gerd Hoffmann | static ISADeviceInfo ne2000_isa_info = {
|
94 | 9453c5bc | Gerd Hoffmann | .qdev.name = "ne2k_isa",
|
95 | 9453c5bc | Gerd Hoffmann | .qdev.size = sizeof(ISANE2000State),
|
96 | 9453c5bc | Gerd Hoffmann | .init = isa_ne2000_initfn, |
97 | 9453c5bc | Gerd Hoffmann | .qdev.props = (Property[]) { |
98 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300), |
99 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9), |
100 | 9453c5bc | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
101 | 9453c5bc | Gerd Hoffmann | }, |
102 | 9453c5bc | Gerd Hoffmann | }; |
103 | 9453c5bc | Gerd Hoffmann | |
104 | 9453c5bc | Gerd Hoffmann | static void ne2000_isa_register_devices(void) |
105 | 9453c5bc | Gerd Hoffmann | { |
106 | 9453c5bc | Gerd Hoffmann | isa_qdev_register(&ne2000_isa_info); |
107 | 9453c5bc | Gerd Hoffmann | } |
108 | 9453c5bc | Gerd Hoffmann | |
109 | 9453c5bc | Gerd Hoffmann | device_init(ne2000_isa_register_devices) |