root / hw / pcnet-pci.c @ 37952117
History | View | Annotate | Download (11.1 kB)
1 | 661a1799 | Paul Brook | /*
|
---|---|---|---|
2 | 661a1799 | Paul Brook | * QEMU AMD PC-Net II (Am79C970A) PCI emulation
|
3 | 661a1799 | Paul Brook | *
|
4 | 661a1799 | Paul Brook | * Copyright (c) 2004 Antony T Curtis
|
5 | 661a1799 | Paul Brook | *
|
6 | 661a1799 | Paul Brook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 661a1799 | Paul Brook | * of this software and associated documentation files (the "Software"), to deal
|
8 | 661a1799 | Paul Brook | * in the Software without restriction, including without limitation the rights
|
9 | 661a1799 | Paul Brook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 661a1799 | Paul Brook | * copies of the Software, and to permit persons to whom the Software is
|
11 | 661a1799 | Paul Brook | * furnished to do so, subject to the following conditions:
|
12 | 661a1799 | Paul Brook | *
|
13 | 661a1799 | Paul Brook | * The above copyright notice and this permission notice shall be included in
|
14 | 661a1799 | Paul Brook | * all copies or substantial portions of the Software.
|
15 | 661a1799 | Paul Brook | *
|
16 | 661a1799 | Paul Brook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 661a1799 | Paul Brook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 661a1799 | Paul Brook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 661a1799 | Paul Brook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 661a1799 | Paul Brook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 661a1799 | Paul Brook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 661a1799 | Paul Brook | * THE SOFTWARE.
|
23 | 661a1799 | Paul Brook | */
|
24 | 661a1799 | Paul Brook | |
25 | 661a1799 | Paul Brook | /* This software was written to be compatible with the specification:
|
26 | 661a1799 | Paul Brook | * AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
|
27 | 661a1799 | Paul Brook | * AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000
|
28 | 661a1799 | Paul Brook | */
|
29 | 661a1799 | Paul Brook | |
30 | 661a1799 | Paul Brook | #include "pci.h" |
31 | 661a1799 | Paul Brook | #include "net.h" |
32 | 661a1799 | Paul Brook | #include "loader.h" |
33 | 661a1799 | Paul Brook | #include "qemu-timer.h" |
34 | 14fecf26 | Eduard - Gabriel Munteanu | #include "dma.h" |
35 | 661a1799 | Paul Brook | |
36 | 661a1799 | Paul Brook | #include "pcnet.h" |
37 | 661a1799 | Paul Brook | |
38 | 661a1799 | Paul Brook | //#define PCNET_DEBUG
|
39 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_IO
|
40 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_BCR
|
41 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_CSR
|
42 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_RMD
|
43 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_TMD
|
44 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_MATCH
|
45 | 661a1799 | Paul Brook | |
46 | 661a1799 | Paul Brook | |
47 | 661a1799 | Paul Brook | typedef struct { |
48 | 661a1799 | Paul Brook | PCIDevice pci_dev; |
49 | 661a1799 | Paul Brook | PCNetState state; |
50 | bd8d6f7c | Avi Kivity | MemoryRegion io_bar; |
51 | 661a1799 | Paul Brook | } PCIPCNetState; |
52 | 661a1799 | Paul Brook | |
53 | 661a1799 | Paul Brook | static void pcnet_aprom_writeb(void *opaque, uint32_t addr, uint32_t val) |
54 | 661a1799 | Paul Brook | { |
55 | 661a1799 | Paul Brook | PCNetState *s = opaque; |
56 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG
|
57 | 661a1799 | Paul Brook | printf("pcnet_aprom_writeb addr=0x%08x val=0x%02x\n", addr, val);
|
58 | 661a1799 | Paul Brook | #endif
|
59 | 488a1a5d | Jan Kiszka | if (BCR_APROMWE(s)) {
|
60 | 661a1799 | Paul Brook | s->prom[addr & 15] = val;
|
61 | 488a1a5d | Jan Kiszka | } |
62 | 661a1799 | Paul Brook | } |
63 | 661a1799 | Paul Brook | |
64 | 661a1799 | Paul Brook | static uint32_t pcnet_aprom_readb(void *opaque, uint32_t addr) |
65 | 661a1799 | Paul Brook | { |
66 | 661a1799 | Paul Brook | PCNetState *s = opaque; |
67 | 661a1799 | Paul Brook | uint32_t val = s->prom[addr & 15];
|
68 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG
|
69 | 661a1799 | Paul Brook | printf("pcnet_aprom_readb addr=0x%08x val=0x%02x\n", addr, val);
|
70 | 661a1799 | Paul Brook | #endif
|
71 | 661a1799 | Paul Brook | return val;
|
72 | 661a1799 | Paul Brook | } |
73 | 661a1799 | Paul Brook | |
74 | bd8d6f7c | Avi Kivity | static uint64_t pcnet_ioport_read(void *opaque, target_phys_addr_t addr, |
75 | bd8d6f7c | Avi Kivity | unsigned size)
|
76 | 661a1799 | Paul Brook | { |
77 | bd8d6f7c | Avi Kivity | PCNetState *d = opaque; |
78 | 661a1799 | Paul Brook | |
79 | 7ba79741 | Jan Kiszka | if (addr < 0x10) { |
80 | 7ba79741 | Jan Kiszka | if (!BCR_DWIO(d) && size == 1) { |
81 | 7ba79741 | Jan Kiszka | return pcnet_aprom_readb(d, addr);
|
82 | 7ba79741 | Jan Kiszka | } else if (!BCR_DWIO(d) && (addr & 1) == 0 && size == 2) { |
83 | 7ba79741 | Jan Kiszka | return pcnet_aprom_readb(d, addr) |
|
84 | 7ba79741 | Jan Kiszka | (pcnet_aprom_readb(d, addr + 1) << 8); |
85 | 7ba79741 | Jan Kiszka | } else if (BCR_DWIO(d) && (addr & 3) == 0 && size == 4) { |
86 | 7ba79741 | Jan Kiszka | return pcnet_aprom_readb(d, addr) |
|
87 | 7ba79741 | Jan Kiszka | (pcnet_aprom_readb(d, addr + 1) << 8) | |
88 | 7ba79741 | Jan Kiszka | (pcnet_aprom_readb(d, addr + 2) << 16) | |
89 | 7ba79741 | Jan Kiszka | (pcnet_aprom_readb(d, addr + 3) << 24); |
90 | 7ba79741 | Jan Kiszka | } |
91 | 7ba79741 | Jan Kiszka | } else {
|
92 | 7ba79741 | Jan Kiszka | if (size == 2) { |
93 | 7ba79741 | Jan Kiszka | return pcnet_ioport_readw(d, addr);
|
94 | 7ba79741 | Jan Kiszka | } else if (size == 4) { |
95 | 7ba79741 | Jan Kiszka | return pcnet_ioport_readl(d, addr);
|
96 | 7ba79741 | Jan Kiszka | } |
97 | bd8d6f7c | Avi Kivity | } |
98 | bd8d6f7c | Avi Kivity | return ((uint64_t)1 << (size * 8)) - 1; |
99 | bd8d6f7c | Avi Kivity | } |
100 | 661a1799 | Paul Brook | |
101 | bd8d6f7c | Avi Kivity | static void pcnet_ioport_write(void *opaque, target_phys_addr_t addr, |
102 | bd8d6f7c | Avi Kivity | uint64_t data, unsigned size)
|
103 | bd8d6f7c | Avi Kivity | { |
104 | bd8d6f7c | Avi Kivity | PCNetState *d = opaque; |
105 | 661a1799 | Paul Brook | |
106 | 7ba79741 | Jan Kiszka | if (addr < 0x10) { |
107 | 7ba79741 | Jan Kiszka | if (!BCR_DWIO(d) && size == 1) { |
108 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr, data); |
109 | 7ba79741 | Jan Kiszka | } else if (!BCR_DWIO(d) && (addr & 1) == 0 && size == 2) { |
110 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr, data & 0xff);
|
111 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr + 1, data >> 8); |
112 | 7ba79741 | Jan Kiszka | } else if (BCR_DWIO(d) && (addr & 3) == 0 && size == 4) { |
113 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr, data & 0xff);
|
114 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr + 1, (data >> 8) & 0xff); |
115 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr + 2, (data >> 16) & 0xff); |
116 | 7ba79741 | Jan Kiszka | pcnet_aprom_writeb(d, addr + 3, data >> 24); |
117 | 7ba79741 | Jan Kiszka | } |
118 | 7ba79741 | Jan Kiszka | } else {
|
119 | 7ba79741 | Jan Kiszka | if (size == 2) { |
120 | 7ba79741 | Jan Kiszka | pcnet_ioport_writew(d, addr, data); |
121 | 7ba79741 | Jan Kiszka | } else if (size == 4) { |
122 | 7ba79741 | Jan Kiszka | pcnet_ioport_writel(d, addr, data); |
123 | 7ba79741 | Jan Kiszka | } |
124 | bd8d6f7c | Avi Kivity | } |
125 | 661a1799 | Paul Brook | } |
126 | 661a1799 | Paul Brook | |
127 | bd8d6f7c | Avi Kivity | static const MemoryRegionOps pcnet_io_ops = { |
128 | bd8d6f7c | Avi Kivity | .read = pcnet_ioport_read, |
129 | bd8d6f7c | Avi Kivity | .write = pcnet_ioport_write, |
130 | bd8d6f7c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
131 | bd8d6f7c | Avi Kivity | }; |
132 | bd8d6f7c | Avi Kivity | |
133 | 661a1799 | Paul Brook | static void pcnet_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
134 | 661a1799 | Paul Brook | { |
135 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
136 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
137 | 661a1799 | Paul Brook | printf("pcnet_mmio_writeb addr=0x" TARGET_FMT_plx" val=0x%02x\n", addr, |
138 | 661a1799 | Paul Brook | val); |
139 | 661a1799 | Paul Brook | #endif
|
140 | 661a1799 | Paul Brook | if (!(addr & 0x10)) |
141 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr & 0x0f, val);
|
142 | 661a1799 | Paul Brook | } |
143 | 661a1799 | Paul Brook | |
144 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readb(void *opaque, target_phys_addr_t addr) |
145 | 661a1799 | Paul Brook | { |
146 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
147 | 661a1799 | Paul Brook | uint32_t val = -1;
|
148 | 661a1799 | Paul Brook | if (!(addr & 0x10)) |
149 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr & 0x0f);
|
150 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
151 | 661a1799 | Paul Brook | printf("pcnet_mmio_readb addr=0x" TARGET_FMT_plx " val=0x%02x\n", addr, |
152 | 661a1799 | Paul Brook | val & 0xff);
|
153 | 661a1799 | Paul Brook | #endif
|
154 | 661a1799 | Paul Brook | return val;
|
155 | 661a1799 | Paul Brook | } |
156 | 661a1799 | Paul Brook | |
157 | 661a1799 | Paul Brook | static void pcnet_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
158 | 661a1799 | Paul Brook | { |
159 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
160 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
161 | 661a1799 | Paul Brook | printf("pcnet_mmio_writew addr=0x" TARGET_FMT_plx " val=0x%04x\n", addr, |
162 | 661a1799 | Paul Brook | val); |
163 | 661a1799 | Paul Brook | #endif
|
164 | 661a1799 | Paul Brook | if (addr & 0x10) |
165 | 661a1799 | Paul Brook | pcnet_ioport_writew(d, addr & 0x0f, val);
|
166 | 661a1799 | Paul Brook | else {
|
167 | 661a1799 | Paul Brook | addr &= 0x0f;
|
168 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr, val & 0xff);
|
169 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+1, (val & 0xff00) >> 8); |
170 | 661a1799 | Paul Brook | } |
171 | 661a1799 | Paul Brook | } |
172 | 661a1799 | Paul Brook | |
173 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readw(void *opaque, target_phys_addr_t addr) |
174 | 661a1799 | Paul Brook | { |
175 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
176 | 661a1799 | Paul Brook | uint32_t val = -1;
|
177 | 661a1799 | Paul Brook | if (addr & 0x10) |
178 | 661a1799 | Paul Brook | val = pcnet_ioport_readw(d, addr & 0x0f);
|
179 | 661a1799 | Paul Brook | else {
|
180 | 661a1799 | Paul Brook | addr &= 0x0f;
|
181 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr+1);
|
182 | 661a1799 | Paul Brook | val <<= 8;
|
183 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr); |
184 | 661a1799 | Paul Brook | } |
185 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
186 | 661a1799 | Paul Brook | printf("pcnet_mmio_readw addr=0x" TARGET_FMT_plx" val = 0x%04x\n", addr, |
187 | 661a1799 | Paul Brook | val & 0xffff);
|
188 | 661a1799 | Paul Brook | #endif
|
189 | 661a1799 | Paul Brook | return val;
|
190 | 661a1799 | Paul Brook | } |
191 | 661a1799 | Paul Brook | |
192 | 661a1799 | Paul Brook | static void pcnet_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
193 | 661a1799 | Paul Brook | { |
194 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
195 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
196 | 661a1799 | Paul Brook | printf("pcnet_mmio_writel addr=0x" TARGET_FMT_plx" val=0x%08x\n", addr, |
197 | 661a1799 | Paul Brook | val); |
198 | 661a1799 | Paul Brook | #endif
|
199 | 661a1799 | Paul Brook | if (addr & 0x10) |
200 | 661a1799 | Paul Brook | pcnet_ioport_writel(d, addr & 0x0f, val);
|
201 | 661a1799 | Paul Brook | else {
|
202 | 661a1799 | Paul Brook | addr &= 0x0f;
|
203 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr, val & 0xff);
|
204 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+1, (val & 0xff00) >> 8); |
205 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+2, (val & 0xff0000) >> 16); |
206 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+3, (val & 0xff000000) >> 24); |
207 | 661a1799 | Paul Brook | } |
208 | 661a1799 | Paul Brook | } |
209 | 661a1799 | Paul Brook | |
210 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr) |
211 | 661a1799 | Paul Brook | { |
212 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
213 | 661a1799 | Paul Brook | uint32_t val; |
214 | 661a1799 | Paul Brook | if (addr & 0x10) |
215 | 661a1799 | Paul Brook | val = pcnet_ioport_readl(d, addr & 0x0f);
|
216 | 661a1799 | Paul Brook | else {
|
217 | 661a1799 | Paul Brook | addr &= 0x0f;
|
218 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr+3);
|
219 | 661a1799 | Paul Brook | val <<= 8;
|
220 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr+2);
|
221 | 661a1799 | Paul Brook | val <<= 8;
|
222 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr+1);
|
223 | 661a1799 | Paul Brook | val <<= 8;
|
224 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr); |
225 | 661a1799 | Paul Brook | } |
226 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
227 | 661a1799 | Paul Brook | printf("pcnet_mmio_readl addr=0x" TARGET_FMT_plx " val=0x%08x\n", addr, |
228 | 661a1799 | Paul Brook | val); |
229 | 661a1799 | Paul Brook | #endif
|
230 | 661a1799 | Paul Brook | return val;
|
231 | 661a1799 | Paul Brook | } |
232 | 661a1799 | Paul Brook | |
233 | 661a1799 | Paul Brook | static const VMStateDescription vmstate_pci_pcnet = { |
234 | 661a1799 | Paul Brook | .name = "pcnet",
|
235 | 661a1799 | Paul Brook | .version_id = 3,
|
236 | 661a1799 | Paul Brook | .minimum_version_id = 2,
|
237 | 661a1799 | Paul Brook | .minimum_version_id_old = 2,
|
238 | 661a1799 | Paul Brook | .fields = (VMStateField []) { |
239 | 661a1799 | Paul Brook | VMSTATE_PCI_DEVICE(pci_dev, PCIPCNetState), |
240 | 661a1799 | Paul Brook | VMSTATE_STRUCT(state, PCIPCNetState, 0, vmstate_pcnet, PCNetState),
|
241 | 661a1799 | Paul Brook | VMSTATE_END_OF_LIST() |
242 | 661a1799 | Paul Brook | } |
243 | 661a1799 | Paul Brook | }; |
244 | 661a1799 | Paul Brook | |
245 | 661a1799 | Paul Brook | /* PCI interface */
|
246 | 661a1799 | Paul Brook | |
247 | bd8d6f7c | Avi Kivity | static const MemoryRegionOps pcnet_mmio_ops = { |
248 | bd8d6f7c | Avi Kivity | .old_mmio = { |
249 | bd8d6f7c | Avi Kivity | .read = { pcnet_mmio_readb, pcnet_mmio_readw, pcnet_mmio_readl }, |
250 | bd8d6f7c | Avi Kivity | .write = { pcnet_mmio_writeb, pcnet_mmio_writew, pcnet_mmio_writel }, |
251 | bd8d6f7c | Avi Kivity | }, |
252 | bd8d6f7c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
253 | 661a1799 | Paul Brook | }; |
254 | 661a1799 | Paul Brook | |
255 | 661a1799 | Paul Brook | static void pci_physical_memory_write(void *dma_opaque, target_phys_addr_t addr, |
256 | 661a1799 | Paul Brook | uint8_t *buf, int len, int do_bswap) |
257 | 661a1799 | Paul Brook | { |
258 | 14fecf26 | Eduard - Gabriel Munteanu | pci_dma_write(dma_opaque, addr, buf, len); |
259 | 661a1799 | Paul Brook | } |
260 | 661a1799 | Paul Brook | |
261 | 661a1799 | Paul Brook | static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr, |
262 | 661a1799 | Paul Brook | uint8_t *buf, int len, int do_bswap) |
263 | 661a1799 | Paul Brook | { |
264 | 14fecf26 | Eduard - Gabriel Munteanu | pci_dma_read(dma_opaque, addr, buf, len); |
265 | 661a1799 | Paul Brook | } |
266 | 661a1799 | Paul Brook | |
267 | 661a1799 | Paul Brook | static void pci_pcnet_cleanup(VLANClientState *nc) |
268 | 661a1799 | Paul Brook | { |
269 | 661a1799 | Paul Brook | PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque; |
270 | 661a1799 | Paul Brook | |
271 | 661a1799 | Paul Brook | pcnet_common_cleanup(d); |
272 | 661a1799 | Paul Brook | } |
273 | 661a1799 | Paul Brook | |
274 | 661a1799 | Paul Brook | static int pci_pcnet_uninit(PCIDevice *dev) |
275 | 661a1799 | Paul Brook | { |
276 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev); |
277 | 661a1799 | Paul Brook | |
278 | bd8d6f7c | Avi Kivity | memory_region_destroy(&d->state.mmio); |
279 | bd8d6f7c | Avi Kivity | memory_region_destroy(&d->io_bar); |
280 | 661a1799 | Paul Brook | qemu_del_timer(d->state.poll_timer); |
281 | 661a1799 | Paul Brook | qemu_free_timer(d->state.poll_timer); |
282 | 661a1799 | Paul Brook | qemu_del_vlan_client(&d->state.nic->nc); |
283 | 661a1799 | Paul Brook | return 0; |
284 | 661a1799 | Paul Brook | } |
285 | 661a1799 | Paul Brook | |
286 | 661a1799 | Paul Brook | static NetClientInfo net_pci_pcnet_info = {
|
287 | 661a1799 | Paul Brook | .type = NET_CLIENT_TYPE_NIC, |
288 | 661a1799 | Paul Brook | .size = sizeof(NICState),
|
289 | 661a1799 | Paul Brook | .can_receive = pcnet_can_receive, |
290 | 661a1799 | Paul Brook | .receive = pcnet_receive, |
291 | e1c2008a | Jan Kiszka | .link_status_changed = pcnet_set_link_status, |
292 | 661a1799 | Paul Brook | .cleanup = pci_pcnet_cleanup, |
293 | 661a1799 | Paul Brook | }; |
294 | 661a1799 | Paul Brook | |
295 | 661a1799 | Paul Brook | static int pci_pcnet_init(PCIDevice *pci_dev) |
296 | 661a1799 | Paul Brook | { |
297 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev); |
298 | 661a1799 | Paul Brook | PCNetState *s = &d->state; |
299 | 661a1799 | Paul Brook | uint8_t *pci_conf; |
300 | 661a1799 | Paul Brook | |
301 | 661a1799 | Paul Brook | #if 0
|
302 | 661a1799 | Paul Brook | printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n",
|
303 | 661a1799 | Paul Brook | sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD));
|
304 | 661a1799 | Paul Brook | #endif
|
305 | 661a1799 | Paul Brook | |
306 | 661a1799 | Paul Brook | pci_conf = pci_dev->config; |
307 | 661a1799 | Paul Brook | |
308 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_STATUS, |
309 | 661a1799 | Paul Brook | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); |
310 | 661a1799 | Paul Brook | |
311 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, 0x0);
|
312 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, 0x0);
|
313 | 661a1799 | Paul Brook | |
314 | 817e0b6f | Michael S. Tsirkin | pci_conf[PCI_INTERRUPT_PIN] = 1; /* interrupt pin A */ |
315 | 661a1799 | Paul Brook | pci_conf[PCI_MIN_GNT] = 0x06;
|
316 | 661a1799 | Paul Brook | pci_conf[PCI_MAX_LAT] = 0xff;
|
317 | 661a1799 | Paul Brook | |
318 | 661a1799 | Paul Brook | /* Handler for memory-mapped I/O */
|
319 | 145aebec | Hervé Poussineau | memory_region_init_io(&d->state.mmio, &pcnet_mmio_ops, s, "pcnet-mmio",
|
320 | bd8d6f7c | Avi Kivity | PCNET_PNPMMIO_SIZE); |
321 | 661a1799 | Paul Brook | |
322 | 145aebec | Hervé Poussineau | memory_region_init_io(&d->io_bar, &pcnet_io_ops, s, "pcnet-io",
|
323 | bd8d6f7c | Avi Kivity | PCNET_IOPORT_SIZE); |
324 | e824b2cc | Avi Kivity | pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->io_bar);
|
325 | 661a1799 | Paul Brook | |
326 | e824b2cc | Avi Kivity | pci_register_bar(pci_dev, 1, 0, &s->mmio); |
327 | 661a1799 | Paul Brook | |
328 | 661a1799 | Paul Brook | s->irq = pci_dev->irq[0];
|
329 | 661a1799 | Paul Brook | s->phys_mem_read = pci_physical_memory_read; |
330 | 661a1799 | Paul Brook | s->phys_mem_write = pci_physical_memory_write; |
331 | 14fecf26 | Eduard - Gabriel Munteanu | s->dma_opaque = pci_dev; |
332 | 661a1799 | Paul Brook | |
333 | 661a1799 | Paul Brook | return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
|
334 | 661a1799 | Paul Brook | } |
335 | 661a1799 | Paul Brook | |
336 | 661a1799 | Paul Brook | static void pci_reset(DeviceState *dev) |
337 | 661a1799 | Paul Brook | { |
338 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev); |
339 | 661a1799 | Paul Brook | |
340 | 661a1799 | Paul Brook | pcnet_h_reset(&d->state); |
341 | 661a1799 | Paul Brook | } |
342 | 661a1799 | Paul Brook | |
343 | 40021f08 | Anthony Liguori | static Property pcnet_properties[] = {
|
344 | 40021f08 | Anthony Liguori | DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf), |
345 | 40021f08 | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
346 | 40021f08 | Anthony Liguori | }; |
347 | 40021f08 | Anthony Liguori | |
348 | 40021f08 | Anthony Liguori | static void pcnet_class_init(ObjectClass *klass, void *data) |
349 | 40021f08 | Anthony Liguori | { |
350 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
351 | 40021f08 | Anthony Liguori | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
352 | 40021f08 | Anthony Liguori | |
353 | 40021f08 | Anthony Liguori | k->init = pci_pcnet_init; |
354 | 40021f08 | Anthony Liguori | k->exit = pci_pcnet_uninit; |
355 | 9ebe95fb | Gerd Hoffmann | k->romfile = "pxe-pcnet.rom",
|
356 | 40021f08 | Anthony Liguori | k->vendor_id = PCI_VENDOR_ID_AMD; |
357 | 40021f08 | Anthony Liguori | k->device_id = PCI_DEVICE_ID_AMD_LANCE; |
358 | 40021f08 | Anthony Liguori | k->revision = 0x10;
|
359 | 40021f08 | Anthony Liguori | k->class_id = PCI_CLASS_NETWORK_ETHERNET; |
360 | 39bffca2 | Anthony Liguori | dc->reset = pci_reset; |
361 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_pci_pcnet; |
362 | 39bffca2 | Anthony Liguori | dc->props = pcnet_properties; |
363 | 40021f08 | Anthony Liguori | } |
364 | 40021f08 | Anthony Liguori | |
365 | 39bffca2 | Anthony Liguori | static TypeInfo pcnet_info = {
|
366 | 39bffca2 | Anthony Liguori | .name = "pcnet",
|
367 | 39bffca2 | Anthony Liguori | .parent = TYPE_PCI_DEVICE, |
368 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(PCIPCNetState),
|
369 | 39bffca2 | Anthony Liguori | .class_init = pcnet_class_init, |
370 | 661a1799 | Paul Brook | }; |
371 | 661a1799 | Paul Brook | |
372 | 83f7d43a | Andreas Färber | static void pci_pcnet_register_types(void) |
373 | 661a1799 | Paul Brook | { |
374 | 39bffca2 | Anthony Liguori | type_register_static(&pcnet_info); |
375 | 661a1799 | Paul Brook | } |
376 | 661a1799 | Paul Brook | |
377 | 83f7d43a | Andreas Färber | type_init(pci_pcnet_register_types) |