~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to video/efi_uga.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) 2005,2006,2007,2008,2009  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
 
#define grub_video_render_target grub_video_fbrender_target
20
 
 
21
 
#include <grub/err.h>
22
 
#include <grub/types.h>
23
 
#include <grub/dl.h>
24
 
#include <grub/misc.h>
25
 
#include <grub/mm.h>
26
 
#include <grub/video.h>
27
 
#include <grub/video_fb.h>
28
 
#include <grub/efi/api.h>
29
 
#include <grub/efi/efi.h>
30
 
#include <grub/efi/uga_draw.h>
31
 
#include <grub/pci.h>
32
 
 
33
 
static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
34
 
static struct grub_efi_uga_draw_protocol *uga;
35
 
static grub_uint32_t uga_fb;
36
 
static grub_uint32_t uga_pitch;
37
 
 
38
 
static struct
39
 
{
40
 
  struct grub_video_mode_info mode_info;
41
 
  struct grub_video_render_target *render_target;
42
 
  grub_uint8_t *ptr;
43
 
} framebuffer;
44
 
 
45
 
#define RGB_MASK        0xffffff
46
 
#define RGB_MAGIC       0x121314
47
 
#define LINE_MIN        800
48
 
#define LINE_MAX        4096
49
 
#define FBTEST_STEP     (0x10000 >> 2)
50
 
#define FBTEST_COUNT    8
51
 
 
52
 
static int
53
 
find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)
54
 
{
55
 
  grub_uint32_t *base = (grub_uint32_t *) (grub_target_addr_t) *fb_base;
56
 
  int i;
57
 
 
58
 
  for (i = 0; i < FBTEST_COUNT; i++, base += FBTEST_STEP)
59
 
    {
60
 
      if ((*base & RGB_MASK) == RGB_MAGIC)
61
 
        {
62
 
          int j;
63
 
 
64
 
          for (j = LINE_MIN; j <= LINE_MAX; j++)
65
 
            {
66
 
              if ((base[j] & RGB_MASK) == RGB_MAGIC)
67
 
                {
68
 
                  *fb_base = (grub_uint32_t) (grub_target_addr_t) base;
69
 
                  *line_len = j << 2;
70
 
 
71
 
                  return 1;
72
 
                }
73
 
            }
74
 
 
75
 
          break;
76
 
        }
77
 
    }
78
 
 
79
 
  return 0;
80
 
}
81
 
 
82
 
static int
83
 
find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
84
 
{
85
 
  int found = 0;
86
 
 
87
 
  auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
88
 
                                       grub_pci_id_t pciid);
89
 
 
90
 
  int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
91
 
                                  grub_pci_id_t pciid)
92
 
    {
93
 
      grub_pci_address_t addr;
94
 
 
95
 
      addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
96
 
      if (grub_pci_read (addr) >> 24 == 0x3)
97
 
        {
98
 
          int i;
99
 
 
100
 
          grub_dprintf ("fb", "Display controller: %d:%d.%d\nDevice id: %x\n",
101
 
                        grub_pci_get_bus (dev), grub_pci_get_device (dev),
102
 
                        grub_pci_get_function (dev), pciid);
103
 
          addr += 8;
104
 
          for (i = 0; i < 6; i++, addr += 4)
105
 
            {
106
 
              grub_uint32_t old_bar1, old_bar2, type;
107
 
              grub_uint64_t base64;
108
 
 
109
 
              old_bar1 = grub_pci_read (addr);
110
 
              if ((! old_bar1) || (old_bar1 & GRUB_PCI_ADDR_SPACE_IO))
111
 
                continue;
112
 
 
113
 
              type = old_bar1 & GRUB_PCI_ADDR_MEM_TYPE_MASK;
114
 
              if (type == GRUB_PCI_ADDR_MEM_TYPE_64)
115
 
                {
116
 
                  if (i == 5)
117
 
                    break;
118
 
 
119
 
                  old_bar2 = grub_pci_read (addr + 4);
120
 
                }
121
 
              else
122
 
                old_bar2 = 0;
123
 
 
124
 
              base64 = old_bar2;
125
 
              base64 <<= 32;
126
 
              base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK);
127
 
 
128
 
              grub_dprintf ("fb", "%s(%d): 0x%llx\n",
129
 
                            ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ?
130
 
                            "VMEM" : "MMIO"), i,
131
 
                           (unsigned long long) base64);
132
 
 
133
 
              if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! found))
134
 
                {
135
 
                  *fb_base = base64;
136
 
                  if (find_line_len (fb_base, line_len))
137
 
                    found++;
138
 
                }
139
 
 
140
 
              if (type == GRUB_PCI_ADDR_MEM_TYPE_64)
141
 
                {
142
 
                  i++;
143
 
                  addr += 4;
144
 
                }
145
 
            }
146
 
        }
147
 
 
148
 
      return found;
149
 
    }
150
 
 
151
 
  grub_pci_iterate (find_card);
152
 
  return found;
153
 
}
154
 
 
155
 
static int
156
 
check_protocol (void)
157
 
{
158
 
  grub_efi_uga_draw_protocol_t *c;
159
 
 
160
 
  c = grub_efi_locate_protocol (&uga_draw_guid, 0);
161
 
  if (c)
162
 
    {
163
 
      grub_uint32_t width, height, depth, rate, pixel;
164
 
      int ret;
165
 
 
166
 
      if (efi_call_5 (c->get_mode, c, &width, &height, &depth, &rate))
167
 
        return 0;
168
 
 
169
 
      grub_efi_set_text_mode (0);
170
 
      pixel = RGB_MAGIC;
171
 
      efi_call_10 (c->blt, c, (struct grub_efi_uga_pixel *) &pixel,
172
 
                   GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0);
173
 
      ret = find_framebuf (&uga_fb, &uga_pitch);
174
 
      grub_efi_set_text_mode (1);
175
 
 
176
 
      if (ret)
177
 
        {
178
 
          uga = c;
179
 
          return 1;
180
 
        }
181
 
    }
182
 
 
183
 
  return 0;
184
 
}
185
 
 
186
 
static grub_err_t
187
 
grub_video_uga_init (void)
188
 
{
189
 
  grub_memset (&framebuffer, 0, sizeof(framebuffer));
190
 
  return grub_video_fb_init ();
191
 
}
192
 
 
193
 
static grub_err_t
194
 
grub_video_uga_fini (void)
195
 
{
196
 
  return grub_video_fb_fini ();
197
 
}
198
 
 
199
 
static grub_err_t
200
 
grub_video_uga_setup (unsigned int width, unsigned int height,
201
 
                      unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
202
 
{
203
 
  unsigned int depth;
204
 
  int found = 0;
205
 
 
206
 
  depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
207
 
    >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
208
 
 
209
 
  {
210
 
    grub_uint32_t w;
211
 
    grub_uint32_t h;
212
 
    grub_uint32_t d;
213
 
    grub_uint32_t r;
214
 
 
215
 
    if ((! efi_call_5 (uga->get_mode, uga, &w, &h, &d, &r)) &&
216
 
        ((! width) || (width == w)) &&
217
 
        ((! height) || (height == h)) &&
218
 
        ((! depth) || (depth == d)))
219
 
      {
220
 
        framebuffer.mode_info.width = w;
221
 
        framebuffer.mode_info.height = h;
222
 
        framebuffer.mode_info.pitch = uga_pitch;
223
 
        framebuffer.ptr = (grub_uint8_t *) (grub_target_addr_t) uga_fb;
224
 
 
225
 
        found = 1;
226
 
      }
227
 
  }
228
 
 
229
 
  if (found)
230
 
    {
231
 
      grub_err_t err;
232
 
 
233
 
      framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
234
 
      framebuffer.mode_info.bpp = 32;
235
 
      framebuffer.mode_info.bytes_per_pixel = 4;
236
 
      framebuffer.mode_info.number_of_colors = 256; /* TODO: fix me.  */
237
 
      framebuffer.mode_info.red_mask_size = 8;
238
 
      framebuffer.mode_info.red_field_pos = 16;
239
 
      framebuffer.mode_info.green_mask_size = 8;
240
 
      framebuffer.mode_info.green_field_pos = 8;
241
 
      framebuffer.mode_info.blue_mask_size = 8;
242
 
      framebuffer.mode_info.blue_field_pos = 0;
243
 
      framebuffer.mode_info.reserved_mask_size = 8;
244
 
      framebuffer.mode_info.reserved_field_pos = 24;
245
 
 
246
 
      framebuffer.mode_info.blit_format =
247
 
        grub_video_get_blit_format (&framebuffer.mode_info);
248
 
 
249
 
      err = grub_video_fb_create_render_target_from_pointer
250
 
        (&framebuffer.render_target,
251
 
         &framebuffer.mode_info,
252
 
         framebuffer.ptr);
253
 
 
254
 
      if (err)
255
 
        return err;
256
 
 
257
 
      err = grub_video_fb_set_active_render_target
258
 
        (framebuffer.render_target);
259
 
 
260
 
      if (err)
261
 
        return err;
262
 
 
263
 
      err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
264
 
                                       grub_video_fbstd_colors);
265
 
 
266
 
      return err;
267
 
    }
268
 
 
269
 
  return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching mode found");
270
 
}
271
 
 
272
 
static grub_err_t
273
 
grub_video_uga_swap_buffers (void)
274
 
{
275
 
  /* TODO: Implement buffer swapping.  */
276
 
  return GRUB_ERR_NONE;
277
 
}
278
 
 
279
 
static grub_err_t
280
 
grub_video_uga_set_active_render_target (struct grub_video_render_target *target)
281
 
{
282
 
  if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
283
 
    target = framebuffer.render_target;
284
 
 
285
 
  return grub_video_fb_set_active_render_target (target);
286
 
}
287
 
 
288
 
static grub_err_t
289
 
grub_video_uga_get_info_and_fini (struct grub_video_mode_info *mode_info,
290
 
                                  void **framebuf)
291
 
{
292
 
  grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
293
 
  *framebuf = (char *) framebuffer.ptr;
294
 
 
295
 
  grub_video_fb_fini ();
296
 
 
297
 
  return GRUB_ERR_NONE;
298
 
}
299
 
 
300
 
static struct grub_video_adapter grub_video_uga_adapter =
301
 
  {
302
 
    .name = "EFI UGA driver",
303
 
    .id = GRUB_VIDEO_DRIVER_EFI_UGA,
304
 
 
305
 
    .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE_DIRTY,
306
 
 
307
 
    .init = grub_video_uga_init,
308
 
    .fini = grub_video_uga_fini,
309
 
    .setup = grub_video_uga_setup,
310
 
    .get_info = grub_video_fb_get_info,
311
 
    .get_info_and_fini = grub_video_uga_get_info_and_fini,
312
 
    .set_palette = grub_video_fb_set_palette,
313
 
    .get_palette = grub_video_fb_get_palette,
314
 
    .set_viewport = grub_video_fb_set_viewport,
315
 
    .get_viewport = grub_video_fb_get_viewport,
316
 
    .map_color = grub_video_fb_map_color,
317
 
    .map_rgb = grub_video_fb_map_rgb,
318
 
    .map_rgba = grub_video_fb_map_rgba,
319
 
    .unmap_color = grub_video_fb_unmap_color,
320
 
    .fill_rect = grub_video_fb_fill_rect,
321
 
    .blit_bitmap = grub_video_fb_blit_bitmap,
322
 
    .blit_render_target = grub_video_fb_blit_render_target,
323
 
    .scroll = grub_video_fb_scroll,
324
 
    .swap_buffers = grub_video_uga_swap_buffers,
325
 
    .create_render_target = grub_video_fb_create_render_target,
326
 
    .delete_render_target = grub_video_fb_delete_render_target,
327
 
    .set_active_render_target = grub_video_uga_set_active_render_target,
328
 
    .get_active_render_target = grub_video_fb_get_active_render_target,
329
 
  };
330
 
 
331
 
GRUB_MOD_INIT(efi_uga)
332
 
{
333
 
  if (check_protocol ())
334
 
    grub_video_register (&grub_video_uga_adapter);
335
 
}
336
 
 
337
 
GRUB_MOD_FINI(efi_uga)
338
 
{
339
 
  if (uga)
340
 
    grub_video_unregister (&grub_video_uga_adapter);
341
 
}