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.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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 #include "openamp/virtio.h"
28 static const char *virtio_feature_name(unsigned long feature,
29 struct virtio_feature_desc *);
31 //TODO : This structure may change depending on the types of devices we support.
32 static struct virtio_ident {
33 unsigned short devid;
34 const char *name;
35 } virtio_ident_table[] = {
36 {
37 VIRTIO_ID_NETWORK, "Network"}, {
38 VIRTIO_ID_BLOCK, "Block"}, {
39 VIRTIO_ID_CONSOLE, "Console"}, {
40 VIRTIO_ID_ENTROPY, "Entropy"}, {
41 VIRTIO_ID_BALLOON, "Balloon"}, {
42 VIRTIO_ID_IOMEMORY, "IOMemory"}, {
43 VIRTIO_ID_SCSI, "SCSI"}, {
44 VIRTIO_ID_9P, "9P Transport"}, {
45 0, NULL}
46 };
48 /* Device independent features. */
49 static struct virtio_feature_desc virtio_common_feature_desc[] = {
50 {VIRTIO_F_NOTIFY_ON_EMPTY, "NotifyOnEmpty"},
51 {VIRTIO_RING_F_INDIRECT_DESC, "RingIndirect"},
52 {VIRTIO_RING_F_EVENT_IDX, "EventIdx"},
53 {VIRTIO_F_BAD_FEATURE, "BadFeature"},
55 {0, NULL}
56 };
58 const char *virtio_dev_name(unsigned short devid)
59 {
60 struct virtio_ident *ident;
62 for (ident = virtio_ident_table; ident->name != NULL; ident++) {
63 if (ident->devid == devid)
64 return (ident->name);
65 }
67 return (NULL);
68 }
70 static const char *virtio_feature_name(unsigned long val,
71 struct virtio_feature_desc *desc)
72 {
73 int i, j;
74 struct virtio_feature_desc *descs[2] = { desc,
75 virtio_common_feature_desc
76 };
78 for (i = 0; i < 2; i++) {
79 if (descs[i] == NULL)
80 continue;
82 for (j = 0; descs[i][j].vfd_val != 0; j++) {
83 if (val == descs[i][j].vfd_val)
84 return (descs[i][j].vfd_str);
85 }
86 }
88 return (NULL);
89 }
91 void virtio_describe(struct virtio_device *dev, const char *msg,
92 uint32_t features, struct virtio_feature_desc *desc)
93 {
94 // TODO: Not used currently - keeping it for future use
95 virtio_feature_name(0, desc);
96 }