Rev 664 | Rev 883 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 664 | Rev 669 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Jakub Jermar |
2 | * Copyright (C) 2005 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <arch/console.h> |
29 | #include <arch/console.h> |
30 | #include <genarch/ofw/ofw.h> |
30 | #include <genarch/ofw/ofw.h> |
31 | #include <console/chardev.h> |
31 | #include <console/chardev.h> |
32 | #include <console/console.h> |
32 | #include <console/console.h> |
33 | #include <arch/asm.h> |
33 | #include <arch/asm.h> |
34 | #include <arch/register.h> |
34 | #include <arch/register.h> |
- | 35 | #include <arch/types.h> |
|
- | 36 | #include <typedefs.h> |
|
- | 37 | #include <proc/thread.h> |
|
- | 38 | #include <synch/mutex.h> |
|
35 | 39 | ||
36 | static void ofw_sparc64_putchar(chardev_t *d, const char ch); |
40 | static void ofw_sparc64_putchar(chardev_t *d, const char ch); |
- | 41 | static char ofw_sparc64_getchar(chardev_t *d); |
|
- | 42 | static void ofw_sparc64_suspend(chardev_t *d); |
|
- | 43 | static void ofw_sparc64_resume(chardev_t *d); |
|
- | 44 | ||
- | 45 | mutex_t canwork; |
|
37 | 46 | ||
38 | static chardev_t ofw_sparc64_console; |
47 | static chardev_t ofw_sparc64_console; |
39 | static chardev_operations_t ofw_sparc64_console_ops = { |
48 | static chardev_operations_t ofw_sparc64_console_ops = { |
40 | .write = ofw_sparc64_putchar |
49 | .write = ofw_sparc64_putchar, |
- | 50 | .read = ofw_sparc64_getchar, |
|
- | 51 | .resume = ofw_sparc64_resume, |
|
- | 52 | .suspend = ofw_sparc64_suspend |
|
41 | }; |
53 | }; |
42 | 54 | ||
43 | void ofw_sparc64_console_init(void) |
55 | void ofw_sparc64_console_init(void) |
44 | { |
56 | { |
45 | chardev_initialize("ofw_sparc64_console", &ofw_sparc64_console, &ofw_sparc64_console_ops); |
57 | chardev_initialize("ofw_sparc64_console", &ofw_sparc64_console, &ofw_sparc64_console_ops); |
- | 58 | stdin = &ofw_sparc64_console; |
|
46 | stdout = &ofw_sparc64_console; |
59 | stdout = &ofw_sparc64_console; |
- | 60 | mutex_initialize(&canwork); |
|
47 | } |
61 | } |
48 | 62 | ||
49 | /** Print one character. |
63 | /** Write one character. |
50 | * |
64 | * |
- | 65 | * @param d Character device (ignored). |
|
51 | * @param ch Character to be printed. |
66 | * @param ch Character to be written. |
52 | */ |
67 | */ |
53 | void ofw_sparc64_putchar(chardev_t *d, const char ch) |
68 | void ofw_sparc64_putchar(chardev_t *d, const char ch) |
54 | { |
69 | { |
55 | pstate_reg_t pstate; |
70 | pstate_reg_t pstate; |
56 | 71 | ||
57 | /* |
72 | /* |
58 | * 32-bit OpenFirmware depends on PSTATE.AM bit set. |
73 | * 32-bit OpenFirmware depends on PSTATE.AM bit set. |
59 | */ |
74 | */ |
60 | pstate.value = pstate_read(); |
75 | pstate.value = pstate_read(); |
61 | pstate.am = true; |
76 | pstate.am = true; |
62 | pstate_write(pstate.value); |
77 | pstate_write(pstate.value); |
63 | 78 | ||
64 | if (ch == '\n') |
79 | if (ch == '\n') |
65 | ofw_putchar('\r'); |
80 | ofw_putchar('\r'); |
66 | ofw_putchar(ch); |
81 | ofw_putchar(ch); |
67 | 82 | ||
68 | pstate.am = false; |
83 | pstate.am = false; |
69 | pstate_write(pstate.value); |
84 | pstate_write(pstate.value); |
70 | } |
85 | } |
- | 86 | ||
- | 87 | /** Read one character. |
|
- | 88 | * |
|
- | 89 | * The call is non-blocking. |
|
- | 90 | * |
|
- | 91 | * @param d Character device (ignored). |
|
- | 92 | * @return Character read or zero if no character was read. |
|
- | 93 | */ |
|
- | 94 | char ofw_sparc64_getchar(chardev_t *d) |
|
- | 95 | { |
|
- | 96 | char ch; |
|
- | 97 | pstate_reg_t pstate; |
|
- | 98 | ||
- | 99 | /* |
|
- | 100 | * 32-bit OpenFirmware depends on PSTATE.AM bit set. |
|
- | 101 | */ |
|
- | 102 | pstate.value = pstate_read(); |
|
- | 103 | pstate.am = true; |
|
- | 104 | pstate_write(pstate.value); |
|
- | 105 | ||
- | 106 | ch = ofw_getchar(); |
|
- | 107 | ||
- | 108 | pstate.am = false; |
|
- | 109 | pstate_write(pstate.value); |
|
- | 110 | ||
- | 111 | return ch; |
|
- | 112 | } |
|
- | 113 | ||
- | 114 | void ofw_sparc64_suspend(chardev_t *d) |
|
- | 115 | { |
|
- | 116 | mutex_lock(&canwork); |
|
- | 117 | } |
|
- | 118 | ||
- | 119 | void ofw_sparc64_resume(chardev_t *d) |
|
- | 120 | { |
|
- | 121 | mutex_unlock(&canwork); |
|
- | 122 | } |
|
- | 123 | ||
- | 124 | /** Kernel thread for pushing characters read from OFW to input buffer. |
|
- | 125 | * |
|
- | 126 | * @param arg Ignored. |
|
- | 127 | */ |
|
- | 128 | void kofwinput(void *arg) |
|
- | 129 | { |
|
- | 130 | ||
- | 131 | while (1) { |
|
- | 132 | char ch = 0; |
|
- | 133 | ||
- | 134 | mutex_lock(&canwork); |
|
- | 135 | mutex_unlock(&canwork); |
|
- | 136 | ||
- | 137 | ch = ofw_sparc64_getchar(NULL); |
|
- | 138 | if (ch) { |
|
- | 139 | if (ch == '\r') |
|
- | 140 | ch = '\n'; |
|
- | 141 | chardev_push_character(&ofw_sparc64_console, ch); |
|
- | 142 | } |
|
- | 143 | thread_usleep(25000); |
|
- | 144 | } |
|
- | 145 | } |
|
71 | 146 |