]>
Commit | Line | Data |
---|---|---|
a0992390 PB |
1 | /*\r |
2 | * libfdt - Flat Device Tree manipulation\r | |
3 | * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>\r | |
4 | *\r | |
5 | * libfdt is dual licensed: you can use it either under the terms of\r | |
6 | * the GPL, or the BSD license, at your option.\r | |
7 | *\r | |
8 | * a) This library is free software; you can redistribute it and/or\r | |
9 | * modify it under the terms of the GNU General Public License as\r | |
10 | * published by the Free Software Foundation; either version 2 of the\r | |
11 | * License, or (at your option) any later version.\r | |
12 | *\r | |
13 | * This library is distributed in the hope that it will be useful,\r | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
16 | * GNU General Public License for more details.\r | |
17 | *\r | |
18 | * You should have received a copy of the GNU General Public\r | |
19 | * License along with this library; if not, write to the Free\r | |
20 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r | |
21 | * MA 02110-1301 USA\r | |
22 | *\r | |
23 | * Alternatively,\r | |
24 | *\r | |
25 | * b) Redistribution and use in source and binary forms, with or\r | |
26 | * without modification, are permitted provided that the following\r | |
27 | * conditions are met:\r | |
28 | *\r | |
29 | * 1. Redistributions of source code must retain the above\r | |
30 | * copyright notice, this list of conditions and the following\r | |
31 | * disclaimer.\r | |
32 | * 2. Redistributions in binary form must reproduce the above\r | |
33 | * copyright notice, this list of conditions and the following\r | |
34 | * disclaimer in the documentation and/or other materials\r | |
35 | * provided with the distribution.\r | |
36 | *\r | |
37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r | |
38 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r | |
39 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r | |
40 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r | |
41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r | |
42 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r | |
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r | |
44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r | |
45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r | |
47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r | |
48 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r | |
49 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
50 | */\r | |
51 | #include "libfdt_env.h"\r | |
52 | \r | |
53 | #include <fdt.h>\r | |
54 | #include <libfdt.h>\r | |
55 | \r | |
56 | #include "libfdt_internal.h"\r | |
57 | \r | |
58 | int fdt_address_cells(const void *fdt, int nodeoffset)\r | |
59 | {\r | |
60 | const fdt32_t *ac;\r | |
61 | int val;\r | |
62 | int len;\r | |
63 | \r | |
64 | ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);\r | |
65 | if (!ac)\r | |
66 | return 2;\r | |
67 | \r | |
68 | if (len != sizeof(*ac))\r | |
69 | return -FDT_ERR_BADNCELLS;\r | |
70 | \r | |
71 | val = fdt32_to_cpu(*ac);\r | |
72 | if ((val <= 0) || (val > FDT_MAX_NCELLS))\r | |
73 | return -FDT_ERR_BADNCELLS;\r | |
74 | \r | |
75 | return val;\r | |
76 | }\r | |
77 | \r | |
78 | int fdt_size_cells(const void *fdt, int nodeoffset)\r | |
79 | {\r | |
80 | const fdt32_t *sc;\r | |
81 | int val;\r | |
82 | int len;\r | |
83 | \r | |
84 | sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);\r | |
85 | if (!sc)\r | |
86 | return 2;\r | |
87 | \r | |
88 | if (len != sizeof(*sc))\r | |
89 | return -FDT_ERR_BADNCELLS;\r | |
90 | \r | |
91 | val = fdt32_to_cpu(*sc);\r | |
92 | if ((val < 0) || (val > FDT_MAX_NCELLS))\r | |
93 | return -FDT_ERR_BADNCELLS;\r | |
94 | \r | |
95 | return val;\r | |
96 | }\r |