status_t init_driver(void) { // Get handle for the pci bus. if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPCI) != B_OK) return B_ERROR; status_t status = gLock.Init("ATI driver lock"); if (status < B_OK) return status; // Get info about all the devices supported by this driver. uint32 pciIndex = 0; uint32 count = 0; while (count < MAX_DEVICES) { DeviceInfo& di = gDeviceInfo[count]; const ChipInfo* pDevice = GetNextSupportedDevice(pciIndex, di.pciInfo); if (pDevice == NULL) break; // all supported devices have been obtained // Compose device name. sprintf(di.name, "graphics/" DEVICE_FORMAT, di.pciInfo.vendor_id, di.pciInfo.device_id, di.pciInfo.bus, di.pciInfo.device, di.pciInfo.function); TRACE("init_driver() match found; name: %s\n", di.name); gDeviceNames[count] = di.name; di.openCount = 0; // mark driver as available for R/W open di.sharedArea = -1; // indicate shared area not yet created di.sharedInfo = NULL; di.pChipInfo = pDevice; count++; pciIndex++; } gDeviceNames[count] = NULL; // terminate list with null pointer TRACE("init_driver() %ld supported devices\n", count); return B_OK; }
status_t init_hardware(void) { // Return B_OK if a device supported by this driver is found; otherwise, // return B_ERROR so the driver will be unloaded. if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPCI) != B_OK) return B_ERROR; // unable to access PCI bus // Check pci devices for a device supported by this driver. uint32 pciIndex = 0; pci_info pciInfo; const ChipInfo* pDevice = GetNextSupportedDevice(pciIndex, pciInfo); TRACE("init_hardware() - %s\n", pDevice == NULL ? "no supported devices" : "device supported"); put_module(B_PCI_MODULE_NAME); // put away the module manager return (pDevice == NULL ? B_ERROR : B_OK); }