ati.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "paging.h"
  19. #include "ati.h"
  20. #include "pci.h"
  21. #include "radeon.h"
  22. #define ATI_VENDOR_ID 0x1002
  23. #define ATI_CRTC_OFF_PITCH_OFS 0x14
  24. #define ATI_CONFIG_CHIP_ID_OFS 0xE0
  25. static unsigned int ati_id;
  26. static unsigned int ati_is_radeon_flag;
  27. static unsigned int off_pitch_before;
  28. static unsigned int off_pitch_after;
  29. static unsigned int mmio_method; /* 0 = not found, 1..4 per header */
  30. static int ati_device_is_radeon(unsigned int device_id)
  31. {
  32. switch (device_id) {
  33. case 0x5960: /* Radeon 9200 PRO */
  34. case 0x5961: /* Radeon 9200 */
  35. case 0x5962: /* Radeon 9200 SE */
  36. case 0x5964: /* Radeon 9200 / 9250 (RV280) */
  37. case 0x5965: /* FireMV 2200 (RV280) */
  38. return 1;
  39. default:
  40. return 0;
  41. }
  42. }
  43. /* Map the 1 KB register block at physical `pa` and probe it. */
  44. static int try_mmio_at(unsigned int pa, unsigned int device_id);
  45. static int try_mmio(volatile unsigned int *mmio, unsigned int device_id)
  46. {
  47. unsigned int chip_id = mmio[ATI_CONFIG_CHIP_ID_OFS / 4];
  48. if ((chip_id & 0xFFFF) != device_id)
  49. return 0;
  50. off_pitch_before = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  51. mmio[ATI_CRTC_OFF_PITCH_OFS / 4] = off_pitch_before & 0xFFF00000;
  52. off_pitch_after = mmio[ATI_CRTC_OFF_PITCH_OFS / 4];
  53. return 1;
  54. }
  55. static void ati_mach64_fixup(unsigned int bus, unsigned int dev,
  56. unsigned int device_id)
  57. {
  58. unsigned int bar0, bar1, bar2;
  59. bar0 = pci_cfg_read32(bus, dev, 0, 0x10);
  60. bar2 = pci_cfg_read32(bus, dev, 0, 0x18);
  61. /* Method 1: BAR2 (separate MMIO aperture) */
  62. if (!(bar2 & 1) && (bar2 & 0xFFFFFFF0)) {
  63. if (try_mmio_at(bar2 & 0xFFFFFFF0, device_id)) {
  64. mmio_method = 1;
  65. return;
  66. }
  67. }
  68. /* Method 2-3: MMIO at end of LFB aperture (264VT/GT) */
  69. if (!(bar0 & 1) && (bar0 & 0xFFFFFFF0)) {
  70. unsigned int lfb = bar0 & 0xFFFFFFF0;
  71. if (try_mmio_at(lfb + 0x7FFC00, device_id)) {
  72. mmio_method = 2;
  73. return;
  74. }
  75. if (try_mmio_at(lfb + 0x3FFC00, 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. static int try_mmio_at(unsigned int pa, unsigned int device_id)
  96. {
  97. volatile unsigned int *mmio = ioremap(pa, 0x400, IOREMAP_MMIO);
  98. return mmio ? try_mmio(mmio, device_id) : 0;
  99. }
  100. void ati_init(unsigned int bus, unsigned int dev)
  101. {
  102. unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
  103. unsigned int device_id = (id >> 16) & 0xFFFF;
  104. ati_id = id;
  105. off_pitch_before = 0;
  106. off_pitch_after = 0;
  107. mmio_method = 0;
  108. ati_is_radeon_flag = ati_device_is_radeon(device_id);
  109. if (ati_is_radeon_flag) {
  110. radeon_init(bus, dev, device_id);
  111. return;
  112. }
  113. ati_mach64_fixup(bus, dev, device_id);
  114. }
  115. int ati_is_radeon(void) { return ati_is_radeon_flag; }
  116. unsigned int ati_pci_id(void) { return ati_id; }
  117. unsigned int ati_off_pitch_before(void){ return off_pitch_before; }
  118. unsigned int ati_off_pitch_after(void) { return off_pitch_after; }
  119. unsigned int ati_mmio_method(void) { return mmio_method; }