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, 9*afb207acSRudolf Cornelissen Rudolf Cornelissen 11/2002-4/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 80*afb207acSRudolf Cornelissen /* make sure a possible 3D add-on will block rendering and re-initialize itself; 81*afb207acSRudolf Cornelissen * it will reset this flag when it's done. */ 82*afb207acSRudolf Cornelissen si->mode_changed = true; 83*afb207acSRudolf Cornelissen 8408705d96Sshatty /* disable interrupts using the kernel driver */ 8508705d96Sshatty interrupt_enable(false); 8608705d96Sshatty 8708705d96Sshatty /* find current DPMS state, then turn off screen(s) */ 880669fe20SRudolf Cornelissen head1_dpms_fetch(&display, &h, &v); 890669fe20SRudolf Cornelissen head1_dpms(false, false, false); 900669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, false); 9108705d96Sshatty 9208705d96Sshatty /*where in framebuffer the screen is (should this be dependant on previous MOVEDISPLAY?)*/ 93f2777ca1SRudolf Cornelissen startadd = (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 9408705d96Sshatty 9508705d96Sshatty /* calculate and set new mode bytes_per_row */ 9605ed3229SRudolf Cornelissen nv_general_validate_pic_size (&target, &si->fbc.bytes_per_row, &si->acc_mode); 9708705d96Sshatty 9808705d96Sshatty /*Perform the very long mode switch!*/ 9908705d96Sshatty if (target.flags & DUALHEAD_BITS) /*if some dualhead mode*/ 10008705d96Sshatty { 10108705d96Sshatty uint8 colour_depth2 = colour_depth1; 10208705d96Sshatty 10308705d96Sshatty /* init display mode for secondary head */ 10408705d96Sshatty display_mode target2 = target; 10508705d96Sshatty 10608705d96Sshatty LOG(1,("SETMODE: setting DUALHEAD mode\n")); 10708705d96Sshatty 10808705d96Sshatty /* validate flags for secondary TVout */ 10908705d96Sshatty if ((i2c_sec_tv_adapter() != B_OK) && (target2.flags & TV_BITS)) 11008705d96Sshatty { 11108705d96Sshatty target.flags &= ~TV_BITS;//still needed for some routines... 11208705d96Sshatty target2.flags &= ~TV_BITS; 11308705d96Sshatty LOG(1,("SETMODE: blocking TVout: no TVout cable connected!\n")); 11408705d96Sshatty } 11508705d96Sshatty 11630f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 11730f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 11830f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 11930f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 12030f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 12130f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 12230f76422SRudolf Cornelissen // if (crt1) 12330f76422SRudolf Cornelissen // { 12430f76422SRudolf Cornelissen /* connector1 is used as primary output */ 12530f76422SRudolf Cornelissen // cross = false; 12630f76422SRudolf Cornelissen // } 12730f76422SRudolf Cornelissen // else 12830f76422SRudolf Cornelissen // { 12930f76422SRudolf Cornelissen // if (crt2) 13030f76422SRudolf Cornelissen /* connector2 is used as primary output */ 13130f76422SRudolf Cornelissen // cross = true; 13230f76422SRudolf Cornelissen // else 13330f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 13430f76422SRudolf Cornelissen // cross = false; 13530f76422SRudolf Cornelissen // } 13630f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 13730f76422SRudolf Cornelissen if ((target.flags & DUALHEAD_BITS) == DUALHEAD_SWITCH) 13830f76422SRudolf Cornelissen /* invert output assignment in switch mode */ 13906f4c439SRudolf Cornelissen nv_general_head_select(true); 14030f76422SRudolf Cornelissen else 14106f4c439SRudolf Cornelissen nv_general_head_select(false); 14230f76422SRudolf Cornelissen 14308705d96Sshatty /* set the pixel clock PLL(s) */ 14408705d96Sshatty LOG(8,("SETMODE: target clock %dkHz\n",target.timing.pixel_clock)); 14530f76422SRudolf Cornelissen if (head1_set_pix_pll(target) == B_ERROR) 14608705d96Sshatty LOG(8,("SETMODE: error setting pixel clock (internal DAC)\n")); 14708705d96Sshatty 14808705d96Sshatty /* we do not need to set the pixelclock here for a head that's in TVout mode */ 14908705d96Sshatty if (!(target2.flags & TV_BITS)) 15008705d96Sshatty { 15108705d96Sshatty LOG(8,("SETMODE: target2 clock %dkHz\n",target2.timing.pixel_clock)); 15230f76422SRudolf Cornelissen if (head2_set_pix_pll(target2) == B_ERROR) 153a3b9d212SRudolf Cornelissen LOG(8,("SETMODE: error setting pixel clock (DAC2)\n")); 15408705d96Sshatty } 15508705d96Sshatty 15608705d96Sshatty /*set the colour depth for CRTC1 and the DAC */ 15708705d96Sshatty switch(target.space) 15808705d96Sshatty { 159bc5690abSRudolf Cornelissen case B_CMAP8: 160bc5690abSRudolf Cornelissen colour_depth1 = 8; 16130f76422SRudolf Cornelissen head1_mode(BPP8, 1.0); 1620669fe20SRudolf Cornelissen head1_depth(BPP8); 163bc5690abSRudolf Cornelissen break; 164bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 165bc5690abSRudolf Cornelissen colour_depth1 = 16; 16630f76422SRudolf Cornelissen head1_mode(BPP15, 1.0); 1670669fe20SRudolf Cornelissen head1_depth(BPP15); 168bc5690abSRudolf Cornelissen break; 16908705d96Sshatty case B_RGB16_LITTLE: 17008705d96Sshatty colour_depth1 = 16; 17130f76422SRudolf Cornelissen head1_mode(BPP16, 1.0); 1720669fe20SRudolf Cornelissen head1_depth(BPP16); 17308705d96Sshatty break; 17408705d96Sshatty case B_RGB32_LITTLE: 17508705d96Sshatty colour_depth1 = 32; 17630f76422SRudolf Cornelissen head1_mode(BPP32, 1.0); 1770669fe20SRudolf Cornelissen head1_depth(BPP32); 17808705d96Sshatty break; 17908705d96Sshatty } 180a3b9d212SRudolf Cornelissen /*set the colour depth for CRTC2 and DAC2 */ 18108705d96Sshatty switch(target2.space) 18208705d96Sshatty { 183bc5690abSRudolf Cornelissen case B_CMAP8: 184bc5690abSRudolf Cornelissen colour_depth2 = 8; 18530f76422SRudolf Cornelissen head2_mode(BPP8, 1.0); 1860669fe20SRudolf Cornelissen head2_depth(BPP8); 187bc5690abSRudolf Cornelissen break; 188bc5690abSRudolf Cornelissen case B_RGB15_LITTLE: 189bc5690abSRudolf Cornelissen colour_depth2 = 16; 19030f76422SRudolf Cornelissen head2_mode(BPP15, 1.0); 1910669fe20SRudolf Cornelissen head2_depth(BPP15); 192bc5690abSRudolf Cornelissen break; 19308705d96Sshatty case B_RGB16_LITTLE: 19408705d96Sshatty colour_depth2 = 16; 19530f76422SRudolf Cornelissen head2_mode(BPP16, 1.0); 1960669fe20SRudolf Cornelissen head2_depth(BPP16); 19708705d96Sshatty break; 19808705d96Sshatty case B_RGB32_LITTLE: 19908705d96Sshatty colour_depth2 = 32; 20030f76422SRudolf Cornelissen head2_mode(BPP32, 1.0); 2010669fe20SRudolf Cornelissen head2_depth(BPP32); 20208705d96Sshatty break; 20308705d96Sshatty } 20408705d96Sshatty 20508705d96Sshatty /* check if we are doing interlaced TVout mode */ 20608705d96Sshatty si->interlaced_tv_mode = false; 20708705d96Sshatty /* if ((target2.flags & TV_BITS) && (si->ps.card_type >= G450)) 20808705d96Sshatty si->interlaced_tv_mode = true; 20908705d96Sshatty */ 21008705d96Sshatty /*set the display(s) pitches*/ 2110669fe20SRudolf Cornelissen head1_set_display_pitch (); 21208705d96Sshatty //fixme: seperate for real dualhead modes: 21308705d96Sshatty //we need a secondary si->fbc! 2140669fe20SRudolf Cornelissen head2_set_display_pitch (); 21508705d96Sshatty 21608705d96Sshatty /*work out where the "right" screen starts*/ 21708705d96Sshatty startadd_right = startadd + (target.timing.h_display * (colour_depth1 >> 3)); 21808705d96Sshatty 21908705d96Sshatty /* Tell card what memory to display */ 22008705d96Sshatty switch (target.flags & DUALHEAD_BITS) 22108705d96Sshatty { 22208705d96Sshatty case DUALHEAD_ON: 22308705d96Sshatty case DUALHEAD_SWITCH: 2240669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2250669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth2); 22608705d96Sshatty break; 22708705d96Sshatty case DUALHEAD_CLONE: 2280669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 2290669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth2); 23008705d96Sshatty break; 23108705d96Sshatty } 23208705d96Sshatty 23308705d96Sshatty /* set the timing */ 2340669fe20SRudolf Cornelissen head1_set_timing(target); 23508705d96Sshatty /* we do not need to setup CRTC2 here for a head that's in TVout mode */ 2360669fe20SRudolf Cornelissen if (!(target2.flags & TV_BITS)) result = head2_set_timing(target2); 23708705d96Sshatty 23808705d96Sshatty /* TVout support: setup CRTC2 and it's pixelclock */ 2397b820745SRudolf Cornelissen if (si->ps.tvout && (target2.flags & TV_BITS)) maventv_init(target2); 24008705d96Sshatty } 24108705d96Sshatty else /* single head mode */ 24208705d96Sshatty { 24308705d96Sshatty status_t status; 24408705d96Sshatty int colour_mode = BPP32; 24508705d96Sshatty 24630f76422SRudolf Cornelissen /* connect output */ 24730f76422SRudolf Cornelissen if (si->ps.secondary_head) 24830f76422SRudolf Cornelissen { 24930f76422SRudolf Cornelissen /* detect which connectors have a CRT connected */ 25030f76422SRudolf Cornelissen //fixme: 'hot-plugging' for analog monitors removed: remove code as well; 25130f76422SRudolf Cornelissen //or make it work with digital panels connected as well. 25230f76422SRudolf Cornelissen // crt1 = nv_dac_crt_connected(); 25330f76422SRudolf Cornelissen // crt2 = nv_dac2_crt_connected(); 25430f76422SRudolf Cornelissen /* connect outputs 'straight-through' */ 25530f76422SRudolf Cornelissen // if (crt1) 25630f76422SRudolf Cornelissen // { 25730f76422SRudolf Cornelissen /* connector1 is used as primary output */ 25830f76422SRudolf Cornelissen // cross = false; 25930f76422SRudolf Cornelissen // } 26030f76422SRudolf Cornelissen // else 26130f76422SRudolf Cornelissen // { 26230f76422SRudolf Cornelissen // if (crt2) 26330f76422SRudolf Cornelissen /* connector2 is used as primary output */ 26430f76422SRudolf Cornelissen // cross = true; 26530f76422SRudolf Cornelissen // else 26630f76422SRudolf Cornelissen /* no CRT detected: assume connector1 is used as primary output */ 26730f76422SRudolf Cornelissen // cross = false; 26830f76422SRudolf Cornelissen // } 26930f76422SRudolf Cornelissen /* set output connectors assignment if possible */ 27006f4c439SRudolf Cornelissen nv_general_head_select(false); 27130f76422SRudolf Cornelissen } 27230f76422SRudolf Cornelissen 27308705d96Sshatty switch(target.space) 27408705d96Sshatty { 27508705d96Sshatty case B_CMAP8: colour_depth1 = 8; colour_mode = BPP8; break; 27608705d96Sshatty case B_RGB15_LITTLE: colour_depth1 = 16; colour_mode = BPP15; break; 27708705d96Sshatty case B_RGB16_LITTLE: colour_depth1 = 16; colour_mode = BPP16; break; 27808705d96Sshatty case B_RGB32_LITTLE: colour_depth1 = 32; colour_mode = BPP32; break; 27908705d96Sshatty default: 28008705d96Sshatty LOG(8,("SETMODE: Invalid singlehead colour depth 0x%08x\n", target.space)); 28108705d96Sshatty return B_ERROR; 28208705d96Sshatty } 28308705d96Sshatty 28408705d96Sshatty /* set the pixel clock PLL */ 28530f76422SRudolf Cornelissen status = head1_set_pix_pll(target); 28608705d96Sshatty 28708705d96Sshatty if (status==B_ERROR) 28808705d96Sshatty LOG(8,("CRTC: error setting pixel clock (internal DAC)\n")); 28908705d96Sshatty 29008705d96Sshatty /* set the colour depth for CRTC1 and the DAC */ 29108705d96Sshatty /* first set the colordepth */ 2920669fe20SRudolf Cornelissen head1_depth(colour_mode); 29308705d96Sshatty /* then(!) program the PAL (<8bit colordepth does not support 8bit PAL) */ 29430f76422SRudolf Cornelissen head1_mode(colour_mode,1.0); 29508705d96Sshatty 29608705d96Sshatty /* set the display pitch */ 2970669fe20SRudolf Cornelissen head1_set_display_pitch(); 29808705d96Sshatty 29908705d96Sshatty /* tell the card what memory to display */ 3000669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth1); 30108705d96Sshatty 30208705d96Sshatty /* set the timing */ 3030669fe20SRudolf Cornelissen head1_set_timing(target); 30408705d96Sshatty 30508705d96Sshatty //fixme: shut-off the videoPLL if it exists... 30608705d96Sshatty } 30708705d96Sshatty 30808705d96Sshatty /* update driver's mode store */ 30908705d96Sshatty si->dm = target; 31008705d96Sshatty 31108705d96Sshatty /* turn screen one on */ 3120669fe20SRudolf Cornelissen head1_dpms(display, h, v); 31308705d96Sshatty /* turn screen two on if a dualhead mode is active */ 3140669fe20SRudolf Cornelissen if (target.flags & DUALHEAD_BITS) head2_dpms(display,h,v); 31508705d96Sshatty 31608705d96Sshatty /* set up acceleration for this mode */ 317dd43fd34SRudolf Cornelissen /* note: 318dd43fd34SRudolf Cornelissen * attempting DMA on NV40 and higher because without it I can't get it going ATM. 319dd43fd34SRudolf Cornelissen * Later on this can become a nv.settings switch, and maybe later we can even 320dd43fd34SRudolf Cornelissen * forget about non-DMA completely (depends on 3D acceleration attempts). */ 321dd446dd3SRudolf Cornelissen if (!si->settings.dma_acc) 322b4c44701Sshatty nv_acc_init(); 323dd43fd34SRudolf Cornelissen else 324dd43fd34SRudolf Cornelissen nv_acc_init_dma(); 325b4c44701Sshatty /* set up overlay unit for this mode */ 326aa1e552fSshatty nv_bes_init(); 32708705d96Sshatty 32889d37d46SRudolf Cornelissen /* note freemem range */ 32989d37d46SRudolf Cornelissen /* first free adress follows hardcursor and workspace */ 33089d37d46SRudolf Cornelissen si->mem_low = si->fbc.bytes_per_row * si->dm.virtual_height; 33189d37d46SRudolf Cornelissen if (si->settings.hardcursor) si->mem_low += 2048; 33289d37d46SRudolf Cornelissen /* last free adress is end-of-ram minus max space needed for overlay bitmaps */ 33389d37d46SRudolf Cornelissen //fixme possible: 33489d37d46SRudolf Cornelissen //if overlay buffers are allocated subtract buffersize from mem_high; 33589d37d46SRudolf Cornelissen //only allocate overlay buffers if 3D is not in use. (block overlay during 3D) 33689d37d46SRudolf Cornelissen si->mem_high = si->ps.memory_size - 1; 337fee251bcSRudolf Cornelissen /* don't touch the DMA acceleration engine command buffer if it exists */ 338fee251bcSRudolf Cornelissen /* note: 339fdd699c7SRudolf Cornelissen * the buffer is 32kB in size. Keep some extra distance for safety (faulty apps). */ 340fdd699c7SRudolf Cornelissen if (si->settings.dma_acc) 341fdd699c7SRudolf Cornelissen { 342fdd699c7SRudolf Cornelissen if (si->ps.card_arch < NV40A) 343fdd699c7SRudolf Cornelissen { 344fdd699c7SRudolf Cornelissen /* keeping 32kB distance from the DMA buffer */ 345fdd699c7SRudolf Cornelissen si->mem_high -= (64 * 1024); 346fdd699c7SRudolf Cornelissen } 347fdd699c7SRudolf Cornelissen else 348fdd699c7SRudolf Cornelissen { 349fdd699c7SRudolf Cornelissen /* 416kB distance is just OK: keeping another 64kB distance for safety; 350fdd699c7SRudolf Cornelissen * confirmed for NV43. */ 351fdd699c7SRudolf Cornelissen /* note: 352fdd699c7SRudolf Cornelissen * if you get too close to the DMA command buffer on NV40 and NV43 at 353fdd699c7SRudolf Cornelissen * least (both confirmed), the source DMA instance will mess-up for 354fdd699c7SRudolf Cornelissen * at least engine cmd NV_IMAGE_BLIT and NV12_IMAGE_BLIT. */ 355fdd699c7SRudolf Cornelissen si->mem_high -= (512 * 1024); 356fdd699c7SRudolf Cornelissen } 357fdd699c7SRudolf Cornelissen } 35889d37d46SRudolf Cornelissen si->mem_high -= (MAXBUFFERS * 1024 * 1024 * 2); /* see overlay.c file */ 35989d37d46SRudolf Cornelissen 360255e5021SRudolf Cornelissen LOG(1,("SETMODE: booted since %f mS\n", system_time()/1000.0)); 36108705d96Sshatty 36208705d96Sshatty /* enable interrupts using the kernel driver */ 36308705d96Sshatty interrupt_enable(true); 36408705d96Sshatty 36508705d96Sshatty /* optimize memory-access if needed */ 3660669fe20SRudolf Cornelissen // head1_mem_priority(colour_depth1); 36708705d96Sshatty 36808705d96Sshatty /* Tune RAM CAS-latency if needed. Must be done *here*! */ 36908705d96Sshatty nv_set_cas_latency(); 37008705d96Sshatty 37108705d96Sshatty return B_OK; 37208705d96Sshatty } 37308705d96Sshatty 37408705d96Sshatty /* 37508705d96Sshatty Set which pixel of the virtual frame buffer will show up in the 37608705d96Sshatty top left corner of the display device. Used for page-flipping 37708705d96Sshatty games and virtual desktops. 37808705d96Sshatty */ 37908705d96Sshatty status_t MOVE_DISPLAY(uint16 h_display_start, uint16 v_display_start) { 38008705d96Sshatty uint8 colour_depth; 38108705d96Sshatty uint32 startadd,startadd_right; 38208705d96Sshatty 38308705d96Sshatty LOG(4,("MOVE_DISPLAY: h %d, v %d\n", h_display_start, v_display_start)); 38408705d96Sshatty 385255e5021SRudolf Cornelissen /* nVidia cards support pixelprecise panning on both heads in all modes: 386255e5021SRudolf Cornelissen * No stepping granularity needed! */ 387255e5021SRudolf Cornelissen 388255e5021SRudolf Cornelissen /* determine bits used for the colordepth */ 38908705d96Sshatty switch(si->dm.space) 39008705d96Sshatty { 39108705d96Sshatty case B_CMAP8: 39208705d96Sshatty colour_depth=8; 39308705d96Sshatty break; 394255e5021SRudolf Cornelissen case B_RGB15_LITTLE: 395255e5021SRudolf Cornelissen case B_RGB16_LITTLE: 39608705d96Sshatty colour_depth=16; 397255e5021SRudolf Cornelissen break; 398255e5021SRudolf Cornelissen case B_RGB24_LITTLE: 399255e5021SRudolf Cornelissen colour_depth=24; 40008705d96Sshatty break; 40108705d96Sshatty case B_RGB32_LITTLE: 40208705d96Sshatty colour_depth=32; 40308705d96Sshatty break; 40408705d96Sshatty default: 40508705d96Sshatty return B_ERROR; 40608705d96Sshatty } 40708705d96Sshatty 40808705d96Sshatty /* do not run past end of display */ 40908705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 41008705d96Sshatty { 41108705d96Sshatty case DUALHEAD_ON: 41208705d96Sshatty case DUALHEAD_SWITCH: 41308705d96Sshatty if (((si->dm.timing.h_display * 2) + h_display_start) > si->dm.virtual_width) 41408705d96Sshatty return B_ERROR; 41508705d96Sshatty break; 41608705d96Sshatty default: 41708705d96Sshatty if ((si->dm.timing.h_display + h_display_start) > si->dm.virtual_width) 41808705d96Sshatty return B_ERROR; 41908705d96Sshatty break; 42008705d96Sshatty } 42108705d96Sshatty if ((si->dm.timing.v_display + v_display_start) > si->dm.virtual_height) 42208705d96Sshatty return B_ERROR; 42308705d96Sshatty 42408705d96Sshatty /* everybody remember where we parked... */ 42508705d96Sshatty si->dm.h_display_start = h_display_start; 42608705d96Sshatty si->dm.v_display_start = v_display_start; 42708705d96Sshatty 42808705d96Sshatty /* actually set the registers */ 42908705d96Sshatty //fixme: seperate both heads: we need a secondary si->fbc! 43008705d96Sshatty startadd = v_display_start * si->fbc.bytes_per_row; 43108705d96Sshatty startadd += h_display_start * (colour_depth >> 3); 432f2777ca1SRudolf Cornelissen startadd += (uint8*)si->fbc.frame_buffer - (uint8*)si->framebuffer; 43308705d96Sshatty startadd_right = startadd + si->dm.timing.h_display * (colour_depth >> 3); 43408705d96Sshatty 43508705d96Sshatty interrupt_enable(false); 43608705d96Sshatty 43708705d96Sshatty switch (si->dm.flags & DUALHEAD_BITS) 43808705d96Sshatty { 43908705d96Sshatty case DUALHEAD_ON: 44008705d96Sshatty case DUALHEAD_SWITCH: 4410669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4420669fe20SRudolf Cornelissen head2_set_display_start(startadd_right,colour_depth); 44308705d96Sshatty break; 44408705d96Sshatty case DUALHEAD_OFF: 4450669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 44608705d96Sshatty break; 44708705d96Sshatty case DUALHEAD_CLONE: 4480669fe20SRudolf Cornelissen head1_set_display_start(startadd,colour_depth); 4490669fe20SRudolf Cornelissen head2_set_display_start(startadd,colour_depth); 45008705d96Sshatty break; 45108705d96Sshatty } 45208705d96Sshatty 45308705d96Sshatty interrupt_enable(true); 45408705d96Sshatty return B_OK; 45508705d96Sshatty } 45608705d96Sshatty 457255e5021SRudolf Cornelissen /* Set the indexed color palette */ 45808705d96Sshatty void SET_INDEXED_COLORS(uint count, uint8 first, uint8 *color_data, uint32 flags) { 45908705d96Sshatty int i; 46008705d96Sshatty uint8 *r,*g,*b; 46108705d96Sshatty 46208705d96Sshatty /* Protect gamma correction when not in CMAP8 */ 46308705d96Sshatty if (si->dm.space != B_CMAP8) return; 46408705d96Sshatty 46508705d96Sshatty r=si->color_data; 46608705d96Sshatty g=r+256; 46708705d96Sshatty b=g+256; 46808705d96Sshatty 46908705d96Sshatty i=first; 47008705d96Sshatty while (count--) 47108705d96Sshatty { 47208705d96Sshatty r[i]=*color_data++; 47308705d96Sshatty g[i]=*color_data++; 47408705d96Sshatty b[i]=*color_data++; 47508705d96Sshatty i++; 47608705d96Sshatty } 47730f76422SRudolf Cornelissen head1_palette(r,g,b); 47830f76422SRudolf Cornelissen if (si->dm.flags & DUALHEAD_BITS) head2_palette(r,g,b); 47908705d96Sshatty } 48008705d96Sshatty 48108705d96Sshatty /* Put the display into one of the Display Power Management modes. */ 48208705d96Sshatty status_t SET_DPMS_MODE(uint32 dpms_flags) { 48308705d96Sshatty interrupt_enable(false); 48408705d96Sshatty 48508705d96Sshatty LOG(4,("SET_DPMS_MODE: 0x%08x\n", dpms_flags)); 48608705d96Sshatty 48708705d96Sshatty if (si->dm.flags & DUALHEAD_BITS) /*dualhead*/ 48808705d96Sshatty { 48908705d96Sshatty switch(dpms_flags) 49008705d96Sshatty { 49108705d96Sshatty case B_DPMS_ON: /* H: on, V: on, display on */ 4920669fe20SRudolf Cornelissen head1_dpms(true, true, true); 4930669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(true, true, true); 49408705d96Sshatty break; 49508705d96Sshatty case B_DPMS_STAND_BY: 4960669fe20SRudolf Cornelissen head1_dpms(false, false, true); 4970669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, true); 49808705d96Sshatty break; 49908705d96Sshatty case B_DPMS_SUSPEND: 5000669fe20SRudolf Cornelissen head1_dpms(false, true, false); 5010669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, true, false); 50208705d96Sshatty break; 50308705d96Sshatty case B_DPMS_OFF: /* H: off, V: off, display off */ 5040669fe20SRudolf Cornelissen head1_dpms(false, false, false); 5050669fe20SRudolf Cornelissen if (si->ps.secondary_head) head2_dpms(false, false, false); 50608705d96Sshatty break; 50708705d96Sshatty default: 50808705d96Sshatty LOG(8,("SET: Invalid DPMS settings (DH) 0x%08x\n", dpms_flags)); 50908705d96Sshatty interrupt_enable(true); 51008705d96Sshatty return B_ERROR; 51108705d96Sshatty } 51208705d96Sshatty } 51308705d96Sshatty else /* singlehead */ 51408705d96Sshatty { 51508705d96Sshatty switch(dpms_flags) 51608705d96Sshatty { 51708705d96Sshatty case B_DPMS_ON: /* H: on, V: on, display on */ 5180669fe20SRudolf Cornelissen head1_dpms(true, true, true); 51908705d96Sshatty break; 52008705d96Sshatty case B_DPMS_STAND_BY: 5210669fe20SRudolf Cornelissen head1_dpms(false, false, true); 52208705d96Sshatty break; 52308705d96Sshatty case B_DPMS_SUSPEND: 5240669fe20SRudolf Cornelissen head1_dpms(false, true, false); 52508705d96Sshatty break; 52608705d96Sshatty case B_DPMS_OFF: /* H: off, V: off, display off */ 5270669fe20SRudolf Cornelissen head1_dpms(false, false, false); 52808705d96Sshatty break; 52908705d96Sshatty default: 53008705d96Sshatty LOG(8,("SET: Invalid DPMS settings (DH) 0x%08x\n", dpms_flags)); 53108705d96Sshatty interrupt_enable(true); 53208705d96Sshatty return B_ERROR; 53308705d96Sshatty } 53408705d96Sshatty } 53508705d96Sshatty interrupt_enable(true); 53608705d96Sshatty return B_OK; 53708705d96Sshatty } 53808705d96Sshatty 53908705d96Sshatty /* Report device DPMS capabilities */ 54008705d96Sshatty uint32 DPMS_CAPABILITIES(void) { 54108705d96Sshatty return (B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF); 54208705d96Sshatty } 54308705d96Sshatty 54408705d96Sshatty /* Return the current DPMS mode */ 54508705d96Sshatty uint32 DPMS_MODE(void) { 54608705d96Sshatty bool display, h, v; 54708705d96Sshatty 54808705d96Sshatty interrupt_enable(false); 5490669fe20SRudolf Cornelissen head1_dpms_fetch(&display, &h, &v); 55008705d96Sshatty interrupt_enable(true); 55108705d96Sshatty 55208705d96Sshatty if (display && h && v) 55308705d96Sshatty return B_DPMS_ON; 55408705d96Sshatty else if(v) 55508705d96Sshatty return B_DPMS_STAND_BY; 55608705d96Sshatty else if(h) 55708705d96Sshatty return B_DPMS_SUSPEND; 55808705d96Sshatty else 55908705d96Sshatty return B_DPMS_OFF; 56008705d96Sshatty } 561