rm = InitialNaming.lookup(ResourceManager.NAME);
} catch (NameNotFoundException ex) {
throw new DriverException("Cannot find ResourceManager");
}
final PCIHeaderType0 pciCfg = device.getConfig().asHeaderType0();
final PCIBaseAddress[] baseAddrs = pciCfg.getBaseAddresses();
if (baseAddrs.length < 1) {
throw new DriverException(
"No memory mapped I/O region in PCI config");
}
final PCIBaseAddress regsAddr = pciCfg.getBaseAddresses()[0];
if (!regsAddr.isMemorySpace()) {
throw new DriverException("Memory mapped I/O is not a memory space");
}
// Claim the memory mapped I/O region
final Address regsAddrPtr = Address.fromLong(regsAddr.getMemoryBase());
final Extent regsSize = Extent.fromIntZeroExtend(regsAddr.getSize());
try {
final MemoryResource regs;
regs = rm.claimMemoryResource(device, regsAddrPtr, regsSize,
ResourceManager.MEMMODE_NORMAL);
this.io = new Prism2IO(regs);
} catch (ResourceNotFreeException ex) {
throw new DriverException("Cannot claim memory mapped I/O", ex);
}
// Claim IRQ
final int irqNo = pciCfg.getInterruptLine();
try {
this.irq = rm.claimIRQ(device, irqNo, this, true);
} catch (ResourceNotFreeException ex) {
// Release IO
io.release();