Subversion Repositories HelenOS

Rev

Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2722
Line 104... Line 104...
104
    "GIOAdapter",
104
    "GIOAdapter",
105
    "TPUAdapter",
105
    "TPUAdapter",
106
    "Anonymous"
106
    "Anonymous"
107
};
107
};
108
 
108
 
109
static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000);
109
static arc_sbp *sbp = (arc_sbp *) PA2KA(0x1000);
110
static arc_func_vector_t *arc_entry;
110
static arc_func_vector_t *arc_entry;
111
 
111
 
112
 
112
 
113
static void arc_putchar(char ch);
-
 
114
 
-
 
115
/** Return true if ARC is available */
113
/** Return true if ARC is available */
116
int arc_enabled(void)
114
#define arc_enabled() (sbp != NULL)
117
{
-
 
118
    return sbp != NULL;
-
 
119
}
-
 
120
 
115
 
121
 
116
 
122
/** Print configuration data that ARC reports about component */
117
/** Print configuration data that ARC reports about component */
123
static void arc_print_confdata(arc_component *c)
118
static void arc_print_confdata(arc_component *c)
124
{
119
{
Line 136... Line 131...
136
    }
131
    }
137
    /* Does not seem to return meaningful data, don't use now */
132
    /* Does not seem to return meaningful data, don't use now */
138
    free(configdata);
133
    free(configdata);
139
    return;
134
    return;
140
   
135
   
141
    for (i=0; i < configdata->count; i++) {
136
    for (i = 0; i < configdata->count; i++) {
142
        switch (configdata->descr[i].type) {
137
        switch (configdata->descr[i].type) {
143
        case CmResourceTypePort:
138
        case CmResourceTypePort:
144
            printf("Port: %p-size:%d ",
139
            printf("Port: %p-size:%d ",
145
                   (uintptr_t)configdata->descr[i].u.port.start,
140
                   (uintptr_t) configdata->descr[i].u.port.start,
146
                   configdata->descr[i].u.port.length);
141
                   configdata->descr[i].u.port.length);
147
            break;
142
            break;
148
        case CmResourceTypeInterrupt:
143
        case CmResourceTypeInterrupt:
149
            printf("Irq: level(%d) vector(%d) ",
144
            printf("Irq: level(%d) vector(%d) ",
150
                   configdata->descr[i].u.interrupt.level,
145
                   configdata->descr[i].u.interrupt.level,
Line 167... Line 162...
167
static void arc_print_component(arc_component *c)
162
static void arc_print_component(arc_component *c)
168
{
163
{
169
    int i;
164
    int i;
170
 
165
 
171
    printf("%s: ",ctypes[c->type]);
166
    printf("%s: ",ctypes[c->type]);
172
    for (i=0;i < c->identifier_len;i++)
167
    for (i = 0; i < c->identifier_len; i++)
173
        printf("%c",c->identifier[i]);
168
        printf("%c", c->identifier[i]);
174
 
169
 
175
    printf(" ");
170
    printf(" ");
176
    arc_print_confdata(c);
171
    arc_print_confdata(c);
177
    printf("\n");
172
    printf("\n");
178
}
173
}
Line 180... Line 175...
180
/**
175
/**
181
 * Read from ARC bios configuration data and print it
176
 * Read from ARC bios configuration data and print it
182
 */
177
 */
183
static int cmd_arc_print_devices(cmd_arg_t *argv)
178
static int cmd_arc_print_devices(cmd_arg_t *argv)
184
{
179
{
185
    arc_component *c,*next;
180
    arc_component *c, *next;
186
 
181
 
187
    c = arc_entry->getchild(NULL);
182
    c = arc_entry->getchild(NULL);
188
    while (c) {
183
    while (c) {
189
        arc_print_component(c);
184
        arc_print_component(c);
190
        next = arc_entry->getchild(c);
185
        next = arc_entry->getchild(c);
Line 208... Line 203...
208
 
203
 
209
 
204
 
210
/** Read from arc bios memory map and print it
205
/** Read from arc bios memory map and print it
211
 *
206
 *
212
 */
207
 */
213
static int cmd_arc_print_memmap(cmd_arg_t *argv)
208
void physmem_print(void)
214
{
209
{
215
    arc_memdescriptor_t *desc;
210
    printf("Base       Size       Type\n");
216
 
-
 
217
    printf("Memory map:\n");
211
    printf("---------- ---------- ---------\n");
218
 
212
   
-
 
213
    if (arc_enabled()) {
219
    desc = arc_entry->getmemorydescriptor(NULL);
214
        arc_memdescriptor_t *desc = arc_entry->getmemorydescriptor(NULL);
-
 
215
       
220
    while (desc) {
216
        while (desc) {
221
        printf("%s: %d(%p) (size: %dKB)\n",basetypes[desc->type],
217
            printf("%#10x %#10x %s\n",
222
               desc->basepage * ARC_FRAME,
-
 
223
               desc->basepage * ARC_FRAME,
218
                desc->basepage * ARC_FRAME, desc->basecount * ARC_FRAME,
224
               desc->basecount*ARC_FRAME/1024);
219
                basetypes[desc->type]);
225
        desc = arc_entry->getmemorydescriptor(desc);
220
            desc = arc_entry->getmemorydescriptor(desc);
226
    }
221
        }  
227
    return 1;
222
    } else
-
 
223
        printf("%#10x %#10x free\n", 0, config.memory_size);
228
}
224
}
229
static cmd_info_t memmap_info = {
-
 
230
    .name = "arcmemmap",
-
 
231
    .description = "Print arc memory map",
-
 
232
    .func = cmd_arc_print_memmap,
-
 
233
    .argc = 0
-
 
234
};
-
 
235
 
225
 
236
/** Print charactor to console */
226
/** Print charactor to console */
237
static void arc_putchar(char ch)
227
static void arc_putchar(char ch)
238
{
228
{
239
    uint32_t cnt;
229
    uint32_t cnt;
Line 241... Line 231...
241
 
231
 
242
    /* TODO: Should be spinlock? */
232
    /* TODO: Should be spinlock? */
243
    ipl = interrupts_disable();
233
    ipl = interrupts_disable();
244
    arc_entry->write(1, &ch, 1, &cnt);
234
    arc_entry->write(1, &ch, 1, &cnt);
245
    interrupts_restore(ipl);
235
    interrupts_restore(ipl);
246
   
-
 
247
}
236
}
248
 
237
 
249
static int cmd_reboot(cmd_arg_t *argv)
-
 
250
{
-
 
251
    arc_entry->reboot();
-
 
252
    return 0;
-
 
253
}
-
 
254
static cmd_info_t reboot_info = {
-
 
255
    .name = "reboot",
-
 
256
    .description = "Reboot computer",
-
 
257
    .func = cmd_reboot,
-
 
258
    .argc = 0
-
 
259
};
-
 
260
 
238
 
261
/** Initialize ARC structure
239
/** Initialize ARC structure
262
 *
240
 *
263
 * @return 0 - ARC OK, -1 - ARC does not exist
241
 * @return 0 - ARC OK, -1 - ARC does not exist
264
 */
242
 */
Line 274... Line 252...
274
    arc_putchar('R');
252
    arc_putchar('R');
275
    arc_putchar('C');
253
    arc_putchar('C');
276
    arc_putchar('\n');
254
    arc_putchar('\n');
277
 
255
 
278
    /* Add command for resetting the computer */
256
    /* Add command for resetting the computer */
279
    cmd_initialize(&reboot_info);
-
 
280
    cmd_register(&reboot_info);
-
 
281
    cmd_initialize(&memmap_info);
-
 
282
    cmd_register(&memmap_info);
-
 
283
    cmd_initialize(&devlist_info);
257
    cmd_initialize(&devlist_info);
284
    cmd_register(&devlist_info);
258
    cmd_register(&devlist_info);
285
 
259
 
286
    return 0;
260
    return 0;
287
}
261
}
288
 
262
 
-
 
263
int arc_reboot(void)
-
 
264
{
-
 
265
    if (arc_enabled()) {
-
 
266
        arc_entry->reboot();
-
 
267
        return true;
-
 
268
    }
-
 
269
   
-
 
270
    return false;
-
 
271
}
-
 
272
 
-
 
273
 
289
static bool kbd_polling_enabled;
274
static bool kbd_polling_enabled;
290
static chardev_t console;
275
static chardev_t console;
291
 
276
 
292
/** Try to get character, return character or -1 if not available */
277
/** Try to get character, return character or -1 if not available */
293
static void arc_keyboard_poll(void)
278
static void arc_keyboard_poll(void)
294
{
279
{
295
    char ch;
280
    char ch;
296
    uint32_t count;
281
    uint32_t count;
297
    long result;
282
    long result;
298
   
283
   
299
    if (! kbd_polling_enabled)
284
    if (!kbd_polling_enabled)
300
        return;
285
        return;
301
 
286
 
302
    if (arc_entry->getreadstatus(0))
287
    if (arc_entry->getreadstatus(0))
303
        return;
288
        return;
304
    result = arc_entry->read(0, &ch, 1, &count);
289
    result = arc_entry->read(0, &ch, 1, &count);
305
    if (result || count!=1) {
290
    if ((result) || (count != 1)) {
306
        return;
291
        return;
307
    }
292
    }
308
    if (ch == '\r')
293
    if (ch == '\r')
309
        ch = '\n';
294
        ch = '\n';
310
    if (ch == 0x7f)
295
    if (ch == 0x7f)
Line 318... Line 303...
318
    char ch;
303
    char ch;
319
    uint32_t count;
304
    uint32_t count;
320
    long result;
305
    long result;
321
 
306
 
322
    result = arc_entry->read(0, &ch, 1, &count);
307
    result = arc_entry->read(0, &ch, 1, &count);
323
    if (result || count!=1) {
308
    if ((result) || (count != 1)) {
324
        printf("Error reading from ARC keyboard.\n");
309
        printf("Error reading from ARC keyboard.\n");
325
        cpu_halt();
310
        cpu_halt();
326
    }
311
    }
327
    if (ch == '\r')
312
    if (ch == '\r')
328
        return '\n';
313
        return '\n';
Line 351... Line 336...
351
    .suspend = arc_disable,
336
    .suspend = arc_disable,
352
    .write = arc_write,
337
    .write = arc_write,
353
    .read = arc_read
338
    .read = arc_read
354
};
339
};
355
 
340
 
356
void arc_console(void)
341
int arc_console(void)
357
{
342
{
-
 
343
    if (arc_enabled()) {
358
    kbd_polling_enabled = true;
344
        kbd_polling_enabled = true;
-
 
345
       
-
 
346
        chardev_initialize("arc_console", &console, &arc_ops);
-
 
347
        virtual_timer_fnc = &arc_keyboard_poll;
-
 
348
        stdin = &console;
-
 
349
        stdout = &console;
-
 
350
       
-
 
351
        return true;
-
 
352
    }
359
   
353
   
360
    chardev_initialize("arc_console", &console, &arc_ops);
-
 
361
    virtual_timer_fnc = &arc_keyboard_poll;
-
 
362
    stdin = &console;
354
    return false;
363
    stdout = &console;
-
 
364
}
355
}
365
 
356
 
366
/* Initialize frame zones from ARC firmware.
357
/* Initialize frame zones from ARC firmware.
367
 * In the future we may use even the FirmwareTemporary regions,
358
 * In the future we may use even the FirmwareTemporary regions,
368
 * currently we use the FreeMemory (what about the LoadedProgram?)
359
 * currently we use the FreeMemory (what about the LoadedProgram?)
369
 */
360
 */
370
void arc_frame_init(void)
361
int arc_frame_init(void)
371
{
362
{
-
 
363
    if (arc_enabled()) {
372
    arc_memdescriptor_t *desc;
364
        arc_memdescriptor_t *desc;
373
    int total = 0;
365
        int total = 0;
374
    uintptr_t base;
366
        uintptr_t base;
375
    size_t basesize;
367
        size_t basesize;
376
 
368
   
377
    desc = arc_entry->getmemorydescriptor(NULL);
369
        desc = arc_entry->getmemorydescriptor(NULL);
378
    while (desc) {
370
        while (desc) {
379
        if (desc->type == FreeMemory ||
371
            if ((desc->type == FreeMemory) ||
380
            desc->type == FreeContiguous) {
372
                (desc->type == FreeContiguous)) {
381
            base = desc->basepage*ARC_FRAME;
373
                base = desc->basepage*ARC_FRAME;
382
            basesize = desc->basecount*ARC_FRAME;
374
                basesize = desc->basecount*ARC_FRAME;
383
 
375
   
384
            if (base % FRAME_SIZE ) {
376
                if (base % FRAME_SIZE ) {
385
                basesize -= FRAME_SIZE - (base % FRAME_SIZE);
377
                    basesize -= FRAME_SIZE - (base % FRAME_SIZE);
386
                base = ALIGN_UP(base, FRAME_SIZE);
378
                    base = ALIGN_UP(base, FRAME_SIZE);
-
 
379
                }
-
 
380
                basesize = ALIGN_DOWN(basesize, FRAME_SIZE);
-
 
381
   
-
 
382
                total += basesize;
-
 
383
               
-
 
384
                zone_create(ADDR2PFN(base), SIZE2FRAMES(basesize),
-
 
385
                        ADDR2PFN(base), 0);
387
            }
386
            }
388
            basesize = ALIGN_DOWN(basesize, FRAME_SIZE);
387
            desc = arc_entry->getmemorydescriptor(desc);
389
 
-
 
390
            total += basesize;
-
 
391
           
-
 
392
            zone_create(ADDR2PFN(base), SIZE2FRAMES(basesize),
-
 
393
                    ADDR2PFN(base), 0);
-
 
394
        }
388
        }
-
 
389
   
395
        desc = arc_entry->getmemorydescriptor(desc);
390
        config.memory_size = total;
-
 
391
        return true;
396
    }
392
    }
397
 
393
   
398
    config.memory_size = total;
394
    return false;
399
}
395
}
400
 
396
 
401
/** @}
397
/** @}
402
 */
398
 */