blob: d7d1d4c438a422785b3001f0ea99d7d0a15cac9a [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_GART_H
2#define _ASM_X86_GART_H
Joerg Roedel395624f2007-10-24 12:49:47 +02003
Pavel Machek0abbc782008-05-20 16:27:17 +02004#include <asm/e820.h>
5
Rafael J. Wysocki6703f6d2008-06-10 00:10:48 +02006extern void set_up_gart_resume(u32, u32);
FUJITA Tomonorie93be882008-07-10 08:27:49 +09007
Joerg Roedel395624f2007-10-24 12:49:47 +02008extern int fallback_aper_order;
9extern int fallback_aper_force;
Joerg Roedel395624f2007-10-24 12:49:47 +020010extern int fix_aperture;
Joerg Roedel395624f2007-10-24 12:49:47 +020011
Pavel Machekaa134f12008-04-08 10:49:03 +020012/* PTE bits. */
13#define GPTE_VALID 1
14#define GPTE_COHERENT 2
15
16/* Aperture control register bits. */
17#define GARTEN (1<<0)
18#define DISGARTCPU (1<<4)
19#define DISGARTIO (1<<5)
20
21/* GART cache control register bits. */
22#define INVGART (1<<0)
23#define GARTPTEERR (1<<1)
24
25/* K8 On-cpu GART registers */
26#define AMD64_GARTAPERTURECTL 0x90
27#define AMD64_GARTAPERTUREBASE 0x94
28#define AMD64_GARTTABLEBASE 0x98
29#define AMD64_GARTCACHECTL 0x9c
30#define AMD64_GARTEN (1<<0)
31
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010032#ifdef CONFIG_GART_IOMMU
33extern int gart_iommu_aperture;
34extern int gart_iommu_aperture_allowed;
35extern int gart_iommu_aperture_disabled;
36
37extern void early_gart_iommu_check(void);
FUJITA Tomonoride957622009-11-10 19:46:14 +090038extern int gart_iommu_init(void);
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010039extern void __init gart_parse_options(char *);
Konrad Rzeszutek Wilk480125b2010-08-26 13:57:57 -040040extern int gart_iommu_hole_init(void);
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010041
42#else
43#define gart_iommu_aperture 0
44#define gart_iommu_aperture_allowed 0
45#define gart_iommu_aperture_disabled 1
46
47static inline void early_gart_iommu_check(void)
48{
49}
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010050static inline void gart_parse_options(char *options)
51{
52}
Konrad Rzeszutek Wilk480125b2010-08-26 13:57:57 -040053static inline int gart_iommu_hole_init(void)
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010054{
Konrad Rzeszutek Wilk480125b2010-08-26 13:57:57 -040055 return -ENODEV;
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010056}
57#endif
58
Joerg Roedel237a6222008-09-25 12:13:53 +020059extern int agp_amd64_init(void);
60
Pavel Machek3bb6fbf2008-04-15 12:43:57 +020061static inline void enable_gart_translation(struct pci_dev *dev, u64 addr)
62{
63 u32 tmp, ctl;
64
65 /* address of the mappings table */
66 addr >>= 12;
67 tmp = (u32) addr<<4;
68 tmp &= ~0xf;
69 pci_write_config_dword(dev, AMD64_GARTTABLEBASE, tmp);
70
71 /* Enable GART translation for this hammer. */
72 pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl);
73 ctl |= GARTEN;
74 ctl &= ~(DISGARTCPU | DISGARTIO);
75 pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
76}
77
Pavel Machek0abbc782008-05-20 16:27:17 +020078static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
79{
80 if (!aper_base)
81 return 0;
82
83 if (aper_base + aper_size > 0x100000000ULL) {
Adam Jackson9b156842008-09-29 14:52:03 -040084 printk(KERN_INFO "Aperture beyond 4GB. Ignoring.\n");
Pavel Machek0abbc782008-05-20 16:27:17 +020085 return 0;
86 }
87 if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
Adam Jackson9b156842008-09-29 14:52:03 -040088 printk(KERN_INFO "Aperture pointing to e820 RAM. Ignoring.\n");
Pavel Machek0abbc782008-05-20 16:27:17 +020089 return 0;
90 }
91 if (aper_size < min_size) {
Adam Jackson9b156842008-09-29 14:52:03 -040092 printk(KERN_INFO "Aperture too small (%d MB) than (%d MB)\n",
Pavel Machek0abbc782008-05-20 16:27:17 +020093 aper_size>>20, min_size>>20);
94 return 0;
95 }
96
97 return 1;
98}
99
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700100#endif /* _ASM_X86_GART_H */