@@ -49,7 +49,7 @@ struct pdbg_target *__pdbg_next_target(const char *class, struct pdbg_target *pa
4949retry :
5050 /* No more targets left to check in this class */
5151 if ((last && last -> class_link .next == & target_class -> targets .n ) ||
52- list_empty (& target_class -> targets ))
52+ list_empty (& target_class -> targets ))
5353 return NULL ;
5454
5555 if (last )
@@ -82,16 +82,16 @@ static struct pdbg_target *target_map_child(struct pdbg_target *next, bool syste
8282 * (the target itself can be virtual or real)
8383 *
8484 * - If there is virtual node associated,
85- * - If the target is virtual, return the associated node
86- * - If the target is real, return NULL
87- * (this target is already covered by previous condition)
85+ * - If the target is virtual, return the associated node
86+ * - If the target is real, return NULL
87+ * (this target is already covered by previous condition)
8888 *
8989 * Map a target in backend tree:
9090 *
9191 * - If the target is real, return the target
9292 *
9393 * - If the target is virtual, return NULL
94- * (no virtual nodes in backend tree)
94+ * (no virtual nodes in backend tree)
9595 */
9696 if (system ) {
9797 if (!next -> vnode )
@@ -118,11 +118,11 @@ struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct
118118 * Parent node can be virtual or real.
119119 *
120120 * If the parent node doesn't have any children,
121- * - If there is associated virtual node,
122- * Use that node as parent
121+ * - If there is associated virtual node,
122+ * Use that node as parent
123123 *
124- * - If there is no associated virtual node,
125- * No children
124+ * - If there is no associated virtual node,
125+ * No children
126126 */
127127 if (list_empty (& parent -> children )) {
128128 if (parent -> vnode )
@@ -133,8 +133,8 @@ struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct
133133
134134 /*
135135 * If the parent node has children,
136- * - Traverse the children
137- * (map the children in system or backend tree)
136+ * - Traverse the children
137+ * (map the children in system or backend tree)
138138 */
139139 if (!last ) {
140140 list_for_each (& parent -> children , child , list )
@@ -150,10 +150,10 @@ struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct
150150 *
151151 * When the last child is specified:
152152 * - If in a system tree traverse, and
153- * the last child has associated node, and
154- * the last child is real
155- * Then the last child is not the actual child of the parent
156- * (the associated virtual node is the actual child)
153+ * the last child has associated node, and
154+ * the last child is real
155+ * Then the last child is not the actual child of the parent
156+ * (the associated virtual node is the actual child)
157157 */
158158 if (system )
159159 last = target_to_virtual (last , false);
@@ -317,20 +317,20 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3
317317int pdbg_target_u32_index (struct pdbg_target * target , const char * name , int index , uint32_t * val )
318318{
319319 const void * p ;
320- size_t len ;
320+ size_t len ;
321321
322- p = pdbg_get_target_property (target , name , & len );
323- if (!p )
324- return -1 ;
322+ p = pdbg_get_target_property (target , name , & len );
323+ if (!p )
324+ return -1 ;
325325
326- assert (len >= (index + 1 )* sizeof (uint32_t ));
326+ assert (len >= (index + 1 )* sizeof (uint32_t ));
327327
328328 /* FDT pointers should be aligned, but best to check */
329329 assert (!((uintptr_t ) p & 0x3 ));
330330
331- /* Always aligned, so this works. */
332- * val = be32toh (((uint32_t * )p )[index ]);
333- return 0 ;
331+ /* Always aligned, so this works. */
332+ * val = be32toh (((uint32_t * )p )[index ]);
333+ return 0 ;
334334}
335335
336336void pdbg_progress_tick (uint64_t cur , uint64_t end )
@@ -362,68 +362,89 @@ bool pdbg_context_is_short(void)
362362
363363struct pdbg_target * pdbg_get_unattached_backend_target (struct pdbg_target * target , const char * class_name )
364364{
365- struct pdbg_target * backend_target = NULL ;
365+ if (!target || !class_name )
366+ {
367+ pdbg_log (PDBG_ERROR , "Invalid input: target or class_name is NULL\n" );
368+ return NULL ;
369+ }
370+
371+ struct pdbg_target * backend_target = NULL ;
366372
367- /* We assume each processor chip contains one and only one pib */
368- pdbg_for_each_target (class_name , target , backend_target )
369- {
373+ /* We assume each processor chip contains one and only one pib */
374+ pdbg_for_each_target (class_name , target , backend_target )
375+ {
370376 /* There is a vnode attached, so this should be the backend target*/
371377 if (!backend_target -> vnode )
372378 {
373379 break ;
374380 }
375- }
381+ }
376382 return backend_target ;
377383}
378384
379385struct pdbg_target * pdbg_get_backend_target (struct pdbg_target * target , const char * class_name )
380386{
381- struct pdbg_target * backend_target = NULL ;
387+ if (!target || !class_name )
388+ {
389+ pdbg_log (PDBG_ERROR , "Invalid input: target or class_name is NULL\n" );
390+ return NULL ;
391+ }
382392
383- /* We assume each processor chip contains one and only one pib */
384- pdbg_for_each_target (class_name , target , backend_target )
385- {
393+ struct pdbg_target * backend_target = NULL ;
394+ /* We assume each processor chip contains one and only one pib */
395+ pdbg_for_each_target (class_name , target , backend_target )
396+ {
386397 /* There is a vnode attached, so this should be the current backend target*/
387398 if (backend_target -> vnode )
388399 {
389400 break ;
390401 }
391- }
402+ }
392403
393- if (!backend_target )
394- {
395- /* If the pib target is not a child target, look for the parent pib target
396- But the translation does not happen here. So better to */
397- while (1 )
404+ /* If the pib target is not a child target, look for the parent pib target
405+ But the translation does not happen here. So better to */
406+ if (!backend_target )
407+ {
408+ backend_target = target_parent (class_name , target , false);
409+ if (!backend_target )
398410 {
399- backend_target = target_parent (class_name , target , false);
400-
401- //TODO, check
402-
403- if (!backend_target )
404- {
405- pdbg_log (PDBG_ERROR , "unable to get %s target for %s\n" ,
406- class_name , pdbg_target_path (target ));
407- return NULL ;
408- }
411+ pdbg_log (PDBG_ERROR , "unable to get %s target for %s\n" ,
412+ class_name , pdbg_target_path (target ));
413+ return NULL ;
409414 }
410- }
411- return backend_target ;
415+ }
416+ return backend_target ;
412417}
413418
414- void pdbg_switch_node_backend (struct pdbg_target * target )
419+ struct pdbg_target * pdbg_switch_node_backend (struct pdbg_target * target , char * backend )
415420{
416421 struct pdbg_target * attached_pib_target = pdbg_get_backend_target (target ,"pib" );
417-
418- struct pdbg_target * unattached_pib_target = pdbg_get_unattached_backend_target (target ,"pib" );
422+ if (!attached_pib_target )
423+ {
424+ pdbg_log (PDBG_ERROR , "Failed to get attached PIB target\n" );
425+ return NULL ;
426+ }
419427
420- struct pdbg_target * virtual_target = target_to_virtual (attached_pib_target , true);
428+ if (backend != NULL && backend [0 ] != '\0' )
429+ {
430+ const char * cur_backend = pdbg_target_property (attached_pib_target , "backend" , NULL );
431+ if (strcmp (cur_backend , backend ) == 0 )
432+ {
433+ //The current backend is same as expected backend. return
434+ return attached_pib_target ;
435+ }
436+ }
421437
422- if (virtual_target && unattached_pib_target )
438+ struct pdbg_target * virtual_target = target_to_virtual (attached_pib_target , true);
439+ struct pdbg_target * new_pib_target = pdbg_get_unattached_backend_target (target ,"pib" );
440+
441+ if (virtual_target && new_pib_target )
423442 {
424- dt_link_virtual (virtual_target , unattached_pib_target );
443+ dt_link_virtual (virtual_target , new_pib_target );
425444 /*remove the virtual link as we have switched the backend*/
426445 attached_pib_target -> vnode = NULL ;
446+ return new_pib_target ;
427447 }
448+ return NULL ;
428449}
429450
0 commit comments