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