Subversion Repositories HelenOS-historic

Rev

Rev 820 | Rev 853 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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