0005-config-udev-split-device_added-for-further-work.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. From 13adad70608f0936a49f640904698386d5f6580f Mon Sep 17 00:00:00 2001
  2. From: Alex Suykov <alex.suykov@gmail.com>
  3. Date: Sun, 21 Jan 2018 03:38:02 +0200
  4. Subject: [PATCH xserver 5/8] config/udev: split device_added for further work
  5. ---
  6. config/udev.c | 173 ++++++++++++++++++++++++++++++----------------------------
  7. 1 file changed, 91 insertions(+), 82 deletions(-)
  8. diff --git a/config/udev.c b/config/udev.c
  9. index c450ac39a..1a6021262 100644
  10. --- a/config/udev.c
  11. +++ b/config/udev.c
  12. @@ -88,57 +88,83 @@ check_seat(struct udev_device *udev_device)
  13. }
  14. static void
  15. -device_added(struct udev_device *udev_device)
  16. +device_added_drm(struct udev_device *udev_device,
  17. + const char* path, const char* syspath)
  18. {
  19. - const char *path, *name = NULL;
  20. - char *config_info = NULL;
  21. - const char *syspath;
  22. - const char *tags_prop;
  23. - const char *key, *value, *tmp;
  24. - InputOption *input_options;
  25. - InputAttributes attrs = { };
  26. - DeviceIntPtr dev = NULL;
  27. - struct udev_list_entry *set, *entry;
  28. - struct udev_device *parent;
  29. - int rc;
  30. - dev_t devnum;
  31. + const char *sysname = udev_device_get_sysname(udev_device);
  32. + dev_t devnum = udev_device_get_devnum(udev_device);
  33. - path = udev_device_get_devnode(udev_device);
  34. -
  35. - syspath = udev_device_get_syspath(udev_device);
  36. -
  37. - if (!path || !syspath)
  38. + if (strncmp(sysname, "card", 4) != 0)
  39. return;
  40. - if (!check_seat(udev_device))
  41. + /* Check for devices already added through xf86platformProbe() */
  42. + if (xf86_find_platform_device_by_devnum(major(devnum), minor(devnum)))
  43. return;
  44. - devnum = udev_device_get_devnum(udev_device);
  45. + LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
  46. -#ifdef CONFIG_UDEV_KMS
  47. - if (!strcmp(udev_device_get_subsystem(udev_device), "drm")) {
  48. - const char *sysname = udev_device_get_sysname(udev_device);
  49. -
  50. - if (strncmp(sysname, "card", 4) != 0)
  51. - return;
  52. + config_udev_odev_setup_attribs(path, syspath, major(devnum),
  53. + minor(devnum), NewGPUDeviceRequest);
  54. +}
  55. - /* Check for devices already added through xf86platformProbe() */
  56. - if (xf86_find_platform_device_by_devnum(major(devnum), minor(devnum)))
  57. - return;
  58. +static const char*
  59. +query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  60. +{
  61. + const char *ppath = udev_device_get_devnode(parent);
  62. + const char *product = udev_device_get_property_value(parent, "PRODUCT");
  63. + const char *pnp_id = udev_device_get_sysattr_value(parent, "id");
  64. + unsigned int vendor, model;
  65. + const char* name = NULL;
  66. - LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
  67. + if ((name = udev_device_get_sysattr_value(parent, "name")))
  68. + LOG_SYSATTR(ppath, "name", name);
  69. + else if((name = udev_device_get_property_value(parent, "NAME")))
  70. + LOG_PROPERTY(ppath, "NAME", name);
  71. + if (name)
  72. + attrs->product = strdup(name);
  73. +
  74. + /* construct USB ID in lowercase hex - "0000:ffff" */
  75. + if (product && sscanf(product, "%*x/%4x/%4x/%*x", &vendor, &model) == 2) {
  76. + char *usb_id;
  77. + if (asprintf(&usb_id, "%04x:%04x", vendor, model) == -1)
  78. + usb_id = NULL;
  79. + else
  80. + LOG_PROPERTY(ppath, "PRODUCT", product);
  81. + attrs->usb_id = usb_id;
  82. + }
  83. - config_udev_odev_setup_attribs(path, syspath, major(devnum),
  84. - minor(devnum), NewGPUDeviceRequest);
  85. - return;
  86. + while ((parent = udev_device_get_parent(parent))) {
  87. + if ((pnp_id = udev_device_get_sysattr_value(parent, "id"))) {
  88. + attrs->pnp_id = strdup(pnp_id);
  89. + ppath = udev_device_get_devnode(parent);
  90. + LOG_SYSATTR(ppath, "id", pnp_id);
  91. + break;
  92. + }
  93. }
  94. -#endif
  95. +
  96. + return name;
  97. +}
  98. +
  99. +static void
  100. +device_added_input(struct udev_device *udev_device,
  101. + const char* path, const char* syspath)
  102. +{
  103. + const char *name = NULL;
  104. + char *config_info = NULL;
  105. + const char *tags_prop;
  106. + const char *key, *value, *tmp;
  107. + InputOption *input_options;
  108. + InputAttributes attrs = { };
  109. + DeviceIntPtr dev = NULL;
  110. + struct udev_list_entry *set, *entry;
  111. + int rc;
  112. +
  113. + struct udev_device *parent = udev_device_get_parent(udev_device);
  114. + dev_t devnum = udev_device_get_devnum(udev_device);
  115. value = udev_device_get_property_value(udev_device, "ID_INPUT");
  116. if (value && !strcmp(value, "0")) {
  117. - LogMessageVerb(X_INFO, 10,
  118. - "config/udev: ignoring device %s without "
  119. - "property ID_INPUT set\n", path);
  120. + LogMessageVerb(X_INFO, 10, "config/udev: ignoring device %s", path);
  121. return;
  122. }
  123. @@ -146,47 +172,11 @@ device_added(struct udev_device *udev_device)
  124. if (!input_options)
  125. return;
  126. - parent = udev_device_get_parent(udev_device);
  127. - if (parent) {
  128. - const char *ppath = udev_device_get_devnode(parent);
  129. - const char *product = udev_device_get_property_value(parent, "PRODUCT");
  130. - const char *pnp_id = udev_device_get_sysattr_value(parent, "id");
  131. - unsigned int usb_vendor, usb_model;
  132. -
  133. - name = udev_device_get_sysattr_value(parent, "name");
  134. - LOG_SYSATTR(ppath, "name", name);
  135. - if (!name) {
  136. - name = udev_device_get_property_value(parent, "NAME");
  137. - LOG_PROPERTY(ppath, "NAME", name);
  138. - }
  139. -
  140. - /* construct USB ID in lowercase hex - "0000:ffff" */
  141. - if (product &&
  142. - sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
  143. - char *usb_id;
  144. - if (asprintf(&usb_id, "%04x:%04x", usb_vendor, usb_model)
  145. - == -1)
  146. - usb_id = NULL;
  147. - else
  148. - LOG_PROPERTY(ppath, "PRODUCT", product);
  149. - attrs.usb_id = usb_id;
  150. - }
  151. -
  152. - while (!pnp_id && (parent = udev_device_get_parent(parent))) {
  153. - pnp_id = udev_device_get_sysattr_value(parent, "id");
  154. - if (!pnp_id)
  155. - continue;
  156. -
  157. - attrs.pnp_id = strdup(pnp_id);
  158. - ppath = udev_device_get_devnode(parent);
  159. - LOG_SYSATTR(ppath, "id", pnp_id);
  160. - }
  161. -
  162. - }
  163. + if (parent)
  164. + name = query_input_name_ids(parent, &attrs);
  165. if (!name)
  166. name = "(unnamed)";
  167. - else
  168. - attrs.product = strdup(name);
  169. +
  170. input_options = input_option_new(input_options, "name", name);
  171. input_options = input_option_new(input_options, "path", path);
  172. input_options = input_option_new(input_options, "device", path);
  173. @@ -205,8 +195,7 @@ device_added(struct udev_device *udev_device)
  174. }
  175. if (device_is_duplicate(config_info)) {
  176. - LogMessage(X_WARNING, "config/udev: device %s already added. "
  177. - "Ignoring.\n", name);
  178. + LogMessage(X_WARNING, "config/udev: device %s already added. ", name);
  179. goto unwind;
  180. }
  181. @@ -277,11 +266,12 @@ device_added(struct udev_device *udev_device)
  182. if (ServerIsNotSeat0())
  183. input_options = input_option_new(input_options, "GrabDevice", "on");
  184. - LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
  185. - name, path);
  186. rc = NewInputDeviceRequest(input_options, &attrs, &dev);
  187. +
  188. if (rc != Success)
  189. - goto unwind;
  190. + LogMessage(X_INFO, "config/udev: cannot add %s (%s)\n", name, path);
  191. + else
  192. + LogMessage(X_INFO, "config/udev: adding %s (%s)\n", name, path);
  193. unwind:
  194. free(config_info);
  195. @@ -301,8 +291,27 @@ device_added(struct udev_device *udev_device)
  196. }
  197. free(attrs.tags);
  198. }
  199. +}
  200. - return;
  201. +static void
  202. +device_added(struct udev_device *udev_device)
  203. +{
  204. + const char* path = udev_device_get_devnode(udev_device);
  205. + const char* syspath = udev_device_get_syspath(udev_device);
  206. + const char* subsystem = udev_device_get_subsystem(udev_device);
  207. +
  208. + if (!subsystem || !path || !syspath)
  209. + return;
  210. +
  211. + if (!check_seat(udev_device))
  212. + return;
  213. +
  214. +#ifdef CONFIG_UDEV_KMS
  215. + if (!strcmp(subsystem, "drm"))
  216. + return device_added_drm(udev_device, path, syspath);
  217. +#endif
  218. + if (!strcmp(subsystem, "input"))
  219. + return device_added_input(udev_device, path, syspath);
  220. }
  221. static void
  222. --
  223. 2.16.1