2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
21
#include <grub/cpu/xnu.h>
22
#include <grub/efi/api.h>
23
#include <grub/efi/efi.h>
24
#include <grub/efi/uga_draw.h>
26
#include <grub/misc.h>
28
/* Setup video for xnu. Big parts are copied from linux.c. */
30
static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
32
#define RGB_MASK 0xffffff
33
#define RGB_MAGIC 0x121314
36
#define FBTEST_STEP (0x10000 >> 2)
37
#define FBTEST_COUNT 8
40
find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)
42
grub_uint32_t *base = (grub_uint32_t *) (grub_target_addr_t) *fb_base;
45
for (i = 0; i < FBTEST_COUNT; i++, base += FBTEST_STEP)
47
if ((*base & RGB_MASK) == RGB_MAGIC)
51
for (j = LINE_MIN; j <= LINE_MAX; j++)
53
if ((base[j] & RGB_MASK) == RGB_MAGIC)
55
*fb_base = (grub_uint32_t) (grub_target_addr_t) base;
70
find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
74
auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
77
int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
80
grub_pci_address_t addr;
82
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
83
if (grub_pci_read (addr) >> 24 == 0x3)
87
grub_printf ("Display controller: %d:%d.%d\nDevice id: %x\n",
88
grub_pci_get_bus (dev), grub_pci_get_device (dev),
89
grub_pci_get_function (dev), pciid);
91
for (i = 0; i < 6; i++, addr += 4)
93
grub_uint32_t old_bar1, old_bar2, type;
96
old_bar1 = grub_pci_read (addr);
97
if ((! old_bar1) || (old_bar1 & GRUB_PCI_ADDR_SPACE_IO))
100
type = old_bar1 & GRUB_PCI_ADDR_MEM_TYPE_MASK;
101
if (type == GRUB_PCI_ADDR_MEM_TYPE_64)
106
old_bar2 = grub_pci_read (addr + 4);
113
base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK);
115
grub_printf ("%s(%d): 0x%llx\n",
116
((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ?
118
(unsigned long long) base64);
120
if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! found))
123
if (find_line_len (fb_base, line_len))
127
if (type == GRUB_PCI_ADDR_MEM_TYPE_64)
138
grub_pci_iterate (find_card);
143
grub_xnu_set_video (struct grub_xnu_boot_params *params)
145
grub_efi_uga_draw_protocol_t *c;
146
grub_uint32_t width, height, depth, rate, pixel, fb_base, line_len;
149
c = grub_efi_locate_protocol (&uga_draw_guid, 0);
151
return grub_error (GRUB_ERR_IO, "couldn't find UGADraw");
153
if (efi_call_5 (c->get_mode, c, &width, &height, &depth, &rate))
154
return grub_error (GRUB_ERR_IO, "couldn't retrieve video mode");
156
grub_printf ("Video mode: %ux%u-%u@%u\n", width, height, depth, rate);
158
grub_efi_set_text_mode (0);
160
efi_call_10 (c->blt, c, (struct grub_efi_uga_pixel *) &pixel,
161
GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0);
162
ret = find_framebuf (&fb_base, &line_len);
163
grub_efi_set_text_mode (1);
166
return grub_error (GRUB_ERR_IO, "can\'t find frame buffer address");
168
grub_printf ("Frame buffer base: 0x%x\n", fb_base);
169
grub_printf ("Video line length: %d\n", line_len);
171
params->lfb_width = width;
172
params->lfb_height = height;
173
params->lfb_depth = depth;
174
params->lfb_line_len = line_len;
175
params->lfb_mode = GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
176
params->lfb_base = fb_base;
177
return GRUB_ERR_NONE;