ati.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * ATI Mach64 (264VT / 3D Rage) -- GPU-specific CRTC fixups.
  3. *
  4. * The CRTC_OFF_PITCH register (byte offset 0x14 in the MMIO block) controls
  5. * display start offset and scanline pitch. Standard VGA CRTC writes and
  6. * VBE 4F07h are ignored by these chips. We zero the offset field directly
  7. * through PCI MMIO or block I/O.
  8. *
  9. * CRTC_OFF_PITCH layout (32 bits):
  10. * bits 0-19: CRTC_OFFSET (display start in 8-byte units)
  11. * bits 22-31: CRTC_PITCH (scanline pitch in 8-pixel units)
  12. *
  13. * Access is verified by reading CONFIG_CHIP_ID (byte offset 0xE0) and
  14. * checking the lower 16 bits match the PCI device ID.
  15. *
  16. * Methods tried in order:
  17. * 1 - BAR2 separate MMIO aperture
  18. * 2 - MMIO at end of LFB aperture (LFB + 8 MB - 1 KB)
  19. * 3 - MMIO at end of LFB aperture (LFB + 4 MB - 1 KB)
  20. * 4 - BAR1 block I/O
  21. */
  22. #include "ati.h"
  23. #include "pci.h"
  24. #define ATI_VENDOR_ID 0x1002
  25. #define ATI_CRTC_OFF_PITCH_OFS 0x14
  26. #define ATI_CONFIG_CHIP_ID_OFS 0xE0
  27. static unsigned int ati_id;
  28. static unsigned int off_pitch_before;
  29. static unsigned int off_pitch_after;
  30. static unsigned int mmio_method; /* 0 = not found, 1..4 per header */
  31. static int try_mmio(volatile unsigned int *mmio, unsigned int device_id)
  32. {
  33. unsigned int chip_id = mmio[ATI_CONFIG_CHIP_ID_OFS / 4];
  34. if ((chip_id & 0xFFFF) != device_id)
  35. return 0;
  36. off_pitch_before = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  37. mmio[ATI_CRTC_OFF_PITCH_OFS / 4] = off_pitch_before & 0xFFF00000;
  38. off_pitch_after = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  39. return 1;
  40. }
  41. void ati_init(void)
  42. {
  43. unsigned int bus, dev, id, class_rev;
  44. unsigned int bar0, bar1, bar2;
  45. unsigned int device_id;
  46. for (bus = 0; bus < 4; bus++) {
  47. for (dev = 0; dev < 32; dev++) {
  48. id = pci_cfg_read32(bus, dev, 0, 0x00);
  49. if ((id & 0xFFFF) != ATI_VENDOR_ID)
  50. continue;
  51. class_rev = pci_cfg_read32(bus, dev, 0, 0x08);
  52. if ((class_rev >> 24) != 0x03)
  53. continue;
  54. ati_id = id;
  55. device_id = (id >> 16) & 0xFFFF;
  56. bar0 = pci_cfg_read32(bus, dev, 0, 0x10);
  57. bar2 = pci_cfg_read32(bus, dev, 0, 0x18);
  58. /* Method 1: BAR2 (separate MMIO aperture) */
  59. if (!(bar2 & 1) && (bar2 & 0xFFFFFFF0)) {
  60. if (try_mmio((volatile unsigned int *)(bar2 & 0xFFFFFFF0),
  61. device_id)) {
  62. mmio_method = 1;
  63. return;
  64. }
  65. }
  66. /* Method 2-3: MMIO at end of LFB aperture (264VT/GT) */
  67. if (!(bar0 & 1) && (bar0 & 0xFFFFFFF0)) {
  68. unsigned int lfb = bar0 & 0xFFFFFFF0;
  69. if (try_mmio((volatile unsigned int *)(lfb + 0x7FFC00),
  70. device_id)) {
  71. mmio_method = 2;
  72. return;
  73. }
  74. if (try_mmio((volatile unsigned int *)(lfb + 0x3FFC00),
  75. device_id)) {
  76. mmio_method = 3;
  77. return;
  78. }
  79. }
  80. /* Method 4: BAR1 block I/O */
  81. bar1 = pci_cfg_read32(bus, dev, 0, 0x14);
  82. if ((bar1 & 1) && (bar1 & 0xFFFC)) {
  83. unsigned short io = (unsigned short)(bar1 & 0xFFFC);
  84. unsigned int chip_id = port_inl(io + ATI_CONFIG_CHIP_ID_OFS);
  85. if ((chip_id & 0xFFFF) == device_id) {
  86. off_pitch_before = port_inl(io + ATI_CRTC_OFF_PITCH_OFS);
  87. port_outl(io + ATI_CRTC_OFF_PITCH_OFS,
  88. off_pitch_before & 0xFFF00000);
  89. off_pitch_after = port_inl(io + ATI_CRTC_OFF_PITCH_OFS);
  90. mmio_method = 4;
  91. return;
  92. }
  93. }
  94. return;
  95. }
  96. }
  97. }
  98. unsigned int ati_pci_id(void) { return ati_id; }
  99. unsigned int ati_off_pitch_before(void){ return off_pitch_before; }
  100. unsigned int ati_off_pitch_after(void) { return off_pitch_after; }
  101. unsigned int ati_mmio_method(void) { return mmio_method; }