[3156582] | 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 |
|
---|
[06e1e95] | 29 | /** @addtogroup mips32
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3156582] | 35 | #include <arch/drivers/arc.h>
|
---|
| 36 | #include <arch/mm/page.h>
|
---|
| 37 | #include <print.h>
|
---|
| 38 | #include <arch.h>
|
---|
| 39 | #include <arch/byteorder.h>
|
---|
[939dfd7] | 40 | #include <arch/mm/frame.h>
|
---|
| 41 | #include <mm/frame.h>
|
---|
[973be64e] | 42 | #include <interrupt.h>
|
---|
[c0b7f00] | 43 | #include <align.h>
|
---|
[af9a7c5] | 44 | #include <console/console.h>
|
---|
[052da81] | 45 | #include <console/kconsole.h>
|
---|
| 46 | #include <console/cmd.h>
|
---|
[daea4bf] | 47 | #include <mm/slab.h>
|
---|
[3156582] | 48 |
|
---|
| 49 | /* This is a good joke, SGI HAS different types than NT bioses... */
|
---|
| 50 | /* Here is the SGI type */
|
---|
| 51 | static char *basetypes[] = {
|
---|
| 52 | "ExceptionBlock",
|
---|
| 53 | "SystemParameterBlock",
|
---|
| 54 | "FreeContiguous",
|
---|
| 55 | "FreeMemory",
|
---|
| 56 | "BadMemory",
|
---|
| 57 | "LoadedProgram",
|
---|
| 58 | "FirmwareTemporary",
|
---|
| 59 | "FirmwarePermanent"
|
---|
| 60 | };
|
---|
| 61 |
|
---|
[c7a7656] | 62 | static char *ctypes[] = {
|
---|
| 63 | "ARC_type",
|
---|
| 64 | "CPU_type",
|
---|
| 65 | "FPU_type",
|
---|
| 66 | "PrimaryICache",
|
---|
| 67 | "PrimaryDCache",
|
---|
| 68 | "SecondaryICache",
|
---|
| 69 | "SecondaryDCache",
|
---|
| 70 | "SecondaryCache",
|
---|
| 71 | "Memory",
|
---|
| 72 | "EISAAdapter",
|
---|
| 73 | "TCAdapter",
|
---|
| 74 | "SCSIAdapter",
|
---|
| 75 | "DTIAdapter",
|
---|
| 76 | "MultiFunctionAdapter",
|
---|
| 77 | "DiskController",
|
---|
| 78 | "TapeController",
|
---|
| 79 | "CDROMController",
|
---|
| 80 | "WORMController",
|
---|
| 81 | "SerialController",
|
---|
| 82 | "NetworkController",
|
---|
| 83 | "DisplayController",
|
---|
| 84 | "ParallelController",
|
---|
| 85 | "PointerController",
|
---|
| 86 | "KeyboardController",
|
---|
| 87 | "AudioController",
|
---|
| 88 | "OtherController",
|
---|
| 89 | "DiskPeripheral",
|
---|
| 90 | "FloppyDiskPeripheral",
|
---|
| 91 | "TapePeripheral",
|
---|
| 92 | "ModemPeripheral",
|
---|
| 93 | "MonitorPeripheral",
|
---|
| 94 | "PrinterPeripheral",
|
---|
| 95 | "PointerPeripheral",
|
---|
| 96 | "KeyboardPeripheral",
|
---|
| 97 | "TerminalPeripheral",
|
---|
| 98 | "OtherPeripheral",
|
---|
| 99 | "LinePeripheral",
|
---|
| 100 | "NetworkPeripheral"
|
---|
| 101 | "OtherPeripheral",
|
---|
| 102 | "XTalkAdapter",
|
---|
| 103 | "PCIAdapter",
|
---|
| 104 | "GIOAdapter",
|
---|
| 105 | "TPUAdapter",
|
---|
| 106 | "Anonymous"
|
---|
| 107 | };
|
---|
| 108 |
|
---|
[3156582] | 109 | static arc_sbp *sbp = (arc_sbp *)PA2KA(0x1000);
|
---|
| 110 | static arc_func_vector_t *arc_entry;
|
---|
| 111 |
|
---|
| 112 |
|
---|
[973be64e] | 113 | static void arc_putchar(char ch);
|
---|
[3156582] | 114 |
|
---|
| 115 | /** Return true if ARC is available */
|
---|
| 116 | int arc_enabled(void)
|
---|
| 117 | {
|
---|
| 118 | return sbp != NULL;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[daea4bf] | 121 |
|
---|
| 122 | /** Print configuration data that ARC reports about component */
|
---|
| 123 | static void arc_print_confdata(arc_component *c)
|
---|
| 124 | {
|
---|
| 125 | cm_resource_list *configdata;
|
---|
| 126 | int i;
|
---|
| 127 |
|
---|
| 128 | if (!c->configdatasize)
|
---|
| 129 | return; /* No configuration data */
|
---|
| 130 |
|
---|
| 131 | configdata = malloc(c->configdatasize, 0);
|
---|
| 132 |
|
---|
| 133 | if (arc_entry->getconfigurationdata(configdata, c)) {
|
---|
| 134 | free(configdata);
|
---|
| 135 | return;
|
---|
| 136 | }
|
---|
| 137 | /* Does not seem to return meaningful data, don't use now */
|
---|
| 138 | free(configdata);
|
---|
| 139 | return;
|
---|
| 140 |
|
---|
| 141 | for (i=0; i < configdata->count; i++) {
|
---|
| 142 | switch (configdata->descr[i].type) {
|
---|
| 143 | case CmResourceTypePort:
|
---|
[cf85e24c] | 144 | printf("Port: %p-size:%d ",
|
---|
[7f1c620] | 145 | (uintptr_t)configdata->descr[i].u.port.start,
|
---|
[daea4bf] | 146 | configdata->descr[i].u.port.length);
|
---|
| 147 | break;
|
---|
| 148 | case CmResourceTypeInterrupt:
|
---|
| 149 | printf("Irq: level(%d) vector(%d) ",
|
---|
| 150 | configdata->descr[i].u.interrupt.level,
|
---|
| 151 | configdata->descr[i].u.interrupt.vector);
|
---|
| 152 | break;
|
---|
| 153 | case CmResourceTypeMemory:
|
---|
[cf85e24c] | 154 | printf("Memory: %p-size:%d ",
|
---|
[7f1c620] | 155 | (uintptr_t)configdata->descr[i].u.port.start,
|
---|
[daea4bf] | 156 | configdata->descr[i].u.port.length);
|
---|
| 157 | break;
|
---|
| 158 | default:
|
---|
| 159 | break;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | free(configdata);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | /** Print information about component */
|
---|
[c7a7656] | 167 | static void arc_print_component(arc_component *c)
|
---|
| 168 | {
|
---|
| 169 | int i;
|
---|
| 170 |
|
---|
| 171 | printf("%s: ",ctypes[c->type]);
|
---|
| 172 | for (i=0;i < c->identifier_len;i++)
|
---|
[daea4bf] | 173 | printf("%c",c->identifier[i]);
|
---|
| 174 |
|
---|
| 175 | printf(" ");
|
---|
| 176 | arc_print_confdata(c);
|
---|
| 177 | printf("\n");
|
---|
[c7a7656] | 178 | }
|
---|
| 179 |
|
---|
[daea4bf] | 180 | /**
|
---|
| 181 | * Read from ARC bios configuration data and print it
|
---|
| 182 | */
|
---|
| 183 | static int cmd_arc_print_devices(cmd_arg_t *argv)
|
---|
[c7a7656] | 184 | {
|
---|
| 185 | arc_component *c,*next;
|
---|
| 186 |
|
---|
| 187 | c = arc_entry->getchild(NULL);
|
---|
| 188 | while (c) {
|
---|
| 189 | arc_print_component(c);
|
---|
| 190 | next = arc_entry->getchild(c);
|
---|
| 191 | while (!next) {
|
---|
| 192 | next = arc_entry->getpeer(c);
|
---|
| 193 | if (!next)
|
---|
| 194 | c = arc_entry->getparent(c);
|
---|
| 195 | if (!c)
|
---|
[daea4bf] | 196 | return 0;
|
---|
[c7a7656] | 197 | }
|
---|
| 198 | c = next;
|
---|
| 199 | }
|
---|
[daea4bf] | 200 | return 1;
|
---|
[c7a7656] | 201 | }
|
---|
[daea4bf] | 202 | static cmd_info_t devlist_info = {
|
---|
| 203 | .name = "arcdevlist",
|
---|
| 204 | .description = "Print arc device list",
|
---|
| 205 | .func = cmd_arc_print_devices,
|
---|
| 206 | .argc = 0
|
---|
| 207 | };
|
---|
[c7a7656] | 208 |
|
---|
[daea4bf] | 209 |
|
---|
| 210 | /** Read from arc bios memory map and print it
|
---|
| 211 | *
|
---|
| 212 | */
|
---|
| 213 | static int cmd_arc_print_memmap(cmd_arg_t *argv)
|
---|
[3156582] | 214 | {
|
---|
| 215 | arc_memdescriptor_t *desc;
|
---|
| 216 |
|
---|
| 217 | printf("Memory map:\n");
|
---|
| 218 |
|
---|
| 219 | desc = arc_entry->getmemorydescriptor(NULL);
|
---|
| 220 | while (desc) {
|
---|
[cf85e24c] | 221 | printf("%s: %d(%p) (size: %dKB)\n",basetypes[desc->type],
|
---|
[052da81] | 222 | desc->basepage * ARC_FRAME,
|
---|
[939dfd7] | 223 | desc->basepage * ARC_FRAME,
|
---|
| 224 | desc->basecount*ARC_FRAME/1024);
|
---|
[3156582] | 225 | desc = arc_entry->getmemorydescriptor(desc);
|
---|
| 226 | }
|
---|
[daea4bf] | 227 | return 1;
|
---|
[3156582] | 228 | }
|
---|
[daea4bf] | 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 | };
|
---|
[3156582] | 235 |
|
---|
| 236 | /** Print charactor to console */
|
---|
[973be64e] | 237 | static void arc_putchar(char ch)
|
---|
[3156582] | 238 | {
|
---|
[7f1c620] | 239 | uint32_t cnt;
|
---|
[22f7769] | 240 | ipl_t ipl;
|
---|
[3156582] | 241 |
|
---|
| 242 | /* TODO: Should be spinlock? */
|
---|
[22f7769] | 243 | ipl = interrupts_disable();
|
---|
[3156582] | 244 | arc_entry->write(1, &ch, 1, &cnt);
|
---|
[22f7769] | 245 | interrupts_restore(ipl);
|
---|
[3156582] | 246 |
|
---|
| 247 | }
|
---|
[ac0cb2a] | 248 |
|
---|
[052da81] | 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 |
|
---|
[973be64e] | 261 | /** Initialize ARC structure
|
---|
| 262 | *
|
---|
| 263 | * @return 0 - ARC OK, -1 - ARC does not exist
|
---|
| 264 | */
|
---|
| 265 | int arc_init(void)
|
---|
| 266 | {
|
---|
| 267 | if (sbp->signature != ARC_MAGIC) {
|
---|
| 268 | sbp = NULL;
|
---|
| 269 | return -1;
|
---|
| 270 | }
|
---|
| 271 | arc_entry = sbp->firmwarevector;
|
---|
| 272 |
|
---|
| 273 | arc_putchar('A');
|
---|
| 274 | arc_putchar('R');
|
---|
| 275 | arc_putchar('C');
|
---|
| 276 | arc_putchar('\n');
|
---|
[80d2bdb] | 277 |
|
---|
[052da81] | 278 | /* Add command for resetting the computer */
|
---|
| 279 | cmd_initialize(&reboot_info);
|
---|
| 280 | cmd_register(&reboot_info);
|
---|
[daea4bf] | 281 | cmd_initialize(&memmap_info);
|
---|
| 282 | cmd_register(&memmap_info);
|
---|
| 283 | cmd_initialize(&devlist_info);
|
---|
| 284 | cmd_register(&devlist_info);
|
---|
[052da81] | 285 |
|
---|
[80d2bdb] | 286 | return 0;
|
---|
[973be64e] | 287 | }
|
---|
| 288 |
|
---|
[6095342] | 289 | static bool kbd_polling_enabled;
|
---|
[973be64e] | 290 | static chardev_t console;
|
---|
| 291 |
|
---|
[ac0cb2a] | 292 | /** Try to get character, return character or -1 if not available */
|
---|
[973be64e] | 293 | static void arc_keyboard_poll(void)
|
---|
[ac0cb2a] | 294 | {
|
---|
| 295 | char ch;
|
---|
[7f1c620] | 296 | uint32_t count;
|
---|
[ac0cb2a] | 297 | long result;
|
---|
[973be64e] | 298 |
|
---|
| 299 | if (! kbd_polling_enabled)
|
---|
| 300 | return;
|
---|
[ac0cb2a] | 301 |
|
---|
| 302 | if (arc_entry->getreadstatus(0))
|
---|
[973be64e] | 303 | return;
|
---|
[ac0cb2a] | 304 | result = arc_entry->read(0, &ch, 1, &count);
|
---|
| 305 | if (result || count!=1) {
|
---|
[973be64e] | 306 | return;
|
---|
[ac0cb2a] | 307 | }
|
---|
| 308 | if (ch == '\r')
|
---|
[973be64e] | 309 | ch = '\n';
|
---|
[e8a9dc3] | 310 | if (ch == 0x7f)
|
---|
| 311 | ch = '\b';
|
---|
| 312 |
|
---|
[973be64e] | 313 | chardev_push_character(&console, ch);
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[fbe058f] | 316 | static char arc_read(chardev_t *dev)
|
---|
| 317 | {
|
---|
| 318 | char ch;
|
---|
[7f1c620] | 319 | uint32_t count;
|
---|
[fbe058f] | 320 | long result;
|
---|
| 321 |
|
---|
| 322 | result = arc_entry->read(0, &ch, 1, &count);
|
---|
| 323 | if (result || count!=1) {
|
---|
| 324 | printf("Error reading from ARC keyboard.\n");
|
---|
| 325 | cpu_halt();
|
---|
| 326 | }
|
---|
| 327 | if (ch == '\r')
|
---|
| 328 | return '\n';
|
---|
| 329 | if (ch == 0x7f)
|
---|
| 330 | return '\b';
|
---|
| 331 | return ch;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[973be64e] | 334 | static void arc_write(chardev_t *dev, const char ch)
|
---|
| 335 | {
|
---|
| 336 | arc_putchar(ch);
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | static void arc_enable(chardev_t *dev)
|
---|
| 340 | {
|
---|
[6095342] | 341 | kbd_polling_enabled = true;
|
---|
[973be64e] | 342 | }
|
---|
| 343 |
|
---|
| 344 | static void arc_disable(chardev_t *dev)
|
---|
| 345 | {
|
---|
[6095342] | 346 | kbd_polling_enabled = false;
|
---|
[973be64e] | 347 | }
|
---|
| 348 |
|
---|
| 349 | static chardev_operations_t arc_ops = {
|
---|
| 350 | .resume = arc_enable,
|
---|
| 351 | .suspend = arc_disable,
|
---|
[fbe058f] | 352 | .write = arc_write,
|
---|
| 353 | .read = arc_read
|
---|
[973be64e] | 354 | };
|
---|
| 355 |
|
---|
[af9a7c5] | 356 | void arc_console(void)
|
---|
[973be64e] | 357 | {
|
---|
[6095342] | 358 | kbd_polling_enabled = true;
|
---|
[973be64e] | 359 |
|
---|
| 360 | chardev_initialize("arc_console", &console, &arc_ops);
|
---|
[7688b5d] | 361 | timer_fnc = &arc_keyboard_poll;
|
---|
[af9a7c5] | 362 | stdin = &console;
|
---|
| 363 | stdout = &console;
|
---|
[ac0cb2a] | 364 | }
|
---|
[939dfd7] | 365 |
|
---|
| 366 | /* Initialize frame zones from ARC firmware.
|
---|
| 367 | * In the future we may use even the FirmwareTemporary regions,
|
---|
| 368 | * currently we use the FreeMemory (what about the LoadedProgram?)
|
---|
| 369 | */
|
---|
| 370 | void arc_frame_init(void)
|
---|
| 371 | {
|
---|
| 372 | arc_memdescriptor_t *desc;
|
---|
| 373 | int total = 0;
|
---|
[7f1c620] | 374 | uintptr_t base;
|
---|
[c0b7f00] | 375 | size_t basesize;
|
---|
[939dfd7] | 376 |
|
---|
| 377 | desc = arc_entry->getmemorydescriptor(NULL);
|
---|
| 378 | while (desc) {
|
---|
| 379 | if (desc->type == FreeMemory ||
|
---|
| 380 | desc->type == FreeContiguous) {
|
---|
[c0b7f00] | 381 | base = desc->basepage*ARC_FRAME;
|
---|
| 382 | basesize = desc->basecount*ARC_FRAME;
|
---|
| 383 |
|
---|
| 384 | if (base % FRAME_SIZE ) {
|
---|
| 385 | basesize -= FRAME_SIZE - (base % FRAME_SIZE);
|
---|
| 386 | base = ALIGN_UP(base, FRAME_SIZE);
|
---|
| 387 | }
|
---|
| 388 | basesize = ALIGN_DOWN(basesize, FRAME_SIZE);
|
---|
| 389 |
|
---|
| 390 | total += basesize;
|
---|
[085d973] | 391 |
|
---|
[052da81] | 392 | zone_create(ADDR2PFN(base), SIZE2FRAMES(basesize),
|
---|
| 393 | ADDR2PFN(base), 0);
|
---|
[939dfd7] | 394 | }
|
---|
| 395 | desc = arc_entry->getmemorydescriptor(desc);
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | config.memory_size = total;
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[06e1e95] | 401 | /** @}
|
---|
[b45c443] | 402 | */
|
---|