Skip to content

Commit 4e8db3b

Browse files
committed
Add Peer targets
1 parent 69bd7f9 commit 4e8db3b

File tree

5 files changed

+99
-24
lines changed

5 files changed

+99
-24
lines changed

libpdbg/device.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,36 @@ static void dt_link_virtual(struct pdbg_target *node, struct pdbg_target *vnode)
657657
vnode->vnode = node;
658658
}
659659

660+
static void dt_link_peer(struct pdbg_target *node, struct pdbg_target *pnode)
661+
{
662+
node->pnode = pnode;
663+
pnode->pnode = node;
664+
}
665+
666+
667+
static void pdbg_targets_init_peer(struct pdbg_target *node, struct pdbg_target *root)
668+
{
669+
struct pdbg_target *child = NULL;
670+
671+
/* Skip virtual nodes */
672+
if (target_is_virtual(node))
673+
goto skip;
674+
675+
struct pdbg_target *pnode = NULL;
676+
pnode = pdbg_get_peer_target(node);
677+
678+
if (!pnode)
679+
goto skip;
680+
681+
dt_link_peer(node, pnode);
682+
683+
skip:
684+
list_for_each(&node->children, child, list) {
685+
pdbg_targets_init_peer(child, root);
686+
}
687+
}
688+
689+
660690
static void pdbg_targets_init_virtual(struct pdbg_target *node, struct pdbg_target *root)
661691
{
662692
struct pdbg_target *vnode, *child = NULL;
@@ -803,6 +833,8 @@ bool pdbg_targets_init(void *fdt)
803833

804834
pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);
805835

836+
pdbg_targets_init_peer(pdbg_dt_root, pdbg_dt_root);
837+
806838
//Close any FDs which might be still opened
807839
close(dtb->system.fd);
808840
close(dtb->backend.fd);

libpdbg/libpdbg.c

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
static pdbg_progress_tick_t progress_tick;
88
static bool pdbg_short_context = false;
99

10+
#define MAX_PEER_TYPE_ENTRIES 3
11+
12+
typedef struct {
13+
char key[120];
14+
char value[120];
15+
} peer_map_struct;
16+
17+
peer_map_struct peer_map[MAX_PEER_TYPE_ENTRIES] = {
18+
{"tbusl", "tbusl"},
19+
{"core", "l3cache"},
20+
{"l3cache", "core"},
21+
};
22+
1023
struct pdbg_target *get_parent(struct pdbg_target *target, bool system)
1124
{
1225
struct pdbg_target *parent;
@@ -372,33 +385,61 @@ char* extract_string_after_colon(char* input)
372385
return "";
373386
}
374387

388+
389+
// Function to get peer class name
390+
const char* get_peer_class_name(const char *key) {
391+
392+
for (int i = 0; i < MAX_PEER_TYPE_ENTRIES; i++) {
393+
if (strcmp(peer_map[i].key, key) == 0) {
394+
return peer_map[i].value;
395+
}
396+
}
397+
return NULL; // Key not found
398+
}
399+
400+
struct pdbg_target *pdbg_get_pnode(struct pdbg_target *target)
401+
{
402+
return target->pnode;
403+
}
404+
375405
struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target)
376406
{
377-
char tgtPeerPath[120];
378-
if (!pdbg_target_get_attribute(target, "ATTR_PEER_PATH", 1, 120,
379-
tgtPeerPath)) {
380-
//unable to find the path
381-
pdbg_log(PDBG_ERROR, "unable to find the attribute ATTR_PEER_PATH for %s\n",
382-
pdbg_target_path(target));
383-
}
384-
else
407+
//Get the class type to find its appropriate peer
408+
const char* peer_class_name = get_peer_class_name(target->class);
409+
410+
//As get attr is an expensive operation, check if the current class
411+
//is expected to have a peer class
412+
if(peer_class_name)
385413
{
386-
struct pdbg_target *same_class_target;
387-
//The peer could only be of the same type, so look for all the targets of that type
388-
pdbg_for_each_class_target(target->class, same_class_target)
414+
char tgtPeerPath[120];
415+
if (!pdbg_target_get_attribute(target, "ATTR_PEER_PATH", 1, 120,
416+
tgtPeerPath)) {
417+
//unable to find the path
418+
pdbg_log(PDBG_ERROR, "unable to find the attribute ATTR_PEER_PATH for %s\n",
419+
pdbg_target_path(target));
420+
}
421+
else
389422
{
390-
char tgtPhyPath[120];
391-
if (pdbg_target_get_attribute(same_class_target, "ATTR_PHYS_DEV_PATH", 1, 120,
392-
tgtPhyPath)) {
393-
//unable to find the path
394-
if( strcmp(extract_string_after_colon(tgtPhyPath), extract_string_after_colon(tgtPeerPath)) == 0)
395-
{
396-
return same_class_target;
423+
struct pdbg_target *traversed_target;
424+
//The peer could only be of the same type, so look for all the targets of that type
425+
pdbg_for_each_class_target(peer_class_name, traversed_target)
426+
{
427+
char tgtPhyPath[120];
428+
if (pdbg_target_get_attribute(traversed_target, "ATTR_PHYS_DEV_PATH", 1, 120,
429+
tgtPhyPath)) {
430+
//unable to find the path
431+
if( strcmp(extract_string_after_colon(tgtPhyPath), extract_string_after_colon(tgtPeerPath)) == 0)
432+
{
433+
return traversed_target;
434+
}
397435
}
398436
}
437+
399438
}
439+
pdbg_log(PDBG_ERROR, "unable to find the peer target for %s\n",
440+
pdbg_target_path(target));
400441
}
401-
pdbg_log(PDBG_ERROR, "unable to find the peer target for %s\n",
402-
pdbg_target_path(target));
442+
pdbg_log(PDBG_ERROR, "Peer class not identified for target class :: %s\n",
443+
target->class);
403444
return NULL;
404445
}

libpdbg/libpdbg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_ta
343343
*/
344344
struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target);
345345

346+
struct pdbg_target *pdbg_get_pnode(struct pdbg_target *target);
347+
346348
/**
347349
* @brief Overwrite the given property in device tree
348350
* @param[in] target pdbg_target to set the property on

libpdbg/target.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ int opb_write(struct pdbg_target *opb_dt, uint32_t addr, uint32_t data)
327327

328328
int fsi_read(struct pdbg_target *fsi_dt, uint32_t addr, uint32_t *data)
329329
{
330+
330331
struct fsi *fsi;
331332
int rc;
332333
uint64_t addr64 = addr;
333-
334334
fsi_dt = get_class_target_addr(fsi_dt, "fsi", &addr64);
335335
fsi = target_to_fsi(fsi_dt);
336336

@@ -350,10 +350,8 @@ int fsi_write(struct pdbg_target *fsi_dt, uint32_t addr, uint32_t data)
350350
struct fsi *fsi;
351351
int rc;
352352
uint64_t addr64 = addr;
353-
354353
fsi_dt = get_class_target_addr(fsi_dt, "fsi", &addr64);
355354
fsi = target_to_fsi(fsi_dt);
356-
357355
if (!fsi->write) {
358356
PR_ERROR("write() not implemented for the target\n");
359357
return -1;
@@ -689,7 +687,6 @@ enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target)
689687
enum pdbg_target_status status;
690688

691689
assert(target);
692-
693690
status = pdbg_target_status(target);
694691
assert(status != PDBG_TARGET_RELEASED);
695692

@@ -740,7 +737,9 @@ enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target)
740737
/* Make sure any virtual nodes are also probed */
741738
vnode = target_to_virtual(target, true);
742739
if (vnode)
740+
{
743741
pdbg_target_probe(vnode);
742+
}
744743

745744
/* At this point any parents must exist and have already been probed */
746745
if (target->probe && target->probe(target)) {

libpdbg/target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct pdbg_target {
6262
struct list_node class_link;
6363
void *priv;
6464
struct pdbg_target *vnode;
65+
struct pdbg_target *pnode;
6566
};
6667

6768
struct pdbg_mfile {

0 commit comments

Comments
 (0)