Advertisement
Guest User

FDT fixup

a guest
Sep 28th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. static void update_fdt_with_owned_resources(void *blob)
  2. {
  3.     /* Traverses the fdt nodes,
  4.       * check its power domain and use the resource id in the power domain
  5.       * for checking whether it is owned by current partition
  6.       */
  7.  
  8.     int offset = 0, next_off;
  9.     int depth = 0, next_depth;
  10.     unsigned int rsrc_id;
  11.     int rc;
  12.  
  13.     for (offset = fdt_next_node(blob, offset, &depth); offset > 0;
  14.          offset = fdt_next_node(blob, offset, &depth)) {
  15.  
  16.         debug("Node name: %s, depth %d\n", fdt_get_name(blob, offset, NULL), depth);
  17.  
  18.         if (!fdtdec_get_is_enabled(blob, offset)) {
  19.             debug("   - ignoring disabled device\n");
  20.             continue;
  21.         }
  22.  
  23.         if (!fdt_node_check_compatible(blob, offset, "nxp,imx8-pd")) {
  24.             /* Skip to next depth=1 node*/
  25.             next_off = offset;
  26.             next_depth = depth;
  27.             do {
  28.                 offset = next_off;
  29.                 depth = next_depth;
  30.                 next_off = fdt_next_node(blob, offset, &next_depth);
  31.                 if (next_off < 0 || next_depth < 1)
  32.                     break;
  33.  
  34.                 debug("PD name: %s, offset %d, depth %d\n",
  35.                     fdt_get_name(blob, next_off, NULL), next_off, next_depth);
  36.             } while (next_depth > 1);
  37.  
  38.             continue;
  39.         }
  40.  
  41.         if (!check_owned_resources_in_pd_tree(blob, offset, &rsrc_id)) {
  42.             /* If the resource is not owned, disable it in FDT */
  43.             rc = disable_fdt_node(blob, offset);
  44.             if (!rc)
  45.                 printf("Disable %s, resource id %u not owned\n",
  46.                     fdt_get_name(blob, offset, NULL), rsrc_id);
  47.             else
  48.                 printf("Unable to disable %s, err=%s\n",
  49.                     fdt_get_name(blob, offset, NULL), fdt_strerror(rc));
  50.         }
  51.  
  52.     }
  53. }
  54.  
  55. static bool check_owned_resources_in_pd_tree(void *blob, int nodeoff,
  56.     unsigned int *unowned_rsrc)
  57. {
  58.     unsigned int rsrc_id;
  59.     int phplen;
  60.     const fdt32_t *php;
  61.  
  62.     /* Search the ancestors nodes in current SS power-domain tree,
  63.     *   if all ancestors' resources are owned,  we can enable the node,
  64.     *   otherwise any ancestor is not owned, we should disable the node.
  65.     */
  66.  
  67.     do {
  68.         php = fdt_getprop(blob, nodeoff, "power-domains", &phplen);
  69.         if (!php) {
  70.             debug("   - ignoring no power-domains\n");
  71.             break;
  72.         }
  73.         if (phplen != 4) {
  74.             printf("ignoring %s power-domains of unexpected length %d\n",
  75.                     fdt_get_name(blob, nodeoff, NULL), phplen);
  76.             break;
  77.         }
  78.         nodeoff = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*php));
  79.  
  80.         rsrc_id = fdtdec_get_uint(blob, nodeoff, "reg", 0);
  81.         if (rsrc_id == SC_R_NONE) {
  82.             debug("%s's power domain use SC_R_NONE\n",
  83.                 fdt_get_name(blob, nodeoff, NULL));
  84.             break;
  85.         }
  86.  
  87.         debug("power-domains node 0x%x, resource id %u\n", nodeoff, rsrc_id);
  88.  
  89.         if (!check_owned_resource(rsrc_id)) {
  90.             if (unowned_rsrc != NULL)
  91.                 *unowned_rsrc = rsrc_id;
  92.             return false;
  93.         }
  94.     } while (fdt_node_check_compatible(blob, nodeoff, "nxp,imx8-pd"));
  95.  
  96.     return true;
  97. }
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement