tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / accelerants / intel_810 / accelerant.cpp
blob0d4b4959f2499eea49c6f1d6fe0d9f8f6a67160b
1 /*
2 * Copyright 2007-2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Gerald Zajac
7 */
10 #include "accelerant.h"
12 #include <errno.h>
13 #include <string.h>
14 #include <unistd.h>
17 AccelerantInfo gInfo; // global data used by source files of accelerant
19 static uint32 videoValue;
22 static int32
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
34 // video memory.
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);
43 while (true) {
44 uint32* src = ((uint32*)(si.videoMemAddr)) + si.videoMemSize / 4 - 1;
45 uint32 count = 65000;
47 while (count-- > 0)
48 videoValue = *src--;
50 snooze(30000); // sleep for 30 msec
53 return 0;
57 static status_t
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.
66 area_id sharedArea;
67 status_t result = ioctl(gInfo.deviceFileDesc, INTEL_GET_SHARED_DATA,
68 &sharedArea, sizeof(sharedArea));
69 if (result != B_OK)
70 return result;
72 gInfo.sharedInfoArea = clone_area("i810 shared info",
73 (void**)&(gInfo.sharedInfo), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
74 sharedArea);
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
85 return B_OK;
89 static void
90 UninitCommon(void)
92 // This function is used by both primary and cloned accelerants.
94 delete_area(gInfo.regsArea);
95 gInfo.regs = 0;
97 delete_area(gInfo.sharedInfoArea);
98 gInfo.sharedInfo = 0;
102 status_t
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
119 // clones)
121 if (si.bAccelerantInUse) {
122 result = B_NOT_ALLOWED;
123 } else {
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,
134 gInfo.sharedInfo);
135 result = resume_thread(threadID);
140 if (result != B_OK)
141 UninitCommon();
144 TRACE("Leave InitAccelerant(), result: 0x%X\n", result);
145 return result;
149 ssize_t
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;
160 void
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);
170 status_t
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)
183 return errno;
185 gInfo.bAccelerantIsClone = true;
187 status_t result = InitCommon(gInfo.deviceFileDesc);
188 if (result != B_OK) {
189 close(gInfo.deviceFileDesc);
190 return result;
193 result = gInfo.modeListArea = clone_area("i810 cloned display_modes",
194 (void**) &gInfo.modeList, B_ANY_ADDRESS, B_READ_AREA,
195 gInfo.sharedInfo->modeArea);
196 if (result < 0) {
197 UninitCommon();
198 close(gInfo.deviceFileDesc);
199 return result;
202 TRACE("Leave CloneAccelerant()\n");
203 return B_OK;
207 void
208 UninitAccelerant(void)
210 delete_area(gInfo.modeListArea);
211 gInfo.modeList = NULL;
213 UninitCommon();
215 if (gInfo.bAccelerantIsClone)
216 close(gInfo.deviceFileDesc);
220 status_t
221 GetAccelerantDeviceInfo(accelerant_device_info* adi)
223 // Get info about the device.
225 SharedInfo& si = *gInfo.sharedInfo;
227 adi->version = 1;
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;
234 return B_OK;