misc,tests: Updated and generalized the resource url for tests
[gem5.git] / ext / libfdt / fdt_wip.c
1 /*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
4 *
5 * Redistribution and use in source and binary forms, with or
6 * without modification, are permitted provided that the following
7 * conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include <fdt.h>
32 #include <libfdt.h>
33
34 #include "libfdt_env.h"
35 #include "libfdt_internal.h"
36
37 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
38 const void *val, int len)
39 {
40 void *propval;
41 int proplen;
42
43 propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);
44 if (! propval)
45 return proplen;
46
47 if (proplen != len)
48 return -FDT_ERR_NOSPACE;
49
50 memcpy(propval, val, len);
51 return 0;
52 }
53
54 static void _fdt_nop_region(void *start, int len)
55 {
56 fdt32_t *p;
57
58 for (p = start; (char *)p < ((char *)start + len); p++)
59 *p = cpu_to_fdt32(FDT_NOP);
60 }
61
62 int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
63 {
64 struct fdt_property *prop;
65 int len;
66
67 prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
68 if (! prop)
69 return len;
70
71 _fdt_nop_region(prop, len + sizeof(*prop));
72
73 return 0;
74 }
75
76 int _fdt_node_end_offset(void *fdt, int offset)
77 {
78 int depth = 0;
79
80 while ((offset >= 0) && (depth >= 0))
81 offset = fdt_next_node(fdt, offset, &depth);
82
83 return offset;
84 }
85
86 int fdt_nop_node(void *fdt, int nodeoffset)
87 {
88 int endoffset;
89
90 endoffset = _fdt_node_end_offset(fdt, nodeoffset);
91 if (endoffset < 0)
92 return endoffset;
93
94 _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),
95 endoffset - nodeoffset);
96 return 0;
97 }