Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 2 | * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 30 | #define LOG_TAG "platform_info" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
| 35 | #include <expat.h> |
| 36 | #include <cutils/log.h> |
| 37 | #include <audio_hw.h> |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 38 | #include "platform_api.h" |
| 39 | #include <platform.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 40 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 41 | #define BUF_SIZE 1024 |
| 42 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 43 | typedef enum { |
| 44 | ROOT, |
| 45 | ACDB, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 46 | BITWIDTH, |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 47 | NATIVESUPPORT, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 48 | PCM_ID, |
| 49 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 50 | INTERFACE_NAME, |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 51 | TZ_NAME, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 52 | } section_t; |
| 53 | |
| 54 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 55 | |
| 56 | static void process_acdb_id(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 57 | static void process_bit_width(const XML_Char **attr); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 58 | static void process_native_support(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 59 | static void process_pcm_id(const XML_Char **attr); |
| 60 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 61 | static void process_interface_name(const XML_Char **attr); |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 62 | static void process_tz_name(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 63 | static void process_root(const XML_Char **attr); |
| 64 | |
| 65 | static section_process_fn section_table[] = { |
| 66 | [ROOT] = process_root, |
| 67 | [ACDB] = process_acdb_id, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 68 | [BITWIDTH] = process_bit_width, |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 69 | [NATIVESUPPORT] = process_native_support, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 70 | [PCM_ID] = process_pcm_id, |
| 71 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 72 | [INTERFACE_NAME] = process_interface_name, |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 73 | [TZ_NAME] = process_tz_name, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static section_t section; |
| 77 | |
| 78 | /* |
| 79 | * <audio_platform_info> |
| 80 | * <acdb_ids> |
| 81 | * <device name="???" acdb_id="???"/> |
| 82 | * ... |
| 83 | * ... |
| 84 | * </acdb_ids> |
| 85 | * <backend_names> |
| 86 | * <device name="???" backend="???"/> |
| 87 | * ... |
| 88 | * ... |
| 89 | * </backend_names> |
| 90 | * <pcm_ids> |
| 91 | * <usecase name="???" type="in/out" id="???"/> |
| 92 | * ... |
| 93 | * ... |
| 94 | * </pcm_ids> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 95 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 96 | * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 97 | * ... |
| 98 | * ... |
| 99 | * </interface_names> |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 100 | * <tz_names> |
| 101 | * <device name="???" spkr_1_tz_name="???" spkr_2_tz_name="???"/> |
| 102 | * ... |
| 103 | * ... |
| 104 | * </tz_names> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 105 | * </audio_platform_info> |
| 106 | */ |
| 107 | |
| 108 | static void process_root(const XML_Char **attr __unused) |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | /* mapping from usecase to pcm dev id */ |
| 113 | static void process_pcm_id(const XML_Char **attr) |
| 114 | { |
| 115 | int index; |
| 116 | |
| 117 | if (strcmp(attr[0], "name") != 0) { |
| 118 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 119 | goto done; |
| 120 | } |
| 121 | |
| 122 | index = platform_get_usecase_index((char *)attr[1]); |
| 123 | if (index < 0) { |
| 124 | ALOGE("%s: usecase %s not found!", |
| 125 | __func__, attr[1]); |
| 126 | goto done; |
| 127 | } |
| 128 | |
| 129 | if (strcmp(attr[2], "type") != 0) { |
| 130 | ALOGE("%s: usecase type not mentioned", __func__); |
| 131 | goto done; |
| 132 | } |
| 133 | |
| 134 | int type = -1; |
| 135 | |
| 136 | if (!strcasecmp((char *)attr[3], "in")) { |
| 137 | type = 1; |
| 138 | } else if (!strcasecmp((char *)attr[3], "out")) { |
| 139 | type = 0; |
| 140 | } else { |
| 141 | ALOGE("%s: type must be IN or OUT", __func__); |
| 142 | goto done; |
| 143 | } |
| 144 | |
| 145 | if (strcmp(attr[4], "id") != 0) { |
| 146 | ALOGE("%s: usecase id not mentioned", __func__); |
| 147 | goto done; |
| 148 | } |
| 149 | |
| 150 | int id = atoi((char *)attr[5]); |
| 151 | |
| 152 | if (platform_set_usecase_pcm_id(index, type, id) < 0) { |
| 153 | ALOGE("%s: usecase %s type %d id %d was not set!", |
| 154 | __func__, attr[1], type, id); |
| 155 | goto done; |
| 156 | } |
| 157 | |
| 158 | done: |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | /* backend to be used for a device */ |
| 163 | static void process_backend_name(const XML_Char **attr) |
| 164 | { |
| 165 | int index; |
| 166 | |
| 167 | if (strcmp(attr[0], "name") != 0) { |
| 168 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 169 | goto done; |
| 170 | } |
| 171 | |
| 172 | index = platform_get_snd_device_index((char *)attr[1]); |
| 173 | if (index < 0) { |
| 174 | ALOGE("%s: Device %s not found, no ACDB ID set!", |
| 175 | __func__, attr[1]); |
| 176 | goto done; |
| 177 | } |
| 178 | |
| 179 | if (strcmp(attr[2], "backend") != 0) { |
| 180 | ALOGE("%s: Device %s has no backend set!", |
| 181 | __func__, attr[1]); |
| 182 | goto done; |
| 183 | } |
| 184 | |
| 185 | if (platform_set_snd_device_backend(index, attr[3]) < 0) { |
| 186 | ALOGE("%s: Device %s backend %s was not set!", |
| 187 | __func__, attr[1], attr[3]); |
| 188 | goto done; |
| 189 | } |
| 190 | |
| 191 | done: |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | static void process_acdb_id(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 196 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 197 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 198 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 199 | if (strcmp(attr[0], "name") != 0) { |
| 200 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 201 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 202 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 203 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 204 | index = platform_get_snd_device_index((char *)attr[1]); |
| 205 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 206 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 207 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 208 | goto done; |
| 209 | } |
| 210 | |
| 211 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 212 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 213 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 214 | goto done; |
| 215 | } |
| 216 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 217 | if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 218 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 219 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 220 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 221 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 222 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 223 | done: |
| 224 | return; |
| 225 | } |
| 226 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 227 | static void process_bit_width(const XML_Char **attr) |
| 228 | { |
| 229 | int index; |
| 230 | |
| 231 | if (strcmp(attr[0], "name") != 0) { |
| 232 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 233 | goto done; |
| 234 | } |
| 235 | |
| 236 | index = platform_get_snd_device_index((char *)attr[1]); |
| 237 | if (index < 0) { |
| 238 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 239 | __func__, attr[1]); |
| 240 | goto done; |
| 241 | } |
| 242 | |
| 243 | if (strcmp(attr[2], "bit_width") != 0) { |
| 244 | ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!", |
| 245 | __func__, attr[1]); |
| 246 | goto done; |
| 247 | } |
| 248 | |
| 249 | if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) { |
| 250 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 251 | __func__, attr[1], atoi((char *)attr[3])); |
| 252 | goto done; |
| 253 | } |
| 254 | |
| 255 | done: |
| 256 | return; |
| 257 | } |
| 258 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 259 | static void process_interface_name(const XML_Char **attr) |
| 260 | { |
| 261 | int ret; |
| 262 | |
| 263 | if (strcmp(attr[0], "name") != 0) { |
| 264 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 265 | |
| 266 | goto done; |
| 267 | } |
| 268 | |
| 269 | if (strcmp(attr[2], "interface") != 0) { |
| 270 | ALOGE("%s: Device %s has no Audio Interface set!", |
| 271 | __func__, attr[1]); |
| 272 | |
| 273 | goto done; |
| 274 | } |
| 275 | |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 276 | if (strcmp(attr[4], "codec_type") != 0) { |
| 277 | ALOGE("%s: Device %s has no codec type set!", |
| 278 | __func__, attr[1]); |
| 279 | |
| 280 | goto done; |
| 281 | } |
| 282 | |
| 283 | ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3], |
| 284 | (char *)attr[5]); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 285 | if (ret < 0) { |
| 286 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 287 | goto done; |
| 288 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 289 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 290 | done: |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | static void process_native_support(const XML_Char **attr) |
| 295 | { |
| 296 | int index; |
| 297 | |
| 298 | if (strcmp(attr[0], "name") != 0) { |
| 299 | ALOGE("%s: 'name' not found, no NATIVE_AUDIO_44.1 set!", __func__); |
| 300 | goto done; |
| 301 | } |
| 302 | |
| 303 | if (strcmp(attr[2], "codec_support") != 0) { |
| 304 | ALOGE("%s: NATIVE_AUDIO_44.1 in platform info xml has no codec_support set!", |
| 305 | __func__); |
| 306 | goto done; |
| 307 | } |
| 308 | |
| 309 | if (platform_set_native_support(atoi((char *)attr[3])) < 0) { |
| 310 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 311 | __func__, attr[1], atoi((char *)attr[3])); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 312 | goto done; |
| 313 | } |
| 314 | |
| 315 | done: |
| 316 | return; |
| 317 | } |
| 318 | |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 319 | static void process_tz_name(const XML_Char **attr) |
| 320 | { |
| 321 | int ret, index; |
| 322 | |
| 323 | if (strcmp(attr[0], "name") != 0) { |
| 324 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 325 | goto done; |
| 326 | } |
| 327 | |
| 328 | index = platform_get_snd_device_index((char *)attr[1]); |
| 329 | if (index < 0) { |
| 330 | ALOGE("%s: Device %s not found, no snd device set!", |
| 331 | __func__, attr[1]); |
| 332 | goto done; |
| 333 | } |
| 334 | |
| 335 | if (strcmp(attr[2], "spkr_1_tz_name") != 0) { |
| 336 | ALOGE("%s: Device %s has no spkr_1_tz_name set!", |
| 337 | __func__, attr[1]); |
| 338 | } |
| 339 | |
| 340 | if (strcmp(attr[4], "spkr_2_tz_name") != 0) { |
| 341 | ALOGE("%s: Device %s has no spkr_2_tz_name set!", |
| 342 | __func__, attr[1]); |
| 343 | } |
| 344 | |
| 345 | ret = platform_set_spkr_device_tz_names(index, (char *)attr[3], (char *)attr[5]); |
| 346 | if (ret < 0) { |
| 347 | ALOGE("%s: Audio Interface not set!", __func__); |
| 348 | goto done; |
| 349 | } |
| 350 | |
| 351 | done: |
| 352 | return; |
| 353 | } |
| 354 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 355 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 356 | const XML_Char **attr) |
| 357 | { |
| 358 | const XML_Char *attr_name = NULL; |
| 359 | const XML_Char *attr_value = NULL; |
| 360 | unsigned int i; |
| 361 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 362 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 363 | section = BITWIDTH; |
| 364 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 365 | section = ACDB; |
| 366 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 367 | section = PCM_ID; |
| 368 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 369 | section = BACKEND_NAME; |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 370 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 371 | section = INTERFACE_NAME; |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 372 | } else if (strcmp(tag_name, "native_configs") == 0) { |
| 373 | section = NATIVESUPPORT; |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 374 | } else if (strcmp(tag_name, "tz_names") == 0) { |
| 375 | section = TZ_NAME; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 376 | } else if (strcmp(tag_name, "device") == 0) { |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 377 | if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) && |
Laxminath Kasam | 8225243 | 2015-05-29 18:37:11 +0530 | [diff] [blame^] | 378 | (section != INTERFACE_NAME) && (section != TZ_NAME)) { |
| 379 | ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface/tz names"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | |
| 383 | /* call into process function for the current section */ |
| 384 | section_process_fn fn = section_table[section]; |
| 385 | fn(attr); |
| 386 | } else if (strcmp(tag_name, "usecase") == 0) { |
| 387 | if (section != PCM_ID) { |
| 388 | ALOGE("usecase tag only supported with PCM_ID section"); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | section_process_fn fn = section_table[PCM_ID]; |
| 393 | fn(attr); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 394 | } else if (strcmp(tag_name, "feature") == 0) { |
| 395 | if (section != NATIVESUPPORT) { |
| 396 | ALOGE("usecase tag only supported with NATIVESUPPORT section"); |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | section_process_fn fn = section_table[NATIVESUPPORT]; |
| 401 | fn(attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 402 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 403 | |
| 404 | return; |
| 405 | } |
| 406 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 407 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 408 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 409 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 410 | section = ROOT; |
| 411 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 412 | section = ROOT; |
| 413 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 414 | section = ROOT; |
| 415 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 416 | section = ROOT; |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 417 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 418 | section = ROOT; |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 419 | } else if (strcmp(tag_name, "native_configs") == 0) { |
| 420 | section = ROOT; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 421 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 424 | int platform_info_init(const char *filename) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 425 | { |
| 426 | XML_Parser parser; |
| 427 | FILE *file; |
| 428 | int ret = 0; |
| 429 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 430 | void *buf; |
| 431 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 432 | file = fopen(filename, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 433 | section = ROOT; |
| 434 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 435 | if (!file) { |
| 436 | ALOGD("%s: Failed to open %s, using defaults.", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 437 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 438 | ret = -ENODEV; |
| 439 | goto done; |
| 440 | } |
| 441 | |
| 442 | parser = XML_ParserCreate(NULL); |
| 443 | if (!parser) { |
| 444 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 445 | ret = -ENODEV; |
| 446 | goto err_close_file; |
| 447 | } |
| 448 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 449 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 450 | |
| 451 | while (1) { |
| 452 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 453 | if (buf == NULL) { |
| 454 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 455 | ret = -ENOMEM; |
| 456 | goto err_free_parser; |
| 457 | } |
| 458 | |
| 459 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 460 | if (bytes_read < 0) { |
| 461 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 462 | ret = bytes_read; |
| 463 | goto err_free_parser; |
| 464 | } |
| 465 | |
| 466 | if (XML_ParseBuffer(parser, bytes_read, |
| 467 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 468 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 469 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 470 | ret = -EINVAL; |
| 471 | goto err_free_parser; |
| 472 | } |
| 473 | |
| 474 | if (bytes_read == 0) |
| 475 | break; |
| 476 | } |
| 477 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 478 | err_free_parser: |
| 479 | XML_ParserFree(parser); |
| 480 | err_close_file: |
| 481 | fclose(file); |
| 482 | done: |
| 483 | return ret; |
| 484 | } |