root / hw / pcnet-pci.c @ 145aebec
History | View | Annotate | Download (10 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 | 661a1799 | Paul Brook | |
35 | 661a1799 | Paul Brook | #include "pcnet.h" |
36 | 661a1799 | Paul Brook | |
37 | 661a1799 | Paul Brook | //#define PCNET_DEBUG
|
38 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_IO
|
39 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_BCR
|
40 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_CSR
|
41 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_RMD
|
42 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_TMD
|
43 | 661a1799 | Paul Brook | //#define PCNET_DEBUG_MATCH
|
44 | 661a1799 | Paul Brook | |
45 | 661a1799 | Paul Brook | |
46 | 661a1799 | Paul Brook | typedef struct { |
47 | 661a1799 | Paul Brook | PCIDevice pci_dev; |
48 | 661a1799 | Paul Brook | PCNetState state; |
49 | bd8d6f7c | Avi Kivity | MemoryRegion io_bar; |
50 | 661a1799 | Paul Brook | } PCIPCNetState; |
51 | 661a1799 | Paul Brook | |
52 | 661a1799 | Paul Brook | static void pcnet_aprom_writeb(void *opaque, uint32_t addr, uint32_t val) |
53 | 661a1799 | Paul Brook | { |
54 | 661a1799 | Paul Brook | PCNetState *s = opaque; |
55 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG
|
56 | 661a1799 | Paul Brook | printf("pcnet_aprom_writeb addr=0x%08x val=0x%02x\n", addr, val);
|
57 | 661a1799 | Paul Brook | #endif
|
58 | 661a1799 | Paul Brook | /* Check APROMWE bit to enable write access */
|
59 | 661a1799 | Paul Brook | if (pcnet_bcr_readw(s,2) & 0x100) |
60 | 661a1799 | Paul Brook | s->prom[addr & 15] = val;
|
61 | 661a1799 | Paul Brook | } |
62 | 661a1799 | Paul Brook | |
63 | 661a1799 | Paul Brook | static uint32_t pcnet_aprom_readb(void *opaque, uint32_t addr) |
64 | 661a1799 | Paul Brook | { |
65 | 661a1799 | Paul Brook | PCNetState *s = opaque; |
66 | 661a1799 | Paul Brook | uint32_t val = s->prom[addr & 15];
|
67 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG
|
68 | 661a1799 | Paul Brook | printf("pcnet_aprom_readb addr=0x%08x val=0x%02x\n", addr, val);
|
69 | 661a1799 | Paul Brook | #endif
|
70 | 661a1799 | Paul Brook | return val;
|
71 | 661a1799 | Paul Brook | } |
72 | 661a1799 | Paul Brook | |
73 | bd8d6f7c | Avi Kivity | static uint64_t pcnet_ioport_read(void *opaque, target_phys_addr_t addr, |
74 | bd8d6f7c | Avi Kivity | unsigned size)
|
75 | 661a1799 | Paul Brook | { |
76 | bd8d6f7c | Avi Kivity | PCNetState *d = opaque; |
77 | 661a1799 | Paul Brook | |
78 | bd8d6f7c | Avi Kivity | if (addr < 16 && size == 1) { |
79 | bd8d6f7c | Avi Kivity | return pcnet_aprom_readb(d, addr);
|
80 | bd8d6f7c | Avi Kivity | } else if (addr >= 0x10 && addr < 0x20 && size == 2) { |
81 | bd8d6f7c | Avi Kivity | return pcnet_ioport_readw(d, addr);
|
82 | bd8d6f7c | Avi Kivity | } else if (addr >= 0x10 && addr < 0x20 && size == 4) { |
83 | bd8d6f7c | Avi Kivity | return pcnet_ioport_readl(d, addr);
|
84 | bd8d6f7c | Avi Kivity | } |
85 | bd8d6f7c | Avi Kivity | return ((uint64_t)1 << (size * 8)) - 1; |
86 | bd8d6f7c | Avi Kivity | } |
87 | 661a1799 | Paul Brook | |
88 | bd8d6f7c | Avi Kivity | static void pcnet_ioport_write(void *opaque, target_phys_addr_t addr, |
89 | bd8d6f7c | Avi Kivity | uint64_t data, unsigned size)
|
90 | bd8d6f7c | Avi Kivity | { |
91 | bd8d6f7c | Avi Kivity | PCNetState *d = opaque; |
92 | 661a1799 | Paul Brook | |
93 | bd8d6f7c | Avi Kivity | if (addr < 16 && size == 1) { |
94 | bd8d6f7c | Avi Kivity | return pcnet_aprom_writeb(d, addr, data);
|
95 | bd8d6f7c | Avi Kivity | } else if (addr >= 0x10 && addr < 0x20 && size == 2) { |
96 | bd8d6f7c | Avi Kivity | return pcnet_ioport_writew(d, addr, data);
|
97 | bd8d6f7c | Avi Kivity | } else if (addr >= 0x10 && addr < 0x20 && size == 4) { |
98 | bd8d6f7c | Avi Kivity | return pcnet_ioport_writel(d, addr, data);
|
99 | bd8d6f7c | Avi Kivity | } |
100 | 661a1799 | Paul Brook | } |
101 | 661a1799 | Paul Brook | |
102 | bd8d6f7c | Avi Kivity | static const MemoryRegionOps pcnet_io_ops = { |
103 | bd8d6f7c | Avi Kivity | .read = pcnet_ioport_read, |
104 | bd8d6f7c | Avi Kivity | .write = pcnet_ioport_write, |
105 | bd8d6f7c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
106 | bd8d6f7c | Avi Kivity | }; |
107 | bd8d6f7c | Avi Kivity | |
108 | 661a1799 | Paul Brook | static void pcnet_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
109 | 661a1799 | Paul Brook | { |
110 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
111 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
112 | 661a1799 | Paul Brook | printf("pcnet_mmio_writeb addr=0x" TARGET_FMT_plx" val=0x%02x\n", addr, |
113 | 661a1799 | Paul Brook | val); |
114 | 661a1799 | Paul Brook | #endif
|
115 | 661a1799 | Paul Brook | if (!(addr & 0x10)) |
116 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr & 0x0f, val);
|
117 | 661a1799 | Paul Brook | } |
118 | 661a1799 | Paul Brook | |
119 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readb(void *opaque, target_phys_addr_t addr) |
120 | 661a1799 | Paul Brook | { |
121 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
122 | 661a1799 | Paul Brook | uint32_t val = -1;
|
123 | 661a1799 | Paul Brook | if (!(addr & 0x10)) |
124 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr & 0x0f);
|
125 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
126 | 661a1799 | Paul Brook | printf("pcnet_mmio_readb addr=0x" TARGET_FMT_plx " val=0x%02x\n", addr, |
127 | 661a1799 | Paul Brook | val & 0xff);
|
128 | 661a1799 | Paul Brook | #endif
|
129 | 661a1799 | Paul Brook | return val;
|
130 | 661a1799 | Paul Brook | } |
131 | 661a1799 | Paul Brook | |
132 | 661a1799 | Paul Brook | static void pcnet_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
133 | 661a1799 | Paul Brook | { |
134 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
135 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
136 | 661a1799 | Paul Brook | printf("pcnet_mmio_writew addr=0x" TARGET_FMT_plx " val=0x%04x\n", addr, |
137 | 661a1799 | Paul Brook | val); |
138 | 661a1799 | Paul Brook | #endif
|
139 | 661a1799 | Paul Brook | if (addr & 0x10) |
140 | 661a1799 | Paul Brook | pcnet_ioport_writew(d, addr & 0x0f, val);
|
141 | 661a1799 | Paul Brook | else {
|
142 | 661a1799 | Paul Brook | addr &= 0x0f;
|
143 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr, val & 0xff);
|
144 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+1, (val & 0xff00) >> 8); |
145 | 661a1799 | Paul Brook | } |
146 | 661a1799 | Paul Brook | } |
147 | 661a1799 | Paul Brook | |
148 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readw(void *opaque, target_phys_addr_t addr) |
149 | 661a1799 | Paul Brook | { |
150 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
151 | 661a1799 | Paul Brook | uint32_t val = -1;
|
152 | 661a1799 | Paul Brook | if (addr & 0x10) |
153 | 661a1799 | Paul Brook | val = pcnet_ioport_readw(d, addr & 0x0f);
|
154 | 661a1799 | Paul Brook | else {
|
155 | 661a1799 | Paul Brook | addr &= 0x0f;
|
156 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr+1);
|
157 | 661a1799 | Paul Brook | val <<= 8;
|
158 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr); |
159 | 661a1799 | Paul Brook | } |
160 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
161 | 661a1799 | Paul Brook | printf("pcnet_mmio_readw addr=0x" TARGET_FMT_plx" val = 0x%04x\n", addr, |
162 | 661a1799 | Paul Brook | val & 0xffff);
|
163 | 661a1799 | Paul Brook | #endif
|
164 | 661a1799 | Paul Brook | return val;
|
165 | 661a1799 | Paul Brook | } |
166 | 661a1799 | Paul Brook | |
167 | 661a1799 | Paul Brook | static void pcnet_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
168 | 661a1799 | Paul Brook | { |
169 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
170 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
171 | 661a1799 | Paul Brook | printf("pcnet_mmio_writel addr=0x" TARGET_FMT_plx" val=0x%08x\n", addr, |
172 | 661a1799 | Paul Brook | val); |
173 | 661a1799 | Paul Brook | #endif
|
174 | 661a1799 | Paul Brook | if (addr & 0x10) |
175 | 661a1799 | Paul Brook | pcnet_ioport_writel(d, addr & 0x0f, val);
|
176 | 661a1799 | Paul Brook | else {
|
177 | 661a1799 | Paul Brook | addr &= 0x0f;
|
178 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr, val & 0xff);
|
179 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+1, (val & 0xff00) >> 8); |
180 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+2, (val & 0xff0000) >> 16); |
181 | 661a1799 | Paul Brook | pcnet_aprom_writeb(d, addr+3, (val & 0xff000000) >> 24); |
182 | 661a1799 | Paul Brook | } |
183 | 661a1799 | Paul Brook | } |
184 | 661a1799 | Paul Brook | |
185 | 661a1799 | Paul Brook | static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr) |
186 | 661a1799 | Paul Brook | { |
187 | 661a1799 | Paul Brook | PCNetState *d = opaque; |
188 | 661a1799 | Paul Brook | uint32_t val; |
189 | 661a1799 | Paul Brook | if (addr & 0x10) |
190 | 661a1799 | Paul Brook | val = pcnet_ioport_readl(d, addr & 0x0f);
|
191 | 661a1799 | Paul Brook | else {
|
192 | 661a1799 | Paul Brook | addr &= 0x0f;
|
193 | 661a1799 | Paul Brook | val = pcnet_aprom_readb(d, addr+3);
|
194 | 661a1799 | Paul Brook | val <<= 8;
|
195 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr+2);
|
196 | 661a1799 | Paul Brook | val <<= 8;
|
197 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr+1);
|
198 | 661a1799 | Paul Brook | val <<= 8;
|
199 | 661a1799 | Paul Brook | val |= pcnet_aprom_readb(d, addr); |
200 | 661a1799 | Paul Brook | } |
201 | 661a1799 | Paul Brook | #ifdef PCNET_DEBUG_IO
|
202 | 661a1799 | Paul Brook | printf("pcnet_mmio_readl addr=0x" TARGET_FMT_plx " val=0x%08x\n", addr, |
203 | 661a1799 | Paul Brook | val); |
204 | 661a1799 | Paul Brook | #endif
|
205 | 661a1799 | Paul Brook | return val;
|
206 | 661a1799 | Paul Brook | } |
207 | 661a1799 | Paul Brook | |
208 | 661a1799 | Paul Brook | static const VMStateDescription vmstate_pci_pcnet = { |
209 | 661a1799 | Paul Brook | .name = "pcnet",
|
210 | 661a1799 | Paul Brook | .version_id = 3,
|
211 | 661a1799 | Paul Brook | .minimum_version_id = 2,
|
212 | 661a1799 | Paul Brook | .minimum_version_id_old = 2,
|
213 | 661a1799 | Paul Brook | .fields = (VMStateField []) { |
214 | 661a1799 | Paul Brook | VMSTATE_PCI_DEVICE(pci_dev, PCIPCNetState), |
215 | 661a1799 | Paul Brook | VMSTATE_STRUCT(state, PCIPCNetState, 0, vmstate_pcnet, PCNetState),
|
216 | 661a1799 | Paul Brook | VMSTATE_END_OF_LIST() |
217 | 661a1799 | Paul Brook | } |
218 | 661a1799 | Paul Brook | }; |
219 | 661a1799 | Paul Brook | |
220 | 661a1799 | Paul Brook | /* PCI interface */
|
221 | 661a1799 | Paul Brook | |
222 | bd8d6f7c | Avi Kivity | static const MemoryRegionOps pcnet_mmio_ops = { |
223 | bd8d6f7c | Avi Kivity | .old_mmio = { |
224 | bd8d6f7c | Avi Kivity | .read = { pcnet_mmio_readb, pcnet_mmio_readw, pcnet_mmio_readl }, |
225 | bd8d6f7c | Avi Kivity | .write = { pcnet_mmio_writeb, pcnet_mmio_writew, pcnet_mmio_writel }, |
226 | bd8d6f7c | Avi Kivity | }, |
227 | bd8d6f7c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
228 | 661a1799 | Paul Brook | }; |
229 | 661a1799 | Paul Brook | |
230 | 661a1799 | Paul Brook | static void pci_physical_memory_write(void *dma_opaque, target_phys_addr_t addr, |
231 | 661a1799 | Paul Brook | uint8_t *buf, int len, int do_bswap) |
232 | 661a1799 | Paul Brook | { |
233 | 661a1799 | Paul Brook | cpu_physical_memory_write(addr, buf, len); |
234 | 661a1799 | Paul Brook | } |
235 | 661a1799 | Paul Brook | |
236 | 661a1799 | Paul Brook | static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr, |
237 | 661a1799 | Paul Brook | uint8_t *buf, int len, int do_bswap) |
238 | 661a1799 | Paul Brook | { |
239 | 661a1799 | Paul Brook | cpu_physical_memory_read(addr, buf, len); |
240 | 661a1799 | Paul Brook | } |
241 | 661a1799 | Paul Brook | |
242 | 661a1799 | Paul Brook | static void pci_pcnet_cleanup(VLANClientState *nc) |
243 | 661a1799 | Paul Brook | { |
244 | 661a1799 | Paul Brook | PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque; |
245 | 661a1799 | Paul Brook | |
246 | 661a1799 | Paul Brook | pcnet_common_cleanup(d); |
247 | 661a1799 | Paul Brook | } |
248 | 661a1799 | Paul Brook | |
249 | 661a1799 | Paul Brook | static int pci_pcnet_uninit(PCIDevice *dev) |
250 | 661a1799 | Paul Brook | { |
251 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev); |
252 | 661a1799 | Paul Brook | |
253 | bd8d6f7c | Avi Kivity | memory_region_destroy(&d->state.mmio); |
254 | bd8d6f7c | Avi Kivity | memory_region_destroy(&d->io_bar); |
255 | 661a1799 | Paul Brook | qemu_del_timer(d->state.poll_timer); |
256 | 661a1799 | Paul Brook | qemu_free_timer(d->state.poll_timer); |
257 | 661a1799 | Paul Brook | qemu_del_vlan_client(&d->state.nic->nc); |
258 | 661a1799 | Paul Brook | return 0; |
259 | 661a1799 | Paul Brook | } |
260 | 661a1799 | Paul Brook | |
261 | 661a1799 | Paul Brook | static NetClientInfo net_pci_pcnet_info = {
|
262 | 661a1799 | Paul Brook | .type = NET_CLIENT_TYPE_NIC, |
263 | 661a1799 | Paul Brook | .size = sizeof(NICState),
|
264 | 661a1799 | Paul Brook | .can_receive = pcnet_can_receive, |
265 | 661a1799 | Paul Brook | .receive = pcnet_receive, |
266 | 661a1799 | Paul Brook | .cleanup = pci_pcnet_cleanup, |
267 | 661a1799 | Paul Brook | }; |
268 | 661a1799 | Paul Brook | |
269 | 661a1799 | Paul Brook | static int pci_pcnet_init(PCIDevice *pci_dev) |
270 | 661a1799 | Paul Brook | { |
271 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev); |
272 | 661a1799 | Paul Brook | PCNetState *s = &d->state; |
273 | 661a1799 | Paul Brook | uint8_t *pci_conf; |
274 | 661a1799 | Paul Brook | |
275 | 661a1799 | Paul Brook | #if 0
|
276 | 661a1799 | Paul Brook | printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n",
|
277 | 661a1799 | Paul Brook | sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD));
|
278 | 661a1799 | Paul Brook | #endif
|
279 | 661a1799 | Paul Brook | |
280 | 661a1799 | Paul Brook | pci_conf = pci_dev->config; |
281 | 661a1799 | Paul Brook | |
282 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_STATUS, |
283 | 661a1799 | Paul Brook | PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM); |
284 | 661a1799 | Paul Brook | |
285 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, 0x0);
|
286 | 661a1799 | Paul Brook | pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, 0x0);
|
287 | 661a1799 | Paul Brook | |
288 | 661a1799 | Paul Brook | pci_conf[PCI_INTERRUPT_PIN] = 1; // interrupt pin 0 |
289 | 661a1799 | Paul Brook | pci_conf[PCI_MIN_GNT] = 0x06;
|
290 | 661a1799 | Paul Brook | pci_conf[PCI_MAX_LAT] = 0xff;
|
291 | 661a1799 | Paul Brook | |
292 | 661a1799 | Paul Brook | /* Handler for memory-mapped I/O */
|
293 | 145aebec | Hervé Poussineau | memory_region_init_io(&d->state.mmio, &pcnet_mmio_ops, s, "pcnet-mmio",
|
294 | bd8d6f7c | Avi Kivity | PCNET_PNPMMIO_SIZE); |
295 | 661a1799 | Paul Brook | |
296 | 145aebec | Hervé Poussineau | memory_region_init_io(&d->io_bar, &pcnet_io_ops, s, "pcnet-io",
|
297 | bd8d6f7c | Avi Kivity | PCNET_IOPORT_SIZE); |
298 | e824b2cc | Avi Kivity | pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->io_bar);
|
299 | 661a1799 | Paul Brook | |
300 | e824b2cc | Avi Kivity | pci_register_bar(pci_dev, 1, 0, &s->mmio); |
301 | 661a1799 | Paul Brook | |
302 | 661a1799 | Paul Brook | s->irq = pci_dev->irq[0];
|
303 | 661a1799 | Paul Brook | s->phys_mem_read = pci_physical_memory_read; |
304 | 661a1799 | Paul Brook | s->phys_mem_write = pci_physical_memory_write; |
305 | 661a1799 | Paul Brook | |
306 | 661a1799 | Paul Brook | if (!pci_dev->qdev.hotplugged) {
|
307 | 661a1799 | Paul Brook | static int loaded = 0; |
308 | 661a1799 | Paul Brook | if (!loaded) {
|
309 | 5ee8ad71 | Alex Williamson | rom_add_option("pxe-pcnet.rom", -1); |
310 | 661a1799 | Paul Brook | loaded = 1;
|
311 | 661a1799 | Paul Brook | } |
312 | 661a1799 | Paul Brook | } |
313 | 661a1799 | Paul Brook | |
314 | 661a1799 | Paul Brook | return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
|
315 | 661a1799 | Paul Brook | } |
316 | 661a1799 | Paul Brook | |
317 | 661a1799 | Paul Brook | static void pci_reset(DeviceState *dev) |
318 | 661a1799 | Paul Brook | { |
319 | 661a1799 | Paul Brook | PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev); |
320 | 661a1799 | Paul Brook | |
321 | 661a1799 | Paul Brook | pcnet_h_reset(&d->state); |
322 | 661a1799 | Paul Brook | } |
323 | 661a1799 | Paul Brook | |
324 | 661a1799 | Paul Brook | static PCIDeviceInfo pcnet_info = {
|
325 | 661a1799 | Paul Brook | .qdev.name = "pcnet",
|
326 | 661a1799 | Paul Brook | .qdev.size = sizeof(PCIPCNetState),
|
327 | 661a1799 | Paul Brook | .qdev.reset = pci_reset, |
328 | 661a1799 | Paul Brook | .qdev.vmsd = &vmstate_pci_pcnet, |
329 | 661a1799 | Paul Brook | .init = pci_pcnet_init, |
330 | 661a1799 | Paul Brook | .exit = pci_pcnet_uninit, |
331 | d7dccd11 | Isaku Yamahata | .vendor_id = PCI_VENDOR_ID_AMD, |
332 | d7dccd11 | Isaku Yamahata | .device_id = PCI_DEVICE_ID_AMD_LANCE, |
333 | d7dccd11 | Isaku Yamahata | .revision = 0x10,
|
334 | d7dccd11 | Isaku Yamahata | .class_id = PCI_CLASS_NETWORK_ETHERNET, |
335 | 661a1799 | Paul Brook | .qdev.props = (Property[]) { |
336 | 661a1799 | Paul Brook | DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf), |
337 | 661a1799 | Paul Brook | DEFINE_PROP_END_OF_LIST(), |
338 | 661a1799 | Paul Brook | } |
339 | 661a1799 | Paul Brook | }; |
340 | 661a1799 | Paul Brook | |
341 | 661a1799 | Paul Brook | static void pci_pcnet_register_devices(void) |
342 | 661a1799 | Paul Brook | { |
343 | 661a1799 | Paul Brook | pci_qdev_register(&pcnet_info); |
344 | 661a1799 | Paul Brook | } |
345 | 661a1799 | Paul Brook | |
346 | 661a1799 | Paul Brook | device_init(pci_pcnet_register_devices) |