0d85f4169dd22f1d5f144e05a80c838d374291ca
[h-e-n] / drivers / dsp / bridge / services / reg.c
1 /*
2  * reg.c
3  *
4  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5  *
6  * Copyright (C) 2005-2006 Texas Instruments, Inc.
7  *
8  * This package is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15  */
16
17
18 /*
19  *  ======== regce.c ========
20  *  Purpose:
21  *      Provide registry functions.
22  *
23  *  Public Functions:
24  *      REG_DeleteValue
25  *      REG_EnumValue
26  *      REG_Exit
27  *      REG_GetValue
28  *      REG_Init
29  *      REG_SetValue
30  *
31  *! Revision History:
32  *! ================
33  *
34  */
35
36 /*  ----------------------------------- Host OS */
37 #include <dspbridge/host_os.h>
38
39 /*  ----------------------------------- DSP/BIOS Bridge */
40 #include <dspbridge/std.h>
41 #include <dspbridge/dbdefs.h>
42 #include <dspbridge/errbase.h>
43
44 /*  ----------------------------------- Trace & Debug */
45 #include <dspbridge/dbc.h>
46 #include <dspbridge/gt.h>
47
48 /*  ----------------------------------- OS Adaptation Layer */
49 #include <dspbridge/csl.h>
50 #include <dspbridge/mem.h>
51
52 /*  ----------------------------------- Others */
53 #include <dspbridge/dbreg.h>
54
55 /*  ----------------------------------- This */
56 #include <dspbridge/reg.h>
57 #include <regsup.h>
58
59 #if GT_TRACE
60 struct GT_Mask REG_debugMask = { NULL, NULL };  /* GT trace var. */
61 #endif
62
63 /*
64  *  ======== REG_DeleteValue ========
65  *  Deletes a registry entry value.  NOTE:  A registry entry value is not the
66  *  same as *  a registry key.
67  */
68 DSP_STATUS REG_DeleteValue(OPTIONAL IN HANDLE *phKey, IN CONST char *pstrSubkey,
69                            IN CONST char *pstrValue)
70 {
71         DSP_STATUS status;
72         DBC_Require(pstrSubkey && pstrValue);
73         DBC_Require(phKey == NULL);
74        DBC_Require(strlen(pstrSubkey) < REG_MAXREGPATHLENGTH);
75        DBC_Require(strlen(pstrValue) < REG_MAXREGPATHLENGTH);
76
77         GT_0trace(REG_debugMask, GT_ENTER, "REG_DeleteValue: entered\n");
78
79         /*  Note that we don't use phKey */
80         if (regsupDeleteValue(pstrSubkey, pstrValue) == DSP_SOK)
81                 status = DSP_SOK;
82         else
83                 status = DSP_EFAIL;
84
85         return status;
86 }
87
88 /*
89  *  ======== REG_EnumValue ========
90  *  Enumerates a registry key and retrieve values stored under the key.
91  *  We will assume the input pdwValueSize is smaller than
92  *  REG_MAXREGPATHLENGTH for implementation purposes.
93  */
94 DSP_STATUS REG_EnumValue(IN HANDLE *phKey, IN u32 dwIndex,
95                          IN CONST char *pstrKey, IN OUT char *pstrValue,
96                          IN OUT u32 *pdwValueSize, IN OUT char *pstrData,
97                          IN OUT u32 *pdwDataSize)
98 {
99         DSP_STATUS status;
100
101         DBC_Require(pstrKey && pstrValue && pdwValueSize && pstrData &&
102                     pdwDataSize);
103         DBC_Require(*pdwValueSize <= REG_MAXREGPATHLENGTH);
104         DBC_Require(phKey == NULL);
105        DBC_Require(strlen(pstrKey) < REG_MAXREGPATHLENGTH);
106
107         GT_0trace(REG_debugMask, GT_ENTER, "REG_EnumValue: entered\n");
108
109         status = regsupEnumValue(dwIndex, pstrKey, pstrValue, pdwValueSize,
110                                  pstrData, pdwDataSize);
111
112         return status;
113 }
114
115 /*
116  *  ======== REG_Exit ========
117  *  Discontinue usage of the REG module.
118  */
119 void REG_Exit(void)
120 {
121         GT_0trace(REG_debugMask, GT_5CLASS, "REG_Exit\n");
122
123         regsupExit();
124 }
125
126 /*
127  *  ======== REG_GetValue ========
128  *  Retrieve a value from the registry.
129  */
130 DSP_STATUS REG_GetValue(OPTIONAL IN HANDLE *phKey, IN CONST char *pstrSubkey,
131                         IN CONST char *pstrValue, OUT u8 *pbData,
132                         IN OUT u32 *pdwDataSize)
133 {
134         DSP_STATUS status;
135
136         DBC_Require(pstrSubkey && pstrValue && pbData);
137         DBC_Require(phKey == NULL);
138        DBC_Require(strlen(pstrSubkey) < REG_MAXREGPATHLENGTH);
139        DBC_Require(strlen(pstrValue) < REG_MAXREGPATHLENGTH);
140
141         GT_0trace(REG_debugMask, GT_ENTER, "REG_GetValue: entered\n");
142
143         /*  We need to use regsup calls...  */
144         /*  ...for now we don't need the key handle or  */
145         /*  the subkey, all we need is the value to lookup.  */
146         if (regsupGetValue((char *)pstrValue, pbData, pdwDataSize) == DSP_SOK)
147                 status = DSP_SOK;
148         else
149                 status = DSP_EFAIL;
150
151         return status;
152 }
153
154 /*
155  *  ======== REG_Init ========
156  *  Initialize the REG module's private state.
157  */
158 bool REG_Init(void)
159 {
160         bool fInit;
161
162         GT_create(&REG_debugMask, "RG");        /* RG for ReG */
163
164         fInit = regsupInit();
165
166         GT_0trace(REG_debugMask, GT_5CLASS, "REG_Init\n");
167
168         return fInit;
169 }
170
171 /*
172  *  ======== REG_SetValue ========
173  *  Set a value in the registry.
174  */
175 DSP_STATUS REG_SetValue(OPTIONAL IN HANDLE *phKey, IN CONST char *pstrSubkey,
176                         IN CONST char *pstrValue, IN CONST u32 dwType,
177                         IN u8 *pbData, IN u32 dwDataSize)
178 {
179         DSP_STATUS status;
180
181         DBC_Require(pstrValue && pbData);
182         DBC_Require(phKey == NULL);
183         DBC_Require(dwDataSize > 0);
184        DBC_Require(strlen(pstrValue) < REG_MAXREGPATHLENGTH);
185
186         /*  We need to use regsup calls...  */
187         /*  ...for now we don't need the key handle or  */
188         /*  the subkey, all we need is the value to lookup.  */
189         if (regsupSetValue((char *)pstrValue, pbData, dwDataSize) == DSP_SOK)
190                 status = DSP_SOK;
191         else
192                 status = DSP_EFAIL;
193
194         return status;
195 }
196