Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Generic System Framebuffers on x86
  4 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
 
 
 
 
 
  5 */
  6
  7/*
  8 * simple-framebuffer probing
  9 * Try to convert "screen_info" into a "simple-framebuffer" compatible mode.
 10 * If the mode is incompatible, we return "false" and let the caller create
 11 * legacy nodes instead.
 12 */
 13
 14#include <linux/err.h>
 15#include <linux/init.h>
 16#include <linux/kernel.h>
 17#include <linux/mm.h>
 18#include <linux/platform_data/simplefb.h>
 19#include <linux/platform_device.h>
 20#include <linux/screen_info.h>
 21#include <asm/sysfb.h>
 22
 23static const char simplefb_resname[] = "BOOTFB";
 24static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
 25
 26/* try parsing x86 screen_info into a simple-framebuffer mode struct */
 27__init bool parse_mode(const struct screen_info *si,
 28		       struct simplefb_platform_data *mode)
 29{
 30	const struct simplefb_format *f;
 31	__u8 type;
 32	unsigned int i;
 33
 34	type = si->orig_video_isVGA;
 35	if (type != VIDEO_TYPE_VLFB && type != VIDEO_TYPE_EFI)
 36		return false;
 37
 38	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
 39		f = &formats[i];
 40		if (si->lfb_depth == f->bits_per_pixel &&
 41		    si->red_size == f->red.length &&
 42		    si->red_pos == f->red.offset &&
 43		    si->green_size == f->green.length &&
 44		    si->green_pos == f->green.offset &&
 45		    si->blue_size == f->blue.length &&
 46		    si->blue_pos == f->blue.offset &&
 47		    si->rsvd_size == f->transp.length &&
 48		    si->rsvd_pos == f->transp.offset) {
 49			mode->format = f->name;
 50			mode->width = si->lfb_width;
 51			mode->height = si->lfb_height;
 52			mode->stride = si->lfb_linelength;
 53			return true;
 54		}
 55	}
 56
 57	return false;
 58}
 59
 60__init int create_simplefb(const struct screen_info *si,
 61			   const struct simplefb_platform_data *mode)
 62{
 63	struct platform_device *pd;
 64	struct resource res;
 65	u64 base, size;
 66	u32 length;
 67
 68	/*
 69	 * If the 64BIT_BASE capability is set, ext_lfb_base will contain the
 70	 * upper half of the base address. Assemble the address, then make sure
 71	 * it is valid and we can actually access it.
 72	 */
 73	base = si->lfb_base;
 74	if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
 75		base |= (u64)si->ext_lfb_base << 32;
 76	if (!base || (u64)(resource_size_t)base != base) {
 77		printk(KERN_DEBUG "sysfb: inaccessible VRAM base\n");
 78		return -EINVAL;
 79	}
 80
 81	/*
 82	 * Don't use lfb_size as IORESOURCE size, since it may contain the
 83	 * entire VMEM, and thus require huge mappings. Use just the part we
 84	 * need, that is, the part where the framebuffer is located. But verify
 85	 * that it does not exceed the advertised VMEM.
 86	 * Note that in case of VBE, the lfb_size is shifted by 16 bits for
 87	 * historical reasons.
 88	 */
 89	size = si->lfb_size;
 90	if (si->orig_video_isVGA == VIDEO_TYPE_VLFB)
 91		size <<= 16;
 92	length = mode->height * mode->stride;
 93	length = PAGE_ALIGN(length);
 94	if (length > size) {
 95		printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n");
 96		return -EINVAL;
 97	}
 98
 99	/* setup IORESOURCE_MEM as framebuffer memory */
100	memset(&res, 0, sizeof(res));
101	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
102	res.name = simplefb_resname;
103	res.start = base;
104	res.end = res.start + length - 1;
105	if (res.end <= res.start)
106		return -EINVAL;
107
108	pd = platform_device_register_resndata(NULL, "simple-framebuffer", 0,
109					       &res, 1, mode, sizeof(*mode));
110	return PTR_ERR_OR_ZERO(pd);
 
 
 
111}
v3.15
 
 1/*
 2 * Generic System Framebuffers on x86
 3 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
 4 *
 5 * This program is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU General Public License as published by the Free
 7 * Software Foundation; either version 2 of the License, or (at your option)
 8 * any later version.
 9 */
10
11/*
12 * simple-framebuffer probing
13 * Try to convert "screen_info" into a "simple-framebuffer" compatible mode.
14 * If the mode is incompatible, we return "false" and let the caller create
15 * legacy nodes instead.
16 */
17
18#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/platform_data/simplefb.h>
23#include <linux/platform_device.h>
24#include <linux/screen_info.h>
25#include <asm/sysfb.h>
26
27static const char simplefb_resname[] = "BOOTFB";
28static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
29
30/* try parsing x86 screen_info into a simple-framebuffer mode struct */
31__init bool parse_mode(const struct screen_info *si,
32		       struct simplefb_platform_data *mode)
33{
34	const struct simplefb_format *f;
35	__u8 type;
36	unsigned int i;
37
38	type = si->orig_video_isVGA;
39	if (type != VIDEO_TYPE_VLFB && type != VIDEO_TYPE_EFI)
40		return false;
41
42	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
43		f = &formats[i];
44		if (si->lfb_depth == f->bits_per_pixel &&
45		    si->red_size == f->red.length &&
46		    si->red_pos == f->red.offset &&
47		    si->green_size == f->green.length &&
48		    si->green_pos == f->green.offset &&
49		    si->blue_size == f->blue.length &&
50		    si->blue_pos == f->blue.offset &&
51		    si->rsvd_size == f->transp.length &&
52		    si->rsvd_pos == f->transp.offset) {
53			mode->format = f->name;
54			mode->width = si->lfb_width;
55			mode->height = si->lfb_height;
56			mode->stride = si->lfb_linelength;
57			return true;
58		}
59	}
60
61	return false;
62}
63
64__init int create_simplefb(const struct screen_info *si,
65			   const struct simplefb_platform_data *mode)
66{
67	struct platform_device *pd;
68	struct resource res;
69	unsigned long len;
 
70
71	/* don't use lfb_size as it may contain the whole VMEM instead of only
72	 * the part that is occupied by the framebuffer */
73	len = mode->height * mode->stride;
74	len = PAGE_ALIGN(len);
75	if (len > (u64)si->lfb_size << 16) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76		printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n");
77		return -EINVAL;
78	}
79
80	/* setup IORESOURCE_MEM as framebuffer memory */
81	memset(&res, 0, sizeof(res));
82	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
83	res.name = simplefb_resname;
84	res.start = si->lfb_base;
85	res.end = si->lfb_base + len - 1;
86	if (res.end <= res.start)
87		return -EINVAL;
88
89	pd = platform_device_register_resndata(NULL, "simple-framebuffer", 0,
90					       &res, 1, mode, sizeof(*mode));
91	if (IS_ERR(pd))
92		return PTR_ERR(pd);
93
94	return 0;
95}