| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Red Hat |
|---|
| 3 | 4 | * Author: Rob Clark <robdclark@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 version 2 as published by |
|---|
| 7 | | - * the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 12 | | - * more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 15 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 18 | 7 | #include <drm/drm_crtc.h> |
|---|
| 19 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 8 | +#include <drm/drm_damage_helper.h> |
|---|
| 9 | +#include <drm/drm_file.h> |
|---|
| 10 | +#include <drm/drm_fourcc.h> |
|---|
| 20 | 11 | #include <drm/drm_gem_framebuffer_helper.h> |
|---|
| 12 | +#include <drm/drm_probe_helper.h> |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #include "msm_drv.h" |
|---|
| 23 | 15 | #include "msm_kms.h" |
|---|
| .. | .. |
|---|
| 35 | 27 | static const struct drm_framebuffer_funcs msm_framebuffer_funcs = { |
|---|
| 36 | 28 | .create_handle = drm_gem_fb_create_handle, |
|---|
| 37 | 29 | .destroy = drm_gem_fb_destroy, |
|---|
| 30 | + .dirty = drm_atomic_helper_dirtyfb, |
|---|
| 38 | 31 | }; |
|---|
| 39 | 32 | |
|---|
| 40 | 33 | #ifdef CONFIG_DEBUG_FS |
|---|
| .. | .. |
|---|
| 66 | 59 | uint64_t iova; |
|---|
| 67 | 60 | |
|---|
| 68 | 61 | for (i = 0; i < n; i++) { |
|---|
| 69 | | - ret = msm_gem_get_iova(fb->obj[i], aspace, &iova); |
|---|
| 62 | + ret = msm_gem_get_and_pin_iova(fb->obj[i], aspace, &iova); |
|---|
| 70 | 63 | DBG("FB[%u]: iova[%d]: %08llx (%d)", fb->base.id, i, iova, ret); |
|---|
| 71 | 64 | if (ret) |
|---|
| 72 | 65 | return ret; |
|---|
| .. | .. |
|---|
| 81 | 74 | int i, n = fb->format->num_planes; |
|---|
| 82 | 75 | |
|---|
| 83 | 76 | for (i = 0; i < n; i++) |
|---|
| 84 | | - msm_gem_put_iova(fb->obj[i], aspace); |
|---|
| 77 | + msm_gem_unpin_iova(fb->obj[i], aspace); |
|---|
| 85 | 78 | } |
|---|
| 86 | 79 | |
|---|
| 87 | 80 | uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb, |
|---|
| .. | .. |
|---|
| 106 | 99 | struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev, |
|---|
| 107 | 100 | struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) |
|---|
| 108 | 101 | { |
|---|
| 102 | + const struct drm_format_info *info = drm_get_format_info(dev, |
|---|
| 103 | + mode_cmd); |
|---|
| 109 | 104 | struct drm_gem_object *bos[4] = {0}; |
|---|
| 110 | 105 | struct drm_framebuffer *fb; |
|---|
| 111 | | - int ret, i, n = drm_format_num_planes(mode_cmd->pixel_format); |
|---|
| 106 | + int ret, i, n = info->num_planes; |
|---|
| 112 | 107 | |
|---|
| 113 | 108 | for (i = 0; i < n; i++) { |
|---|
| 114 | 109 | bos[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); |
|---|
| .. | .. |
|---|
| 128 | 123 | |
|---|
| 129 | 124 | out_unref: |
|---|
| 130 | 125 | for (i = 0; i < n; i++) |
|---|
| 131 | | - drm_gem_object_put_unlocked(bos[i]); |
|---|
| 126 | + drm_gem_object_put(bos[i]); |
|---|
| 132 | 127 | return ERR_PTR(ret); |
|---|
| 133 | 128 | } |
|---|
| 134 | 129 | |
|---|
| 135 | 130 | static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, |
|---|
| 136 | 131 | const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) |
|---|
| 137 | 132 | { |
|---|
| 133 | + const struct drm_format_info *info = drm_get_format_info(dev, |
|---|
| 134 | + mode_cmd); |
|---|
| 138 | 135 | struct msm_drm_private *priv = dev->dev_private; |
|---|
| 139 | 136 | struct msm_kms *kms = priv->kms; |
|---|
| 140 | 137 | struct msm_framebuffer *msm_fb = NULL; |
|---|
| 141 | 138 | struct drm_framebuffer *fb; |
|---|
| 142 | 139 | const struct msm_format *format; |
|---|
| 143 | 140 | int ret, i, n; |
|---|
| 144 | | - unsigned int hsub, vsub; |
|---|
| 145 | 141 | |
|---|
| 146 | 142 | DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)", |
|---|
| 147 | 143 | dev, mode_cmd, mode_cmd->width, mode_cmd->height, |
|---|
| 148 | 144 | (char *)&mode_cmd->pixel_format); |
|---|
| 149 | 145 | |
|---|
| 150 | | - n = drm_format_num_planes(mode_cmd->pixel_format); |
|---|
| 151 | | - hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format); |
|---|
| 152 | | - vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format); |
|---|
| 153 | | - |
|---|
| 146 | + n = info->num_planes; |
|---|
| 154 | 147 | format = kms->funcs->get_format(kms, mode_cmd->pixel_format, |
|---|
| 155 | 148 | mode_cmd->modifier[0]); |
|---|
| 156 | 149 | if (!format) { |
|---|
| 157 | | - dev_err(dev->dev, "unsupported pixel format: %4.4s\n", |
|---|
| 150 | + DRM_DEV_ERROR(dev->dev, "unsupported pixel format: %4.4s\n", |
|---|
| 158 | 151 | (char *)&mode_cmd->pixel_format); |
|---|
| 159 | 152 | ret = -EINVAL; |
|---|
| 160 | 153 | goto fail; |
|---|
| .. | .. |
|---|
| 176 | 169 | } |
|---|
| 177 | 170 | |
|---|
| 178 | 171 | for (i = 0; i < n; i++) { |
|---|
| 179 | | - unsigned int width = mode_cmd->width / (i ? hsub : 1); |
|---|
| 180 | | - unsigned int height = mode_cmd->height / (i ? vsub : 1); |
|---|
| 172 | + unsigned int width = mode_cmd->width / (i ? info->hsub : 1); |
|---|
| 173 | + unsigned int height = mode_cmd->height / (i ? info->vsub : 1); |
|---|
| 181 | 174 | unsigned int min_size; |
|---|
| 182 | 175 | |
|---|
| 183 | 176 | min_size = (height - 1) * mode_cmd->pitches[i] |
|---|
| 184 | | - + width * drm_format_plane_cpp(mode_cmd->pixel_format, i) |
|---|
| 177 | + + width * info->cpp[i] |
|---|
| 185 | 178 | + mode_cmd->offsets[i]; |
|---|
| 186 | 179 | |
|---|
| 187 | 180 | if (bos[i]->size < min_size) { |
|---|
| .. | .. |
|---|
| 196 | 189 | |
|---|
| 197 | 190 | ret = drm_framebuffer_init(dev, fb, &msm_framebuffer_funcs); |
|---|
| 198 | 191 | if (ret) { |
|---|
| 199 | | - dev_err(dev->dev, "framebuffer init failed: %d\n", ret); |
|---|
| 192 | + DRM_DEV_ERROR(dev->dev, "framebuffer init failed: %d\n", ret); |
|---|
| 200 | 193 | goto fail; |
|---|
| 201 | 194 | } |
|---|
| 202 | 195 | |
|---|
| .. | .. |
|---|
| 233 | 226 | bo = msm_gem_new(dev, size, MSM_BO_SCANOUT | MSM_BO_WC); |
|---|
| 234 | 227 | } |
|---|
| 235 | 228 | if (IS_ERR(bo)) { |
|---|
| 236 | | - dev_err(dev->dev, "failed to allocate buffer object\n"); |
|---|
| 229 | + DRM_DEV_ERROR(dev->dev, "failed to allocate buffer object\n"); |
|---|
| 237 | 230 | return ERR_CAST(bo); |
|---|
| 238 | 231 | } |
|---|
| 239 | 232 | |
|---|
| 233 | + msm_gem_object_set_name(bo, "stolenfb"); |
|---|
| 234 | + |
|---|
| 240 | 235 | fb = msm_framebuffer_init(dev, &mode_cmd, &bo); |
|---|
| 241 | 236 | if (IS_ERR(fb)) { |
|---|
| 242 | | - dev_err(dev->dev, "failed to allocate fb\n"); |
|---|
| 237 | + DRM_DEV_ERROR(dev->dev, "failed to allocate fb\n"); |
|---|
| 243 | 238 | /* note: if fb creation failed, we can't rely on fb destroy |
|---|
| 244 | 239 | * to unref the bo: |
|---|
| 245 | 240 | */ |
|---|
| 246 | | - drm_gem_object_put_unlocked(bo); |
|---|
| 241 | + drm_gem_object_put(bo); |
|---|
| 247 | 242 | return ERR_CAST(fb); |
|---|
| 248 | 243 | } |
|---|
| 249 | 244 | |
|---|