framebuffer.c revision 294981
1241823Smarcel/*- 2241823Smarcel * Copyright (c) 2013 The FreeBSD Foundation 3241823Smarcel * All rights reserved. 4241823Smarcel * 5241823Smarcel * This software was developed by Benno Rice under sponsorship from 6241823Smarcel * the FreeBSD Foundation. 7241823Smarcel * Redistribution and use in source and binary forms, with or without 8241823Smarcel * modification, are permitted provided that the following conditions 9241823Smarcel * are met: 10241823Smarcel * 1. Redistributions of source code must retain the above copyright 11241823Smarcel * notice, this list of conditions and the following disclaimer. 12241823Smarcel * 2. Redistributions in binary form must reproduce the above copyright 13241823Smarcel * notice, this list of conditions and the following disclaimer in the 14241823Smarcel * documentation and/or other materials provided with the distribution. 15241823Smarcel * 16241823Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17241823Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18241823Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19241823Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20241823Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21241823Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22241823Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23241823Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24241823Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25241823Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26241823Smarcel * SUCH DAMAGE. 27241823Smarcel */ 28241823Smarcel 29241823Smarcel#include <sys/cdefs.h> 30305911Sngie__FBSDID("$FreeBSD: stable/10/sys/boot/efi/loader/arch/amd64/framebuffer.c 294981 2016-01-28 12:11:42Z smh $"); 31305911Sngie 32305911Sngie#include <stand.h> 33305911Sngie 34305911Sngie#include <efi.h> 35305911Sngie#include <efilib.h> 36305911Sngie#include <machine/metadata.h> 37305911Sngie 38305911Sngie#include "framebuffer.h" 39275988Sngie 40305911Sngiestatic EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; 41305911Sngie 42305911Sngieint 43305911Sngieefi_find_framebuffer(struct efi_fb *efifb) 44305911Sngie{ 45305911Sngie EFI_GRAPHICS_OUTPUT *gop; 46241823Smarcel EFI_STATUS status; 47270905Sngie EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode; 48275988Sngie EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; 49241823Smarcel 50305911Sngie status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); 51241823Smarcel if (EFI_ERROR(status)) 52241823Smarcel return (1); 53241823Smarcel 54241823Smarcel mode = gop->Mode; 55305911Sngie info = gop->Mode->Info; 56305911Sngie 57305911Sngie efifb->fb_addr = mode->FrameBufferBase; 58305911Sngie efifb->fb_size = mode->FrameBufferSize; 59305911Sngie efifb->fb_height = info->VerticalResolution; 60305911Sngie efifb->fb_width = info->HorizontalResolution; 61241823Smarcel efifb->fb_stride = info->PixelsPerScanLine; 62241823Smarcel 63241823Smarcel switch (info->PixelFormat) { 64241823Smarcel case PixelRedGreenBlueReserved8BitPerColor: 65241823Smarcel efifb->fb_mask_red = 0x000000ff; 66241823Smarcel efifb->fb_mask_green = 0x0000ff00; 67241823Smarcel efifb->fb_mask_blue = 0x00ff0000; 68241823Smarcel efifb->fb_mask_reserved = 0xff000000; 69241823Smarcel break; 70241823Smarcel case PixelBlueGreenRedReserved8BitPerColor: 71241823Smarcel efifb->fb_mask_red = 0x00ff0000; 72241823Smarcel efifb->fb_mask_green = 0x0000ff00; 73241823Smarcel efifb->fb_mask_blue = 0x000000ff; 74241823Smarcel efifb->fb_mask_reserved = 0xff000000; 75241823Smarcel break; 76241823Smarcel case PixelBitMask: 77241823Smarcel efifb->fb_mask_red = info->PixelInformation.RedMask; 78241823Smarcel efifb->fb_mask_green = info->PixelInformation.GreenMask; 79241823Smarcel efifb->fb_mask_blue = info->PixelInformation.BlueMask; 80241823Smarcel efifb->fb_mask_reserved = 81241823Smarcel info->PixelInformation.ReservedMask; 82241823Smarcel break; 83241823Smarcel default: 84241823Smarcel return (1); 85241823Smarcel } 86241823Smarcel return (0); 87241823Smarcel} 88241823Smarcel