agp.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * AGPGART
  3. * Copyright (C) 2004 Silicon Graphics, Inc.
  4. * Copyright (C) 2002-2004 Dave Jones
  5. * Copyright (C) 1999 Jeff Hartmann
  6. * Copyright (C) 1999 Precision Insight, Inc.
  7. * Copyright (C) 1999 Xi Graphics, Inc.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included
  17. * in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
  23. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  25. * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. #ifndef _AGP_BACKEND_PRIV_H
  29. #define _AGP_BACKEND_PRIV_H 1
  30. #include <asm/agp.h> /* for flush_agp_cache() */
  31. #define PFX "agpgart: "
  32. //#define AGP_DEBUG 1
  33. #ifdef AGP_DEBUG
  34. #define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __FUNCTION__ , ## y)
  35. #else
  36. #define DBG(x,y...) do { } while (0)
  37. #endif
  38. extern struct agp_bridge_data *agp_bridge;
  39. enum aper_size_type {
  40. U8_APER_SIZE,
  41. U16_APER_SIZE,
  42. U32_APER_SIZE,
  43. LVL2_APER_SIZE,
  44. FIXED_APER_SIZE
  45. };
  46. struct gatt_mask {
  47. unsigned long mask;
  48. u32 type;
  49. /* totally device specific, for integrated chipsets that
  50. * might have different types of memory masks. For other
  51. * devices this will probably be ignored */
  52. };
  53. struct aper_size_info_8 {
  54. int size;
  55. int num_entries;
  56. int page_order;
  57. u8 size_value;
  58. };
  59. struct aper_size_info_16 {
  60. int size;
  61. int num_entries;
  62. int page_order;
  63. u16 size_value;
  64. };
  65. struct aper_size_info_32 {
  66. int size;
  67. int num_entries;
  68. int page_order;
  69. u32 size_value;
  70. };
  71. struct aper_size_info_lvl2 {
  72. int size;
  73. int num_entries;
  74. u32 size_value;
  75. };
  76. struct aper_size_info_fixed {
  77. int size;
  78. int num_entries;
  79. int page_order;
  80. };
  81. struct agp_bridge_driver {
  82. struct module *owner;
  83. void *aperture_sizes;
  84. int num_aperture_sizes;
  85. enum aper_size_type size_type;
  86. int cant_use_aperture;
  87. int needs_scratch_page;
  88. struct gatt_mask *masks;
  89. int (*fetch_size)(void);
  90. int (*configure)(void);
  91. void (*agp_enable)(struct agp_bridge_data *, u32);
  92. void (*cleanup)(void);
  93. void (*tlb_flush)(struct agp_memory *);
  94. unsigned long (*mask_memory)(struct agp_bridge_data *, unsigned long, int);
  95. void (*cache_flush)(void);
  96. int (*create_gatt_table)(struct agp_bridge_data *);
  97. int (*free_gatt_table)(struct agp_bridge_data *);
  98. int (*insert_memory)(struct agp_memory *, off_t, int);
  99. int (*remove_memory)(struct agp_memory *, off_t, int);
  100. struct agp_memory *(*alloc_by_type) (size_t, int);
  101. void (*free_by_type)(struct agp_memory *);
  102. void *(*agp_alloc_page)(struct agp_bridge_data *);
  103. void (*agp_destroy_page)(void *);
  104. };
  105. struct agp_bridge_data {
  106. const struct agp_version *version;
  107. struct agp_bridge_driver *driver;
  108. struct vm_operations_struct *vm_ops;
  109. void *previous_size;
  110. void *current_size;
  111. void *dev_private_data;
  112. struct pci_dev *dev;
  113. u32 __iomem *gatt_table;
  114. u32 *gatt_table_real;
  115. unsigned long scratch_page;
  116. unsigned long scratch_page_real;
  117. unsigned long gart_bus_addr;
  118. unsigned long gatt_bus_addr;
  119. u32 mode;
  120. enum chipset_type type;
  121. unsigned long *key_list;
  122. atomic_t current_memory_agp;
  123. atomic_t agp_in_use;
  124. int max_memory_agp; /* in number of pages */
  125. int aperture_size_idx;
  126. int capndx;
  127. int flags;
  128. char major_version;
  129. char minor_version;
  130. struct list_head list;
  131. u32 apbase_config;
  132. };
  133. #define KB(x) ((x) * 1024)
  134. #define MB(x) (KB (KB (x)))
  135. #define GB(x) (MB (KB (x)))
  136. #define A_SIZE_8(x) ((struct aper_size_info_8 *) x)
  137. #define A_SIZE_16(x) ((struct aper_size_info_16 *) x)
  138. #define A_SIZE_32(x) ((struct aper_size_info_32 *) x)
  139. #define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x)
  140. #define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x)
  141. #define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i)
  142. #define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i)
  143. #define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i)
  144. #define MAXKEY (4096 * 32)
  145. #define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page)
  146. /* Intel registers */
  147. #define INTEL_APSIZE 0xb4
  148. #define INTEL_ATTBASE 0xb8
  149. #define INTEL_AGPCTRL 0xb0
  150. #define INTEL_NBXCFG 0x50
  151. #define INTEL_ERRSTS 0x91
  152. /* Intel i830 registers */
  153. #define I830_GMCH_CTRL 0x52
  154. #define I830_GMCH_ENABLED 0x4
  155. #define I830_GMCH_MEM_MASK 0x1
  156. #define I830_GMCH_MEM_64M 0x1
  157. #define I830_GMCH_MEM_128M 0
  158. #define I830_GMCH_GMS_MASK 0x70
  159. #define I830_GMCH_GMS_DISABLED 0x00
  160. #define I830_GMCH_GMS_LOCAL 0x10
  161. #define I830_GMCH_GMS_STOLEN_512 0x20
  162. #define I830_GMCH_GMS_STOLEN_1024 0x30
  163. #define I830_GMCH_GMS_STOLEN_8192 0x40
  164. #define I830_RDRAM_CHANNEL_TYPE 0x03010
  165. #define I830_RDRAM_ND(x) (((x) & 0x20) >> 5)
  166. #define I830_RDRAM_DDT(x) (((x) & 0x18) >> 3)
  167. /* This one is for I830MP w. an external graphic card */
  168. #define INTEL_I830_ERRSTS 0x92
  169. /* Intel 855GM/852GM registers */
  170. #define I855_GMCH_GMS_STOLEN_0M 0x0
  171. #define I855_GMCH_GMS_STOLEN_1M (0x1 << 4)
  172. #define I855_GMCH_GMS_STOLEN_4M (0x2 << 4)
  173. #define I855_GMCH_GMS_STOLEN_8M (0x3 << 4)
  174. #define I855_GMCH_GMS_STOLEN_16M (0x4 << 4)
  175. #define I855_GMCH_GMS_STOLEN_32M (0x5 << 4)
  176. #define I85X_CAPID 0x44
  177. #define I85X_VARIANT_MASK 0x7
  178. #define I85X_VARIANT_SHIFT 5
  179. #define I855_GME 0x0
  180. #define I855_GM 0x4
  181. #define I852_GME 0x2
  182. #define I852_GM 0x5
  183. /* Intel i845 registers */
  184. #define INTEL_I845_AGPM 0x51
  185. #define INTEL_I845_ERRSTS 0xc8
  186. /* Intel i860 registers */
  187. #define INTEL_I860_MCHCFG 0x50
  188. #define INTEL_I860_ERRSTS 0xc8
  189. /* Intel i810 registers */
  190. #define I810_GMADDR 0x10
  191. #define I810_MMADDR 0x14
  192. #define I810_PTE_BASE 0x10000
  193. #define I810_PTE_MAIN_UNCACHED 0x00000000
  194. #define I810_PTE_LOCAL 0x00000002
  195. #define I810_PTE_VALID 0x00000001
  196. #define I810_SMRAM_MISCC 0x70
  197. #define I810_GFX_MEM_WIN_SIZE 0x00010000
  198. #define I810_GFX_MEM_WIN_32M 0x00010000
  199. #define I810_GMS 0x000000c0
  200. #define I810_GMS_DISABLE 0x00000000
  201. #define I810_PGETBL_CTL 0x2020
  202. #define I810_PGETBL_ENABLED 0x00000001
  203. #define I810_DRAM_CTL 0x3000
  204. #define I810_DRAM_ROW_0 0x00000001
  205. #define I810_DRAM_ROW_0_SDRAM 0x00000001
  206. struct agp_device_ids {
  207. unsigned short device_id; /* first, to make table easier to read */
  208. enum chipset_type chipset;
  209. const char *chipset_name;
  210. int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */
  211. };
  212. /* Driver registration */
  213. struct agp_bridge_data *agp_alloc_bridge(void);
  214. void agp_put_bridge(struct agp_bridge_data *bridge);
  215. int agp_add_bridge(struct agp_bridge_data *bridge);
  216. void agp_remove_bridge(struct agp_bridge_data *bridge);
  217. /* Frontend routines. */
  218. int agp_frontend_initialize(void);
  219. void agp_frontend_cleanup(void);
  220. /* Generic routines. */
  221. void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
  222. int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
  223. int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
  224. struct agp_memory *agp_create_memory(int scratch_pages);
  225. int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
  226. int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
  227. struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
  228. void agp_generic_free_by_type(struct agp_memory *curr);
  229. void *agp_generic_alloc_page(struct agp_bridge_data *bridge);
  230. void agp_generic_destroy_page(void *addr);
  231. void agp_free_key(int key);
  232. int agp_num_entries(void);
  233. u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
  234. void agp_device_command(u32 command, int agp_v3);
  235. int agp_3_5_enable(struct agp_bridge_data *bridge);
  236. void global_cache_flush(void);
  237. void get_agp_version(struct agp_bridge_data *bridge);
  238. unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
  239. unsigned long addr, int type);
  240. struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
  241. /* generic routines for agp>=3 */
  242. int agp3_generic_fetch_size(void);
  243. void agp3_generic_tlbflush(struct agp_memory *mem);
  244. int agp3_generic_configure(void);
  245. void agp3_generic_cleanup(void);
  246. /* aperture sizes have been standardised since v3 */
  247. #define AGP_GENERIC_SIZES_ENTRIES 11
  248. extern struct aper_size_info_16 agp3_generic_sizes[];
  249. #define virt_to_gart(x) (phys_to_gart(virt_to_phys(x)))
  250. #define gart_to_virt(x) (phys_to_virt(gart_to_phys(x)))
  251. extern int agp_off;
  252. extern int agp_try_unsupported_boot;
  253. /* Chipset independant registers (from AGP Spec) */
  254. #define AGP_APBASE 0x10
  255. #define AGPSTAT 0x4
  256. #define AGPCMD 0x8
  257. #define AGPNISTAT 0xc
  258. #define AGPCTRL 0x10
  259. #define AGPAPSIZE 0x14
  260. #define AGPNEPG 0x16
  261. #define AGPGARTLO 0x18
  262. #define AGPGARTHI 0x1c
  263. #define AGPNICMD 0x20
  264. #define AGP_MAJOR_VERSION_SHIFT (20)
  265. #define AGP_MINOR_VERSION_SHIFT (16)
  266. #define AGPSTAT_RQ_DEPTH (0xff000000)
  267. #define AGPSTAT_RQ_DEPTH_SHIFT 24
  268. #define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10)
  269. #define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13)
  270. #define AGPSTAT_ARQSZ_SHIFT 13
  271. #define AGPSTAT_SBA (1<<9)
  272. #define AGPSTAT_AGP_ENABLE (1<<8)
  273. #define AGPSTAT_FW (1<<4)
  274. #define AGPSTAT_MODE_3_0 (1<<3)
  275. #define AGPSTAT2_1X (1<<0)
  276. #define AGPSTAT2_2X (1<<1)
  277. #define AGPSTAT2_4X (1<<2)
  278. #define AGPSTAT3_RSVD (1<<2)
  279. #define AGPSTAT3_8X (1<<1)
  280. #define AGPSTAT3_4X (1)
  281. #define AGPCTRL_APERENB (1<<8)
  282. #define AGPCTRL_GTLBEN (1<<7)
  283. #define AGP2_RESERVED_MASK 0x00fffcc8
  284. #define AGP3_RESERVED_MASK 0x00ff00c4
  285. #define AGP_ERRATA_FASTWRITES 1<<0
  286. #define AGP_ERRATA_SBA 1<<1
  287. #define AGP_ERRATA_1X 1<<2
  288. #endif /* _AGP_BACKEND_PRIV_H */