286
280
* might refer to.
288
282
LoaderRefSymLists(vgahwSymbols, exaSymbols, fbSymbols,
289
ramdacSymbols, shadowSymbols, drmSymbols,
283
shadowSymbols, drmSymbols,
290
284
i2cSymbols, ddcSymbols, vbeSymbols,
291
285
int10Symbols, NULL);
666
663
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVEnterVT is called.\n");
669
if (pNv->Architecture >= NV_ARCH_50 && pNv->EXADriverPtr) {
670
nouveau_bo_tile(pNv->FB, NOUVEAU_BO_VRAM | NOUVEAU_BO_TILED,
671
pNv->EXADriverPtr->offScreenBase,
672
pNv->EXADriverPtr->memorySize -
673
pNv->EXADriverPtr->offScreenBase);
666
NVAccelCommonInit(pScrn);
668
if (!pNv->kms_enable) {
669
/* Save current state, VGA fonts etc */
672
/* Clear the framebuffer, we don't want to see garbage
673
* on-screen up until X decides to draw something
675
nouveau_bo_map(pNv->FB, NOUVEAU_BO_WR);
676
memset(pNv->FB->map, 0, NOUVEAU_ALIGN(pScrn->virtualX, 64) *
677
pScrn->virtualY * (pScrn->bitsPerPixel >> 3));
678
nouveau_bo_unmap(pNv->FB);
680
if (pNv->Architecture == NV_ARCH_50) {
681
if (!NV50AcquireDisplay(pScrn))
676
if (!pNv->kms_enable && pNv->randr12_enable)
679
686
if (!pNv->randr12_enable) {
680
687
if (!NVModeInit(pScrn, pScrn->currentMode))
682
689
NVAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
684
pScrn->vtSema = TRUE;
686
if (!pNv->kms_enable && pNv->Architecture == NV_ARCH_50)
687
if (!NV50AcquireDisplay(pScrn))
691
pNv->allow_dpms = FALSE;
690
692
if (!xf86SetDesiredModes(pScrn))
696
NVAccelCommonInit(pScrn);
694
pNv->allow_dpms = TRUE;
699
697
if (pNv->overlayAdaptor && pNv->Architecture != NV_ARCH_04)
716
714
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
717
715
NVPtr pNv = NVPTR(pScrn);
719
if (pNv->randr12_enable)
720
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVLeaveVT is called.\n");
717
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NVLeaveVT is called.\n");
724
NVTakedownVideo(pScrn);
725
NVTakedownDma(pScrn);
731
if (pNv->Architecture == NV_ARCH_50) {
732
NV50ReleaseDisplay(pScrn);
721
if (!pNv->kms_enable) {
722
if (pNv->Architecture < NV_ARCH_50)
725
NV50ReleaseDisplay(pScrn);
885
872
Bool NVI2CInit(ScrnInfoPtr pScrn)
887
NVPtr pNv = NVPTR(pScrn);
889
if (xf86LoadSubModule(pScrn, "i2c") && xf86LoadSubModule(pScrn, "ddc")) {
890
xf86LoaderReqSymLists(i2cSymbols,NULL);
891
xf86LoaderReqSymLists(ddcSymbols, NULL);
893
/* randr-1.2 clients have their DDCs initialized elsewhere */
894
if (!pNv->randr12_enable)
895
return NVDACi2cInit(pScrn);
898
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
899
"Couldn't load i2c and ddc modules. DDC probing can't be done\n");
904
static bool nouveau_kernel_modesetting_enabled(ScrnInfoPtr pScrn)
906
#if XSERVER_LIBPCIACCESS
907
struct pci_device *PciInfo;
915
pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
916
PciInfo = xf86GetPciInfoForEntity(pEnt->index);
918
busIdString = DRICreatePCIBusID(PciInfo);
920
ret = drmCheckModesettingSupported(busIdString);
928
#define nouveau_kernel_modesetting_enabled(x) FALSE
931
static Bool NVPreInitDRI(ScrnInfoPtr pScrn)
933
NVPtr pNv = NVPTR(pScrn);
935
if (!NVDRIGetVersion(pScrn))
938
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
939
"[dri] Found DRI library version %d.%d.%d and kernel"
940
" module version %d.%d.%d\n",
941
pNv->pLibDRMVersion->version_major,
942
pNv->pLibDRMVersion->version_minor,
943
pNv->pLibDRMVersion->version_patchlevel,
944
pNv->pKernelDRMVersion->version_major,
945
pNv->pKernelDRMVersion->version_minor,
946
pNv->pKernelDRMVersion->version_patchlevel);
874
xf86LoaderReqSymLists(i2cSymbols,NULL);
875
xf86LoaderReqSymLists(ddcSymbols, NULL);
877
if (!NVPTR(pScrn)->randr12_enable)
878
return NVDACi2cInit(pScrn);
905
NVCloseDRM(ScrnInfoPtr pScrn)
907
NVPtr pNv = NVPTR(pScrn);
909
nouveau_device_close(&pNv->dev);
913
NVPreInitDRM(ScrnInfoPtr pScrn)
915
NVPtr pNv = NVPTR(pScrn);
920
/* Load the kernel module, and open the DRM */
921
bus_id = DRICreatePCIBusID(pNv->PciInfo);
922
ret = DRIOpenDRMMaster(pScrn, SAREA_MAX, bus_id, "nouveau");
924
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
925
"[drm] error opening the drm\n");
930
/* Check the version reported by the kernel module. In theory we
931
* shouldn't have to do this, as libdrm_nouveau will do its own checks.
932
* But, we're currently using the kernel patchlevel to also version
935
version = drmGetVersion(DRIMasterFD(pScrn));
936
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
937
"[drm] nouveau interface version: %d.%d.%d\n",
938
version->version_major, version->version_minor,
939
version->version_patchlevel);
941
ret = !(version->version_patchlevel == NOUVEAU_DRM_HEADER_PATCHLEVEL);
944
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
945
"[drm] wrong version, expecting 0.0.%d\n",
946
NOUVEAU_DRM_HEADER_PATCHLEVEL);
951
/* Initialise libdrm_nouveau */
952
ret = nouveau_device_open_existing(&pNv->dev, 1, DRIMasterFD(pScrn), 0);
954
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
955
"[drm] error creating device, setting NoAccel\n");
960
/* Check if KMS is enabled before we do anything, we don't want to
961
* go stomping on registers behind its back
964
pNv->kms_enable = !drmCheckModesettingSupported(bus_id);
966
/* Additional sanity check */
967
if (!nouveau_device(pNv->dev)->mm_enabled)
968
pNv->kms_enable = false;
970
xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
971
"[drm] kernel modesetting %s\n", pNv->kms_enable ?
972
"in use" : "not available");
975
980
NVPreInit(ScrnInfoPtr pScrn, int flags)
978
983
MessageType from;
979
int i, max_width, max_height;
980
984
ClockRangePtr clockRanges;
985
int max_width, max_height;
981
986
int config_mon_rates = FALSE;
983
989
if (flags & PROBE_DETECT) {
984
990
EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
1113
/* Attempt to initialise the kernel module, if we fail this we'll
1114
* fallback to limited functionality.
1116
if (!NVPreInitDRM(pScrn)) {
1117
xf86DrvMsg(pScrn->scrnIndex, X_NOTICE,
1118
"Failing back to NoAccel mode\n");
1119
pNv->NoAccel = TRUE;
1120
pNv->ShadowFB = TRUE;
1107
1123
/* Save current console video mode */
1108
1124
if (pNv->Architecture >= NV_ARCH_50 && pNv->pInt10 && !pNv->kms_enable) {
1109
1125
const xf86Int10InfoPtr pInt10 = pNv->pInt10;
1194
1210
from = X_DEFAULT;
1196
pNv->kms_enable = false;
1198
if (pNv->Architecture == NV_ARCH_50)
1199
pNv->kms_enable = nouveau_kernel_modesetting_enabled(pScrn);
1200
#endif /* XF86DRM_MODE */
1202
if (pNv->kms_enable)
1203
xf86DrvMsg(pScrn->scrnIndex, from, "NV50 Kernel modesetting enabled\n");
1205
1212
pNv->randr12_enable = true;
1206
if (pNv->Architecture != NV_ARCH_50 && !xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, TRUE))
1213
if (pNv->Architecture != NV_ARCH_50 && !pNv->kms_enable &&
1214
!xf86ReturnOptValBool(pNv->Options, OPTION_RANDR12, TRUE))
1207
1215
pNv->randr12_enable = false;
1208
xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n", pNv->randr12_enable ? "en" : "dis");
1216
xf86DrvMsg(pScrn->scrnIndex, from, "Randr1.2 support %sabled\n",
1217
pNv->randr12_enable ? "en" : "dis");
1210
1219
pNv->HWCursor = TRUE;
1229
1240
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Flat panel scaling %s\n",
1230
1241
pNv->FpScale ? "on" : "off");
1232
1244
if (xf86ReturnOptValBool(pNv->Options, OPTION_NOACCEL, FALSE)) {
1233
1245
pNv->NoAccel = TRUE;
1234
1246
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
1236
1249
if (xf86ReturnOptValBool(pNv->Options, OPTION_SHADOW_FB, FALSE)) {
1237
1250
pNv->ShadowFB = TRUE;
1238
1251
pNv->NoAccel = TRUE;
1240
1253
"Using \"Shadow Framebuffer\" - acceleration disabled\n");
1256
if (xf86ReturnOptValBool(pNv->Options, OPTION_EXA_PIXMAPS, FALSE))
1257
pNv->exa_driver_pixmaps = TRUE;
1243
1259
if(xf86GetOptValInteger(pNv->Options, OPTION_VIDEO_KEY, &(pNv->videoKey))) {
1244
1260
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n",
1245
1261
pNv->videoKey);
1325
1341
#ifdef XF86DRM_MODE
1326
1342
if (pNv->kms_enable){
1329
bus_id = DRICreatePCIBusID(pNv->PciInfo);
1331
pNv->drmmode = calloc(1, sizeof(drmmode_rec));
1332
res = drmmode_pre_init(pScrn, bus_id, pNv->drmmode, pScrn->bitsPerPixel >> 3);
1343
ret = drmmode_pre_init(pScrn, nouveau_device(pNv->dev)->fd,
1344
pScrn->bitsPerPixel >> 3);
1335
1346
NVPreInitFail("Kernel modesetting failed to initialize\n");
1339
1349
if (pNv->randr12_enable) {
1342
1352
xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
1345
if (!pNv->NoAccel && NVPreInitDRI(pScrn) == FALSE) {
1346
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1347
"DRI pre-initialisation failed. Setting NoAccel\n");
1348
pNv->ShadowFB = TRUE;
1349
pNv->NoAccel = TRUE;
1352
1355
if (!pNv->randr12_enable) {
1353
1356
if ((pScrn->monitor->nHsync == 0) &&
1354
1357
(pScrn->monitor->nVrefresh == 0)) {
1582
1577
Cursor0Offset = VRAMReserved;
1583
Cursor1Offset = Cursor0Offset + (64 * 1024);
1584
CLUTOffset[0] = Cursor1Offset + (64 * 1024);
1578
Cursor1Offset = Cursor0Offset + (64 * 64 * 4);
1579
CLUTOffset[0] = Cursor1Offset + (64 * 64 * 4);
1585
1580
CLUTOffset[1] = CLUTOffset[0] + (4 * 1024);
1587
1582
ret = nouveau_bo_fake(&dev, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1594
1589
ret = nouveau_bo_fake(&dev, Cursor0Offset,
1595
1590
NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1596
64*1024, pNv->VRAMMap + Cursor0Offset,
1591
64 * 64 * 4, pNv->VRAMMap + Cursor0Offset,
1601
1596
ret = nouveau_bo_fake(&dev, Cursor1Offset,
1602
1597
NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1603
64*1024, pNv->VRAMMap + Cursor1Offset,
1598
64 * 64 * 4, pNv->VRAMMap + Cursor1Offset,
1604
1599
&pNv->Cursor2);
1647
1642
nouveau_device_get_param(pNv->dev, NOUVEAU_GETPARAM_AGP_SIZE, &res);
1648
1643
pNv->AGPSize=res;
1645
if (pNv->exa_driver_pixmaps) {
1646
size = NOUVEAU_ALIGN(pScrn->virtualX, 64);
1647
size = size * (pScrn->bitsPerPixel >> 3);
1648
size = size * pScrn->virtualY;
1650
size = pNv->VRAMPhysicalSize / 2;
1650
1653
if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN,
1651
0, pNv->VRAMPhysicalSize / 2, &pNv->FB)) {
1652
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to allocate memory for framebuffer!\n");
1654
0, size, &pNv->FB)) {
1655
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1656
"Failed to allocate framebuffer memory\n");
1655
1659
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1656
"Allocated %dMiB VRAM for framebuffer + offscreen pixmaps, at offset 0x%X\n",
1657
(uint32_t)(pNv->FB->size >> 20), (uint32_t) pNv->FB->offset);
1659
if (pNv->kms_enable)
1660
drmmode_set_fb(pScrn, pNv->drmmode, pScrn->virtualX, pScrn->virtualY, pScrn->displayWidth*(pScrn->bitsPerPixel >> 3), pNv->FB);
1660
"Allocated %dMiB VRAM for framebuffer + offscreen pixmaps, "
1662
(uint32_t)(pNv->FB->size >> 20), (uint32_t) pNv->FB->offset);
1663
1664
if (pNv->AGPSize) {
1664
1665
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1665
1666
"AGPGART: %dMiB available\n",
1666
1667
(unsigned int)(pNv->AGPSize >> 20));
1667
1668
if (pNv->AGPSize > (16*1024*1024))
1668
gart_scratch_size = 16*1024*1024;
1669
size = 16*1024*1024;
1670
1671
/* always leave 512kb for other things like the fifos */
1671
gart_scratch_size = pNv->AGPSize - 512*1024;
1672
size = pNv->AGPSize - 512*1024;
1673
gart_scratch_size = (4 << 20) - (1 << 18) ;
1674
size = (4 << 20) - (1 << 18) ;
1674
1675
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
1675
1676
"GART: PCI DMA - using %dKiB\n",
1676
gart_scratch_size >> 10);
1679
1680
if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_GART | NOUVEAU_BO_PIN, 0,
1680
gart_scratch_size, &pNv->GART)) {
1681
size, &pNv->GART)) {
1681
1682
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1682
1683
"Unable to allocate GART memory\n");
1687
1688
(unsigned int)(pNv->GART->size >> 20));
1691
/* We don't need to allocate cursors / lut here if we're using
1692
* kernel modesetting
1694
if (pNv->kms_enable)
1690
1697
if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1691
64 * 1024, &pNv->Cursor)) {
1698
64 * 64 * 4, &pNv->Cursor)) {
1692
1699
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1693
1700
"Failed to allocate memory for hardware cursor\n");
1697
if (pNv->randr12_enable) {
1698
if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1699
64 * 1024, &pNv->Cursor2)) {
1700
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1701
"Failed to allocate memory for hardware cursor\n");
1704
if (nouveau_bo_new(pNv->dev, NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN, 0,
1705
64 * 64 * 4, &pNv->Cursor2)) {
1706
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1707
"Failed to allocate memory for hardware cursor\n");
1706
1711
/* This is not the ideal solution, but significant changes are needed
1936
1941
/* NV17,18,34 Apple iMac, iBook, PowerBook */
1937
1942
CARD32 tmp_pmc, tmp_pcrt;
1938
1943
tmp_pmc = nvReadMC(pNv, NV_PBUS_DEBUG_DUALHEAD_CTL) & 0x7FFFFFFF;
1939
tmp_pcrt = NVReadCRTC(pNv, 0, NV_CRTC_GPIO_EXT) & 0xFFFFFFFC;
1944
tmp_pcrt = NVReadCRTC(pNv, 0, NV_PCRTC_GPIO_EXT) & 0xFFFFFFFC;
1941
1946
tmp_pmc |= (1 << 31);
1942
1947
tmp_pcrt |= 0x1;
1944
1949
nvWriteMC(pNv, NV_PBUS_DEBUG_DUALHEAD_CTL, tmp_pmc);
1945
NVWriteCRTC(pNv, 0, NV_CRTC_GPIO_EXT, tmp_pcrt);
1950
NVWriteCRTC(pNv, 0, NV_PCRTC_GPIO_EXT, tmp_pcrt);
1954
1959
CARD32 fpcontrol;
1956
fpcontrol = nvReadCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL) & 0xCfffffCC;
1961
fpcontrol = nvReadCurRAMDAC(pNv, NV_PRAMDAC_FP_TG_CONTROL) & 0xCfffffCC;
1958
1963
/* cut the TMDS output */
1959
1964
if(on) fpcontrol |= pNv->fpSyncs;
1960
1965
else fpcontrol |= 0x20000022;
1962
nvWriteCurRAMDAC(pNv, NV_RAMDAC_FP_CONTROL, fpcontrol);
1967
nvWriteCurRAMDAC(pNv, NV_PRAMDAC_FP_TG_CONTROL, fpcontrol);
2043
/* First init DRI/DRM */
2044
if (!pNv->NoAccel && !NVDRIScreenInit(pScrn)) {
2045
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
2046
"DRI initialisation failed. Setting NoAccel\n");
2047
pNv->ShadowFB = TRUE;
2048
pNv->NoAccel = TRUE;
2051
2048
/* Allocate and map memory areas we need */
2052
2049
if (!NVMapMem(pScrn))
2055
2052
if (!pNv->NoAccel) {
2053
if (!pNv->exa_driver_pixmaps)
2054
NVDRIScreenInit(pScrn);
2057
nouveau_dri2_init(pScreen);
2056
2060
/* Init DRM - Alloc FIFO */
2057
2061
if (!NVInitDma(pScrn))
2076
2080
if (!pNv->kms_enable)
2079
if (!pNv->randr12_enable) {
2080
if (!NVModeInit(pScrn, pScrn->currentMode))
2082
pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
2084
pScrn->vtSema = TRUE;
2086
if (!pNv->kms_enable && pNv->Architecture == NV_ARCH_50)
2087
if (!NV50AcquireDisplay(pScrn))
2090
if (!xf86SetDesiredModes(pScrn))
2094
/* Darken the screen for aesthetic reasons */
2095
if (!pNv->kms_enable)
2096
NVSaveScreen(pScreen, SCREEN_SAVER_ON);
2099
2084
* The next step is to setup the screen's visuals, and initialise the
2100
2085
* framebuffer code. In cases where the framebuffer's default
2209
ShadowFBInit(pScreen, NVRefreshArea);
2211
pScrn->memPhysBase = pNv->VRAMPhysical;
2212
pScrn->fbOffset = 0;
2214
NVInitVideo(pScreen);
2216
pScrn->vtSema = TRUE;
2217
pScrn->pScreen = pScreen;
2218
if (!NVEnterVT(pScrn->scrnIndex, 0))
2217
2221
if (pNv->randr12_enable) {
2218
2222
xf86DPMSInit(pScreen, xf86DPMSSet, 0);
2220
2224
if (!xf86CrtcScreenInit(pScreen))
2227
if(pNv->FlatPanel) {
2228
xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2230
xf86DPMSInit(pScreen, NVDPMSSet, 0);
2224
2234
/* Initialise default colourmap */
2229
2239
* Initialize colormap layer.
2230
2240
* Must follow initialization of the default colormap
2232
if (!pNv->randr12_enable && !pNv->kms_enable) {
2242
if (!pNv->randr12_enable) {
2233
2243
if(!xf86HandleColormaps(pScreen, 256, 8, NVDACLoadPalette,
2234
NULL, CMAP_RELOAD_ON_MODE_SWITCH | CMAP_PALETTED_TRUECOLOR))
2244
NULL, CMAP_RELOAD_ON_MODE_SWITCH |
2245
CMAP_PALETTED_TRUECOLOR))
2237
2248
if (!xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
2238
NULL, CMAP_PALETTED_TRUECOLOR))
2249
NULL, CMAP_PALETTED_TRUECOLOR))
2243
ShadowFBInit(pScreen, NVRefreshArea);
2245
if (!pNv->randr12_enable) {
2246
if(pNv->FlatPanel) {
2247
xf86DPMSInit(pScreen, NVDPMSSetLCD, 0);
2249
xf86DPMSInit(pScreen, NVDPMSSet, 0);
2253
pScrn->memPhysBase = pNv->VRAMPhysical;
2254
pScrn->fbOffset = 0;
2256
NVInitVideo(pScreen);
2258
2253
pScreen->SaveScreen = NVSaveScreen;
2260
2255
/* Wrap the current CloseScreen function */