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