agp.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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", __func__ , ## 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. #define AGP_PAGE_DESTROY_UNMAP 1
  54. #define AGP_PAGE_DESTROY_FREE 2
  55. struct aper_size_info_8 {
  56. int size;
  57. int num_entries;
  58. int page_order;
  59. u8 size_value;
  60. };
  61. struct aper_size_info_16 {
  62. int size;
  63. int num_entries;
  64. int page_order;
  65. u16 size_value;
  66. };
  67. struct aper_size_info_32 {
  68. int size;
  69. int num_entries;
  70. int page_order;
  71. u32 size_value;
  72. };
  73. struct aper_size_info_lvl2 {
  74. int size;
  75. int num_entries;
  76. u32 size_value;
  77. };
  78. struct aper_size_info_fixed {
  79. int size;
  80. int num_entries;
  81. int page_order;
  82. };
  83. struct agp_bridge_driver {
  84. struct module *owner;
  85. const void *aperture_sizes;
  86. int num_aperture_sizes;
  87. enum aper_size_type size_type;
  88. bool cant_use_aperture;
  89. bool needs_scratch_page;
  90. const struct gatt_mask *masks;
  91. int (*fetch_size)(void);
  92. int (*configure)(void);
  93. void (*agp_enable)(struct agp_bridge_data *, u32);
  94. void (*cleanup)(void);
  95. void (*tlb_flush)(struct agp_memory *);
  96. unsigned long (*mask_memory)(struct agp_bridge_data *, dma_addr_t, int);
  97. void (*cache_flush)(void);
  98. int (*create_gatt_table)(struct agp_bridge_data *);
  99. int (*free_gatt_table)(struct agp_bridge_data *);
  100. int (*insert_memory)(struct agp_memory *, off_t, int);
  101. int (*remove_memory)(struct agp_memory *, off_t, int);
  102. struct agp_memory *(*alloc_by_type) (size_t, int);
  103. void (*free_by_type)(struct agp_memory *);
  104. struct page *(*agp_alloc_page)(struct agp_bridge_data *);
  105. int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
  106. void (*agp_destroy_page)(struct page *, int flags);
  107. void (*agp_destroy_pages)(struct agp_memory *);
  108. int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
  109. };
  110. struct agp_bridge_data {
  111. const struct agp_version *version;
  112. const struct agp_bridge_driver *driver;
  113. const struct vm_operations_struct *vm_ops;
  114. void *previous_size;
  115. void *current_size;
  116. void *dev_private_data;
  117. struct pci_dev *dev;
  118. u32 __iomem *gatt_table;
  119. u32 *gatt_table_real;
  120. unsigned long scratch_page;
  121. struct page *scratch_page_page;
  122. dma_addr_t scratch_page_dma;
  123. unsigned long gart_bus_addr;
  124. unsigned long gatt_bus_addr;
  125. u32 mode;
  126. enum chipset_type type;
  127. unsigned long *key_list;
  128. atomic_t current_memory_agp;
  129. atomic_t agp_in_use;
  130. int max_memory_agp; /* in number of pages */
  131. int aperture_size_idx;
  132. int capndx;
  133. int flags;
  134. char major_version;
  135. char minor_version;
  136. struct list_head list;
  137. u32 apbase_config;
  138. /* list of agp_memory mapped to the aperture */
  139. struct list_head mapped_list;
  140. spinlock_t mapped_lock;
  141. };
  142. #define KB(x) ((x) * 1024)
  143. #define MB(x) (KB (KB (x)))
  144. #define GB(x) (MB (KB (x)))
  145. #define A_SIZE_8(x) ((struct aper_size_info_8 *) x)
  146. #define A_SIZE_16(x) ((struct aper_size_info_16 *) x)
  147. #define A_SIZE_32(x) ((struct aper_size_info_32 *) x)
  148. #define A_SIZE_LVL2(x) ((struct aper_size_info_lvl2 *) x)
  149. #define A_SIZE_FIX(x) ((struct aper_size_info_fixed *) x)
  150. #define A_IDX8(bridge) (A_SIZE_8((bridge)->driver->aperture_sizes) + i)
  151. #define A_IDX16(bridge) (A_SIZE_16((bridge)->driver->aperture_sizes) + i)
  152. #define A_IDX32(bridge) (A_SIZE_32((bridge)->driver->aperture_sizes) + i)
  153. #define MAXKEY (4096 * 32)
  154. #define PGE_EMPTY(b, p) (!(p) || (p) == (unsigned long) (b)->scratch_page)
  155. struct agp_device_ids {
  156. unsigned short device_id; /* first, to make table easier to read */
  157. enum chipset_type chipset;
  158. const char *chipset_name;
  159. int (*chipset_setup) (struct pci_dev *pdev); /* used to override generic */
  160. };
  161. /* Driver registration */
  162. struct agp_bridge_data *agp_alloc_bridge(void);
  163. void agp_put_bridge(struct agp_bridge_data *bridge);
  164. int agp_add_bridge(struct agp_bridge_data *bridge);
  165. void agp_remove_bridge(struct agp_bridge_data *bridge);
  166. /* Frontend routines. */
  167. int agp_frontend_initialize(void);
  168. void agp_frontend_cleanup(void);
  169. /* Generic routines. */
  170. void agp_generic_enable(struct agp_bridge_data *bridge, u32 mode);
  171. int agp_generic_create_gatt_table(struct agp_bridge_data *bridge);
  172. int agp_generic_free_gatt_table(struct agp_bridge_data *bridge);
  173. struct agp_memory *agp_create_memory(int scratch_pages);
  174. int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
  175. int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
  176. struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
  177. void agp_generic_free_by_type(struct agp_memory *curr);
  178. struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
  179. int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
  180. struct agp_memory *memory, size_t page_count);
  181. void agp_generic_destroy_page(struct page *page, int flags);
  182. void agp_generic_destroy_pages(struct agp_memory *memory);
  183. void agp_free_key(int key);
  184. int agp_num_entries(void);
  185. u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 mode, u32 command);
  186. void agp_device_command(u32 command, bool agp_v3);
  187. int agp_3_5_enable(struct agp_bridge_data *bridge);
  188. void global_cache_flush(void);
  189. void get_agp_version(struct agp_bridge_data *bridge);
  190. unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
  191. dma_addr_t phys, int type);
  192. int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
  193. int type);
  194. struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
  195. /* generic functions for user-populated AGP memory types */
  196. struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
  197. void agp_alloc_page_array(size_t size, struct agp_memory *mem);
  198. static inline void agp_free_page_array(struct agp_memory *mem)
  199. {
  200. kvfree(mem->pages);
  201. }
  202. /* generic routines for agp>=3 */
  203. int agp3_generic_fetch_size(void);
  204. void agp3_generic_tlbflush(struct agp_memory *mem);
  205. int agp3_generic_configure(void);
  206. void agp3_generic_cleanup(void);
  207. /* aperture sizes have been standardised since v3 */
  208. #define AGP_GENERIC_SIZES_ENTRIES 11
  209. extern const struct aper_size_info_16 agp3_generic_sizes[];
  210. extern int agp_off;
  211. extern int agp_try_unsupported_boot;
  212. long compat_agp_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  213. /* Chipset independent registers (from AGP Spec) */
  214. #define AGP_APBASE 0x10
  215. #define AGP_APERTURE_BAR 0
  216. #define AGPSTAT 0x4
  217. #define AGPCMD 0x8
  218. #define AGPNISTAT 0xc
  219. #define AGPCTRL 0x10
  220. #define AGPAPSIZE 0x14
  221. #define AGPNEPG 0x16
  222. #define AGPGARTLO 0x18
  223. #define AGPGARTHI 0x1c
  224. #define AGPNICMD 0x20
  225. #define AGP_MAJOR_VERSION_SHIFT (20)
  226. #define AGP_MINOR_VERSION_SHIFT (16)
  227. #define AGPSTAT_RQ_DEPTH (0xff000000)
  228. #define AGPSTAT_RQ_DEPTH_SHIFT 24
  229. #define AGPSTAT_CAL_MASK (1<<12|1<<11|1<<10)
  230. #define AGPSTAT_ARQSZ (1<<15|1<<14|1<<13)
  231. #define AGPSTAT_ARQSZ_SHIFT 13
  232. #define AGPSTAT_SBA (1<<9)
  233. #define AGPSTAT_AGP_ENABLE (1<<8)
  234. #define AGPSTAT_FW (1<<4)
  235. #define AGPSTAT_MODE_3_0 (1<<3)
  236. #define AGPSTAT2_1X (1<<0)
  237. #define AGPSTAT2_2X (1<<1)
  238. #define AGPSTAT2_4X (1<<2)
  239. #define AGPSTAT3_RSVD (1<<2)
  240. #define AGPSTAT3_8X (1<<1)
  241. #define AGPSTAT3_4X (1)
  242. #define AGPCTRL_APERENB (1<<8)
  243. #define AGPCTRL_GTLBEN (1<<7)
  244. #define AGP2_RESERVED_MASK 0x00fffcc8
  245. #define AGP3_RESERVED_MASK 0x00ff00c4
  246. #define AGP_ERRATA_FASTWRITES 1<<0
  247. #define AGP_ERRATA_SBA 1<<1
  248. #define AGP_ERRATA_1X 1<<2
  249. #endif /* _AGP_BACKEND_PRIV_H */