1 /* 2 Copyright 2007-2009 Haiku, Inc. All rights reserved. 3 Distributed under the terms of the MIT license. 4 5 Authors: 6 Gerald Zajac 2007-2009 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 19 extern "C" void _sPrintf(const char* format, ...); 20 # define TRACE(x...) _sPrintf("ati: " x) 21 #else 22 # define TRACE(x...) ; 23 #endif 24 25 26 // Global data used by various source files of the accelerant. 27 28 struct AccelerantInfo { 29 int deviceFileDesc; // file descriptor of kernel driver 30 31 SharedInfo* sharedInfo; // address of info shared between accelerants & driver 32 area_id sharedInfoArea; // shared info area ID 33 34 uint8* regs; // base address of MMIO register area 35 area_id regsArea; // MMIO register area ID 36 37 display_mode* modeList; // list of standard display modes 38 area_id modeListArea; // mode list area ID 39 40 bool bAccelerantIsClone; // true if this is a cloned accelerant 41 42 // Pointers to various global accelerant functions. 43 //------------------------------------------------- 44 45 // Pointers to wait handlers. 46 void (*WaitForFifo)(uint32); 47 void (*WaitForIdle)(); 48 49 // Pointers to DPMS functions. 50 uint32 (*DPMSCapabilities)(void); 51 uint32 (*GetDPMSMode)(void); 52 status_t (*SetDPMSMode)(uint32 dpms_flags); 53 54 // Pointers to cursor functions. 55 bool (*LoadCursorImage)(int width, int height, uint8* and_mask, uint8* xor_mask); 56 void (*SetCursorPosition)(int x, int y); 57 void (*ShowCursor)(bool bShow); 58 59 // Pointers to 2D acceleration functions. 60 void (*FillRectangle)(engine_token*, uint32 color, fill_rect_params*, uint32 count); 61 void (*FillSpan)(engine_token*, uint32 color, uint16* list, uint32 count); 62 void (*InvertRectangle)(engine_token*, fill_rect_params*, uint32 count); 63 void (*ScreenToScreenBlit)(engine_token*, blit_params*, uint32 count); 64 65 // Pointers to other functions. 66 void (*AdjustFrame)(const DisplayModeEx& mode); 67 status_t (*ChipInit)(void); 68 bool (*GetColorSpaceParams)(int colorSpace, uint8& bpp, uint32& maxPixelClk); 69 status_t (*SetDisplayMode)(const DisplayModeEx& mode); 70 void (*SetIndexedColors)(uint count, uint8 first, uint8* color_data, uint32 flags); 71 }; 72 73 extern AccelerantInfo gInfo; 74 75 76 // Prototypes of the interface functions called by the app_server. Note that 77 // the functions that are unique to a particular chip family, will be prefixed 78 // with the name of the family, and the functions that are applicable to all 79 // chips will have no prefix. 80 //================================================================ 81 82 #if defined(__cplusplus) 83 extern "C" { 84 #endif 85 86 // General 87 status_t InitAccelerant(int fd); 88 ssize_t AccelerantCloneInfoSize(void); 89 void GetAccelerantCloneInfo(void* data); 90 status_t CloneAccelerant(void* data); 91 void UninitAccelerant(void); 92 status_t GetAccelerantDeviceInfo(accelerant_device_info* adi); 93 sem_id AccelerantRetraceSemaphore(void); 94 95 // Mode Configuration 96 uint32 AccelerantModeCount(void); 97 status_t GetModeList(display_mode* dm); 98 status_t ProposeDisplayMode(display_mode* target, const display_mode* low, const display_mode* high); 99 status_t SetDisplayMode(display_mode* mode_to_set); 100 status_t GetDisplayMode(display_mode* current_mode); 101 status_t GetFrameBufferConfig(frame_buffer_config* a_frame_buffer); 102 status_t GetPixelClockLimits(display_mode* dm, uint32* low, uint32* high); 103 status_t MoveDisplay(uint16 h_display_start, uint16 v_display_start); 104 status_t GetTimingConstraints(display_timing_constraints* dtc); 105 void Mach64_SetIndexedColors(uint count, uint8 first, uint8* color_data, uint32 flags); 106 void Rage128_SetIndexedColors(uint count, uint8 first, uint8* color_data, uint32 flags); 107 status_t GetPreferredDisplayMode(display_mode* preferredMode); 108 status_t GetEdidInfo(void* info, size_t size, uint32* _version); 109 110 // DPMS 111 uint32 Mach64_DPMSCapabilities(void); 112 uint32 Mach64_GetDPMSMode(void); 113 status_t Mach64_SetDPMSMode(uint32 dpms_flags); 114 115 uint32 Rage128_DPMSCapabilities(void); 116 uint32 Rage128_GetDPMSMode(void); 117 status_t Rage128_SetDPMSMode(uint32 dpms_flags); 118 119 // Cursor 120 status_t SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y, 121 uint8* andMask, uint8* xorMask); 122 void MoveCursor(uint16 x, uint16 y); 123 124 // Engine Management 125 uint32 AccelerantEngineCount(void); 126 status_t AcquireEngine(uint32 capabilities, uint32 max_wait, sync_token* st, engine_token** et); 127 status_t ReleaseEngine(engine_token* et, sync_token* st); 128 void WaitEngineIdle(void); 129 status_t GetSyncToken(engine_token* et, sync_token* st); 130 status_t SyncToToken(sync_token* st); 131 132 // 2D acceleration 133 void Mach64_FillRectangle(engine_token* et, uint32 color, fill_rect_params* list, uint32 count); 134 void Mach64_FillSpan(engine_token* et, uint32 color, uint16* list, uint32 count); 135 void Mach64_InvertRectangle(engine_token* et, fill_rect_params* list, uint32 count); 136 void Mach64_ScreenToScreenBlit(engine_token* et, blit_params* list, uint32 count); 137 138 void Rage128_FillRectangle(engine_token* et, uint32 color, fill_rect_params* list, uint32 count); 139 void Rage128_FillSpan(engine_token* et, uint32 color, uint16* list, uint32 count); 140 void Rage128_InvertRectangle(engine_token* et, fill_rect_params* list, uint32 count); 141 void Rage128_ScreenToScreenBlit(engine_token* et, blit_params* list, uint32 count); 142 143 #if defined(__cplusplus) 144 } 145 #endif 146 147 148 149 // Prototypes for other functions that are called from source files other than 150 // where they are defined. 151 //============================================================================ 152 153 status_t CreateModeList(bool (*checkMode)(const display_mode* mode)); 154 uint16 GetVesaModeNumber(const display_mode& mode, uint8 bitsPerPixel); 155 bool IsModeUsable(const display_mode* mode); 156 157 // Mach64 functions. 158 159 void Mach64_EngineReset(void); 160 void Mach64_EngineInit(const DisplayModeEx& mode); 161 162 bool Mach64_LoadCursorImage(int width, int height, uint8* and_mask, uint8* xor_mask); 163 void Mach64_SetCursorPosition(int x, int y); 164 void Mach64_ShowCursor(bool bShow); 165 166 void Mach64_AdjustFrame(const DisplayModeEx& mode); 167 status_t Mach64_SetDisplayMode(const DisplayModeEx& mode); 168 void Mach64_SetFunctionPointers(void); 169 170 int Mach64_Divide(int numerator, int denom, int shift, const int roundingKind); 171 void Mach64_ReduceRatio(int *numerator, int *denominator); 172 173 174 // Rage128 functions. 175 176 void Rage128_EngineFlush(void); 177 void Rage128_EngineReset(void); 178 void Rage128_EngineInit(const DisplayModeEx& mode); 179 180 bool Rage128_GetEdidInfo(void); 181 182 bool Rage128_LoadCursorImage(int width, int height, uint8* and_mask, uint8* xor_mask); 183 void Rage128_SetCursorPosition(int x, int y); 184 void Rage128_ShowCursor(bool bShow); 185 186 void Rage128_AdjustFrame(const DisplayModeEx& mode); 187 status_t Rage128_SetDisplayMode(const DisplayModeEx& mode); 188 void Rage128_SetFunctionPointers(void); 189 190 191 // Macros for memory mapped I/O for both Mach64 and Rage128 chips. 192 //================================================================ 193 194 #define INREG8(addr) *((vuint8*)(gInfo.regs + addr)) 195 #define INREG16(addr) *((vuint16*)(gInfo.regs + addr)) 196 #define INREG(addr) *((vuint32*)(gInfo.regs + addr)) 197 198 #define OUTREG8(addr, val) *((vuint8*)(gInfo.regs + addr)) = val 199 #define OUTREG16(addr, val) *((vuint16*)(gInfo.regs + addr)) = val 200 #define OUTREG(addr, val) *((vuint32*)(gInfo.regs + addr)) = val 201 202 // Write a value to an 32-bit reg using a mask. The mask selects the 203 // bits to be modified. 204 #define OUTREGM(addr, value, mask) \ 205 (OUTREG(addr, (INREG(addr) & ~(mask)) | ((value) & (mask)))) 206 207 208 #endif // _ACCELERANT_H 209