Changeset 28ecadb in mainline


Ignore:
Timestamp:
2006-09-22T21:44:54Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5d684e4
Parents:
16529d5
Message:

Convert sparc64 to detect keyboard and determine
its physical address by walking the memory representation
of the OpenFirmware device tree.

Add bus-specific functions that know how to apply the
"ranges" property to one component of the "reg" property.
Buses supported so far include FHC, EBUS and PCI.

Files:
3 added
27 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/sparc64/loader/main.c

    r16529d5 r28ecadb  
    6666        bootinfo.screen.scanline = bootinfo.screen.scanline*bpp2align[bootinfo.screen.bpp >> 3];
    6767       
    68         if (!ofw_keyboard(&bootinfo.keyboard))
    69                 printf("Error: unable to get keyboard properties\n");
    70 
    7168        if (!ofw_cpu(&bootinfo.cpu))
    7269                printf("Error: unable to get cpu properties\n");
     
    7673        printf(" memory: %dM\n", bootinfo.memmap.total>>20);
    7774        printf(" screen at %P, resolution %dx%d, %d bpp (scanline %d bytes)\n", (uintptr_t) bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);
    78         printf(" keyboard at %P (size %d bytes)\n", (uintptr_t) bootinfo.keyboard.addr, bootinfo.keyboard.size);
    7975
    8076        printf("\nMemory statistics\n");
  • boot/arch/sparc64/loader/main.h

    r16529d5 r28ecadb  
    5555        memmap_t memmap;
    5656        screen_t screen;
    57         keyboard_t keyboard;
    5857        cpu_t cpu;
    5958        ballocs_t ballocs;
  • boot/arch/sparc64/loader/ofwarch.c

    r16529d5 r28ecadb  
    9696        for (; node != 0 && node != -1; node = ofw_get_peer_node(node)) {
    9797                if (ofw_get_property(node, "device_type", type_name, sizeof(type_name)) > 0) {
    98                         if (strncmp(type_name, "cpu", 3) == 0) {
     98                        if (strcmp(type_name, "cpu") == 0) {
    9999                                uint32_t mhz;
    100100                               
  • boot/genarch/ofw_tree.c

    r16529d5 r28ecadb  
    4848static void * ofw_tree_space_alloc(size_t size)
    4949{
    50         return balloc(size, size);
     50        char *addr;
     51
     52        /*
     53         * What we do here is a nasty hack :-)
     54         * Problem: string property values that are allocated via this
     55         * function typically do not contain the trailing '\0'. This
     56         * is very uncomfortable for kernel, which is supposed to deal
     57         * with the properties.
     58         * Solution: when allocating space via this function, we always
     59         * allocate space for the extra '\0' character that we store
     60         * behind the requested memory.
     61         */
     62        addr = balloc(size + 1, size);
     63        if (addr)
     64                addr[size] = '\0';
     65        return addr;
    5166}
    5267
     
    154169                        break;
    155170               
    156                 strncpy(current_node->property[i].name, name, sizeof(name));
     171                memcpy(current_node->property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN);
     172                current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
    157173
    158174                size = ofw_get_proplen(current, name);
  • boot/generic/string.c

    r16529d5 r28ecadb  
    5858 * Do a char-by-char comparison of two NULL terminated strings.
    5959 * The strings are considered equal iff they consist of the same
     60 * characters on the minimum of their lengths.
     61 *
     62 * @param src First string to compare.
     63 * @param dst Second string to compare.
     64 *
     65 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
     66 *
     67 */
     68int strcmp(const char *src, const char *dst)
     69{
     70        for (; *src && *dst; src++, dst++) {
     71                if (*src < *dst)
     72                        return -1;
     73                if (*src > *dst)
     74                        return 1;
     75        }
     76        if (*src == *dst)
     77                return 0;
     78        if (!*src)
     79                return -1;
     80        return 1;
     81}
     82
     83
     84/** Compare two NULL terminated strings
     85 *
     86 * Do a char-by-char comparison of two NULL terminated strings.
     87 * The strings are considered equal iff they consist of the same
    6088 * characters on the minimum of their lengths and specified maximal
    6189 * length.
     
    72100        int i;
    73101       
    74         i = 0;
    75         for (;*src && *dst && i < len;src++,dst++,i++) {
     102        for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
    76103                if (*src < *dst)
    77104                        return -1;
  • boot/generic/string.h

    r16529d5 r28ecadb  
    3939
    4040extern size_t strlen(const char *str);
     41extern int strcmp(const char *src, const char *dst);
    4142extern int strncmp(const char *src, const char *dst, size_t len);
    4243extern void strncpy(char *dest, const char *src, size_t len);
  • kernel/Makefile

    r16529d5 r28ecadb  
    8282ifeq ($(CONFIG_TSB),y)
    8383        DEFS += -DCONFIG_TSB
     84endif
     85
     86ifeq ($(CONFIG_Z8530),y)
     87        DEFS += -DCONFIG_Z8530
     88endif
     89
     90ifeq ($(CONFIG_NS16550),y)
     91        DEFS += -DCONFIG_NS16550
    8492endif
    8593
  • kernel/arch/sparc64/Makefile.inc

    r16529d5 r28ecadb  
    6161CONFIG_FB = y
    6262
     63## Compile with support for Sun keyboard.
     64#
     65
     66CONFIG_SUN_KBD = y
     67
    6368## Compile with support for OpenFirmware device tree.
    6469#
    6570
    6671CONFIG_OFW_TREE = y
    67 
    68 ifeq ($(MACHINE),enterprise)
    69         ## Compile with support for z8530 controller.
    70         #
    71 
    72         CONFIG_Z8530 = y
    73         DEFS += -DCONFIG_Z8530
    74 endif
    75 ifeq ($(MACHINE),ultra)
    76         ## Compile with support for ns16550 controller.
    77         #
    78        
    79         CONFIG_NS16550 = y
    80         DEFS += -DCONFIG_NS16550
    81        
    82         DEFS += -DKBD_ADDR_OVRD=0x1fff13083f8ULL
    83        
    84 endif
    85 
    8672
    8773ARCH_SOURCES = \
  • kernel/arch/sparc64/include/boot/boot.h

    r16529d5 r28ecadb  
    8080
    8181typedef struct {
    82         uintptr_t addr;
    83         uint32_t size;
    84 } keyboard_t;
    85 
    86 typedef struct {
    8782        uint32_t clock_frequency;
    8883} processor_t;
     
    9691        memmap_t memmap;
    9792        screen_t screen;
    98         keyboard_t keyboard;
    9993        processor_t processor;
    10094        ballocs_t ballocs;
  • kernel/arch/sparc64/include/drivers/kbd.h

    r16529d5 r28ecadb  
    3737
    3838#include <arch/types.h>
     39#include <genarch/ofw/ofw_tree.h>
     40
     41typedef enum {
     42        KBD_UNKNOWN,
     43        KBD_Z8530,
     44        KBD_NS16550
     45} kbd_type_t;
     46
     47extern kbd_type_t kbd_type;
    3948
    4049extern volatile uint8_t *kbd_virt_address;
    4150
    42 extern void kbd_init(void);
     51extern void kbd_init(ofw_tree_node_t *node);
    4352
    4453#endif
  • kernel/arch/sparc64/src/console.c

    r16529d5 r28ecadb  
    5454#include <arch/mm/tlb.h>
    5555#include <arch/boot/boot.h>
     56#include <genarch/ofw/ofw_tree.h>
    5657#include <arch.h>
     58#include <panic.h>
     59#include <print.h>
    5760
    5861#define KEYBOARD_POLL_PAUSE     50000   /* 50ms */
     
    6265{
    6366        stdin = NULL;
    64                
     67
     68        ofw_tree_node_t *aliases;
     69        ofw_tree_property_t *prop;
     70        ofw_tree_node_t *screen;
     71        ofw_tree_node_t *keyboard;
     72       
     73        aliases = ofw_tree_lookup("/aliases");
     74        if (!aliases)
     75                panic("Can't find /aliases.\n");
     76       
     77        prop = ofw_tree_getprop(aliases, "screen");
     78        if (!prop)
     79                panic("Can't find property \"screen\".\n");
     80        if (!prop->value)
     81                panic("Can't find screen alias.\n");
     82        screen = ofw_tree_lookup(prop->value);
     83        if (!screen)
     84                panic("Can't find %s\n", prop->value);
     85
    6586        fb_init(bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height,
    6687                bootinfo.screen.bpp, bootinfo.screen.scanline, true);
     88       
     89        prop = ofw_tree_getprop(aliases, "keyboard");
     90        if (!prop)
     91                panic("Can't find property \"keyboard\".\n");
     92        if (!prop->value)
     93                panic("Can't find keyboard alias.\n");
     94        keyboard = ofw_tree_lookup(prop->value);
     95        if (!keyboard)
     96                panic("Can't find %s\n", prop->value);
    6797
    68 #ifdef KBD_ADDR_OVRD
    69         if (!bootinfo.keyboard.addr)
    70                 bootinfo.keyboard.addr = KBD_ADDR_OVRD;
    71 #endif
    72 
    73         if (bootinfo.keyboard.addr)
    74                 kbd_init();
     98        kbd_init(keyboard);
    7599}
    76100
     
    83107        thread_detach(THREAD);
    84108
    85         if (!bootinfo.keyboard.addr)
    86                 return;
    87                
    88         while (1) {
    89109#ifdef CONFIG_Z8530
     110        if (kbd_type == KBD_Z8530)
    90111                return;
    91112#endif
     113
     114        while (1) {
    92115#ifdef CONFIG_NS16550
    93                 ns16550_poll();
     116                if (kbd_type == KBD_NS16550)
     117                        ns16550_poll();
    94118#endif
    95119                thread_usleep(KEYBOARD_POLL_PAUSE);
     
    103127{
    104128#ifdef CONFIG_Z8530
    105         z8530_grab();
     129        if (kbd_type == KBD_Z8530)
     130                z8530_grab();
    106131#endif
    107132}
     
    113138{
    114139#ifdef CONFIG_Z8530
    115         z8530_release();
     140        if (kbd_type == KBD_Z8530)
     141                z8530_release();
    116142#endif
    117143}
  • kernel/arch/sparc64/src/drivers/kbd.c

    r16529d5 r28ecadb  
    3434
    3535#include <arch/drivers/kbd.h>
     36#include <genarch/ofw/ofw_tree.h>
    3637#ifdef CONFIG_Z8530
    3738#include <genarch/kbd/z8530.h>
     
    4142#endif
    4243
    43 #include <arch/boot/boot.h>
    4444#include <arch/mm/page.h>
    4545#include <arch/types.h>
    4646#include <typedefs.h>
    4747#include <align.h>
     48#include <func.h>
     49#include <print.h>
    4850
    4951volatile uint8_t *kbd_virt_address = NULL;
    5052
    51 void kbd_init()
     53kbd_type_t kbd_type = KBD_UNKNOWN;
     54
     55/** Initialize keyboard.
     56 *
     57 * Traverse OpenFirmware device tree in order to find necessary
     58 * info about the keyboard device.
     59 *
     60 * @param node Keyboard device node.
     61 */
     62void kbd_init(ofw_tree_node_t *node)
    5263{
    5364        size_t offset;
    5465        uintptr_t aligned_addr;
    55 
    56         /* FIXME: supply value read from OpenFirmware */
    57         bootinfo.keyboard.size = 8;
    58 
     66        ofw_tree_property_t *prop;
     67        const char *name;
     68       
     69        name = ofw_tree_node_name(node);
     70       
     71        if (strcmp(name, "zs") == 0)
     72                kbd_type = KBD_Z8530;
     73        else if (strcmp(name, "su") == 0)
     74                kbd_type = KBD_NS16550;
     75       
     76        if (kbd_type == KBD_UNKNOWN) {
     77                printf("Unknown keyboard device.\n");
     78                return;
     79        }
     80       
     81        prop = ofw_tree_getprop(node, "reg");
     82        if (!prop)
     83                panic("Can't find \"reg\" property.\n");
     84       
     85        uintptr_t pa;
     86        size_t size;
     87       
     88        switch (kbd_type) {
     89        case KBD_Z8530:
     90                size = ((ofw_fhc_reg_t *) prop->value)->size;
     91                if (!ofw_fhc_apply_ranges(node->parent, ((ofw_fhc_reg_t *) prop->value) , &pa)) {
     92                        printf("Failed to determine keyboard address.\n");
     93                        return;
     94                }
     95                break;
     96        case KBD_NS16550:
     97                size = ((ofw_ebus_reg_t *) prop->value)->size;
     98                if (!ofw_ebus_apply_ranges(node->parent, ((ofw_ebus_reg_t *) prop->value) , &pa)) {
     99                        printf("Failed to determine keyboard address.\n");
     100                        return;
     101                }
     102                break;
     103        default:
     104                panic("Unexpected type.\n");
     105        }
     106       
    59107        /*
    60108         * We need to pass aligned address to hw_map().
    61109         * However, the physical keyboard address can
    62          * be pretty much unaligned on some systems
    63          * (e.g. Ultra 5, Ultra 60).
     110         * be pretty much unaligned, depending on the
     111         * underlying controller.
    64112         */
    65         aligned_addr = ALIGN_DOWN(bootinfo.keyboard.addr, PAGE_SIZE);
    66         offset = bootinfo.keyboard.addr - aligned_addr;
    67         kbd_virt_address = (uint8_t *) hw_map(aligned_addr, offset + bootinfo.keyboard.size) + offset;
     113        aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
     114        offset = pa - aligned_addr;
     115        kbd_virt_address = (uint8_t *) hw_map(aligned_addr, offset + size) + offset;
    68116
     117        switch (kbd_type) {
    69118#ifdef CONFIG_Z8530
    70         z8530_init();
     119        case KBD_Z8530:
     120                z8530_init();
     121                break;
    71122#endif
    72123#ifdef CONFIG_NS16550
    73         ns16550_init();
     124        case KBD_NS16550:
     125                ns16550_init();
     126                break;
    74127#endif
     128        default:
     129                printf("Kernel is not compiled with the necessary keyboard driver this machine requires.\n");
     130        }
    75131}
    76132
  • kernel/arch/sparc64/src/trap/interrupt.c

    r16529d5 r28ecadb  
    3737#include <interrupt.h>
    3838#include <arch/drivers/fhc.h>
     39#include <arch/drivers/kbd.h>
    3940#include <typedefs.h>
    4041#include <arch/types.h>
     
    6364{
    6465#ifdef CONFIG_Z8530
    65         z8530_belongs_to_kernel = false;
     66        if (kbd_type == KBD_Z8530)
     67                z8530_belongs_to_kernel = false;
    6668#endif
    6769}
     
    7880#ifdef CONFIG_Z8530
    7981        case Z8530_INTRCV_DATA0:
     82                if (kbd_type != KBD_Z8530)
     83                        break;
    8084                /*
    8185                 * So far, we know we got this interrupt through the FHC.
  • kernel/genarch/Makefile.inc

    r16529d5 r28ecadb  
    7373endif
    7474
     75## Sun keyboard
     76ifeq ($(CONFIG_SUN_KBD),y)
     77        GENARCH_SOURCES += \
     78                genarch/src/kbd/key.c \
     79                genarch/src/kbd/scanc_sun.c
     80endif
     81
    7582## z8530 controller
    7683ifeq ($(CONFIG_Z8530),y)
    7784        GENARCH_SOURCES += \
    78                 genarch/src/kbd/z8530.c \
    79                 genarch/src/kbd/key.c \
    80                 genarch/src/kbd/scanc_sun.c
     85                genarch/src/kbd/z8530.c
    8186endif
    8287
     
    8489ifeq ($(CONFIG_NS16550),y)
    8590        GENARCH_SOURCES += \
    86                 genarch/src/kbd/ns16550.c \
    87                 genarch/src/kbd/key.c \
    88                 genarch/src/kbd/scanc_sun.c
     91                genarch/src/kbd/ns16550.c
    8992endif
    9093
     
    9396ifeq ($(CONFIG_OFW_TREE), y)
    9497        GENARCH_SOURCES += \
    95                 genarch/src/ofw/ofw_tree.c
     98                genarch/src/ofw/ofw_tree.c \
     99                genarch/src/ofw/ebus.c \
     100                genarch/src/ofw/fhc.c \
     101                genarch/src/ofw/pci.c
    96102endif
  • kernel/genarch/include/kbd/i8042.h

    r16529d5 r28ecadb  
    3636#define KERN_I8042_H_
    3737
     38#include <typedefs.h>
     39
    3840extern void i8042_init(void);
    3941extern void i8042_poll(void);
    4042extern void i8042_grab(void);
    4143extern void i8042_release(void);
     44extern char i8042_key_read(chardev_t *d);
    4245
    4346#endif
  • kernel/genarch/include/kbd/key.h

    r16529d5 r28ecadb  
    5050extern void active_read_key_pressed(uint8_t sc);
    5151
    52 extern char key_read(chardev_t *d);
    53 
    5452#endif
    5553
  • kernel/genarch/include/kbd/ns16550.h

    r16529d5 r28ecadb  
    3838#define KERN_NS16550_H_
    3939
     40#include <typedefs.h>
     41
    4042extern void ns16550_init(void);
    4143extern void ns16550_poll(void);
    4244extern void ns16550_grab(void);
    4345extern void ns16550_release(void);
     46extern char ns16550_key_read(chardev_t *d);
    4447
    4548#endif
  • kernel/genarch/include/kbd/z8530.h

    r16529d5 r28ecadb  
    4949extern void z8530_release(void);
    5050extern void z8530_interrupt(void);
     51extern char z8530_key_read(chardev_t *d);
    5152
    5253#endif
  • kernel/genarch/include/ofw/ofw_tree.h

    r16529d5 r28ecadb  
    5757};
    5858
     59/*
     60 * Definition of 'reg' and 'ranges' properties for various buses.
     61 */
     62 
     63struct ofw_fhc_reg {
     64        uint64_t addr;
     65        uint32_t size;
     66} __attribute__ ((packed));
     67typedef struct ofw_fhc_reg ofw_fhc_reg_t;
     68                       
     69struct ofw_fhc_range {
     70        uint64_t child_base;
     71        uint64_t parent_base;
     72        uint32_t size;
     73} __attribute__ ((packed));
     74typedef struct ofw_fhc_range ofw_fhc_range_t;
     75
     76struct ofw_central_reg {
     77        uint64_t addr;
     78        uint32_t size;
     79} __attribute__ ((packed));
     80typedef struct ofw_central_reg ofw_central_reg_t;
     81
     82struct ofw_central_range {
     83        uint64_t child_base;
     84        uint64_t parent_base;
     85        uint32_t size;
     86} __attribute__ ((packed));
     87typedef struct ofw_central_range ofw_central_range_t;
     88
     89struct ofw_ebus_reg {
     90        uint32_t space;
     91        uint32_t addr;
     92        uint32_t size;
     93} __attribute__ ((packed));
     94typedef struct ofw_ebus_reg ofw_ebus_reg_t;
     95
     96struct ofw_ebus_range {
     97        uint32_t child_space;
     98        uint32_t child_base;
     99        uint32_t parent_space;
     100        uint64_t parent_base;           /* group phys.mid and phys.lo together */
     101        uint32_t size;
     102} __attribute__ ((packed));
     103typedef struct ofw_ebus_range ofw_ebus_range_t;
     104
     105struct ofw_pci_reg {
     106        uint32_t space;                 /* needs to masked to obtain pure space id */
     107        uint64_t addr;                  /* group phys.mid and phys.lo together */
     108        uint64_t size;
     109} __attribute__ ((packed));
     110typedef struct ofw_pci_reg ofw_pci_reg_t;
     111
     112struct ofw_pci_range {
     113        uint32_t space;
     114        uint64_t child_base;            /* group phys.mid and phys.lo together */
     115        uint64_t parent_base;
     116        uint64_t size;
     117} __attribute__ ((packed));
     118typedef struct ofw_pci_range ofw_pci_range_t;
     119
     120struct ofw_ffb_reg {
     121} __attribute__ ((packed));
     122typedef struct ofw_ffb_reg ofw_ffb_reg_t;
     123
    59124extern void ofw_tree_init(ofw_tree_node_t *root);
    60125extern void ofw_tree_print(void);
    61126extern const char *ofw_tree_node_name(const ofw_tree_node_t *node);
    62127extern ofw_tree_node_t *ofw_tree_lookup(const char *path);
     128extern ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name);
     129
     130extern bool ofw_fhc_apply_ranges(ofw_tree_node_t *node, ofw_fhc_reg_t *reg, uintptr_t *pa);
     131extern bool ofw_central_apply_ranges(ofw_tree_node_t *node, ofw_central_reg_t *reg, uintptr_t *pa);
     132extern bool ofw_ebus_apply_ranges(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uintptr_t *pa);
     133extern bool ofw_pci_apply_ranges(ofw_tree_node_t *node, ofw_pci_reg_t *reg, uintptr_t *pa);
     134extern bool ofw_ffb_apply_ranges(ofw_tree_node_t *node, ofw_ffb_reg_t *reg, uintptr_t *pa);
    63135
    64136#endif
  • kernel/genarch/src/kbd/i8042.c

    r16529d5 r28ecadb  
    8181static void i8042_resume(chardev_t *);
    8282
    83 chardev_t kbrd;
    8483static chardev_operations_t ops = {
    8584        .suspend = i8042_suspend,
    8685        .resume = i8042_resume,
    87         .read = key_read
     86        .read = i8042_key_read
    8887};
    8988
     
    174173}
    175174
    176 char key_read(chardev_t *d)
     175char i8042_key_read(chardev_t *d)
    177176{
    178177        char ch;       
  • kernel/genarch/src/kbd/key.c

    r16529d5 r28ecadb  
    5454#define ACTIVE_READ_BUFF_SIZE 16        /* Must be power of 2 */
    5555
     56chardev_t kbrd;
     57
    5658static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
    5759
  • kernel/genarch/src/kbd/ns16550.c

    r16529d5 r28ecadb  
    6060static void ns16550_resume(chardev_t *);
    6161
    62 chardev_t kbrd;
    6362static chardev_operations_t ops = {
    6463        .suspend = ns16550_suspend,
    6564        .resume = ns16550_resume,
    66         .read = key_read
     65        .read = ns16550_key_read
    6766};
    6867
     
    119118}
    120119
    121 char key_read(chardev_t *d)
     120char ns16550_key_read(chardev_t *d)
    122121{
    123122        char ch;       
  • kernel/genarch/src/kbd/z8530.c

    r16529d5 r28ecadb  
    6363static void z8530_resume(chardev_t *);
    6464
    65 chardev_t kbrd;
    6665static chardev_operations_t ops = {
    6766        .suspend = z8530_suspend,
    6867        .resume = z8530_resume,
    69         .read = key_read
     68        .read = z8530_key_read
    7069};
    7170
     
    142141}
    143142
    144 char key_read(chardev_t *d)
     143char z8530_key_read(chardev_t *d)
    145144{
    146145        char ch;       
  • kernel/genarch/src/ofw/ofw_tree.c

    r16529d5 r28ecadb  
    5252}
    5353
     54/** Get OpenFirmware node property.
     55 *
     56 * @param node Node in which to lookup the property.
     57 * @param name Name of the property.
     58 *
     59 * @return Pointer to the property structure or NULL if no such property.
     60 */
     61ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name)
     62{
     63        int i;
     64       
     65        for (i = 0; i < node->properties; i++) {
     66                if (strcmp(node->property[i].name, name) == 0)
     67                        return &node->property[i];
     68        }
     69
     70        return NULL;
     71}
     72
    5473/** Return value of the 'name' property.
    5574 *
     
    6079const char *ofw_tree_node_name(const ofw_tree_node_t *node)
    6180{
    62         int i;
     81        ofw_tree_property_t *prop;
    6382       
    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         }
     83        prop = ofw_tree_getprop(node, "name");
     84        if (!prop)
     85                panic("Node without name property.\n");
     86               
     87        if (prop->size < 2)
     88                panic("Invalid name property.\n");
    7189       
    72         panic("Node without name property.\n");
     90        return prop->value;
    7391}
    7492
     
    7694 *
    7795 * @param node Node whose child is being looked up.
    78  * @param da_name Disambigued name of the child being looked up.
     96 * @param name Name of the child being looked up.
    7997 *
    8098 * @return NULL if there is no such child or pointer to the matching child node.
    8199 */
    82 static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *da_name)
     100static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name)
    83101{
    84102        ofw_tree_node_t *cur;
    85103       
     104        /*
     105         * Try to find the disambigued name.
     106         */
    86107        for (cur = node->child; cur; cur = cur->peer) {
    87                 if (strncmp(cur->da_name, da_name, strlen(da_name)) == 0)
     108                if (strcmp(cur->da_name, name) == 0)
    88109                        return cur;
    89110        }
    90111       
     112        /*
     113         * Disambigued name not found.
     114         * Lets try our luck with possibly ambiguous "name" property.
     115         *
     116         * We need to do this because paths stored in "/aliases"
     117         * are not always fully-qualified.
     118         */
     119        for (cur = node->child; cur; cur = cur->peer) {
     120                if (strcmp(ofw_tree_node_name(cur), name) == 0)
     121                        return cur;
     122        }
     123               
    91124        return NULL;
    92125}
  • kernel/generic/include/func.h

    r16529d5 r28ecadb  
    4545
    4646extern size_t strlen(const char *str);
     47extern int strcmp(const char *src, const char *dst);
    4748extern int strncmp(const char *src, const char *dst, size_t len);
    4849extern void strncpy(char *dest, const char *src, size_t len);
  • kernel/generic/src/lib/func.c

    r16529d5 r28ecadb  
    101101 * Do a char-by-char comparison of two NULL terminated strings.
    102102 * The strings are considered equal iff they consist of the same
     103 * characters on the minimum of their lengths.
     104 *
     105 * @param src First string to compare.
     106 * @param dst Second string to compare.
     107 *
     108 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
     109 *
     110 */
     111int strcmp(const char *src, const char *dst)
     112{
     113        for (; *src && *dst; src++, dst++) {
     114                if (*src < *dst)
     115                        return -1;
     116                if (*src > *dst)
     117                        return 1;
     118        }
     119        if (*src == *dst)
     120                return 0;
     121        if (!*src)
     122                return -1;
     123        return 1;
     124}
     125
     126
     127/** Compare two NULL terminated strings
     128 *
     129 * Do a char-by-char comparison of two NULL terminated strings.
     130 * The strings are considered equal iff they consist of the same
    103131 * characters on the minimum of their lengths and specified maximal
    104132 * length.
     
    115143        int i;
    116144       
    117         i = 0;
    118         for (;*src && *dst && i < len;src++,dst++,i++) {
     145        for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
    119146                if (*src < *dst)
    120147                        return -1;
     
    128155        return 1;
    129156}
     157
     158
    130159
    131160/** Copy NULL terminated string.
  • kernel/kernel.config

    r16529d5 r28ecadb  
    3636@ "indy" SGI Indy
    3737! [ARCH=mips32] MACHINE (choice)
    38 
    39 # Machine type
    40 @ "ultra" Sun Ultra 5
    41 @ "enterprise" Sun Enterprise E6500
    42 ! [ARCH=sparc64] MACHINE (choice)
    4338
    4439# Framebuffer support
     
    111106! [ARCH=sparc64] CONFIG_TSB (n/y)
    112107
     108# Support for Z8530 serial port
     109! [ARCH=sparc64] CONFIG_Z8530 (y/n)
     110
     111# Support for NS16550 serial port
     112! [ARCH=sparc64] CONFIG_NS16550 (y/n)
     113
    113114## Run-time configuration directives
    114115
Note: See TracChangeset for help on using the changeset viewer.