static status_t InitDevice(DeviceInfo& di) { // Perform initialization and mapping of the device, and return B_OK if // sucessful; else, return error code. // Create the area for shared info with NO user-space read or write // permissions, to prevent accidental damage. TRACE("enter InitDevice()\n"); pci_info& pciInfo = di.pciInfo; char sharedName[B_OS_NAME_LENGTH]; sprintf(sharedName, DEVICE_FORMAT " shared", pciInfo.vendor_id, pciInfo.device_id, pciInfo.bus, pciInfo.device, pciInfo.function); di.sharedArea = create_area(sharedName, (void**) &(di.sharedInfo), B_ANY_KERNEL_ADDRESS, ((sizeof(SharedInfo) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1)), B_FULL_LOCK, 0); if (di.sharedArea < 0) return di.sharedArea; // return error code SharedInfo& si = *(di.sharedInfo); si.vendorID = pciInfo.vendor_id; si.deviceID = pciInfo.device_id; si.revision = pciInfo.revision; si.chipType = di.pChipInfo->chipType; strcpy(si.chipName, di.pChipInfo->chipName); // Trio64 and Trio64V+ chips have the same ID but different revision numbers. // Since the Trio64V+ supports MMIO, better performance can be obtained // from it if it is distinguished from the Trio64. if (si.chipType == S3_TRIO64 && si.revision & 0x40) { si.chipType = S3_TRIO64_VP; strcpy(si.chipName, "Trio64 V+"); } status_t status = MapDevice(di); if (status < 0) { delete_area(di.sharedArea); di.sharedArea = -1; di.sharedInfo = NULL; return status; // return error code } InitInterruptHandler(di); TRACE("Interrupt assigned: %s\n", si.bInterruptAssigned ? "yes" : "no"); return B_OK; }
static status_t OpenHook(const char *name, uint32 flags, void **cookie) { status_t ret = B_OK; pci_info *pcii = &gPd->pcii; uint32 tmpUlong; TRACE("OpenHook (%s, %ld)\n", name, flags); ACQUIRE_BEN(gPd->kernel); if (gPd->isOpen) goto markAsOpen; /* Enable memory mapped IO and VGA I/O */ tmpUlong = get_pci(PCI_command, 2); tmpUlong |= PCI_command_memory; tmpUlong |= PCI_command_io; set_pci(PCI_command, 2, tmpUlong); if ((ret = CreateShared()) != B_OK) goto done; if ((ret = CheckCapabilities()) != B_OK) goto freeShared; if ((ret = MapDevice()) != B_OK) goto freeShared; markAsOpen: gPd->isOpen++; *cookie = gPd; goto done; freeShared: FreeShared(); done: RELEASE_BEN(gPd->kernel); TRACE("OpenHook: %ld\n", ret); return ret; }
static status_t InitDevice(DeviceInfo& di) { // Perform initialization and mapping of the device, and return B_OK if // sucessful; else, return error code. // Get the table of VESA modes that the chip supports. Note that we will // need this table only for chips that are currently connected to a laptop // display or a monitor connected via a DVI interface. size_t vesaModeTableSize = 0; VesaMode* vesaModes = (VesaMode*)get_boot_item(VESA_MODES_BOOT_INFO, &vesaModeTableSize); size_t sharedSize = (sizeof(SharedInfo) + 7) & ~7; // Create the area for shared info with NO user-space read or write // permissions, to prevent accidental damage. di.sharedArea = create_area("ATI shared info", (void**) &(di.sharedInfo), B_ANY_KERNEL_ADDRESS, ROUND_TO_PAGE_SIZE(sharedSize + vesaModeTableSize), B_FULL_LOCK, 0); if (di.sharedArea < 0) return di.sharedArea; // return error code SharedInfo& si = *(di.sharedInfo); memset(&si, 0, sharedSize); if (vesaModes != NULL) { si.vesaModeTableOffset = sharedSize; si.vesaModeCount = vesaModeTableSize / sizeof(VesaMode); memcpy((uint8*)&si + si.vesaModeTableOffset, vesaModes, vesaModeTableSize); } pci_info& pciInfo = di.pciInfo; si.vendorID = pciInfo.vendor_id; si.deviceID = pciInfo.device_id; si.revision = pciInfo.revision; si.chipType = di.pChipInfo->chipType; strcpy(si.chipName, di.pChipInfo->chipName); TRACE("Chip revision: 0x%x\n", si.revision); // 264GT has two chip versions. If version is non-zero, chip is 264GTB. if (si.chipType == MACH64_264GT && si.revision & 0x7) si.chipType = MACH64_264GTB; // 264VT has two chip versions. If version is non-zero, chip is 264VTB. if (si.chipType == MACH64_264VT && si.revision & 0x7) si.chipType = MACH64_264VTB; status_t status = MapDevice(di); // If device mapped without any error, get the bios parameters from the // chip's BIOS ROM. if (status >= 0) { if (MACH64_FAMILY(si.chipType)) { uint8 clockType; Mach64_GetBiosParameters(di, clockType); // All chips supported by this driver should have an internal clock. // If the clock is not an internal clock, the video chip is not // supported. if (clockType != M64_CLOCK_INTERNAL) { TRACE("Video chip clock type %d not supported\n", clockType); status = B_UNSUPPORTED; } } else if (RAGE128_FAMILY(si.chipType)) Rage128_GetBiosParameters(di); } if (status < 0) { delete_area(di.sharedArea); di.sharedArea = -1; di.sharedInfo = NULL; return status; // return error code } InitInterruptHandler(di); TRACE("Interrupt assigned: %s\n", si.bInterruptAssigned ? "yes" : "no"); return B_OK; }