Rev 3908 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3908 | Rev 4153 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * Copyright (c) 2008 Pavel Rimsky |
4 | * Copyright (c) 2008 Pavel Rimsky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** @defgroup sgcnfb SGCN |
31 | /** @defgroup sgcnfb SGCN |
32 | * @brief userland driver of the Serengeti console output |
32 | * @brief userland driver of the Serengeti console output |
33 | * @{ |
33 | * @{ |
34 | */ |
34 | */ |
35 | /** @file |
35 | /** @file |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <sysinfo.h> |
39 | #include <sysinfo.h> |
40 | #include <as.h> |
40 | #include <as.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | #include <stdio.h> |
42 | #include <stdio.h> |
43 | #include <ddi.h> |
43 | #include <ddi.h> |
44 | 44 | ||
45 | #include "serial_console.h" |
45 | #include "serial_console.h" |
46 | #include "sgcn.h" |
46 | #include "sgcn.h" |
47 | 47 | ||
48 | #define WIDTH 80 |
48 | #define WIDTH 80 |
49 | #define HEIGHT 24 |
49 | #define HEIGHT 24 |
50 | 50 | ||
51 | /** |
51 | /** |
52 | * Virtual address mapped to SRAM. |
52 | * Virtual address mapped to SRAM. |
53 | */ |
53 | */ |
54 | static uintptr_t sram_virt_addr; |
54 | static uintptr_t sram_virt_addr; |
55 | 55 | ||
56 | /** |
56 | /** |
57 | * SGCN buffer offset within SGCN. |
57 | * SGCN buffer offset within SGCN. |
58 | */ |
58 | */ |
59 | static uintptr_t sram_buffer_offset; |
59 | static uintptr_t sram_buffer_offset; |
60 | 60 | ||
61 | /** |
61 | /** |
62 | * SGCN buffer header. It is placed at the very beginning of the SGCN |
62 | * SGCN buffer header. It is placed at the very beginning of the SGCN |
63 | * buffer. |
63 | * buffer. |
64 | */ |
64 | */ |
65 | typedef struct { |
65 | typedef struct { |
66 | /** hard-wired to "CON" */ |
66 | /** hard-wired to "CON" */ |
67 | char magic[4]; |
67 | char magic[4]; |
68 | 68 | ||
69 | /** we don't need this */ |
69 | /** we don't need this */ |
70 | char unused[24]; |
70 | char unused[24]; |
71 | 71 | ||
72 | /** offset within the SGCN buffer of the output buffer start */ |
72 | /** offset within the SGCN buffer of the output buffer start */ |
73 | uint32_t out_begin; |
73 | uint32_t out_begin; |
74 | 74 | ||
75 | /** offset within the SGCN buffer of the output buffer end */ |
75 | /** offset within the SGCN buffer of the output buffer end */ |
76 | uint32_t out_end; |
76 | uint32_t out_end; |
77 | 77 | ||
78 | /** offset within the SGCN buffer of the output buffer read pointer */ |
78 | /** offset within the SGCN buffer of the output buffer read pointer */ |
79 | uint32_t out_rdptr; |
79 | uint32_t out_rdptr; |
80 | 80 | ||
81 | /** offset within the SGCN buffer of the output buffer write pointer */ |
81 | /** offset within the SGCN buffer of the output buffer write pointer */ |
82 | uint32_t out_wrptr; |
82 | uint32_t out_wrptr; |
83 | } __attribute__ ((packed)) sgcn_buffer_header_t; |
83 | } __attribute__ ((packed)) sgcn_buffer_header_t; |
84 | 84 | ||
85 | 85 | ||
86 | /* |
86 | /* |
87 | * Returns a pointer to the object of a given type which is placed at the given |
87 | * Returns a pointer to the object of a given type which is placed at the given |
88 | * offset from the console buffer beginning. |
88 | * offset from the console buffer beginning. |
89 | */ |
89 | */ |
90 | #define SGCN_BUFFER(type, offset) \ |
90 | #define SGCN_BUFFER(type, offset) \ |
91 | ((type *) (sram_virt_addr + sram_buffer_offset + (offset))) |
91 | ((type *) (sram_virt_addr + sram_buffer_offset + (offset))) |
92 | 92 | ||
93 | /** Returns a pointer to the console buffer header. */ |
93 | /** Returns a pointer to the console buffer header. */ |
94 | #define SGCN_BUFFER_HEADER (SGCN_BUFFER(sgcn_buffer_header_t, 0)) |
94 | #define SGCN_BUFFER_HEADER (SGCN_BUFFER(sgcn_buffer_header_t, 0)) |
95 | 95 | ||
96 | /** |
96 | /** |
97 | * Pushes the character to the SGCN serial. |
97 | * Pushes the character to the SGCN serial. |
98 | * @param c character to be pushed |
98 | * @param c character to be pushed |
99 | */ |
99 | */ |
100 | static void sgcn_putc(char c) |
100 | static void sgcn_putc(char c) |
101 | { |
101 | { |
102 | uint32_t begin = SGCN_BUFFER_HEADER->out_begin; |
102 | uint32_t begin = SGCN_BUFFER_HEADER->out_begin; |
103 | uint32_t end = SGCN_BUFFER_HEADER->out_end; |
103 | uint32_t end = SGCN_BUFFER_HEADER->out_end; |
104 | uint32_t size = end - begin; |
104 | uint32_t size = end - begin; |
105 | 105 | ||
106 | /* we need pointers to volatile variables */ |
106 | /* we need pointers to volatile variables */ |
107 | volatile char *buf_ptr = (volatile char *) |
107 | volatile char *buf_ptr = (volatile char *) |
108 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->out_wrptr); |
108 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->out_wrptr); |
109 | volatile uint32_t *out_wrptr_ptr = &(SGCN_BUFFER_HEADER->out_wrptr); |
109 | volatile uint32_t *out_wrptr_ptr = &(SGCN_BUFFER_HEADER->out_wrptr); |
110 | volatile uint32_t *out_rdptr_ptr = &(SGCN_BUFFER_HEADER->out_rdptr); |
110 | volatile uint32_t *out_rdptr_ptr = &(SGCN_BUFFER_HEADER->out_rdptr); |
111 | 111 | ||
112 | uint32_t new_wrptr = (((*out_wrptr_ptr) - begin + 1) % size) + begin; |
112 | uint32_t new_wrptr = (((*out_wrptr_ptr) - begin + 1) % size) + begin; |
113 | while (*out_rdptr_ptr == new_wrptr) |
113 | while (*out_rdptr_ptr == new_wrptr) |
114 | ; |
114 | ; |
115 | *buf_ptr = c; |
115 | *buf_ptr = c; |
116 | *out_wrptr_ptr = new_wrptr; |
116 | *out_wrptr_ptr = new_wrptr; |
117 | } |
117 | } |
118 | 118 | ||
119 | /** |
119 | /** |
120 | * Initializes the SGCN serial driver. |
120 | * Initializes the SGCN serial driver. |
121 | */ |
121 | */ |
122 | int sgcn_init(void) |
122 | int sgcn_init(void) |
123 | { |
123 | { |
124 | sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size")); |
124 | sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size")); |
125 | 125 | ||
126 | if (physmem_map((void *) sysinfo_value("sram.address.physical"), |
126 | if (physmem_map((void *) sysinfo_value("sram.address.physical"), |
127 | (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE, |
127 | (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE, |
128 | AS_AREA_READ | AS_AREA_WRITE) != 0) |
128 | AS_AREA_READ | AS_AREA_WRITE) != 0) |
129 | return -1; |
129 | return -1; |
130 | 130 | ||
131 | serial_console_init(sgcn_putc, WIDTH, HEIGHT); |
131 | serial_console_init(sgcn_putc, WIDTH, HEIGHT); |
132 | 132 | ||
133 | sram_buffer_offset = sysinfo_value("sram.buffer.offset"); |
133 | sram_buffer_offset = sysinfo_value("sram.buffer.offset"); |
134 | 134 | ||
135 | async_set_client_connection(serial_client_connection); |
135 | async_set_client_connection(serial_client_connection); |
136 | return 0; |
136 | return 0; |
137 | } |
137 | } |
138 | 138 | ||
139 | /** |
139 | /** |
140 | * @} |
140 | * @} |
141 | */ |
141 | */ |
142 | 142 | ||
143 | 143 |