Rev 3607 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3607 | Rev 3618 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Pavel Rimsky |
2 | * Copyright (c) 2008 Pavel Rimsky |
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 | /** @addtogroup kbdsparc64 sparc64 |
29 | /** @addtogroup kbdsparc64 sparc64 |
30 | * @brief Serengeti-specific parts of uspace keyboard handler. |
30 | * @brief Serengeti-specific parts of uspace keyboard handler. |
31 | * @ingroup kbd |
31 | * @ingroup kbd |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <arch/sgcn.h> |
37 | #include <arch/sgcn.h> |
38 | #include <as.h> |
38 | #include <as.h> |
39 | #include <ddi.h> |
39 | #include <ddi.h> |
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <kbd.h> |
41 | #include <kbd.h> |
42 | #include <genarch/nofb.h> |
42 | #include <genarch/nofb.h> |
43 | #include <genarch/kbd.h> |
43 | #include <genarch/kbd.h> |
44 | #include <sysinfo.h> |
44 | #include <sysinfo.h> |
45 | #include <stdio.h> |
45 | #include <stdio.h> |
46 | #include <futex.h> |
46 | #include <futex.h> |
47 | 47 | ||
48 | /** |
48 | /** |
49 | * SGCN buffer header. It is placed at the very beginning of the SGCN |
49 | * SGCN buffer header. It is placed at the very beginning of the SGCN |
50 | * buffer. |
50 | * buffer. |
51 | */ |
51 | */ |
52 | typedef struct { |
52 | typedef struct { |
53 | /** hard-wired to "CON" */ |
53 | /** hard-wired to "CON" */ |
54 | char magic[4]; |
54 | char magic[4]; |
55 | 55 | ||
56 | /** we don't need this */ |
56 | /** we don't need this */ |
57 | char unused[8]; |
57 | char unused[8]; |
58 | 58 | ||
59 | /** offset within the SGCN buffer of the input buffer start */ |
59 | /** offset within the SGCN buffer of the input buffer start */ |
60 | uint32_t in_begin; |
60 | uint32_t in_begin; |
61 | 61 | ||
62 | /** offset within the SGCN buffer of the input buffer end */ |
62 | /** offset within the SGCN buffer of the input buffer end */ |
63 | uint32_t in_end; |
63 | uint32_t in_end; |
64 | 64 | ||
65 | /** offset within the SGCN buffer of the input buffer read pointer */ |
65 | /** offset within the SGCN buffer of the input buffer read pointer */ |
66 | uint32_t in_rdptr; |
66 | uint32_t in_rdptr; |
67 | 67 | ||
68 | /** offset within the SGCN buffer of the input buffer write pointer */ |
68 | /** offset within the SGCN buffer of the input buffer write pointer */ |
69 | uint32_t in_wrptr; |
69 | uint32_t in_wrptr; |
70 | } __attribute__ ((packed)) sgcn_buffer_header_t; |
70 | } __attribute__ ((packed)) sgcn_buffer_header_t; |
71 | 71 | ||
72 | /* |
72 | /* |
73 | * Returns a pointer to the object of a given type which is placed at the given |
73 | * Returns a pointer to the object of a given type which is placed at the given |
74 | * offset from the console buffer beginning. |
74 | * offset from the console buffer beginning. |
75 | */ |
75 | */ |
76 | #define SGCN_BUFFER(type, offset) \ |
76 | #define SGCN_BUFFER(type, offset) \ |
77 | ((type *) (sram_virt_addr + sram_buffer_offset + (offset))) |
77 | ((type *) (sram_virt_addr + sram_buffer_offset + (offset))) |
78 | 78 | ||
79 | /** Returns a pointer to the console buffer header. */ |
79 | /** Returns a pointer to the console buffer header. */ |
80 | #define SGCN_BUFFER_HEADER (SGCN_BUFFER(sgcn_buffer_header_t, 0)) |
80 | #define SGCN_BUFFER_HEADER (SGCN_BUFFER(sgcn_buffer_header_t, 0)) |
81 | 81 | ||
82 | extern keybuffer_t keybuffer; |
82 | extern keybuffer_t keybuffer; |
83 | 83 | ||
84 | /** |
84 | /** |
85 | * Virtual address mapped to SRAM. |
85 | * Virtual address mapped to SRAM. |
86 | */ |
86 | */ |
87 | static uintptr_t sram_virt_addr; |
87 | static uintptr_t sram_virt_addr; |
88 | 88 | ||
89 | /** |
89 | /** |
90 | * SGCN buffer offset within SGCN. |
90 | * SGCN buffer offset within SGCN. |
91 | */ |
91 | */ |
92 | static uintptr_t sram_buffer_offset; |
92 | static uintptr_t sram_buffer_offset; |
93 | 93 | ||
94 | /** |
94 | /** |
95 | * Initializes the SGCN driver. |
95 | * Initializes the SGCN driver. |
96 | * Maps the physical memory (SRAM) and registers the interrupt. |
96 | * Maps the physical memory (SRAM) and registers the interrupt. |
97 | */ |
97 | */ |
98 | void sgcn_init(void) |
98 | void sgcn_init(void) |
99 | { |
99 | { |
100 | sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size")); |
100 | sram_virt_addr = (uintptr_t) as_get_mappable_page( |
- | 101 | sysinfo_value("sram.area.size")); |
|
101 | int result = physmem_map( |
102 | int result = physmem_map( |
102 | (void *) sysinfo_value("sram.address.physical"), |
103 | (void *) sysinfo_value("sram.address.physical"), |
103 | (void *) sram_virt_addr, |
104 | (void *) sram_virt_addr, |
104 | sysinfo_value("sram.area.size") / PAGE_SIZE, |
105 | sysinfo_value("sram.area.size") / PAGE_SIZE, |
105 | AS_AREA_READ | AS_AREA_WRITE |
106 | AS_AREA_READ | AS_AREA_WRITE |
106 | ); |
107 | ); |
107 | if (result != 0) { |
108 | if (result != 0) { |
108 | printf("SGCN: uspace driver could not map physical memory."); |
109 | printf("SGCN: uspace driver could not map physical memory."); |
109 | } |
110 | } |
110 | 111 | ||
111 | sram_buffer_offset = sysinfo_value("sram.buffer.offset"); |
112 | sram_buffer_offset = sysinfo_value("sram.buffer.offset"); |
112 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), |
113 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), |
113 | 0, (void *) 0); |
114 | 0, (void *) 0); |
114 | } |
115 | } |
115 | 116 | ||
116 | /** |
117 | /** |
117 | * Handler of the "key pressed" event. Reads codes of all the pressed keys from |
118 | * Handler of the "key pressed" event. Reads codes of all the pressed keys from |
118 | * the buffer. |
119 | * the buffer. |
119 | */ |
120 | */ |
120 | void sgcn_key_pressed(void) |
121 | void sgcn_key_pressed(void) |
121 | { |
122 | { |
122 | char c; |
123 | char c; |
123 | 124 | ||
124 | uint32_t begin = SGCN_BUFFER_HEADER->in_begin; |
125 | uint32_t begin = SGCN_BUFFER_HEADER->in_begin; |
125 | uint32_t end = SGCN_BUFFER_HEADER->in_end; |
126 | uint32_t end = SGCN_BUFFER_HEADER->in_end; |
126 | uint32_t size = end - begin; |
127 | uint32_t size = end - begin; |
127 | 128 | ||
128 | volatile char *buf_ptr = (volatile char *) |
129 | volatile char *buf_ptr = (volatile char *) |
129 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
130 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
130 | volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr); |
131 | volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr); |
131 | volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr); |
132 | volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr); |
132 | 133 | ||
133 | while (*in_rdptr_ptr != *in_wrptr_ptr) { |
134 | while (*in_rdptr_ptr != *in_wrptr_ptr) { |
134 | c = *buf_ptr; |
135 | c = *buf_ptr; |
135 | *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin; |
136 | *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin; |
136 | buf_ptr = (volatile char *) |
137 | buf_ptr = (volatile char *) |
137 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
138 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
138 | if (c == '\r') { |
139 | if (c == '\r') { |
139 | c = '\n'; |
140 | c = '\n'; |
140 | } |
141 | } |
141 | kbd_process_no_fb(&keybuffer, c); |
142 | kbd_process_no_fb(&keybuffer, c); |
142 | } |
143 | } |
143 | } |
144 | } |
144 | 145 | ||
145 | /** @} |
146 | /** @} |
146 | */ |
- | |
147 | 147 | */ |
|
- | 148 |