*/
public Mach64Core(Mach64Driver driver, String model, PCIDevice device)
throws ResourceNotFreeException, DriverException {
this.driver = driver;
final PCIDeviceConfig pciCfg = device.getConfig();
// Disable VGA I/O, enable memory mapped I/O
int cmd = pciCfg.getCommand();
cmd &= ~PCIConstants.PCI_COMMAND_IO;
cmd |= PCIConstants.PCI_COMMAND_MEMORY;
pciCfg.setCommand(cmd);
final PCIBaseAddress fbAddr = pciCfg.asHeaderType0().getBaseAddresses()[0];
log.info("Found ATI " + model + ", pci " + pciCfg);
try {
final ResourceManager rm = InitialNaming.lookup(ResourceManager.NAME);
final int fbBase = (int) fbAddr.getMemoryBase() /* & 0xFF800000 */;
final int memSize = fbAddr.getSize();
log.info("Memory size " + NumberUtils.toBinaryByte(memSize));
// Map Device RAM
this.deviceRam =
rm.claimMemoryResource(device, Address.fromIntZeroExtend(fbBase), memSize,
ResourceManager.MEMMODE_NORMAL);
// Map MMIO block 0, first test for 8Mb framebuffers.
Offset block0Ofs = Offset.fromIntZeroExtend(0x7ffc00);
Extent mmioSize = Extent.fromIntZeroExtend(1024); // 1K
MemoryResource mmio0 = deviceRam.claimChildResource(block0Ofs, mmioSize, false);
Mach64VgaIO io = new Mach64VgaIO(deviceRam, mmio0);
if ((io.getReg32(CONFIG_CHIP_ID) & CFG_CHIP_TYPE) != pciCfg.getDeviceID()) {
// Try for 4Mb framebuffers.
mmio0.release();
block0Ofs = Offset.fromIntZeroExtend(0x3ffc00);
mmio0 = deviceRam.claimChildResource(block0Ofs, mmioSize, false);
io = new Mach64VgaIO(deviceRam, mmio0);
if ((io.getReg32(CONFIG_CHIP_ID) & CFG_CHIP_TYPE) != pciCfg.getDeviceID()) {
throw new DriverException("Cannot find block0 registers.");
}
}
this.vgaIO = io;
this.mmio0 = mmio0;