1/* 2 * Copyright 2007-2010 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Gerald Zajac 7 */ 8 9#ifndef _ACCELERANT_H 10#define _ACCELERANT_H 11 12#include "DriverInterface.h" 13 14 15 16#undef TRACE 17 18#ifdef ENABLE_DEBUG_TRACE 19extern "C" void _sPrintf(const char* format, ...); 20# define TRACE(x...) _sPrintf("3dfx: " x) 21#else 22# define TRACE(x...) ; 23#endif 24 25 26#define CURSOR_BYTES 1024 // bytes used for cursor image in video memory 27 28 29// Global data used by various source files of the accelerant. 30 31struct AccelerantInfo { 32 int deviceFileDesc; // file descriptor of kernel driver 33 34 SharedInfo* sharedInfo; // address of info shared between 35 // accelerants & driver 36 area_id sharedInfoArea; // shared info area ID 37 38 uint8* regs; // base address of MMIO register area 39 area_id regsArea; // MMIO register area ID 40 41 display_mode* modeList; // list of standard display modes 42 area_id modeListArea; // mode list area ID 43 44 bool bAccelerantIsClone; // true if this is a cloned accelerant 45}; 46 47extern AccelerantInfo gInfo; 48 49 50// Prototypes of the interface functions called by the app_server. Note that 51// the functions that are unique to a particular chip family, will be prefixed 52// with the name of the family, and the functions that are applicable to all 53// chips will have no prefix. 54//================================================================ 55 56#if defined(__cplusplus) 57extern "C" { 58#endif 59 60// General 61status_t InitAccelerant(int fd); 62ssize_t AccelerantCloneInfoSize(void); 63void GetAccelerantCloneInfo(void* data); 64status_t CloneAccelerant(void* data); 65void UninitAccelerant(void); 66status_t GetAccelerantDeviceInfo(accelerant_device_info* adi); 67 68// Mode Configuration 69uint32 AccelerantModeCount(void); 70status_t GetModeList(display_mode* dm); 71status_t ProposeDisplayMode(display_mode* target, const display_mode* low, 72 const display_mode* high); 73status_t SetDisplayMode(display_mode* mode_to_set); 74status_t GetDisplayMode(display_mode* current_mode); 75status_t GetFrameBufferConfig(frame_buffer_config* a_frame_buffer); 76status_t GetPixelClockLimits(display_mode* dm, uint32* low, uint32* high); 77status_t MoveDisplay(uint16 h_display_start, uint16 v_display_start); 78void TDFX_SetIndexedColors(uint count, uint8 first, uint8* color_data, 79 uint32 flags); 80status_t GetEdidInfo(void* info, size_t size, uint32* _version); 81 82// DPMS 83uint32 TDFX_DPMSCapabilities(void); 84uint32 TDFX_GetDPMSMode(void); 85status_t TDFX_SetDPMSMode(uint32 dpms_flags); 86 87// Cursor 88status_t SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y, 89 uint8* andMask, uint8* xorMask); 90void MoveCursor(uint16 x, uint16 y); 91void TDFX_ShowCursor(bool bShow); 92 93// Engine Management 94uint32 AccelerantEngineCount(void); 95status_t AcquireEngine(uint32 capabilities, uint32 max_wait, sync_token* st, 96 engine_token** et); 97status_t ReleaseEngine(engine_token* et, sync_token* st); 98void WaitEngineIdle(void); 99status_t GetSyncToken(engine_token* et, sync_token* st); 100status_t SyncToToken(sync_token* st); 101 102// 2D acceleration 103void TDFX_FillRectangle(engine_token* et, uint32 color, 104 fill_rect_params* list, uint32 count); 105void TDFX_FillSpan(engine_token* et, uint32 color, uint16* list, 106 uint32 count); 107void TDFX_InvertRectangle(engine_token* et, fill_rect_params* list, 108 uint32 count); 109void TDFX_ScreenToScreenBlit(engine_token* et, blit_params* list, 110 uint32 count); 111 112// Video_overlay 113uint32 OverlayCount(const display_mode* dm); 114const uint32* OverlaySupportedSpaces(const display_mode *dm); 115uint32 OverlaySupportedFeatures(uint32 a_color_space); 116const overlay_buffer* AllocateOverlayBuffer(color_space cs, uint16 width, 117 uint16 height); 118status_t ReleaseOverlayBuffer(const overlay_buffer* ob); 119status_t GetOverlayConstraints(const display_mode* dm, 120 const overlay_buffer* ob, overlay_constraints* oc); 121overlay_token AllocateOverlay(void); 122status_t ReleaseOverlay(overlay_token ot); 123status_t ConfigureOverlay(overlay_token ot, const overlay_buffer* ob, 124 const overlay_window* ow, const overlay_view* ov); 125 126#if defined(__cplusplus) 127} 128#endif 129 130 131 132// Prototypes for other functions that are called from source files other than 133// where they are defined. 134//============================================================================ 135 136status_t CreateModeList(bool (*checkMode)(const display_mode* mode)); 137uint16 GetVesaModeNumber(const display_mode& mode, uint8 bitsPerPixel); 138bool IsModeUsable(const display_mode* mode); 139 140// 3dfx functions. 141 142bool TDFX_DisplayOverlay(const overlay_window* window, 143 const overlay_buffer* buffer, const overlay_view* view); 144void TDFX_StopOverlay(void); 145 146status_t TDFX_Init(void); 147bool TDFX_GetColorSpaceParams(int colorSpace, uint8& bpp); 148bool TDFX_GetEdidInfo(edid1_info& edidInfo); 149 150void TDFX_EngineReset(void); 151void TDFX_EngineInit(const DisplayModeEx& mode); 152 153bool TDFX_LoadCursorImage(int width, int height, uint8* and_mask, 154 uint8* xor_mask); 155void TDFX_SetCursorPosition(int x, int y); 156 157void TDFX_AdjustFrame(const DisplayModeEx& mode); 158status_t TDFX_SetDisplayMode(const DisplayModeEx& mode); 159 160void TDFX_WaitForFifo(uint32); 161void TDFX_WaitForIdle(); 162 163 164// Address of various VGA registers. 165 166#define MISC_OUT_R 0x3cc // read 167#define MISC_OUT_W 0x3c2 // write 168#define CRTC_INDEX 0x3d4 169#define CRTC_DATA 0x3d5 170#define SEQ_INDEX 0x3c4 171#define SEQ_DATA 0x3c5 172 173 174// Macros for memory mapped I/O. 175//=============================== 176 177#define INREG8(addr) *((vuint8*)(gInfo.regs + addr)) 178#define INREG16(addr) *((vuint16*)(gInfo.regs + addr)) 179#define INREG32(addr) *((vuint32*)(gInfo.regs + addr)) 180 181#define OUTREG8(addr, val) *((vuint8*)(gInfo.regs + addr)) = val 182#define OUTREG16(addr, val) *((vuint16*)(gInfo.regs + addr)) = val 183#define OUTREG32(addr, val) *((vuint32*)(gInfo.regs + addr)) = val 184 185// Write a value to an 32-bit reg using a mask. The mask selects the 186// bits to be modified. 187#define OUTREGM(addr, value, mask) \ 188 (OUTREG(addr, (INREG(addr) & ~(mask)) | ((value) & (mask)))) 189 190 191#endif // _ACCELERANT_H 192