Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0+
  2
  3#include "vkms_drv.h"
  4#include <drm/drm_atomic_helper.h>
 
  5#include <drm/drm_probe_helper.h>
  6
  7static void vkms_connector_destroy(struct drm_connector *connector)
  8{
  9	drm_connector_cleanup(connector);
 10}
 11
 12static const struct drm_connector_funcs vkms_connector_funcs = {
 13	.fill_modes = drm_helper_probe_single_connector_modes,
 14	.destroy = vkms_connector_destroy,
 15	.reset = drm_atomic_helper_connector_reset,
 16	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 17	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 18};
 19
 20static const struct drm_encoder_funcs vkms_encoder_funcs = {
 21	.destroy = drm_encoder_cleanup,
 22};
 23
 24static int vkms_conn_get_modes(struct drm_connector *connector)
 25{
 26	int count;
 27
 28	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
 29	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
 30
 31	return count;
 32}
 33
 34static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
 35	.get_modes    = vkms_conn_get_modes,
 36};
 37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38int vkms_output_init(struct vkms_device *vkmsdev, int index)
 39{
 40	struct vkms_output *output = &vkmsdev->output;
 41	struct drm_device *dev = &vkmsdev->drm;
 42	struct drm_connector *connector = &output->connector;
 43	struct drm_encoder *encoder = &output->encoder;
 44	struct drm_crtc *crtc = &output->crtc;
 45	struct drm_plane *primary, *cursor = NULL;
 46	int ret;
 
 
 47
 48	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
 49	if (IS_ERR(primary))
 50		return PTR_ERR(primary);
 51
 52	if (enable_cursor) {
 53		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
 54		if (IS_ERR(cursor)) {
 55			ret = PTR_ERR(cursor);
 56			goto err_cursor;
 57		}
 58	}
 59
 60	ret = vkms_crtc_init(dev, crtc, primary, cursor);
 
 
 
 
 
 
 61	if (ret)
 62		goto err_crtc;
 63
 64	ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
 65				 DRM_MODE_CONNECTOR_VIRTUAL);
 66	if (ret) {
 67		DRM_ERROR("Failed to init connector\n");
 68		goto err_connector;
 69	}
 70
 71	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
 72
 73	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
 74			       DRM_MODE_ENCODER_VIRTUAL, NULL);
 75	if (ret) {
 76		DRM_ERROR("Failed to init encoder\n");
 77		goto err_encoder;
 78	}
 79	encoder->possible_crtcs = 1;
 80
 81	ret = drm_connector_attach_encoder(connector, encoder);
 82	if (ret) {
 83		DRM_ERROR("Failed to attach connector to encoder\n");
 84		goto err_attach;
 85	}
 86
 
 
 
 
 
 
 87	drm_mode_config_reset(dev);
 88
 89	return 0;
 90
 91err_attach:
 92	drm_encoder_cleanup(encoder);
 93
 94err_encoder:
 95	drm_connector_cleanup(connector);
 96
 97err_connector:
 98	drm_crtc_cleanup(crtc);
 99
100err_crtc:
101	if (enable_cursor)
102		drm_plane_cleanup(cursor);
103
104err_cursor:
105	drm_plane_cleanup(primary);
106
107	return ret;
108}
v6.8
  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	count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
 25	drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
 26
 27	return count;
 28}
 29
 30static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
 31	.get_modes    = vkms_conn_get_modes,
 32};
 33
 34static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
 35				  struct drm_crtc *crtc)
 36{
 37	struct vkms_plane *overlay;
 38
 39	overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
 40	if (IS_ERR(overlay))
 41		return PTR_ERR(overlay);
 42
 43	if (!overlay->base.possible_crtcs)
 44		overlay->base.possible_crtcs = drm_crtc_mask(crtc);
 45
 46	return 0;
 47}
 48
 49int vkms_output_init(struct vkms_device *vkmsdev, int index)
 50{
 51	struct vkms_output *output = &vkmsdev->output;
 52	struct drm_device *dev = &vkmsdev->drm;
 53	struct drm_connector *connector = &output->connector;
 54	struct drm_encoder *encoder = &output->encoder;
 55	struct drm_crtc *crtc = &output->crtc;
 56	struct vkms_plane *primary, *cursor = NULL;
 57	int ret;
 58	int writeback;
 59	unsigned int n;
 60
 61	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
 62	if (IS_ERR(primary))
 63		return PTR_ERR(primary);
 64
 65	if (vkmsdev->config->overlay) {
 66		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
 67			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
 68			if (ret)
 69				return ret;
 70		}
 71	}
 72
 73	if (vkmsdev->config->cursor) {
 74		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
 75		if (IS_ERR(cursor))
 76			return PTR_ERR(cursor);
 77	}
 78
 79	ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
 80	if (ret)
 81		return ret;
 82
 83	ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
 84				 DRM_MODE_CONNECTOR_VIRTUAL);
 85	if (ret) {
 86		DRM_ERROR("Failed to init connector\n");
 87		goto err_connector;
 88	}
 89
 90	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
 91
 92	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
 93			       DRM_MODE_ENCODER_VIRTUAL, NULL);
 94	if (ret) {
 95		DRM_ERROR("Failed to init encoder\n");
 96		goto err_encoder;
 97	}
 98	encoder->possible_crtcs = 1;
 99
100	ret = drm_connector_attach_encoder(connector, encoder);
101	if (ret) {
102		DRM_ERROR("Failed to attach connector to encoder\n");
103		goto err_attach;
104	}
105
106	if (vkmsdev->config->writeback) {
107		writeback = vkms_enable_writeback_connector(vkmsdev);
108		if (writeback)
109			DRM_ERROR("Failed to init writeback connector\n");
110	}
111
112	drm_mode_config_reset(dev);
113
114	return 0;
115
116err_attach:
117	drm_encoder_cleanup(encoder);
118
119err_encoder:
120	drm_connector_cleanup(connector);
121
122err_connector:
123	drm_crtc_cleanup(crtc);
 
 
 
 
 
 
 
124
125	return ret;
126}