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 */ 2008705d96Sshatty static void interrupt_enable(bool flag) { 2108705d96Sshatty status_t result; 2208705d96Sshatty nv_set_bool_state sbs; 2308705d96Sshatty 2408705d96Sshatty /* set the magic number so the driver knows we're for real */ 2508705d96Sshatty sbs.magic = NV_PRIVATE_DATA_MAGIC; 2608705d96Sshatty sbs.do_it = flag; 2708705d96Sshatty /* contact driver and get a pointer to the registers and shared data */ 2808705d96Sshatty result = ioctl(fd, NV_RUN_INTERRUPTS, &sbs, sizeof(sbs)); 2908705d96Sshatty } 3008705d96Sshatty 3108705d96Sshatty /* First validate the mode, then call lots of bit banging stuff to set the mode(s)! */ 3208705d96Sshatty status_t SET_DISPLAY_MODE(display_mode *mode_to_set) 3308705d96Sshatty { 3408705d96Sshatty /* BOUNDS WARNING: 3508705d96Sshatty * It's impossible to deviate whatever small amount in a display_mode if the lower 3608705d96Sshatty * and upper limits are the same! 3708705d96Sshatty * Besides: 3808705d96Sshatty * BeOS (tested R5.0.3PE) is failing BWindowScreen::SetFrameBuffer() if PROPOSEMODE 3908705d96Sshatty * returns B_BAD_VALUE! 4008705d96Sshatty * Which means PROPOSEMODE should not return that on anything except on 4108705d96Sshatty * deviations for: 4208705d96Sshatty * display_mode.virtual_width; 4308705d96Sshatty * display_mode.virtual_height; 4408705d96Sshatty * display_mode.timing.h_display; 4508705d96Sshatty * display_mode.timing.v_display; 4608705d96Sshatty * So: 4708705d96Sshatty * We don't use bounds here by making sure bounds and target are the same struct! 4808705d96Sshatty * (See the call to PROPOSE_DISPLAY_MODE below) */ 4908705d96Sshatty display_mode /*bounds,*/ target; 5008705d96Sshatty 5108705d96Sshatty uint8 colour_depth1 = 32; 5208705d96Sshatty status_t result; 5308705d96Sshatty uint32 startadd,startadd_right; 5408705d96Sshatty bool display, h, v; 5530f76422SRudolf Cornelissen // bool crt1, crt2, cross; 5608705d96Sshatty 5708705d96Sshatty /* Adjust mode to valid one and fail if invalid */ 5808705d96Sshatty target /*= bounds*/ = *mode_to_set; 5908705d96Sshatty /* show the mode bits */ 6008705d96Sshatty LOG(1, ("SETMODE: (ENTER) initial modeflags: $%08x\n", target.flags)); 6108705d96Sshatty LOG(1, ("SETMODE: requested target pixelclock %dkHz\n", target.timing.pixel_clock)); 6208705d96Sshatty LOG(1, ("SETMODE: requested virtual_width %d, virtual_height %d\n", 6308705d96Sshatty target.virtual_width, target.virtual_height)); 6408705d96Sshatty 6508705d96Sshatty /* See BOUNDS WARNING above... */ 6608705d96Sshatty if (PROPOSE_DISPLAY_MODE(&target, &target, &target) == B_ERROR) return B_ERROR; 6708705d96Sshatty 6808705d96Sshatty /* if not dualhead capable card clear dualhead flags */ 6908705d96Sshatty if (!(target.flags & DUALHEAD_CAPABLE)) 7008705d96Sshatty { 7108705d96Sshatty target.flags &= ~DUALHEAD_BITS; 7208705d96Sshatty } 7308705d96Sshatty /* if not TVout capable card clear TVout flags */ 7408705d96Sshatty if (!(target.flags & TV_CAPABLE)) 7508705d96Sshatty { 7608705d96Sshatty target.flags &= ~TV_BITS; 7708705d96Sshatty } 7808705d96Sshatty LOG(1, ("SETMODE: (CONT.) validated command modeflags: $%08x\n", target.flags)); 7908705d96Sshatty 80c9c0c72bSRudolf Cornelissen /* make sure a possible 3D add-on will block rendering and re-initialize itself. 81c9c0c72bSRudolf Cornelissen * note: update in _this_ order only */ 82c9c0c72bSRudolf Cornelissen /* SET_DISPLAY_MODE will reset this flag when it's done. */ 8321545d00SRudolf Cornelissen si->engine.threeD.mode_changing = true; 8421545d00SRudolf Cornelissen /* every 3D add-on will reset this bit-flag when it's done. */ 8521545d00SRudolf Cornelissen si->engine.threeD.newmode = 0xffffffff; 8621545d00SRudolf Cornelissen /* every 3D clone needs to reclaim a slot. 8721545d00SRudolf Cornelissen * note: this also cleans up reserved channels for killed 3D clones.. */ 8821545d00SRudolf Cornelissen si->engine.threeD.clones = 0x00000000; 89afb207acSRudolf Cornelissen 9008705d96Sshatty /* disable interrupts using the kernel driver */ 9108705d96Sshatty interrupt_enable(false); 9208705d96Sshatty 93*0703480cSRudolf Cornelissen /* disable TVout if supported */ 94*0703480cSRudolf Cornelissen if (si->ps.tvout) BT_stop_tvout(); 950b36eea4SRudolf Cornelissen 9608705d96Sshatty /* find current DPMS state, then turn off screen(s) */ 970669fe20SRudolf Cornelissen head1_dpms_fetch(&display, &h, &v); 980669fe20SRudolf Cornelissen head1_dpms(false, false, false); 990669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, false); 10008705d96Sshatty 10108705d96Sshatty /*where in framebuffer the screen is (should this be dependant on previous MOVEDISPLAY?)*/ 102f2777ca1SRudolf Cornelissen startadd = (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 10308705d96Sshatty 10408705d96Sshatty /* calculate and set new mode bytes_per_row */ 10505ed3229SRudolf Cornelissen nv_general_validate_pic_size (&target, &si->fbc.bytes_per_row, &si->acc_mode); 10608705d96Sshatty 10708705d96Sshatty /*Perform the very long mode switch!*/ 10808705d96Sshatty if (target.flags & DUALHEAD_BITS) /*if some dualhead mode*/ 10908705d96Sshatty { 11008705d96Sshatty uint8 colour_depth2 = colour_depth1; 11108705d96Sshatty 11208705d96Sshatty /* init display mode for secondary head */ 11308705d96Sshatty display_mode target2 = target; 11408705d96Sshatty 11508705d96Sshatty LOG(1,("SETMODE: setting DUALHEAD mode\n")); 11608705d96Sshatty 11708705d96Sshatty /* validate flags for secondary TVout */ 118b2459715SRudolf Cornelissen //fixme: remove or block on autodetect fail. (is now shutoff) 119b2459715SRudolf Cornelissen if ((0) && (target2.flags & TV_BITS)) 12008705d96Sshatty { 12108705d96Sshatty target.flags &= ~TV_BITS;//still needed for some routines... 12208705d96Sshatty target2.flags &= ~TV_BITS; 12308705d96Sshatty LOG(1,("SETMODE: blocking TVout: no TVout cable connected!\n")); 12408705d96Sshatty } 12508705d96Sshatty 12630f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 12730f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 12830f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 12930f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 13030f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 13130f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 13230f76422SRudolf Cornelissen // if (crt1) 13330f76422SRudolf Cornelissen // { 13430f76422SRudolf Cornelissen /* connector1 is used as primary output */ 13530f76422SRudolf Cornelissen // cross = false; 13630f76422SRudolf Cornelissen // } 13730f76422SRudolf Cornelissen // else 13830f76422SRudolf Cornelissen // { 13930f76422SRudolf Cornelissen // if (crt2) 14030f76422SRudolf Cornelissen /* connector2 is used as primary output */ 14130f76422SRudolf Cornelissen // cross = true; 14230f76422SRudolf Cornelissen // else 14330f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 14430f76422SRudolf Cornelissen // cross = false; 14530f76422SRudolf Cornelissen // } 14630f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 14730f76422SRudolf Cornelissen if ((target.flags & DUALHEAD_BITS) == DUALHEAD_SWITCH) 14830f76422SRudolf Cornelissen /* invert output assignment in switch mode */ 14906f4c439SRudolf Cornelissen nv_general_head_select(true); 15030f76422SRudolf Cornelissen else 15106f4c439SRudolf Cornelissen nv_general_head_select(false); 15230f76422SRudolf Cornelissen 15308705d96Sshatty /* set the pixel clock PLL(s) */ 15408705d96Sshatty LOG(8,("SETMODE: target clock %dkHz\n",target.timing.pixel_clock)); 15530f76422SRudolf Cornelissen if (head1_set_pix_pll(target) == B_ERROR) 15608705d96Sshatty LOG(8,("SETMODE: error setting pixel clock (internal DAC)\n")); 15708705d96Sshatty 15808705d96Sshatty /* we do not need to set the pixelclock here for a head that's in TVout mode */ 15908705d96Sshatty if (!(target2.flags & TV_BITS)) 16008705d96Sshatty { 16108705d96Sshatty LOG(8,("SETMODE: target2 clock %dkHz\n",target2.timing.pixel_clock)); 16230f76422SRudolf Cornelissen if (head2_set_pix_pll(target2) == B_ERROR) 163a3b9d212SRudolf Cornelissen LOG(8,("SETMODE: error setting pixel clock (DAC2)\n")); 16408705d96Sshatty } 16508705d96Sshatty 16608705d96Sshatty /*set the colour depth for CRTC1 and the DAC */ 16708705d96Sshatty switch(target.space) 16808705d96Sshatty { 169bc5690abSRudolf Cornelissen case B_CMAP8: 170bc5690abSRudolf Cornelissen colour_depth1 = 8; 17130f76422SRudolf Cornelissen head1_mode(BPP8, 1.0); 1720669fe20SRudolf Cornelissen head1_depth(BPP8); 173bc5690abSRudolf Cornelissen break; 174bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 175bc5690abSRudolf Cornelissen colour_depth1 = 16; 17630f76422SRudolf Cornelissen head1_mode(BPP15, 1.0); 1770669fe20SRudolf Cornelissen head1_depth(BPP15); 178bc5690abSRudolf Cornelissen break; 17908705d96Sshatty case B_RGB16_LITTLE: 18008705d96Sshatty colour_depth1 = 16; 18130f76422SRudolf Cornelissen head1_mode(BPP16, 1.0); 1820669fe20SRudolf Cornelissen head1_depth(BPP16); 18308705d96Sshatty break; 18408705d96Sshatty case B_RGB32_LITTLE: 18508705d96Sshatty colour_depth1 = 32; 18630f76422SRudolf Cornelissen head1_mode(BPP32, 1.0); 1870669fe20SRudolf Cornelissen head1_depth(BPP32); 18808705d96Sshatty break; 18908705d96Sshatty } 190a3b9d212SRudolf Cornelissen /*set the colour depth for CRTC2 and DAC2 */ 19108705d96Sshatty switch(target2.space) 19208705d96Sshatty { 193bc5690abSRudolf Cornelissen case B_CMAP8: 194bc5690abSRudolf Cornelissen colour_depth2 = 8; 19530f76422SRudolf Cornelissen head2_mode(BPP8, 1.0); 1960669fe20SRudolf Cornelissen head2_depth(BPP8); 197bc5690abSRudolf Cornelissen break; 198bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 199bc5690abSRudolf Cornelissen colour_depth2 = 16; 20030f76422SRudolf Cornelissen head2_mode(BPP15, 1.0); 2010669fe20SRudolf Cornelissen head2_depth(BPP15); 202bc5690abSRudolf Cornelissen break; 20308705d96Sshatty case B_RGB16_LITTLE: 20408705d96Sshatty colour_depth2 = 16; 20530f76422SRudolf Cornelissen head2_mode(BPP16, 1.0); 2060669fe20SRudolf Cornelissen head2_depth(BPP16); 20708705d96Sshatty break; 20808705d96Sshatty case B_RGB32_LITTLE: 20908705d96Sshatty colour_depth2 = 32; 21030f76422SRudolf Cornelissen head2_mode(BPP32, 1.0); 2110669fe20SRudolf Cornelissen head2_depth(BPP32); 21208705d96Sshatty break; 21308705d96Sshatty } 21408705d96Sshatty 21508705d96Sshatty /* check if we are doing interlaced TVout mode */ 216b2459715SRudolf Cornelissen //fixme: we don't support interlaced mode? 21708705d96Sshatty si->interlaced_tv_mode = false; 21808705d96Sshatty /* if ((target2.flags & TV_BITS) && (si->ps.card_type >= G450)) 21908705d96Sshatty si->interlaced_tv_mode = true; 22008705d96Sshatty */ 22108705d96Sshatty /*set the display(s) pitches*/ 2220669fe20SRudolf Cornelissen head1_set_display_pitch (); 22308705d96Sshatty //fixme: seperate for real dualhead modes: 22408705d96Sshatty //we need a secondary si->fbc! 2250669fe20SRudolf Cornelissen head2_set_display_pitch (); 22608705d96Sshatty 22708705d96Sshatty /*work out where the "right" screen starts*/ 22808705d96Sshatty startadd_right = startadd + (target.timing.h_display * (colour_depth1 >> 3)); 22908705d96Sshatty 23008705d96Sshatty /* Tell card what memory to display */ 23108705d96Sshatty switch (target.flags & DUALHEAD_BITS) 23208705d96Sshatty { 23308705d96Sshatty case DUALHEAD_ON: 23408705d96Sshatty case DUALHEAD_SWITCH: 2350669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2360669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth2); 23708705d96Sshatty break; 23808705d96Sshatty case DUALHEAD_CLONE: 2390669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2400669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth2); 24108705d96Sshatty break; 24208705d96Sshatty } 24308705d96Sshatty 24408705d96Sshatty /* set the timing */ 2450669fe20SRudolf Cornelissen head1_set_timing(target); 24608705d96Sshatty /* we do not need to setup CRTC2 here for a head that's in TVout mode */ 2470669fe20SRudolf Cornelissen if (!(target2.flags & TV_BITS)) result = head2_set_timing(target2); 24808705d96Sshatty 24908705d96Sshatty /* TVout support: setup CRTC2 and it's pixelclock */ 250b2459715SRudolf Cornelissen if (si->ps.tvout && (target2.flags & TV_BITS)) BT_setmode(target2); 25108705d96Sshatty } 25208705d96Sshatty else /* single head mode */ 25308705d96Sshatty { 25408705d96Sshatty status_t status; 25508705d96Sshatty int colour_mode = BPP32; 25608705d96Sshatty 25730f76422SRudolf Cornelissen /* connect output */ 25830f76422SRudolf Cornelissen if (si->ps.secondary_head) 25930f76422SRudolf Cornelissen { 26030f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 26130f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 26230f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 26330f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 26430f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 26530f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 26630f76422SRudolf Cornelissen // if (crt1) 26730f76422SRudolf Cornelissen // { 26830f76422SRudolf Cornelissen /* connector1 is used as primary output */ 26930f76422SRudolf Cornelissen // cross = false; 27030f76422SRudolf Cornelissen // } 27130f76422SRudolf Cornelissen // else 27230f76422SRudolf Cornelissen // { 27330f76422SRudolf Cornelissen // if (crt2) 27430f76422SRudolf Cornelissen /* connector2 is used as primary output */ 27530f76422SRudolf Cornelissen // cross = true; 27630f76422SRudolf Cornelissen // else 27730f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 27830f76422SRudolf Cornelissen // cross = false; 27930f76422SRudolf Cornelissen // } 28030f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 28106f4c439SRudolf Cornelissen nv_general_head_select(false); 28230f76422SRudolf Cornelissen } 28330f76422SRudolf Cornelissen 28408705d96Sshatty switch(target.space) 28508705d96Sshatty { 28608705d96Sshatty case B_CMAP8: colour_depth1 = 8; colour_mode = BPP8; break; 28708705d96Sshatty case B_RGB15_LITTLE: colour_depth1 = 16; colour_mode = BPP15; break; 28808705d96Sshatty case B_RGB16_LITTLE: colour_depth1 = 16; colour_mode = BPP16; break; 28908705d96Sshatty case B_RGB32_LITTLE: colour_depth1 = 32; colour_mode = BPP32; break; 29008705d96Sshatty default: 29108705d96Sshatty LOG(8,("SETMODE: Invalid singlehead colour depth 0x%08x\n", target.space)); 29208705d96Sshatty return B_ERROR; 29308705d96Sshatty } 29408705d96Sshatty 29508705d96Sshatty /* set the pixel clock PLL */ 29630f76422SRudolf Cornelissen status = head1_set_pix_pll(target); 29708705d96Sshatty 29808705d96Sshatty if (status==B_ERROR) 29908705d96Sshatty LOG(8,("CRTC: error setting pixel clock (internal DAC)\n")); 30008705d96Sshatty 30108705d96Sshatty /* set the colour depth for CRTC1 and the DAC */ 30208705d96Sshatty /* first set the colordepth */ 3030669fe20SRudolf Cornelissen head1_depth(colour_mode); 30408705d96Sshatty /* then(!) program the PAL (<8bit colordepth does not support 8bit PAL) */ 30530f76422SRudolf Cornelissen head1_mode(colour_mode,1.0); 30608705d96Sshatty 30708705d96Sshatty /* set the display pitch */ 3080669fe20SRudolf Cornelissen head1_set_display_pitch(); 30908705d96Sshatty 31008705d96Sshatty /* tell the card what memory to display */ 3110669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 31208705d96Sshatty 31308705d96Sshatty /* set the timing */ 314b2459715SRudolf Cornelissen if (!(target.flags & TV_BITS)) head1_set_timing(target); 315b2459715SRudolf Cornelissen 316b2459715SRudolf Cornelissen /* TVout support: setup CRTC and it's pixelclock */ 317b2459715SRudolf Cornelissen if (si->ps.tvout && (target.flags & TV_BITS)) BT_setmode(target); 31808705d96Sshatty 31908705d96Sshatty //fixme: shut-off the videoPLL if it exists... 32008705d96Sshatty } 32108705d96Sshatty 32208705d96Sshatty /* update driver's mode store */ 32308705d96Sshatty si->dm = target; 32408705d96Sshatty 3253c4c0505SRudolf Cornelissen /* update FIFO data fetching according to mode */ 3263c4c0505SRudolf Cornelissen nv_crtc_update_fifo(); 3273c4c0505SRudolf Cornelissen 32808705d96Sshatty /* turn screen one on */ 3290669fe20SRudolf Cornelissen head1_dpms(display, h, v); 33008705d96Sshatty /* turn screen two on if a dualhead mode is active */ 3310669fe20SRudolf Cornelissen if (target.flags & DUALHEAD_BITS) head2_dpms(display,h,v); 33208705d96Sshatty 33308705d96Sshatty /* set up acceleration for this mode */ 334dd43fd34SRudolf Cornelissen /* note: 3353c4c0505SRudolf Cornelissen * Maybe later we can forget about non-DMA mode (depends on 3D acceleration 3363c4c0505SRudolf Cornelissen * attempts). */ 337dd446dd3SRudolf Cornelissen if (!si->settings.dma_acc) 338b4c44701Sshatty nv_acc_init(); 339dd43fd34SRudolf Cornelissen else 340dd43fd34SRudolf Cornelissen nv_acc_init_dma(); 341b4c44701Sshatty /* set up overlay unit for this mode */ 342aa1e552fSshatty nv_bes_init(); 34308705d96Sshatty 34489d37d46SRudolf Cornelissen /* note freemem range */ 34589d37d46SRudolf Cornelissen /* first free adress follows hardcursor and workspace */ 34621545d00SRudolf Cornelissen si->engine.threeD.mem_low = si->fbc.bytes_per_row * si->dm.virtual_height; 34721545d00SRudolf Cornelissen if (si->settings.hardcursor) si->engine.threeD.mem_low += 2048; 34889d37d46SRudolf Cornelissen /* last free adress is end-of-ram minus max space needed for overlay bitmaps */ 34989d37d46SRudolf Cornelissen //fixme possible: 35089d37d46SRudolf Cornelissen //if overlay buffers are allocated subtract buffersize from mem_high; 35189d37d46SRudolf Cornelissen //only allocate overlay buffers if 3D is not in use. (block overlay during 3D) 35221545d00SRudolf Cornelissen si->engine.threeD.mem_high = si->ps.memory_size - 1; 353fee251bcSRudolf Cornelissen /* don't touch the DMA acceleration engine command buffer if it exists */ 354fee251bcSRudolf Cornelissen /* note: 355fdd699c7SRudolf Cornelissen * the buffer is 32kB in size. Keep some extra distance for safety (faulty apps). */ 356fdd699c7SRudolf Cornelissen if (si->settings.dma_acc) 357fdd699c7SRudolf Cornelissen { 358fdd699c7SRudolf Cornelissen if (si->ps.card_arch < NV40A) 359fdd699c7SRudolf Cornelissen { 360fdd699c7SRudolf Cornelissen /* keeping 32kB distance from the DMA buffer */ 36121545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (64 * 1024); 362fdd699c7SRudolf Cornelissen } 363fdd699c7SRudolf Cornelissen else 364fdd699c7SRudolf Cornelissen { 365fdd699c7SRudolf Cornelissen /* 416kB distance is just OK: keeping another 64kB distance for safety; 366fdd699c7SRudolf Cornelissen * confirmed for NV43. */ 367fdd699c7SRudolf Cornelissen /* note: 368fdd699c7SRudolf Cornelissen * if you get too close to the DMA command buffer on NV40 and NV43 at 369fdd699c7SRudolf Cornelissen * least (both confirmed), the source DMA instance will mess-up for 370fdd699c7SRudolf Cornelissen * at least engine cmd NV_IMAGE_BLIT and NV12_IMAGE_BLIT. */ 37121545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (512 * 1024); 372fdd699c7SRudolf Cornelissen } 373fdd699c7SRudolf Cornelissen } 37421545d00SRudolf Cornelissen si->engine.threeD.mem_high -= (MAXBUFFERS * 1024 * 1024 * 2); /* see overlay.c file */ 37589d37d46SRudolf Cornelissen 376255e5021SRudolf Cornelissen LOG(1,("SETMODE: booted since %f mS\n", system_time()/1000.0)); 37708705d96Sshatty 37808705d96Sshatty /* enable interrupts using the kernel driver */ 37908705d96Sshatty interrupt_enable(true); 38008705d96Sshatty 381c9c0c72bSRudolf Cornelissen /* make sure a possible 3D add-on will re-initialize itself by signalling ready */ 38221545d00SRudolf Cornelissen si->engine.threeD.mode_changing = false; 383c9c0c72bSRudolf Cornelissen 38408705d96Sshatty /* optimize memory-access if needed */ 3850669fe20SRudolf Cornelissen // head1_mem_priority(colour_depth1); 38608705d96Sshatty 38708705d96Sshatty /* Tune RAM CAS-latency if needed. Must be done *here*! */ 38808705d96Sshatty nv_set_cas_latency(); 38908705d96Sshatty 39008705d96Sshatty return B_OK; 39108705d96Sshatty } 39208705d96Sshatty 39308705d96Sshatty /* 39408705d96Sshatty Set which pixel of the virtual frame buffer will show up in the 39508705d96Sshatty top left corner of the display device. Used for page-flipping 39608705d96Sshatty games and virtual desktops. 39708705d96Sshatty */ 39808705d96Sshatty status_t MOVE_DISPLAY(uint16 h_display_start, uint16 v_display_start) { 39908705d96Sshatty uint8 colour_depth; 40008705d96Sshatty uint32 startadd,startadd_right; 40108705d96Sshatty 40208705d96Sshatty LOG(4,("MOVE_DISPLAY: h %d, v %d\n", h_display_start, v_display_start)); 40308705d96Sshatty 404255e5021SRudolf Cornelissen /* nVidia cards support pixelprecise panning on both heads in all modes: 405255e5021SRudolf Cornelissen * No stepping granularity needed! */ 406255e5021SRudolf Cornelissen 407255e5021SRudolf Cornelissen /* determine bits used for the colordepth */ 40808705d96Sshatty switch(si->dm.space) 40908705d96Sshatty { 41008705d96Sshatty case B_CMAP8: 41108705d96Sshatty colour_depth=8; 41208705d96Sshatty break; 413255e5021SRudolf Cornelissen case B_RGB15_LITTLE: 414255e5021SRudolf Cornelissen case B_RGB16_LITTLE: 41508705d96Sshatty colour_depth=16; 416255e5021SRudolf Cornelissen break; 417255e5021SRudolf Cornelissen case B_RGB24_LITTLE: 418255e5021SRudolf Cornelissen colour_depth=24; 41908705d96Sshatty break; 42008705d96Sshatty case B_RGB32_LITTLE: 42108705d96Sshatty colour_depth=32; 42208705d96Sshatty break; 42308705d96Sshatty default: 42408705d96Sshatty return B_ERROR; 42508705d96Sshatty } 42608705d96Sshatty 42708705d96Sshatty /* do not run past end of display */ 42808705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 42908705d96Sshatty { 43008705d96Sshatty case DUALHEAD_ON: 43108705d96Sshatty case DUALHEAD_SWITCH: 43208705d96Sshatty if (((si->dm.timing.h_display * 2) + h_display_start) > si->dm.virtual_width) 43308705d96Sshatty return B_ERROR; 43408705d96Sshatty break; 43508705d96Sshatty default: 43608705d96Sshatty if ((si->dm.timing.h_display + h_display_start) > si->dm.virtual_width) 43708705d96Sshatty return B_ERROR; 43808705d96Sshatty break; 43908705d96Sshatty } 44008705d96Sshatty if ((si->dm.timing.v_display + v_display_start) > si->dm.virtual_height) 44108705d96Sshatty return B_ERROR; 44208705d96Sshatty 44308705d96Sshatty /* everybody remember where we parked... */ 44408705d96Sshatty si->dm.h_display_start = h_display_start; 44508705d96Sshatty si->dm.v_display_start = v_display_start; 44608705d96Sshatty 44708705d96Sshatty /* actually set the registers */ 44808705d96Sshatty //fixme: seperate both heads: we need a secondary si->fbc! 44908705d96Sshatty startadd = v_display_start * si->fbc.bytes_per_row; 45008705d96Sshatty startadd += h_display_start * (colour_depth >> 3); 451f2777ca1SRudolf Cornelissen startadd += (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 45208705d96Sshatty startadd_right = startadd + si->dm.timing.h_display * (colour_depth >> 3); 45308705d96Sshatty 45408705d96Sshatty interrupt_enable(false); 45508705d96Sshatty 45608705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 45708705d96Sshatty { 45808705d96Sshatty case DUALHEAD_ON: 45908705d96Sshatty case DUALHEAD_SWITCH: 4600669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4610669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth); 46208705d96Sshatty break; 46308705d96Sshatty case DUALHEAD_OFF: 4640669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 46508705d96Sshatty break; 46608705d96Sshatty case DUALHEAD_CLONE: 4670669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4680669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth); 46908705d96Sshatty break; 47008705d96Sshatty } 47108705d96Sshatty 47208705d96Sshatty interrupt_enable(true); 47308705d96Sshatty return B_OK; 47408705d96Sshatty } 47508705d96Sshatty 476255e5021SRudolf Cornelissen /* Set the indexed color palette */ 47708705d96Sshatty void SET_INDEXED_COLORS(uint count, uint8 first, uint8 *color_data, uint32 flags) { 47808705d96Sshatty int i; 47908705d96Sshatty uint8 *r,*g,*b; 48008705d96Sshatty 48108705d96Sshatty /* Protect gamma correction when not in CMAP8 */ 48208705d96Sshatty if (si->dm.space != B_CMAP8) return; 48308705d96Sshatty 48408705d96Sshatty r=si->color_data; 48508705d96Sshatty g=r+256; 48608705d96Sshatty b=g+256; 48708705d96Sshatty 48808705d96Sshatty i=first; 48908705d96Sshatty while (count--) 49008705d96Sshatty { 49108705d96Sshatty r[i]=*color_data++; 49208705d96Sshatty g[i]=*color_data++; 49308705d96Sshatty b[i]=*color_data++; 49408705d96Sshatty i++; 49508705d96Sshatty } 49630f76422SRudolf Cornelissen head1_palette(r,g,b); 49730f76422SRudolf Cornelissen if (si->dm.flags & DUALHEAD_BITS) head2_palette(r,g,b); 49808705d96Sshatty } 49908705d96Sshatty 50008705d96Sshatty /* Put the display into one of the Display Power Management modes. */ 50108705d96Sshatty status_t SET_DPMS_MODE(uint32 dpms_flags) { 50208705d96Sshatty interrupt_enable(false); 50308705d96Sshatty 50408705d96Sshatty LOG(4,("SET_DPMS_MODE: 0x%08x\n", dpms_flags)); 50508705d96Sshatty 50608705d96Sshatty if (si->dm.flags & DUALHEAD_BITS) /*dualhead*/ 50708705d96Sshatty { 50808705d96Sshatty switch(dpms_flags) 50908705d96Sshatty { 51008705d96Sshatty case B_DPMS_ON: /* H: on, V: on, display on */ 5110669fe20SRudolf Cornelissen head1_dpms(true, true, true); 5120669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(true, true, true); 51308705d96Sshatty break; 51408705d96Sshatty case B_DPMS_STAND_BY: 5150669fe20SRudolf Cornelissen head1_dpms(false, false, true); 5160669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, true); 51708705d96Sshatty break; 51808705d96Sshatty case B_DPMS_SUSPEND: 5190669fe20SRudolf Cornelissen head1_dpms(false, true, false); 5200669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, true, false); 52108705d96Sshatty break; 52208705d96Sshatty case B_DPMS_OFF: /* H: off, V: off, display off */ 5230669fe20SRudolf Cornelissen head1_dpms(false, false, false); 5240669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, false); 52508705d96Sshatty break; 52608705d96Sshatty default: 52708705d96Sshatty LOG(8,("SET: Invalid DPMS settings (DH) 0x%08x\n", dpms_flags)); 52808705d96Sshatty interrupt_enable(true); 52908705d96Sshatty return B_ERROR; 53008705d96Sshatty } 53108705d96Sshatty } 53208705d96Sshatty else /* singlehead */ 53308705d96Sshatty { 53408705d96Sshatty switch(dpms_flags) 53508705d96Sshatty { 53608705d96Sshatty case B_DPMS_ON: /* H: on, V: on, display on */ 5370669fe20SRudolf Cornelissen head1_dpms(true, true, true); 53808705d96Sshatty break; 53908705d96Sshatty case B_DPMS_STAND_BY: 5400669fe20SRudolf Cornelissen head1_dpms(false, false, true); 54108705d96Sshatty break; 54208705d96Sshatty case B_DPMS_SUSPEND: 5430669fe20SRudolf Cornelissen head1_dpms(false, true, false); 54408705d96Sshatty break; 54508705d96Sshatty case B_DPMS_OFF: /* H: off, V: off, display off */ 5460669fe20SRudolf Cornelissen head1_dpms(false, false, false); 54708705d96Sshatty break; 54808705d96Sshatty default: 54908705d96Sshatty LOG(8,("SET: Invalid DPMS settings (DH) 0x%08x\n", dpms_flags)); 55008705d96Sshatty interrupt_enable(true); 55108705d96Sshatty return B_ERROR; 55208705d96Sshatty } 55308705d96Sshatty } 55408705d96Sshatty interrupt_enable(true); 55508705d96Sshatty return B_OK; 55608705d96Sshatty } 55708705d96Sshatty 55808705d96Sshatty /* Report device DPMS capabilities */ 55908705d96Sshatty uint32 DPMS_CAPABILITIES(void) { 56008705d96Sshatty return (B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF); 56108705d96Sshatty } 56208705d96Sshatty 56308705d96Sshatty /* Return the current DPMS mode */ 56408705d96Sshatty uint32 DPMS_MODE(void) { 56508705d96Sshatty bool display, h, v; 56608705d96Sshatty 56708705d96Sshatty interrupt_enable(false); 5680669fe20SRudolf Cornelissen head1_dpms_fetch(&display, &h, &v); 56908705d96Sshatty interrupt_enable(true); 57008705d96Sshatty 57108705d96Sshatty if (display && h && v) 57208705d96Sshatty return B_DPMS_ON; 57308705d96Sshatty else if(v) 57408705d96Sshatty return B_DPMS_STAND_BY; 57508705d96Sshatty else if(h) 57608705d96Sshatty return B_DPMS_SUSPEND; 57708705d96Sshatty else 57808705d96Sshatty return B_DPMS_OFF; 57908705d96Sshatty } 580