Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1895 → Rev 1896

/trunk/kernel/kernel.config
36,11 → 36,6
@ "indy" SGI Indy
! [ARCH=mips32] MACHINE (choice)
 
# Machine type
@ "ultra" Sun Ultra 5
@ "enterprise" Sun Enterprise E6500
! [ARCH=sparc64] MACHINE (choice)
 
# Framebuffer support
! [(ARCH=mips32&MACHINE=lgxemul)|(ARCH=mips32&MACHINE=bgxemul)|(ARCH=ia32)|(ARCH=amd64)] CONFIG_FB (y/n)
 
110,6 → 105,12
# Use TSB
! [ARCH=sparc64] CONFIG_TSB (n/y)
 
# Support for Z8530 serial port
! [ARCH=sparc64] CONFIG_Z8530 (y/n)
 
# Support for NS16550 serial port
! [ARCH=sparc64] CONFIG_NS16550 (y/n)
 
## Run-time configuration directives
 
# Kernel test type
/trunk/kernel/genarch/include/kbd/z8530.h
48,6 → 48,7
extern void z8530_grab(void);
extern void z8530_release(void);
extern void z8530_interrupt(void);
extern char z8530_key_read(chardev_t *d);
 
#endif
 
/trunk/kernel/genarch/include/kbd/ns16550.h
37,10 → 37,13
#ifndef KERN_NS16550_H_
#define KERN_NS16550_H_
 
#include <typedefs.h>
 
extern void ns16550_init(void);
extern void ns16550_poll(void);
extern void ns16550_grab(void);
extern void ns16550_release(void);
extern char ns16550_key_read(chardev_t *d);
 
#endif
 
/trunk/kernel/genarch/include/kbd/i8042.h
35,10 → 35,13
#ifndef KERN_I8042_H_
#define KERN_I8042_H_
 
#include <typedefs.h>
 
extern void i8042_init(void);
extern void i8042_poll(void);
extern void i8042_grab(void);
extern void i8042_release(void);
extern char i8042_key_read(chardev_t *d);
 
#endif
 
/trunk/kernel/genarch/include/kbd/key.h
49,8 → 49,6
extern void active_read_buff_write(uint8_t ch);
extern void active_read_key_pressed(uint8_t sc);
 
extern char key_read(chardev_t *d);
 
#endif
 
/** @}
/trunk/kernel/genarch/include/ofw/ofw_tree.h
56,9 → 56,81
void *value;
};
 
/*
* Definition of 'reg' and 'ranges' properties for various buses.
*/
struct ofw_fhc_reg {
uint64_t addr;
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_fhc_reg ofw_fhc_reg_t;
struct ofw_fhc_range {
uint64_t child_base;
uint64_t parent_base;
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_fhc_range ofw_fhc_range_t;
 
struct ofw_central_reg {
uint64_t addr;
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_central_reg ofw_central_reg_t;
 
struct ofw_central_range {
uint64_t child_base;
uint64_t parent_base;
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_central_range ofw_central_range_t;
 
struct ofw_ebus_reg {
uint32_t space;
uint32_t addr;
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_ebus_reg ofw_ebus_reg_t;
 
struct ofw_ebus_range {
uint32_t child_space;
uint32_t child_base;
uint32_t parent_space;
uint64_t parent_base; /* group phys.mid and phys.lo together */
uint32_t size;
} __attribute__ ((packed));
typedef struct ofw_ebus_range ofw_ebus_range_t;
 
struct ofw_pci_reg {
uint32_t space; /* needs to masked to obtain pure space id */
uint64_t addr; /* group phys.mid and phys.lo together */
uint64_t size;
} __attribute__ ((packed));
typedef struct ofw_pci_reg ofw_pci_reg_t;
 
struct ofw_pci_range {
uint32_t space;
uint64_t child_base; /* group phys.mid and phys.lo together */
uint64_t parent_base;
uint64_t size;
} __attribute__ ((packed));
typedef struct ofw_pci_range ofw_pci_range_t;
 
struct ofw_ffb_reg {
} __attribute__ ((packed));
typedef struct ofw_ffb_reg ofw_ffb_reg_t;
 
extern void ofw_tree_init(ofw_tree_node_t *root);
extern void ofw_tree_print(void);
extern const char *ofw_tree_node_name(const ofw_tree_node_t *node);
extern ofw_tree_node_t *ofw_tree_lookup(const char *path);
extern ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name);
 
extern bool ofw_fhc_apply_ranges(ofw_tree_node_t *node, ofw_fhc_reg_t *reg, uintptr_t *pa);
extern bool ofw_central_apply_ranges(ofw_tree_node_t *node, ofw_central_reg_t *reg, uintptr_t *pa);
extern bool ofw_ebus_apply_ranges(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uintptr_t *pa);
extern bool ofw_pci_apply_ranges(ofw_tree_node_t *node, ofw_pci_reg_t *reg, uintptr_t *pa);
extern bool ofw_ffb_apply_ranges(ofw_tree_node_t *node, ofw_ffb_reg_t *reg, uintptr_t *pa);
 
#endif
/trunk/kernel/genarch/Makefile.inc
72,20 → 72,23
genarch/src/kbd/scanc_pc.c
endif
 
## z8530 controller
ifeq ($(CONFIG_Z8530),y)
## Sun keyboard
ifeq ($(CONFIG_SUN_KBD),y)
GENARCH_SOURCES += \
genarch/src/kbd/z8530.c \
genarch/src/kbd/key.c \
genarch/src/kbd/scanc_sun.c
endif
 
## z8530 controller
ifeq ($(CONFIG_Z8530),y)
GENARCH_SOURCES += \
genarch/src/kbd/z8530.c
endif
 
## ns16550 controller
ifeq ($(CONFIG_NS16550),y)
GENARCH_SOURCES += \
genarch/src/kbd/ns16550.c \
genarch/src/kbd/key.c \
genarch/src/kbd/scanc_sun.c
genarch/src/kbd/ns16550.c
endif
 
 
92,5 → 95,8
## OpenFirmware Device Tree
ifeq ($(CONFIG_OFW_TREE), y)
GENARCH_SOURCES += \
genarch/src/ofw/ofw_tree.c
genarch/src/ofw/ofw_tree.c \
genarch/src/ofw/ebus.c \
genarch/src/ofw/fhc.c \
genarch/src/ofw/pci.c
endif
/trunk/kernel/genarch/src/kbd/ns16550.c
59,11 → 59,10
static void ns16550_suspend(chardev_t *);
static void ns16550_resume(chardev_t *);
 
chardev_t kbrd;
static chardev_operations_t ops = {
.suspend = ns16550_suspend,
.resume = ns16550_resume,
.read = key_read
.read = ns16550_key_read
};
 
void ns16550_interrupt(int n, istate_t *istate);
118,7 → 117,7
{
}
 
char key_read(chardev_t *d)
char ns16550_key_read(chardev_t *d)
{
char ch;
 
/trunk/kernel/genarch/src/kbd/i8042.c
80,11 → 80,10
static void i8042_suspend(chardev_t *);
static void i8042_resume(chardev_t *);
 
chardev_t kbrd;
static chardev_operations_t ops = {
.suspend = i8042_suspend,
.resume = i8042_resume,
.read = key_read
.read = i8042_key_read
};
 
static void i8042_interrupt(int n, istate_t *istate);
173,7 → 172,7
{
}
 
char key_read(chardev_t *d)
char i8042_key_read(chardev_t *d)
{
char ch;
 
/trunk/kernel/genarch/src/kbd/key.c
53,6 → 53,8
 
#define ACTIVE_READ_BUFF_SIZE 16 /* Must be power of 2 */
 
chardev_t kbrd;
 
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
 
SPINLOCK_INITIALIZE(keylock); /**< keylock protects keyflags and lockflags. */
/trunk/kernel/genarch/src/kbd/z8530.c
62,11 → 62,10
static void z8530_suspend(chardev_t *);
static void z8530_resume(chardev_t *);
 
chardev_t kbrd;
static chardev_operations_t ops = {
.suspend = z8530_suspend,
.resume = z8530_resume,
.read = key_read
.read = z8530_key_read
};
 
void z8530_wait(void);
141,7 → 140,7
{
}
 
char key_read(chardev_t *d)
char z8530_key_read(chardev_t *d)
{
char ch;
 
/trunk/kernel/genarch/src/ofw/ebus.c
0,0 → 1,77
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ofw
* @{
*/
/**
* @file
* @brief EBUS 'reg' and 'ranges' properties handling.
*
*/
 
#include <genarch/ofw/ofw_tree.h>
#include <arch/memstr.h>
#include <func.h>
#include <panic.h>
#include <macros.h>
 
bool ofw_ebus_apply_ranges(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uintptr_t *pa)
{
ofw_tree_property_t *prop;
ofw_ebus_range_t *range;
count_t ranges;
 
prop = ofw_tree_getprop(node, "ranges");
if (!prop)
return false;
ranges = prop->size / sizeof(ofw_ebus_range_t);
range = prop->value;
int i;
for (i = 0; i < ranges; i++) {
if (reg->space != range[i].child_space)
continue;
if (overlaps(reg->addr, reg->size, range[i].child_base, range[i].size)) {
ofw_pci_reg_t pci_reg;
pci_reg.space = range[i].parent_space;
pci_reg.addr = range[i].parent_base + (reg->addr - range[i].child_base);
pci_reg.size = reg->size;
return ofw_pci_apply_ranges(node->parent, &pci_reg, pa);
}
}
 
return false;
}
 
/** @}
*/
/trunk/kernel/genarch/src/ofw/fhc.c
0,0 → 1,112
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ofw
* @{
*/
/**
* @file
* @brief FHC 'reg' and 'ranges' properties handling.
*
*/
 
#include <genarch/ofw/ofw_tree.h>
#include <arch/memstr.h>
#include <func.h>
#include <panic.h>
#include <macros.h>
 
bool ofw_fhc_apply_ranges(ofw_tree_node_t *node, ofw_fhc_reg_t *reg, uintptr_t *pa)
{
ofw_tree_property_t *prop;
ofw_fhc_range_t *range;
count_t ranges;
 
prop = ofw_tree_getprop(node, "ranges");
if (!prop)
return false;
ranges = prop->size / sizeof(ofw_fhc_range_t);
range = prop->value;
int i;
for (i = 0; i < ranges; i++) {
if (overlaps(reg->addr, reg->size, range[i].child_base, range[i].size)) {
uintptr_t addr;
addr = range[i].parent_base + (reg->addr - range[i].child_base);
if (!node->parent->parent) {
*pa = addr;
return true;
}
if (strcmp(ofw_tree_node_name(node->parent), "central") != 0)
panic("Unexpected parent node: %s.\n", ofw_tree_node_name(node->parent));
ofw_central_reg_t central_reg;
central_reg.addr = addr;
central_reg.size = reg->size;
return ofw_central_apply_ranges(node->parent, &central_reg, pa);
}
}
 
return false;
}
 
bool ofw_central_apply_ranges(ofw_tree_node_t *node, ofw_central_reg_t *reg, uintptr_t *pa)
{
if (node->parent->parent)
panic("Unexpected parent node: %s.\n", ofw_tree_node_name(node->parent));
ofw_tree_property_t *prop;
ofw_central_range_t *range;
count_t ranges;
prop = ofw_tree_getprop(node, "ranges");
if (!prop)
return false;
ranges = prop->size / sizeof(ofw_central_range_t);
range = prop->value;
int i;
for (i = 0; i < ranges; i++) {
if (overlaps(reg->addr, reg->size, range[i].child_base, range[i].size)) {
*pa = range[i].parent_base + (reg->addr - range[i].child_base);
return true;
}
}
return false;
}
 
/** @}
*/
/trunk/kernel/genarch/src/ofw/ofw_tree.c
51,6 → 51,25
ofw_root = root;
}
 
/** Get OpenFirmware node property.
*
* @param node Node in which to lookup the property.
* @param name Name of the property.
*
* @return Pointer to the property structure or NULL if no such property.
*/
ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name)
{
int i;
for (i = 0; i < node->properties; i++) {
if (strcmp(node->property[i].name, name) == 0)
return &node->property[i];
}
 
return NULL;
}
 
/** Return value of the 'name' property.
*
* @param node Node of interest.
59,35 → 78,49
*/
const char *ofw_tree_node_name(const ofw_tree_node_t *node)
{
int i;
ofw_tree_property_t *prop;
for (i = 0; i < node->properties; i++) {
if (strncmp(node->property[i].name, "name", strlen("name")) == 0) {
if (node->property[i].size < 2)
panic("Invalid name property.\n");
return node->property[i].value;
}
}
prop = ofw_tree_getprop(node, "name");
if (!prop)
panic("Node without name property.\n");
if (prop->size < 2)
panic("Invalid name property.\n");
panic("Node without name property.\n");
return prop->value;
}
 
/** Lookup child of given name.
*
* @param node Node whose child is being looked up.
* @param da_name Disambigued name of the child being looked up.
* @param name Name of the child being looked up.
*
* @return NULL if there is no such child or pointer to the matching child node.
*/
static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *da_name)
static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name)
{
ofw_tree_node_t *cur;
/*
* Try to find the disambigued name.
*/
for (cur = node->child; cur; cur = cur->peer) {
if (strncmp(cur->da_name, da_name, strlen(da_name)) == 0)
if (strcmp(cur->da_name, name) == 0)
return cur;
}
/*
* Disambigued name not found.
* Lets try our luck with possibly ambiguous "name" property.
*
* We need to do this because paths stored in "/aliases"
* are not always fully-qualified.
*/
for (cur = node->child; cur; cur = cur->peer) {
if (strcmp(ofw_tree_node_name(cur), name) == 0)
return cur;
}
return NULL;
}
 
/trunk/kernel/genarch/src/ofw/pci.c
0,0 → 1,77
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ofw
* @{
*/
/**
* @file
* @brief PCI 'reg' and 'ranges' properties handling.
*
*/
 
#include <genarch/ofw/ofw_tree.h>
#include <arch/memstr.h>
#include <func.h>
#include <panic.h>
#include <macros.h>
 
#define PCI_SPACE_MASK 0x03000000
 
bool ofw_pci_apply_ranges(ofw_tree_node_t *node, ofw_pci_reg_t *reg, uintptr_t *pa)
{
ofw_tree_property_t *prop;
ofw_pci_range_t *range;
count_t ranges;
 
prop = ofw_tree_getprop(node, "ranges");
if (!prop) {
if (strcmp(ofw_tree_node_name(node->parent), "pci") == 0)
return ofw_pci_apply_ranges(node->parent, reg, pa);
return false;
}
ranges = prop->size / sizeof(ofw_pci_range_t);
range = prop->value;
int i;
for (i = 0; i < ranges; i++) {
if ((reg->space & PCI_SPACE_MASK) != (range[i].space & PCI_SPACE_MASK))
continue;
if (overlaps(reg->addr, reg->size, range[i].child_base, range[i].size)) {
*pa = range[i].parent_base + (reg->addr - range[i].child_base);
return true;
}
}
 
return false;
}
 
/** @}
*/
/trunk/kernel/generic/include/func.h
44,6 → 44,7
extern void halt(void);
 
extern size_t strlen(const char *str);
extern int strcmp(const char *src, const char *dst);
extern int strncmp(const char *src, const char *dst, size_t len);
extern void strncpy(char *dest, const char *src, size_t len);
extern unative_t atoi(const char *text);
/trunk/kernel/generic/src/lib/func.c
100,6 → 100,34
*
* Do a char-by-char comparison of two NULL terminated strings.
* The strings are considered equal iff they consist of the same
* characters on the minimum of their lengths.
*
* @param src First string to compare.
* @param dst Second string to compare.
*
* @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
*
*/
int strcmp(const char *src, const char *dst)
{
for (; *src && *dst; src++, dst++) {
if (*src < *dst)
return -1;
if (*src > *dst)
return 1;
}
if (*src == *dst)
return 0;
if (!*src)
return -1;
return 1;
}
 
 
/** Compare two NULL terminated strings
*
* Do a char-by-char comparison of two NULL terminated strings.
* The strings are considered equal iff they consist of the same
* characters on the minimum of their lengths and specified maximal
* length.
*
114,8 → 142,7
{
int i;
i = 0;
for (;*src && *dst && i < len;src++,dst++,i++) {
for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
if (*src < *dst)
return -1;
if (*src > *dst)
128,6 → 155,8
return 1;
}
 
 
 
/** Copy NULL terminated string.
*
* Copy at most 'len' characters from string 'src' to 'dest'.
/trunk/kernel/Makefile
83,6 → 83,14
DEFS += -DCONFIG_TSB
endif
 
ifeq ($(CONFIG_Z8530),y)
DEFS += -DCONFIG_Z8530
endif
 
ifeq ($(CONFIG_NS16550),y)
DEFS += -DCONFIG_NS16550
endif
 
ifeq ($(CONFIG_POWEROFF),y)
DEFS += -DCONFIG_POWEROFF
endif
/trunk/kernel/arch/sparc64/include/boot/boot.h
79,11 → 79,6
} screen_t;
 
typedef struct {
uintptr_t addr;
uint32_t size;
} keyboard_t;
 
typedef struct {
uint32_t clock_frequency;
} processor_t;
 
95,7 → 90,6
taskmap_t taskmap;
memmap_t memmap;
screen_t screen;
keyboard_t keyboard;
processor_t processor;
ballocs_t ballocs;
ofw_tree_node_t *ofw_root;
/trunk/kernel/arch/sparc64/include/drivers/kbd.h
36,10 → 36,19
#define KERN_sparc64_KBD_H_
 
#include <arch/types.h>
#include <genarch/ofw/ofw_tree.h>
 
typedef enum {
KBD_UNKNOWN,
KBD_Z8530,
KBD_NS16550
} kbd_type_t;
 
extern kbd_type_t kbd_type;
 
extern volatile uint8_t *kbd_virt_address;
 
extern void kbd_init(void);
extern void kbd_init(ofw_tree_node_t *node);
 
#endif
 
/trunk/kernel/arch/sparc64/Makefile.inc
60,30 → 60,16
 
CONFIG_FB = y
 
## Compile with support for Sun keyboard.
#
 
CONFIG_SUN_KBD = y
 
## Compile with support for OpenFirmware device tree.
#
 
CONFIG_OFW_TREE = y
 
ifeq ($(MACHINE),enterprise)
## Compile with support for z8530 controller.
#
 
CONFIG_Z8530 = y
DEFS += -DCONFIG_Z8530
endif
ifeq ($(MACHINE),ultra)
## Compile with support for ns16550 controller.
#
CONFIG_NS16550 = y
DEFS += -DCONFIG_NS16550
DEFS += -DKBD_ADDR_OVRD=0x1fff13083f8ULL
endif
 
 
ARCH_SOURCES = \
arch/$(ARCH)/src/cpu/cpu.c \
arch/$(ARCH)/src/asm.S \
/trunk/kernel/arch/sparc64/src/console.c
53,7 → 53,10
#include <proc/thread.h>
#include <arch/mm/tlb.h>
#include <arch/boot/boot.h>
#include <genarch/ofw/ofw_tree.h>
#include <arch.h>
#include <panic.h>
#include <print.h>
 
#define KEYBOARD_POLL_PAUSE 50000 /* 50ms */
 
61,17 → 64,38
void standalone_sparc64_console_init(void)
{
stdin = NULL;
 
ofw_tree_node_t *aliases;
ofw_tree_property_t *prop;
ofw_tree_node_t *screen;
ofw_tree_node_t *keyboard;
aliases = ofw_tree_lookup("/aliases");
if (!aliases)
panic("Can't find /aliases.\n");
prop = ofw_tree_getprop(aliases, "screen");
if (!prop)
panic("Can't find property \"screen\".\n");
if (!prop->value)
panic("Can't find screen alias.\n");
screen = ofw_tree_lookup(prop->value);
if (!screen)
panic("Can't find %s\n", prop->value);
 
fb_init(bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height,
bootinfo.screen.bpp, bootinfo.screen.scanline, true);
prop = ofw_tree_getprop(aliases, "keyboard");
if (!prop)
panic("Can't find property \"keyboard\".\n");
if (!prop->value)
panic("Can't find keyboard alias.\n");
keyboard = ofw_tree_lookup(prop->value);
if (!keyboard)
panic("Can't find %s\n", prop->value);
 
#ifdef KBD_ADDR_OVRD
if (!bootinfo.keyboard.addr)
bootinfo.keyboard.addr = KBD_ADDR_OVRD;
#endif
 
if (bootinfo.keyboard.addr)
kbd_init();
kbd_init(keyboard);
}
 
/** Kernel thread for polling keyboard.
82,15 → 106,15
{
thread_detach(THREAD);
 
if (!bootinfo.keyboard.addr)
return;
while (1) {
#ifdef CONFIG_Z8530
if (kbd_type == KBD_Z8530)
return;
#endif
 
while (1) {
#ifdef CONFIG_NS16550
ns16550_poll();
if (kbd_type == KBD_NS16550)
ns16550_poll();
#endif
thread_usleep(KEYBOARD_POLL_PAUSE);
}
102,7 → 126,8
void arch_grab_console(void)
{
#ifdef CONFIG_Z8530
z8530_grab();
if (kbd_type == KBD_Z8530)
z8530_grab();
#endif
}
 
112,7 → 137,8
void arch_release_console(void)
{
#ifdef CONFIG_Z8530
z8530_release();
if (kbd_type == KBD_Z8530)
z8530_release();
#endif
}
 
/trunk/kernel/arch/sparc64/src/trap/interrupt.c
36,6 → 36,7
#include <arch/trap/interrupt.h>
#include <interrupt.h>
#include <arch/drivers/fhc.h>
#include <arch/drivers/kbd.h>
#include <typedefs.h>
#include <arch/types.h>
#include <debug.h>
62,7 → 63,8
void irq_ipc_bind_arch(unative_t irq)
{
#ifdef CONFIG_Z8530
z8530_belongs_to_kernel = false;
if (kbd_type == KBD_Z8530)
z8530_belongs_to_kernel = false;
#endif
}
 
77,6 → 79,8
switch (data0) {
#ifdef CONFIG_Z8530
case Z8530_INTRCV_DATA0:
if (kbd_type != KBD_Z8530)
break;
/*
* So far, we know we got this interrupt through the FHC.
* Since we don't have enough information about the FHC and
/trunk/kernel/arch/sparc64/src/drivers/kbd.c
33,6 → 33,7
*/
 
#include <arch/drivers/kbd.h>
#include <genarch/ofw/ofw_tree.h>
#ifdef CONFIG_Z8530
#include <genarch/kbd/z8530.h>
#endif
40,38 → 41,93
#include <genarch/kbd/ns16550.h>
#endif
 
#include <arch/boot/boot.h>
#include <arch/mm/page.h>
#include <arch/types.h>
#include <typedefs.h>
#include <align.h>
#include <func.h>
#include <print.h>
 
volatile uint8_t *kbd_virt_address = NULL;
 
void kbd_init()
kbd_type_t kbd_type = KBD_UNKNOWN;
 
/** Initialize keyboard.
*
* Traverse OpenFirmware device tree in order to find necessary
* info about the keyboard device.
*
* @param node Keyboard device node.
*/
void kbd_init(ofw_tree_node_t *node)
{
size_t offset;
uintptr_t aligned_addr;
 
/* FIXME: supply value read from OpenFirmware */
bootinfo.keyboard.size = 8;
 
ofw_tree_property_t *prop;
const char *name;
name = ofw_tree_node_name(node);
if (strcmp(name, "zs") == 0)
kbd_type = KBD_Z8530;
else if (strcmp(name, "su") == 0)
kbd_type = KBD_NS16550;
if (kbd_type == KBD_UNKNOWN) {
printf("Unknown keyboard device.\n");
return;
}
prop = ofw_tree_getprop(node, "reg");
if (!prop)
panic("Can't find \"reg\" property.\n");
uintptr_t pa;
size_t size;
switch (kbd_type) {
case KBD_Z8530:
size = ((ofw_fhc_reg_t *) prop->value)->size;
if (!ofw_fhc_apply_ranges(node->parent, ((ofw_fhc_reg_t *) prop->value) , &pa)) {
printf("Failed to determine keyboard address.\n");
return;
}
break;
case KBD_NS16550:
size = ((ofw_ebus_reg_t *) prop->value)->size;
if (!ofw_ebus_apply_ranges(node->parent, ((ofw_ebus_reg_t *) prop->value) , &pa)) {
printf("Failed to determine keyboard address.\n");
return;
}
break;
default:
panic("Unexpected type.\n");
}
/*
* We need to pass aligned address to hw_map().
* However, the physical keyboard address can
* be pretty much unaligned on some systems
* (e.g. Ultra 5, Ultra 60).
* be pretty much unaligned, depending on the
* underlying controller.
*/
aligned_addr = ALIGN_DOWN(bootinfo.keyboard.addr, PAGE_SIZE);
offset = bootinfo.keyboard.addr - aligned_addr;
kbd_virt_address = (uint8_t *) hw_map(aligned_addr, offset + bootinfo.keyboard.size) + offset;
aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
offset = pa - aligned_addr;
kbd_virt_address = (uint8_t *) hw_map(aligned_addr, offset + size) + offset;
 
switch (kbd_type) {
#ifdef CONFIG_Z8530
z8530_init();
case KBD_Z8530:
z8530_init();
break;
#endif
#ifdef CONFIG_NS16550
ns16550_init();
case KBD_NS16550:
ns16550_init();
break;
#endif
default:
printf("Kernel is not compiled with the necessary keyboard driver this machine requires.\n");
}
}
 
/** @}
/trunk/boot/genarch/ofw_tree.c
47,7 → 47,22
 
static void * ofw_tree_space_alloc(size_t size)
{
return balloc(size, size);
char *addr;
 
/*
* What we do here is a nasty hack :-)
* Problem: string property values that are allocated via this
* function typically do not contain the trailing '\0'. This
* is very uncomfortable for kernel, which is supposed to deal
* with the properties.
* Solution: when allocating space via this function, we always
* allocate space for the extra '\0' character that we store
* behind the requested memory.
*/
addr = balloc(size + 1, size);
if (addr)
addr[size] = '\0';
return addr;
}
 
/** Transfer information from one OpenFirmware node into its memory representation.
153,7 → 168,8
if (i == current_node->properties)
break;
strncpy(current_node->property[i].name, name, sizeof(name));
memcpy(current_node->property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN);
current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
 
size = ofw_get_proplen(current, name);
current_node->property[i].size = size;
/trunk/boot/generic/string.c
57,6 → 57,34
*
* Do a char-by-char comparison of two NULL terminated strings.
* The strings are considered equal iff they consist of the same
* characters on the minimum of their lengths.
*
* @param src First string to compare.
* @param dst Second string to compare.
*
* @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
*
*/
int strcmp(const char *src, const char *dst)
{
for (; *src && *dst; src++, dst++) {
if (*src < *dst)
return -1;
if (*src > *dst)
return 1;
}
if (*src == *dst)
return 0;
if (!*src)
return -1;
return 1;
}
 
 
/** Compare two NULL terminated strings
*
* Do a char-by-char comparison of two NULL terminated strings.
* The strings are considered equal iff they consist of the same
* characters on the minimum of their lengths and specified maximal
* length.
*
71,8 → 99,7
{
int i;
i = 0;
for (;*src && *dst && i < len;src++,dst++,i++) {
for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
if (*src < *dst)
return -1;
if (*src > *dst)
/trunk/boot/generic/string.h
38,6 → 38,7
#include <types.h>
 
extern size_t strlen(const char *str);
extern int strcmp(const char *src, const char *dst);
extern int strncmp(const char *src, const char *dst, size_t len);
extern void strncpy(char *dest, const char *src, size_t len);
extern unative_t atoi(const char *text);
/trunk/boot/arch/sparc64/loader/main.c
65,9 → 65,6
/* transform scanline to bytes with respect to potential alignment */
bootinfo.screen.scanline = bootinfo.screen.scanline*bpp2align[bootinfo.screen.bpp >> 3];
if (!ofw_keyboard(&bootinfo.keyboard))
printf("Error: unable to get keyboard properties\n");
 
if (!ofw_cpu(&bootinfo.cpu))
printf("Error: unable to get cpu properties\n");
 
75,7 → 72,6
printf(" cpu: %dMHz\n", bootinfo.cpu.clock_frequency/1000000);
printf(" memory: %dM\n", bootinfo.memmap.total>>20);
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);
printf(" keyboard at %P (size %d bytes)\n", (uintptr_t) bootinfo.keyboard.addr, bootinfo.keyboard.size);
 
printf("\nMemory statistics\n");
printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS);
/trunk/boot/arch/sparc64/loader/main.h
54,7 → 54,6
taskmap_t taskmap;
memmap_t memmap;
screen_t screen;
keyboard_t keyboard;
cpu_t cpu;
ballocs_t ballocs;
ofw_tree_node_t *ofw_root;
/trunk/boot/arch/sparc64/loader/ofwarch.c
95,7 → 95,7
for (; node != 0 && node != -1; node = ofw_get_peer_node(node)) {
if (ofw_get_property(node, "device_type", type_name, sizeof(type_name)) > 0) {
if (strncmp(type_name, "cpu", 3) == 0) {
if (strcmp(type_name, "cpu") == 0) {
uint32_t mhz;
if (ofw_get_property(node, "clock-frequency", &mhz, sizeof(mhz)) <= 0)