Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
Other authors:
Mark Watson,
Rudolf Cornelissen 10/2002-1/2016.
*/
#define MODULE_BIT 0x00800000
#include <string.h>
#include <unistd.h>
#include "acc_std.h"
static status_t init_common(int the_fd);
static status_t init_common(int the_fd) {
status_t result;
nv_get_private_data gpd;
fd = the_fd;
gpd.magic = NV_PRIVATE_DATA_MAGIC;
result = ioctl(fd, NV_GET_PRIVATE_DATA, &gpd, sizeof(gpd));
if (result != B_OK)
goto error0;
shared_info_area = clone_area(DRIVER_PREFIX " shared", (void **)&si, B_ANY_ADDRESS,
B_READ_AREA | B_WRITE_AREA, gpd.shared_info_area);
if (shared_info_area < 0) {
result = shared_info_area;
goto error0;
}
LOG(4,("init_common: logmask 0x%08x, memory %dMB, hardcursor %d, usebios %d, switchhead %d, force_pci %d\n",
si->settings.logmask, si->settings.memory, si->settings.hardcursor, si->settings.usebios, si->settings.switchhead, si->settings.force_pci));
LOG(4,("init_common: dumprom %d, unhide_fw %d, pgm_panel %d, dma_acc %d, tv_output %d, vga_on_tv %d\n",
si->settings.dumprom, si->settings.unhide_fw, si->settings.pgm_panel, si->settings.dma_acc, si->settings.tv_output, si->settings.vga_on_tv));
LOG(4,("init_common: force_sync %d, gpu_clk %dMhz, ram_clk %dMhz, force_ws %d, block_acc %d, check_edid %d\n",
si->settings.force_sync, si->settings.gpu_clk, si->settings.ram_clk, si->settings.force_ws, si->settings.block_acc, si->settings.check_edid));
{
if (si->use_clone_bugfix)
{
LOG(2,("InitACC: Found R4.5.0 bug - attempting to work around\n"));
regs = si->clone_bugfix_regs;
}
else
{
regs_area = clone_area(DRIVER_PREFIX " regs", (void **)®s, B_ANY_ADDRESS,
B_READ_AREA | B_WRITE_AREA, si->regs_area);
if (regs_area < 0) {
result = regs_area;
goto error1;
}
}
}
goto error0;
error1:
delete_area(shared_info_area);
error0:
return result;
}
static void uninit_common(void) {
delete_area(regs_area);
regs = 0;
delete_area(shared_info_area);
si = 0;
}
Initialize the accelerant. the_fd is the file handle of the device (in
/dev/graphics) that has been opened by the app_server (or some test harness).
We need to determine if the kernel driver and the accelerant are compatible.
If they are, get the accelerant ready to handle other hook functions and
report success or failure.
*/
status_t INIT_ACCELERANT(int the_fd)
{
status_t result;
int pointer_reservation;
int cnt;
if (0) {
time_t now = time (NULL);
MSG(("INIT_ACCELERANT: %s", ctime (&now)));
}
accelerantIsClone = 0;
result = init_common(the_fd);
if (result != B_OK)
goto error0;
if (si->accelerant_in_use)
{
result = B_NOT_ALLOWED;
goto error1;
}
result = nv_general_powerup();
if (result != B_OK)
goto error1;
Now would be a good time to figure out what video modes your card supports.
We'll place the list of modes in another shared area so all of the copies
of the driver can see them. The primary copy of the accelerant (ie the one
initialized with this routine) will own the "one true copy" of the list.
Everybody else get's a read-only clone.
*/
result = create_mode_list();
if (result != B_OK)
goto error1;
Put the cursor at the start of the frame buffer.
Nvidia cursor is 32x32 16 color? takes up 4096 bytes of RAM.
*/
si->cursor.width = 16;
si->cursor.height = 16;
si->cursor.hot_x = 0;
si->cursor.hot_y = 0;
si->cursor.x = 0;
si->cursor.y = 0;
si->cursor.dh_right = false;
Put the frame buffer immediately following the cursor data. We store this
info in a frame_buffer_config structure to make it convienient to return
to the app_server later.
*/
pointer_reservation = 0;
if (si->settings.hardcursor) pointer_reservation = 2048;
si->fbc.frame_buffer = (void *)((char *)si->framebuffer+pointer_reservation);
si->fbc.frame_buffer_dma = (void *)((char *)si->framebuffer_pci+pointer_reservation);
si->engine.last_idle = si->engine.count = 0;
si->engine.threeD.clones = 0;
si->engine.threeD.reload = 0xffffffff;
INIT_BEN(si->engine.lock);
INIT_BEN(si->overlay.lock);
for (cnt = 0; cnt < MAXBUFFERS; cnt++)
{
si->overlay.myBuffer[cnt].buffer = NULL;
si->overlay.myBuffer[cnt].buffer_dma = NULL;
}
si->overlay.myToken = NULL;
si->overlay.active = false;
head1_cursor_init();
if (si->ps.secondary_head) head2_cursor_init();
head1_cursor_hide();
if (si->ps.secondary_head) head2_cursor_hide();
si->dpms_flags = B_DPMS_ON;
* TVencoder is on head to be assigned primary, no dualhead switch mode active. */
si->dm.flags = TV_PRIMARY;
* note: update in _this_ order only */
si->engine.threeD.mode_changing = true;
si->engine.threeD.newmode = 0xffffffff;
si->haiku_prefs_used = false;
si->Haiku_switch_head = false;
result = B_OK;
si->accelerant_in_use = true;
goto error0;
error1:
Initialization failed after init_common() succeeded, so we need to clean
up before quiting.
*/
uninit_common();
error0:
return result;
}
Return the number of bytes required to hold the information required
to clone the device.
*/
ssize_t ACCELERANT_CLONE_INFO_SIZE(void) {
Since we're passing the name of the device as the only required
info, return the size of the name buffer
*/
return B_OS_NAME_LENGTH;
}
Return the info required to clone the device. void *data points to
a buffer at least ACCELERANT_CLONE_INFO_SIZE() bytes in length.
*/
void GET_ACCELERANT_CLONE_INFO(void *data) {
nv_device_name dn;
status_t result;
dn.magic = NV_PRIVATE_DATA_MAGIC;
dn.name = (char *)data;
result = ioctl(fd, NV_DEVICE_NAME, &dn, sizeof(dn));
}
Initialize a copy of the accelerant as a clone. void *data points to
a copy of the data returned by GET_ACCELERANT_CLONE_INFO().
*/
status_t CLONE_ACCELERANT(void *data)
{
status_t result;
char path[MAXPATHLEN];
strcpy(path, "/dev/");
strcat(path, (const char *)data);
fd = open(path, B_READ_WRITE);
if (fd < 0)
{
char fname[64];
FILE *myhand = NULL;
sprintf (fname, "/boot/home/" DRIVER_PREFIX ".accelerant.0.log");
myhand=fopen(fname,"a+");
fprintf(myhand, "CLONE_ACCELERANT: couldn't open kerneldriver %s! Aborting.\n", path);
fclose(myhand);
result = fd;
goto error0;
}
accelerantIsClone = 1;
result = init_common(fd);
if (result != B_OK) goto error1;
if (!(si->accelerant_in_use))
{
result = B_NOT_ALLOWED;
goto error2;
}
if (si->ps.secondary_head)
setup_virtualized_heads(si->crtc_switch_mode);
else
setup_virtualized_heads(si->ps.crtc2_prim);
result = my_mode_list_area = clone_area(
DRIVER_PREFIX " cloned display_modes",
(void **)&my_mode_list,
B_ANY_ADDRESS,
B_READ_AREA,
si->mode_area
);
if (result < B_OK) goto error2;
LOG(4,("CLONE_ACCELERANT: cloning was succesfull.\n"));
result = B_OK;
goto error0;
error2:
uninit_common();
error1:
close(fd);
error0:
return result;
}
void UNINIT_ACCELERANT(void)
{
if (accelerantIsClone)
{
LOG(4,("UNINIT_ACCELERANT: shutting down clone accelerant.\n"));
}
else
{
LOG(4,("UNINIT_ACCELERANT: shutting down primary accelerant.\n"));
DELETE_BEN(si->engine.lock);
DELETE_BEN(si->overlay.lock);
si->accelerant_in_use = false;
}
delete_area(my_mode_list_area);
my_mode_list = 0;
uninit_common();
if (accelerantIsClone) close(fd);
}