pci: add helper functions to check ranges overlap.
[qemu/aliguori-queue.git] / qemu-config.c
blobd83d2a697c453e562fd110bb69285c623daebaa5
1 #include "qemu-common.h"
2 #include "qemu-option.h"
3 #include "qemu-config.h"
4 #include "sysemu.h"
6 QemuOptsList qemu_drive_opts = {
7 .name = "drive",
8 .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
9 .desc = {
11 .name = "bus",
12 .type = QEMU_OPT_NUMBER,
13 .help = "bus number",
14 },{
15 .name = "unit",
16 .type = QEMU_OPT_NUMBER,
17 .help = "unit number (i.e. lun for scsi)",
18 },{
19 .name = "if",
20 .type = QEMU_OPT_STRING,
21 .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
22 },{
23 .name = "index",
24 .type = QEMU_OPT_NUMBER,
25 },{
26 .name = "cyls",
27 .type = QEMU_OPT_NUMBER,
28 .help = "number of cylinders (ide disk geometry)",
29 },{
30 .name = "heads",
31 .type = QEMU_OPT_NUMBER,
32 .help = "number of heads (ide disk geometry)",
33 },{
34 .name = "secs",
35 .type = QEMU_OPT_NUMBER,
36 .help = "number of sectors (ide disk geometry)",
37 },{
38 .name = "trans",
39 .type = QEMU_OPT_STRING,
40 .help = "chs translation (auto, lba. none)",
41 },{
42 .name = "media",
43 .type = QEMU_OPT_STRING,
44 .help = "media type (disk, cdrom)",
45 },{
46 .name = "snapshot",
47 .type = QEMU_OPT_BOOL,
48 },{
49 .name = "file",
50 .type = QEMU_OPT_STRING,
51 .help = "disk image",
52 },{
53 .name = "cache",
54 .type = QEMU_OPT_STRING,
55 .help = "host cache usage (none, writeback, writethrough)",
56 },{
57 .name = "aio",
58 .type = QEMU_OPT_STRING,
59 .help = "host AIO implementation (threads, native)",
60 },{
61 .name = "format",
62 .type = QEMU_OPT_STRING,
63 .help = "disk format (raw, qcow2, ...)",
64 },{
65 .name = "serial",
66 .type = QEMU_OPT_STRING,
67 },{
68 .name = "werror",
69 .type = QEMU_OPT_STRING,
70 },{
71 .name = "addr",
72 .type = QEMU_OPT_STRING,
73 .help = "pci address (virtio only)",
74 },{
75 .name = "readonly",
76 .type = QEMU_OPT_BOOL,
78 { /* end if list */ }
82 QemuOptsList qemu_chardev_opts = {
83 .name = "chardev",
84 .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
85 .desc = {
87 .name = "backend",
88 .type = QEMU_OPT_STRING,
89 },{
90 .name = "path",
91 .type = QEMU_OPT_STRING,
92 },{
93 .name = "host",
94 .type = QEMU_OPT_STRING,
95 },{
96 .name = "port",
97 .type = QEMU_OPT_STRING,
98 },{
99 .name = "localaddr",
100 .type = QEMU_OPT_STRING,
102 .name = "localport",
103 .type = QEMU_OPT_STRING,
105 .name = "to",
106 .type = QEMU_OPT_NUMBER,
108 .name = "ipv4",
109 .type = QEMU_OPT_BOOL,
111 .name = "ipv6",
112 .type = QEMU_OPT_BOOL,
114 .name = "wait",
115 .type = QEMU_OPT_BOOL,
117 .name = "server",
118 .type = QEMU_OPT_BOOL,
120 .name = "delay",
121 .type = QEMU_OPT_BOOL,
123 .name = "telnet",
124 .type = QEMU_OPT_BOOL,
126 .name = "width",
127 .type = QEMU_OPT_NUMBER,
129 .name = "height",
130 .type = QEMU_OPT_NUMBER,
132 .name = "cols",
133 .type = QEMU_OPT_NUMBER,
135 .name = "rows",
136 .type = QEMU_OPT_NUMBER,
138 .name = "mux",
139 .type = QEMU_OPT_BOOL,
141 .name = "signal",
142 .type = QEMU_OPT_BOOL,
144 { /* end if list */ }
148 QemuOptsList qemu_device_opts = {
149 .name = "device",
150 .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
151 .desc = {
153 * no elements => accept any
154 * sanity checking will happen later
155 * when setting device properties
157 { /* end if list */ }
161 QemuOptsList qemu_netdev_opts = {
162 .name = "netdev",
163 .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
164 .desc = {
166 * no elements => accept any params
167 * validation will happen later
169 { /* end of list */ }
173 QemuOptsList qemu_net_opts = {
174 .name = "net",
175 .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
176 .desc = {
178 * no elements => accept any params
179 * validation will happen later
181 { /* end of list */ }
185 QemuOptsList qemu_rtc_opts = {
186 .name = "rtc",
187 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
188 .desc = {
190 .name = "base",
191 .type = QEMU_OPT_STRING,
193 .name = "clock",
194 .type = QEMU_OPT_STRING,
195 #ifdef TARGET_I386
197 .name = "driftfix",
198 .type = QEMU_OPT_STRING,
199 #endif
201 { /* end if list */ }
205 static QemuOptsList *lists[] = {
206 &qemu_drive_opts,
207 &qemu_chardev_opts,
208 &qemu_device_opts,
209 &qemu_netdev_opts,
210 &qemu_net_opts,
211 &qemu_rtc_opts,
212 NULL,
215 int qemu_set_option(const char *str)
217 char group[64], id[64], arg[64];
218 QemuOpts *opts;
219 int i, rc, offset;
221 rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
222 if (rc < 3 || str[offset] != '=') {
223 qemu_error("can't parse: \"%s\"\n", str);
224 return -1;
227 for (i = 0; lists[i] != NULL; i++) {
228 if (strcmp(lists[i]->name, group) == 0)
229 break;
231 if (lists[i] == NULL) {
232 qemu_error("there is no option group \"%s\"\n", group);
233 return -1;
236 opts = qemu_opts_find(lists[i], id);
237 if (!opts) {
238 qemu_error("there is no %s \"%s\" defined\n",
239 lists[i]->name, id);
240 return -1;
243 if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
244 return -1;
246 return 0;