108705d96Sshatty 208705d96Sshatty /* 308705d96Sshatty Copyright 1999, Be Incorporated. All Rights Reserved. 408705d96Sshatty This file may be used under the terms of the Be Sample Code License. 508705d96Sshatty 608705d96Sshatty Other authors: 708705d96Sshatty Mark Watson, 808705d96Sshatty Apsed, 9b2459715SRudolf Cornelissen Rudolf Cornelissen 11/2002-10/2005 1008705d96Sshatty */ 1108705d96Sshatty 1208705d96Sshatty #define MODULE_BIT 0x00200000 1308705d96Sshatty 1408705d96Sshatty #include "acc_std.h" 1508705d96Sshatty 1608705d96Sshatty /* 1708705d96Sshatty Enable/Disable interrupts. Just a wrapper around the 1808705d96Sshatty ioctl() to the kernel driver. 1908705d96Sshatty */ 20ce3fc95eSRudolf Cornelissen static void interrupt_enable(bool flag) 21ce3fc95eSRudolf Cornelissen { 22ce3fc95eSRudolf Cornelissen status_t result = B_OK; 2308705d96Sshatty nv_set_bool_state sbs; 2408705d96Sshatty 25ce3fc95eSRudolf Cornelissen if (si->ps.int_assigned) 26ce3fc95eSRudolf Cornelissen { 2708705d96Sshatty /* set the magic number so the driver knows we're for real */ 2808705d96Sshatty sbs.magic = NV_PRIVATE_DATA_MAGIC; 2908705d96Sshatty sbs.do_it = flag; 3008705d96Sshatty /* contact driver and get a pointer to the registers and shared data */ 3108705d96Sshatty result = ioctl(fd, NV_RUN_INTERRUPTS, &sbs, sizeof(sbs)); 3208705d96Sshatty } 33ce3fc95eSRudolf Cornelissen } 3408705d96Sshatty 3508705d96Sshatty /* First validate the mode, then call lots of bit banging stuff to set the mode(s)! */ 3608705d96Sshatty status_t SET_DISPLAY_MODE(display_mode *mode_to_set) 3708705d96Sshatty { 3808705d96Sshatty /* BOUNDS WARNING: 3908705d96Sshatty * It's impossible to deviate whatever small amount in a display_mode if the lower 4008705d96Sshatty * and upper limits are the same! 4108705d96Sshatty * Besides: 4208705d96Sshatty * BeOS (tested R5.0.3PE) is failing BWindowScreen::SetFrameBuffer() if PROPOSEMODE 4308705d96Sshatty * returns B_BAD_VALUE! 4408705d96Sshatty * Which means PROPOSEMODE should not return that on anything except on 4508705d96Sshatty * deviations for: 4608705d96Sshatty * display_mode.virtual_width; 4708705d96Sshatty * display_mode.virtual_height; 4808705d96Sshatty * display_mode.timing.h_display; 4908705d96Sshatty * display_mode.timing.v_display; 5008705d96Sshatty * So: 5108705d96Sshatty * We don't use bounds here by making sure bounds and target are the same struct! 5208705d96Sshatty * (See the call to PROPOSE_DISPLAY_MODE below) */ 5308705d96Sshatty display_mode /*bounds,*/ target; 5408705d96Sshatty 5508705d96Sshatty uint8 colour_depth1 = 32; 5608705d96Sshatty status_t result; 5708705d96Sshatty uint32 startadd,startadd_right; 5830f76422SRudolf Cornelissen // bool crt1, crt2, cross; 5908705d96Sshatty 6008705d96Sshatty /* Adjust mode to valid one and fail if invalid */ 6108705d96Sshatty target /*= bounds*/ = *mode_to_set; 6208705d96Sshatty /* show the mode bits */ 6308705d96Sshatty LOG(1, ("SETMODE: (ENTER) initial modeflags: $%08x\n", target.flags)); 6408705d96Sshatty LOG(1, ("SETMODE: requested target pixelclock %dkHz\n", target.timing.pixel_clock)); 6508705d96Sshatty LOG(1, ("SETMODE: requested virtual_width %d, virtual_height %d\n", 6608705d96Sshatty target.virtual_width, target.virtual_height)); 6708705d96Sshatty 6808705d96Sshatty /* See BOUNDS WARNING above... */ 6908705d96Sshatty if (PROPOSE_DISPLAY_MODE(&target, &target, &target) == B_ERROR) return B_ERROR; 7008705d96Sshatty 7108705d96Sshatty /* if not dualhead capable card clear dualhead flags */ 7208705d96Sshatty if (!(target.flags & DUALHEAD_CAPABLE)) 7308705d96Sshatty { 7408705d96Sshatty target.flags &= ~DUALHEAD_BITS; 7508705d96Sshatty } 7608705d96Sshatty /* if not TVout capable card clear TVout flags */ 7708705d96Sshatty if (!(target.flags & TV_CAPABLE)) 7808705d96Sshatty { 7908705d96Sshatty target.flags &= ~TV_BITS; 8008705d96Sshatty } 8108705d96Sshatty LOG(1, ("SETMODE: (CONT.) validated command modeflags: $%08x\n", target.flags)); 8208705d96Sshatty 83c9c0c72bSRudolf Cornelissen /* make sure a possible 3D add-on will block rendering and re-initialize itself. 84c9c0c72bSRudolf Cornelissen * note: update in _this_ order only */ 85c9c0c72bSRudolf Cornelissen /* SET_DISPLAY_MODE will reset this flag when it's done. */ 8621545d00SRudolf Cornelissen si->engine.threeD.mode_changing = true; 8721545d00SRudolf Cornelissen /* every 3D add-on will reset this bit-flag when it's done. */ 8821545d00SRudolf Cornelissen si->engine.threeD.newmode = 0xffffffff; 8921545d00SRudolf Cornelissen /* every 3D clone needs to reclaim a slot. 9021545d00SRudolf Cornelissen * note: this also cleans up reserved channels for killed 3D clones.. */ 9121545d00SRudolf Cornelissen si->engine.threeD.clones = 0x00000000; 92afb207acSRudolf Cornelissen 9308705d96Sshatty /* disable interrupts using the kernel driver */ 9408705d96Sshatty interrupt_enable(false); 9508705d96Sshatty 960703480cSRudolf Cornelissen /* disable TVout if supported */ 970703480cSRudolf Cornelissen if (si->ps.tvout) BT_stop_tvout(); 980b36eea4SRudolf Cornelissen 99*20603b95SRudolf Cornelissen /* turn off screen(s) _after_ TVout is disabled (if applicable) */ 1000669fe20SRudolf Cornelissen head1_dpms(false, false, false); 1010669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, false); 1023aa21459SRudolf Cornelissen if (si->ps.tvout) BT_dpms(false); 10308705d96Sshatty 10408705d96Sshatty /*where in framebuffer the screen is (should this be dependant on previous MOVEDISPLAY?)*/ 105f2777ca1SRudolf Cornelissen startadd = (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 10608705d96Sshatty 10708705d96Sshatty /* calculate and set new mode bytes_per_row */ 10805ed3229SRudolf Cornelissen nv_general_validate_pic_size (&target, &si->fbc.bytes_per_row, &si->acc_mode); 10908705d96Sshatty 11008705d96Sshatty /*Perform the very long mode switch!*/ 11108705d96Sshatty if (target.flags & DUALHEAD_BITS) /*if some dualhead mode*/ 11208705d96Sshatty { 11308705d96Sshatty uint8 colour_depth2 = colour_depth1; 11408705d96Sshatty 11508705d96Sshatty /* init display mode for secondary head */ 11608705d96Sshatty display_mode target2 = target; 11708705d96Sshatty 11808705d96Sshatty LOG(1,("SETMODE: setting DUALHEAD mode\n")); 11908705d96Sshatty 12008705d96Sshatty /* validate flags for secondary TVout */ 121b2459715SRudolf Cornelissen //fixme: remove or block on autodetect fail. (is now shutoff) 122b2459715SRudolf Cornelissen if ((0) && (target2.flags & TV_BITS)) 12308705d96Sshatty { 12408705d96Sshatty target.flags &= ~TV_BITS;//still needed for some routines... 12508705d96Sshatty target2.flags &= ~TV_BITS; 12608705d96Sshatty LOG(1,("SETMODE: blocking TVout: no TVout cable connected!\n")); 12708705d96Sshatty } 12808705d96Sshatty 12930f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 13030f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 13130f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 13230f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 13330f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 13430f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 13530f76422SRudolf Cornelissen // if (crt1) 13630f76422SRudolf Cornelissen // { 13730f76422SRudolf Cornelissen /* connector1 is used as primary output */ 13830f76422SRudolf Cornelissen // cross = false; 13930f76422SRudolf Cornelissen // } 14030f76422SRudolf Cornelissen // else 14130f76422SRudolf Cornelissen // { 14230f76422SRudolf Cornelissen // if (crt2) 14330f76422SRudolf Cornelissen /* connector2 is used as primary output */ 14430f76422SRudolf Cornelissen // cross = true; 14530f76422SRudolf Cornelissen // else 14630f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 14730f76422SRudolf Cornelissen // cross = false; 14830f76422SRudolf Cornelissen // } 14930f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 15030f76422SRudolf Cornelissen if ((target.flags & DUALHEAD_BITS) == DUALHEAD_SWITCH) 15130f76422SRudolf Cornelissen /* invert output assignment in switch mode */ 15206f4c439SRudolf Cornelissen nv_general_head_select(true); 15330f76422SRudolf Cornelissen else 15406f4c439SRudolf Cornelissen nv_general_head_select(false); 15530f76422SRudolf Cornelissen 15608705d96Sshatty /* set the pixel clock PLL(s) */ 15708705d96Sshatty LOG(8,("SETMODE: target clock %dkHz\n",target.timing.pixel_clock)); 15830f76422SRudolf Cornelissen if (head1_set_pix_pll(target) == B_ERROR) 15908705d96Sshatty LOG(8,("SETMODE: error setting pixel clock (internal DAC)\n")); 16008705d96Sshatty 16108705d96Sshatty /* we do not need to set the pixelclock here for a head that's in TVout mode */ 16208705d96Sshatty if (!(target2.flags & TV_BITS)) 16308705d96Sshatty { 16408705d96Sshatty LOG(8,("SETMODE: target2 clock %dkHz\n",target2.timing.pixel_clock)); 16530f76422SRudolf Cornelissen if (head2_set_pix_pll(target2) == B_ERROR) 166a3b9d212SRudolf Cornelissen LOG(8,("SETMODE: error setting pixel clock (DAC2)\n")); 16708705d96Sshatty } 16808705d96Sshatty 16908705d96Sshatty /*set the colour depth for CRTC1 and the DAC */ 17008705d96Sshatty switch(target.space) 17108705d96Sshatty { 172bc5690abSRudolf Cornelissen case B_CMAP8: 173bc5690abSRudolf Cornelissen colour_depth1 = 8; 17430f76422SRudolf Cornelissen head1_mode(BPP8, 1.0); 1750669fe20SRudolf Cornelissen head1_depth(BPP8); 176bc5690abSRudolf Cornelissen break; 177bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 178bc5690abSRudolf Cornelissen colour_depth1 = 16; 17930f76422SRudolf Cornelissen head1_mode(BPP15, 1.0); 1800669fe20SRudolf Cornelissen head1_depth(BPP15); 181bc5690abSRudolf Cornelissen break; 18208705d96Sshatty case B_RGB16_LITTLE: 18308705d96Sshatty colour_depth1 = 16; 18430f76422SRudolf Cornelissen head1_mode(BPP16, 1.0); 1850669fe20SRudolf Cornelissen head1_depth(BPP16); 18608705d96Sshatty break; 18708705d96Sshatty case B_RGB32_LITTLE: 18808705d96Sshatty colour_depth1 = 32; 18930f76422SRudolf Cornelissen head1_mode(BPP32, 1.0); 1900669fe20SRudolf Cornelissen head1_depth(BPP32); 19108705d96Sshatty break; 19208705d96Sshatty } 193a3b9d212SRudolf Cornelissen /*set the colour depth for CRTC2 and DAC2 */ 19408705d96Sshatty switch(target2.space) 19508705d96Sshatty { 196bc5690abSRudolf Cornelissen case B_CMAP8: 197bc5690abSRudolf Cornelissen colour_depth2 = 8; 19830f76422SRudolf Cornelissen head2_mode(BPP8, 1.0); 1990669fe20SRudolf Cornelissen head2_depth(BPP8); 200bc5690abSRudolf Cornelissen break; 201bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 202bc5690abSRudolf Cornelissen colour_depth2 = 16; 20330f76422SRudolf Cornelissen head2_mode(BPP15, 1.0); 2040669fe20SRudolf Cornelissen head2_depth(BPP15); 205bc5690abSRudolf Cornelissen break; 20608705d96Sshatty case B_RGB16_LITTLE: 20708705d96Sshatty colour_depth2 = 16; 20830f76422SRudolf Cornelissen head2_mode(BPP16, 1.0); 2090669fe20SRudolf Cornelissen head2_depth(BPP16); 21008705d96Sshatty break; 21108705d96Sshatty case B_RGB32_LITTLE: 21208705d96Sshatty colour_depth2 = 32; 21330f76422SRudolf Cornelissen head2_mode(BPP32, 1.0); 2140669fe20SRudolf Cornelissen head2_depth(BPP32); 21508705d96Sshatty break; 21608705d96Sshatty } 21708705d96Sshatty 21808705d96Sshatty /* check if we are doing interlaced TVout mode */ 219b2459715SRudolf Cornelissen //fixme: we don't support interlaced mode? 22008705d96Sshatty si->interlaced_tv_mode = false; 22108705d96Sshatty /* if ((target2.flags & TV_BITS) && (si->ps.card_type >= G450)) 22208705d96Sshatty si->interlaced_tv_mode = true; 22308705d96Sshatty */ 22408705d96Sshatty /*set the display(s) pitches*/ 2250669fe20SRudolf Cornelissen head1_set_display_pitch (); 22608705d96Sshatty //fixme: seperate for real dualhead modes: 22708705d96Sshatty //we need a secondary si->fbc! 2280669fe20SRudolf Cornelissen head2_set_display_pitch (); 22908705d96Sshatty 23008705d96Sshatty /*work out where the "right" screen starts*/ 23108705d96Sshatty startadd_right = startadd + (target.timing.h_display * (colour_depth1 >> 3)); 23208705d96Sshatty 23308705d96Sshatty /* Tell card what memory to display */ 23408705d96Sshatty switch (target.flags & DUALHEAD_BITS) 23508705d96Sshatty { 23608705d96Sshatty case DUALHEAD_ON: 23708705d96Sshatty case DUALHEAD_SWITCH: 2380669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2390669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth2); 24008705d96Sshatty break; 24108705d96Sshatty case DUALHEAD_CLONE: 2420669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2430669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth2); 24408705d96Sshatty break; 24508705d96Sshatty } 24608705d96Sshatty 24708705d96Sshatty /* set the timing */ 2480669fe20SRudolf Cornelissen head1_set_timing(target); 24908705d96Sshatty /* we do not need to setup CRTC2 here for a head that's in TVout mode */ 2500669fe20SRudolf Cornelissen if (!(target2.flags & TV_BITS)) result = head2_set_timing(target2); 25108705d96Sshatty 25208705d96Sshatty /* TVout support: setup CRTC2 and it's pixelclock */ 253b2459715SRudolf Cornelissen if (si->ps.tvout && (target2.flags & TV_BITS)) BT_setmode(target2); 25408705d96Sshatty } 25508705d96Sshatty else /* single head mode */ 25608705d96Sshatty { 25708705d96Sshatty status_t status; 25808705d96Sshatty int colour_mode = BPP32; 25908705d96Sshatty 26030f76422SRudolf Cornelissen /* connect output */ 26130f76422SRudolf Cornelissen if (si->ps.secondary_head) 26230f76422SRudolf Cornelissen { 26330f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 26430f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 26530f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 26630f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 26730f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 26830f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 26930f76422SRudolf Cornelissen // if (crt1) 27030f76422SRudolf Cornelissen // { 27130f76422SRudolf Cornelissen /* connector1 is used as primary output */ 27230f76422SRudolf Cornelissen // cross = false; 27330f76422SRudolf Cornelissen // } 27430f76422SRudolf Cornelissen // else 27530f76422SRudolf Cornelissen // { 27630f76422SRudolf Cornelissen // if (crt2) 27730f76422SRudolf Cornelissen /* connector2 is used as primary output */ 27830f76422SRudolf Cornelissen // cross = true; 27930f76422SRudolf Cornelissen // else 28030f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 28130f76422SRudolf Cornelissen // cross = false; 28230f76422SRudolf Cornelissen // } 28330f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 28406f4c439SRudolf Cornelissen nv_general_head_select(false); 28530f76422SRudolf Cornelissen } 28630f76422SRudolf Cornelissen 28708705d96Sshatty switch(target.space) 28808705d96Sshatty { 28908705d96Sshatty case B_CMAP8: colour_depth1 = 8; colour_mode = BPP8; break; 29008705d96Sshatty case B_RGB15_LITTLE: colour_depth1 = 16; colour_mode = BPP15; break; 29108705d96Sshatty case B_RGB16_LITTLE: colour_depth1 = 16; colour_mode = BPP16; break; 29208705d96Sshatty case B_RGB32_LITTLE: colour_depth1 = 32; colour_mode = BPP32; break; 29308705d96Sshatty default: 29408705d96Sshatty LOG(8,("SETMODE: Invalid singlehead colour depth 0x%08x\n", target.space)); 29508705d96Sshatty return B_ERROR; 29608705d96Sshatty } 29708705d96Sshatty 29808705d96Sshatty /* set the pixel clock PLL */ 29930f76422SRudolf Cornelissen status = head1_set_pix_pll(target); 30008705d96Sshatty 30108705d96Sshatty if (status==B_ERROR) 30208705d96Sshatty LOG(8,("CRTC: error setting pixel clock (internal DAC)\n")); 30308705d96Sshatty 30408705d96Sshatty /* set the colour depth for CRTC1 and the DAC */ 30508705d96Sshatty /* first set the colordepth */ 3060669fe20SRudolf Cornelissen head1_depth(colour_mode); 30708705d96Sshatty /* then(!) program the PAL (<8bit colordepth does not support 8bit PAL) */ 30830f76422SRudolf Cornelissen head1_mode(colour_mode,1.0); 30908705d96Sshatty 31008705d96Sshatty /* set the display pitch */ 3110669fe20SRudolf Cornelissen head1_set_display_pitch(); 31208705d96Sshatty 31308705d96Sshatty /* tell the card what memory to display */ 3140669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 31508705d96Sshatty 31608705d96Sshatty /* set the timing */ 317b2459715SRudolf Cornelissen if (!(target.flags & TV_BITS)) head1_set_timing(target); 318b2459715SRudolf Cornelissen 319b2459715SRudolf Cornelissen /* TVout support: setup CRTC and it's pixelclock */ 320b2459715SRudolf Cornelissen if (si->ps.tvout && (target.flags & TV_BITS)) BT_setmode(target); 32108705d96Sshatty 32208705d96Sshatty //fixme: shut-off the videoPLL if it exists... 32308705d96Sshatty } 32408705d96Sshatty 32508705d96Sshatty /* update driver's mode store */ 32608705d96Sshatty si->dm = target; 32708705d96Sshatty 3283c4c0505SRudolf Cornelissen /* update FIFO data fetching according to mode */ 3293c4c0505SRudolf Cornelissen nv_crtc_update_fifo(); 3303c4c0505SRudolf Cornelissen 33108705d96Sshatty /* set up acceleration for this mode */ 332dd43fd34SRudolf Cornelissen /* note: 3333c4c0505SRudolf Cornelissen * Maybe later we can forget about non-DMA mode (depends on 3D acceleration 3343c4c0505SRudolf Cornelissen * attempts). */ 335dd446dd3SRudolf Cornelissen if (!si->settings.dma_acc) 336b4c44701Sshatty nv_acc_init(); 337dd43fd34SRudolf Cornelissen else 338dd43fd34SRudolf Cornelissen nv_acc_init_dma(); 339b4c44701Sshatty /* set up overlay unit for this mode */ 340aa1e552fSshatty nv_bes_init(); 34108705d96Sshatty 34289d37d46SRudolf Cornelissen /* note freemem range */ 34389d37d46SRudolf Cornelissen /* first free adress follows hardcursor and workspace */ 34421545d00SRudolf Cornelissen si->engine.threeD.mem_low = si->fbc.bytes_per_row * si->dm.virtual_height; 34521545d00SRudolf Cornelissen if (si->settings.hardcursor) si->engine.threeD.mem_low += 2048; 34689d37d46SRudolf Cornelissen /* last free adress is end-of-ram minus max space needed for overlay bitmaps */ 34789d37d46SRudolf Cornelissen //fixme possible: 34889d37d46SRudolf Cornelissen //if overlay buffers are allocated subtract buffersize from mem_high; 34989d37d46SRudolf Cornelissen //only allocate overlay buffers if 3D is not in use. (block overlay during 3D) 35021545d00SRudolf Cornelissen si->engine.threeD.mem_high = si->ps.memory_size - 1; 351fee251bcSRudolf Cornelissen /* don't touch the DMA acceleration engine command buffer if it exists */ 352fee251bcSRudolf Cornelissen /* note: 353fdd699c7SRudolf Cornelissen * the buffer is 32kB in size. Keep some extra distance for safety (faulty apps). */ 354fdd699c7SRudolf Cornelissen if (si->settings.dma_acc) 355fdd699c7SRudolf Cornelissen { 356fdd699c7SRudolf Cornelissen if (si->ps.card_arch < NV40A) 357fdd699c7SRudolf Cornelissen { 358fdd699c7SRudolf Cornelissen /* keeping 32kB distance from the DMA buffer */ 35921545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (64 * 1024); 360fdd699c7SRudolf Cornelissen } 361fdd699c7SRudolf Cornelissen else 362fdd699c7SRudolf Cornelissen { 363fdd699c7SRudolf Cornelissen /* 416kB distance is just OK: keeping another 64kB distance for safety; 364fdd699c7SRudolf Cornelissen * confirmed for NV43. */ 365fdd699c7SRudolf Cornelissen /* note: 366fdd699c7SRudolf Cornelissen * if you get too close to the DMA command buffer on NV40 and NV43 at 367fdd699c7SRudolf Cornelissen * least (both confirmed), the source DMA instance will mess-up for 368fdd699c7SRudolf Cornelissen * at least engine cmd NV_IMAGE_BLIT and NV12_IMAGE_BLIT. */ 36921545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (512 * 1024); 370fdd699c7SRudolf Cornelissen } 371fdd699c7SRudolf Cornelissen } 37221545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (MAXBUFFERS * 1024 * 1024 * 2); /* see overlay.c file */ 37389d37d46SRudolf Cornelissen 374bfecd0cdSRudolf Cornelissen /* restore screen(s) output state(s) */ 375bfecd0cdSRudolf Cornelissen SET_DPMS_MODE(si->dpms_flags); 37608705d96Sshatty 37708705d96Sshatty /* enable interrupts using the kernel driver */ 37808705d96Sshatty interrupt_enable(true); 37908705d96Sshatty 380c9c0c72bSRudolf Cornelissen /* make sure a possible 3D add-on will re-initialize itself by signalling ready */ 38121545d00SRudolf Cornelissen si->engine.threeD.mode_changing = false; 382c9c0c72bSRudolf Cornelissen 38308705d96Sshatty /* optimize memory-access if needed */ 3840669fe20SRudolf Cornelissen // head1_mem_priority(colour_depth1); 38508705d96Sshatty 38608705d96Sshatty /* Tune RAM CAS-latency if needed. Must be done *here*! */ 38708705d96Sshatty nv_set_cas_latency(); 38808705d96Sshatty 389bfecd0cdSRudolf Cornelissen LOG(1,("SETMODE: booted since %f mS\n", system_time()/1000.0)); 390bfecd0cdSRudolf Cornelissen 39108705d96Sshatty return B_OK; 39208705d96Sshatty } 39308705d96Sshatty 39408705d96Sshatty /* 39508705d96Sshatty Set which pixel of the virtual frame buffer will show up in the 39608705d96Sshatty top left corner of the display device. Used for page-flipping 39708705d96Sshatty games and virtual desktops. 39808705d96Sshatty */ 39908705d96Sshatty status_t MOVE_DISPLAY(uint16 h_display_start, uint16 v_display_start) { 40008705d96Sshatty uint8 colour_depth; 40108705d96Sshatty uint32 startadd,startadd_right; 40208705d96Sshatty 40308705d96Sshatty LOG(4,("MOVE_DISPLAY: h %d, v %d\n", h_display_start, v_display_start)); 40408705d96Sshatty 405255e5021SRudolf Cornelissen /* nVidia cards support pixelprecise panning on both heads in all modes: 406255e5021SRudolf Cornelissen * No stepping granularity needed! */ 407255e5021SRudolf Cornelissen 408255e5021SRudolf Cornelissen /* determine bits used for the colordepth */ 40908705d96Sshatty switch(si->dm.space) 41008705d96Sshatty { 41108705d96Sshatty case B_CMAP8: 41208705d96Sshatty colour_depth=8; 41308705d96Sshatty break; 414255e5021SRudolf Cornelissen case B_RGB15_LITTLE: 415255e5021SRudolf Cornelissen case B_RGB16_LITTLE: 41608705d96Sshatty colour_depth=16; 417255e5021SRudolf Cornelissen break; 418255e5021SRudolf Cornelissen case B_RGB24_LITTLE: 419255e5021SRudolf Cornelissen colour_depth=24; 42008705d96Sshatty break; 42108705d96Sshatty case B_RGB32_LITTLE: 42208705d96Sshatty colour_depth=32; 42308705d96Sshatty break; 42408705d96Sshatty default: 42508705d96Sshatty return B_ERROR; 42608705d96Sshatty } 42708705d96Sshatty 42808705d96Sshatty /* do not run past end of display */ 42908705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 43008705d96Sshatty { 43108705d96Sshatty case DUALHEAD_ON: 43208705d96Sshatty case DUALHEAD_SWITCH: 43308705d96Sshatty if (((si->dm.timing.h_display * 2) + h_display_start) > si->dm.virtual_width) 43408705d96Sshatty return B_ERROR; 43508705d96Sshatty break; 43608705d96Sshatty default: 43708705d96Sshatty if ((si->dm.timing.h_display + h_display_start) > si->dm.virtual_width) 43808705d96Sshatty return B_ERROR; 43908705d96Sshatty break; 44008705d96Sshatty } 44108705d96Sshatty if ((si->dm.timing.v_display + v_display_start) > si->dm.virtual_height) 44208705d96Sshatty return B_ERROR; 44308705d96Sshatty 44408705d96Sshatty /* everybody remember where we parked... */ 44508705d96Sshatty si->dm.h_display_start = h_display_start; 44608705d96Sshatty si->dm.v_display_start = v_display_start; 44708705d96Sshatty 44808705d96Sshatty /* actually set the registers */ 44908705d96Sshatty //fixme: seperate both heads: we need a secondary si->fbc! 45008705d96Sshatty startadd = v_display_start * si->fbc.bytes_per_row; 45108705d96Sshatty startadd += h_display_start * (colour_depth >> 3); 452f2777ca1SRudolf Cornelissen startadd += (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 45308705d96Sshatty startadd_right = startadd + si->dm.timing.h_display * (colour_depth >> 3); 45408705d96Sshatty 45508705d96Sshatty interrupt_enable(false); 45608705d96Sshatty 45708705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 45808705d96Sshatty { 45908705d96Sshatty case DUALHEAD_ON: 46008705d96Sshatty case DUALHEAD_SWITCH: 4610669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4620669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth); 46308705d96Sshatty break; 46408705d96Sshatty case DUALHEAD_OFF: 4650669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 46608705d96Sshatty break; 46708705d96Sshatty case DUALHEAD_CLONE: 4680669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4690669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth); 47008705d96Sshatty break; 47108705d96Sshatty } 47208705d96Sshatty 47308705d96Sshatty interrupt_enable(true); 47408705d96Sshatty return B_OK; 47508705d96Sshatty } 47608705d96Sshatty 477255e5021SRudolf Cornelissen /* Set the indexed color palette */ 47808705d96Sshatty void SET_INDEXED_COLORS(uint count, uint8 first, uint8 *color_data, uint32 flags) { 47908705d96Sshatty int i; 48008705d96Sshatty uint8 *r,*g,*b; 48108705d96Sshatty 48208705d96Sshatty /* Protect gamma correction when not in CMAP8 */ 48308705d96Sshatty if (si->dm.space != B_CMAP8) return; 48408705d96Sshatty 48508705d96Sshatty r=si->color_data; 48608705d96Sshatty g=r+256; 48708705d96Sshatty b=g+256; 48808705d96Sshatty 48908705d96Sshatty i=first; 49008705d96Sshatty while (count--) 49108705d96Sshatty { 49208705d96Sshatty r[i]=*color_data++; 49308705d96Sshatty g[i]=*color_data++; 49408705d96Sshatty b[i]=*color_data++; 49508705d96Sshatty i++; 49608705d96Sshatty } 49730f76422SRudolf Cornelissen head1_palette(r,g,b); 49830f76422SRudolf Cornelissen if (si->dm.flags & DUALHEAD_BITS) head2_palette(r,g,b); 49908705d96Sshatty } 50008705d96Sshatty 50108705d96Sshatty /* Put the display into one of the Display Power Management modes. */ 502bfecd0cdSRudolf Cornelissen status_t SET_DPMS_MODE(uint32 dpms_flags) 503bfecd0cdSRudolf Cornelissen { 504*20603b95SRudolf Cornelissen bool display, h1h, h1v, h2h, h2v; 505*20603b95SRudolf Cornelissen 50608705d96Sshatty interrupt_enable(false); 50708705d96Sshatty 50808705d96Sshatty LOG(4,("SET_DPMS_MODE: 0x%08x\n", dpms_flags)); 50908705d96Sshatty 510bfecd0cdSRudolf Cornelissen /* note current DPMS state for our reference */ 511bfecd0cdSRudolf Cornelissen si->dpms_flags = dpms_flags; 512bfecd0cdSRudolf Cornelissen 513*20603b95SRudolf Cornelissen /* determine signals to send to head(s) */ 514*20603b95SRudolf Cornelissen display = h1h = h1v = h2h = h2v = true; 51508705d96Sshatty switch(dpms_flags) 51608705d96Sshatty { 51708705d96Sshatty case B_DPMS_ON: /* H: on, V: on, display on */ 51808705d96Sshatty break; 51908705d96Sshatty case B_DPMS_STAND_BY: 520*20603b95SRudolf Cornelissen display = h1h = h2h = false; 52108705d96Sshatty break; 52208705d96Sshatty case B_DPMS_SUSPEND: 523*20603b95SRudolf Cornelissen display = h1v = h2v = false; 52408705d96Sshatty break; 52508705d96Sshatty case B_DPMS_OFF: /* H: off, V: off, display off */ 526*20603b95SRudolf Cornelissen display = h1h = h1v = h2h = h2v = false; 52708705d96Sshatty break; 52808705d96Sshatty default: 52908705d96Sshatty LOG(8,("SET: Invalid DPMS settings (DH) 0x%08x\n", dpms_flags)); 53008705d96Sshatty interrupt_enable(true); 53108705d96Sshatty return B_ERROR; 53208705d96Sshatty } 533*20603b95SRudolf Cornelissen 534*20603b95SRudolf Cornelissen /* CRTC used for TVout needs specific DPMS programming */ 535*20603b95SRudolf Cornelissen //fixme: assuming tvout is on head1, while head assignment is straight!! 536*20603b95SRudolf Cornelissen if (si->dm.flags & TV_BITS) 53708705d96Sshatty { 538*20603b95SRudolf Cornelissen LOG(4,("SET_DPMS_MODE: tuning DPMS settings for TVout compatibility\n")); 539*20603b95SRudolf Cornelissen 540*20603b95SRudolf Cornelissen if (!(si->settings.vga_on_tv)) 54108705d96Sshatty { 542*20603b95SRudolf Cornelissen /* block VGA output on head displaying on TV */ 543*20603b95SRudolf Cornelissen /* Note: 544*20603b95SRudolf Cornelissen * this specific sync setting is required: Vsync is used to keep TVout 545*20603b95SRudolf Cornelissen * synchronized to the CRTC 'vertically' (otherwise 'rolling' occurs). 546*20603b95SRudolf Cornelissen * This leaves Hsync only for shutting off the VGA screen. */ 547*20603b95SRudolf Cornelissen h1h = false; 548*20603b95SRudolf Cornelissen h1v = true; 549*20603b95SRudolf Cornelissen } 550*20603b95SRudolf Cornelissen else 551*20603b95SRudolf Cornelissen { 552*20603b95SRudolf Cornelissen /* when concurrent VGA is used alongside TVout on a head, DPMS is safest 553*20603b95SRudolf Cornelissen * applied this way: Vsync is needed for stopping TVout successfully when 554*20603b95SRudolf Cornelissen * a (new) modeswitch occurs. 555*20603b95SRudolf Cornelissen * (see routine BT_stop_tvout() in nv_brooktreetv.c) */ 556*20603b95SRudolf Cornelissen /* Note: 557*20603b95SRudolf Cornelissen * applying 'normal' DPMS here and forcing Vsync on in the above mentioned 558*20603b95SRudolf Cornelissen * routine seems to not always be enough: sometimes image generation will 559*20603b95SRudolf Cornelissen * not resume in that case. */ 560*20603b95SRudolf Cornelissen h1h = display; 561*20603b95SRudolf Cornelissen h1v = true; 56208705d96Sshatty } 56308705d96Sshatty } 5643aa21459SRudolf Cornelissen 565*20603b95SRudolf Cornelissen /* issue actual DPMS commands as far as applicable */ 566*20603b95SRudolf Cornelissen head1_dpms(display, h1h, h1v); 567*20603b95SRudolf Cornelissen if ((si->ps.secondary_head) && (si->dm.flags & DUALHEAD_BITS)) 568*20603b95SRudolf Cornelissen head2_dpms(display, h2h, h2v); 569*20603b95SRudolf Cornelissen if (si->dm.flags & TV_BITS) 570*20603b95SRudolf Cornelissen BT_dpms(display); 571*20603b95SRudolf Cornelissen 57208705d96Sshatty interrupt_enable(true); 57308705d96Sshatty return B_OK; 57408705d96Sshatty } 57508705d96Sshatty 57608705d96Sshatty /* Report device DPMS capabilities */ 577*20603b95SRudolf Cornelissen uint32 DPMS_CAPABILITIES(void) 578*20603b95SRudolf Cornelissen { 57908705d96Sshatty return (B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF); 58008705d96Sshatty } 58108705d96Sshatty 58208705d96Sshatty /* Return the current DPMS mode */ 583bfecd0cdSRudolf Cornelissen uint32 DPMS_MODE(void) 584bfecd0cdSRudolf Cornelissen { 585bfecd0cdSRudolf Cornelissen return si->dpms_flags; 58608705d96Sshatty } 587