* @throws DriverException
*/
public Prism2Core(Prism2Driver driver, ResourceOwner owner,
PCIDevice device, Flags flags) throws DriverException {
if (!(flags instanceof Prism2Flags))
throw new DriverException("Wrong flags to the Prism2 driver");
this.driver = driver;
this.device = device;
this.flags = (Prism2Flags) flags;
final ResourceManager rm;
try {
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();
io = null;
// re-throw exception
throw new DriverException("Cannot claim IRQ", ex);
}
log.info("Found " + flags.getName() + ", regs at "
+ MagicUtils.toString(regsAddrPtr));
}