/* * Start from the current node and return the next node besides * the current one which has the requested model property. */ static Prom_node * dev_next_node_by_compat(Prom_node *root, char *compat) { Prom_node *node; if (root == NULL) return (NULL); /* look at your children first */ if ((node = dev_find_node_by_compat(root->child, compat)) != NULL) return (node); /* now look at your siblings */ if ((node = dev_find_node_by_compat(root->sibling, compat)) != NULL) return (node); return (NULL); /* not found */ }
/* * Do a depth-first walk of a device tree and * return the first node with the matching model. */ static Prom_node * dev_find_node_by_compat(Prom_node *root, char *compat) { Prom_node *node; char *compatible; char *name; if (root == NULL) return (NULL); if (compat == NULL) return (NULL); name = get_node_name(root); if (name == NULL) name = ""; compatible = (char *)get_prop_val(find_prop(root, "compatible")); if (compatible == NULL) return (NULL); if ((strcmp(name, "pci") == 0) && (compatible != NULL) && (strcmp(compatible, compat) == 0)) { return (root); /* found a match */ } /* look at your children first */ if ((node = dev_find_node_by_compat(root->child, compat)) != NULL) return (node); /* now look at your siblings */ if ((node = dev_find_node_by_compat(root->sibling, compat)) != NULL) return (node); return (NULL); /* not found */ }
static void display_schizo_revisions(Board_node *bdlist) { Prom_node *pnode; int *int_val; int portid; int prev_portid = -1; char *status_a = NULL; char *status_b = NULL; int revision; #ifdef DEBUG uint32_t a_notes, b_notes; #endif int pci_bus; Board_node *bnode; bnode = bdlist; while (bnode != NULL) { /* * search this board node for all Schizos */ for (pnode = dev_find_node_by_compat(bnode->nodes, SCHIZO_COMPAT_PROP); pnode != NULL; pnode = dev_next_node_by_compat(pnode, SCHIZO_COMPAT_PROP)) { /* * get the reg property to determine * whether we are looking at side A or B */ int_val = (int *)get_prop_val (find_prop(pnode, "reg")); if (int_val != NULL) { int_val ++; /* second integer in array */ pci_bus = ((*int_val) & 0x7f0000); } /* get portid */ int_val = (int *)get_prop_val (find_prop(pnode, "portid")); if (int_val == NULL) continue; portid = *int_val; /* * If this is a new portid and it is PCI bus B, * we skip onto the PCI bus A. */ if ((portid != prev_portid) && (pci_bus == 0x700000)) { prev_portid = portid; /* status */ status_b = (char *)get_prop_val (find_prop(pnode, "status")); #ifdef DEBUG b_notes = pci_bus; #endif continue; /* skip to the next schizo */ } /* * This must be side A of the same Schizo. * Gather all its props and display them. */ #ifdef DEBUG a_notes = pci_bus; #endif prev_portid = portid; int_val = (int *)get_prop_val (find_prop(pnode, "version#")); if (int_val != NULL) revision = *int_val; else revision = -1; status_a = (char *)get_prop_val(find_prop (pnode, "status")); log_printf(dgettext(TEXT_DOMAIN, "Schizo ")); log_printf(dgettext(TEXT_DOMAIN, "%-3d "), portid, 0); log_printf((status_a == NULL && status_b == NULL) ? dgettext(TEXT_DOMAIN, " ok ") : dgettext(TEXT_DOMAIN, " fail ")); log_printf(dgettext(TEXT_DOMAIN, " %4d "), revision); #ifdef DEBUG log_printf(" 0x%x 0x%x", a_notes, b_notes); #endif log_printf("\n"); } bnode = bnode->next; } }
/* * display_pci * Display all the PCI IO cards on this board. */ void display_pci(Board_node *board) { struct io_card *card_list = NULL; struct io_card card; void *value; Prom_node *pci; Prom_node *card_node; static int banner = FALSE; char *slot_name_arr[NUM_PCI_SLOTS]; int i; if (board == NULL) return; (void) memset(&card, 0, sizeof (struct io_card)); /* Initialize all the common information */ card.display = TRUE; card.board = board->board_num; /* * Search for each pci instance, then find/display all nodes under * each instance node found. */ for (pci = dev_find_node_by_compat(board->nodes, SCHIZO_COMPAT_PROP); pci != NULL; pci = dev_next_node_by_compat(pci, SCHIZO_COMPAT_PROP)) { (void) snprintf(card.bus_type, MAXSTRLEN, dgettext(TEXT_DOMAIN, "PCI")); /* * Get slot-name properties from parent node and * store them in an array. */ value = (char *)get_prop_val( find_prop(pci, "slot-names")); if (value != NULL) { /* array starts after first int */ slot_name_arr[0] = (char *)value + sizeof (int); for (i = 1; i < NUM_PCI_SLOTS; i++) { slot_name_arr[i] = (char *)slot_name_arr[i - 1] + strlen(slot_name_arr[i - 1]) +1; } } /* * Search for Children of this node ie. Cards. * Note: any of these cards can be a pci-bridge * that itself has children. If we find a * pci-bridge we need to handle it specially. */ card_node = pci->child; /* Generate the list of pci cards on pci instance: pci */ fill_pci_card_list(pci, card_node, &card, &card_list, slot_name_arr); } /* end-for */ if (!banner && card_list != NULL) { log_printf(dgettext(TEXT_DOMAIN, " Bus Max\n" " IO Port Bus Freq Bus Dev,\n" "Type ID Side Slot MHz Freq Func State " "Name Model" #ifdef DEBUG " Notes" #endif "\n" "---- ---- ---- ---- ---- ---- ---- ----- " "-------------------------------- " #ifdef DEBUG "---------------------- " #endif "----------------------\n")); banner = TRUE; } display_io_cards(card_list); free_io_cards(card_list); }