#define MODULE_BIT 0x00000100
#include <unistd.h>
#include "nv_std.h"
static void nv_agp_list_info(agp_info ai);
static void nv_agp_list_active(uint32 cmd);
status_t
nv_agp_setup(bool enable_agp)
{
nv_nth_agp_info nai;
nv_cmd_agp nca;
uint8 index;
agp_info nv_ai = {0};
bool agp = false;
si->engine.agp_mode = false;
if (si->settings.unhide_fw) {
uint32 reg;
LOG(4, ("AGP: STRAPINFO2 contains $%08x\n", NV_REG32(NV32_NVSTRAPINFO2)));
LOG(4, ("AGP: attempting to enable fastwrite support..\n"));
reg = (NV_REG32(NV32_NVSTRAPINFO2) & ~0x00000800);
NV_REG32(NV32_NVSTRAPINFO2) = (reg | 0x80000000);
LOG(4, ("AGP: STRAPINFO2 now contains $%08x\n", NV_REG32(NV32_NVSTRAPINFO2)));
}
nca.magic = nai.magic = NV_PRIVATE_DATA_MAGIC;
for (index = 0; index < 8; index++) {
nai.index = index;
ioctl(fd, NV_GET_NTH_AGP_INFO, &nai, sizeof(nai));
if (!nai.agp_bus) {
LOG(4,("AGP: no AGP busmanager found.\n"));
return B_ERROR;
}
if (!nai.exist) {
if (index != 0)
LOG(4,("AGP: end of AGP capable devices list.\n"));
else
LOG(4,("AGP: no AGP capable devices found.\n"));
break;
}
LOG(4,("AGP: AGP capable device #%d:\n", (index + 1)));
if (nai.agpi.device_id == si->device_id
&& nai.agpi.vendor_id == si->vendor_id
&& nai.agpi.bus == si->bus
&& nai.agpi.device == si->device
&& nai.agpi.function == si->function) {
LOG(4,("AGP: (this is the device this accelerant controls)\n"));
agp = true;
nv_ai = nai.agpi;
}
nv_agp_list_info(nai.agpi);
}
if (!agp) {
LOG(4,("AGP: the graphicscard this accelerant controls is PCI type.\n"));
CFGW(AGPCMD, 0x00000000);
return B_ERROR;
}
if (si->settings.force_pci || !enable_agp) {
if (enable_agp)
LOG(4,("AGP: forcing PCI mode (specified in nv.settings)\n"));
else
LOG(4,("AGP: forcing PCI mode during coldstart (required)\n"));
nca.cmd = 0x00000000;
ioctl(fd, NV_ENABLE_AGP, &nca, sizeof(nca));
} else {
LOG(4,("AGP: activating AGP mode...\n"));
nca.cmd = 0xfffffff7;
if (nv_ai.interface.status & AGP_3_MODE)
nca.cmd |= AGP_3_MODE;
ioctl(fd, NV_ENABLE_AGP, &nca, sizeof(nca));
if (nca.cmd & AGP_ENABLE)
si->engine.agp_mode = true;
}
nv_agp_list_active(nca.cmd | (nv_ai.interface.status & AGP_3_MODE));
LOG(4,("AGP: graphics card AGPCMD register readback $%08x\n", CFGR(AGPCMD)));
return B_OK;
}
static void
nv_agp_list_info(agp_info ai)
{
if (ai.class_base == PCI_display)
LOG(4,("AGP: device is a graphicscard, subclass ID is $%02x\n", ai.class_sub));
else
LOG(4,("AGP: device is a hostbridge, subclass ID is $%02x\n", ai.class_sub));
LOG(4,("AGP: vendor ID $%04x\n", ai.vendor_id));
LOG(4,("AGP: device ID $%04x\n", ai.device_id));
LOG(4,("AGP: bus %d, device %d, function %d\n", ai.bus, ai.device, ai.function));
LOG(4,("AGP: this device supports AGP specification %d.%d;\n",
((ai.interface.capability_id & AGP_REV_MAJOR) >> AGP_REV_MAJOR_SHIFT),
((ai.interface.capability_id & AGP_REV_MINOR) >> AGP_REV_MINOR_SHIFT)));
if (!(ai.interface.status & AGP_3_MODE)) {
if (ai.interface.status & AGP_2_1x)
LOG(4,("AGP: AGP 2.0 1x mode is available\n"));
if (ai.interface.status & AGP_2_2x)
LOG(4,("AGP: AGP 2.0 2x mode is available\n"));
if (ai.interface.status & AGP_2_4x)
LOG(4,("AGP: AGP 2.0 4x mode is available\n"));
} else {
if (ai.interface.status & AGP_3_4x)
LOG(4,("AGP: AGP 3.0 4x mode is available\n"));
if (ai.interface.status & AGP_3_8x)
LOG(4,("AGP: AGP 3.0 8x mode is available\n"));
}
if (ai.interface.status & AGP_FAST_WRITE)
LOG(4,("AGP: fastwrite transfers are supported\n"));
if (ai.interface.status & AGP_SBA)
LOG(4,("AGP: sideband adressing is supported\n"));
LOG(4,("AGP: %d queued AGP requests can be handled.\n",
(((ai.interface.status & AGP_REQUEST) >> AGP_REQUEST_SHIFT) + 1)));
nv_agp_list_active(ai.interface.command
| (ai.interface.status & AGP_3_MODE));
}
static void
nv_agp_list_active(uint32 cmd)
{
LOG(4,("AGP: listing settings now in use:\n"));
if (!(cmd & AGP_3_MODE)) {
if (cmd & AGP_2_1x)
LOG(4,("AGP: AGP 2.0 1x mode is set\n"));
if (cmd & AGP_2_2x)
LOG(4,("AGP: AGP 2.0 2x mode is set\n"));
if (cmd & AGP_2_4x)
LOG(4,("AGP: AGP 2.0 4x mode is set\n"));
} else {
if (cmd & AGP_3_4x)
LOG(4,("AGP: AGP 3.0 4x mode is set\n"));
if (cmd & AGP_3_8x)
LOG(4,("AGP: AGP 3.0 8x mode is set\n"));
}
if (cmd & AGP_FAST_WRITE)
LOG(4,("AGP: fastwrite transfers are enabled\n"));
if (cmd & AGP_SBA)
LOG(4,("AGP: sideband adressing is enabled\n"));
LOG(4,("AGP: max. AGP queued request depth is set to %d\n",
(((cmd & AGP_REQUEST) >> AGP_REQUEST_SHIFT) + 1)));
if (cmd & AGP_ENABLE)
LOG(4,("AGP: the AGP interface is enabled.\n"));
else
LOG(4,("AGP: the AGP interface is disabled.\n"));
}