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