Deleted Added
sdiff udiff text old ( 241470 ) new ( 252707 )
full compact
1/*-
2 * Copyright (c) 2011, Bryan Venteicher <bryanv@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.

--- 9 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/virtio/virtio.c 252707 2013-07-04 17:57:26Z bryanv $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/module.h>
35#include <sys/sbuf.h>
36
37#include <machine/bus.h>
38#include <machine/resource.h>
39#include <sys/bus.h>
40#include <sys/rman.h>
41
42#include <dev/virtio/virtio.h>
43#include <dev/virtio/virtqueue.h>
44
45#include "virtio_bus_if.h"
46
47static int virtio_modevent(module_t, int, void *);
48static const char *virtio_feature_name(uint64_t, struct virtio_feature_desc *);
49
50static struct virtio_ident {
51 uint16_t devid;
52 const char *name;
53} virtio_ident_table[] = {
54 { VIRTIO_ID_NETWORK, "Network" },
55 { VIRTIO_ID_BLOCK, "Block" },
56 { VIRTIO_ID_CONSOLE, "Console" },
57 { VIRTIO_ID_ENTROPY, "Entropy" },
58 { VIRTIO_ID_BALLOON, "Balloon" },
59 { VIRTIO_ID_IOMEMORY, "IOMemory" },
60 { VIRTIO_ID_SCSI, "SCSI" },

--- 20 unchanged lines hidden (view full) ---

81 for (ident = virtio_ident_table; ident->name != NULL; ident++) {
82 if (ident->devid == devid)
83 return (ident->name);
84 }
85
86 return (NULL);
87}
88
89static const char *
90virtio_feature_name(uint64_t val, struct virtio_feature_desc *desc)
91{
92 int i, j;
93 struct virtio_feature_desc *descs[2] = { desc,
94 virtio_common_feature_desc };
95
96 for (i = 0; i < 2; i++) {
97 if (descs[i] == NULL)
98 continue;
99
100 for (j = 0; descs[i][j].vfd_val != 0; j++) {
101 if (val == descs[i][j].vfd_val)
102 return (descs[i][j].vfd_str);
103 }
104 }
105
106 return (NULL);
107}
108
109void
110virtio_describe(device_t dev, const char *msg,
111 uint64_t features, struct virtio_feature_desc *desc)
112{
113 struct sbuf sb;
114 uint64_t val;
115 char *buf;
116 const char *name;
117 int n;
118
119 if ((buf = malloc(512, M_TEMP, M_NOWAIT)) == NULL) {
120 device_printf(dev, "%s features: %#jx\n", msg, (uintmax_t) features);
121 return;
122 }
123
124 sbuf_new(&sb, buf, 512, SBUF_FIXEDLEN);
125 sbuf_printf(&sb, "%s features: %#jx", msg, (uintmax_t) features);
126
127 for (n = 0, val = 1ULL << 63; val != 0; val >>= 1) {
128 /*
129 * BAD_FEATURE is used to detect broken Linux clients
130 * and therefore is not applicable to FreeBSD.
131 */
132 if (((features & val) == 0) || val == VIRTIO_F_BAD_FEATURE)
133 continue;
134
135 if (n++ == 0)
136 sbuf_cat(&sb, " <");
137 else
138 sbuf_cat(&sb, ",");
139
140 name = virtio_feature_name(val, desc);
141 if (name == NULL)
142 sbuf_printf(&sb, "%#jx", (uintmax_t) val);
143 else
144 sbuf_cat(&sb, name);
145 }
146
147 if (n > 0)
148 sbuf_cat(&sb, ">");
149
150#if __FreeBSD_version < 900020
151 sbuf_finish(&sb);
152 if (sbuf_overflowed(&sb) == 0)
153#else
154 if (sbuf_finish(&sb) == 0)
155#endif
156 device_printf(dev, "%s\n", sbuf_data(&sb));
157
158 sbuf_delete(&sb);
159 free(buf, M_TEMP);
160}
161
162/*
163 * VirtIO bus method wrappers.
164 */
165
166void
167virtio_read_ivar(device_t dev, int ivar, uintptr_t *val)
168{
169

--- 76 unchanged lines hidden (view full) ---

246 offset, dst, len);
247}
248
249static int
250virtio_modevent(module_t mod, int type, void *unused)
251{
252 int error;
253
254 switch (type) {
255 case MOD_LOAD:
256 case MOD_QUIESCE:
257 case MOD_UNLOAD:
258 case MOD_SHUTDOWN:
259 error = 0;
260 break;
261 default:
262 error = EOPNOTSUPP;
263 break;
264 }
265
266 return (error);
267}
268
269static moduledata_t virtio_mod = {
270 "virtio",
271 virtio_modevent,
272 0
273};
274
275DECLARE_MODULE(virtio, virtio_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
276MODULE_VERSION(virtio, 1);