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