Subversion Repositories HelenOS

Rev

Rev 567 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
332 palkovsky 1
/*
2
 * Copyright (C) 2005 Ondrej Palkovsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <arch/drivers/arc.h>
30
#include <arch/mm/page.h>
31
#include <print.h>
32
#include <arch.h>
33
#include <arch/byteorder.h>
573 palkovsky 34
#include <arch/mm/frame.h>
35
#include <mm/frame.h>
332 palkovsky 36
 
37
/* This is a good joke, SGI HAS different types than NT bioses... */
38
/* Here is the SGI type */
39
static char *basetypes[] = {
40
    "ExceptionBlock",
41
    "SystemParameterBlock",
42
    "FreeContiguous",
43
    "FreeMemory",
44
    "BadMemory",
45
    "LoadedProgram",
46
    "FirmwareTemporary",
47
    "FirmwarePermanent"
48
};
49
 
344 palkovsky 50
static char *ctypes[] = {
51
    "ARC_type",
52
    "CPU_type",
53
    "FPU_type",
54
    "PrimaryICache",
55
    "PrimaryDCache",
56
    "SecondaryICache",
57
    "SecondaryDCache",
58
    "SecondaryCache",
59
    "Memory",
60
    "EISAAdapter",
61
    "TCAdapter",
62
    "SCSIAdapter",
63
    "DTIAdapter",
64
    "MultiFunctionAdapter",
65
    "DiskController",
66
    "TapeController",
67
    "CDROMController",
68
    "WORMController",
69
    "SerialController",
70
    "NetworkController",
71
    "DisplayController",
72
    "ParallelController",
73
    "PointerController",
74
    "KeyboardController",
75
    "AudioController",
76
    "OtherController",
77
    "DiskPeripheral",
78
    "FloppyDiskPeripheral",
79
    "TapePeripheral",
80
    "ModemPeripheral",
81
    "MonitorPeripheral",
82
    "PrinterPeripheral",
83
    "PointerPeripheral",
84
    "KeyboardPeripheral",
85
    "TerminalPeripheral",
86
    "OtherPeripheral",
87
    "LinePeripheral",
88
    "NetworkPeripheral"
89
    "OtherPeripheral",
90
    "XTalkAdapter",
91
    "PCIAdapter",
92
    "GIOAdapter",
93
    "TPUAdapter",
94
    "Anonymous"
95
};
96
 
332 palkovsky 97
static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000);
98
static arc_func_vector_t *arc_entry;
99
 
100
static void _arc_putchar(char ch);
101
 
102
/** Initialize ARC structure
103
 *
104
 * @return 0 - ARC OK, -1 - ARC does not exist
105
 */
573 palkovsky 106
int arc_init(void)
332 palkovsky 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');
118
}
119
 
120
/** Return true if ARC is available */
121
int arc_enabled(void)
122
{
123
    return sbp != NULL;
124
}
125
 
344 palkovsky 126
static void arc_print_component(arc_component *c)
127
{
128
    int i;
129
 
130
    printf("%s: ",ctypes[c->type]);
131
    for (i=0;i < c->identifier_len;i++)
132
        putchar(c->identifier[i]);
133
    putchar('\n');
134
}
135
 
136
void arc_print_devices(void)
137
{
138
    arc_component *c,*next;
139
 
140
    if (!arc_enabled())
141
        return;
142
 
143
    c = arc_entry->getchild(NULL);
144
    while (c) {
145
        arc_print_component(c);
146
        next = arc_entry->getchild(c);
147
        while (!next) {
148
            next = arc_entry->getpeer(c);
149
            if (!next)
150
                c = arc_entry->getparent(c);
151
            if (!c)
152
                return;
153
        }
154
        c = next;
155
    }
156
}
157
 
332 palkovsky 158
void arc_print_memory_map(void)
159
{
160
    arc_memdescriptor_t *desc;
161
 
364 palkovsky 162
    if (!arc_enabled())
332 palkovsky 163
        return;
164
 
165
    printf("Memory map:\n");
166
 
167
    desc = arc_entry->getmemorydescriptor(NULL);
168
    while (desc) {
169
        printf("%s: %d (size: %dKB)\n",basetypes[desc->type],
573 palkovsky 170
               desc->basepage * ARC_FRAME,
171
               desc->basecount*ARC_FRAME/1024);
332 palkovsky 172
        desc = arc_entry->getmemorydescriptor(desc);
173
    }
174
}
175
 
176
/** Print charactor to console */
177
void arc_putchar(char ch)
178
{
179
    __u32 cnt;
413 jermar 180
    ipl_t ipl;
332 palkovsky 181
 
182
    /* TODO: Should be spinlock? */
413 jermar 183
    ipl = interrupts_disable();
332 palkovsky 184
    arc_entry->write(1, &ch, 1, &cnt);
413 jermar 185
    interrupts_restore(ipl);
332 palkovsky 186
 
187
}
567 palkovsky 188
 
189
/** Try to get character, return character or -1 if not available */
190
int arc_getchar(void)
191
{
192
    char ch;
193
    __u32 count;
194
    long result;
195
 
196
    if (arc_entry->getreadstatus(0))
197
        return -1;
198
    result = arc_entry->read(0, &ch, 1, &count);
199
    if (result || count!=1) {
200
        cpu_halt();
201
        return -1;
202
    }
203
    if (ch == '\r')
204
        return '\n';
205
    return ch;
206
}
573 palkovsky 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