root / hw / lance.c @ 3e21ffc9
History | View | Annotate | Download (4.2 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 | |
44 | 94e1a912 | Gerd Hoffmann | #include "pcnet.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 | 94e1a912 | Gerd Hoffmann | static void lance_mem_writew(void *opaque, target_phys_addr_t addr, |
59 | 94e1a912 | Gerd Hoffmann | uint32_t val) |
60 | 94e1a912 | Gerd Hoffmann | { |
61 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = opaque; |
62 | 94e1a912 | Gerd Hoffmann | #ifdef PCNET_DEBUG_IO
|
63 | 94e1a912 | Gerd Hoffmann | printf("lance_mem_writew addr=" TARGET_FMT_plx " val=0x%04x\n", addr, |
64 | 94e1a912 | Gerd Hoffmann | val & 0xffff);
|
65 | 94e1a912 | Gerd Hoffmann | #endif
|
66 | 94e1a912 | Gerd Hoffmann | pcnet_ioport_writew(&d->state, addr, val & 0xffff);
|
67 | 94e1a912 | Gerd Hoffmann | } |
68 | 94e1a912 | Gerd Hoffmann | |
69 | 94e1a912 | Gerd Hoffmann | static uint32_t lance_mem_readw(void *opaque, target_phys_addr_t addr) |
70 | 94e1a912 | Gerd Hoffmann | { |
71 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = opaque; |
72 | 94e1a912 | Gerd Hoffmann | uint32_t val; |
73 | 94e1a912 | Gerd Hoffmann | |
74 | 94e1a912 | Gerd Hoffmann | val = pcnet_ioport_readw(&d->state, addr); |
75 | 94e1a912 | Gerd Hoffmann | #ifdef PCNET_DEBUG_IO
|
76 | 94e1a912 | Gerd Hoffmann | printf("lance_mem_readw addr=" TARGET_FMT_plx " val = 0x%04x\n", addr, |
77 | 94e1a912 | Gerd Hoffmann | val & 0xffff);
|
78 | 94e1a912 | Gerd Hoffmann | #endif
|
79 | 94e1a912 | Gerd Hoffmann | |
80 | 94e1a912 | Gerd Hoffmann | return val & 0xffff; |
81 | 94e1a912 | Gerd Hoffmann | } |
82 | 94e1a912 | Gerd Hoffmann | |
83 | 94e1a912 | Gerd Hoffmann | static CPUReadMemoryFunc * const lance_mem_read[3] = { |
84 | 94e1a912 | Gerd Hoffmann | NULL,
|
85 | 94e1a912 | Gerd Hoffmann | lance_mem_readw, |
86 | 94e1a912 | Gerd Hoffmann | NULL,
|
87 | 94e1a912 | Gerd Hoffmann | }; |
88 | 94e1a912 | Gerd Hoffmann | |
89 | 94e1a912 | Gerd Hoffmann | static CPUWriteMemoryFunc * const lance_mem_write[3] = { |
90 | 94e1a912 | Gerd Hoffmann | NULL,
|
91 | 94e1a912 | Gerd Hoffmann | lance_mem_writew, |
92 | 94e1a912 | Gerd Hoffmann | NULL,
|
93 | 94e1a912 | Gerd Hoffmann | }; |
94 | 94e1a912 | Gerd Hoffmann | |
95 | 94e1a912 | Gerd Hoffmann | static void lance_cleanup(VLANClientState *vc) |
96 | 94e1a912 | Gerd Hoffmann | { |
97 | 94e1a912 | Gerd Hoffmann | PCNetState *d = vc->opaque; |
98 | 94e1a912 | Gerd Hoffmann | |
99 | 3d865059 | Juan Quintela | vmstate_unregister(&vmstate_pcnet, d); |
100 | 94e1a912 | Gerd Hoffmann | pcnet_common_cleanup(d); |
101 | 94e1a912 | Gerd Hoffmann | } |
102 | 94e1a912 | Gerd Hoffmann | |
103 | 94e1a912 | Gerd Hoffmann | static int lance_init(SysBusDevice *dev) |
104 | 94e1a912 | Gerd Hoffmann | { |
105 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); |
106 | 94e1a912 | Gerd Hoffmann | PCNetState *s = &d->state; |
107 | 94e1a912 | Gerd Hoffmann | |
108 | 94e1a912 | Gerd Hoffmann | s->mmio_index = |
109 | 94e1a912 | Gerd Hoffmann | cpu_register_io_memory(lance_mem_read, lance_mem_write, d); |
110 | 94e1a912 | Gerd Hoffmann | |
111 | 94e1a912 | Gerd Hoffmann | qdev_init_gpio_in(&dev->qdev, parent_lance_reset, 1);
|
112 | 94e1a912 | Gerd Hoffmann | |
113 | 94e1a912 | Gerd Hoffmann | sysbus_init_mmio(dev, 4, s->mmio_index);
|
114 | 94e1a912 | Gerd Hoffmann | |
115 | 94e1a912 | Gerd Hoffmann | sysbus_init_irq(dev, &s->irq); |
116 | 94e1a912 | Gerd Hoffmann | |
117 | 94e1a912 | Gerd Hoffmann | s->phys_mem_read = ledma_memory_read; |
118 | 94e1a912 | Gerd Hoffmann | s->phys_mem_write = ledma_memory_write; |
119 | 94e1a912 | Gerd Hoffmann | |
120 | 3d865059 | Juan Quintela | vmstate_register(-1, &vmstate_pcnet, d);
|
121 | 94e1a912 | Gerd Hoffmann | return pcnet_common_init(&dev->qdev, s, lance_cleanup);
|
122 | 94e1a912 | Gerd Hoffmann | } |
123 | 94e1a912 | Gerd Hoffmann | |
124 | 94e1a912 | Gerd Hoffmann | static void lance_reset(DeviceState *dev) |
125 | 94e1a912 | Gerd Hoffmann | { |
126 | 94e1a912 | Gerd Hoffmann | SysBusPCNetState *d = DO_UPCAST(SysBusPCNetState, busdev.qdev, dev); |
127 | 94e1a912 | Gerd Hoffmann | |
128 | 94e1a912 | Gerd Hoffmann | pcnet_h_reset(&d->state); |
129 | 94e1a912 | Gerd Hoffmann | } |
130 | 94e1a912 | Gerd Hoffmann | |
131 | 94e1a912 | Gerd Hoffmann | static SysBusDeviceInfo lance_info = {
|
132 | 94e1a912 | Gerd Hoffmann | .init = lance_init, |
133 | 94e1a912 | Gerd Hoffmann | .qdev.name = "lance",
|
134 | 94e1a912 | Gerd Hoffmann | .qdev.size = sizeof(SysBusPCNetState),
|
135 | 94e1a912 | Gerd Hoffmann | .qdev.reset = lance_reset, |
136 | 94e1a912 | Gerd Hoffmann | .qdev.props = (Property[]) { |
137 | 94e1a912 | Gerd Hoffmann | DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
|
138 | 94e1a912 | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf), |
139 | 94e1a912 | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
140 | 94e1a912 | Gerd Hoffmann | } |
141 | 94e1a912 | Gerd Hoffmann | }; |
142 | 94e1a912 | Gerd Hoffmann | |
143 | 94e1a912 | Gerd Hoffmann | static void lance_register_devices(void) |
144 | 94e1a912 | Gerd Hoffmann | { |
145 | 94e1a912 | Gerd Hoffmann | sysbus_register_withprop(&lance_info); |
146 | 94e1a912 | Gerd Hoffmann | } |
147 | 94e1a912 | Gerd Hoffmann | device_init(lance_register_devices) |