~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/kern/mips/yeeloong/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <grub/kernel.h>
 
20
#include <grub/misc.h>
 
21
#include <grub/env.h>
 
22
#include <grub/time.h>
 
23
#include <grub/types.h>
 
24
#include <grub/misc.h>
 
25
#include <grub/mm.h>
 
26
#include <grub/time.h>
 
27
#include <grub/machine/kernel.h>
 
28
#include <grub/machine/memory.h>
 
29
#include <grub/memory.h>
 
30
#include <grub/mips/loongson.h>
 
31
#include <grub/cs5536.h>
 
32
#include <grub/term.h>
 
33
#include <grub/machine/ec.h>
 
34
 
 
35
extern void grub_video_sm712_init (void);
 
36
extern void grub_video_init (void);
 
37
extern void grub_bitmap_init (void);
 
38
extern void grub_font_init (void);
 
39
extern void grub_gfxterm_init (void);
 
40
extern void grub_at_keyboard_init (void);
 
41
extern void grub_serial_init (void);
 
42
extern void grub_terminfo_init (void);
 
43
extern void grub_keylayouts_init (void);
 
44
 
 
45
/* FIXME: use interrupt to count high.  */
 
46
grub_uint64_t
 
47
grub_get_rtc (void)
 
48
{
 
49
  static grub_uint32_t high = 0;
 
50
  static grub_uint32_t last = 0;
 
51
  grub_uint32_t low;
 
52
 
 
53
  asm volatile ("mfc0 %0, " GRUB_CPU_LOONGSON_COP0_TIMER_COUNT : "=r" (low));
 
54
  if (low < last)
 
55
    high++;
 
56
  last = low;
 
57
 
 
58
  return (((grub_uint64_t) high) << 32) | low;
 
59
}
 
60
 
 
61
grub_err_t
 
62
grub_machine_mmap_iterate (grub_memory_hook_t hook)
 
63
{
 
64
  hook (GRUB_ARCH_LOWMEMPSTART, grub_arch_memsize << 20,
 
65
        GRUB_MEMORY_AVAILABLE);
 
66
  hook (GRUB_ARCH_HIGHMEMPSTART, grub_arch_highmemsize << 20,
 
67
        GRUB_MEMORY_AVAILABLE);
 
68
  return GRUB_ERR_NONE;
 
69
}
 
70
 
 
71
static void
 
72
init_pci (void)
 
73
{
 
74
  auto int NESTED_FUNC_ATTR set_card (grub_pci_device_t dev, grub_pci_id_t pciid);
 
75
  int NESTED_FUNC_ATTR set_card (grub_pci_device_t dev, grub_pci_id_t pciid)
 
76
  {
 
77
    grub_pci_address_t addr;
 
78
    /* FIXME: autoscan for BARs and devices.  */
 
79
    switch (pciid)
 
80
      {
 
81
      case GRUB_YEELOONG_OHCI_PCIID:
 
82
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
 
83
        grub_pci_write (addr, 0x5025000);
 
84
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
 
85
        grub_pci_write_word (addr, GRUB_PCI_COMMAND_SERR_ENABLE
 
86
                             | GRUB_PCI_COMMAND_PARITY_ERROR
 
87
                             | GRUB_PCI_COMMAND_BUS_MASTER
 
88
                             | GRUB_PCI_COMMAND_MEM_ENABLED);
 
89
 
 
90
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_STATUS);
 
91
        grub_pci_write_word (addr, 0x0200 | GRUB_PCI_STATUS_CAPABILITIES);
 
92
        break;
 
93
      case GRUB_YEELOONG_EHCI_PCIID:
 
94
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
 
95
        grub_pci_write (addr, 0x5026000);
 
96
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
 
97
        grub_pci_write_word (addr, GRUB_PCI_COMMAND_SERR_ENABLE
 
98
                             | GRUB_PCI_COMMAND_PARITY_ERROR
 
99
                             | GRUB_PCI_COMMAND_BUS_MASTER
 
100
                             | GRUB_PCI_COMMAND_MEM_ENABLED);
 
101
 
 
102
        addr = grub_pci_make_address (dev, GRUB_PCI_REG_STATUS);
 
103
        grub_pci_write_word (addr, (1 << GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT)
 
104
                             | GRUB_PCI_STATUS_CAPABILITIES);
 
105
        break;
 
106
      }
 
107
    return 0;
 
108
  }
 
109
 
 
110
  *((volatile grub_uint32_t *) GRUB_CPU_LOONGSON_PCI_HIT1_SEL_LO) = 0x8000000c;
 
111
  *((volatile grub_uint32_t *) GRUB_CPU_LOONGSON_PCI_HIT1_SEL_HI) = 0xffffffff;
 
112
 
 
113
  /* Setup PCI controller.  */
 
114
  *((volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONTROLLER_HEADER
 
115
                                + GRUB_PCI_REG_COMMAND))
 
116
    = GRUB_PCI_COMMAND_PARITY_ERROR | GRUB_PCI_COMMAND_BUS_MASTER
 
117
    | GRUB_PCI_COMMAND_MEM_ENABLED;
 
118
  *((volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONTROLLER_HEADER
 
119
                                + GRUB_PCI_REG_STATUS))
 
120
    = (1 << GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT)
 
121
    | GRUB_PCI_STATUS_FAST_B2B_CAPABLE | GRUB_PCI_STATUS_66MHZ_CAPABLE
 
122
    | GRUB_PCI_STATUS_CAPABILITIES;
 
123
 
 
124
  *((volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONTROLLER_HEADER
 
125
                                + GRUB_PCI_REG_CACHELINE)) = 0xff;
 
126
  *((volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONTROLLER_HEADER 
 
127
                                + GRUB_PCI_REG_ADDRESS_REG0))
 
128
    = 0x80000000 | GRUB_PCI_ADDR_MEM_TYPE_64 | GRUB_PCI_ADDR_MEM_PREFETCH;
 
129
  *((volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONTROLLER_HEADER 
 
130
                                + GRUB_PCI_REG_ADDRESS_REG1)) = 0;
 
131
 
 
132
  grub_pci_iterate (set_card);
 
133
}
 
134
 
 
135
void
 
136
grub_machine_init (void)
 
137
{
 
138
  grub_addr_t modend;
 
139
 
 
140
  /* FIXME: measure this.  */
 
141
  if (grub_arch_busclock == 0)
 
142
    {
 
143
      grub_arch_busclock = 66000000;
 
144
      grub_arch_cpuclock = 797000000;
 
145
    }
 
146
 
 
147
  grub_install_get_time_ms (grub_rtc_get_time_ms);
 
148
 
 
149
  if (grub_arch_memsize == 0)
 
150
    {
 
151
      grub_port_t smbbase;
 
152
      grub_err_t err;
 
153
      grub_pci_device_t dev;
 
154
      struct grub_smbus_spd spd;
 
155
      unsigned totalmem;
 
156
      int i;
 
157
 
 
158
      if (!grub_cs5536_find (&dev))
 
159
        grub_fatal ("No CS5536 found\n");
 
160
 
 
161
      err = grub_cs5536_init_smbus (dev, 0x7ff, &smbbase);
 
162
      if (err)
 
163
        grub_fatal ("Couldn't init SMBus: %s\n", grub_errmsg);
 
164
 
 
165
      /* Yeeloong has only one memory slot.  */
 
166
      err = grub_cs5536_read_spd (smbbase, GRUB_SMB_RAM_START_ADDR, &spd);
 
167
      if (err)
 
168
        grub_fatal ("Couldn't read SPD: %s\n", grub_errmsg);
 
169
      for (i = 5; i < 13; i++)
 
170
        if (spd.ddr2.rank_capacity & (1 << (i & 7)))
 
171
          break;
 
172
      /* Something is wrong.  */
 
173
      if (i == 13)
 
174
        totalmem = 256;
 
175
      else
 
176
        totalmem = ((spd.ddr2.num_of_ranks
 
177
                     & GRUB_SMBUS_SPD_MEMORY_NUM_OF_RANKS_MASK) + 1) << (i + 2);
 
178
      
 
179
      if (totalmem >= 256)
 
180
        {
 
181
          grub_arch_memsize = 256;
 
182
          grub_arch_highmemsize = totalmem - 256;
 
183
        }
 
184
      else
 
185
        {
 
186
          grub_arch_memsize = (totalmem >> 20);
 
187
          grub_arch_highmemsize = 0;
 
188
        }
 
189
 
 
190
      grub_cs5536_init_geode (dev);
 
191
 
 
192
      init_pci ();
 
193
    }
 
194
 
 
195
  modend = grub_modules_get_end ();
 
196
  grub_mm_init_region ((void *) modend, (grub_arch_memsize << 20)
 
197
                       - (modend - GRUB_ARCH_LOWMEMVSTART));
 
198
  /* FIXME: use upper memory as well.  */
 
199
 
 
200
  /* Initialize output terminal (can't be done earlier, as gfxterm
 
201
     relies on a working heap.  */
 
202
  grub_video_init ();
 
203
  grub_video_sm712_init ();
 
204
  grub_bitmap_init ();
 
205
  grub_font_init ();
 
206
  grub_gfxterm_init ();
 
207
 
 
208
  grub_keylayouts_init ();
 
209
  grub_at_keyboard_init ();
 
210
 
 
211
  grub_terminfo_init ();
 
212
  grub_serial_init ();
 
213
}
 
214
 
 
215
void
 
216
grub_machine_fini (void)
 
217
{
 
218
}
 
219
 
 
220
void
 
221
grub_halt (void)
 
222
{
 
223
  grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG)
 
224
             & ~GRUB_CPU_LOONGSON_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG);
 
225
 
 
226
  grub_printf ("Shutdown failed\n");
 
227
  grub_refresh ();
 
228
  while (1);
 
229
}
 
230
 
 
231
void
 
232
grub_exit (void)
 
233
{
 
234
  grub_halt ();
 
235
}
 
236
 
 
237
void
 
238
grub_reboot (void)
 
239
{
 
240
  grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT);
 
241
 
 
242
  grub_printf ("Reboot failed\n");
 
243
  grub_refresh ();
 
244
  while (1);
 
245
}
 
246