blob: ccba1fd4a4a15f7e729d795e222a576d3283c696 [file] [log] [blame]
aurel32f652e6a2008-12-16 10:43:48 +00001/*
2 * Functions to help device tree manipulation using libfdt.
3 * It also provides functions to read entries from device tree proc
4 * interface.
5 *
6 * Copyright 2008 IBM Corporation.
7 * Authors: Jerone Young <jyoung5@us.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
9 *
10 * This work is licensed under the GNU GPL license version 2 or later.
11 *
12 */
13
Peter Maydelld38ea872016-01-29 17:50:05 +000014#include "qemu/osdep.h"
aurel32f652e6a2008-12-16 10:43:48 +000015
Eric Auger60e43e92016-02-19 09:42:29 -070016#ifdef CONFIG_LINUX
17#include <dirent.h>
18#endif
19
Markus Armbrusterda34e652016-03-14 09:01:28 +010020#include "qapi/error.h"
aurel32f652e6a2008-12-16 10:43:48 +000021#include "qemu-common.h"
Li Liudb013f82014-08-26 14:38:02 +080022#include "qemu/error-report.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010023#include "sysemu/device_tree.h"
Markus Armbruster2ff3de62013-07-04 15:09:22 +020024#include "sysemu/sysemu.h"
Blue Swirl39b7f202009-09-22 17:51:36 +000025#include "hw/loader.h"
Marcel Apfelbaum6cabe7f2015-02-04 17:43:53 +020026#include "hw/boards.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010027#include "qemu/config-file.h"
aurel32f652e6a2008-12-16 10:43:48 +000028
29#include <libfdt.h>
30
Alexander Grafce362522012-05-17 15:33:54 +020031#define FDT_MAX_SIZE 0x10000
32
33void *create_device_tree(int *sizep)
34{
35 void *fdt;
36 int ret;
37
38 *sizep = FDT_MAX_SIZE;
39 fdt = g_malloc0(FDT_MAX_SIZE);
40 ret = fdt_create(fdt, FDT_MAX_SIZE);
41 if (ret < 0) {
42 goto fail;
43 }
Peter Maydellef6de702013-11-22 17:17:09 +000044 ret = fdt_finish_reservemap(fdt);
45 if (ret < 0) {
46 goto fail;
47 }
Alexander Grafce362522012-05-17 15:33:54 +020048 ret = fdt_begin_node(fdt, "");
49 if (ret < 0) {
50 goto fail;
51 }
52 ret = fdt_end_node(fdt);
53 if (ret < 0) {
54 goto fail;
55 }
56 ret = fdt_finish(fdt);
57 if (ret < 0) {
58 goto fail;
59 }
60 ret = fdt_open_into(fdt, fdt, *sizep);
61 if (ret) {
Li Liu508e2212014-08-26 14:38:03 +080062 error_report("Unable to copy device tree in memory");
Alexander Grafce362522012-05-17 15:33:54 +020063 exit(1);
64 }
65
66 return fdt;
67fail:
Li Liu508e2212014-08-26 14:38:03 +080068 error_report("%s Couldn't create dt: %s", __func__, fdt_strerror(ret));
Alexander Grafce362522012-05-17 15:33:54 +020069 exit(1);
70}
71
pbrook7ec632b2009-04-10 16:23:59 +000072void *load_device_tree(const char *filename_path, int *sizep)
aurel32f652e6a2008-12-16 10:43:48 +000073{
pbrook7ec632b2009-04-10 16:23:59 +000074 int dt_size;
aurel32f652e6a2008-12-16 10:43:48 +000075 int dt_file_load_size;
aurel32f652e6a2008-12-16 10:43:48 +000076 int ret;
pbrook7ec632b2009-04-10 16:23:59 +000077 void *fdt = NULL;
aurel32f652e6a2008-12-16 10:43:48 +000078
pbrook7ec632b2009-04-10 16:23:59 +000079 *sizep = 0;
80 dt_size = get_image_size(filename_path);
81 if (dt_size < 0) {
Li Liudb013f82014-08-26 14:38:02 +080082 error_report("Unable to get size of device tree file '%s'",
83 filename_path);
aurel32f652e6a2008-12-16 10:43:48 +000084 goto fail;
85 }
86
pbrook7ec632b2009-04-10 16:23:59 +000087 /* Expand to 2x size to give enough room for manipulation. */
Alexander Grafded57c52011-07-23 10:54:11 +020088 dt_size += 10000;
pbrook7ec632b2009-04-10 16:23:59 +000089 dt_size *= 2;
aurel32f652e6a2008-12-16 10:43:48 +000090 /* First allocate space in qemu for device tree */
Anthony Liguori7267c092011-08-20 22:09:37 -050091 fdt = g_malloc0(dt_size);
aurel32f652e6a2008-12-16 10:43:48 +000092
pbrook7ec632b2009-04-10 16:23:59 +000093 dt_file_load_size = load_image(filename_path, fdt);
94 if (dt_file_load_size < 0) {
Li Liudb013f82014-08-26 14:38:02 +080095 error_report("Unable to open device tree file '%s'",
96 filename_path);
pbrook7ec632b2009-04-10 16:23:59 +000097 goto fail;
98 }
aurel32f652e6a2008-12-16 10:43:48 +000099
pbrook7ec632b2009-04-10 16:23:59 +0000100 ret = fdt_open_into(fdt, fdt, dt_size);
aurel32f652e6a2008-12-16 10:43:48 +0000101 if (ret) {
Li Liudb013f82014-08-26 14:38:02 +0800102 error_report("Unable to copy device tree in memory");
aurel32f652e6a2008-12-16 10:43:48 +0000103 goto fail;
104 }
105
106 /* Check sanity of device tree */
107 if (fdt_check_header(fdt)) {
Li Liudb013f82014-08-26 14:38:02 +0800108 error_report("Device tree file loaded into memory is invalid: %s",
109 filename_path);
aurel32f652e6a2008-12-16 10:43:48 +0000110 goto fail;
111 }
pbrook7ec632b2009-04-10 16:23:59 +0000112 *sizep = dt_size;
aurel32f652e6a2008-12-16 10:43:48 +0000113 return fdt;
114
115fail:
Anthony Liguori7267c092011-08-20 22:09:37 -0500116 g_free(fdt);
aurel32f652e6a2008-12-16 10:43:48 +0000117 return NULL;
118}
119
Eric Auger60e43e92016-02-19 09:42:29 -0700120#ifdef CONFIG_LINUX
121
122#define SYSFS_DT_BASEDIR "/proc/device-tree"
123
124/**
125 * read_fstree: this function is inspired from dtc read_fstree
126 * @fdt: preallocated fdt blob buffer, to be populated
127 * @dirname: directory to scan under SYSFS_DT_BASEDIR
128 * the search is recursive and the tree is searched down to the
129 * leaves (property files).
130 *
131 * the function asserts in case of error
132 */
133static void read_fstree(void *fdt, const char *dirname)
134{
135 DIR *d;
136 struct dirent *de;
137 struct stat st;
138 const char *root_dir = SYSFS_DT_BASEDIR;
139 const char *parent_node;
140
141 if (strstr(dirname, root_dir) != dirname) {
142 error_setg(&error_fatal, "%s: %s must be searched within %s",
143 __func__, dirname, root_dir);
144 }
145 parent_node = &dirname[strlen(SYSFS_DT_BASEDIR)];
146
147 d = opendir(dirname);
148 if (!d) {
149 error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
150 }
151
152 while ((de = readdir(d)) != NULL) {
153 char *tmpnam;
154
155 if (!g_strcmp0(de->d_name, ".")
156 || !g_strcmp0(de->d_name, "..")) {
157 continue;
158 }
159
160 tmpnam = g_strdup_printf("%s/%s", dirname, de->d_name);
161
162 if (lstat(tmpnam, &st) < 0) {
163 error_setg(&error_fatal, "%s cannot lstat %s", __func__, tmpnam);
164 }
165
166 if (S_ISREG(st.st_mode)) {
167 gchar *val;
168 gsize len;
169
170 if (!g_file_get_contents(tmpnam, &val, &len, NULL)) {
171 error_setg(&error_fatal, "%s not able to extract info from %s",
172 __func__, tmpnam);
173 }
174
175 if (strlen(parent_node) > 0) {
176 qemu_fdt_setprop(fdt, parent_node,
177 de->d_name, val, len);
178 } else {
179 qemu_fdt_setprop(fdt, "/", de->d_name, val, len);
180 }
181 g_free(val);
182 } else if (S_ISDIR(st.st_mode)) {
183 char *node_name;
184
185 node_name = g_strdup_printf("%s/%s",
186 parent_node, de->d_name);
187 qemu_fdt_add_subnode(fdt, node_name);
188 g_free(node_name);
189 read_fstree(fdt, tmpnam);
190 }
191
192 g_free(tmpnam);
193 }
194
195 closedir(d);
196}
197
198/* load_device_tree_from_sysfs: extract the dt blob from host sysfs */
199void *load_device_tree_from_sysfs(void)
200{
201 void *host_fdt;
202 int host_fdt_size;
203
204 host_fdt = create_device_tree(&host_fdt_size);
205 read_fstree(host_fdt, SYSFS_DT_BASEDIR);
206 if (fdt_check_header(host_fdt)) {
207 error_setg(&error_fatal,
208 "%s host device tree extracted into memory is invalid",
209 __func__);
210 }
211 return host_fdt;
212}
213
214#endif /* CONFIG_LINUX */
215
Alexander Grafccbcfed2011-07-23 10:52:00 +0200216static int findnode_nofail(void *fdt, const char *node_path)
aurel32f652e6a2008-12-16 10:43:48 +0000217{
218 int offset;
219
220 offset = fdt_path_offset(fdt, node_path);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200221 if (offset < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800222 error_report("%s Couldn't find node %s: %s", __func__, node_path,
223 fdt_strerror(offset));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200224 exit(1);
225 }
aurel32f652e6a2008-12-16 10:43:48 +0000226
Alexander Grafccbcfed2011-07-23 10:52:00 +0200227 return offset;
228}
229
Eric Auger6d795662016-02-19 09:42:30 -0700230char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
231 Error **errp)
232{
233 int offset, len, ret;
234 const char *iter_name;
235 unsigned int path_len = 16, n = 0;
236 GSList *path_list = NULL, *iter;
237 char **path_array;
238
239 offset = fdt_node_offset_by_compatible(fdt, -1, compat);
240
241 while (offset >= 0) {
242 iter_name = fdt_get_name(fdt, offset, &len);
243 if (!iter_name) {
244 offset = len;
245 break;
246 }
247 if (!strcmp(iter_name, name)) {
248 char *path;
249
250 path = g_malloc(path_len);
251 while ((ret = fdt_get_path(fdt, offset, path, path_len))
252 == -FDT_ERR_NOSPACE) {
253 path_len += 16;
254 path = g_realloc(path, path_len);
255 }
256 path_list = g_slist_prepend(path_list, path);
257 n++;
258 }
259 offset = fdt_node_offset_by_compatible(fdt, offset, compat);
260 }
261
262 if (offset < 0 && offset != -FDT_ERR_NOTFOUND) {
263 error_setg(errp, "%s: abort parsing dt for %s/%s: %s",
264 __func__, name, compat, fdt_strerror(offset));
265 for (iter = path_list; iter; iter = iter->next) {
266 g_free(iter->data);
267 }
268 g_slist_free(path_list);
269 return NULL;
270 }
271
272 path_array = g_new(char *, n + 1);
273 path_array[n--] = NULL;
274
275 for (iter = path_list; iter; iter = iter->next) {
276 path_array[n--] = iter->data;
277 }
278
279 g_slist_free(path_list);
280
281 return path_array;
282}
283
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000284int qemu_fdt_setprop(void *fdt, const char *node_path,
Peter Crosthwaitebe5907f2013-11-11 18:15:21 +1000285 const char *property, const void *val, int size)
Alexander Grafccbcfed2011-07-23 10:52:00 +0200286{
287 int r;
288
Peter Crosthwaitebe5907f2013-11-11 18:15:21 +1000289 r = fdt_setprop(fdt, findnode_nofail(fdt, node_path), property, val, size);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200290 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800291 error_report("%s: Couldn't set %s/%s: %s", __func__, node_path,
292 property, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200293 exit(1);
294 }
295
296 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000297}
298
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000299int qemu_fdt_setprop_cell(void *fdt, const char *node_path,
300 const char *property, uint32_t val)
aurel32f652e6a2008-12-16 10:43:48 +0000301{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200302 int r;
aurel32f652e6a2008-12-16 10:43:48 +0000303
Alexander Grafccbcfed2011-07-23 10:52:00 +0200304 r = fdt_setprop_cell(fdt, findnode_nofail(fdt, node_path), property, val);
305 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800306 error_report("%s: Couldn't set %s/%s = %#08x: %s", __func__,
307 node_path, property, val, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200308 exit(1);
309 }
aurel32f652e6a2008-12-16 10:43:48 +0000310
Alexander Grafccbcfed2011-07-23 10:52:00 +0200311 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000312}
313
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000314int qemu_fdt_setprop_u64(void *fdt, const char *node_path,
315 const char *property, uint64_t val)
Alexander Grafbb28eb32012-05-18 01:53:01 +0200316{
317 val = cpu_to_be64(val);
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000318 return qemu_fdt_setprop(fdt, node_path, property, &val, sizeof(val));
Alexander Grafbb28eb32012-05-18 01:53:01 +0200319}
320
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000321int qemu_fdt_setprop_string(void *fdt, const char *node_path,
322 const char *property, const char *string)
aurel32f652e6a2008-12-16 10:43:48 +0000323{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200324 int r;
aurel32f652e6a2008-12-16 10:43:48 +0000325
Alexander Grafccbcfed2011-07-23 10:52:00 +0200326 r = fdt_setprop_string(fdt, findnode_nofail(fdt, node_path), property, string);
327 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800328 error_report("%s: Couldn't set %s/%s = %s: %s", __func__,
329 node_path, property, string, fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200330 exit(1);
331 }
aurel32f652e6a2008-12-16 10:43:48 +0000332
Alexander Grafccbcfed2011-07-23 10:52:00 +0200333 return r;
aurel32f652e6a2008-12-16 10:43:48 +0000334}
Alexander Grafd69a8e62011-07-21 01:52:57 +0200335
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000336const void *qemu_fdt_getprop(void *fdt, const char *node_path,
Eric Auger78e24f22016-02-19 09:42:30 -0700337 const char *property, int *lenp, Error **errp)
Peter Maydellf0aa7132012-07-20 13:34:50 +0100338{
339 int len;
340 const void *r;
Eric Auger78e24f22016-02-19 09:42:30 -0700341
Peter Maydellf0aa7132012-07-20 13:34:50 +0100342 if (!lenp) {
343 lenp = &len;
344 }
345 r = fdt_getprop(fdt, findnode_nofail(fdt, node_path), property, lenp);
346 if (!r) {
Eric Auger78e24f22016-02-19 09:42:30 -0700347 error_setg(errp, "%s: Couldn't get %s/%s: %s", __func__,
348 node_path, property, fdt_strerror(*lenp));
Peter Maydellf0aa7132012-07-20 13:34:50 +0100349 }
350 return r;
351}
352
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000353uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path,
Eric Auger58e71092016-02-19 09:42:30 -0700354 const char *property, int *lenp, Error **errp)
Peter Maydellf0aa7132012-07-20 13:34:50 +0100355{
356 int len;
Eric Auger58e71092016-02-19 09:42:30 -0700357 const uint32_t *p;
358
359 if (!lenp) {
360 lenp = &len;
361 }
362 p = qemu_fdt_getprop(fdt, node_path, property, lenp, errp);
363 if (!p) {
364 return 0;
365 } else if (*lenp != 4) {
366 error_setg(errp, "%s: %s/%s not 4 bytes long (not a cell?)",
367 __func__, node_path, property);
368 *lenp = -EINVAL;
369 return 0;
Peter Maydellf0aa7132012-07-20 13:34:50 +0100370 }
371 return be32_to_cpu(*p);
372}
373
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000374uint32_t qemu_fdt_get_phandle(void *fdt, const char *path)
Alexander Graf7d5fd102012-05-17 15:23:39 +0200375{
376 uint32_t r;
377
378 r = fdt_get_phandle(fdt, findnode_nofail(fdt, path));
Stefan Weil909a1962013-06-10 22:12:25 +0200379 if (r == 0) {
Li Liu508e2212014-08-26 14:38:03 +0800380 error_report("%s: Couldn't get phandle for %s: %s", __func__,
381 path, fdt_strerror(r));
Alexander Graf7d5fd102012-05-17 15:23:39 +0200382 exit(1);
383 }
384
385 return r;
386}
387
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000388int qemu_fdt_setprop_phandle(void *fdt, const char *node_path,
389 const char *property,
390 const char *target_node_path)
Alexander Graf8535ab12012-05-17 14:11:52 +0200391{
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000392 uint32_t phandle = qemu_fdt_get_phandle(fdt, target_node_path);
393 return qemu_fdt_setprop_cell(fdt, node_path, property, phandle);
Alexander Graf8535ab12012-05-17 14:11:52 +0200394}
395
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000396uint32_t qemu_fdt_alloc_phandle(void *fdt)
Alexander Graf3601b572012-05-17 16:58:55 +0200397{
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200398 static int phandle = 0x0;
399
400 /*
401 * We need to find out if the user gave us special instruction at
Kamalesh Babulalcc47a162015-07-24 13:48:13 +0530402 * which phandle id to start allocating phandles.
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200403 */
404 if (!phandle) {
Marcel Apfelbaum6cabe7f2015-02-04 17:43:53 +0200405 phandle = machine_phandle_start(current_machine);
Alexander Graf4b1b1c82012-06-06 01:01:23 +0200406 }
407
408 if (!phandle) {
409 /*
410 * None or invalid phandle given on the command line, so fall back to
411 * default starting point.
412 */
413 phandle = 0x8000;
414 }
Alexander Graf3601b572012-05-17 16:58:55 +0200415
416 return phandle++;
417}
418
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000419int qemu_fdt_nop_node(void *fdt, const char *node_path)
Alexander Grafd69a8e62011-07-21 01:52:57 +0200420{
Alexander Grafccbcfed2011-07-23 10:52:00 +0200421 int r;
Alexander Grafd69a8e62011-07-21 01:52:57 +0200422
Alexander Grafccbcfed2011-07-23 10:52:00 +0200423 r = fdt_nop_node(fdt, findnode_nofail(fdt, node_path));
424 if (r < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800425 error_report("%s: Couldn't nop node %s: %s", __func__, node_path,
426 fdt_strerror(r));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200427 exit(1);
428 }
Alexander Grafd69a8e62011-07-21 01:52:57 +0200429
Alexander Grafccbcfed2011-07-23 10:52:00 +0200430 return r;
Alexander Grafd69a8e62011-07-21 01:52:57 +0200431}
Alexander Graf80ad7812011-07-22 13:55:37 +0200432
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000433int qemu_fdt_add_subnode(void *fdt, const char *name)
Alexander Graf80ad7812011-07-22 13:55:37 +0200434{
Alexander Graf80ad7812011-07-22 13:55:37 +0200435 char *dupname = g_strdup(name);
436 char *basename = strrchr(dupname, '/');
437 int retval;
Alexander Grafc640d082012-05-17 11:40:42 +0200438 int parent = 0;
Alexander Graf80ad7812011-07-22 13:55:37 +0200439
440 if (!basename) {
Stefan Weilbff39b62011-10-17 22:12:09 +0200441 g_free(dupname);
Alexander Graf80ad7812011-07-22 13:55:37 +0200442 return -1;
443 }
444
445 basename[0] = '\0';
446 basename++;
447
Alexander Grafc640d082012-05-17 11:40:42 +0200448 if (dupname[0]) {
449 parent = findnode_nofail(fdt, dupname);
450 }
451
452 retval = fdt_add_subnode(fdt, parent, basename);
Alexander Grafccbcfed2011-07-23 10:52:00 +0200453 if (retval < 0) {
Li Liu508e2212014-08-26 14:38:03 +0800454 error_report("FDT: Failed to create subnode %s: %s", name,
455 fdt_strerror(retval));
Alexander Grafccbcfed2011-07-23 10:52:00 +0200456 exit(1);
Alexander Graf80ad7812011-07-22 13:55:37 +0200457 }
458
Alexander Graf80ad7812011-07-22 13:55:37 +0200459 g_free(dupname);
460 return retval;
461}
Alexander Graf71193432012-09-23 08:37:59 +0200462
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000463void qemu_fdt_dumpdtb(void *fdt, int size)
Alexander Graf71193432012-09-23 08:37:59 +0200464{
Markus Armbruster2ff3de62013-07-04 15:09:22 +0200465 const char *dumpdtb = qemu_opt_get(qemu_get_machine_opts(), "dumpdtb");
Alexander Graf71193432012-09-23 08:37:59 +0200466
Markus Armbruster2ff3de62013-07-04 15:09:22 +0200467 if (dumpdtb) {
468 /* Dump the dtb to a file and quit */
469 exit(g_file_set_contents(dumpdtb, fdt, size, NULL) ? 0 : 1);
Alexander Graf71193432012-09-23 08:37:59 +0200470 }
Alexander Graf71193432012-09-23 08:37:59 +0200471}
Peter Maydell97c38f82013-07-16 13:25:05 +0100472
Peter Crosthwaite5a4348d2013-11-11 18:14:41 +1000473int qemu_fdt_setprop_sized_cells_from_array(void *fdt,
474 const char *node_path,
475 const char *property,
476 int numvalues,
477 uint64_t *values)
Peter Maydell97c38f82013-07-16 13:25:05 +0100478{
479 uint32_t *propcells;
480 uint64_t value;
481 int cellnum, vnum, ncells;
482 uint32_t hival;
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300483 int ret;
Peter Maydell97c38f82013-07-16 13:25:05 +0100484
485 propcells = g_new0(uint32_t, numvalues * 2);
486
487 cellnum = 0;
488 for (vnum = 0; vnum < numvalues; vnum++) {
489 ncells = values[vnum * 2];
490 if (ncells != 1 && ncells != 2) {
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300491 ret = -1;
492 goto out;
Peter Maydell97c38f82013-07-16 13:25:05 +0100493 }
494 value = values[vnum * 2 + 1];
495 hival = cpu_to_be32(value >> 32);
496 if (ncells > 1) {
497 propcells[cellnum++] = hival;
498 } else if (hival != 0) {
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300499 ret = -1;
500 goto out;
Peter Maydell97c38f82013-07-16 13:25:05 +0100501 }
502 propcells[cellnum++] = cpu_to_be32(value);
503 }
504
Sergey Fedorov2bf9feb2014-12-11 18:45:05 +0300505 ret = qemu_fdt_setprop(fdt, node_path, property, propcells,
506 cellnum * sizeof(uint32_t));
507out:
508 g_free(propcells);
509 return ret;
Peter Maydell97c38f82013-07-16 13:25:05 +0100510}