root / hw / lance.c @ 9a3a8895
History | View | Annotate | Download (4.9 kB)
1 | 94e1a912 | Gerd Hoffmann | /*
|
---|---|---|---|
2 | 94e1a912 | Gerd Hoffmann | * QEMU AMD PC-Net II (Am79C970A) emulation
|
3 | 94e1a912 | Gerd Hoffmann | *
|
4 | 94e1a912 | Gerd Hoffmann | * Copyright (c) 2004 Antony T Curtis
|
5 | 94e1a912 | Gerd Hoffmann | *
|
6 | 94e1a912 | Gerd Hoffmann | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 94e1a912 | Gerd Hoffmann | * of this software and associated documentation files (the "Software"), to deal
|
8 | 94e1a912 | Gerd Hoffmann | * in the Software without restriction, including without limitation the rights
|
9 | 94e1a912 | Gerd Hoffmann | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 94e1a912 | Gerd Hoffmann | * copies of the Software, and to permit persons to whom the Software is
|
11 | 94e1a912 | Gerd Hoffmann | * furnished to do so, subject to the following conditions:
|
12 | 94e1a912 | Gerd Hoffmann | *
|
13 | 94e1a912 | Gerd Hoffmann | * The above copyright notice and this permission notice shall be included in
|
14 | 94e1a912 | Gerd Hoffmann | * all copies or substantial portions of the Software.
|
15 | 94e1a912 | Gerd Hoffmann | *
|
16 | 94e1a912 | Gerd Hoffmann | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 94e1a912 | Gerd Hoffmann | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 94e1a912 | Gerd Hoffmann | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 94e1a912 | Gerd Hoffmann | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 94e1a912 | Gerd Hoffmann | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 94e1a912 | Gerd Hoffmann | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 94e1a912 | Gerd Hoffmann | * THE SOFTWARE.
|
23 | 94e1a912 | Gerd Hoffmann | */
|
24 | 94e1a912 | Gerd Hoffmann | |
25 | 94e1a912 | Gerd Hoffmann | /* This software was written to be compatible with the specification:
|
26 | 94e1a912 | Gerd Hoffmann | * AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
|
27 | 94e1a912 | Gerd Hoffmann | * AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000
|
28 | 94e1a912 | Gerd Hoffmann | */
|
29 | 94e1a912 | Gerd Hoffmann | |
30 | 94e1a912 | Gerd Hoffmann | /*
|
31 | 94e1a912 | Gerd Hoffmann | * On Sparc32, this is the Lance (Am7990) part of chip STP2000 (Master I/O), also
|
32 | 94e1a912 | Gerd Hoffmann | * produced as NCR89C100. See
|
33 | 94e1a912 | Gerd Hoffmann | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C100.txt
|
34 | 94e1a912 | Gerd Hoffmann | * and
|
35 | 94e1a912 | Gerd Hoffmann | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR92C990.txt
|
36 | 94e1a912 | Gerd Hoffmann | */
|
37 | 94e1a912 | Gerd Hoffmann | |
38 | 94e1a912 | Gerd Hoffmann | #include "sysbus.h" |
39 | 94e1a912 | Gerd Hoffmann | #include "net.h" |
40 | 94e1a912 | Gerd Hoffmann | #include "qemu-timer.h" |
41 | 94e1a912 | Gerd Hoffmann | #include "qemu_socket.h" |
42 | 94e1a912 | Gerd Hoffmann | #include "sun4m.h" |
43 | 94e1a912 | Gerd Hoffmann | #include "pcnet.h" |
44 | 97bf4851 | Blue Swirl | #include "trace.h" |
45 | 94e1a912 | Gerd Hoffmann | |
46 | 94e1a912 | Gerd Hoffmann | typedef struct { |
47 | 94e1a912 | Gerd Hoffmann | SysBusDevice busdev; |
48 | 94e1a912 | Gerd Hoffmann | PCNetState state; |
49 | 94e1a912 | Gerd Hoffmann | } SysBusPCNetState; |
50 | 94e1a912 | Gerd Hoffmann | |
51 | 94e1a912 | Gerd Hoffmann | static void parent_lance_reset(void *opaque, int irq, int level) |
52 | 94e1a912 | Gerd Hoffmann | { |
53 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = opaque; |
54 | 94e1a912 | Gerd Hoffmann | if (level)
|
55 | 94e1a912 | Gerd Hoffmann | pcnet_h_reset(&d->state); |
56 | 94e1a912 | Gerd Hoffmann | } |
57 | 94e1a912 | Gerd Hoffmann | |
58 | bd8d6f7c | Avi Kivity | static void lance_mem_write(void *opaque, target_phys_addr_t addr, |
59 | bd8d6f7c | Avi Kivity | uint64_t val, unsigned size)
|
60 | 94e1a912 | Gerd Hoffmann | { |
61 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = opaque; |
62 | 97bf4851 | Blue Swirl | |
63 | 97bf4851 | Blue Swirl | trace_lance_mem_writew(addr, val & 0xffff);
|
64 | 94e1a912 | Gerd Hoffmann | pcnet_ioport_writew(&d->state, addr, val & 0xffff);
|
65 | 94e1a912 | Gerd Hoffmann | } |
66 | 94e1a912 | Gerd Hoffmann | |
67 | bd8d6f7c | Avi Kivity | static uint64_t lance_mem_read(void *opaque, target_phys_addr_t addr, |
68 | bd8d6f7c | Avi Kivity | unsigned size)
|
69 | 94e1a912 | Gerd Hoffmann | { |
70 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = opaque; |
71 | 94e1a912 | Gerd Hoffmann | uint32_t val; |
72 | 94e1a912 | Gerd Hoffmann | |
73 | 94e1a912 | Gerd Hoffmann | val = pcnet_ioport_readw(&d->state, addr); |
74 | 97bf4851 | Blue Swirl | trace_lance_mem_readw(addr, val & 0xffff);
|
75 | 94e1a912 | Gerd Hoffmann | return val & 0xffff; |
76 | 94e1a912 | Gerd Hoffmann | } |
77 | 94e1a912 | Gerd Hoffmann | |
78 | bd8d6f7c | Avi Kivity | static const MemoryRegionOps lance_mem_ops = { |
79 | bd8d6f7c | Avi Kivity | .read = lance_mem_read, |
80 | bd8d6f7c | Avi Kivity | .write = lance_mem_write, |
81 | bd8d6f7c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
82 | bd8d6f7c | Avi Kivity | .valid = { |
83 | bd8d6f7c | Avi Kivity | .min_access_size = 2,
|
84 | bd8d6f7c | Avi Kivity | .max_access_size = 2,
|
85 | bd8d6f7c | Avi Kivity | }, |
86 | 94e1a912 | Gerd Hoffmann | }; |
87 | 94e1a912 | Gerd Hoffmann | |
88 | 4e68f7a0 | Stefan Hajnoczi | static void lance_cleanup(NetClientState *nc) |
89 | 94e1a912 | Gerd Hoffmann | { |
90 | 1fa51482 | Mark McLoughlin | PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque; |
91 | 94e1a912 | Gerd Hoffmann | |
92 | 94e1a912 | Gerd Hoffmann | pcnet_common_cleanup(d); |
93 | 94e1a912 | Gerd Hoffmann | } |
94 | 94e1a912 | Gerd Hoffmann | |
95 | 1fa51482 | Mark McLoughlin | static NetClientInfo net_lance_info = {
|
96 | 2be64a68 | Laszlo Ersek | .type = NET_CLIENT_OPTIONS_KIND_NIC, |
97 | 1fa51482 | Mark McLoughlin | .size = sizeof(NICState),
|
98 | 1fa51482 | Mark McLoughlin | .can_receive = pcnet_can_receive, |
99 | 1fa51482 | Mark McLoughlin | .receive = pcnet_receive, |
100 | e1c2008a | Jan Kiszka | .link_status_changed = pcnet_set_link_status, |
101 | 1fa51482 | Mark McLoughlin | .cleanup = lance_cleanup, |
102 | 1fa51482 | Mark McLoughlin | }; |
103 | 1fa51482 | Mark McLoughlin | |
104 | be73cfe2 | Juan Quintela | static const VMStateDescription vmstate_lance = { |
105 | be73cfe2 | Juan Quintela | .name = "pcnet",
|
106 | be73cfe2 | Juan Quintela | .version_id = 3,
|
107 | be73cfe2 | Juan Quintela | .minimum_version_id = 2,
|
108 | be73cfe2 | Juan Quintela | .minimum_version_id_old = 2,
|
109 | be73cfe2 | Juan Quintela | .fields = (VMStateField []) { |
110 | be73cfe2 | Juan Quintela | VMSTATE_STRUCT(state, SysBusPCNetState, 0, vmstate_pcnet, PCNetState),
|
111 | be73cfe2 | Juan Quintela | VMSTATE_END_OF_LIST() |
112 | be73cfe2 | Juan Quintela | } |
113 | be73cfe2 | Juan Quintela | }; |
114 | be73cfe2 | Juan Quintela | |
115 | 94e1a912 | Gerd Hoffmann | static int lance_init(SysBusDevice *dev) |
116 | 94e1a912 | Gerd Hoffmann | { |
117 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); |
118 | 94e1a912 | Gerd Hoffmann | PCNetState *s = &d->state; |
119 | 94e1a912 | Gerd Hoffmann | |
120 | 032a7c4e | Avi Kivity | memory_region_init_io(&s->mmio, &lance_mem_ops, d, "lance-mmio", 4); |
121 | 94e1a912 | Gerd Hoffmann | |
122 | 94e1a912 | Gerd Hoffmann | qdev_init_gpio_in(&dev->qdev, parent_lance_reset, 1);
|
123 | 94e1a912 | Gerd Hoffmann | |
124 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->mmio); |
125 | 94e1a912 | Gerd Hoffmann | |
126 | 94e1a912 | Gerd Hoffmann | sysbus_init_irq(dev, &s->irq); |
127 | 94e1a912 | Gerd Hoffmann | |
128 | 94e1a912 | Gerd Hoffmann | s->phys_mem_read = ledma_memory_read; |
129 | 94e1a912 | Gerd Hoffmann | s->phys_mem_write = ledma_memory_write; |
130 | 1fa51482 | Mark McLoughlin | return pcnet_common_init(&dev->qdev, s, &net_lance_info);
|
131 | 94e1a912 | Gerd Hoffmann | } |
132 | 94e1a912 | Gerd Hoffmann | |
133 | 94e1a912 | Gerd Hoffmann | static void lance_reset(DeviceState *dev) |
134 | 94e1a912 | Gerd Hoffmann | { |
135 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = DO_UPCAST(SysBusPCNetState, busdev.qdev, dev); |
136 | 94e1a912 | Gerd Hoffmann | |
137 | 94e1a912 | Gerd Hoffmann | pcnet_h_reset(&d->state); |
138 | 94e1a912 | Gerd Hoffmann | } |
139 | 94e1a912 | Gerd Hoffmann | |
140 | 999e12bb | Anthony Liguori | static Property lance_properties[] = {
|
141 | 999e12bb | Anthony Liguori | DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
|
142 | 999e12bb | Anthony Liguori | DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf), |
143 | 999e12bb | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
144 | 999e12bb | Anthony Liguori | }; |
145 | 999e12bb | Anthony Liguori | |
146 | 999e12bb | Anthony Liguori | static void lance_class_init(ObjectClass *klass, void *data) |
147 | 999e12bb | Anthony Liguori | { |
148 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
149 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
150 | 999e12bb | Anthony Liguori | |
151 | 999e12bb | Anthony Liguori | k->init = lance_init; |
152 | 39bffca2 | Anthony Liguori | dc->fw_name = "ethernet";
|
153 | 39bffca2 | Anthony Liguori | dc->reset = lance_reset; |
154 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_lance; |
155 | 39bffca2 | Anthony Liguori | dc->props = lance_properties; |
156 | 999e12bb | Anthony Liguori | } |
157 | 999e12bb | Anthony Liguori | |
158 | 39bffca2 | Anthony Liguori | static TypeInfo lance_info = {
|
159 | 39bffca2 | Anthony Liguori | .name = "lance",
|
160 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
161 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(SysBusPCNetState),
|
162 | 39bffca2 | Anthony Liguori | .class_init = lance_class_init, |
163 | 94e1a912 | Gerd Hoffmann | }; |
164 | 94e1a912 | Gerd Hoffmann | |
165 | 83f7d43a | Andreas Färber | static void lance_register_types(void) |
166 | 94e1a912 | Gerd Hoffmann | { |
167 | 39bffca2 | Anthony Liguori | type_register_static(&lance_info); |
168 | 94e1a912 | Gerd Hoffmann | } |
169 | 83f7d43a | Andreas Färber | |
170 | 83f7d43a | Andreas Färber | type_init(lance_register_types) |