HelenOS sources
This source file includes following definitions.
- do_putchar
- niagara_putuchar
- niagara_poll
- kniagarapoll
- niagara_init
- niagarain_init
#include <arch/drivers/niagara.h>
#include <console/chardev.h>
#include <console/console.h>
#include <ddi/ddi.h>
#include <arch/asm.h>
#include <arch.h>
#include <stdlib.h>
#include <arch/drivers/niagara_buf.h>
#include <arch/drivers/kbd.h>
#include <arch/sun4v/hypercall.h>
#include <sysinfo/sysinfo.h>
#include <ipc/irq.h>
#include <proc/thread.h>
#include <console/console.h>
#include <genarch/srln/srln.h>
#define POLL_INTERVAL 10000
static niagara_instance_t *instance = NULL;
static void niagara_putuchar(outdev_t *, const char32_t);
static outdev_operations_t niagara_ops = {
.write = niagara_putuchar,
.redraw = NULL,
.scroll_up = NULL,
.scroll_down = NULL
};
static volatile niagara_output_buffer_t __attribute__((aligned(PAGE_SIZE)))
output_buffer;
static parea_t outbuf_parea;
static volatile niagara_input_buffer_t __attribute__((aligned(PAGE_SIZE)))
input_buffer;
static parea_t inbuf_parea;
static inline void do_putchar(char c)
{
while (__hypercall_fast1(CONS_PUTCHAR, c) == HV_EWOULDBLOCK)
;
}
static void niagara_putuchar(outdev_t *dev, char32_t ch)
{
if ((!outbuf_parea.mapped) || (console_override)) {
if (ascii_check(ch)) {
do_putchar(ch);
if (ch == '\n')
do_putchar('\r');
} else {
do_putchar('?');
}
}
}
static void niagara_poll(void)
{
while (output_buffer.read_ptr != output_buffer.write_ptr) {
do_putchar(output_buffer.data[output_buffer.read_ptr]);
output_buffer.read_ptr =
((output_buffer.read_ptr) + 1) % OUTPUT_BUFFER_SIZE;
}
uint64_t c;
if (__hypercall_fast_ret1(0, 0, 0, 0, 0, CONS_GETCHAR, &c) == HV_EOK) {
if ((!inbuf_parea.mapped) || (console_override)) {
indev_push_character(instance->srlnin, c);
} else {
input_buffer.data[input_buffer.write_ptr] = (char) c;
input_buffer.write_ptr =
((input_buffer.write_ptr) + 1) % INPUT_BUFFER_SIZE;
}
}
}
static void kniagarapoll(void *arg)
{
while (true) {
niagara_poll();
thread_usleep(POLL_INTERVAL);
}
}
static void niagara_init(void)
{
if (instance)
return;
instance = malloc(sizeof(niagara_instance_t));
instance->thread = thread_create(kniagarapoll, NULL, TASK,
THREAD_FLAG_UNCOUNTED, "kniagarapoll");
if (!instance->thread) {
free(instance);
instance = NULL;
return;
}
instance->srlnin = NULL;
output_buffer.read_ptr = 0;
output_buffer.write_ptr = 0;
input_buffer.write_ptr = 0;
input_buffer.read_ptr = 0;
sysinfo_set_item_val("fb", NULL, true);
sysinfo_set_item_val("fb.kind", NULL, 5);
sysinfo_set_item_val("niagara.outbuf.address", NULL,
KA2PA(&output_buffer));
sysinfo_set_item_val("niagara.outbuf.size", NULL,
PAGE_SIZE);
sysinfo_set_item_val("niagara.outbuf.datasize", NULL,
OUTPUT_BUFFER_SIZE);
sysinfo_set_item_val("niagara.inbuf.address", NULL,
KA2PA(&input_buffer));
sysinfo_set_item_val("niagara.inbuf.size", NULL,
PAGE_SIZE);
sysinfo_set_item_val("niagara.inbuf.datasize", NULL,
INPUT_BUFFER_SIZE);
ddi_parea_init(&outbuf_parea);
outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
outbuf_parea.frames = 1;
outbuf_parea.unpriv = false;
outbuf_parea.mapped = false;
ddi_parea_register(&outbuf_parea);
inbuf_parea.pbase = (uintptr_t) (KA2PA(&input_buffer));
inbuf_parea.frames = 1;
inbuf_parea.unpriv = false;
inbuf_parea.mapped = false;
ddi_parea_register(&inbuf_parea);
outdev_t *niagara_dev = malloc(sizeof(outdev_t));
outdev_initialize("niagara_dev", niagara_dev, &niagara_ops);
stdout_wire(niagara_dev);
}
niagara_instance_t *niagarain_init(void)
{
niagara_init();
if (instance) {
srln_instance_t *srln_instance = srln_init();
if (srln_instance) {
indev_t *sink = stdin_wire();
indev_t *srln = srln_wire(srln_instance, sink);
instance->srlnin = srln;
thread_start(instance->thread);
}
}
return instance;
}
HelenOS homepage, sources at GitHub