ati.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * ATI GPU init.
  3. *
  4. * Two distinct ATI families need different handling:
  5. *
  6. * - Mach64 / 3D Rage: the CRTC_OFF_PITCH register (MMIO offset 0x14) drives
  7. * display start + scanline pitch, and ignores standard VGA CRTC writes and
  8. * VBE 4F07h. We zero the offset field directly through PCI MMIO or block
  9. * I/O (see the header comment in the old ati.c for the method ladder).
  10. *
  11. * - Radeon (R200 family, incl. the RV280 / Radeon 9200/9250): the VBIOS sets
  12. * a clean mode and needs no CRTC fixup. We instead set up the hardware
  13. * cursor (radeon.c).
  14. *
  15. * Access is verified by reading CONFIG_CHIP_ID (byte offset 0xE0) and checking
  16. * the lower 16 bits match the PCI device ID.
  17. */
  18. #include "ati.h"
  19. #include "pci.h"
  20. #include "radeon.h"
  21. #define ATI_VENDOR_ID 0x1002
  22. #define ATI_CRTC_OFF_PITCH_OFS 0x14
  23. #define ATI_CONFIG_CHIP_ID_OFS 0xE0
  24. static unsigned int ati_id;
  25. static unsigned int ati_is_radeon_flag;
  26. static unsigned int off_pitch_before;
  27. static unsigned int off_pitch_after;
  28. static unsigned int mmio_method; /* 0 = not found, 1..4 per header */
  29. static int ati_device_is_radeon(unsigned int device_id)
  30. {
  31. switch (device_id) {
  32. case 0x5960: /* Radeon 9200 PRO */
  33. case 0x5961: /* Radeon 9200 */
  34. case 0x5962: /* Radeon 9200 SE */
  35. case 0x5964: /* Radeon 9200 / 9250 (RV280) */
  36. case 0x5965: /* FireMV 2200 (RV280) */
  37. return 1;
  38. default:
  39. return 0;
  40. }
  41. }
  42. static int try_mmio(volatile unsigned int *mmio, unsigned int device_id)
  43. {
  44. unsigned int chip_id = mmio[ATI_CONFIG_CHIP_ID_OFS / 4];
  45. if ((chip_id & 0xFFFF) != device_id)
  46. return 0;
  47. off_pitch_before = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  48. mmio[ATI_CRTC_OFF_PITCH_OFS / 4] = off_pitch_before & 0xFFF00000;
  49. off_pitch_after = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  50. return 1;
  51. }
  52. static void ati_mach64_fixup(unsigned int bus, unsigned int dev,
  53. unsigned int device_id)
  54. {
  55. unsigned int bar0, bar1, bar2;
  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. }
  95. void ati_init(unsigned int bus, unsigned int dev)
  96. {
  97. unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
  98. unsigned int device_id = (id >> 16) & 0xFFFF;
  99. ati_id = id;
  100. off_pitch_before = 0;
  101. off_pitch_after = 0;
  102. mmio_method = 0;
  103. ati_is_radeon_flag = ati_device_is_radeon(device_id);
  104. if (ati_is_radeon_flag) {
  105. radeon_init(bus, dev, device_id);
  106. return;
  107. }
  108. ati_mach64_fixup(bus, dev, device_id);
  109. }
  110. int ati_is_radeon(void) { return ati_is_radeon_flag; }
  111. unsigned int ati_pci_id(void) { return ati_id; }
  112. unsigned int ati_off_pitch_before(void){ return off_pitch_before; }
  113. unsigned int ati_off_pitch_after(void) { return off_pitch_after; }
  114. unsigned int ati_mmio_method(void) { return mmio_method; }