xen_drm_front_cfg.c 1.8 KB

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