[113c677] | 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 |
|
---|
[7c014d1] | 33 | #include <sys/types.h>
|
---|
| 34 | #include <errno.h>
|
---|
[113c677] | 35 | #include <sysinfo.h>
|
---|
| 36 | #include <ddi.h>
|
---|
[7c014d1] | 37 | #include <as.h>
|
---|
| 38 | #include <align.h>
|
---|
| 39 | #include "../ctl/serial.h"
|
---|
| 40 | #include "kchar.h"
|
---|
[113c677] | 41 |
|
---|
[7c014d1] | 42 | typedef struct {
|
---|
| 43 | uint8_t *addr;
|
---|
| 44 | } kchar_t;
|
---|
[113c677] | 45 |
|
---|
[7c014d1] | 46 | static kchar_t kchar;
|
---|
[113c677] | 47 |
|
---|
[7c014d1] | 48 | static void kchar_putchar(wchar_t ch)
|
---|
| 49 | {
|
---|
[446ac2a] | 50 | if (ascii_check(ch))
|
---|
[7c014d1] | 51 | *kchar.addr = ch;
|
---|
| 52 | else
|
---|
| 53 | *kchar.addr = '?';
|
---|
| 54 | }
|
---|
[113c677] | 55 |
|
---|
[7c014d1] | 56 | static void kchar_control_puts(const char *str)
|
---|
[113c677] | 57 | {
|
---|
[7c014d1] | 58 | while (*str)
|
---|
| 59 | *kchar.addr = *(str++);
|
---|
[113c677] | 60 | }
|
---|
| 61 |
|
---|
[7c014d1] | 62 | int kchar_init(void)
|
---|
[113c677] | 63 | {
|
---|
[7c014d1] | 64 | sysarg_t present;
|
---|
| 65 | int rc = sysinfo_get_value("fb", &present);
|
---|
| 66 | if (rc != EOK)
|
---|
| 67 | present = false;
|
---|
| 68 |
|
---|
| 69 | if (!present)
|
---|
| 70 | return ENOENT;
|
---|
| 71 |
|
---|
| 72 | sysarg_t kind;
|
---|
| 73 | rc = sysinfo_get_value("fb.kind", &kind);
|
---|
| 74 | if (rc != EOK)
|
---|
| 75 | kind = (sysarg_t) -1;
|
---|
| 76 |
|
---|
| 77 | if (kind != 3)
|
---|
| 78 | return EINVAL;
|
---|
[d9fae235] | 79 |
|
---|
[7c014d1] | 80 | sysarg_t paddr;
|
---|
| 81 | rc = sysinfo_get_value("fb.address.physical", &paddr);
|
---|
| 82 | if (rc != EOK)
|
---|
| 83 | return rc;
|
---|
[113c677] | 84 |
|
---|
[fbcdeb8] | 85 | rc = physmem_map((void *) paddr,
|
---|
| 86 | ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH,
|
---|
| 87 | AS_AREA_READ | AS_AREA_WRITE, (void *) &kchar.addr);
|
---|
[7c014d1] | 88 | if (rc != EOK)
|
---|
| 89 | return rc;
|
---|
[965dc18] | 90 |
|
---|
[7c014d1] | 91 | return serial_init(kchar_putchar, kchar_control_puts);
|
---|
[113c677] | 92 | }
|
---|
| 93 |
|
---|
[d9fae235] | 94 | /** @}
|
---|
[113c677] | 95 | */
|
---|