Rev 573 | Rev 577 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 573 | Rev 575 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Ondrej Palkovsky |
2 | * Copyright (C) 2005 Ondrej Palkovsky |
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/drivers/arc.h> |
29 | #include <arch/drivers/arc.h> |
30 | #include <arch/mm/page.h> |
30 | #include <arch/mm/page.h> |
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <arch.h> |
32 | #include <arch.h> |
33 | #include <arch/byteorder.h> |
33 | #include <arch/byteorder.h> |
34 | #include <arch/mm/frame.h> |
34 | #include <arch/mm/frame.h> |
35 | #include <mm/frame.h> |
35 | #include <mm/frame.h> |
- | 36 | #include <interrupt.h> |
|
36 | 37 | ||
37 | /* This is a good joke, SGI HAS different types than NT bioses... */ |
38 | /* This is a good joke, SGI HAS different types than NT bioses... */ |
38 | /* Here is the SGI type */ |
39 | /* Here is the SGI type */ |
39 | static char *basetypes[] = { |
40 | static char *basetypes[] = { |
40 | "ExceptionBlock", |
41 | "ExceptionBlock", |
41 | "SystemParameterBlock", |
42 | "SystemParameterBlock", |
42 | "FreeContiguous", |
43 | "FreeContiguous", |
43 | "FreeMemory", |
44 | "FreeMemory", |
44 | "BadMemory", |
45 | "BadMemory", |
45 | "LoadedProgram", |
46 | "LoadedProgram", |
46 | "FirmwareTemporary", |
47 | "FirmwareTemporary", |
47 | "FirmwarePermanent" |
48 | "FirmwarePermanent" |
48 | }; |
49 | }; |
49 | 50 | ||
50 | static char *ctypes[] = { |
51 | static char *ctypes[] = { |
51 | "ARC_type", |
52 | "ARC_type", |
52 | "CPU_type", |
53 | "CPU_type", |
53 | "FPU_type", |
54 | "FPU_type", |
54 | "PrimaryICache", |
55 | "PrimaryICache", |
55 | "PrimaryDCache", |
56 | "PrimaryDCache", |
56 | "SecondaryICache", |
57 | "SecondaryICache", |
57 | "SecondaryDCache", |
58 | "SecondaryDCache", |
58 | "SecondaryCache", |
59 | "SecondaryCache", |
59 | "Memory", |
60 | "Memory", |
60 | "EISAAdapter", |
61 | "EISAAdapter", |
61 | "TCAdapter", |
62 | "TCAdapter", |
62 | "SCSIAdapter", |
63 | "SCSIAdapter", |
63 | "DTIAdapter", |
64 | "DTIAdapter", |
64 | "MultiFunctionAdapter", |
65 | "MultiFunctionAdapter", |
65 | "DiskController", |
66 | "DiskController", |
66 | "TapeController", |
67 | "TapeController", |
67 | "CDROMController", |
68 | "CDROMController", |
68 | "WORMController", |
69 | "WORMController", |
69 | "SerialController", |
70 | "SerialController", |
70 | "NetworkController", |
71 | "NetworkController", |
71 | "DisplayController", |
72 | "DisplayController", |
72 | "ParallelController", |
73 | "ParallelController", |
73 | "PointerController", |
74 | "PointerController", |
74 | "KeyboardController", |
75 | "KeyboardController", |
75 | "AudioController", |
76 | "AudioController", |
76 | "OtherController", |
77 | "OtherController", |
77 | "DiskPeripheral", |
78 | "DiskPeripheral", |
78 | "FloppyDiskPeripheral", |
79 | "FloppyDiskPeripheral", |
79 | "TapePeripheral", |
80 | "TapePeripheral", |
80 | "ModemPeripheral", |
81 | "ModemPeripheral", |
81 | "MonitorPeripheral", |
82 | "MonitorPeripheral", |
82 | "PrinterPeripheral", |
83 | "PrinterPeripheral", |
83 | "PointerPeripheral", |
84 | "PointerPeripheral", |
84 | "KeyboardPeripheral", |
85 | "KeyboardPeripheral", |
85 | "TerminalPeripheral", |
86 | "TerminalPeripheral", |
86 | "OtherPeripheral", |
87 | "OtherPeripheral", |
87 | "LinePeripheral", |
88 | "LinePeripheral", |
88 | "NetworkPeripheral" |
89 | "NetworkPeripheral" |
89 | "OtherPeripheral", |
90 | "OtherPeripheral", |
90 | "XTalkAdapter", |
91 | "XTalkAdapter", |
91 | "PCIAdapter", |
92 | "PCIAdapter", |
92 | "GIOAdapter", |
93 | "GIOAdapter", |
93 | "TPUAdapter", |
94 | "TPUAdapter", |
94 | "Anonymous" |
95 | "Anonymous" |
95 | }; |
96 | }; |
96 | 97 | ||
97 | static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000); |
98 | static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000); |
98 | static arc_func_vector_t *arc_entry; |
99 | static arc_func_vector_t *arc_entry; |
99 | 100 | ||
100 | static void _arc_putchar(char ch); |
- | |
101 | 101 | ||
102 | /** Initialize ARC structure |
- | |
103 | * |
- | |
104 | * @return 0 - ARC OK, -1 - ARC does not exist |
- | |
105 | */ |
- | |
106 | int arc_init(void) |
- | |
107 | { |
- | |
108 | if (sbp->signature != ARC_MAGIC) { |
- | |
109 | sbp = NULL; |
- | |
110 | return -1; |
- | |
111 | } |
- | |
112 | arc_entry = sbp->firmwarevector; |
- | |
113 | - | ||
114 | arc_putchar('A'); |
- | |
115 | arc_putchar('R'); |
- | |
116 | arc_putchar('C'); |
- | |
117 | arc_putchar('\n'); |
102 | static void arc_putchar(char ch); |
118 | } |
- | |
119 | 103 | ||
120 | /** Return true if ARC is available */ |
104 | /** Return true if ARC is available */ |
121 | int arc_enabled(void) |
105 | int arc_enabled(void) |
122 | { |
106 | { |
123 | return sbp != NULL; |
107 | return sbp != NULL; |
124 | } |
108 | } |
125 | 109 | ||
126 | static void arc_print_component(arc_component *c) |
110 | static void arc_print_component(arc_component *c) |
127 | { |
111 | { |
128 | int i; |
112 | int i; |
129 | 113 | ||
130 | printf("%s: ",ctypes[c->type]); |
114 | printf("%s: ",ctypes[c->type]); |
131 | for (i=0;i < c->identifier_len;i++) |
115 | for (i=0;i < c->identifier_len;i++) |
132 | putchar(c->identifier[i]); |
116 | arc_putchar(c->identifier[i]); |
133 | putchar('\n'); |
117 | arc_putchar('\n'); |
134 | } |
118 | } |
135 | 119 | ||
136 | void arc_print_devices(void) |
120 | void arc_print_devices(void) |
137 | { |
121 | { |
138 | arc_component *c,*next; |
122 | arc_component *c,*next; |
139 | 123 | ||
140 | if (!arc_enabled()) |
124 | if (!arc_enabled()) |
141 | return; |
125 | return; |
142 | 126 | ||
143 | c = arc_entry->getchild(NULL); |
127 | c = arc_entry->getchild(NULL); |
144 | while (c) { |
128 | while (c) { |
145 | arc_print_component(c); |
129 | arc_print_component(c); |
146 | next = arc_entry->getchild(c); |
130 | next = arc_entry->getchild(c); |
147 | while (!next) { |
131 | while (!next) { |
148 | next = arc_entry->getpeer(c); |
132 | next = arc_entry->getpeer(c); |
149 | if (!next) |
133 | if (!next) |
150 | c = arc_entry->getparent(c); |
134 | c = arc_entry->getparent(c); |
151 | if (!c) |
135 | if (!c) |
152 | return; |
136 | return; |
153 | } |
137 | } |
154 | c = next; |
138 | c = next; |
155 | } |
139 | } |
156 | } |
140 | } |
157 | 141 | ||
158 | void arc_print_memory_map(void) |
142 | void arc_print_memory_map(void) |
159 | { |
143 | { |
160 | arc_memdescriptor_t *desc; |
144 | arc_memdescriptor_t *desc; |
161 | 145 | ||
162 | if (!arc_enabled()) |
146 | if (!arc_enabled()) |
163 | return; |
147 | return; |
164 | 148 | ||
165 | printf("Memory map:\n"); |
149 | printf("Memory map:\n"); |
166 | 150 | ||
167 | desc = arc_entry->getmemorydescriptor(NULL); |
151 | desc = arc_entry->getmemorydescriptor(NULL); |
168 | while (desc) { |
152 | while (desc) { |
169 | printf("%s: %d (size: %dKB)\n",basetypes[desc->type], |
153 | printf("%s: %d (size: %dKB)\n",basetypes[desc->type], |
170 | desc->basepage * ARC_FRAME, |
154 | desc->basepage * ARC_FRAME, |
171 | desc->basecount*ARC_FRAME/1024); |
155 | desc->basecount*ARC_FRAME/1024); |
172 | desc = arc_entry->getmemorydescriptor(desc); |
156 | desc = arc_entry->getmemorydescriptor(desc); |
173 | } |
157 | } |
174 | } |
158 | } |
175 | 159 | ||
176 | /** Print charactor to console */ |
160 | /** Print charactor to console */ |
177 | void arc_putchar(char ch) |
161 | static void arc_putchar(char ch) |
178 | { |
162 | { |
179 | __u32 cnt; |
163 | __u32 cnt; |
180 | ipl_t ipl; |
164 | ipl_t ipl; |
181 | 165 | ||
182 | /* TODO: Should be spinlock? */ |
166 | /* TODO: Should be spinlock? */ |
183 | ipl = interrupts_disable(); |
167 | ipl = interrupts_disable(); |
184 | arc_entry->write(1, &ch, 1, &cnt); |
168 | arc_entry->write(1, &ch, 1, &cnt); |
185 | interrupts_restore(ipl); |
169 | interrupts_restore(ipl); |
186 | 170 | ||
187 | } |
171 | } |
188 | 172 | ||
- | 173 | /** Initialize ARC structure |
|
- | 174 | * |
|
- | 175 | * @return 0 - ARC OK, -1 - ARC does not exist |
|
- | 176 | */ |
|
- | 177 | int arc_init(void) |
|
- | 178 | { |
|
- | 179 | if (sbp->signature != ARC_MAGIC) { |
|
- | 180 | sbp = NULL; |
|
- | 181 | return -1; |
|
- | 182 | } |
|
- | 183 | arc_entry = sbp->firmwarevector; |
|
- | 184 | ||
- | 185 | arc_putchar('A'); |
|
- | 186 | arc_putchar('R'); |
|
- | 187 | arc_putchar('C'); |
|
- | 188 | arc_putchar('\n'); |
|
- | 189 | } |
|
- | 190 | ||
- | 191 | static int kbd_polling_enabled; |
|
- | 192 | static chardev_t console; |
|
- | 193 | ||
189 | /** Try to get character, return character or -1 if not available */ |
194 | /** Try to get character, return character or -1 if not available */ |
190 | int arc_getchar(void) |
195 | static void arc_keyboard_poll(void) |
191 | { |
196 | { |
192 | char ch; |
197 | char ch; |
193 | __u32 count; |
198 | __u32 count; |
194 | long result; |
199 | long result; |
- | 200 | ||
- | 201 | if (! kbd_polling_enabled) |
|
- | 202 | return; |
|
195 | 203 | ||
196 | if (arc_entry->getreadstatus(0)) |
204 | if (arc_entry->getreadstatus(0)) |
197 | return -1; |
205 | return; |
198 | result = arc_entry->read(0, &ch, 1, &count); |
206 | result = arc_entry->read(0, &ch, 1, &count); |
199 | if (result || count!=1) { |
207 | if (result || count!=1) { |
200 | cpu_halt(); |
- | |
201 | return -1; |
208 | return; |
202 | } |
209 | } |
203 | if (ch == '\r') |
210 | if (ch == '\r') |
204 | return '\n'; |
211 | ch = '\n'; |
- | 212 | ||
- | 213 | chardev_push_character(&console, ch); |
|
- | 214 | } |
|
- | 215 | ||
- | 216 | static void arc_write(chardev_t *dev, const char ch) |
|
- | 217 | { |
|
- | 218 | arc_putchar(ch); |
|
- | 219 | } |
|
- | 220 | ||
- | 221 | static void arc_enable(chardev_t *dev) |
|
- | 222 | { |
|
- | 223 | kbd_polling_enabled = 1; |
|
- | 224 | } |
|
- | 225 | ||
- | 226 | static void arc_disable(chardev_t *dev) |
|
- | 227 | { |
|
- | 228 | kbd_polling_enabled = 0; |
|
- | 229 | } |
|
- | 230 | ||
- | 231 | static chardev_operations_t arc_ops = { |
|
- | 232 | .resume = arc_enable, |
|
- | 233 | .suspend = arc_disable, |
|
- | 234 | .write = arc_write |
|
- | 235 | }; |
|
- | 236 | ||
- | 237 | iroutine old_timer; |
|
- | 238 | /** Do polling on timer interrupt */ |
|
- | 239 | static void timer_replace(int n, void *stack) |
|
- | 240 | { |
|
- | 241 | arc_keyboard_poll(); |
|
- | 242 | old_timer(n, stack); |
|
- | 243 | arc_keyboard_poll(); |
|
- | 244 | } |
|
- | 245 | ||
- | 246 | ||
- | 247 | chardev_t * arc_console(void) |
|
- | 248 | { |
|
- | 249 | kbd_polling_enabled = 1; |
|
- | 250 | ||
- | 251 | chardev_initialize("arc_console", &console, &arc_ops); |
|
- | 252 | old_timer = exc_register(TIMER_IRQ, "arc_kb_poll", timer_replace); |
|
205 | return ch; |
253 | return &console; |
206 | } |
254 | } |
207 | 255 | ||
208 | /* Initialize frame zones from ARC firmware. |
256 | /* Initialize frame zones from ARC firmware. |
209 | * In the future we may use even the FirmwareTemporary regions, |
257 | * In the future we may use even the FirmwareTemporary regions, |
210 | * currently we use the FreeMemory (what about the LoadedProgram?) |
258 | * currently we use the FreeMemory (what about the LoadedProgram?) |
211 | */ |
259 | */ |
212 | void arc_frame_init(void) |
260 | void arc_frame_init(void) |
213 | { |
261 | { |
214 | arc_memdescriptor_t *desc; |
262 | arc_memdescriptor_t *desc; |
215 | int total = 0; |
263 | int total = 0; |
216 | 264 | ||
217 | desc = arc_entry->getmemorydescriptor(NULL); |
265 | desc = arc_entry->getmemorydescriptor(NULL); |
218 | while (desc) { |
266 | while (desc) { |
219 | if (desc->type == FreeMemory || |
267 | if (desc->type == FreeMemory || |
220 | desc->type == FreeContiguous) { |
268 | desc->type == FreeContiguous) { |
221 | total += desc->basecount*ARC_FRAME; |
269 | total += desc->basecount*ARC_FRAME; |
222 | zone_create_in_region(desc->basepage*ARC_FRAME, |
270 | zone_create_in_region(desc->basepage*ARC_FRAME, |
223 | desc->basecount*ARC_FRAME); |
271 | desc->basecount*ARC_FRAME); |
224 | } |
272 | } |
225 | desc = arc_entry->getmemorydescriptor(desc); |
273 | desc = arc_entry->getmemorydescriptor(desc); |
226 | } |
274 | } |
227 | 275 | ||
228 | config.memory_size = total; |
276 | config.memory_size = total; |
229 | } |
277 | } |
230 | 278 | ||
231 | 279 |