Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1908 → Rev 1909

/trunk/kernel/genarch/include/ofw/ofw_tree.h
49,6 → 49,12
 
unsigned properties; /**< Number of properties. */
ofw_tree_property_t *property;
/**
* Pointer to a structure representing respective device.
* Its semantics is device dependent.
*/
void *device;
};
 
/** Memory representation of OpenFirmware device tree node property. */
104,8 → 110,24
} __attribute__ ((packed));
typedef struct ofw_ebus_range ofw_ebus_range_t;
 
struct ofw_ebus_intr_map {
uint32_t space;
uint32_t addr;
uint32_t intr;
uint32_t controller_handle;
uint32_t controller_ino;
} __attribute__ ((packed));
typedef struct ofw_ebus_intr_map ofw_ebus_intr_map_t;
 
struct ofw_ebus_intr_mask {
uint32_t space_mask;
uint32_t addr_mask;
uint32_t intr_mask;
} __attribute__ ((packed));
typedef struct ofw_ebus_intr_mask ofw_ebus_intr_mask_t;
 
struct ofw_pci_reg {
uint32_t space; /* needs to masked to obtain pure space id */
uint32_t space; /* needs to be masked to obtain pure space id */
uint64_t addr; /* group phys.mid and phys.lo together */
uint64_t size;
} __attribute__ ((packed));
143,4 → 165,7
 
extern bool ofw_pci_reg_absolutize(ofw_tree_node_t *node, ofw_pci_reg_t *reg, ofw_pci_reg_t *out);
 
extern bool ofw_fhc_map_interrupts(ofw_tree_node_t *node, ofw_fhc_reg_t *reg, uint32_t interrupt, int *ino);
extern bool ofw_ebus_map_interrupts(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uint32_t interrupt, int *ino);
 
#endif
/trunk/kernel/genarch/src/kbd/z8530.c
38,7 → 38,6
#include <genarch/kbd/key.h>
#include <genarch/kbd/scanc.h>
#include <genarch/kbd/scanc_sun.h>
#include <arch/drivers/fhc.h>
#include <arch/drivers/z8530.h>
#include <arch/interrupt.h>
#include <arch/drivers/kbd.h>
106,14 → 105,6
z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE);
z8530_write_a(WR9, WR9_MIE); /* Master Interrupt Enable. */
/*
* We need to initialize the FireHose Controller,
* to which is this z8530 attached. Otherwise
* interrupts generated by the z8530 would not
* be forwarded to the CPU.
*/
fhc_init();
}
 
/** Process z8530 interrupt.
/trunk/kernel/genarch/src/ofw/ebus.c
39,6 → 39,7
#include <arch/memstr.h>
#include <func.h>
#include <panic.h>
#include <debug.h>
#include <macros.h>
 
bool ofw_ebus_apply_ranges(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uintptr_t *pa)
73,5 → 74,51
return false;
}
 
bool ofw_ebus_map_interrupts(ofw_tree_node_t *node, ofw_ebus_reg_t *reg, uint32_t interrupt, int *ino)
{
ofw_tree_property_t *prop;
ofw_tree_node_t *controller;
prop = ofw_tree_getprop(node, "interrupt-map");
if (!prop || !prop->value)
return false;
 
ofw_ebus_intr_map_t *intr_map = prop->value;
count_t count = prop->size / sizeof(ofw_ebus_intr_map_t);
ASSERT(count);
prop = ofw_tree_getprop(node, "interrupt-map-mask");
if (!prop || !prop->value)
return false;
ofw_ebus_intr_mask_t *intr_mask = prop->value;
ASSERT(prop->size == sizeof(ofw_ebus_intr_mask_t));
uint32_t space = reg->space & intr_mask->space_mask;
uint32_t addr = reg->addr & intr_mask->addr_mask;
uint32_t intr = interrupt & intr_mask->intr_mask;
int i;
for (i = 0; i < count; i++) {
if ((intr_map[i].space == space) && (intr_map[i].addr == addr)
&& (intr_map[i].intr == intr))
goto found;
}
return false;
 
found:
/*
* We found the device that functions as an interrupt controller
* for the interrupt. We also found mapping from interrupt to INO.
*/
 
controller = ofw_tree_find_node_by_handle(ofw_tree_lookup("/"), intr_map[i].controller_handle);
*ino = intr_map[i].controller_ino;
return true;
}
 
/** @}
*/
/trunk/kernel/genarch/src/ofw/fhc.c
36,6 → 36,7
*/
 
#include <genarch/ofw/ofw_tree.h>
#include <arch/drivers/fhc.h>
#include <arch/memstr.h>
#include <func.h>
#include <panic.h>
108,5 → 109,25
return false;
}
 
bool ofw_fhc_map_interrupts(ofw_tree_node_t *node, ofw_fhc_reg_t *reg, uint32_t interrupt, int *ino)
{
fhc_t *fhc = NULL;
if (!node->device) {
fhc = fhc_init(node);
if (!fhc)
return false;
node->device = fhc;
central_fhc = fhc;
}
/*
* The interrupt controller for the interrupt is the FHC itself.
*/
fhc_enable_interrupt(fhc, interrupt);
*ino = interrupt;
return true;
}
 
/** @}
*/
/trunk/kernel/arch/sparc64/include/drivers/fhc.h
36,12 → 36,18
#define KERN_sparc64_FHC_H_
 
#include <arch/types.h>
#include <genarch/ofw/ofw_tree.h>
 
extern volatile uint32_t *fhc;
typedef struct {
volatile uint32_t *uart_imap;
} fhc_t;
 
extern void fhc_init(void);
extern void fhc_uart_reset(void);
extern fhc_t *central_fhc;
 
extern fhc_t *fhc_init(ofw_tree_node_t *node);
extern void fhc_enable_interrupt(fhc_t *fhc, int ino);
extern void fhc_clear_interrupt(fhc_t *fhc, int ino);
 
#endif
 
/** @}
/trunk/kernel/arch/sparc64/src/trap/interrupt.c
96,7 → 96,7
z8530_interrupt();
else
ipc_irq_send_notif(0);
fhc_uart_reset();
fhc_clear_interrupt(central_fhc, data0);
break;
 
#endif
/trunk/kernel/arch/sparc64/src/drivers/fhc.c
41,30 → 41,81
 
#include <arch/drivers/fhc.h>
#include <arch/mm/page.h>
#include <mm/slab.h>
#include <arch/types.h>
#include <typedefs.h>
 
#include <genarch/ofw/ofw_tree.h>
#include <genarch/kbd/z8530.h>
 
volatile uint32_t *fhc = NULL;
fhc_t *central_fhc = NULL;
 
#define FHC_UART_ADDR 0x1fff8808000ULL /* hardcoded for Simics simulation */
/**
* I suspect this must be hardcoded in the FHC.
* If it is not, than we can read all IMAP registers
* and get the complete mapping.
*/
#define FHC_UART_INO 0x39
 
#define FHC_UART_IMAP 0x0
#define FHC_UART_ICLR 0x4
 
void fhc_init(void)
#define UART_IMAP_REG 4
 
fhc_t *fhc_init(ofw_tree_node_t *node)
{
fhc = (void *) hw_map(FHC_UART_ADDR, PAGE_SIZE);
fhc_t *fhc;
ofw_tree_property_t *prop;
 
fhc[FHC_UART_ICLR] = 0;
fhc[FHC_UART_IMAP] = 0x80000000;
prop = ofw_tree_getprop(node, "reg");
if (!prop || !prop->value)
return NULL;
count_t regs = prop->size / sizeof(ofw_central_reg_t);
if (regs + 1 < UART_IMAP_REG)
return NULL;
 
ofw_central_reg_t *reg = &((ofw_central_reg_t *) prop->value)[UART_IMAP_REG];
 
uintptr_t paddr;
if (!ofw_central_apply_ranges(node->parent, reg, &paddr))
return NULL;
 
fhc = (fhc_t *) malloc(sizeof(fhc_t), FRAME_ATOMIC);
if (!fhc)
return NULL;
 
fhc->uart_imap = (uint32_t *) hw_map(paddr, reg->size);
return fhc;
}
 
void fhc_uart_reset(void)
void fhc_enable_interrupt(fhc_t *fhc, int ino)
{
fhc[FHC_UART_ICLR] = 0;
switch (ino) {
case FHC_UART_INO:
fhc->uart_imap[FHC_UART_ICLR] = 0x0;
fhc->uart_imap[FHC_UART_IMAP] = 0x80000000;
break;
default:
panic("Unexpected INO (%d)\n", ino);
break;
}
}
 
void fhc_clear_interrupt(fhc_t *fhc, int ino)
{
ASSERT(fhc->uart_imap);
 
switch (ino) {
case FHC_UART_INO:
fhc->uart_imap[FHC_UART_ICLR] = 0;
break;
default:
panic("Unexpected INO (%d)\n", ino);
break;
}
}
 
/** @}
*/
/trunk/kernel/arch/sparc64/src/drivers/kbd.c
68,6 → 68,9
name = ofw_tree_node_name(node);
/*
* Determine keyboard serial controller type.
*/
if (strcmp(name, "zs") == 0)
kbd_type = KBD_Z8530;
else if (strcmp(name, "su") == 0)
78,12 → 81,25
return;
}
/*
* Read 'interrupts' property.
*/
uint32_t interrupts;
prop = ofw_tree_getprop(node, "interrupts");
if (!prop || !prop->value)
panic("Can't find \"interrupts\" property.\n");
interrupts = *((uint32_t *) prop->value);
 
/*
* Read 'reg' property.
*/
prop = ofw_tree_getprop(node, "reg");
if (!prop)
if (!prop || !prop->value)
panic("Can't find \"reg\" property.\n");
uintptr_t pa;
size_t size;
int ino;
switch (kbd_type) {
case KBD_Z8530:
92,6 → 108,10
printf("Failed to determine keyboard address.\n");
return;
}
if (!ofw_fhc_map_interrupts(node->parent, ((ofw_fhc_reg_t *) prop->value), interrupts, &ino)) {
printf("Failed to determine keyboard interrupts.\n");
return;
}
break;
case KBD_NS16550:
size = ((ofw_ebus_reg_t *) prop->value)->size;
99,6 → 119,10
printf("Failed to determine keyboard address.\n");
return;
}
if (!ofw_ebus_map_interrupts(node->parent, ((ofw_ebus_reg_t *) prop->value), interrupts, &ino)) {
printf("Failed to determine keyboard interrupts.\n");
return;
}
break;
default:
panic("Unexpected type.\n");
/trunk/boot/genarch/ofw_tree.h
49,6 → 49,8
 
unsigned properties; /**< Number of properties. */
ofw_tree_property_t *property;
void *device; /**< Member used solely by the kernel. */
};
 
/** Memory representation of OpenFirmware device tree node property. */
/trunk/boot/genarch/ofw_tree.c
96,6 → 96,7
current_node->node_handle = current;
current_node->properties = 0;
current_node->property = NULL;
current_node->device = NULL;
/*
* Get the disambigued name.