2 * Copyright 2007-2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
9 #include "accelerant.h"
17 AccelerantInfo gInfo
; // global data used by various source files of
23 InitCommon(int fileDesc
)
25 // Initialization function used by primary and cloned accelerants.
27 gInfo
.deviceFileDesc
= fileDesc
;
29 // Get area ID of shared data from driver.
32 status_t result
= ioctl(gInfo
.deviceFileDesc
, TDFX_GET_SHARED_DATA
,
33 &sharedArea
, sizeof(sharedArea
));
37 gInfo
.sharedInfoArea
= clone_area("3DFX shared info",
38 (void**)&(gInfo
.sharedInfo
), B_ANY_ADDRESS
, B_READ_AREA
| B_WRITE_AREA
,
40 if (gInfo
.sharedInfoArea
< 0)
41 return gInfo
.sharedInfoArea
; // sharedInfoArea has error code
43 gInfo
.regsArea
= clone_area("3DFX regs area", (void**)&(gInfo
.regs
),
44 B_ANY_ADDRESS
, B_READ_AREA
| B_WRITE_AREA
, gInfo
.sharedInfo
->regsArea
);
45 if (gInfo
.regsArea
< 0) {
46 delete_area(gInfo
.sharedInfoArea
);
47 return gInfo
.regsArea
; // regsArea has error code
57 // This function is used by both primary and cloned accelerants.
59 delete_area(gInfo
.regsArea
);
62 delete_area(gInfo
.sharedInfoArea
);
68 InitAccelerant(int fileDesc
)
70 // Initialize the accelerant. fileDesc is the file handle of the device
71 // (in /dev/graphics) that has been opened by the app_server.
73 TRACE("Enter InitAccelerant()\n");
75 gInfo
.bAccelerantIsClone
= false; // indicate this is primary accelerant
77 status_t result
= InitCommon(fileDesc
);
79 SharedInfo
& si
= *gInfo
.sharedInfo
;
81 TRACE("Vendor ID: 0x%X, Device ID: 0x%X\n", si
.vendorID
, si
.deviceID
);
83 // Ensure that InitAccelerant is executed just once (copies should be clones)
85 if (si
.bAccelerantInUse
) {
86 result
= B_NOT_ALLOWED
;
88 result
= TDFX_Init(); // perform init related to current chip
90 result
= si
.engineLock
.Init("3DFX engine lock");
92 result
= si
.overlayLock
.Init("3DFX overlay lock");
94 TDFX_ShowCursor(false);
96 // ensure that this function won't be executed again
97 // (copies should be clones)
98 si
.bAccelerantInUse
= true;
107 TRACE("Leave InitAccelerant(), result: 0x%X\n", result
);
113 AccelerantCloneInfoSize(void)
115 // Return the number of bytes required to hold the information required
116 // to clone the device. The information is merely the name of the device;
117 // thus, return the size of the name buffer.
119 return B_OS_NAME_LENGTH
;
124 GetAccelerantCloneInfo(void* data
)
126 // Return the info required to clone the device. Argument data points to
127 // a buffer which is the size returned by AccelerantCloneInfoSize().
129 ioctl(gInfo
.deviceFileDesc
, TDFX_DEVICE_NAME
, data
, B_OS_NAME_LENGTH
);
134 CloneAccelerant(void* data
)
136 // Initialize a copy of the accelerant as a clone. Argument data points to
137 // a copy of the data which was returned by GetAccelerantCloneInfo().
139 TRACE("Enter CloneAccelerant()\n");
141 char path
[MAXPATHLEN
] = "/dev/";
142 strcat(path
, (const char*)data
);
144 gInfo
.deviceFileDesc
= open(path
, B_READ_WRITE
); // open the device
145 if (gInfo
.deviceFileDesc
< 0)
148 gInfo
.bAccelerantIsClone
= true;
150 status_t result
= InitCommon(gInfo
.deviceFileDesc
);
151 if (result
!= B_OK
) {
152 close(gInfo
.deviceFileDesc
);
156 result
= gInfo
.modeListArea
= clone_area("3DFX cloned display_modes",
157 (void**) &gInfo
.modeList
, B_ANY_ADDRESS
, B_READ_AREA
,
158 gInfo
.sharedInfo
->modeArea
);
161 close(gInfo
.deviceFileDesc
);
165 TRACE("Leave CloneAccelerant()\n");
171 UninitAccelerant(void)
173 delete_area(gInfo
.modeListArea
);
174 gInfo
.modeList
= NULL
;
178 if (gInfo
.bAccelerantIsClone
)
179 close(gInfo
.deviceFileDesc
);
184 GetAccelerantDeviceInfo(accelerant_device_info
* adi
)
186 // Get info about the device.
188 SharedInfo
& si
= *gInfo
.sharedInfo
;
191 strcpy(adi
->name
, "3dfx chipset");
192 strcpy(adi
->chipset
, si
.chipName
);
193 strcpy(adi
->serial_no
, "unknown");
194 adi
->memory
= si
.maxFrameBufferSize
;
195 adi
->dac_speed
= 270;