Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0+
  2
  3#include "vkms_drv.h"
  4#include <drm/drm_atomic_helper.h>
  5#include <drm/drm_edid.h>
  6#include <drm/drm_probe_helper.h>
 
 
 
 
 
 
  7
  8static const struct drm_connector_funcs vkms_connector_funcs = {
  9	.fill_modes = drm_helper_probe_single_connector_modes,
 10	.destroy = drm_connector_cleanup,
 11	.reset = drm_atomic_helper_connector_reset,
 12	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 13	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 14};
 15
 16static const struct drm_encoder_funcs vkms_encoder_funcs = {
 17	.destroy = drm_encoder_cleanup,
 18};
 19
 20static int vkms_conn_get_modes(struct drm_connector *connector)
 21{
 22	int count;
 23
 24	/* Use the default modes list from DRM */
 25	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
 26	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
 27
 28	return count;
 29}
 30
 31static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
 32	.get_modes    = vkms_conn_get_modes,
 33};
 34
 35static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
 36				  struct drm_crtc *crtc)
 37{
 38	struct vkms_plane *overlay;
 39
 40	overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
 41	if (IS_ERR(overlay))
 42		return PTR_ERR(overlay);
 43
 44	if (!overlay->base.possible_crtcs)
 45		overlay->base.possible_crtcs = drm_crtc_mask(crtc);
 46
 47	return 0;
 48}
 49
 50int vkms_output_init(struct vkms_device *vkmsdev, int index)
 51{
 52	struct vkms_output *output = &vkmsdev->output;
 53	struct drm_device *dev = &vkmsdev->drm;
 54	struct drm_connector *connector = &output->connector;
 55	struct drm_encoder *encoder = &output->encoder;
 56	struct drm_crtc *crtc = &output->crtc;
 57	struct vkms_plane *primary, *cursor = NULL;
 58	int ret;
 59	int writeback;
 60	unsigned int n;
 61
 62	/*
 63	 * Initialize used plane. One primary plane is required to perform the composition.
 64	 *
 65	 * The overlay and cursor planes are not mandatory, but can be used to perform complex
 66	 * composition.
 67	 */
 68	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
 69	if (IS_ERR(primary))
 70		return PTR_ERR(primary);
 71
 72	if (vkmsdev->config->overlay) {
 73		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
 74			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
 75			if (ret)
 76				return ret;
 77		}
 78	}
 79
 80	if (vkmsdev->config->cursor) {
 81		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
 82		if (IS_ERR(cursor))
 83			return PTR_ERR(cursor);
 84	}
 85
 86	/* [1]: Allocation of a CRTC, its index will be BIT(0) = 1 */
 87	ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
 88	if (ret)
 89		return ret;
 90
 91	ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
 92				 DRM_MODE_CONNECTOR_VIRTUAL);
 93	if (ret) {
 94		DRM_ERROR("Failed to init connector\n");
 95		return ret;
 96	}
 97
 98	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
 99
100	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
101			       DRM_MODE_ENCODER_VIRTUAL, NULL);
102	if (ret) {
103		DRM_ERROR("Failed to init encoder\n");
104		goto err_encoder;
105	}
106	/*
107	 * This is a hardcoded value to select crtc for the encoder.
108	 * BIT(0) here designate the first registered CRTC, the one allocated in [1]
109	 */
110	encoder->possible_crtcs = BIT(0);
111
112	ret = drm_connector_attach_encoder(connector, encoder);
113	if (ret) {
114		DRM_ERROR("Failed to attach connector to encoder\n");
115		goto err_attach;
116	}
117
118	if (vkmsdev->config->writeback) {
119		writeback = vkms_enable_writeback_connector(vkmsdev);
120		if (writeback)
121			DRM_ERROR("Failed to init writeback connector\n");
122	}
123
124	drm_mode_config_reset(dev);
125
126	return 0;
127
128err_attach:
129	drm_encoder_cleanup(encoder);
130
131err_encoder:
132	drm_connector_cleanup(connector);
 
 
 
133
134	return ret;
135}
v6.2
  1// SPDX-License-Identifier: GPL-2.0+
  2
  3#include "vkms_drv.h"
  4#include <drm/drm_atomic_helper.h>
  5#include <drm/drm_edid.h>
  6#include <drm/drm_probe_helper.h>
  7#include <drm/drm_simple_kms_helper.h>
  8
  9static void vkms_connector_destroy(struct drm_connector *connector)
 10{
 11	drm_connector_cleanup(connector);
 12}
 13
 14static const struct drm_connector_funcs vkms_connector_funcs = {
 15	.fill_modes = drm_helper_probe_single_connector_modes,
 16	.destroy = vkms_connector_destroy,
 17	.reset = drm_atomic_helper_connector_reset,
 18	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 19	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 20};
 21
 
 
 
 
 22static int vkms_conn_get_modes(struct drm_connector *connector)
 23{
 24	int count;
 25
 
 26	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
 27	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
 28
 29	return count;
 30}
 31
 32static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
 33	.get_modes    = vkms_conn_get_modes,
 34};
 35
 36static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
 37				  struct drm_crtc *crtc)
 38{
 39	struct vkms_plane *overlay;
 40
 41	overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
 42	if (IS_ERR(overlay))
 43		return PTR_ERR(overlay);
 44
 45	if (!overlay->base.possible_crtcs)
 46		overlay->base.possible_crtcs = drm_crtc_mask(crtc);
 47
 48	return 0;
 49}
 50
 51int vkms_output_init(struct vkms_device *vkmsdev, int index)
 52{
 53	struct vkms_output *output = &vkmsdev->output;
 54	struct drm_device *dev = &vkmsdev->drm;
 55	struct drm_connector *connector = &output->connector;
 56	struct drm_encoder *encoder = &output->encoder;
 57	struct drm_crtc *crtc = &output->crtc;
 58	struct vkms_plane *primary, *cursor = NULL;
 59	int ret;
 60	int writeback;
 61	unsigned int n;
 62
 
 
 
 
 
 
 63	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
 64	if (IS_ERR(primary))
 65		return PTR_ERR(primary);
 66
 67	if (vkmsdev->config->overlay) {
 68		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
 69			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
 70			if (ret)
 71				return ret;
 72		}
 73	}
 74
 75	if (vkmsdev->config->cursor) {
 76		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
 77		if (IS_ERR(cursor))
 78			return PTR_ERR(cursor);
 79	}
 80
 
 81	ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
 82	if (ret)
 83		return ret;
 84
 85	ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
 86				 DRM_MODE_CONNECTOR_VIRTUAL);
 87	if (ret) {
 88		DRM_ERROR("Failed to init connector\n");
 89		goto err_connector;
 90	}
 91
 92	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
 93
 94	ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL);
 
 95	if (ret) {
 96		DRM_ERROR("Failed to init encoder\n");
 97		goto err_encoder;
 98	}
 99	encoder->possible_crtcs = 1;
 
 
 
 
100
101	ret = drm_connector_attach_encoder(connector, encoder);
102	if (ret) {
103		DRM_ERROR("Failed to attach connector to encoder\n");
104		goto err_attach;
105	}
106
107	if (vkmsdev->config->writeback) {
108		writeback = vkms_enable_writeback_connector(vkmsdev);
109		if (writeback)
110			DRM_ERROR("Failed to init writeback connector\n");
111	}
112
113	drm_mode_config_reset(dev);
114
115	return 0;
116
117err_attach:
118	drm_encoder_cleanup(encoder);
119
120err_encoder:
121	drm_connector_cleanup(connector);
122
123err_connector:
124	drm_crtc_cleanup(crtc);
125
126	return ret;
127}