| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
|---|
| 3 | * Copyright (c) 2008 Martin Decky
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @file
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #include <sys/types.h>
|
|---|
| 34 | #include <errno.h>
|
|---|
| 35 | #include <str.h>
|
|---|
| 36 | #include <sysinfo.h>
|
|---|
| 37 | #include <ddi.h>
|
|---|
| 38 | #include <align.h>
|
|---|
| 39 | #include <as.h>
|
|---|
| 40 | #include "../ctl/serial.h"
|
|---|
| 41 | #include "kchar.h"
|
|---|
| 42 |
|
|---|
| 43 | typedef struct {
|
|---|
| 44 | uint8_t *addr;
|
|---|
| 45 | } kchar_t;
|
|---|
| 46 |
|
|---|
| 47 | static kchar_t kchar;
|
|---|
| 48 |
|
|---|
| 49 | static void kchar_putchar(wchar_t ch)
|
|---|
| 50 | {
|
|---|
| 51 | if (ascii_check(ch))
|
|---|
| 52 | *kchar.addr = ch;
|
|---|
| 53 | else
|
|---|
| 54 | *kchar.addr = '?';
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | static void kchar_control_puts(const char *str)
|
|---|
| 58 | {
|
|---|
| 59 | while (*str)
|
|---|
| 60 | *kchar.addr = *(str++);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | int kchar_init(void)
|
|---|
| 64 | {
|
|---|
| 65 | sysarg_t present;
|
|---|
| 66 | int rc = sysinfo_get_value("fb", &present);
|
|---|
| 67 | if (rc != EOK)
|
|---|
| 68 | present = false;
|
|---|
| 69 |
|
|---|
| 70 | if (!present)
|
|---|
| 71 | return ENOENT;
|
|---|
| 72 |
|
|---|
| 73 | sysarg_t kind;
|
|---|
| 74 | rc = sysinfo_get_value("fb.kind", &kind);
|
|---|
| 75 | if (rc != EOK)
|
|---|
| 76 | kind = (sysarg_t) -1;
|
|---|
| 77 |
|
|---|
| 78 | if (kind != 3)
|
|---|
| 79 | return EINVAL;
|
|---|
| 80 |
|
|---|
| 81 | sysarg_t paddr;
|
|---|
| 82 | rc = sysinfo_get_value("fb.address.physical", &paddr);
|
|---|
| 83 | if (rc != EOK)
|
|---|
| 84 | return rc;
|
|---|
| 85 |
|
|---|
| 86 | rc = physmem_map((void *) paddr,
|
|---|
| 87 | ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH,
|
|---|
| 88 | AS_AREA_READ | AS_AREA_WRITE, (void *) &kchar.addr);
|
|---|
| 89 | if (rc != EOK)
|
|---|
| 90 | return rc;
|
|---|
| 91 |
|
|---|
| 92 | return serial_init(kchar_putchar, kchar_control_puts);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /** @}
|
|---|
| 96 | */
|
|---|