Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
b9fc5e0
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fmc
fpga
fsi
gnss
gpio
gpu
drm
amd
arc
arm
armada
ast
atmel-hlcdc
bochs
bridge
cirrus
etnaviv
exynos
fsl-dcu
gma500
hisilicon
i2c
i810
i915
imx
lib
mediatek
meson
mga
mgag200
msm
mxsfb
nouveau
omapdrm
panel
pl111
qxl
r128
radeon
rcar-du
rockchip
savage
scheduler
selftests
shmobile
sis
sti
stm
sun4i
tdfx
tegra
tilcdc
tinydrm
ttm
tve200
udl
v3d
vc4
vgem
via
virtio
vkms
vmwgfx
xen
zte
Kconfig
Makefile
ati_pcigart.c
drm_agpsupport.c
drm_atomic.c
drm_atomic_helper.c
drm_atomic_state_helper.c
drm_atomic_uapi.c
drm_auth.c
drm_blend.c
drm_bridge.c
drm_bufs.c
drm_cache.c
drm_client.c
drm_color_mgmt.c
drm_connector.c
drm_context.c
drm_crtc.c
drm_crtc_helper.c
drm_crtc_helper_internal.h
drm_crtc_internal.h
drm_damage_helper.c
drm_debugfs.c
drm_debugfs_crc.c
drm_dma.c
drm_dp_aux_dev.c
drm_dp_cec.c
drm_dp_dual_mode_helper.c
drm_dp_helper.c
drm_dp_mst_topology.c
drm_drv.c
drm_dumb_buffers.c
drm_edid.c
drm_edid_load.c
drm_encoder.c
drm_encoder_slave.c
drm_fb_cma_helper.c
drm_fb_helper.c
drm_file.c
drm_flip_work.c
drm_fourcc.c
drm_framebuffer.c
drm_gem.c
drm_gem_cma_helper.c
drm_gem_framebuffer_helper.c
drm_hashtab.c
drm_internal.h
drm_ioc32.c
drm_ioctl.c
drm_irq.c
drm_kms_helper_common.c
drm_lease.c
drm_legacy.h
drm_lock.c
drm_memory.c
drm_mipi_dsi.c
drm_mm.c
drm_mode_config.c
drm_mode_object.c
drm_modes.c
drm_modeset_helper.c
drm_modeset_lock.c
drm_of.c
drm_panel.c
drm_panel_orientation_quirks.c
drm_pci.c
drm_plane.c
drm_plane_helper.c
drm_prime.c
drm_print.c
drm_probe_helper.c
drm_property.c
drm_rect.c
drm_scatter.c
drm_scdc_helper.c
drm_simple_kms_helper.c
drm_syncobj.c
drm_sysfs.c
drm_trace.h
drm_trace_points.c
drm_vblank.c
drm_vm.c
drm_vma_manager.c
drm_writeback.c
host1x
ipu-v3
vga
Makefile
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
ide
idle
iio
infiniband
input
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
siox
slimbus
sn
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
uwb
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
gpu
/
drm
/
drm_damage_helper.c
Blame
Blame
Latest commit
History
History
334 lines (298 loc) · 11.3 KB
Breadcrumbs
linux
/
drivers
/
gpu
/
drm
/
drm_damage_helper.c
Top
File metadata and controls
Code
Blame
334 lines (298 loc) · 11.3 KB
Raw
// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright (c) 2018 VMware, Inc., Palo Alto, CA., USA * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. * * Authors: * Deepak Rawat <drawat@vmware.com> * Rob Clark <robdclark@gmail.com> * **************************************************************************/ #include <drm/drm_atomic.h> #include <drm/drm_damage_helper.h> /** * DOC: overview * * FB_DAMAGE_CLIPS is an optional plane property which provides a means to * specify a list of damage rectangles on a plane in framebuffer coordinates of * the framebuffer attached to the plane. In current context damage is the area * of plane framebuffer that has changed since last plane update (also called * page-flip), irrespective of whether currently attached framebuffer is same as * framebuffer attached during last plane update or not. * * FB_DAMAGE_CLIPS is a hint to kernel which could be helpful for some drivers * to optimize internally especially for virtual devices where each framebuffer * change needs to be transmitted over network, usb, etc. * * Since FB_DAMAGE_CLIPS is a hint so it is an optional property. User-space can * ignore damage clips property and in that case driver will do a full plane * update. In case damage clips are provided then it is guaranteed that the area * inside damage clips will be updated to plane. For efficiency driver can do * full update or can update more than specified in damage clips. Since driver * is free to read more, user-space must always render the entire visible * framebuffer. Otherwise there can be corruptions. Also, if a user-space * provides damage clips which doesn't encompass the actual damage to * framebuffer (since last plane update) can result in incorrect rendering. * * FB_DAMAGE_CLIPS is a blob property with the layout of blob data is simply an * array of &drm_mode_rect. Unlike plane &drm_plane_state.src coordinates, * damage clips are not in 16.16 fixed point. Similar to plane src in * framebuffer, damage clips cannot be negative. In damage clip, x1/y1 are * inclusive and x2/y2 are exclusive. While kernel does not error for overlapped * damage clips, it is strongly discouraged. * * Drivers that are interested in damage interface for plane should enable * FB_DAMAGE_CLIPS property by calling drm_plane_enable_fb_damage_clips(). * Drivers implementing damage can use drm_atomic_helper_damage_iter_init() and * drm_atomic_helper_damage_iter_next() helper iterator function to get damage * rectangles clipped to &drm_plane_state.src. */ static void convert_clip_rect_to_rect(const struct drm_clip_rect *src, struct drm_mode_rect *dest, uint32_t num_clips, uint32_t src_inc) { while (num_clips > 0) { dest->x1 = src->x1; dest->y1 = src->y1; dest->x2 = src->x2; dest->y2 = src->y2; src += src_inc; dest++; num_clips--; } } /** * drm_plane_enable_fb_damage_clips - Enables plane fb damage clips property. * @plane: Plane on which to enable damage clips property. * * This function lets driver to enable the damage clips property on a plane. */ void drm_plane_enable_fb_damage_clips(struct drm_plane *plane) { struct drm_device *dev = plane->dev; struct drm_mode_config *config = &dev->mode_config; drm_object_attach_property(&plane->base, config->prop_fb_damage_clips, 0); } EXPORT_SYMBOL(drm_plane_enable_fb_damage_clips); /** * drm_atomic_helper_check_plane_damage - Verify plane damage on atomic_check. * @state: The driver state object. * @plane_state: Plane state for which to verify damage. * * This helper function makes sure that damage from plane state is discarded * for full modeset. If there are more reasons a driver would want to do a full * plane update rather than processing individual damage regions, then those * cases should be taken care of here. * * Note that &drm_plane_state.fb_damage_clips == NULL in plane state means that * full plane update should happen. It also ensure helper iterator will return * &drm_plane_state.src as damage. */ void drm_atomic_helper_check_plane_damage(struct drm_atomic_state *state, struct drm_plane_state *plane_state) { struct drm_crtc_state *crtc_state; if (plane_state->crtc) { crtc_state = drm_atomic_get_new_crtc_state(state, plane_state->crtc); if (WARN_ON(!crtc_state)) return; if (drm_atomic_crtc_needs_modeset(crtc_state)) { drm_property_blob_put(plane_state->fb_damage_clips); plane_state->fb_damage_clips = NULL; } } } EXPORT_SYMBOL(drm_atomic_helper_check_plane_damage); /** * drm_atomic_helper_dirtyfb - Helper for dirtyfb. * @fb: DRM framebuffer. * @file_priv: Drm file for the ioctl call. * @flags: Dirty fb annotate flags. * @color: Color for annotate fill. * @clips: Dirty region. * @num_clips: Count of clip in clips. * * A helper to implement &drm_framebuffer_funcs.dirty using damage interface * during plane update. If num_clips is 0 then this helper will do a full plane * update. This is the same behaviour expected by DIRTFB IOCTL. * * Note that this helper is blocking implementation. This is what current * drivers and userspace expect in their DIRTYFB IOCTL implementation, as a way * to rate-limit userspace and make sure its rendering doesn't get ahead of * uploading new data too much. * * Return: Zero on success, negative errno on failure. */ int drm_atomic_helper_dirtyfb(struct drm_framebuffer *fb, struct drm_file *file_priv, unsigned int flags, unsigned int color, struct drm_clip_rect *clips, unsigned int num_clips) { struct drm_modeset_acquire_ctx ctx; struct drm_property_blob *damage = NULL; struct drm_mode_rect *rects = NULL; struct drm_atomic_state *state; struct drm_plane *plane; int ret = 0; /* * When called from ioctl, we are interruptable, but not when called * internally (ie. defio worker) */ drm_modeset_acquire_init(&ctx, file_priv ? DRM_MODESET_ACQUIRE_INTERRUPTIBLE : 0); state = drm_atomic_state_alloc(fb->dev); if (!state) { ret = -ENOMEM; goto out; } state->acquire_ctx = &ctx; if (clips) { uint32_t inc = 1; if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { inc = 2; num_clips /= 2; } rects = kcalloc(num_clips, sizeof(*rects), GFP_KERNEL); if (!rects) { ret = -ENOMEM; goto out; } convert_clip_rect_to_rect(clips, rects, num_clips, inc); damage = drm_property_create_blob(fb->dev, num_clips * sizeof(*rects), rects); if (IS_ERR(damage)) { ret = PTR_ERR(damage); damage = NULL; goto out; } } retry: drm_for_each_plane(plane, fb->dev) { struct drm_plane_state *plane_state; if (plane->state->fb != fb) continue; plane_state = drm_atomic_get_plane_state(state, plane); if (IS_ERR(plane_state)) { ret = PTR_ERR(plane_state); goto out; } drm_property_replace_blob(&plane_state->fb_damage_clips, damage); } ret = drm_atomic_commit(state); out: if (ret == -EDEADLK) { drm_atomic_state_clear(state); ret = drm_modeset_backoff(&ctx); if (!ret) goto retry; } drm_property_blob_put(damage); kfree(rects); drm_atomic_state_put(state); drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); return ret; } EXPORT_SYMBOL(drm_atomic_helper_dirtyfb); /** * drm_atomic_helper_damage_iter_init - Initialize the damage iterator. * @iter: The iterator to initialize. * @old_state: Old plane state for validation. * @new_state: Plane state from which to iterate the damage clips. * * Initialize an iterator, which clips plane damage * &drm_plane_state.fb_damage_clips to plane &drm_plane_state.src. This iterator * returns full plane src in case damage is not present because either * user-space didn't sent or driver discarded it (it want to do full plane * update). Currently this iterator returns full plane src in case plane src * changed but that can be changed in future to return damage. * * For the case when plane is not visible or plane update should not happen the * first call to iter_next will return false. Note that this helper use clipped * &drm_plane_state.src, so driver calling this helper should have called * drm_atomic_helper_check_plane_state() earlier. */ void drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter, const struct drm_plane_state *old_state, const struct drm_plane_state *state) { memset(iter, 0, sizeof(*iter)); if (!state || !state->crtc || !state->fb || !state->visible) return; iter->clips = drm_helper_get_plane_damage_clips(state); iter->num_clips = drm_plane_get_damage_clips_count(state); /* Round down for x1/y1 and round up for x2/y2 to catch all pixels */ iter->plane_src.x1 = state->src.x1 >> 16; iter->plane_src.y1 = state->src.y1 >> 16; iter->plane_src.x2 = (state->src.x2 >> 16) + !!(state->src.x2 & 0xFFFF); iter->plane_src.y2 = (state->src.y2 >> 16) + !!(state->src.y2 & 0xFFFF); if (!iter->clips || !drm_rect_equals(&state->src, &old_state->src)) { iter->clips = 0; iter->num_clips = 0; iter->full_update = true; } } EXPORT_SYMBOL(drm_atomic_helper_damage_iter_init); /** * drm_atomic_helper_damage_iter_next - Advance the damage iterator. * @iter: The iterator to advance. * @rect: Return a rectangle in fb coordinate clipped to plane src. * * Since plane src is in 16.16 fixed point and damage clips are whole number, * this iterator round off clips that intersect with plane src. Round down for * x1/y1 and round up for x2/y2 for the intersected coordinate. Similar rounding * off for full plane src, in case it's returned as damage. This iterator will * skip damage clips outside of plane src. * * Return: True if the output is valid, false if reached the end. * * If the first call to iterator next returns false then it means no need to * update the plane. */ bool drm_atomic_helper_damage_iter_next(struct drm_atomic_helper_damage_iter *iter, struct drm_rect *rect) { bool ret = false; if (iter->full_update) { *rect = iter->plane_src; iter->full_update = false; return true; } while (iter->curr_clip < iter->num_clips) { *rect = iter->clips[iter->curr_clip]; iter->curr_clip++; if (drm_rect_intersect(rect, &iter->plane_src)) { ret = true; break; } } return ret; } EXPORT_SYMBOL(drm_atomic_helper_damage_iter_next);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
You can’t perform that action at this time.