status_t Transaction::RegisterBlock(uint64 blockIndex) { ASSERT(fID >= 0); // look it up -- maybe it's already registered BlockInfo* info = fBlockInfos.Lookup(blockIndex); if (info != NULL) { info->refCount++; return B_OK; } // nope, create a new one info = new(std::nothrow) BlockInfo; if (info == NULL) RETURN_ERROR(B_NO_MEMORY); ObjectDeleter<BlockInfo> infoDeleter(info); info->indexAndCheckSum.blockIndex = blockIndex; info->refCount = 1; info->dirty = false; // get the old check sum if (ioctl(fVolume->FD(), CHECKSUM_DEVICE_IOCTL_GET_CHECK_SUM, &info->indexAndCheckSum, sizeof(info->indexAndCheckSum)) < 0) { RETURN_ERROR(errno); } // get the data (we're fine with read-only) info->data = block_cache_get(fVolume->BlockCache(), blockIndex); if (info->data == NULL) { delete info; RETURN_ERROR(B_ERROR); } fBlockInfos.Insert(infoDeleter.Detach()); return B_OK; }
static status_t openpic_init_driver(device_node *node, void **cookie) { // OK, this module is broken for now. But it compiles. return B_ERROR; openpic_info *info = new(nothrow) openpic_info; if (!info) return B_NO_MEMORY; ObjectDeleter<openpic_info> infoDeleter(info); info->node = node; // get interface to PCI device void *aCookie; void *anotherCookie; // possibly the same cookie. driver_module_info *driver; status_t status = sDeviceManager->get_driver(sDeviceManager->get_parent_node(node), &driver, &aCookie); if (status != B_OK) return status; driver->init_driver(node, &anotherCookie); /* status = sDeviceManager->init_driver( sDeviceManager->get_parent(node), NULL, (driver_module_info**)&info->pci, (void**)&info->device); if (status != B_OK) return status; */ // get the pci info for the device pci_info pciInfo; info->pci->get_pci_info(info->device, &pciInfo); // find supported device info info->supported_device = openpic_check_supported_device(pciInfo.vendor_id, pciInfo.device_id); if (!info->supported_device) { dprintf("openpic: device (0x%04hx:0x%04hx) not supported\n", pciInfo.vendor_id, pciInfo.device_id); return B_ERROR; } dprintf("openpic: found supported device: %s (0x%04hx:0x%04hx)\n", info->supported_device->name, pciInfo.vendor_id, pciInfo.device_id); // get register space addr_t physicalRegisterBase = pciInfo.u.h0.base_registers[0]; uint32 registerSpaceSize = pciInfo.u.h0.base_register_sizes[0]; if (registerSpaceSize < info->supported_device->register_offset || registerSpaceSize - info->supported_device->register_offset < OPENPIC_MIN_REGISTER_SPACE_SIZE) { dprintf("openpic: register space too small\n"); } physicalRegisterBase += info->supported_device->register_offset; registerSpaceSize -= info->supported_device->register_offset; if (registerSpaceSize > OPENPIC_MAX_REGISTER_SPACE_SIZE) registerSpaceSize = OPENPIC_MAX_REGISTER_SPACE_SIZE; // map register space void *virtualRegisterBase = NULL; area_id registerArea = map_physical_memory("openpic registers", (void*)physicalRegisterBase, registerSpaceSize, B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &virtualRegisterBase); if (registerArea < 0) return info->register_area; info->physical_registers = physicalRegisterBase; info->register_space_size = registerSpaceSize; info->register_area = registerArea; info->virtual_registers = (addr_t)virtualRegisterBase; // init the controller status = openpic_init(info); if (status != B_OK) return status; // keep the info infoDeleter.Detach(); *cookie = info; dprintf("openpic_init_driver(): Successfully initialized!\n"); return B_OK; }