hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
....@@ -23,20 +23,21 @@
2323 * Authors:
2424 * David Airlie
2525 */
26
-#include <linux/module.h>
27
-#include <linux/slab.h>
28
-#include <linux/pm_runtime.h>
2926
30
-#include <drm/drmP.h>
27
+#include <linux/module.h>
28
+#include <linux/pm_runtime.h>
29
+#include <linux/slab.h>
30
+#include <linux/vga_switcheroo.h>
31
+
32
+#include <drm/amdgpu_drm.h>
3133 #include <drm/drm_crtc.h>
3234 #include <drm/drm_crtc_helper.h>
33
-#include <drm/amdgpu_drm.h>
35
+#include <drm/drm_fb_helper.h>
36
+#include <drm/drm_fourcc.h>
37
+
3438 #include "amdgpu.h"
3539 #include "cikd.h"
36
-
37
-#include <drm/drm_fb_helper.h>
38
-
39
-#include <linux/vga_switcheroo.h>
40
+#include "amdgpu_gem.h"
4041
4142 #include "amdgpu_display.h"
4243
....@@ -48,12 +49,11 @@
4849 static int
4950 amdgpufb_open(struct fb_info *info, int user)
5051 {
51
- struct amdgpu_fbdev *rfbdev = info->par;
52
- struct amdgpu_device *adev = rfbdev->adev;
53
- int ret = pm_runtime_get_sync(adev->ddev->dev);
52
+ struct drm_fb_helper *fb_helper = info->par;
53
+ int ret = pm_runtime_get_sync(fb_helper->dev->dev);
5454 if (ret < 0 && ret != -EACCES) {
55
- pm_runtime_mark_last_busy(adev->ddev->dev);
56
- pm_runtime_put_autosuspend(adev->ddev->dev);
55
+ pm_runtime_mark_last_busy(fb_helper->dev->dev);
56
+ pm_runtime_put_autosuspend(fb_helper->dev->dev);
5757 return ret;
5858 }
5959 return 0;
....@@ -62,15 +62,14 @@
6262 static int
6363 amdgpufb_release(struct fb_info *info, int user)
6464 {
65
- struct amdgpu_fbdev *rfbdev = info->par;
66
- struct amdgpu_device *adev = rfbdev->adev;
65
+ struct drm_fb_helper *fb_helper = info->par;
6766
68
- pm_runtime_mark_last_busy(adev->ddev->dev);
69
- pm_runtime_put_autosuspend(adev->ddev->dev);
67
+ pm_runtime_mark_last_busy(fb_helper->dev->dev);
68
+ pm_runtime_put_autosuspend(fb_helper->dev->dev);
7069 return 0;
7170 }
7271
73
-static struct fb_ops amdgpufb_ops = {
72
+static const struct fb_ops amdgpufb_ops = {
7473 .owner = THIS_MODULE,
7574 DRM_FB_HELPER_DEFAULT_OPS,
7675 .fb_open = amdgpufb_open,
....@@ -115,13 +114,14 @@
115114 amdgpu_bo_unpin(abo);
116115 amdgpu_bo_unreserve(abo);
117116 }
118
- drm_gem_object_put_unlocked(gobj);
117
+ drm_gem_object_put(gobj);
119118 }
120119
121120 static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
122121 struct drm_mode_fb_cmd2 *mode_cmd,
123122 struct drm_gem_object **gobj_p)
124123 {
124
+ const struct drm_format_info *info;
125125 struct amdgpu_device *adev = rfbdev->adev;
126126 struct drm_gem_object *gobj = NULL;
127127 struct amdgpu_bo *abo = NULL;
....@@ -131,22 +131,22 @@
131131 int aligned_size, size;
132132 int height = mode_cmd->height;
133133 u32 cpp;
134
+ u64 flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
135
+ AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
136
+ AMDGPU_GEM_CREATE_VRAM_CLEARED;
134137
135
- cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
138
+ info = drm_get_format_info(adev_to_drm(adev), mode_cmd);
139
+ cpp = info->cpp[0];
136140
137141 /* need to align pitch with crtc limits */
138142 mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp,
139143 fb_tiled);
140
- domain = amdgpu_display_supported_domains(adev);
141
-
144
+ domain = amdgpu_display_supported_domains(adev, flags);
142145 height = ALIGN(mode_cmd->height, 8);
143146 size = mode_cmd->pitches[0] * height;
144147 aligned_size = ALIGN(size, PAGE_SIZE);
145
- ret = amdgpu_gem_object_create(adev, aligned_size, 0, domain,
146
- AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
147
- AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
148
- AMDGPU_GEM_CREATE_VRAM_CLEARED,
149
- ttm_bo_type_kernel, NULL, &gobj);
148
+ ret = amdgpu_gem_object_create(adev, aligned_size, 0, domain, flags,
149
+ ttm_bo_type_device, NULL, &gobj);
150150 if (ret) {
151151 pr_err("failed to allocate framebuffer (%d)\n", aligned_size);
152152 return -ENOMEM;
....@@ -166,7 +166,6 @@
166166 if (ret)
167167 dev_err(adev->dev, "FB failed to set tiling flags\n");
168168 }
169
-
170169
171170 ret = amdgpu_bo_pin(abo, domain);
172171 if (ret) {
....@@ -232,10 +231,7 @@
232231 goto out;
233232 }
234233
235
- info->par = rfbdev;
236
- info->skip_vt_switch = true;
237
-
238
- ret = amdgpu_display_framebuffer_init(adev->ddev, &rfbdev->rfb,
234
+ ret = amdgpu_display_framebuffer_init(adev_to_drm(adev), &rfbdev->rfb,
239235 &mode_cmd, gobj);
240236 if (ret) {
241237 DRM_ERROR("failed to initialize framebuffer %d\n", ret);
....@@ -247,10 +243,6 @@
247243 /* setup helper */
248244 rfbdev->helper.fb = fb;
249245
250
- strcpy(info->fix.id, "amdgpudrmfb");
251
-
252
- drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
253
-
254246 info->fbops = &amdgpufb_ops;
255247
256248 tmp = amdgpu_bo_gpu_offset(abo) - adev->gmc.vram_start;
....@@ -259,10 +251,10 @@
259251 info->screen_base = amdgpu_bo_kptr(abo);
260252 info->screen_size = amdgpu_bo_size(abo);
261253
262
- drm_fb_helper_fill_var(info, &rfbdev->helper, sizes->fb_width, sizes->fb_height);
254
+ drm_fb_helper_fill_info(info, &rfbdev->helper, sizes);
263255
264256 /* setup aperture base/size for vesafb takeover */
265
- info->apertures->ranges[0].base = adev->ddev->mode_config.fb_base;
257
+ info->apertures->ranges[0].base = adev_to_drm(adev)->mode_config.fb_base;
266258 info->apertures->ranges[0].size = adev->gmc.aper_size;
267259
268260 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
....@@ -278,7 +270,7 @@
278270 DRM_INFO("fb depth is %d\n", fb->format->depth);
279271 DRM_INFO(" pitch is %d\n", fb->pitches[0]);
280272
281
- vga_switcheroo_client_fb_set(adev->ddev->pdev, info);
273
+ vga_switcheroo_client_fb_set(adev_to_drm(adev)->pdev, info);
282274 return 0;
283275
284276 out:
....@@ -286,7 +278,7 @@
286278
287279 }
288280 if (fb && ret) {
289
- drm_gem_object_put_unlocked(gobj);
281
+ drm_gem_object_put(gobj);
290282 drm_framebuffer_unregister_private(fb);
291283 drm_framebuffer_cleanup(fb);
292284 kfree(fb);
....@@ -329,7 +321,7 @@
329321 return 0;
330322
331323 /* don't init fbdev if there are no connectors */
332
- if (list_empty(&adev->ddev->mode_config.connector_list))
324
+ if (list_empty(&adev_to_drm(adev)->mode_config.connector_list))
333325 return 0;
334326
335327 /* select 8 bpp console on low vram cards */
....@@ -343,21 +335,18 @@
343335 rfbdev->adev = adev;
344336 adev->mode_info.rfbdev = rfbdev;
345337
346
- drm_fb_helper_prepare(adev->ddev, &rfbdev->helper,
347
- &amdgpu_fb_helper_funcs);
338
+ drm_fb_helper_prepare(adev_to_drm(adev), &rfbdev->helper,
339
+ &amdgpu_fb_helper_funcs);
348340
349
- ret = drm_fb_helper_init(adev->ddev, &rfbdev->helper,
350
- AMDGPUFB_CONN_LIMIT);
341
+ ret = drm_fb_helper_init(adev_to_drm(adev), &rfbdev->helper);
351342 if (ret) {
352343 kfree(rfbdev);
353344 return ret;
354345 }
355346
356
- drm_fb_helper_single_add_all_connectors(&rfbdev->helper);
357
-
358347 /* disable all the possible outputs/crtcs before entering KMS mode */
359348 if (!amdgpu_device_has_dc_support(adev))
360
- drm_helper_disable_unused_functions(adev->ddev);
349
+ drm_helper_disable_unused_functions(adev_to_drm(adev));
361350
362351 drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel);
363352 return 0;
....@@ -368,7 +357,7 @@
368357 if (!adev->mode_info.rfbdev)
369358 return;
370359
371
- amdgpu_fbdev_destroy(adev->ddev, adev->mode_info.rfbdev);
360
+ amdgpu_fbdev_destroy(adev_to_drm(adev), adev->mode_info.rfbdev);
372361 kfree(adev->mode_info.rfbdev);
373362 adev->mode_info.rfbdev = NULL;
374363 }