flatdevtree_misc.c 2.2 KB
Newer Older
M
Mark A. Greer 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * This file does the necessary interface mapping between the bootwrapper
 * device tree operations and the interface provided by shared source
 * files flatdevicetree.[ch].
 *
 * Author: Mark A. Greer <mgreer@mvista.com>
 *
 * 2006 (c) MontaVista Software, Inc.  This file is licensed under
 * the terms of the GNU General Public License version 2.  This program
 * is licensed "as is" without any warranty of any kind, whether express
 * or implied.
 */
#include <stddef.h>
#include "flatdevtree.h"
#include "ops.h"

static struct ft_cxt cxt;

19
static void *fdtm_finddevice(const char *name)
M
Mark A. Greer 已提交
20
{
21
	return ft_find_device(&cxt, NULL, name);
M
Mark A. Greer 已提交
22 23
}

24 25
static int fdtm_getprop(const void *phandle, const char *propname,
                        void *buf, const int buflen)
M
Mark A. Greer 已提交
26 27 28 29
{
	return ft_get_prop(&cxt, phandle, propname, buf, buflen);
}

30 31
static int fdtm_setprop(const void *phandle, const char *propname,
                        const void *buf, const int buflen)
M
Mark A. Greer 已提交
32 33 34 35
{
	return ft_set_prop(&cxt, phandle, propname, buf, buflen);
}

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
static void *fdtm_get_parent(const void *phandle)
{
	return ft_get_parent(&cxt, phandle);
}

static void *fdtm_create_node(const void *phandle, const char *name)
{
	return ft_create_node(&cxt, phandle, name);
}

static void *fdtm_find_node_by_prop_value(const void *prev,
                                          const char *propname,
                                          const char *propval,
                                          int proplen)
{
	return ft_find_node_by_prop_value(&cxt, prev, propname,
	                                  propval, proplen);
}

static unsigned long fdtm_finalize(void)
M
Mark A. Greer 已提交
56 57 58 59 60
{
	ft_end_tree(&cxt);
	return (unsigned long)cxt.bph;
}

61 62 63 64 65
static char *fdtm_get_path(const void *phandle, char *buf, int len)
{
	return ft_get_path(&cxt, phandle, buf, len);
}

M
Mark A. Greer 已提交
66 67
int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
{
68 69 70 71 72 73 74
	dt_ops.finddevice = fdtm_finddevice;
	dt_ops.getprop = fdtm_getprop;
	dt_ops.setprop = fdtm_setprop;
	dt_ops.get_parent = fdtm_get_parent;
	dt_ops.create_node = fdtm_create_node;
	dt_ops.find_node_by_prop_value = fdtm_find_node_by_prop_value;
	dt_ops.finalize = fdtm_finalize;
75
	dt_ops.get_path = fdtm_get_path;
M
Mark A. Greer 已提交
76 77 78 79

	return ft_open(&cxt, dt_blob, max_size, max_find_device,
			platform_ops.realloc);
}