]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/boot/amd64/efi/framebuffer.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / boot / amd64 / efi / framebuffer.c
1 /*-
2  * Copyright (c) 2013 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Benno Rice under sponsorship from
6  * the FreeBSD Foundation.
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <stand.h>
33
34 #include <efi.h>
35 #include <efilib.h>
36 #include <machine/metadata.h>
37
38 static EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
39
40 int
41 efi_find_framebuffer(struct efi_fb *efifb)
42 {
43         EFI_GRAPHICS_OUTPUT                     *gop;
44         EFI_STATUS                              status;
45         EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE       *mode;
46         EFI_GRAPHICS_OUTPUT_MODE_INFORMATION    *info;
47
48         status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop);
49         if (EFI_ERROR(status))
50                 return (1);
51
52         mode = gop->Mode;
53         info = gop->Mode->Info;
54
55         efifb->fb_addr = mode->FrameBufferBase;
56         efifb->fb_size = mode->FrameBufferSize;
57         efifb->fb_height = info->VerticalResolution;
58         efifb->fb_width = info->HorizontalResolution;
59         efifb->fb_stride = info->PixelsPerScanLine;
60
61         switch (info->PixelFormat) {
62         case PixelRedGreenBlueReserved8BitPerColor:
63                 efifb->fb_mask_red = 0x000000ff;
64                 efifb->fb_mask_green = 0x0000ff00;
65                 efifb->fb_mask_blue = 0x00ff0000;
66                 efifb->fb_mask_reserved = 0xff000000;
67                 break;
68         case PixelBlueGreenRedReserved8BitPerColor:
69                 efifb->fb_mask_red = 0x00ff0000;
70                 efifb->fb_mask_green = 0x0000ff00;
71                 efifb->fb_mask_blue = 0x000000ff;
72                 efifb->fb_mask_reserved = 0xff000000;
73                 break;
74         case PixelBitMask:
75                 efifb->fb_mask_red = info->PixelInformation.RedMask;
76                 efifb->fb_mask_green = info->PixelInformation.GreenMask;
77                 efifb->fb_mask_blue = info->PixelInformation.BlueMask;
78                 efifb->fb_mask_reserved =
79                     info->PixelInformation.ReservedMask;
80                 break;
81         default:
82                 return (1);
83         }
84         return (0);
85 }