| .. | .. |
|---|
| 23 | 23 | * Authors: |
|---|
| 24 | 24 | * David Airlie |
|---|
| 25 | 25 | */ |
|---|
| 26 | | -#include <linux/module.h> |
|---|
| 27 | | -#include <linux/slab.h> |
|---|
| 28 | | -#include <linux/pm_runtime.h> |
|---|
| 29 | 26 | |
|---|
| 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> |
|---|
| 31 | 33 | #include <drm/drm_crtc.h> |
|---|
| 32 | 34 | #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 | + |
|---|
| 34 | 38 | #include "amdgpu.h" |
|---|
| 35 | 39 | #include "cikd.h" |
|---|
| 36 | | - |
|---|
| 37 | | -#include <drm/drm_fb_helper.h> |
|---|
| 38 | | - |
|---|
| 39 | | -#include <linux/vga_switcheroo.h> |
|---|
| 40 | +#include "amdgpu_gem.h" |
|---|
| 40 | 41 | |
|---|
| 41 | 42 | #include "amdgpu_display.h" |
|---|
| 42 | 43 | |
|---|
| .. | .. |
|---|
| 48 | 49 | static int |
|---|
| 49 | 50 | amdgpufb_open(struct fb_info *info, int user) |
|---|
| 50 | 51 | { |
|---|
| 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); |
|---|
| 54 | 54 | 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); |
|---|
| 57 | 57 | return ret; |
|---|
| 58 | 58 | } |
|---|
| 59 | 59 | return 0; |
|---|
| .. | .. |
|---|
| 62 | 62 | static int |
|---|
| 63 | 63 | amdgpufb_release(struct fb_info *info, int user) |
|---|
| 64 | 64 | { |
|---|
| 65 | | - struct amdgpu_fbdev *rfbdev = info->par; |
|---|
| 66 | | - struct amdgpu_device *adev = rfbdev->adev; |
|---|
| 65 | + struct drm_fb_helper *fb_helper = info->par; |
|---|
| 67 | 66 | |
|---|
| 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); |
|---|
| 70 | 69 | return 0; |
|---|
| 71 | 70 | } |
|---|
| 72 | 71 | |
|---|
| 73 | | -static struct fb_ops amdgpufb_ops = { |
|---|
| 72 | +static const struct fb_ops amdgpufb_ops = { |
|---|
| 74 | 73 | .owner = THIS_MODULE, |
|---|
| 75 | 74 | DRM_FB_HELPER_DEFAULT_OPS, |
|---|
| 76 | 75 | .fb_open = amdgpufb_open, |
|---|
| .. | .. |
|---|
| 115 | 114 | amdgpu_bo_unpin(abo); |
|---|
| 116 | 115 | amdgpu_bo_unreserve(abo); |
|---|
| 117 | 116 | } |
|---|
| 118 | | - drm_gem_object_put_unlocked(gobj); |
|---|
| 117 | + drm_gem_object_put(gobj); |
|---|
| 119 | 118 | } |
|---|
| 120 | 119 | |
|---|
| 121 | 120 | static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev, |
|---|
| 122 | 121 | struct drm_mode_fb_cmd2 *mode_cmd, |
|---|
| 123 | 122 | struct drm_gem_object **gobj_p) |
|---|
| 124 | 123 | { |
|---|
| 124 | + const struct drm_format_info *info; |
|---|
| 125 | 125 | struct amdgpu_device *adev = rfbdev->adev; |
|---|
| 126 | 126 | struct drm_gem_object *gobj = NULL; |
|---|
| 127 | 127 | struct amdgpu_bo *abo = NULL; |
|---|
| .. | .. |
|---|
| 131 | 131 | int aligned_size, size; |
|---|
| 132 | 132 | int height = mode_cmd->height; |
|---|
| 133 | 133 | u32 cpp; |
|---|
| 134 | + u64 flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | |
|---|
| 135 | + AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS | |
|---|
| 136 | + AMDGPU_GEM_CREATE_VRAM_CLEARED; |
|---|
| 134 | 137 | |
|---|
| 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]; |
|---|
| 136 | 140 | |
|---|
| 137 | 141 | /* need to align pitch with crtc limits */ |
|---|
| 138 | 142 | mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp, |
|---|
| 139 | 143 | fb_tiled); |
|---|
| 140 | | - domain = amdgpu_display_supported_domains(adev); |
|---|
| 141 | | - |
|---|
| 144 | + domain = amdgpu_display_supported_domains(adev, flags); |
|---|
| 142 | 145 | height = ALIGN(mode_cmd->height, 8); |
|---|
| 143 | 146 | size = mode_cmd->pitches[0] * height; |
|---|
| 144 | 147 | 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); |
|---|
| 150 | 150 | if (ret) { |
|---|
| 151 | 151 | pr_err("failed to allocate framebuffer (%d)\n", aligned_size); |
|---|
| 152 | 152 | return -ENOMEM; |
|---|
| .. | .. |
|---|
| 166 | 166 | if (ret) |
|---|
| 167 | 167 | dev_err(adev->dev, "FB failed to set tiling flags\n"); |
|---|
| 168 | 168 | } |
|---|
| 169 | | - |
|---|
| 170 | 169 | |
|---|
| 171 | 170 | ret = amdgpu_bo_pin(abo, domain); |
|---|
| 172 | 171 | if (ret) { |
|---|
| .. | .. |
|---|
| 232 | 231 | goto out; |
|---|
| 233 | 232 | } |
|---|
| 234 | 233 | |
|---|
| 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, |
|---|
| 239 | 235 | &mode_cmd, gobj); |
|---|
| 240 | 236 | if (ret) { |
|---|
| 241 | 237 | DRM_ERROR("failed to initialize framebuffer %d\n", ret); |
|---|
| .. | .. |
|---|
| 247 | 243 | /* setup helper */ |
|---|
| 248 | 244 | rfbdev->helper.fb = fb; |
|---|
| 249 | 245 | |
|---|
| 250 | | - strcpy(info->fix.id, "amdgpudrmfb"); |
|---|
| 251 | | - |
|---|
| 252 | | - drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); |
|---|
| 253 | | - |
|---|
| 254 | 246 | info->fbops = &amdgpufb_ops; |
|---|
| 255 | 247 | |
|---|
| 256 | 248 | tmp = amdgpu_bo_gpu_offset(abo) - adev->gmc.vram_start; |
|---|
| .. | .. |
|---|
| 259 | 251 | info->screen_base = amdgpu_bo_kptr(abo); |
|---|
| 260 | 252 | info->screen_size = amdgpu_bo_size(abo); |
|---|
| 261 | 253 | |
|---|
| 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); |
|---|
| 263 | 255 | |
|---|
| 264 | 256 | /* 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; |
|---|
| 266 | 258 | info->apertures->ranges[0].size = adev->gmc.aper_size; |
|---|
| 267 | 259 | |
|---|
| 268 | 260 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
|---|
| .. | .. |
|---|
| 278 | 270 | DRM_INFO("fb depth is %d\n", fb->format->depth); |
|---|
| 279 | 271 | DRM_INFO(" pitch is %d\n", fb->pitches[0]); |
|---|
| 280 | 272 | |
|---|
| 281 | | - vga_switcheroo_client_fb_set(adev->ddev->pdev, info); |
|---|
| 273 | + vga_switcheroo_client_fb_set(adev_to_drm(adev)->pdev, info); |
|---|
| 282 | 274 | return 0; |
|---|
| 283 | 275 | |
|---|
| 284 | 276 | out: |
|---|
| .. | .. |
|---|
| 286 | 278 | |
|---|
| 287 | 279 | } |
|---|
| 288 | 280 | if (fb && ret) { |
|---|
| 289 | | - drm_gem_object_put_unlocked(gobj); |
|---|
| 281 | + drm_gem_object_put(gobj); |
|---|
| 290 | 282 | drm_framebuffer_unregister_private(fb); |
|---|
| 291 | 283 | drm_framebuffer_cleanup(fb); |
|---|
| 292 | 284 | kfree(fb); |
|---|
| .. | .. |
|---|
| 329 | 321 | return 0; |
|---|
| 330 | 322 | |
|---|
| 331 | 323 | /* 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)) |
|---|
| 333 | 325 | return 0; |
|---|
| 334 | 326 | |
|---|
| 335 | 327 | /* select 8 bpp console on low vram cards */ |
|---|
| .. | .. |
|---|
| 343 | 335 | rfbdev->adev = adev; |
|---|
| 344 | 336 | adev->mode_info.rfbdev = rfbdev; |
|---|
| 345 | 337 | |
|---|
| 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); |
|---|
| 348 | 340 | |
|---|
| 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); |
|---|
| 351 | 342 | if (ret) { |
|---|
| 352 | 343 | kfree(rfbdev); |
|---|
| 353 | 344 | return ret; |
|---|
| 354 | 345 | } |
|---|
| 355 | 346 | |
|---|
| 356 | | - drm_fb_helper_single_add_all_connectors(&rfbdev->helper); |
|---|
| 357 | | - |
|---|
| 358 | 347 | /* disable all the possible outputs/crtcs before entering KMS mode */ |
|---|
| 359 | 348 | 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)); |
|---|
| 361 | 350 | |
|---|
| 362 | 351 | drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel); |
|---|
| 363 | 352 | return 0; |
|---|
| .. | .. |
|---|
| 368 | 357 | if (!adev->mode_info.rfbdev) |
|---|
| 369 | 358 | return; |
|---|
| 370 | 359 | |
|---|
| 371 | | - amdgpu_fbdev_destroy(adev->ddev, adev->mode_info.rfbdev); |
|---|
| 360 | + amdgpu_fbdev_destroy(adev_to_drm(adev), adev->mode_info.rfbdev); |
|---|
| 372 | 361 | kfree(adev->mode_info.rfbdev); |
|---|
| 373 | 362 | adev->mode_info.rfbdev = NULL; |
|---|
| 374 | 363 | } |
|---|