Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-03 Thread Dave Airlie
On Mon, Jul 2, 2012 at 10:31 PM, Keith Packard kei...@keithp.com wrote:

 Dave Airlie airl...@gmail.com writes:
 No they can all do it, just haven't the code to do the picking yet of
 a driver, and since
 USB is really the only thing I can hotplug so far.

 It seems like more driver ABI changes would be required to let them know
 about the new device then?

No the drivers will just have to be able to accept the udev entry
point with the GPU screen flag.

no further changes needed, granted I've no idea what drivers other
than modesetting will ever do proper hotplug,
I suppose I could get a real PCIE dock at some point and hotplug
radeon or nouveau, but there is a lot of work
kernel side before we could even start on the userspace drivers.

with dual-gpu machines even if we power off the discrete we never
unplug it, its all abstracted in the kernel.

Dave.
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-03 Thread Keith Packard
Dave Airlie airl...@gmail.com writes:

 no further changes needed, granted I've no idea what drivers other
 than modesetting will ever do proper hotplug,
 I suppose I could get a real PCIE dock at some point and hotplug
 radeon or nouveau, but there is a lot of work
 kernel side before we could even start on the userspace drivers.

Definitely an adventure for a future time (where we imagine things like
Thunder Bolt monitors with integrated GPUs).

 with dual-gpu machines even if we power off the discrete we never
 unplug it, its all abstracted in the kernel.

Cool.

If we aren't dealing with hot-plug drivers (aside from modesetting),
then perhaps the privates issue is far less daunting than we feared.
The modesetting driver uses no privates, and so we need only get the
full set of privates allocated from non-hotplug drivers at server
startup time, leaving the current private allocation system in place.

-- 
keith.pack...@intel.com


pgpey4rVPkATC.pgp
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-03 Thread Keith Packard
Dave Airlie airl...@gmail.com writes:

 It uses one private in the prime code for pixmaps, as it has to store
 the framebuffer id in it for slave scanout pixmap.

Ok, so it's only touching pixmaps at least.  If we add privates API to
allocate private screen space, then we can change the modesetting driver
to use that and it will then re-use the same space at each
re-load. Other drivers could migrate to using the new API as they liked,
but not doing so wouldn't hurt this project any.

-- 
keith.pack...@intel.com


pgpWIq21XNPNQ.pgp
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

[PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-02 Thread Dave Airlie
From: Dave Airlie airl...@redhat.com

This provides add/remove support for platform devices at xfree86 ddx level.

v2: cleanup properly if no driver found.

Signed-off-by: Dave Airlie airl...@redhat.com
---
 hw/xfree86/common/xf86platformBus.c|   99 
 hw/xfree86/common/xf86platformBus.h|5 ++
 hw/xfree86/os-support/linux/lnx_platform.c |   49 ++
 3 files changed, 153 insertions(+)

diff --git a/hw/xfree86/common/xf86platformBus.c 
b/hw/xfree86/common/xf86platformBus.c
index 50b7636..fa3edfd 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -376,4 +376,103 @@ xf86platformProbeDev(DriverPtr drvp)
 return foundScreen;
 }
 
+int
+xf86platformAddDevice(int index)
+{
+int i, old_screens, scr_index;
+DriverPtr drvp = NULL;
+int entity;
+screenLayoutPtr layout;
+
+for (i = 0; i  xf86NumDrivers; i++) {
+if (!xf86DriverList[i])
+continue;
+
+if (!strcmp(xf86DriverList[i]-driverName, modesetting)) {
+drvp = xf86DriverList[i];
+break;
+}
+}
+if (i == xf86NumDrivers)
+return -1;
+
+old_screens = xf86NumGPUScreens;
+entity = xf86ClaimPlatformSlot(xf86_platform_devices[index],
+   drvp, 0, 0, 0);
+if (!drvp-platformProbe(drvp, entity, PLATFORM_PROBE_GPU_SCREEN, 
xf86_platform_devices[index], 0)) {
+xf86UnclaimPlatformSlot(xf86_platform_devices[index], NULL);
+}
+if (old_screens == xf86NumGPUScreens)
+return -1;
+i = old_screens;
+
+for (layout = xf86ConfigLayout.screens; layout-screen != NULL;
+ layout++) {
+xf86GPUScreens[i]-confScreen = layout-screen;
+break;
+}
+
+if (xf86GPUScreens[i]-PreInit 
+xf86GPUScreens[i]-PreInit(xf86GPUScreens[i], 0))
+xf86GPUScreens[i]-configured = TRUE; 
+
+if (!xf86GPUScreens[i]-configured) {
+ErrorF(hotplugged device %d didn't configure\n, i);
+xf86DeleteScreen(xf86GPUScreens[i]);
+return -1;
+}
+
+   scr_index = AddGPUScreen(xf86GPUScreens[i]-ScreenInit, 0, NULL);
+   
+   dixSetPrivate(xf86GPUScreens[i]-pScreen-devPrivates,
+ xf86ScreenKey, xf86GPUScreens[i]);
+
+   CreateScratchPixmapsForScreen(xf86GPUScreens[i]-pScreen);
+  
+   return 0;
+}
+
+void
+xf86platformRemoveDevice(int index)
+{
+EntityPtr entity;
+int ent_num, i, j;
+Bool found;
+
+for (ent_num = 0; ent_num  xf86NumEntities; ent_num++) {
+entity = xf86Entities[ent_num];
+if (entity-bus.type == BUS_PLATFORM 
+entity-bus.id.plat == xf86_platform_devices[index])
+break;
+}
+if (ent_num == xf86NumEntities)
+goto out;
+
+found = FALSE;
+for (i = 0; i  xf86NumGPUScreens; i++) {
+for (j = 0; j  xf86GPUScreens[i]-numEntities; j++)
+if (xf86GPUScreens[i]-entityList[j] == ent_num) {
+found = TRUE;
+break;
+}
+if (found)
+break;
+}
+if (!found) {
+ErrorF(failed to find screen to remove\n);
+goto out;
+}
+
+xf86GPUScreens[i]-pScreen-CloseScreen(xf86GPUScreens[i]-pScreen);
+
+RemoveGPUScreen(xf86GPUScreens[i]-pScreen);
+xf86DeleteScreen(xf86GPUScreens[i]);
+
+xf86UnclaimPlatformSlot(xf86_platform_devices[index], NULL);
+
+xf86_remove_platform_device(index);
+
+ out:
+return;
+}
 #endif
diff --git a/hw/xfree86/common/xf86platformBus.h 
b/hw/xfree86/common/xf86platformBus.h
index 15a3022..49afc24 100644
--- a/hw/xfree86/common/xf86platformBus.h
+++ b/hw/xfree86/common/xf86platformBus.h
@@ -47,6 +47,11 @@ xf86_remove_platform_device(int dev_index);
 extern Bool
 xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_str);
 
+extern int
+xf86platformAddDevice(int index);
+extern void
+xf86platformRemoveDevice(int index);
+
 extern _X_EXPORT char *
 xf86_get_platform_device_attrib(struct xf86_platform_device *device, int 
attrib_id);
 extern _X_EXPORT Bool
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c 
b/hw/xfree86/os-support/linux/lnx_platform.c
index 9c63ee5..76f5583 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -15,6 +15,8 @@
 #include xf86platformBus.h
 #include xf86Bus.h
 
+#include hotplug.h
+
 static Bool
 get_drm_info(struct OdevAttributes *attribs, char *path)
 {
@@ -127,4 +129,51 @@ out_free:
 config_odev_free_attribute_list(attribs);
 }
 
+void NewGPUDeviceRequest(struct OdevAttributes *attribs)
+{
+int old_num = xf86_num_platform_devices;
+int ret;
+xf86PlatformDeviceProbe(attribs);
+
+if (old_num == xf86_num_platform_devices)
+return;
+
+ret = xf86platformAddDevice(xf86_num_platform_devices-1);
+if (ret == -1)
+xf86_remove_platform_device(xf86_num_platform_devices-1);
+
+ErrorF(xf86: found device %d\n, 

Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-02 Thread Keith Packard
Dave Airlie airl...@gmail.com writes:

 +int
 +xf86platformAddDevice(int index)
 +{
 +int i, old_screens, scr_index;
 +DriverPtr drvp = NULL;
 +int entity;
 +screenLayoutPtr layout;
 +
 +for (i = 0; i  xf86NumDrivers; i++) {
 +if (!xf86DriverList[i])
 +continue;
 +
 +if (!strcmp(xf86DriverList[i]-driverName, modesetting)) {
 +drvp = xf86DriverList[i];
 +break;
 +}

Am I right in assuming that this means that only the 'modesetting'
driver can have hotplugged devices? Would we need changes in the driver
ABI to make this more general?

-- 
keith.pack...@intel.com


pgpwu7NGu1QGt.pgp
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-02 Thread Dave Airlie
On Mon, Jul 2, 2012 at 7:37 PM, Keith Packard kei...@keithp.com wrote:
 Dave Airlie airl...@gmail.com writes:

 +int
 +xf86platformAddDevice(int index)
 +{
 +int i, old_screens, scr_index;
 +DriverPtr drvp = NULL;
 +int entity;
 +screenLayoutPtr layout;
 +
 +for (i = 0; i  xf86NumDrivers; i++) {
 +if (!xf86DriverList[i])
 +continue;
 +
 +if (!strcmp(xf86DriverList[i]-driverName, modesetting)) {
 +drvp = xf86DriverList[i];
 +break;
 +}

 Am I right in assuming that this means that only the 'modesetting'
 driver can have hotplugged devices? Would we need changes in the driver
 ABI to make this more general?

No they can all do it, just haven't the code to do the picking yet of
a driver, and since
USB is really the only thing I can hotplug so far.

the udev interface is fine for it to work.

Dave.
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH 08/36] xfree86: add platform bus hotplug support (v2)

2012-07-02 Thread Keith Packard

Dave Airlie airl...@gmail.com writes:
 No they can all do it, just haven't the code to do the picking yet of
 a driver, and since
 USB is really the only thing I can hotplug so far.

It seems like more driver ABI changes would be required to let them know
about the new device then?

 the udev interface is fine for it to work.

Cool.

-- 
keith.pack...@intel.com


pgpyF2QdyyrGk.pgp
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel