vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / ati / accelerant.h
blob1640dd942f4717168b2920fbdc63e6b5feb8e745
1 /*
2 Copyright 2007-2011 Haiku, Inc. All rights reserved.
3 Distributed under the terms of the MIT license.
5 Authors:
6 Gerald Zajac
7 */
9 #ifndef _ACCELERANT_H
10 #define _ACCELERANT_H
12 #include "DriverInterface.h"
16 #undef TRACE
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
26 // Global data used by various source files of the accelerant.
28 struct AccelerantInfo {
29 int deviceFileDesc; // file descriptor of kernel driver
31 SharedInfo* sharedInfo; // address of info shared between accelerants & driver
32 area_id sharedInfoArea; // shared info area ID
34 uint8* regs; // base address of MMIO register area
35 area_id regsArea; // MMIO register area ID
37 display_mode* modeList; // list of standard display modes
38 area_id modeListArea; // mode list area ID
40 bool bAccelerantIsClone; // true if this is a cloned accelerant
42 // Pointers to various global accelerant functions.
43 //-------------------------------------------------
45 // Pointers to wait handlers.
46 void (*WaitForFifo)(uint32);
47 void (*WaitForIdle)();
49 // Pointers to DPMS functions.
50 uint32 (*DPMSCapabilities)(void);
51 uint32 (*GetDPMSMode)(void);
52 status_t (*SetDPMSMode)(uint32 dpms_flags);
54 // Pointers to cursor functions.
55 bool (*LoadCursorImage)(int width, int height, uint8* and_mask,
56 uint8* xor_mask);
57 void (*SetCursorPosition)(int x, int y);
58 void (*ShowCursor)(bool bShow);
60 // Pointers to 2D acceleration functions.
61 void (*FillRectangle)(engine_token*, uint32 color, fill_rect_params*,
62 uint32 count);
63 void (*FillSpan)(engine_token*, uint32 color, uint16* list,
64 uint32 count);
65 void (*InvertRectangle)(engine_token*, fill_rect_params*, uint32 count);
66 void (*ScreenToScreenBlit)(engine_token*, blit_params*, uint32 count);
68 // Pointers to other functions.
69 void (*AdjustFrame)(const DisplayModeEx& mode);
70 status_t (*ChipInit)(void);
71 bool (*GetColorSpaceParams)(int colorSpace, uint8& bpp,
72 uint32& maxPixelClk);
73 status_t (*SetDisplayMode)(const DisplayModeEx& mode);
74 void (*SetIndexedColors)(uint count, uint8 first, uint8* color_data,
75 uint32 flags);
78 extern AccelerantInfo gInfo;
81 // Prototypes of the interface functions called by the app_server. Note that
82 // the functions that are unique to a particular chip family, will be prefixed
83 // with the name of the family, and the functions that are applicable to all
84 // chips will have no prefix.
85 //================================================================
87 #if defined(__cplusplus)
88 extern "C" {
89 #endif
91 // General
92 status_t InitAccelerant(int fd);
93 ssize_t AccelerantCloneInfoSize(void);
94 void GetAccelerantCloneInfo(void* data);
95 status_t CloneAccelerant(void* data);
96 void UninitAccelerant(void);
97 status_t GetAccelerantDeviceInfo(accelerant_device_info* adi);
98 sem_id AccelerantRetraceSemaphore(void);
100 // Mode Configuration
101 uint32 AccelerantModeCount(void);
102 status_t GetModeList(display_mode* dm);
103 status_t ProposeDisplayMode(display_mode* target, const display_mode* low,
104 const display_mode* high);
105 status_t SetDisplayMode(display_mode* mode_to_set);
106 status_t GetDisplayMode(display_mode* current_mode);
107 status_t GetFrameBufferConfig(frame_buffer_config* a_frame_buffer);
108 status_t GetPixelClockLimits(display_mode* dm, uint32* low, uint32* high);
109 status_t MoveDisplay(uint16 h_display_start, uint16 v_display_start);
110 status_t GetTimingConstraints(display_timing_constraints* dtc);
111 void Mach64_SetIndexedColors(uint count, uint8 first, uint8* color_data,
112 uint32 flags);
113 void Rage128_SetIndexedColors(uint count, uint8 first, uint8* color_data,
114 uint32 flags);
115 status_t GetPreferredDisplayMode(display_mode* preferredMode);
116 status_t GetEdidInfo(void* info, size_t size, uint32* _version);
118 // DPMS
119 uint32 Mach64_DPMSCapabilities(void);
120 uint32 Mach64_GetDPMSMode(void);
121 status_t Mach64_SetDPMSMode(uint32 dpms_flags);
123 uint32 Rage128_DPMSCapabilities(void);
124 uint32 Rage128_GetDPMSMode(void);
125 status_t Rage128_SetDPMSMode(uint32 dpms_flags);
127 // Cursor
128 status_t SetCursorShape(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y,
129 uint8* andMask, uint8* xorMask);
130 void MoveCursor(uint16 x, uint16 y);
132 // Engine Management
133 uint32 AccelerantEngineCount(void);
134 status_t AcquireEngine(uint32 capabilities, uint32 max_wait, sync_token* st,
135 engine_token** et);
136 status_t ReleaseEngine(engine_token* et, sync_token* st);
137 void WaitEngineIdle(void);
138 status_t GetSyncToken(engine_token* et, sync_token* st);
139 status_t SyncToToken(sync_token* st);
141 // 2D acceleration
142 void Mach64_FillRectangle(engine_token* et, uint32 color,
143 fill_rect_params* list, uint32 count);
144 void Mach64_FillSpan(engine_token* et, uint32 color, uint16* list,
145 uint32 count);
146 void Mach64_InvertRectangle(engine_token* et, fill_rect_params* list,
147 uint32 count);
148 void Mach64_ScreenToScreenBlit(engine_token* et, blit_params* list,
149 uint32 count);
151 void Rage128_FillRectangle(engine_token* et, uint32 color,
152 fill_rect_params* list, uint32 count);
153 void Rage128_FillSpan(engine_token* et, uint32 color, uint16* list,
154 uint32 count);
155 void Rage128_InvertRectangle(engine_token* et, fill_rect_params* list,
156 uint32 count);
157 void Rage128_ScreenToScreenBlit(engine_token* et, blit_params* list,
158 uint32 count);
160 // Video_overlay
161 uint32 OverlayCount(const display_mode* dm);
162 const uint32* OverlaySupportedSpaces(const display_mode* dm);
163 uint32 OverlaySupportedFeatures(uint32 a_color_space);
164 const overlay_buffer* AllocateOverlayBuffer(color_space cs, uint16 width,
165 uint16 height);
166 status_t ReleaseOverlayBuffer(const overlay_buffer* ob);
167 status_t GetOverlayConstraints(const display_mode* dm,
168 const overlay_buffer* ob, overlay_constraints* oc);
169 overlay_token AllocateOverlay(void);
170 status_t ReleaseOverlay(overlay_token ot);
171 status_t ConfigureOverlay(overlay_token ot, const overlay_buffer* ob,
172 const overlay_window* ow, const overlay_view* ov);
174 #if defined(__cplusplus)
176 #endif
180 // Prototypes for other functions that are called from source files other than
181 // where they are defined.
182 //============================================================================
184 status_t CreateModeList(bool (*checkMode)(const display_mode* mode));
185 uint16 GetVesaModeNumber(const display_mode& mode, uint8 bitsPerPixel);
186 bool IsModeUsable(const display_mode* mode);
188 // Mach64 functions.
190 bool Mach64_DisplayOverlay(const overlay_window* window,
191 const overlay_buffer* buffer);
192 void Mach64_StopOverlay(void);
194 void Mach64_EngineReset(void);
195 void Mach64_EngineInit(const DisplayModeEx& mode);
197 bool Mach64_LoadCursorImage(int width, int height, uint8* and_mask,
198 uint8* xor_mask);
199 void Mach64_SetCursorPosition(int x, int y);
200 void Mach64_ShowCursor(bool bShow);
202 void Mach64_AdjustFrame(const DisplayModeEx& mode);
203 status_t Mach64_SetDisplayMode(const DisplayModeEx& mode);
204 void Mach64_SetFunctionPointers(void);
206 int Mach64_Divide(int numerator, int denom, int shift,
207 const int roundingKind);
208 void Mach64_ReduceRatio(int* numerator, int* denominator);
211 // Rage128 functions.
213 bool Rage128_DisplayOverlay(const overlay_window* window,
214 const overlay_buffer* buffer);
215 void Rage128_StopOverlay(void);
217 void Rage128_EngineFlush(void);
218 void Rage128_EngineReset(void);
219 void Rage128_EngineInit(const DisplayModeEx& mode);
221 bool Rage128_GetEdidInfo(void);
223 bool Rage128_LoadCursorImage(int width, int height, uint8* and_mask,
224 uint8* xor_mask);
225 void Rage128_SetCursorPosition(int x, int y);
226 void Rage128_ShowCursor(bool bShow);
228 void Rage128_AdjustFrame(const DisplayModeEx& mode);
229 status_t Rage128_SetDisplayMode(const DisplayModeEx& mode);
230 void Rage128_SetFunctionPointers(void);
233 // Macros for memory mapped I/O for both Mach64 and Rage128 chips.
234 //================================================================
236 #define INREG8(addr) *((vuint8*)(gInfo.regs + addr))
237 #define INREG16(addr) *((vuint16*)(gInfo.regs + addr))
238 #define INREG(addr) *((vuint32*)(gInfo.regs + addr))
240 #define OUTREG8(addr, val) *((vuint8*)(gInfo.regs + addr)) = val
241 #define OUTREG16(addr, val) *((vuint16*)(gInfo.regs + addr)) = val
242 #define OUTREG(addr, val) *((vuint32*)(gInfo.regs + addr)) = val
244 // Write a value to an 32-bit reg using a mask. The mask selects the
245 // bits to be modified.
246 #define OUTREGM(addr, value, mask) \
247 (OUTREG(addr, (INREG(addr) & ~(mask)) | ((value) & (mask))))
250 #endif // _ACCELERANT_H