Ejemplo n.º 1
0
 /** Release all resources */
 final void release() {
   mmio.release();
   deviceRam.release();
   if (rom != null) {
     rom.release();
   }
 }
Ejemplo n.º 2
0
  /**
   * Look for the ROM in the ISA region.
   *
   * @param rm
   * @return The claimed ROM region, or null if not found.
   */
  private final MemoryResource findRom(final ResourceOwner owner, final ResourceManager rm)
      throws ResourceNotFreeException {
    final MemoryScanner scanner =
        AccessController.doPrivileged(
            new PrivilegedAction<MemoryScanner>() {

              public MemoryScanner run() {
                return rm.getMemoryScanner();
              }
            });

    final Address start = Address.fromIntZeroExtend(0xC0000);
    final Address end = Address.fromIntZeroExtend(0xF0000);
    final int size = end.toWord().sub(start.toWord()).toInt();
    final int stepSize = 0x1000;
    int offset = 0;
    while (offset < size) {
      final Address romAddr;
      // Search for BIOS expansion
      romAddr =
          scanner.findInt8Array(
              start.add(offset),
              size - offset,
              BIOS_ROM_SIGNATURE,
              0,
              BIOS_ROM_SIGNATURE.length,
              stepSize);
      if (romAddr == null) {
        return null;
      } else {
        offset = romAddr.toWord().sub(start.toWord()).toInt() + stepSize;
      }
      // Search for ATI signature
      final Address atiSigAddr;
      atiSigAddr =
          scanner.findInt8Array(romAddr, 128, ATI_ROM_SIGNATURE, 0, ATI_ROM_SIGNATURE.length, 1);
      if (atiSigAddr == null) {
        continue;
      }

      // We found it
      // Claim a small region, so we can read the size.
      MemoryResource mem;
      mem = rm.claimMemoryResource(owner, romAddr, 4, ResourceManager.MEMMODE_NORMAL);
      final int blocks = mem.getByte(2) & 0xFF;
      final int romSize = blocks * 512;
      mem.release();

      log.info(
          "Found ATI ROM at 0x"
              + NumberUtils.hex(romAddr.toInt())
              + " size="
              + NumberUtils.toBinaryByte(romSize));
      return rm.claimMemoryResource(owner, romAddr, romSize, ResourceManager.MEMMODE_NORMAL);
    }

    return null;
  }
Ejemplo n.º 3
0
 /**
  * Verify the ROM signature as being an ATI BIOS expansion area.
  *
  * @param rom
  * @return
  */
 private final boolean verifyBiosSignature(MemoryResource rom) {
   if ((rom.getByte(0) & 0xFF) != 0x55) {
     return false;
   }
   if ((rom.getByte(1) & 0xFF) != 0xAA) {
     return false;
   }
   return true;
 }
Ejemplo n.º 4
0
 private static int getRSDTVersion(ResourceManager rm, Address start) {
   final MemoryResource res;
   try {
     res = rm.claimMemoryResource(ResourceOwner.SYSTEM, start, 20, ResourceManager.MEMMODE_NORMAL);
   } catch (ResourceNotFreeException e) {
     // Cannot claim memory
     return 1;
   }
   try {
     return res.getByte(15);
   } finally {
     res.release();
   }
 }
Ejemplo n.º 5
0
  public EEPRO100TxFD(ResourceManager rm) {
    // Create a large enough buffer
    final int size = (TxFDSize + DataBufferSize) + 16 /* alignment */;
    this.data = new byte[size];
    this.mem = rm.asMemoryResource(data);

    final Address memAddr = mem.getAddress();

    this.firstDPDOffset = 0;
    this.firstDPDAddress = memAddr.add(firstDPDOffset);
  }
Ejemplo n.º 6
0
 final void setCount(int value) {
   mem.setInt(12, value);
 }
Ejemplo n.º 7
0
 final int getCount() {
   return mem.getInt(12);
 }
Ejemplo n.º 8
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getGRAF(int) */
 public int getGRAF(int index) {
   mmio.setByte(NV8_GRPHIND, (byte) index);
   return mmio.getByte(NV8_GRPHDAT) & 0xff;
 }
Ejemplo n.º 9
0
 final int getLink() {
   return mem.getInt(4);
 }
Ejemplo n.º 10
0
 final int getCommand() {
   return mem.getInt(2);
 }
Ejemplo n.º 11
0
 final int getStatus() {
   return mem.getInt(0);
 }
Ejemplo n.º 12
0
 //  put paramater array into the cmd buffer
 void setParams(byte[] p) {
   for (int i = 0; i < p.length; i++) {
     mem.setShort(i + 8, p[i]);
   }
 }
Ejemplo n.º 13
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getCRT(int) */
 public int getCRT(int index) {
   mmio.setByte(NV8_CRTCIND, (byte) index);
   return mmio.getByte(NV8_CRTCDAT) & 0xff;
 }
Ejemplo n.º 14
0
  /**
   * Open the given configuration
   *
   * @param config
   */
  final RadeonSurface open(RadeonConfiguration config) throws ResourceNotFreeException {

    // Get the best matching config
    config = fbinfo.getBestConfiguration(config);
    log.debug("BestConfig:" + config);

    // Calculate new configuration
    final DisplayMode mode = config.getDisplayMode();
    final int width = mode.getWidth();
    final int height = mode.getHeight();
    final int pixels = width * height;
    final int bitsPerPixel = config.getBitsPerPixel();
    final int bytesPerLine = config.getBytesPerLine();
    final int bytesPerScreen = bytesPerLine * height;
    log.debug("PLLInfo:" + fbinfo.getPllInfo());
    currentState.calcForConfiguration(config, vgaIO, fbinfo);

    // Disable video interrupts
    vgaIO.disableIRQ();

    // Allocate the screen memory
    final MemoryResource screen = claimDeviceMemory(bytesPerScreen, 4 * 1024);
    // final MemoryResource screen = deviceRam;
    log.debug(
        "Screen at 0x"
            + NumberUtils.hex(screen.getOffset().toInt())
            + ", size 0x"
            + NumberUtils.hex(screen.getSize().toInt()));

    // if (true) { throw new ResourceNotFreeException("TEST"); }

    // Save the current state
    oldVgaState.saveFromVGA(vgaIO);
    log.debug("oldState:" + oldVgaState);

    // Turn off the screen
    final DpmsState dpmsState = getDpms();
    setDpms(DpmsState.OFF);

    try {
      // Set the new configuration
      currentState.restoreToVGA(vgaIO);
      log.debug("NewState: " + currentState);
      vgaIO.setReg32(CRTC_OFFSET, (int) screen.getOffset().toInt());
      if (fbinfo.hasCRTC2) {
        vgaIO.setReg32(CRTC2_OFFSET, (int) screen.getOffset().toInt());
      }

      // Set the 8-bit palette
      setPalette(1.0f);

      // Create the graphics helper & clear the screen
      final BitmapGraphics bitmapGraphics;
      switch (bitsPerPixel) {
        case 8:
          bitmapGraphics =
              BitmapGraphics.create8bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setByte(0, (byte) 0, pixels);
          break;
        case 16:
          bitmapGraphics =
              BitmapGraphics.create16bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setShort(0, (byte) 0, pixels);
          break;
        case 24:
          bitmapGraphics =
              BitmapGraphics.create24bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setInt24(0, 0, pixels);
          break;
        case 32:
          bitmapGraphics =
              BitmapGraphics.create32bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setInt(0, 0, pixels);
          break;
        default:
          throw new IllegalArgumentException("Invalid bits per pixel " + bitsPerPixel);
      }
      return new RadeonSurface(this, config, bitmapGraphics, screen, accel);
    } finally {
      // Turn the screen back on
      setDpms(dpmsState);
    }
  }
Ejemplo n.º 15
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#setATTIndex(int) */
 public void setATTIndex(int index) {
   getSTAT();
   mmio.setByte(NV8_ATTRINDW, (byte) (index | 0x20));
 }
Ejemplo n.º 16
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#setATT(int, int) */
 public void setATT(int index, int val) {
   getSTAT();
   mmio.setByte(NV8_ATTRINDW, (byte) (index | 0x20));
   mmio.setByte(NV8_ATTRDATW, (byte) val);
 }
Ejemplo n.º 17
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getSTAT() */
 public int getSTAT() {
   return mmio.getByte(NV8_INSTAT1) & 0xff;
 }
Ejemplo n.º 18
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getSEQ(int) */
 public int getSEQ(int index) {
   mmio.setByte(NV8_SEQIND, (byte) index);
   return mmio.getByte(NV8_SEQDAT) & 0xff;
 }
Ejemplo n.º 19
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getMISC() */
 public int getMISC() {
   return mmio.getByte(NV8_MISCR) & 0xff;
 }
Ejemplo n.º 20
0
 void bufferAddress0(int address) {
   mem.setInt(16, address);
 }
Ejemplo n.º 21
0
 void bufferSize0(int size) {
   mem.setInt(20, size);
 }
Ejemplo n.º 22
0
 /**
  * Claim a portion of RAM on the device.
  *
  * @param size
  * @param align
  * @return
  * @throws IndexOutOfBoundsException
  * @throws ResourceNotFreeException
  */
 final MemoryResource claimDeviceMemory(int size, int align)
     throws IndexOutOfBoundsException, ResourceNotFreeException {
   return deviceRam.claimChildResource(size, align);
 }
Ejemplo n.º 23
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getATT(int) */
 public int getATT(int index) {
   getSTAT();
   mmio.setByte(NV8_ATTRINDW, (byte) (index | 0x20));
   return mmio.getByte(NV8_ATTRDATR) & 0xff;
 }
Ejemplo n.º 24
0
 /**
  * Gets an 32-bit MMIO value
  *
  * @param index
  */
 final void setReg32(int index, int value) {
   mmio.setInt(index, value);
 }
Ejemplo n.º 25
0
 final void setStatus(int value) {
   mem.setInt(0, value);
 }
Ejemplo n.º 26
0
  /**
   * @param driver
   * @param architecture
   * @param model
   * @param device
   */
  public RadeonCore(RadeonDriver driver, int architecture, String model, PCIDevice device)
      throws ResourceNotFreeException, DriverException {
    this.driver = driver;
    this.fbinfo = new FBInfo(architecture);

    final PCIHeaderType0 pciCfg = device.getConfig().asHeaderType0();
    final PCIBaseAddress ioAddr = pciCfg.getBaseAddresses()[2];
    final PCIBaseAddress fbAddr = pciCfg.getBaseAddresses()[0];
    final PCIRomAddress romAddr = pciCfg.getRomAddress();
    log.info("Found ATI " + model + ", chipset 0x" + NumberUtils.hex(pciCfg.getRevision()));
    try {
      final ResourceManager rm = InitialNaming.lookup(ResourceManager.NAME);
      final int ioBase = (int) ioAddr.getMemoryBase();
      final int ioSize = ioAddr.getSize();
      final int fbBase = (int) fbAddr.getMemoryBase() /* & 0xFF800000 */;

      // Map Memory Mapped IO
      this.mmio =
          rm.claimMemoryResource(
              device, Address.fromIntZeroExtend(ioBase), ioSize, ResourceManager.MEMMODE_NORMAL);
      this.vgaIO = new RadeonVgaIO(mmio);
      final int memSize = readMemorySize();
      log.info("Memory size " + NumberUtils.toBinaryByte(memSize));
      this.accel = new RadeonAcceleration(vgaIO);

      // Map Device RAM
      this.deviceRam =
          rm.claimMemoryResource(
              device, Address.fromIntZeroExtend(fbBase), memSize, ResourceManager.MEMMODE_NORMAL);
      vgaIO.setVideoRam(deviceRam);

      // Find ROM
      MemoryResource rom = null;
      if (romAddr != null) {
        romAddr.setEnabled(true);
        if (romAddr.isEnabled()) {
          rom =
              rm.claimMemoryResource(
                  device,
                  Address.fromIntZeroExtend(romAddr.getRomBase()),
                  romAddr.getSize(),
                  ResourceManager.MEMMODE_NORMAL);
          if (!verifyBiosSignature(rom)) {
            log.info("Signature mismatch");
            rom.release();
            rom = null;
          }
        } else {
          log.debug("Failed to enabled expansion ROM");
        }
      }
      if (rom == null) {
        // Use the ISA regions rom instead
        rom = findRom(device, rm);
      }
      this.rom = rom;

      log.debug(
          "Found ATI "
              + model
              + ", FB at 0x"
              + NumberUtils.hex(fbBase)
              + "s0x"
              + NumberUtils.hex(memSize)
              + ", MMIO at 0x"
              + NumberUtils.hex(ioBase)
              + ", ROM "
              + pciCfg.getRomAddress());

      fbinfo.readMonitorInfo(vgaIO);
      if (this.rom != null) {
        log.info("ROM[0-3] 0x" + NumberUtils.hex(rom.getInt(0)));
        // Read monitor information
        fbinfo.readFPIInfo(rom);
      }

    } catch (NameNotFoundException ex) {
      throw new ResourceNotFreeException(ex);
    }

    // Read the current state of the device
    this.oldVgaState = new RadeonVgaState(architecture, fbinfo.hasCRTC2, vgaIO);
    this.currentState = new RadeonVgaState(architecture, fbinfo.hasCRTC2, vgaIO);

    // Claim the first 128K for VGA only
    deviceRam.claimChildResource(0, 128 * 1024, false);

    // Allocate the hardware cursor
    this.hwCursor = new RadeonHardwareCursor(this, vgaIO);
  }
Ejemplo n.º 27
0
 final void setCommand(int value) {
   mem.setInt(2, value);
 }
Ejemplo n.º 28
0
 final void setDescriptorAddress(int value) {
   mem.setInt(8, value);
 }
Ejemplo n.º 29
0
 final void setLink(int value) {
   mem.setInt(4, value);
 }
Ejemplo n.º 30
0
 /** @see org.jnode.driver.video.vgahw.VgaIO#getDACData() */
 public int getDACData() {
   return mmio.getByte(PDIO_OFS + DAC_D) & 0xFF;
 }