Changeset 16529d5 in mainline


Ignore:
Timestamp:
2006-09-20T20:31:44Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
28ecadb
Parents:
61e90dd
Message:

More ofw_tree work and fixes.
Add ofw_tree_lookup().
Every ofw_tree_node now also contains a disambigued name which is essential for tree lookups.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • boot/genarch/ofw.c

    r61e90dd r16529d5  
    115115}
    116116
    117 int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
     117int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen)
    118118{
    119119        return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
     
    128128{
    129129        return ofw_call("nextprop", 3, 1, NULL, device, previous, buf);
     130}
     131
     132int ofw_package_to_path(const phandle device, char *buf, const int buflen)
     133{
     134        return ofw_call("package-to-path", 3, 1, NULL, device, buf, buflen);
    130135}
    131136
  • boot/genarch/ofw.h

    r61e90dd r16529d5  
    103103extern void ofw_write(const char *str, const int len);
    104104
    105 extern int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen);
     105extern int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen);
    106106extern int ofw_get_proplen(const phandle device, const char *name);
    107107extern int ofw_next_property(const phandle device, char *previous, char *buf);
     
    110110extern phandle ofw_get_peer_node(const phandle node);
    111111extern phandle ofw_find_device(const char *name);
     112
     113extern int ofw_package_to_path(const phandle device, char *buf, const int buflen);
    112114
    113115extern int ofw(ofw_args_t *arg);
  • boot/genarch/ofw_tree.c

    r61e90dd r16529d5  
    3232#include <string.h>
    3333#include <balloc.h>
     34#include <asm.h>
     35
     36#define MAX_PATH_LEN    256
    3437
    3538static ofw_tree_node_t *ofw_tree_node_alloc(void)
     
    6265        ofw_tree_node_t *parent_node, phandle current)
    6366{
     67        static char path[MAX_PATH_LEN+1];
     68        static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
    6469        phandle peer;
    6570        phandle child;
    6671        unsigned properties = 0;
    67         char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
     72        size_t len;
     73        int i;
    6874
    6975        /*
     
    7783       
    7884        /*
     85         * Get the disambigued name.
     86         */
     87        len = ofw_package_to_path(current, path, MAX_PATH_LEN);
     88        if (len == -1)
     89                return;
     90       
     91        path[len] = '\0';
     92        for (i = len - 1; i >= 0 && path[i] != '/'; i--)
     93                ;
     94        i++;                                                            /* do not include '/' */
     95       
     96        len -= i;
     97        current_node->da_name = ofw_tree_space_alloc(len + 1);          /* add space for trailing '\0' */
     98        if (!current_node->da_name)
     99                return;
     100       
     101        memcpy(current_node->da_name, &path[i], len);
     102        current_node->da_name[len] = '\0';
     103       
     104        /*
    79105         * Recursively process the potential peer node.
    80106         */
     
    85111                peer_node = ofw_tree_node_alloc();
    86112                if (peer_node) {
    87                         ofw_tree_node_process(peer_node, current_node, peer);
     113                        ofw_tree_node_process(peer_node, parent_node, peer);
    88114                        current_node->peer = peer_node;
    89115                }
     
    121147                return;
    122148               
    123         int i = 0;
    124 
    125149        name[0] = '\0';
    126150        for (i = 0; ofw_next_property(current, name, name) == 1; i++) {
  • boot/genarch/ofw_tree.h

    r61e90dd r16529d5  
    4444        ofw_tree_node_t *child;
    4545
     46        char *da_name;                          /**< Disambigued name. */
     47
    4648        unsigned properties;                    /**< Number of properties. */
    4749        ofw_tree_property_t *property;
  • kernel/arch/sparc64/Makefile.inc

    r61e90dd r16529d5  
    6161CONFIG_FB = y
    6262
     63## Compile with support for OpenFirmware device tree.
     64#
     65
     66CONFIG_OFW_TREE = y
    6367
    6468ifeq ($(MACHINE),enterprise)
  • kernel/arch/sparc64/src/sparc64.c

    r61e90dd r16529d5  
    4646#include <arch/mm/page.h>
    4747#include <arch/stack.h>
     48#include <genarch/ofw/ofw_tree.h>
    4849#include <userspace.h>
    4950
     
    6566        ballocs.base = bootinfo.ballocs.base;
    6667        ballocs.size = bootinfo.ballocs.size;
     68       
     69        ofw_tree_init(bootinfo.ofw_root);
    6770}
    6871
  • kernel/genarch/Makefile.inc

    r61e90dd r16529d5  
    9393ifeq ($(CONFIG_OFW_TREE), y)
    9494        GENARCH_SOURCES += \
    95                 genarch/src/ofw/ofw_tree,c
     95                genarch/src/ofw/ofw_tree.c
    9696endif
  • kernel/genarch/include/ofw/ofw_tree.h

    r61e90dd r16529d5  
    3131
    3232#include <arch/types.h>
     33#include <typedefs.h>
    3334
    3435#define OFW_TREE_PROPERTY_MAX_NAMELEN   32
     
    4344        ofw_tree_node_t *child;
    4445
    45         unsigned properties;                    /**< Number of properties. */
     46        char *da_name;                                  /**< Disambigued name. */
     47
     48        unsigned properties;                            /**< Number of properties. */
    4649        ofw_tree_property_t *property;
    4750};
     
    5457};
    5558
     59extern void ofw_tree_init(ofw_tree_node_t *root);
     60extern void ofw_tree_print(void);
     61extern const char *ofw_tree_node_name(const ofw_tree_node_t *node);
     62extern ofw_tree_node_t *ofw_tree_lookup(const char *path);
     63
    5664#endif
  • kernel/genarch/src/ofw/ofw_tree.c

    r61e90dd r16529d5  
    3636 */
    3737
     38#include <genarch/ofw/ofw_tree.h>
     39#include <arch/memstr.h>
     40#include <func.h>
     41#include <print.h>
     42#include <panic.h>
     43
     44#define PATH_MAX_LEN    80
     45#define NAME_BUF_LEN    50
     46
     47static ofw_tree_node_t *ofw_root;
     48
     49void ofw_tree_init(ofw_tree_node_t *root)
     50{
     51        ofw_root = root;
     52}
     53
     54/** Return value of the 'name' property.
     55 *
     56 * @param node Node of interest.
     57 *
     58 * @return Value of the 'name' property belonging to the node.
     59 */
     60const char *ofw_tree_node_name(const ofw_tree_node_t *node)
     61{
     62        int i;
     63       
     64        for (i = 0; i < node->properties; i++) {
     65                if (strncmp(node->property[i].name, "name", strlen("name")) == 0) {
     66                        if (node->property[i].size < 2)
     67                                panic("Invalid name property.\n");
     68                        return node->property[i].value;
     69                }
     70        }
     71       
     72        panic("Node without name property.\n");
     73}
     74
     75/** Lookup child of given name.
     76 *
     77 * @param node Node whose child is being looked up.
     78 * @param da_name Disambigued name of the child being looked up.
     79 *
     80 * @return NULL if there is no such child or pointer to the matching child node.
     81 */
     82static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *da_name)
     83{
     84        ofw_tree_node_t *cur;
     85       
     86        for (cur = node->child; cur; cur = cur->peer) {
     87                if (strncmp(cur->da_name, da_name, strlen(da_name)) == 0)
     88                        return cur;
     89        }
     90       
     91        return NULL;
     92}
     93
     94/** Lookup OpenFirmware node by its path.
     95 *
     96 * @param path Path to the node.
     97 *
     98 * @return NULL if there is no such node or pointer to the leaf node.
     99 */
     100ofw_tree_node_t *ofw_tree_lookup(const char *path)
     101{
     102        char buf[NAME_BUF_LEN+1];
     103        ofw_tree_node_t *node = ofw_root;
     104        index_t i, j;
     105       
     106        if (path[0] != '/')
     107                return NULL;
     108       
     109        for (i = 1; i < strlen(path) && node; i = j + 1) {
     110                for (j = i; j < strlen(path) && path[j] != '/'; j++)
     111                        ;
     112                if (i == j)     /* skip extra slashes */
     113                        continue;
     114                       
     115                memcpy(buf, &path[i], j - i);
     116                buf[j - i] = '\0';
     117                node = ofw_tree_find_child(node, buf);
     118        }
     119       
     120        return node;
     121}
     122
     123/** Recursively print subtree rooted in a node.
     124 *
     125 * @param node Root of the subtree.
     126 * @param path Current path, NULL for the very root of the entire tree.
     127 */
     128static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path)
     129{
     130        char p[PATH_MAX_LEN];
     131       
     132        if (node->parent) {
     133                snprintf(p, PATH_MAX_LEN, "%s/%s", path, node->da_name);
     134                printf("%s\n", p);
     135        } else {
     136                snprintf(p, PATH_MAX_LEN, "%s", node->da_name);
     137                printf("/\n");
     138        }
     139
     140        if (node->child)
     141                ofw_tree_node_print(node->child, p);
     142       
     143        if (node->peer)
     144                ofw_tree_node_print(node->peer, path);
     145}
     146
     147/** Print the structure of the OpenFirmware device tree. */
     148void ofw_tree_print(void)
     149{
     150        ofw_tree_node_print(ofw_root, NULL);
     151}
     152
    38153/** @}
    39154 */
Note: See TracChangeset for help on using the changeset viewer.