2 * Copyright 2007-2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
10 #include "accelerant.h"
17 AccelerantInfo gInfo
; // global data used by source files of accelerant
19 static uint32 videoValue
;
23 SuppressArtifacts(void* dataPtr
)
25 // The Intel 810 & 815 video chips create annoying artifacts which are
26 // most noticeable when the cursor is moved by itself or the user goes up
27 // and down through a menu. However, if a large number of video memory
28 // locations are accessed frequently like when the GLTeapot demo is
29 // running, the artifacts are greatly suppressed. Thus, that is the reason
30 // why this function accesses a large number of video memory locations
31 // frequently. Note that the accessed memory locations are at the end of
32 // the video memory. This is because some artifacts still occur at the
33 // top of the screen if the accessed memory is at the beginning of the
36 // Note that this function will reduce the general performance of a
37 // computer somewhat, but it is much less of a hit than if double
38 // buffering was used for the video. Base on the frame rate of the
39 // the GLTeapot demo, it is less than a 10% reduction.
41 SharedInfo
& si
= *((SharedInfo
*)dataPtr
);
44 uint32
* src
= ((uint32
*)(si
.videoMemAddr
)) + si
.videoMemSize
/ 4 - 1;
50 snooze(30000); // sleep for 30 msec
58 InitCommon(int fileDesc
)
60 // Initialization function used by primary and cloned accelerants.
62 gInfo
.deviceFileDesc
= fileDesc
;
64 // Get area ID of shared data from driver.
67 status_t result
= ioctl(gInfo
.deviceFileDesc
, INTEL_GET_SHARED_DATA
,
68 &sharedArea
, sizeof(sharedArea
));
72 gInfo
.sharedInfoArea
= clone_area("i810 shared info",
73 (void**)&(gInfo
.sharedInfo
), B_ANY_ADDRESS
, B_READ_AREA
| B_WRITE_AREA
,
75 if (gInfo
.sharedInfoArea
< 0)
76 return gInfo
.sharedInfoArea
; // sharedInfoArea has error code
78 gInfo
.regsArea
= clone_area("i810 regs area", (void**)&(gInfo
.regs
),
79 B_ANY_ADDRESS
, B_READ_AREA
| B_WRITE_AREA
, gInfo
.sharedInfo
->regsArea
);
80 if (gInfo
.regsArea
< 0) {
81 delete_area(gInfo
.sharedInfoArea
);
82 return gInfo
.regsArea
; // regsArea has error code
92 // This function is used by both primary and cloned accelerants.
94 delete_area(gInfo
.regsArea
);
97 delete_area(gInfo
.sharedInfoArea
);
103 InitAccelerant(int fileDesc
)
105 // Initialize the accelerant. fileDesc is the file handle of the device
106 // (in /dev/graphics) that has been opened by the app_server.
108 TRACE("Enter InitAccelerant()\n");
110 gInfo
.bAccelerantIsClone
= false; // indicate this is primary accelerant
112 status_t result
= InitCommon(fileDesc
);
113 if (result
== B_OK
) {
114 SharedInfo
& si
= *gInfo
.sharedInfo
;
116 TRACE("Vendor ID: 0x%X, Device ID: 0x%X\n", si
.vendorID
, si
.deviceID
);
118 // Ensure that InitAccelerant is executed just once (copies should be
121 if (si
.bAccelerantInUse
) {
122 result
= B_NOT_ALLOWED
;
124 result
= I810_Init(); // perform init related to current chip
125 if (result
== B_OK
) {
126 result
= si
.engineLock
.Init("i810 engine lock");
127 if (result
== B_OK
) {
128 // Ensure that this function won't be executed again
129 // (copies should be clones)
130 si
.bAccelerantInUse
= true;
132 thread_id threadID
= spawn_thread(SuppressArtifacts
,
133 "SuppressArtifacts_Thread", B_DISPLAY_PRIORITY
,
135 result
= resume_thread(threadID
);
144 TRACE("Leave InitAccelerant(), result: 0x%X\n", result
);
150 AccelerantCloneInfoSize(void)
152 // Return the number of bytes required to hold the information required
153 // to clone the device. The information is merely the name of the device;
154 // thus, return the size of the name buffer.
156 return B_OS_NAME_LENGTH
;
161 GetAccelerantCloneInfo(void* data
)
163 // Return the info required to clone the device. Argument data points to
164 // a buffer which is the size returned by AccelerantCloneInfoSize().
166 ioctl(gInfo
.deviceFileDesc
, INTEL_DEVICE_NAME
, data
, B_OS_NAME_LENGTH
);
171 CloneAccelerant(void* data
)
173 // Initialize a copy of the accelerant as a clone. Argument data points to
174 // a copy of the data which was returned by GetAccelerantCloneInfo().
176 TRACE("Enter CloneAccelerant()\n");
178 char path
[MAXPATHLEN
] = "/dev/";
179 strcat(path
, (const char*)data
);
181 gInfo
.deviceFileDesc
= open(path
, B_READ_WRITE
); // open the device
182 if (gInfo
.deviceFileDesc
< 0)
185 gInfo
.bAccelerantIsClone
= true;
187 status_t result
= InitCommon(gInfo
.deviceFileDesc
);
188 if (result
!= B_OK
) {
189 close(gInfo
.deviceFileDesc
);
193 result
= gInfo
.modeListArea
= clone_area("i810 cloned display_modes",
194 (void**) &gInfo
.modeList
, B_ANY_ADDRESS
, B_READ_AREA
,
195 gInfo
.sharedInfo
->modeArea
);
198 close(gInfo
.deviceFileDesc
);
202 TRACE("Leave CloneAccelerant()\n");
208 UninitAccelerant(void)
210 delete_area(gInfo
.modeListArea
);
211 gInfo
.modeList
= NULL
;
215 if (gInfo
.bAccelerantIsClone
)
216 close(gInfo
.deviceFileDesc
);
221 GetAccelerantDeviceInfo(accelerant_device_info
* adi
)
223 // Get info about the device.
225 SharedInfo
& si
= *gInfo
.sharedInfo
;
228 strcpy(adi
->name
, "Intel 810/815 chipset");
229 strcpy(adi
->chipset
, si
.chipName
);
230 strcpy(adi
->serial_no
, "unknown");
231 adi
->memory
= si
.maxFrameBufferSize
;
232 adi
->dac_speed
= 270;