1 /* $NetBSD: xen_drm_front_cfg.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $ */
2
3 // SPDX-License-Identifier: GPL-2.0 OR MIT
4
5 /*
6 * Xen para-virtual DRM device
7 *
8 * Copyright (C) 2016-2018 EPAM Systems Inc.
9 *
10 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
11 */
12
13 #include <sys/cdefs.h>
14 __KERNEL_RCSID(0, "$NetBSD: xen_drm_front_cfg.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $");
15
16 #include <linux/device.h>
17
18 #include <drm/drm_print.h>
19
20 #include <xen/interface/io/displif.h>
21 #include <xen/xenbus.h>
22
23 #include "xen_drm_front.h"
24 #include "xen_drm_front_cfg.h"
25
cfg_connector(struct xen_drm_front_info * front_info,struct xen_drm_front_cfg_connector * connector,const char * path,int index)26 static int cfg_connector(struct xen_drm_front_info *front_info,
27 struct xen_drm_front_cfg_connector *connector,
28 const char *path, int index)
29 {
30 char *connector_path;
31
32 connector_path = devm_kasprintf(&front_info->xb_dev->dev,
33 GFP_KERNEL, "%s/%d", path, index);
34 if (!connector_path)
35 return -ENOMEM;
36
37 if (xenbus_scanf(XBT_NIL, connector_path, XENDISPL_FIELD_RESOLUTION,
38 "%d" XENDISPL_RESOLUTION_SEPARATOR "%d",
39 &connector->width, &connector->height) < 0) {
40 /* either no entry configured or wrong resolution set */
41 connector->width = 0;
42 connector->height = 0;
43 return -EINVAL;
44 }
45
46 connector->xenstore_path = connector_path;
47
48 DRM_INFO("Connector %s: resolution %dx%d\n",
49 connector_path, connector->width, connector->height);
50 return 0;
51 }
52
xen_drm_front_cfg_card(struct xen_drm_front_info * front_info,struct xen_drm_front_cfg * cfg)53 int xen_drm_front_cfg_card(struct xen_drm_front_info *front_info,
54 struct xen_drm_front_cfg *cfg)
55 {
56 struct xenbus_device *xb_dev = front_info->xb_dev;
57 int ret, i;
58
59 if (xenbus_read_unsigned(front_info->xb_dev->nodename,
60 XENDISPL_FIELD_BE_ALLOC, 0)) {
61 DRM_INFO("Backend can provide display buffers\n");
62 cfg->be_alloc = true;
63 }
64
65 cfg->num_connectors = 0;
66 for (i = 0; i < ARRAY_SIZE(cfg->connectors); i++) {
67 ret = cfg_connector(front_info, &cfg->connectors[i],
68 xb_dev->nodename, i);
69 if (ret < 0)
70 break;
71 cfg->num_connectors++;
72 }
73
74 if (!cfg->num_connectors) {
75 DRM_ERROR("No connector(s) configured at %s\n",
76 xb_dev->nodename);
77 return -ENODEV;
78 }
79
80 return 0;
81 }
82
83