1 /*
2  INTEL CONFIDENTIAL
3  Copyright 2009 Intel Corporation All Rights Reserved.
4  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
5 
6  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
7  */
8 
9 #include <glib.h>
10 
11 #include "vbp_loader.h"
12 #include "vbp_utils.h"
13 
14 /**
15  *
16  */
vbp_open(uint32 parser_type,Handle * hcontext)17 uint32 vbp_open(uint32 parser_type, Handle *hcontext)
18 {
19 	vbp_context **ppcontext;
20 	uint32 error;
21 
22 	if (NULL == hcontext)
23 	{
24 		return VBP_PARM;
25 	}
26 
27 	*hcontext = NULL;  /* prepare for failure. */
28 
29 	ppcontext = (vbp_context **)hcontext;
30 
31 	/**
32 	* TO DO:
33 	* check if vbp context has been created.
34 	*/
35 
36 	error = vbp_utils_create_context(parser_type, ppcontext);
37 	if (VBP_OK != error)
38 	{
39 		ETRACE("Failed to create context: %d.", error);
40 	}
41 
42 	return error;
43 }
44 
45 /**
46  *
47  */
vbp_close(Handle hcontext)48 uint32 vbp_close(Handle hcontext)
49 {
50 	uint32 error;
51 
52 	if (NULL == hcontext)
53 	{
54 		return VBP_PARM;
55 	}
56 
57 	vbp_context *pcontext = (vbp_context *)hcontext;
58 
59 	if (MAGIC_NUMBER != pcontext->identifier)
60 	{
61 		/* not a valid vbp context. */
62 		ETRACE("context is not initialized");
63 		return VBP_INIT;
64 	}
65 	error = vbp_utils_destroy_context(pcontext);
66 	if (VBP_OK != error)
67 	{
68 		ETRACE("Failed to destroy context: %d.", error);
69 	}
70 
71 	return error;
72 }
73 
74 
75 /**
76  *
77  */
vbp_parse(Handle hcontext,uint8 * data,uint32 size,uint8 init_data_flag)78 uint32 vbp_parse(Handle hcontext, uint8 *data, uint32 size, uint8 init_data_flag)
79 {
80 	vbp_context *pcontext;
81 	uint32 error = VBP_OK;
82 
83 	if ((NULL == hcontext) || (NULL == data) || (0 == size))
84 	{
85 		ETRACE("Invalid input parameters.");
86 		return VBP_PARM;
87 	}
88 
89 	pcontext = (vbp_context *)hcontext;
90 
91 	if (MAGIC_NUMBER != pcontext->identifier)
92 	{
93 		ETRACE("context is not initialized");
94 		return VBP_INIT;
95 	}
96 
97 	error = vbp_utils_parse_buffer(pcontext, data, size, init_data_flag);
98 
99 	if (VBP_OK != error)
100 	{
101 		ETRACE("Failed to parse buffer: %d.", error);
102 	}
103 	return error;
104 }
105 
106 /**
107  *
108  */
vbp_query(Handle hcontext,void ** data)109 uint32 vbp_query(Handle hcontext, void **data)
110 {
111 	vbp_context *pcontext;
112 	uint32 error = VBP_OK;
113 
114 	if ((NULL == hcontext) || (NULL == data))
115 	{
116 		ETRACE("Invalid input parameters.");
117 		return VBP_PARM;
118 	}
119 
120 	pcontext = (vbp_context *)hcontext;
121 
122 	if (MAGIC_NUMBER != pcontext->identifier)
123 	{
124 		ETRACE("context is not initialized");
125 		return VBP_INIT;
126 	}
127 
128 	error = vbp_utils_query(pcontext, data);
129 
130 	if (VBP_OK != error)
131 	{
132 		ETRACE("Failed to query parsing result: %d.", error);
133 	}
134 		return error;
135 }
136 
137 /**
138  *
139  */
vbp_flush(Handle hcontext)140 uint32 vbp_flush(Handle hcontext)
141 {
142 	vbp_context *pcontext;
143 	uint32 error = VBP_OK;
144 
145 	if (NULL == hcontext)
146 	{
147 		ETRACE("Invalid input parameters.");
148 		return VBP_PARM;
149 	}
150 
151 	pcontext = (vbp_context *)hcontext;
152 
153 	if (MAGIC_NUMBER != pcontext->identifier)
154 	{
155 		ETRACE("context is not initialized");
156 		return VBP_INIT;
157 	}
158 
159 	error = vbp_utils_flush(pcontext);
160 
161 	return error;
162 }
163