Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file does the necessary interface mapping between the bootwrapper |
| 3 | * device tree operations and the interface provided by shared source |
| 4 | * files flatdevicetree.[ch]. |
| 5 | * |
| 6 | * Author: Mark A. Greer <mgreer@mvista.com> |
| 7 | * |
| 8 | * 2006 (c) MontaVista Software, Inc. This file is licensed under |
| 9 | * the terms of the GNU General Public License version 2. This program |
| 10 | * is licensed "as is" without any warranty of any kind, whether express |
| 11 | * or implied. |
| 12 | */ |
| 13 | #include <stddef.h> |
| 14 | #include "flatdevtree.h" |
| 15 | #include "ops.h" |
| 16 | |
| 17 | static struct ft_cxt cxt; |
| 18 | |
Scott Wood | a07940b | 2007-03-16 12:27:54 -0500 | [diff] [blame] | 19 | static void *fdtm_finddevice(const char *name) |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 20 | { |
Scott Wood | 4674f2f | 2007-09-06 05:21:04 +1000 | [diff] [blame] | 21 | return ft_find_device(&cxt, NULL, name); |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Scott Wood | a07940b | 2007-03-16 12:27:54 -0500 | [diff] [blame] | 24 | static int fdtm_getprop(const void *phandle, const char *propname, |
| 25 | void *buf, const int buflen) |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 26 | { |
| 27 | return ft_get_prop(&cxt, phandle, propname, buf, buflen); |
| 28 | } |
| 29 | |
Scott Wood | a07940b | 2007-03-16 12:27:54 -0500 | [diff] [blame] | 30 | static int fdtm_setprop(const void *phandle, const char *propname, |
| 31 | const void *buf, const int buflen) |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 32 | { |
| 33 | return ft_set_prop(&cxt, phandle, propname, buf, buflen); |
| 34 | } |
| 35 | |
Scott Wood | a07940b | 2007-03-16 12:27:54 -0500 | [diff] [blame] | 36 | static void *fdtm_get_parent(const void *phandle) |
| 37 | { |
| 38 | return ft_get_parent(&cxt, phandle); |
| 39 | } |
| 40 | |
| 41 | static void *fdtm_create_node(const void *phandle, const char *name) |
| 42 | { |
| 43 | return ft_create_node(&cxt, phandle, name); |
| 44 | } |
| 45 | |
| 46 | static void *fdtm_find_node_by_prop_value(const void *prev, |
| 47 | const char *propname, |
| 48 | const char *propval, |
| 49 | int proplen) |
| 50 | { |
| 51 | return ft_find_node_by_prop_value(&cxt, prev, propname, |
| 52 | propval, proplen); |
| 53 | } |
| 54 | |
| 55 | static unsigned long fdtm_finalize(void) |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 56 | { |
| 57 | ft_end_tree(&cxt); |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 58 | return (unsigned long)cxt.bph; |
| 59 | } |
| 60 | |
Scott Wood | 21f3fe2 | 2007-09-06 05:21:12 +1000 | [diff] [blame] | 61 | static char *fdtm_get_path(const void *phandle, char *buf, int len) |
| 62 | { |
| 63 | return ft_get_path(&cxt, phandle, buf, len); |
| 64 | } |
| 65 | |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 66 | int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device) |
| 67 | { |
Scott Wood | a07940b | 2007-03-16 12:27:54 -0500 | [diff] [blame] | 68 | dt_ops.finddevice = fdtm_finddevice; |
| 69 | dt_ops.getprop = fdtm_getprop; |
| 70 | dt_ops.setprop = fdtm_setprop; |
| 71 | dt_ops.get_parent = fdtm_get_parent; |
| 72 | dt_ops.create_node = fdtm_create_node; |
| 73 | dt_ops.find_node_by_prop_value = fdtm_find_node_by_prop_value; |
| 74 | dt_ops.finalize = fdtm_finalize; |
Scott Wood | 21f3fe2 | 2007-09-06 05:21:12 +1000 | [diff] [blame] | 75 | dt_ops.get_path = fdtm_get_path; |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 76 | |
| 77 | return ft_open(&cxt, dt_blob, max_size, max_find_device, |
| 78 | platform_ops.realloc); |
| 79 | } |