gart.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_GART_H
  3. #define _ASM_X86_GART_H
  4. #include <asm/e820/api.h>
  5. extern void set_up_gart_resume(u32, u32);
  6. extern int fallback_aper_order;
  7. extern int fallback_aper_force;
  8. extern int fix_aperture;
  9. /* PTE bits. */
  10. #define GPTE_VALID 1
  11. #define GPTE_COHERENT 2
  12. /* Aperture control register bits. */
  13. #define GARTEN (1<<0)
  14. #define DISGARTCPU (1<<4)
  15. #define DISGARTIO (1<<5)
  16. #define DISTLBWALKPRB (1<<6)
  17. /* GART cache control register bits. */
  18. #define INVGART (1<<0)
  19. #define GARTPTEERR (1<<1)
  20. /* K8 On-cpu GART registers */
  21. #define AMD64_GARTAPERTURECTL 0x90
  22. #define AMD64_GARTAPERTUREBASE 0x94
  23. #define AMD64_GARTTABLEBASE 0x98
  24. #define AMD64_GARTCACHECTL 0x9c
  25. #ifdef CONFIG_GART_IOMMU
  26. extern int gart_iommu_aperture;
  27. extern int gart_iommu_aperture_allowed;
  28. extern int gart_iommu_aperture_disabled;
  29. extern void early_gart_iommu_check(void);
  30. extern int gart_iommu_init(void);
  31. extern void __init gart_parse_options(char *);
  32. extern int gart_iommu_hole_init(void);
  33. #else
  34. #define gart_iommu_aperture 0
  35. #define gart_iommu_aperture_allowed 0
  36. #define gart_iommu_aperture_disabled 1
  37. static inline void early_gart_iommu_check(void)
  38. {
  39. }
  40. static inline void gart_parse_options(char *options)
  41. {
  42. }
  43. static inline int gart_iommu_hole_init(void)
  44. {
  45. return -ENODEV;
  46. }
  47. #endif
  48. extern int agp_amd64_init(void);
  49. static inline void gart_set_size_and_enable(struct pci_dev *dev, u32 order)
  50. {
  51. u32 ctl;
  52. /*
  53. * Don't enable translation but enable GART IO and CPU accesses.
  54. * Also, set DISTLBWALKPRB since GART tables memory is UC.
  55. */
  56. ctl = order << 1;
  57. pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
  58. }
  59. static inline void enable_gart_translation(struct pci_dev *dev, u64 addr)
  60. {
  61. u32 tmp, ctl;
  62. /* address of the mappings table */
  63. addr >>= 12;
  64. tmp = (u32) addr<<4;
  65. tmp &= ~0xf;
  66. pci_write_config_dword(dev, AMD64_GARTTABLEBASE, tmp);
  67. /* Enable GART translation for this hammer. */
  68. pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl);
  69. ctl |= GARTEN | DISTLBWALKPRB;
  70. ctl &= ~(DISGARTCPU | DISGARTIO);
  71. pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
  72. }
  73. static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
  74. {
  75. if (!aper_base)
  76. return 0;
  77. if (aper_base + aper_size > 0x100000000ULL) {
  78. printk(KERN_INFO "Aperture beyond 4GB. Ignoring.\n");
  79. return 0;
  80. }
  81. if (e820__mapped_any(aper_base, aper_base + aper_size, E820_TYPE_RAM)) {
  82. printk(KERN_INFO "Aperture pointing to e820 RAM. Ignoring.\n");
  83. return 0;
  84. }
  85. if (aper_size < min_size) {
  86. printk(KERN_INFO "Aperture too small (%d MB) than (%d MB)\n",
  87. aper_size>>20, min_size>>20);
  88. return 0;
  89. }
  90. return 1;
  91. }
  92. #endif /* _ASM_X86_GART_H */