1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#include "qemu/osdep.h"
39#include "hw/sysbus.h"
40#include "net/net.h"
41#include "qemu/timer.h"
42#include "qemu/sockets.h"
43#include "hw/sparc/sun4m.h"
44#include "pcnet.h"
45#include "trace.h"
46#include "sysemu/sysemu.h"
47
48#define TYPE_LANCE "lance"
49#define SYSBUS_PCNET(obj) \
50 OBJECT_CHECK(SysBusPCNetState, (obj), TYPE_LANCE)
51
52typedef struct {
53 SysBusDevice parent_obj;
54
55 PCNetState state;
56} SysBusPCNetState;
57
58static void parent_lance_reset(void *opaque, int irq, int level)
59{
60 SysBusPCNetState *d = opaque;
61 if (level)
62 pcnet_h_reset(&d->state);
63}
64
65static void lance_mem_write(void *opaque, hwaddr addr,
66 uint64_t val, unsigned size)
67{
68 SysBusPCNetState *d = opaque;
69
70 trace_lance_mem_writew(addr, val & 0xffff);
71 pcnet_ioport_writew(&d->state, addr, val & 0xffff);
72}
73
74static uint64_t lance_mem_read(void *opaque, hwaddr addr,
75 unsigned size)
76{
77 SysBusPCNetState *d = opaque;
78 uint32_t val;
79
80 val = pcnet_ioport_readw(&d->state, addr);
81 trace_lance_mem_readw(addr, val & 0xffff);
82 return val & 0xffff;
83}
84
85static const MemoryRegionOps lance_mem_ops = {
86 .read = lance_mem_read,
87 .write = lance_mem_write,
88 .endianness = DEVICE_NATIVE_ENDIAN,
89 .valid = {
90 .min_access_size = 2,
91 .max_access_size = 2,
92 },
93};
94
95static NetClientInfo net_lance_info = {
96 .type = NET_CLIENT_DRIVER_NIC,
97 .size = sizeof(NICState),
98 .receive = pcnet_receive,
99 .link_status_changed = pcnet_set_link_status,
100};
101
102static const VMStateDescription vmstate_lance = {
103 .name = "pcnet",
104 .version_id = 3,
105 .minimum_version_id = 2,
106 .fields = (VMStateField[]) {
107 VMSTATE_STRUCT(state, SysBusPCNetState, 0, vmstate_pcnet, PCNetState),
108 VMSTATE_END_OF_LIST()
109 }
110};
111
112static int lance_init(SysBusDevice *sbd)
113{
114 DeviceState *dev = DEVICE(sbd);
115 SysBusPCNetState *d = SYSBUS_PCNET(dev);
116 PCNetState *s = &d->state;
117
118 memory_region_init_io(&s->mmio, OBJECT(d), &lance_mem_ops, d,
119 "lance-mmio", 4);
120
121 qdev_init_gpio_in(dev, parent_lance_reset, 1);
122
123 sysbus_init_mmio(sbd, &s->mmio);
124
125 sysbus_init_irq(sbd, &s->irq);
126
127 s->phys_mem_read = ledma_memory_read;
128 s->phys_mem_write = ledma_memory_write;
129 pcnet_common_init(dev, s, &net_lance_info);
130 return 0;
131}
132
133static void lance_reset(DeviceState *dev)
134{
135 SysBusPCNetState *d = SYSBUS_PCNET(dev);
136
137 pcnet_h_reset(&d->state);
138}
139
140static void lance_instance_init(Object *obj)
141{
142 SysBusPCNetState *d = SYSBUS_PCNET(obj);
143 PCNetState *s = &d->state;
144
145 device_add_bootindex_property(obj, &s->conf.bootindex,
146 "bootindex", "/ethernet-phy@0",
147 DEVICE(obj), NULL);
148}
149
150static Property lance_properties[] = {
151 DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
152 DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf),
153 DEFINE_PROP_END_OF_LIST(),
154};
155
156static void lance_class_init(ObjectClass *klass, void *data)
157{
158 DeviceClass *dc = DEVICE_CLASS(klass);
159 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
160
161 k->init = lance_init;
162 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
163 dc->fw_name = "ethernet";
164 dc->reset = lance_reset;
165 dc->vmsd = &vmstate_lance;
166 dc->props = lance_properties;
167
168 dc->cannot_instantiate_with_device_add_yet = true;
169}
170
171static const TypeInfo lance_info = {
172 .name = TYPE_LANCE,
173 .parent = TYPE_SYS_BUS_DEVICE,
174 .instance_size = sizeof(SysBusPCNetState),
175 .class_init = lance_class_init,
176 .instance_init = lance_instance_init,
177};
178
179static void lance_register_types(void)
180{
181 type_register_static(&lance_info);
182}
183
184type_init(lance_register_types)
185