]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0013-fbdev-simplefb-Request-memory-region-in-driver.patch
backport "io_uring: fix race between timeout flush and removal"
[pve-kernel.git] / patches / kernel / 0013-fbdev-simplefb-Request-memory-region-in-driver.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Thomas Zimmermann <tzimmermann@suse.de>
3 Date: Tue, 25 Jan 2022 10:12:21 +0100
4 Subject: [PATCH] fbdev/simplefb: Request memory region in driver
5
6 Requesting the framebuffer memory in simpledrm marks the memory
7 range as busy. This used to be done by the firmware sysfb code,
8 but the driver is the correct place.
9
10 v2:
11 * store memory region in struct for later cleanup (Javier)
12
13 Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
14 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
15 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
16 ---
17 drivers/video/fbdev/simplefb.c | 65 +++++++++++++++++++++++-----------
18 1 file changed, 45 insertions(+), 20 deletions(-)
19
20 diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
21 index b63074fd892e..6885ac0203de 100644
22 --- a/drivers/video/fbdev/simplefb.c
23 +++ b/drivers/video/fbdev/simplefb.c
24 @@ -66,16 +66,36 @@ static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
25 return 0;
26 }
27
28 -struct simplefb_par;
29 +struct simplefb_par {
30 + u32 palette[PSEUDO_PALETTE_SIZE];
31 + struct resource *mem;
32 +#if defined CONFIG_OF && defined CONFIG_COMMON_CLK
33 + bool clks_enabled;
34 + unsigned int clk_count;
35 + struct clk **clks;
36 +#endif
37 +#if defined CONFIG_OF && defined CONFIG_REGULATOR
38 + bool regulators_enabled;
39 + u32 regulator_count;
40 + struct regulator **regulators;
41 +#endif
42 +};
43 +
44 static void simplefb_clocks_destroy(struct simplefb_par *par);
45 static void simplefb_regulators_destroy(struct simplefb_par *par);
46
47 static void simplefb_destroy(struct fb_info *info)
48 {
49 + struct simplefb_par *par = info->par;
50 + struct resource *mem = par->mem;
51 +
52 simplefb_regulators_destroy(info->par);
53 simplefb_clocks_destroy(info->par);
54 if (info->screen_base)
55 iounmap(info->screen_base);
56 +
57 + if (mem)
58 + release_mem_region(mem->start, resource_size(mem));
59 }
60
61 static const struct fb_ops simplefb_ops = {
62 @@ -169,20 +189,6 @@ static int simplefb_parse_pd(struct platform_device *pdev,
63 return 0;
64 }
65
66 -struct simplefb_par {
67 - u32 palette[PSEUDO_PALETTE_SIZE];
68 -#if defined CONFIG_OF && defined CONFIG_COMMON_CLK
69 - bool clks_enabled;
70 - unsigned int clk_count;
71 - struct clk **clks;
72 -#endif
73 -#if defined CONFIG_OF && defined CONFIG_REGULATOR
74 - bool regulators_enabled;
75 - u32 regulator_count;
76 - struct regulator **regulators;
77 -#endif
78 -};
79 -
80 #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
81 /*
82 * Clock handling code.
83 @@ -405,7 +411,7 @@ static int simplefb_probe(struct platform_device *pdev)
84 struct simplefb_params params;
85 struct fb_info *info;
86 struct simplefb_par *par;
87 - struct resource *mem;
88 + struct resource *res, *mem;
89
90 /*
91 * Generic drivers must not be registered if a framebuffer exists.
92 @@ -430,15 +436,28 @@ static int simplefb_probe(struct platform_device *pdev)
93 if (ret)
94 return ret;
95
96 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 - if (!mem) {
98 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
99 + if (!res) {
100 dev_err(&pdev->dev, "No memory resource\n");
101 return -EINVAL;
102 }
103
104 + mem = request_mem_region(res->start, resource_size(res), "simplefb");
105 + if (!mem) {
106 + /*
107 + * We cannot make this fatal. Sometimes this comes from magic
108 + * spaces our resource handlers simply don't know about. Use
109 + * the I/O-memory resource as-is and try to map that instead.
110 + */
111 + dev_warn(&pdev->dev, "simplefb: cannot reserve video memory at %pR\n", res);
112 + mem = res;
113 + }
114 +
115 info = framebuffer_alloc(sizeof(struct simplefb_par), &pdev->dev);
116 - if (!info)
117 - return -ENOMEM;
118 + if (!info) {
119 + ret = -ENOMEM;
120 + goto error_release_mem_region;
121 + }
122 platform_set_drvdata(pdev, info);
123
124 par = info->par;
125 @@ -495,6 +514,9 @@ static int simplefb_probe(struct platform_device *pdev)
126 info->var.xres, info->var.yres,
127 info->var.bits_per_pixel, info->fix.line_length);
128
129 + if (mem != res)
130 + par->mem = mem; /* release in clean-up handler */
131 +
132 ret = register_framebuffer(info);
133 if (ret < 0) {
134 dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
135 @@ -513,6 +535,9 @@ static int simplefb_probe(struct platform_device *pdev)
136 iounmap(info->screen_base);
137 error_fb_release:
138 framebuffer_release(info);
139 +error_release_mem_region:
140 + if (mem != res)
141 + release_mem_region(mem->start, resource_size(mem));
142 return ret;
143 }
144