Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_GART_H |
| 3 | #define _ASM_X86_GART_H |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 4 | |
Ingo Molnar | 66441bd | 2017-01-27 10:27:10 +0100 | [diff] [blame] | 5 | #include <asm/e820/api.h> |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 6 | |
Rafael J. Wysocki | 6703f6d | 2008-06-10 00:10:48 +0200 | [diff] [blame] | 7 | extern void set_up_gart_resume(u32, u32); |
FUJITA Tomonori | e93be88 | 2008-07-10 08:27:49 +0900 | [diff] [blame] | 8 | |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 9 | extern int fallback_aper_order; |
| 10 | extern int fallback_aper_force; |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 11 | extern int fix_aperture; |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 12 | |
Pavel Machek | aa134f1 | 2008-04-08 10:49:03 +0200 | [diff] [blame] | 13 | /* PTE bits. */ |
| 14 | #define GPTE_VALID 1 |
| 15 | #define GPTE_COHERENT 2 |
| 16 | |
| 17 | /* Aperture control register bits. */ |
| 18 | #define GARTEN (1<<0) |
| 19 | #define DISGARTCPU (1<<4) |
| 20 | #define DISGARTIO (1<<5) |
Borislav Petkov | 260133a | 2010-09-03 18:39:40 +0200 | [diff] [blame] | 21 | #define DISTLBWALKPRB (1<<6) |
Pavel Machek | aa134f1 | 2008-04-08 10:49:03 +0200 | [diff] [blame] | 22 | |
| 23 | /* GART cache control register bits. */ |
| 24 | #define INVGART (1<<0) |
| 25 | #define GARTPTEERR (1<<1) |
| 26 | |
| 27 | /* K8 On-cpu GART registers */ |
| 28 | #define AMD64_GARTAPERTURECTL 0x90 |
| 29 | #define AMD64_GARTAPERTUREBASE 0x94 |
| 30 | #define AMD64_GARTTABLEBASE 0x98 |
| 31 | #define AMD64_GARTCACHECTL 0x9c |
Pavel Machek | aa134f1 | 2008-04-08 10:49:03 +0200 | [diff] [blame] | 32 | |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_GART_IOMMU |
| 34 | extern int gart_iommu_aperture; |
| 35 | extern int gart_iommu_aperture_allowed; |
| 36 | extern int gart_iommu_aperture_disabled; |
| 37 | |
| 38 | extern void early_gart_iommu_check(void); |
FUJITA Tomonori | de95762 | 2009-11-10 19:46:14 +0900 | [diff] [blame] | 39 | extern int gart_iommu_init(void); |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 40 | extern void __init gart_parse_options(char *); |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 41 | extern int gart_iommu_hole_init(void); |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 42 | |
| 43 | #else |
| 44 | #define gart_iommu_aperture 0 |
| 45 | #define gart_iommu_aperture_allowed 0 |
| 46 | #define gart_iommu_aperture_disabled 1 |
| 47 | |
| 48 | static inline void early_gart_iommu_check(void) |
| 49 | { |
| 50 | } |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 51 | static inline void gart_parse_options(char *options) |
| 52 | { |
| 53 | } |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 54 | static inline int gart_iommu_hole_init(void) |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 55 | { |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 56 | return -ENODEV; |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 57 | } |
| 58 | #endif |
| 59 | |
Joerg Roedel | 237a622 | 2008-09-25 12:13:53 +0200 | [diff] [blame] | 60 | extern int agp_amd64_init(void); |
| 61 | |
Borislav Petkov | 260133a | 2010-09-03 18:39:40 +0200 | [diff] [blame] | 62 | static inline void gart_set_size_and_enable(struct pci_dev *dev, u32 order) |
| 63 | { |
| 64 | u32 ctl; |
| 65 | |
| 66 | /* |
| 67 | * Don't enable translation but enable GART IO and CPU accesses. |
| 68 | * Also, set DISTLBWALKPRB since GART tables memory is UC. |
| 69 | */ |
Joerg Roedel | c34151a | 2011-04-18 15:45:45 +0200 | [diff] [blame] | 70 | ctl = order << 1; |
Borislav Petkov | 260133a | 2010-09-03 18:39:40 +0200 | [diff] [blame] | 71 | |
| 72 | pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl); |
| 73 | } |
| 74 | |
Pavel Machek | 3bb6fbf | 2008-04-15 12:43:57 +0200 | [diff] [blame] | 75 | static inline void enable_gart_translation(struct pci_dev *dev, u64 addr) |
| 76 | { |
| 77 | u32 tmp, ctl; |
| 78 | |
Joerg Roedel | af289bf | 2011-04-18 15:45:44 +0200 | [diff] [blame] | 79 | /* address of the mappings table */ |
| 80 | addr >>= 12; |
| 81 | tmp = (u32) addr<<4; |
| 82 | tmp &= ~0xf; |
| 83 | pci_write_config_dword(dev, AMD64_GARTTABLEBASE, tmp); |
Pavel Machek | 3bb6fbf | 2008-04-15 12:43:57 +0200 | [diff] [blame] | 84 | |
Joerg Roedel | af289bf | 2011-04-18 15:45:44 +0200 | [diff] [blame] | 85 | /* Enable GART translation for this hammer. */ |
| 86 | pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl); |
Joerg Roedel | c34151a | 2011-04-18 15:45:45 +0200 | [diff] [blame] | 87 | ctl |= GARTEN | DISTLBWALKPRB; |
Joerg Roedel | af289bf | 2011-04-18 15:45:44 +0200 | [diff] [blame] | 88 | ctl &= ~(DISGARTCPU | DISGARTIO); |
| 89 | pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl); |
Pavel Machek | 3bb6fbf | 2008-04-15 12:43:57 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 92 | static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size) |
| 93 | { |
| 94 | if (!aper_base) |
| 95 | return 0; |
| 96 | |
| 97 | if (aper_base + aper_size > 0x100000000ULL) { |
Adam Jackson | 9b15684 | 2008-09-29 14:52:03 -0400 | [diff] [blame] | 98 | printk(KERN_INFO "Aperture beyond 4GB. Ignoring.\n"); |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | } |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 101 | if (e820__mapped_any(aper_base, aper_base + aper_size, E820_TYPE_RAM)) { |
Adam Jackson | 9b15684 | 2008-09-29 14:52:03 -0400 | [diff] [blame] | 102 | printk(KERN_INFO "Aperture pointing to e820 RAM. Ignoring.\n"); |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | if (aper_size < min_size) { |
Adam Jackson | 9b15684 | 2008-09-29 14:52:03 -0400 | [diff] [blame] | 106 | printk(KERN_INFO "Aperture too small (%d MB) than (%d MB)\n", |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 107 | aper_size>>20, min_size>>20); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | return 1; |
| 112 | } |
| 113 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 114 | #endif /* _ASM_X86_GART_H */ |