From 5d0e6e39764beafb347415e694ce7fc2093122e5 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Fri, 2 Nov 2012 01:45:33 +0000 Subject: [PATCH 1/4] nouveau: Remove unneeded xf86GetEntityInfo() Retrieving the whole entity information is not needed as we only use the index - stored already in entity_num Signed-off-by: Emil Velikov --- src/nv_driver.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/nv_driver.c b/src/nv_driver.c index 9b5b9d6..c885e73 100644 --- a/src/nv_driver.c +++ b/src/nv_driver.c @@ -261,7 +261,6 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, { -1, -1, NULL } }; struct nouveau_device *dev = NULL; - EntityInfoPtr pEnt = NULL; ScrnInfoPtr pScrn = NULL; drmVersion *version; int chipset, ret; @@ -340,10 +339,8 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, pScrn->FreeScreen = NVFreeScreen; xf86SetEntitySharable(entity_num); - - pEnt = xf86GetEntityInfo(entity_num); - xf86SetEntityInstanceForScreen(pScrn, pEnt->index, xf86GetNumEntityInstances(pEnt->index) - 1); - free(pEnt); + xf86SetEntityInstanceForScreen(pScrn, entity_num, + xf86GetNumEntityInstances(entity_num) - 1); return TRUE; } -- 1.8.0 From f0a47a6113f4e09e10871533a43a22b1f5bfb1e3 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Fri, 2 Nov 2012 01:58:49 +0000 Subject: [PATCH 2/4] nouveau: introduce NVInitScrn() Common/helper function for NV{Pci,Platform}Probe() This introduces some the following functions to the NVPlatformProbe codepath * xf86SetEntitySharable() * xf86SetEntityInstanceForScreen() Necessary for dualhead, xinerama and/or zaphodhead v2: Rename nouveau_init_scrn() to NVInitScrn() Signed-off-by: Emil Velikov --- src/nv_driver.c | 91 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/src/nv_driver.c b/src/nv_driver.c index c885e73..dc4f3b2 100644 --- a/src/nv_driver.c +++ b/src/nv_driver.c @@ -74,36 +74,10 @@ static Bool NVPciProbe ( DriverPtr drv, intptr_t match_data ); #ifdef XSERVER_PLATFORM_BUS -static Bool -NVPlatformProbe(DriverPtr driver, - int entity_num, int flags, struct xf86_platform_device *dev, intptr_t dev_match_data) -{ - ScrnInfoPtr scrn = NULL; - uint32_t scr_flags = 0; - - if (!dev->pdev) - return FALSE; - - if (flags & PLATFORM_PROBE_GPU_SCREEN) - scr_flags = XF86_ALLOCATE_GPU_SCREEN; - - scrn = xf86AllocateScreen(driver, scr_flags); - xf86AddEntityToScreen(scrn, entity_num); - - scrn->driverVersion = NV_VERSION; - scrn->driverName = NV_DRIVER_NAME; - scrn->name = NV_NAME; - - scrn->Probe = NULL; - scrn->PreInit = NVPreInit; - scrn->ScreenInit = NVScreenInit; - scrn->SwitchMode = NVSwitchMode; - scrn->AdjustFrame = NVAdjustFrame; - scrn->EnterVT = NVEnterVT; - scrn->LeaveVT = NVLeaveVT; - scrn->FreeScreen = NVFreeScreen; - return scrn != NULL; -} +static Bool NVPlatformProbe(DriverPtr driver, + int entity_num, int flags, + struct xf86_platform_device *dev, + intptr_t dev_match_data); #endif /* @@ -251,6 +225,27 @@ NVDriverFunc(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data) } } +static void +NVInitScrn(ScrnInfoPtr pScrn, int entity_num) +{ + pScrn->driverVersion = NV_VERSION; + pScrn->driverName = NV_DRIVER_NAME; + pScrn->name = NV_NAME; + + pScrn->Probe = NULL; + pScrn->PreInit = NVPreInit; + pScrn->ScreenInit = NVScreenInit; + pScrn->SwitchMode = NVSwitchMode; + pScrn->AdjustFrame = NVAdjustFrame; + pScrn->EnterVT = NVEnterVT; + pScrn->LeaveVT = NVLeaveVT; + pScrn->FreeScreen = NVFreeScreen; + + xf86SetEntitySharable(entity_num); + xf86SetEntityInstanceForScreen(pScrn, entity_num, + xf86GetNumEntityInstances(entity_num) - 1); +} + static Bool NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, intptr_t match_data) @@ -325,25 +320,33 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, if (!pScrn) return FALSE; - pScrn->driverVersion = NV_VERSION; - pScrn->driverName = NV_DRIVER_NAME; - pScrn->name = NV_NAME; + NVInitScrn(pScrn, entity_num); - pScrn->Probe = NULL; - pScrn->PreInit = NVPreInit; - pScrn->ScreenInit = NVScreenInit; - pScrn->SwitchMode = NVSwitchMode; - pScrn->AdjustFrame = NVAdjustFrame; - pScrn->EnterVT = NVEnterVT; - pScrn->LeaveVT = NVLeaveVT; - pScrn->FreeScreen = NVFreeScreen; + return TRUE; +} - xf86SetEntitySharable(entity_num); - xf86SetEntityInstanceForScreen(pScrn, entity_num, - xf86GetNumEntityInstances(entity_num) - 1); +#ifdef XSERVER_PLATFORM_BUS +static Bool +NVPlatformProbe(DriverPtr driver, + int entity_num, int flags, struct xf86_platform_device *dev, intptr_t dev_match_data) +{ + ScrnInfoPtr scrn = NULL; + uint32_t scr_flags = 0; + + if (!dev->pdev) + return FALSE; + + if (flags & PLATFORM_PROBE_GPU_SCREEN) + scr_flags = XF86_ALLOCATE_GPU_SCREEN; + + scrn = xf86AllocateScreen(driver, scr_flags); + xf86AddEntityToScreen(scrn, entity_num); + + NVInitScrn(scrn, entity_num); return TRUE; } +#endif #define MAX_CHIPS MAXSCREENS -- 1.8.0 From e62e8a448569be36e5ea232bec85eabec32ccabe Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Fri, 2 Nov 2012 02:59:20 +0000 Subject: [PATCH 3/4] nouveau: Factor out common code to NVHasKMS() As the name suggests checks if it has kernel mode setting, prints out the interface version and checkes if the chipset is supported Function is used in NVPciProbe and NVPlatformProbe Signed-off-by: Emil Velikov --- src/nv_driver.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/nv_driver.c b/src/nv_driver.c index dc4f3b2..f184cd4 100644 --- a/src/nv_driver.c +++ b/src/nv_driver.c @@ -247,19 +247,12 @@ NVInitScrn(ScrnInfoPtr pScrn, int entity_num) } static Bool -NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, - intptr_t match_data) +NVHasKMS(struct pci_device *pci_dev) { - PciChipsets NVChipsets[] = { - { pci_dev->device_id, - (pci_dev->vendor_id << 16) | pci_dev->device_id, NULL }, - { -1, -1, NULL } - }; struct nouveau_device *dev = NULL; - ScrnInfoPtr pScrn = NULL; drmVersion *version; - int chipset, ret; char *busid; + int chipset, ret; if (!xf86LoaderCheckSymbol("DRICreatePCIBusID")) { xf86DrvMsg(-1, X_ERROR, "[drm] No DRICreatePCIBusID symbol\n"); @@ -267,10 +260,17 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, } busid = DRICreatePCIBusID(pci_dev); + ret = drmCheckModesettingSupported(busid); + if (ret) { + xf86DrvMsg(-1, X_ERROR, "[drm] KMS not enabled\n"); + free(busid); + return FALSE; + } + ret = nouveau_device_open(busid, &dev); + free(busid); if (ret) { xf86DrvMsg(-1, X_ERROR, "[drm] failed to open device\n"); - free(busid); return FALSE; } @@ -288,12 +288,6 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, chipset = dev->chipset; nouveau_device_del(&dev); - ret = drmCheckModesettingSupported(busid); - free(busid); - if (ret) { - xf86DrvMsg(-1, X_ERROR, "[drm] KMS not enabled\n"); - return FALSE; - } switch (chipset & 0xf0) { case 0x00: @@ -314,6 +308,22 @@ NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, xf86DrvMsg(-1, X_ERROR, "Unknown chipset: NV%02x\n", chipset); return FALSE; } + return TRUE; +} + +static Bool +NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev, + intptr_t match_data) +{ + PciChipsets NVChipsets[] = { + { pci_dev->device_id, + (pci_dev->vendor_id << 16) | pci_dev->device_id, NULL }, + { -1, -1, NULL } + }; + ScrnInfoPtr pScrn = NULL; + + if (!NVHasKMS(pci_dev)) + return FALSE; pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets, NULL, NULL, NULL, NULL, NULL); @@ -336,6 +346,9 @@ NVPlatformProbe(DriverPtr driver, if (!dev->pdev) return FALSE; + if (!NVHasKMS(dev->pdev)) + return FALSE; + if (flags & PLATFORM_PROBE_GPU_SCREEN) scr_flags = XF86_ALLOCATE_GPU_SCREEN; -- 1.8.0 From c70b6d1c0e3599032adbbae612f244f1f22b63a9 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Fri, 2 Nov 2012 03:11:03 +0000 Subject: [PATCH 4/4] nouveau: NVPlatformProbe, handle shareable entities During NVPciProbe, xf86ConfigPciEntity() implicitly calls checks and sets the entity as shared Here we are only allocating the screen, thus need to explicitly call the functions ZaphodHead and Xinerama should finally work Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=56347 Reported-By: Vladimir Chebotarev Reported-By: Damian Nowak Tested-By: Damian Nowak Signed-off-by: Emil Velikov --- src/nv_driver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nv_driver.c b/src/nv_driver.c index f184cd4..83bb7f4 100644 --- a/src/nv_driver.c +++ b/src/nv_driver.c @@ -353,6 +353,11 @@ NVPlatformProbe(DriverPtr driver, scr_flags = XF86_ALLOCATE_GPU_SCREEN; scrn = xf86AllocateScreen(driver, scr_flags); + if (!scrn) + return FALSE; + + if (xf86IsEntitySharable(entity_num)) + xf86SetEntityShared(entity_num); xf86AddEntityToScreen(scrn, entity_num); NVInitScrn(scrn, entity_num); -- 1.8.0