2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2009,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/kernel.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/env.h>
2N/A#include <grub/time.h>
2N/A#include <grub/types.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/time.h>
2N/A#include <grub/machine/kernel.h>
2N/A#include <grub/machine/memory.h>
2N/A#include <grub/arc/console.h>
2N/A#include <grub/cpu/memory.h>
2N/A#include <grub/cpu/time.h>
2N/A#include <grub/memory.h>
2N/A#include <grub/term.h>
2N/A#include <grub/arc/arc.h>
2N/A#include <grub/offsets.h>
2N/A#include <grub/i18n.h>
2N/A
2N/Aconst char *type_names[] = {
2N/A#ifdef GRUB_CPU_WORDS_BIGENDIAN
2N/A NULL,
2N/A#endif
2N/A NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2N/A "eisa", "tc", "scsi", "dti", "multi", "disk", "tape", "cdrom", "worm",
2N/A "serial", "net", "video", "par", "point", "key", "audio", "other",
2N/A "rdisk", "fdisk", "tape", "modem", "monitor", "print", "pointer",
2N/A "keyboard", "term", "other", "line", "network", NULL
2N/A};
2N/A
2N/Astatic int
2N/Aiterate_rec (const char *prefix, const struct grub_arc_component *parent,
2N/A int (*hook) (const char *name,
2N/A const struct grub_arc_component *comp),
2N/A int alt_names)
2N/A{
2N/A const struct grub_arc_component *comp;
2N/A FOR_ARC_CHILDREN(comp, parent)
2N/A {
2N/A char *name;
2N/A const char *cname = NULL;
2N/A if (comp->type < ARRAY_SIZE (type_names))
2N/A cname = type_names[comp->type];
2N/A if (!cname)
2N/A cname = "unknown";
2N/A if (alt_names)
2N/A name = grub_xasprintf ("%s/%s%lu", prefix, cname, comp->key);
2N/A else
2N/A name = grub_xasprintf ("%s%s(%lu)", prefix, cname, comp->key);
2N/A if (!name)
2N/A return 1;
2N/A if (hook (name, comp))
2N/A {
2N/A grub_free (name);
2N/A return 1;
2N/A }
2N/A if (iterate_rec ((parent ? name : prefix), comp, hook, alt_names))
2N/A {
2N/A grub_free (name);
2N/A return 1;
2N/A }
2N/A grub_free (name);
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Agrub_arc_iterate_devs (int (*hook) (const char *name,
2N/A const struct grub_arc_component *comp),
2N/A int alt_names)
2N/A{
2N/A return iterate_rec ((alt_names ? "arc" : ""), NULL, hook, alt_names);
2N/A}
2N/A
2N/Agrub_err_t
2N/Agrub_machine_mmap_iterate (grub_memory_hook_t hook)
2N/A{
2N/A struct grub_arc_memory_descriptor *cur = NULL;
2N/A while (1)
2N/A {
2N/A grub_memory_type_t type;
2N/A cur = GRUB_ARC_FIRMWARE_VECTOR->getmemorydescriptor (cur);
2N/A if (!cur)
2N/A return GRUB_ERR_NONE;
2N/A switch (cur->type)
2N/A {
2N/A case GRUB_ARC_MEMORY_EXCEPTION_BLOCK:
2N/A case GRUB_ARC_MEMORY_SYSTEM_PARAMETER_BLOCK:
2N/A case GRUB_ARC_MEMORY_FW_PERMANENT:
2N/A default:
2N/A type = GRUB_MEMORY_RESERVED;
2N/A break;
2N/A
2N/A case GRUB_ARC_MEMORY_FW_TEMPORARY:
2N/A case GRUB_ARC_MEMORY_FREE:
2N/A case GRUB_ARC_MEMORY_LOADED:
2N/A case GRUB_ARC_MEMORY_FREE_CONTIGUOUS:
2N/A type = GRUB_MEMORY_AVAILABLE;
2N/A break;
2N/A case GRUB_ARC_MEMORY_BADRAM:
2N/A type = GRUB_MEMORY_BADRAM;
2N/A break;
2N/A }
2N/A if (hook (((grub_uint64_t) cur->start_page) << 12,
2N/A ((grub_uint64_t) cur->num_pages) << 12, type))
2N/A return GRUB_ERR_NONE;
2N/A }
2N/A}
2N/A
2N/Aextern grub_uint32_t grub_total_modules_size;
2N/Agrub_addr_t grub_modbase;
2N/A
2N/Avoid
2N/Agrub_machine_init (void)
2N/A{
2N/A struct grub_arc_memory_descriptor *cur = NULL;
2N/A
2N/A grub_modbase = GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size;
2N/A grub_console_init_early ();
2N/A
2N/A /* FIXME: measure this. */
2N/A grub_arch_cpuclock = 64000000;
2N/A grub_install_get_time_ms (grub_rtc_get_time_ms);
2N/A
2N/A while (1)
2N/A {
2N/A grub_uint64_t start, end;
2N/A cur = GRUB_ARC_FIRMWARE_VECTOR->getmemorydescriptor (cur);
2N/A if (!cur)
2N/A break;
2N/A if (cur->type != GRUB_ARC_MEMORY_FREE
2N/A && cur->type != GRUB_ARC_MEMORY_LOADED
2N/A && cur->type != GRUB_ARC_MEMORY_FREE_CONTIGUOUS)
2N/A continue;
2N/A start = ((grub_uint64_t) cur->start_page) << 12;
2N/A end = ((grub_uint64_t) cur->num_pages) << 12;
2N/A end += start;
2N/A if ((grub_uint64_t) end > ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR
2N/A - grub_total_modules_size) & 0x1fffffff))
2N/A end = ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size)
2N/A & 0x1fffffff);
2N/A if (end > start)
2N/A grub_mm_init_region ((void *) (grub_addr_t) (start | 0x80000000),
2N/A end - start);
2N/A }
2N/A
2N/A grub_console_init_lately ();
2N/A
2N/A grub_arcdisk_init ();
2N/A}
2N/A
2N/Avoid
2N/Agrub_machine_fini (void)
2N/A{
2N/A}
2N/A
2N/Avoid
2N/Agrub_halt (void)
2N/A{
2N/A GRUB_ARC_FIRMWARE_VECTOR->powerdown ();
2N/A
2N/A grub_millisleep (1500);
2N/A
2N/A grub_puts_ (N_("Shutdown failed"));
2N/A grub_refresh ();
2N/A while (1);
2N/A}
2N/A
2N/Avoid
2N/Agrub_exit (void)
2N/A{
2N/A GRUB_ARC_FIRMWARE_VECTOR->exit ();
2N/A
2N/A grub_millisleep (1500);
2N/A
2N/A grub_puts_ (N_("Exit failed"));
2N/A grub_refresh ();
2N/A while (1);
2N/A}
2N/A