xserver-autobind-hotplug.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. From 471289fa1dc359555ceed6302f7d9605ab6be3ea Mon Sep 17 00:00:00 2001
  2. From: Dave Airlie <airlied@redhat.com>
  3. Date: Mon, 2 Apr 2018 16:49:02 -0400
  4. Subject: [PATCH] autobind GPUs to the screen
  5. This is a modified version of a patch we've been carry-ing in Fedora and
  6. RHEL for years now. This patch automatically adds secondary GPUs to the
  7. master as output sink / offload source making e.g. the use of
  8. slave-outputs just work, with requiring the user to manually run
  9. "xrandr --setprovideroutputsource" before he can hookup an external
  10. monitor to his hybrid graphics laptop.
  11. There is one problem with this patch, which is why it was not upstreamed
  12. before. What to do when a secondary GPU gets detected really is a policy
  13. decission (e.g. one may want to autobind PCI GPUs but not USB ones) and
  14. as such should be under control of the Desktop Environment.
  15. Unconditionally adding autobinding support to the xserver will result
  16. in races between the DE dealing with the hotplug of a secondary GPU
  17. and the server itself dealing with it.
  18. However we've waited for years for any Desktop Environments to actually
  19. start doing some sort of autoconfiguration of secondary GPUs and there
  20. is still not a single DE dealing with this, so I believe that it is
  21. time to upstream this now.
  22. To avoid potential future problems if any DEs get support for doing
  23. secondary GPU configuration themselves, the new autobind functionality
  24. is made optional. Since no DEs currently support doing this themselves it
  25. is enabled by default. When DEs grow support for doing this themselves
  26. they can disable the servers autobinding through the servers cmdline or a
  27. xorg.conf snippet.
  28. Signed-off-by: Dave Airlie <airlied@gmail.com>
  29. [hdegoede@redhat.com: Make configurable, fix with nvidia, submit upstream]
  30. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  31. ---
  32. hw/xfree86/common/xf86Config.c | 19 +++++++++++++++++++
  33. hw/xfree86/common/xf86Globals.c | 2 ++
  34. hw/xfree86/common/xf86Init.c | 20 ++++++++++++++++++++
  35. hw/xfree86/common/xf86Priv.h | 1 +
  36. hw/xfree86/common/xf86Privstr.h | 1 +
  37. hw/xfree86/common/xf86platformBus.c | 4 ++++
  38. hw/xfree86/man/Xorg.man | 7 +++++++
  39. hw/xfree86/man/xorg.conf.man | 6 ++++++
  40. randr/randrstr.h | 3 +++
  41. randr/rrprovider.c | 22 ++++++++++++++++++++++
  42. 10 files changed, 85 insertions(+)
  43. diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
  44. index 2c1d335..d7d7c2e 100644
  45. --- a/hw/xfree86/common/xf86Config.c
  46. +++ b/hw/xfree86/common/xf86Config.c
  47. @@ -643,6 +643,7 @@ typedef enum {
  48. FLAG_DRI2,
  49. FLAG_USE_SIGIO,
  50. FLAG_AUTO_ADD_GPU,
  51. + FLAG_AUTO_BIND_GPU,
  52. FLAG_MAX_CLIENTS,
  53. FLAG_IGLX,
  54. FLAG_DEBUG,
  55. @@ -699,6 +700,8 @@ static OptionInfoRec FlagOptions[] = {
  56. {0}, FALSE},
  57. {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN,
  58. {0}, FALSE},
  59. + {FLAG_AUTO_BIND_GPU, "AutoBindGPU", OPTV_BOOLEAN,
  60. + {0}, FALSE},
  61. {FLAG_MAX_CLIENTS, "MaxClients", OPTV_INTEGER,
  62. {0}, FALSE },
  63. {FLAG_IGLX, "IndirectGLX", OPTV_BOOLEAN,
  64. @@ -779,6 +782,22 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
  65. }
  66. xf86Msg(from, "%sutomatically adding GPU devices\n",
  67. xf86Info.autoAddGPU ? "A" : "Not a");
  68. +
  69. + if (xf86AutoBindGPUDisabled) {
  70. + xf86Info.autoBindGPU = FALSE;
  71. + from = X_CMDLINE;
  72. + }
  73. + else if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_BIND_GPU)) {
  74. + xf86GetOptValBool(FlagOptions, FLAG_AUTO_BIND_GPU,
  75. + &xf86Info.autoBindGPU);
  76. + from = X_CONFIG;
  77. + }
  78. + else {
  79. + from = X_DEFAULT;
  80. + }
  81. + xf86Msg(from, "%sutomatically binding GPU devices\n",
  82. + xf86Info.autoBindGPU ? "A" : "Not a");
  83. +
  84. /*
  85. * Set things up based on the config file information. Some of these
  86. * settings may be overridden later when the command line options are
  87. diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
  88. index e890f05..7b27b4c 100644
  89. --- a/hw/xfree86/common/xf86Globals.c
  90. +++ b/hw/xfree86/common/xf86Globals.c
  91. @@ -131,6 +131,7 @@ xf86InfoRec xf86Info = {
  92. #else
  93. .autoAddGPU = FALSE,
  94. #endif
  95. + .autoBindGPU = TRUE,
  96. };
  97. const char *xf86ConfigFile = NULL;
  98. @@ -191,6 +192,7 @@ Bool xf86FlipPixels = FALSE;
  99. Gamma xf86Gamma = { 0.0, 0.0, 0.0 };
  100. Bool xf86AllowMouseOpenFail = FALSE;
  101. +Bool xf86AutoBindGPUDisabled = FALSE;
  102. #ifdef XF86VIDMODE
  103. Bool xf86VidModeDisabled = FALSE;
  104. diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
  105. index ea42ec9..ec255b6 100644
  106. --- a/hw/xfree86/common/xf86Init.c
  107. +++ b/hw/xfree86/common/xf86Init.c
  108. @@ -76,6 +76,7 @@
  109. #include "xf86DDC.h"
  110. #include "xf86Xinput.h"
  111. #include "xf86InPriv.h"
  112. +#include "xf86Crtc.h"
  113. #include "picturestr.h"
  114. #include "randrstr.h"
  115. #include "glxvndabi.h"
  116. @@ -237,6 +238,19 @@ xf86PrivsElevated(void)
  117. return PrivsElevated();
  118. }
  119. +static void
  120. +xf86AutoConfigOutputDevices(void)
  121. +{
  122. + int i;
  123. +
  124. + if (!xf86Info.autoBindGPU)
  125. + return;
  126. +
  127. + for (i = 0; i < xf86NumGPUScreens; i++)
  128. + RRProviderAutoConfigGpuScreen(xf86ScrnToScreen(xf86GPUScreens[i]),
  129. + xf86ScrnToScreen(xf86Screens[0]));
  130. +}
  131. +
  132. static void
  133. TrapSignals(void)
  134. {
  135. @@ -770,6 +784,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
  136. for (i = 0; i < xf86NumGPUScreens; i++)
  137. AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
  138. + xf86AutoConfigOutputDevices();
  139. +
  140. xf86VGAarbiterWrapFunctions();
  141. if (sigio_blocked)
  142. input_unlock();
  143. @@ -1278,6 +1294,10 @@ ddxProcessArgument(int argc, char **argv, int i)
  144. xf86Info.iglxFrom = X_CMDLINE;
  145. return 0;
  146. }
  147. + if (!strcmp(argv[i], "-noautoBindGPU")) {
  148. + xf86AutoBindGPUDisabled = TRUE;
  149. + return 1;
  150. + }
  151. /* OS-specific processing */
  152. return xf86ProcessArgument(argc, argv, i);
  153. diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
  154. index 4fe2b5f..6566622 100644
  155. --- a/hw/xfree86/common/xf86Priv.h
  156. +++ b/hw/xfree86/common/xf86Priv.h
  157. @@ -46,6 +46,7 @@
  158. extern _X_EXPORT const char *xf86ConfigFile;
  159. extern _X_EXPORT const char *xf86ConfigDir;
  160. extern _X_EXPORT Bool xf86AllowMouseOpenFail;
  161. +extern _X_EXPORT Bool xf86AutoBindGPUDisabled;
  162. #ifdef XF86VIDMODE
  163. extern _X_EXPORT Bool xf86VidModeDisabled;
  164. diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h
  165. index 21c2e1f..6c71863 100644
  166. --- a/hw/xfree86/common/xf86Privstr.h
  167. +++ b/hw/xfree86/common/xf86Privstr.h
  168. @@ -98,6 +98,7 @@ typedef struct {
  169. Bool autoAddGPU;
  170. const char *debug;
  171. + Bool autoBindGPU;
  172. } xf86InfoRec, *xf86InfoPtr;
  173. /* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */
  174. diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
  175. index cef47da..913a324 100644
  176. --- a/hw/xfree86/common/xf86platformBus.c
  177. +++ b/hw/xfree86/common/xf86platformBus.c
  178. @@ -49,6 +49,7 @@
  179. #include "Pci.h"
  180. #include "xf86platformBus.h"
  181. #include "xf86Config.h"
  182. +#include "xf86Crtc.h"
  183. #include "randrstr.h"
  184. int platformSlotClaimed;
  185. @@ -665,6 +666,9 @@ xf86platformAddDevice(int index)
  186. }
  187. /* attach unbound to 0 protocol screen */
  188. AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
  189. + if (xf86Info.autoBindGPU)
  190. + RRProviderAutoConfigGpuScreen(xf86ScrnToScreen(xf86GPUScreens[i]),
  191. + xf86ScrnToScreen(xf86Screens[0]));
  192. RRResourcesChanged(xf86Screens[0]->pScreen);
  193. RRTellChanged(xf86Screens[0]->pScreen);
  194. diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man
  195. index 13a9dc3..745f986 100644
  196. --- a/hw/xfree86/man/Xorg.man
  197. +++ b/hw/xfree86/man/Xorg.man
  198. @@ -283,6 +283,13 @@ is a comma separated list of directories to search for
  199. server modules. This option is only available when the server is run
  200. as root (i.e, with real-uid 0).
  201. .TP 8
  202. +.B \-noautoBindGPU
  203. +Disable automatically setting secondary GPUs up as output sinks and offload
  204. +sources. This is equivalent to setting the
  205. +.B AutoBindGPU
  206. +xorg.conf(__filemansuffix__) file option. To
  207. +.B false.
  208. +.TP 8
  209. .B \-nosilk
  210. Disable Silken Mouse support.
  211. .TP 8
  212. diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
  213. index 9589262..8d51e06 100644
  214. --- a/hw/xfree86/man/xorg.conf.man
  215. +++ b/hw/xfree86/man/xorg.conf.man
  216. @@ -672,6 +672,12 @@ Enabled by default.
  217. If this option is disabled, then no GPU devices will be added from the udev
  218. backend. Enabled by default. (May need to be disabled to setup Xinerama).
  219. .TP 7
  220. +.BI "Option \*qAutoBindGPU\*q \*q" boolean \*q
  221. +If enabled then secondary GPUs will be automatically set up as output-sinks and
  222. +offload-sources. Making e.g. laptop outputs connected only to the secondary
  223. +GPU directly available for use without needing to run
  224. +"xrandr --setprovideroutputsource". Enabled by default.
  225. +.TP 7
  226. .BI "Option \*qLog\*q \*q" string \*q
  227. This option controls whether the log is flushed and/or synced to disk after
  228. each message.
  229. diff --git a/randr/randrstr.h b/randr/randrstr.h
  230. index f94174b..092d726 100644
  231. --- a/randr/randrstr.h
  232. +++ b/randr/randrstr.h
  233. @@ -1039,6 +1039,9 @@ RRProviderLookup(XID id, RRProviderPtr *provider_p);
  234. extern _X_EXPORT void
  235. RRDeliverProviderEvent(ClientPtr client, WindowPtr pWin, RRProviderPtr provider);
  236. +extern _X_EXPORT void
  237. +RRProviderAutoConfigGpuScreen(ScreenPtr pScreen, ScreenPtr masterScreen);
  238. +
  239. /* rrproviderproperty.c */
  240. extern _X_EXPORT void
  241. diff --git a/randr/rrprovider.c b/randr/rrprovider.c
  242. index e4bc2bf..e04c18f 100644
  243. --- a/randr/rrprovider.c
  244. +++ b/randr/rrprovider.c
  245. @@ -485,3 +485,25 @@ RRDeliverProviderEvent(ClientPtr client, WindowPtr pWin, RRProviderPtr provider)
  246. WriteEventsToClient(client, 1, (xEvent *) &pe);
  247. }
  248. +
  249. +void
  250. +RRProviderAutoConfigGpuScreen(ScreenPtr pScreen, ScreenPtr masterScreen)
  251. +{
  252. + rrScrPrivPtr pScrPriv = rrGetScrPriv(pScreen);
  253. + rrScrPrivPtr masterPriv = rrGetScrPriv(masterScreen);
  254. + RRProviderPtr provider = pScrPriv->provider;
  255. + RRProviderPtr master_provider = masterPriv->provider;
  256. +
  257. + if (!provider || !master_provider)
  258. + return;
  259. +
  260. + if ((provider->capabilities & RR_Capability_SinkOutput) &&
  261. + (master_provider->capabilities & RR_Capability_SourceOutput)) {
  262. + pScrPriv->rrProviderSetOutputSource(pScreen, provider, master_provider);
  263. + RRInitPrimeSyncProps(pScreen);
  264. + }
  265. +
  266. + if ((provider->capabilities & RR_Capability_SourceOffload) &&
  267. + (master_provider->capabilities & RR_Capability_SinkOffload))
  268. + pScrPriv->rrProviderSetOffloadSink(pScreen, provider, master_provider);
  269. +}
  270. --
  271. 2.16.2