Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 1 | #ifndef _ASM_X8664_IOMMU_H |
| 2 | #define _ASM_X8664_IOMMU_H 1 |
| 3 | |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame^] | 4 | #include <asm/e820.h> |
| 5 | |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 6 | extern void pci_iommu_shutdown(void); |
| 7 | extern void no_iommu_init(void); |
| 8 | extern int force_iommu, no_iommu; |
| 9 | extern int iommu_detected; |
Pavel Machek | aa134f1 | 2008-04-08 10:49:03 +0200 | [diff] [blame] | 10 | extern int agp_amd64_init(void); |
Joerg Roedel | 966396d | 2007-10-24 12:49:48 +0200 | [diff] [blame] | 11 | #ifdef CONFIG_GART_IOMMU |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 12 | extern void gart_iommu_init(void); |
| 13 | extern void gart_iommu_shutdown(void); |
| 14 | extern void __init gart_parse_options(char *); |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 15 | extern void early_gart_iommu_check(void); |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 16 | extern void gart_iommu_hole_init(void); |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 17 | extern int fallback_aper_order; |
| 18 | extern int fallback_aper_force; |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 19 | extern int gart_iommu_aperture; |
| 20 | extern int gart_iommu_aperture_allowed; |
| 21 | extern int gart_iommu_aperture_disabled; |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 22 | extern int fix_aperture; |
| 23 | #else |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 24 | #define gart_iommu_aperture 0 |
| 25 | #define gart_iommu_aperture_allowed 0 |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 26 | |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 27 | static inline void early_gart_iommu_check(void) |
| 28 | { |
| 29 | } |
| 30 | |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 31 | static inline void gart_iommu_shutdown(void) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | #endif |
| 36 | |
Pavel Machek | aa134f1 | 2008-04-08 10:49:03 +0200 | [diff] [blame] | 37 | /* PTE bits. */ |
| 38 | #define GPTE_VALID 1 |
| 39 | #define GPTE_COHERENT 2 |
| 40 | |
| 41 | /* Aperture control register bits. */ |
| 42 | #define GARTEN (1<<0) |
| 43 | #define DISGARTCPU (1<<4) |
| 44 | #define DISGARTIO (1<<5) |
| 45 | |
| 46 | /* GART cache control register bits. */ |
| 47 | #define INVGART (1<<0) |
| 48 | #define GARTPTEERR (1<<1) |
| 49 | |
| 50 | /* K8 On-cpu GART registers */ |
| 51 | #define AMD64_GARTAPERTURECTL 0x90 |
| 52 | #define AMD64_GARTAPERTUREBASE 0x94 |
| 53 | #define AMD64_GARTTABLEBASE 0x98 |
| 54 | #define AMD64_GARTCACHECTL 0x9c |
| 55 | #define AMD64_GARTEN (1<<0) |
| 56 | |
Pavel Machek | 3bb6fbf | 2008-04-15 12:43:57 +0200 | [diff] [blame] | 57 | static inline void enable_gart_translation(struct pci_dev *dev, u64 addr) |
| 58 | { |
| 59 | u32 tmp, ctl; |
| 60 | |
| 61 | /* address of the mappings table */ |
| 62 | addr >>= 12; |
| 63 | tmp = (u32) addr<<4; |
| 64 | tmp &= ~0xf; |
| 65 | pci_write_config_dword(dev, AMD64_GARTTABLEBASE, tmp); |
| 66 | |
| 67 | /* Enable GART translation for this hammer. */ |
| 68 | pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl); |
| 69 | ctl |= GARTEN; |
| 70 | ctl &= ~(DISGARTCPU | DISGARTIO); |
| 71 | pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl); |
| 72 | } |
| 73 | |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame^] | 74 | static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size) |
| 75 | { |
| 76 | if (!aper_base) |
| 77 | return 0; |
| 78 | |
| 79 | if (aper_base + aper_size > 0x100000000ULL) { |
| 80 | printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n"); |
| 81 | return 0; |
| 82 | } |
| 83 | if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) { |
| 84 | printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n"); |
| 85 | return 0; |
| 86 | } |
| 87 | if (aper_size < min_size) { |
| 88 | printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n", |
| 89 | aper_size>>20, min_size>>20); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | return 1; |
| 94 | } |
| 95 | |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 96 | #endif |