1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2021, Linaro Limited 4 * Copyright (c) 2021, Bootlin 5 * Copyright (c) 2021, Linaro Limited 6 * Copyright (c) 2021, STMicroelectronics 7 */ 8 9 #include <assert.h> 10 #include <config.h> 11 #include <initcall.h> 12 #include <kernel/boot.h> 13 #include <kernel/dt.h> 14 #include <kernel/dt_driver.h> 15 #include <libfdt.h> 16 #include <malloc.h> 17 #include <sys/queue.h> 18 #include <tee_api_defines_extensions.h> 19 #include <tee_api_types.h> 20 21 /* 22 * struct dt_driver_probe - Node instance in secure FDT to probe a driver for 23 * 24 * @link: List hook 25 * @nodeoffset: Node offset of device referenced in the FDT 26 * @type: One of DT_DRIVER_* or DT_DRIVER_NOTYPE. 27 * @deferrals: Driver probe deferrals count 28 * @dt_drv: Matching driver to probe if found or NULL 29 * @dm: Matching reference if applicable or NULL 30 */ 31 struct dt_driver_probe { 32 int nodeoffset; 33 enum dt_driver_type type; 34 unsigned int deferrals; 35 const struct dt_driver *dt_drv; 36 const struct dt_device_match *dm; 37 TAILQ_ENTRY(dt_driver_probe) link; 38 }; 39 40 /* 41 * struct dt_driver_provider - DT related info on probed device 42 * 43 * Saves information on the probed device so that device 44 * drivers can get resources from DT phandle and related arguments. 45 * 46 * @nodeoffset: Node offset of device referenced in the FDT 47 * @type: One of DT_DRIVER_* or DT_DRIVER_NOTYPE. 48 * @provider_cells: Cells count in the FDT used by the driver's references 49 * @get_of_device: Function to get driver's device ref from phandle data 50 * @priv_data: Driver private data passed as @get_of_device argument 51 * @link: Reference in DT driver providers list 52 */ 53 struct dt_driver_provider { 54 int nodeoffset; 55 enum dt_driver_type type; 56 unsigned int provider_cells; 57 uint32_t phandle; 58 get_of_device_func get_of_device; 59 void *priv_data; 60 SLIST_ENTRY(dt_driver_provider) link; 61 }; 62 63 /* 64 * Device driver providers are able to provide a driver specific instance 65 * related to device phandle arguments found in the secure embedded FDT. 66 */ 67 static SLIST_HEAD(, dt_driver_provider) dt_driver_provider_list = 68 SLIST_HEAD_INITIALIZER(dt_driver_provider_list); 69 70 /* FDT nodes for which a matching driver is to be probed */ 71 static TAILQ_HEAD(dt_driver_probe_head, dt_driver_probe) dt_driver_probe_list = 72 TAILQ_HEAD_INITIALIZER(dt_driver_probe_list); 73 74 /* FDT nodes for which a matching driver has been successfully probed */ 75 static TAILQ_HEAD(, dt_driver_probe) dt_driver_ready_list = 76 TAILQ_HEAD_INITIALIZER(dt_driver_ready_list); 77 78 /* List of the nodes for which a compatible driver but reported a failure */ 79 static TAILQ_HEAD(, dt_driver_probe) dt_driver_failed_list = 80 TAILQ_HEAD_INITIALIZER(dt_driver_failed_list); 81 82 /* Flag enabled when a new node (possibly typed) is added in the probe list */ 83 static bool added_node; 84 85 /* Resolve drivers dependencies on core crypto layer */ 86 static bool tee_crypt_is_ready; 87 88 void dt_driver_crypt_init_complete(void) 89 { 90 assert(!tee_crypt_is_ready); 91 tee_crypt_is_ready = true; 92 } 93 94 TEE_Result dt_driver_get_crypto(void) 95 { 96 if (tee_crypt_is_ready) 97 return TEE_SUCCESS; 98 else 99 return TEE_ERROR_DEFER_DRIVER_INIT; 100 } 101 102 static void assert_type_is_valid(enum dt_driver_type type) 103 { 104 switch (type) { 105 case DT_DRIVER_NOTYPE: 106 case DT_DRIVER_CLK: 107 case DT_DRIVER_RSTCTRL: 108 case DT_DRIVER_UART: 109 return; 110 default: 111 assert(0); 112 } 113 } 114 115 /* 116 * Driver provider registering API functions 117 */ 118 119 TEE_Result dt_driver_register_provider(const void *fdt, int nodeoffset, 120 get_of_device_func get_of_device, 121 void *priv, enum dt_driver_type type) 122 { 123 struct dt_driver_provider *prv = NULL; 124 int provider_cells = 0; 125 uint32_t phandle = 0; 126 127 assert_type_is_valid(type); 128 129 provider_cells = fdt_get_dt_driver_cells(fdt, nodeoffset, type); 130 if (provider_cells < 0) { 131 DMSG("Failed to find provider cells: %d", provider_cells); 132 return TEE_ERROR_GENERIC; 133 } 134 135 phandle = fdt_get_phandle(fdt, nodeoffset); 136 if (!phandle || phandle == (uint32_t)-1) { 137 DMSG("Failed to find provide phandle"); 138 return TEE_ERROR_GENERIC; 139 } 140 141 prv = calloc(1, sizeof(*prv)); 142 if (!prv) 143 return TEE_ERROR_OUT_OF_MEMORY; 144 145 prv->nodeoffset = nodeoffset; 146 prv->type = type; 147 prv->provider_cells = provider_cells; 148 prv->phandle = phandle; 149 prv->get_of_device = get_of_device; 150 prv->priv_data = priv; 151 152 SLIST_INSERT_HEAD(&dt_driver_provider_list, prv, link); 153 154 return TEE_SUCCESS; 155 } 156 157 /* 158 * Helper functions for dt_drivers querying driver provider information 159 */ 160 161 int fdt_get_dt_driver_cells(const void *fdt, int nodeoffset, 162 enum dt_driver_type type) 163 { 164 const char *cells_name = NULL; 165 const fdt32_t *c = NULL; 166 int len = 0; 167 168 switch (type) { 169 case DT_DRIVER_CLK: 170 cells_name = "#clock-cells"; 171 break; 172 case DT_DRIVER_RSTCTRL: 173 cells_name = "#reset-cells"; 174 break; 175 default: 176 panic(); 177 } 178 179 c = fdt_getprop(fdt, nodeoffset, cells_name, &len); 180 if (!c) 181 return len; 182 183 if (len != sizeof(*c)) 184 return -FDT_ERR_BADNCELLS; 185 186 return fdt32_to_cpu(*c); 187 } 188 189 unsigned int dt_driver_provider_cells(struct dt_driver_provider *prv) 190 { 191 return prv->provider_cells; 192 } 193 194 struct dt_driver_provider * 195 dt_driver_get_provider_by_node(int nodeoffset, enum dt_driver_type type) 196 { 197 struct dt_driver_provider *prv = NULL; 198 199 SLIST_FOREACH(prv, &dt_driver_provider_list, link) 200 if (prv->nodeoffset == nodeoffset && prv->type == type) 201 return prv; 202 203 return NULL; 204 } 205 206 struct dt_driver_provider * 207 dt_driver_get_provider_by_phandle(uint32_t phandle, enum dt_driver_type type) 208 { 209 struct dt_driver_provider *prv = NULL; 210 211 SLIST_FOREACH(prv, &dt_driver_provider_list, link) 212 if (prv->phandle == phandle && prv->type == type) 213 return prv; 214 215 return NULL; 216 } 217 218 static void *device_from_provider_prop(struct dt_driver_provider *prv, 219 const uint32_t *prop, 220 TEE_Result *res) 221 { 222 struct dt_driver_phandle_args *pargs = NULL; 223 unsigned int n = 0; 224 void *device = NULL; 225 226 pargs = calloc(1, prv->provider_cells * sizeof(uint32_t *) + 227 sizeof(*pargs)); 228 if (!pargs) { 229 *res = TEE_ERROR_OUT_OF_MEMORY; 230 return NULL; 231 } 232 233 pargs->args_count = prv->provider_cells; 234 for (n = 0; n < prv->provider_cells; n++) 235 pargs->args[n] = fdt32_to_cpu(prop[n + 1]); 236 237 device = prv->get_of_device(pargs, prv->priv_data, res); 238 239 free(pargs); 240 241 return device; 242 } 243 244 void *dt_driver_device_from_node_idx_prop(const char *prop_name, 245 const void *fdt, int nodeoffset, 246 unsigned int prop_idx, 247 enum dt_driver_type type, 248 TEE_Result *res) 249 { 250 int len = 0; 251 int idx = 0; 252 int idx32 = 0; 253 int prv_cells = 0; 254 uint32_t phandle = 0; 255 const uint32_t *prop = NULL; 256 struct dt_driver_provider *prv = NULL; 257 258 prop = fdt_getprop(fdt, nodeoffset, prop_name, &len); 259 if (!prop) { 260 DMSG("Property %s missing in node %s", prop_name, 261 fdt_get_name(fdt, nodeoffset, NULL)); 262 *res = TEE_ERROR_GENERIC; 263 return NULL; 264 } 265 266 while (idx < len) { 267 idx32 = idx / sizeof(uint32_t); 268 phandle = fdt32_to_cpu(prop[idx32]); 269 if (!phandle) { 270 if (!prop_idx) 271 break; 272 idx += sizeof(phandle); 273 prop_idx--; 274 continue; 275 } 276 277 prv = dt_driver_get_provider_by_phandle(phandle, type); 278 if (!prv) { 279 /* No provider registered yet */ 280 *res = TEE_ERROR_DEFER_DRIVER_INIT; 281 return NULL; 282 } 283 284 prv_cells = dt_driver_provider_cells(prv); 285 if (prop_idx) { 286 prop_idx--; 287 idx += sizeof(phandle) + prv_cells * sizeof(uint32_t); 288 continue; 289 } 290 291 return device_from_provider_prop(prv, prop + idx32, res); 292 } 293 294 *res = TEE_ERROR_GENERIC; 295 return NULL; 296 } 297 298 static void __maybe_unused print_probe_list(const void *fdt __maybe_unused) 299 { 300 struct dt_driver_probe *elt = NULL; 301 unsigned int count = 0; 302 303 TAILQ_FOREACH(elt, &dt_driver_probe_list, link) 304 count++; 305 306 DMSG("Probe list: %u elements", count); 307 TAILQ_FOREACH(elt, &dt_driver_probe_list, link) 308 DMSG("|- Driver %s probes on node %s", 309 elt->dt_drv->name, 310 fdt_get_name(fdt, elt->nodeoffset, NULL)); 311 312 DMSG("`- Probe list end"); 313 314 count = 0; 315 TAILQ_FOREACH(elt, &dt_driver_failed_list, link) 316 count++; 317 318 DMSG("Failed list: %u elements", count); 319 TAILQ_FOREACH(elt, &dt_driver_failed_list, link) 320 EMSG("|- Driver %s on node %s failed", elt->dt_drv->name, 321 fdt_get_name(fdt, elt->nodeoffset, NULL)); 322 323 DMSG("`- Failed list end"); 324 } 325 326 /* 327 * Probe element: push to ready list if succeeds, push to probe list if probe 328 * if deferred, panic with an error trace otherwise. 329 */ 330 static TEE_Result probe_driver_node(const void *fdt, 331 struct dt_driver_probe *elt) 332 { 333 TEE_Result res = TEE_ERROR_GENERIC; 334 const char __maybe_unused *drv_name = NULL; 335 const char __maybe_unused *node_name = NULL; 336 337 node_name = fdt_get_name(fdt, elt->nodeoffset, NULL); 338 drv_name = elt->dt_drv->name; 339 340 if (!elt->dt_drv->probe) { 341 DMSG("No probe operator for driver %s, skipped", drv_name); 342 return TEE_SUCCESS; 343 } 344 345 FMSG("Probing %s on node %s", drv_name, node_name); 346 347 res = elt->dt_drv->probe(fdt, elt->nodeoffset, elt->dm->compat_data); 348 switch (res) { 349 case TEE_SUCCESS: 350 TAILQ_INSERT_HEAD(&dt_driver_ready_list, elt, link); 351 352 DMSG("element: %s on node %s initialized", drv_name, node_name); 353 break; 354 case TEE_ERROR_DEFER_DRIVER_INIT: 355 elt->deferrals++; 356 TAILQ_INSERT_TAIL(&dt_driver_probe_list, elt, link); 357 358 DMSG("element: %s on node %s deferred %u time(s)", drv_name, 359 node_name, elt->deferrals); 360 break; 361 default: 362 TAILQ_INSERT_HEAD(&dt_driver_failed_list, elt, link); 363 364 EMSG("Failed to probe %s on node %s: %#"PRIx32, 365 drv_name, node_name, res); 366 break; 367 } 368 369 return res; 370 } 371 372 static TEE_Result alloc_elt_and_probe(const void *fdt, int node, 373 const struct dt_driver *dt_drv, 374 const struct dt_device_match *dm) 375 { 376 struct dt_driver_probe *elt = NULL; 377 378 /* Will be freed when lists are released */ 379 elt = calloc(1, sizeof(*elt)); 380 if (!elt) 381 return TEE_ERROR_OUT_OF_MEMORY; 382 383 elt->nodeoffset = node; 384 elt->dt_drv = dt_drv; 385 elt->dm = dm; 386 elt->type = dt_drv->type; 387 388 return probe_driver_node(fdt, elt); 389 } 390 391 /* Lookup a compatible driver, possibly of a specific @type, for the FDT node */ 392 static TEE_Result probe_device_by_compat(const void *fdt, int node, 393 const char *compat, 394 enum dt_driver_type type) 395 { 396 const struct dt_driver *drv = NULL; 397 const struct dt_device_match *dm = NULL; 398 399 for_each_dt_driver(drv) { 400 if (drv->type != type) 401 continue; 402 403 for (dm = drv->match_table; dm && dm->compatible; dm++) 404 if (strcmp(dm->compatible, compat) == 0) 405 return alloc_elt_and_probe(fdt, node, drv, dm); 406 } 407 408 return TEE_ERROR_ITEM_NOT_FOUND; 409 } 410 411 /* 412 * Lookup the best matching compatible driver, possibly of a specific @type, 413 * for the FDT node. 414 */ 415 TEE_Result dt_driver_probe_device_by_node(const void *fdt, int nodeoffset, 416 enum dt_driver_type type) 417 { 418 int idx = 0; 419 int len = 0; 420 int count = 0; 421 const char *compat = NULL; 422 TEE_Result res = TEE_ERROR_GENERIC; 423 424 assert_type_is_valid(type); 425 426 count = fdt_stringlist_count(fdt, nodeoffset, "compatible"); 427 if (count < 0) 428 return TEE_ERROR_ITEM_NOT_FOUND; 429 430 for (idx = 0; idx < count; idx++) { 431 compat = fdt_stringlist_get(fdt, nodeoffset, "compatible", 432 idx, &len); 433 if (!compat) 434 return TEE_ERROR_GENERIC; 435 436 res = probe_device_by_compat(fdt, nodeoffset, compat, type); 437 438 if (res != TEE_ERROR_ITEM_NOT_FOUND) 439 return res; 440 } 441 442 return TEE_ERROR_ITEM_NOT_FOUND; 443 } 444 445 static TEE_Result process_probe_list(const void *fdt) 446 { 447 struct dt_driver_probe *elt = NULL; 448 struct dt_driver_probe *prev = NULL; 449 static unsigned int __maybe_unused loop_count; 450 static unsigned int __maybe_unused deferral_loop_count; 451 bool __maybe_unused one_deferred = false; 452 bool one_probed_ok = false; 453 454 do { 455 loop_count++; 456 FMSG("Probe loop %u after %u for deferral(s)", loop_count, 457 deferral_loop_count); 458 459 /* Hack here for TRACE_DEBUG messages on probe list elements */ 460 if (TRACE_LEVEL >= TRACE_FLOW) 461 print_probe_list(fdt); 462 463 if (TAILQ_EMPTY(&dt_driver_probe_list)) 464 return TEE_SUCCESS; 465 466 /* 467 * Probe from current end to top. Deferred probed node are 468 * pushed back after current tail for the next probe round. 469 * Reset probe result flags and see status after probe round. 470 */ 471 one_deferred = false; 472 one_probed_ok = false; 473 added_node = false; 474 475 TAILQ_FOREACH_REVERSE_SAFE(elt, &dt_driver_probe_list, 476 dt_driver_probe_head, link, prev) { 477 TAILQ_REMOVE(&dt_driver_probe_list, elt, link); 478 479 switch (probe_driver_node(fdt, elt)) { 480 case TEE_SUCCESS: 481 one_probed_ok = true; 482 break; 483 case TEE_ERROR_DEFER_DRIVER_INIT: 484 one_deferred = true; 485 break; 486 default: 487 break; 488 } 489 } 490 491 if (one_deferred) 492 deferral_loop_count++; 493 494 } while (added_node || one_probed_ok); 495 496 DMSG("Unresolved dependencies after %u rounds, %u deferred", 497 loop_count, deferral_loop_count); 498 499 if (one_deferred) 500 return TEE_ERROR_DEFER_DRIVER_INIT; 501 else 502 return TEE_ERROR_GENERIC; 503 } 504 505 static int driver_probe_compare(struct dt_driver_probe *candidate, 506 struct dt_driver_probe *elt) 507 { 508 if (candidate->nodeoffset != elt->nodeoffset || 509 candidate->type != elt->type) 510 return 1; 511 512 assert(elt->dt_drv == candidate->dt_drv); 513 return 0; 514 } 515 516 /* 517 * Return TEE_SUCCESS if compatible found 518 * TEE_ERROR_OUT_OF_MEMORY if heap is exhausted 519 */ 520 static TEE_Result add_node_to_probe(const void *fdt, int node, 521 const struct dt_driver *dt_drv, 522 const struct dt_device_match *dm) 523 { 524 const char __maybe_unused *node_name = fdt_get_name(fdt, node, NULL); 525 const char __maybe_unused *drv_name = dt_drv->name; 526 struct dt_driver_probe *elt = NULL; 527 struct dt_driver_probe elt_new = { 528 .dm = dm, 529 .dt_drv = dt_drv, 530 .nodeoffset = node, 531 .type = dt_drv->type, 532 }; 533 534 /* If node/type found in probe list or ready list, nothing to do */ 535 TAILQ_FOREACH(elt, &dt_driver_probe_list, link) 536 if (!driver_probe_compare(&elt_new, elt)) 537 return TEE_SUCCESS; 538 539 TAILQ_FOREACH(elt, &dt_driver_ready_list, link) 540 if (!driver_probe_compare(&elt_new, elt)) 541 return TEE_SUCCESS; 542 543 elt = malloc(sizeof(*elt)); 544 if (!elt) 545 return TEE_ERROR_OUT_OF_MEMORY; 546 547 DMSG("element: %s on node %s", node_name, drv_name); 548 549 memcpy(elt, &elt_new, sizeof(*elt)); 550 551 added_node = true; 552 553 TAILQ_INSERT_TAIL(&dt_driver_probe_list, elt, link); 554 555 /* Hack here for TRACE_DEBUG messages on current probe list elements */ 556 if (TRACE_LEVEL >= TRACE_FLOW) 557 print_probe_list(fdt); 558 559 return TEE_SUCCESS; 560 } 561 562 /* 563 * Add a node to the probe list if a dt_driver matches target compatible. 564 * 565 * If @type is DT_DRIVER_ANY, probe list can hold only 1 driver to probe for 566 * the node. A node may probe several drivers if have a unique driver type. 567 * 568 * Return TEE_SUCCESS if compatible found 569 * TEE_ERROR_ITEM_NOT_FOUND if no matching driver 570 * TEE_ERROR_OUT_OF_MEMORY if heap is exhausted 571 */ 572 static TEE_Result add_probe_node_by_compat(const void *fdt, int node, 573 const char *compat) 574 { 575 TEE_Result res = TEE_ERROR_ITEM_NOT_FOUND; 576 const struct dt_driver *dt_drv = NULL; 577 const struct dt_device_match *dm = NULL; 578 uint32_t found_types = 0; 579 580 for_each_dt_driver(dt_drv) { 581 for (dm = dt_drv->match_table; dm && dm->compatible; dm++) { 582 if (strcmp(dm->compatible, compat) == 0) { 583 assert(dt_drv->type < 32); 584 585 res = add_node_to_probe(fdt, node, dt_drv, dm); 586 if (res) 587 return res; 588 589 if (found_types & BIT(dt_drv->type)) { 590 EMSG("Driver %s multi hit on type %u", 591 dt_drv->name, dt_drv->type); 592 panic(); 593 } 594 found_types |= BIT(dt_drv->type); 595 596 /* Matching found for this driver, try next */ 597 break; 598 } 599 } 600 } 601 602 return res; 603 } 604 605 /* 606 * Add the node to the probe list if matching compatible drivers are found. 607 * Follow node's compatible property list ordering to find matching driver. 608 */ 609 TEE_Result dt_driver_maybe_add_probe_node(const void *fdt, int node) 610 { 611 int idx = 0; 612 int len = 0; 613 int count = 0; 614 const char *compat = NULL; 615 TEE_Result res = TEE_ERROR_GENERIC; 616 617 if (_fdt_get_status(fdt, node) == DT_STATUS_DISABLED) 618 return TEE_SUCCESS; 619 620 count = fdt_stringlist_count(fdt, node, "compatible"); 621 if (count < 0) 622 return TEE_SUCCESS; 623 624 for (idx = 0; idx < count; idx++) { 625 compat = fdt_stringlist_get(fdt, node, "compatible", idx, &len); 626 assert(compat && len > 0); 627 628 res = add_probe_node_by_compat(fdt, node, compat); 629 630 /* Stop lookup if something was found */ 631 if (res != TEE_ERROR_ITEM_NOT_FOUND) 632 return res; 633 } 634 635 return TEE_SUCCESS; 636 } 637 638 static void parse_node(const void *fdt, int node) 639 { 640 TEE_Result __maybe_unused res = TEE_ERROR_GENERIC; 641 int subnode = 0; 642 643 fdt_for_each_subnode(subnode, fdt, node) { 644 res = dt_driver_maybe_add_probe_node(fdt, subnode); 645 if (res) { 646 EMSG("Failed on node %s with %#"PRIx32, 647 fdt_get_name(fdt, subnode, NULL), res); 648 panic(); 649 } 650 651 /* 652 * Rescursively parse the FDT, skipping disabled nodes. 653 * FDT is expected reliable and core shall have sufficient 654 * stack depth to possibly parse all DT nodes. 655 */ 656 if (IS_ENABLED(CFG_DRIVERS_DT_RECURSIVE_PROBE)) { 657 if (_fdt_get_status(fdt, subnode) == DT_STATUS_DISABLED) 658 continue; 659 660 parse_node(fdt, subnode); 661 } 662 } 663 } 664 665 /* 666 * Parse FDT for nodes and save in probe list the node for which a dt_driver 667 * matches node's compatible property. 668 */ 669 static TEE_Result probe_dt_drivers_early(void) 670 { 671 TEE_Result res = TEE_ERROR_GENERIC; 672 const void *fdt = NULL; 673 674 if (!IS_ENABLED(CFG_EMBED_DTB)) 675 return TEE_SUCCESS; 676 677 fdt = get_embedded_dt(); 678 assert(fdt); 679 680 parse_node(fdt, fdt_path_offset(fdt, "/")); 681 682 res = process_probe_list(fdt); 683 if (res == TEE_ERROR_DEFER_DRIVER_INIT) { 684 DMSG("Deferred drivers probing"); 685 print_probe_list(fdt); 686 res = TEE_SUCCESS; 687 } 688 689 return res; 690 } 691 692 static TEE_Result probe_dt_drivers(void) 693 { 694 TEE_Result res = TEE_ERROR_GENERIC; 695 const void *fdt = NULL; 696 697 if (!IS_ENABLED(CFG_EMBED_DTB)) 698 return TEE_SUCCESS; 699 700 fdt = get_embedded_dt(); 701 assert(fdt); 702 703 res = process_probe_list(fdt); 704 if (res || !TAILQ_EMPTY(&dt_driver_failed_list)) { 705 EMSG("Probe sequence result: %#"PRIx32, res); 706 print_probe_list(fdt); 707 } 708 if (res) 709 panic(); 710 711 return TEE_SUCCESS; 712 } 713 714 early_init_late(probe_dt_drivers_early); 715 driver_init(probe_dt_drivers); 716 717 static TEE_Result release_probe_lists(void) 718 { 719 struct dt_driver_probe *elt = NULL; 720 struct dt_driver_probe *next = NULL; 721 struct dt_driver_provider *prov = NULL; 722 struct dt_driver_provider *next_prov = NULL; 723 const void * __maybe_unused fdt = NULL; 724 725 if (!IS_ENABLED(CFG_EMBED_DTB)) 726 return TEE_SUCCESS; 727 728 fdt = get_embedded_dt(); 729 730 assert(fdt && TAILQ_EMPTY(&dt_driver_probe_list)); 731 732 TAILQ_FOREACH_SAFE(elt, &dt_driver_ready_list, link, next) 733 free(elt); 734 735 TAILQ_FOREACH_SAFE(elt, &dt_driver_failed_list, link, next) 736 free(elt); 737 738 SLIST_FOREACH_SAFE(prov, &dt_driver_provider_list, link, next_prov) 739 free(prov); 740 741 return TEE_SUCCESS; 742 } 743 744 release_init_resource(release_probe_lists); 745 746 /* 747 * Simple bus support: handy to parse subnodes 748 */ 749 static TEE_Result simple_bus_probe(const void *fdt, int node, 750 const void *compat_data __unused) 751 { 752 TEE_Result res = TEE_ERROR_GENERIC; 753 int subnode = 0; 754 755 fdt_for_each_subnode(subnode, fdt, node) { 756 res = dt_driver_maybe_add_probe_node(fdt, subnode); 757 if (res) { 758 EMSG("Failed on node %s with %#"PRIx32, 759 fdt_get_name(fdt, subnode, NULL), res); 760 panic(); 761 } 762 } 763 764 return TEE_SUCCESS; 765 } 766 767 static const struct dt_device_match simple_bus_match_table[] = { 768 { .compatible = "simple-bus" }, 769 { } 770 }; 771 772 DEFINE_DT_DRIVER(simple_bus_dt_driver) = { 773 .name = "simple-bus", 774 .match_table = simple_bus_match_table, 775 .probe = simple_bus_probe, 776 }; 777