xref: /linux/drivers/gpu/drm/vkms/vkms_plane.c (revision e9f0878c4b2004ac19581274c1ae4c61ae3ca70e)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  */
8 
9 #include "vkms_drv.h"
10 #include <drm/drm_plane_helper.h>
11 #include <drm/drm_atomic_helper.h>
12 
13 static const struct drm_plane_funcs vkms_plane_funcs = {
14 	.update_plane		= drm_atomic_helper_update_plane,
15 	.disable_plane		= drm_atomic_helper_disable_plane,
16 	.destroy		= drm_plane_cleanup,
17 	.reset			= drm_atomic_helper_plane_reset,
18 	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
19 	.atomic_destroy_state	= drm_atomic_helper_plane_destroy_state,
20 };
21 
22 static void vkms_primary_plane_update(struct drm_plane *plane,
23 				      struct drm_plane_state *old_state)
24 {
25 }
26 
27 static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = {
28 	.atomic_update		= vkms_primary_plane_update,
29 };
30 
31 struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev)
32 {
33 	struct drm_device *dev = &vkmsdev->drm;
34 	struct drm_plane *plane;
35 	const u32 *formats;
36 	int ret, nformats;
37 
38 	plane = kzalloc(sizeof(*plane), GFP_KERNEL);
39 	if (!plane)
40 		return ERR_PTR(-ENOMEM);
41 
42 	formats = vkms_formats;
43 	nformats = ARRAY_SIZE(vkms_formats);
44 
45 	ret = drm_universal_plane_init(dev, plane, 0,
46 				       &vkms_plane_funcs,
47 				       formats, nformats,
48 				       NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
49 	if (ret) {
50 		kfree(plane);
51 		return ERR_PTR(ret);
52 	}
53 
54 	drm_plane_helper_add(plane, &vkms_primary_helper_funcs);
55 
56 	return plane;
57 }
58