43 #include <asm/current.h>
45 #include <linux/kernel.h>
52 #include <linux/pci.h>
58 #include <linux/slab.h>
59 #if defined(__alpha__) || defined(__powerpc__)
60 #include <asm/pgtable.h>
64 #include <asm/uaccess.h>
68 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
69 #include <linux/types.h>
73 #include <linux/poll.h>
74 #include <asm/pgalloc.h>
80 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
81 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
92 #define DRM_UT_CORE 0x01
93 #define DRM_UT_DRIVER 0x02
94 #define DRM_UT_KMS 0x04
95 #define DRM_UT_PRIME 0x08
131 const char *function_name,
141 #define DRIVER_USE_AGP 0x1
142 #define DRIVER_REQUIRE_AGP 0x2
143 #define DRIVER_USE_MTRR 0x4
144 #define DRIVER_PCI_DMA 0x8
145 #define DRIVER_SG 0x10
146 #define DRIVER_HAVE_DMA 0x20
147 #define DRIVER_HAVE_IRQ 0x40
148 #define DRIVER_IRQ_SHARED 0x80
149 #define DRIVER_IRQ_VBL 0x100
150 #define DRIVER_DMA_QUEUE 0x200
151 #define DRIVER_FB_DMA 0x400
152 #define DRIVER_IRQ_VBL2 0x800
153 #define DRIVER_GEM 0x1000
154 #define DRIVER_MODESET 0x2000
155 #define DRIVER_PRIME 0x4000
157 #define DRIVER_BUS_PCI 0x1
158 #define DRIVER_BUS_PLATFORM 0x2
159 #define DRIVER_BUS_USB 0x3
165 #define DRM_DEBUG_CODE 2
168 #define DRM_MAGIC_HASH_ORDER 4
169 #define DRM_KERNEL_CONTEXT 0
170 #define DRM_RESERVED_CONTEXTS 1
171 #define DRM_LOOPING_LIMIT 5000000
172 #define DRM_TIME_SLICE (HZ/20)
173 #define DRM_LOCK_SLICE 1
175 #define DRM_FLAG_DEBUG 0x01
177 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
178 #define DRM_MAP_HASH_OFFSET 0x10000000
192 #define DRM_ERROR(fmt, ...) \
193 drm_err(__func__, fmt, ##__VA_ARGS__)
195 #define DRM_INFO(fmt, ...) \
196 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
205 #define DRM_DEBUG(fmt, args...) \
207 drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME, \
208 __func__, fmt, ##args); \
211 #define DRM_DEBUG_DRIVER(fmt, args...) \
213 drm_ut_debug_printk(DRM_UT_DRIVER, DRM_NAME, \
214 __func__, fmt, ##args); \
216 #define DRM_DEBUG_KMS(fmt, args...) \
218 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \
219 __func__, fmt, ##args); \
221 #define DRM_DEBUG_PRIME(fmt, args...) \
223 drm_ut_debug_printk(DRM_UT_PRIME, DRM_NAME, \
224 __func__, fmt, ##args); \
226 #define DRM_LOG(fmt, args...) \
228 drm_ut_debug_printk(DRM_UT_CORE, NULL, \
229 NULL, fmt, ##args); \
231 #define DRM_LOG_KMS(fmt, args...) \
233 drm_ut_debug_printk(DRM_UT_KMS, NULL, \
234 NULL, fmt, ##args); \
236 #define DRM_LOG_MODE(fmt, args...) \
238 drm_ut_debug_printk(DRM_UT_MODE, NULL, \
239 NULL, fmt, ##args); \
241 #define DRM_LOG_DRIVER(fmt, args...) \
243 drm_ut_debug_printk(DRM_UT_DRIVER, NULL, \
244 NULL, fmt, ##args); \
247 #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
248 #define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
249 #define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
250 #define DRM_DEBUG(fmt, arg...) do { } while (0)
251 #define DRM_LOG(fmt, arg...) do { } while (0)
252 #define DRM_LOG_KMS(fmt, args...) do { } while (0)
253 #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
254 #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
264 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
266 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
267 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
269 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
277 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
279 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
280 _file_priv->master->lock.file_priv != _file_priv) { \
281 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
282 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
283 _file_priv->master->lock.file_priv, _file_priv); \
297 struct drm_file *file_priv);
299 typedef int drm_ioctl_compat_t(
struct file *filp,
unsigned int cmd,
302 #define DRM_IOCTL_NR(n) _IOC_NR(n)
303 #define DRM_MAJOR 226
306 #define DRM_MASTER 0x2
307 #define DRM_ROOT_ONLY 0x4
308 #define DRM_CONTROL_ALLOW 0x8
309 #define DRM_UNLOCKED 0x10
311 struct drm_ioctl_desc {
315 unsigned int cmd_drv;
323 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
324 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
326 struct drm_magic_entry {
329 struct drm_file *
priv;
332 struct drm_vma_entry {
348 unsigned long bus_address;
349 struct drm_buf *
next;
350 __volatile__
int waiting;
351 __volatile__
int pending;
352 struct drm_file *file_priv;
369 struct drm_waitlist {
371 struct drm_buf **
bufs;
374 struct drm_buf **
end;
379 struct drm_freelist {
382 struct drm_buf *
next;
391 typedef struct drm_dma_handle {
400 struct drm_buf_entry {
406 struct drm_dma_handle **seglist;
408 struct drm_freelist freelist;
412 struct drm_pending_event {
415 struct drm_file *file_priv;
422 struct drm_prime_file_private {
433 unsigned long ioctl_count;
435 struct drm_minor *
minor;
436 unsigned long lock_count;
439 struct idr object_idr;
447 struct drm_master *master;
455 struct drm_prime_file_private prime;
471 struct drm_waitlist waitlist;
478 struct drm_lock_data {
481 struct drm_file *file_priv;
483 unsigned long lock_time;
493 struct drm_device_dma {
500 unsigned long *pagelist;
501 unsigned long byte_count;
503 _DRM_DMA_USE_AGP = 0x01,
504 _DRM_DMA_USE_SG = 0x02,
505 _DRM_DMA_USE_FB = 0x04,
506 _DRM_DMA_USE_PCI_RO = 0x08
527 struct drm_agp_head {
536 int cant_use_aperture;
537 unsigned long page_mask;
547 struct page **pagelist;
560 struct drm_local_map {
570 typedef struct drm_local_map drm_local_map_t;
575 struct drm_map_list {
578 struct drm_local_map *
map;
580 struct drm_master *master;
587 struct drm_ctx_list {
590 struct drm_file *
tag;
594 #define DRM_ATI_GART_MAIN 1
595 #define DRM_ATI_GART_FB 2
597 #define DRM_ATI_GART_PCI 1
598 #define DRM_ATI_GART_PCIE 2
599 #define DRM_ATI_GART_IGP 3
601 struct drm_ati_pcigart_info {
602 int gart_table_location;
607 struct drm_dma_handle *table_handle;
616 struct drm_mm offset_manager;
624 struct drm_gem_object {
673 struct dma_buf *export_dma_buf;
687 struct drm_minor *
minor;
701 struct drm_lock_data
lock;
709 #define DRM_VBLANKTIME_RBSIZE 2
712 #define DRM_CALLED_FROM_VBLIRQ 1
713 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
714 #define DRM_VBLANKTIME_INVBL (1 << 1)
717 #define DRM_SCANOUTPOS_VALID (1 << 0)
718 #define DRM_SCANOUTPOS_INVBL (1 << 1)
719 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
743 void (*preclose) (
struct drm_device *,
struct drm_file *file_priv);
895 int (*debugfs_init)(
struct drm_minor *
minor);
896 void (*debugfs_cleanup)(
struct drm_minor *
minor);
904 int (*gem_init_object) (
struct drm_gem_object *obj);
905 void (*gem_free_object) (
struct drm_gem_object *obj);
906 int (*gem_open_object) (
struct drm_gem_object *,
struct drm_file *);
907 void (*gem_close_object) (
struct drm_gem_object *,
struct drm_file *);
911 int (*prime_handle_to_fd)(
struct drm_device *
dev,
struct drm_file *file_priv,
914 int (*prime_fd_to_handle)(
struct drm_device *
dev,
struct drm_file *file_priv,
918 struct drm_gem_object *obj,
int flags);
920 struct drm_gem_object * (*gem_prime_import)(
struct drm_device *
dev,
927 int (*dumb_create)(
struct drm_file *file_priv,
930 int (*dumb_map_offset)(
struct drm_file *file_priv,
933 int (*dumb_destroy)(
struct drm_file *file_priv,
938 const struct vm_operations_struct *gem_vm_ops;
949 struct drm_ioctl_desc *
ioctls;
955 struct usb_driver *
usb;
963 #define DRM_MINOR_UNASSIGNED 0
964 #define DRM_MINOR_LEGACY 1
965 #define DRM_MINOR_CONTROL 2
966 #define DRM_MINOR_RENDER 3
973 struct drm_debugfs_list {
982 struct drm_debugfs_node {
984 struct drm_minor *
minor;
985 struct drm_debugfs_list *debugfs_ent;
993 struct drm_info_list {
1003 struct drm_info_node {
1005 struct drm_minor *
minor;
1006 struct drm_info_list *info_ent;
1021 struct drm_info_node proc_nodes;
1022 struct dentry *debugfs_root;
1025 struct mutex debugfs_lock;
1027 struct drm_master *master;
1033 struct drm_cmdline_mode {
1035 bool refresh_specified;
1048 struct drm_pending_vblank_event {
1049 struct drm_pending_event
base;
1066 struct mutex struct_mutex;
1080 unsigned long counters;
1097 struct mutex ctxlist_mutex;
1107 struct drm_device_dma *
dma;
1113 __volatile__
long context_flag;
1114 __volatile__
long interrupt_flag;
1115 __volatile__
long dma_flag;
1119 unsigned long last_switch;
1132 int vblank_disable_allowed;
1142 int *vblank_enabled;
1144 int *vblank_inmodeset;
1145 u32 *last_vblank_wait;
1148 u32 max_vblank_count;
1164 struct drm_agp_head *
agp;
1175 struct usb_device *usbdev;
1177 struct drm_sg_mem *
sg;
1178 unsigned int num_crtcs;
1182 struct drm_sigdata sigdata;
1185 struct drm_driver *
driver;
1186 struct drm_local_map *agp_buffer_map;
1187 unsigned int agp_buffer_token;
1196 struct idr object_name_idr;
1198 int switch_power_state;
1203 #define DRM_SWITCH_POWER_ON 0
1204 #define DRM_SWITCH_POWER_OFF 1
1205 #define DRM_SWITCH_POWER_CHANGING 2
1210 return ((dev->driver->driver_features & feature) ? 1 : 0);
1213 static inline int drm_dev_to_irq(
struct drm_device *dev)
1215 return dev->driver->bus->get_irq(dev);
1220 static inline int drm_core_has_AGP(
struct drm_device *dev)
1222 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1225 #define drm_core_has_AGP(dev) (0)
1229 static inline int drm_core_has_MTRR(
struct drm_device *dev)
1231 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1234 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
1236 static inline int drm_mtrr_add(
unsigned long offset,
unsigned long size,
1239 return mtrr_add(offset, size, flags, 1);
1242 static inline int drm_mtrr_del(
int handle,
unsigned long offset,
1245 return mtrr_del(handle, offset, size);
1249 #define drm_core_has_MTRR(dev) (0)
1251 #define DRM_MTRR_WC 0
1253 static inline int drm_mtrr_add(
unsigned long offset,
unsigned long size,
1259 static inline int drm_mtrr_del(
int handle,
unsigned long offset,
1266 static inline void drm_device_set_unplugged(
struct drm_device *dev)
1272 static inline int drm_device_is_unplugged(
struct drm_device *dev)
1285 unsigned int cmd,
unsigned long arg);
1287 unsigned int cmd,
unsigned long arg);
1291 extern struct mutex drm_global_mutex;
1319 struct drm_file *file_priv);
1321 struct drm_file *file_priv);
1323 struct drm_file *file_priv);
1325 struct drm_file *file_priv);
1327 struct drm_file *file_priv);
1329 struct drm_file *file_priv);
1331 struct drm_file *file_priv);
1333 struct drm_file *file_priv);
1335 struct drm_file *file_priv);
1339 struct drm_file *file_priv);
1341 struct drm_file *file_priv);
1343 struct drm_file *file_priv);
1345 struct drm_file *file_priv);
1347 struct drm_file *file_priv);
1349 struct drm_file *file_priv);
1351 struct drm_file *file_priv);
1358 struct drm_file *file_priv);
1360 struct drm_file *file_priv);
1364 struct drm_file *file_priv);
1366 struct drm_file *file_priv);
1376 struct drm_file *file_priv);
1378 struct drm_file *file_priv);
1397 struct drm_file *file_priv);
1401 struct drm_file *file_priv);
1403 struct drm_file *file_priv);
1405 struct drm_file *file_priv);
1407 struct drm_file *file_priv);
1409 struct drm_file *file_priv);
1411 struct drm_file *file_priv);
1419 struct drm_file *filp);
1423 struct drm_file *file_priv);
1429 struct drm_file *filp);
1430 extern int drm_vblank_wait(
struct drm_device *dev,
unsigned int *vbl_seq);
1442 int crtc,
int *max_error,
1451 struct drm_cmdline_mode *
mode);
1455 struct drm_cmdline_mode *
cmd);
1461 struct drm_file *file_priv);
1464 extern struct drm_agp_head *drm_agp_init(
struct drm_device *dev);
1465 extern int drm_agp_acquire(
struct drm_device *dev);
1466 extern int drm_agp_acquire_ioctl(
struct drm_device *dev,
void *
data,
1467 struct drm_file *file_priv);
1468 extern int drm_agp_release(
struct drm_device *dev);
1469 extern int drm_agp_release_ioctl(
struct drm_device *dev,
void *
data,
1470 struct drm_file *file_priv);
1472 extern int drm_agp_enable_ioctl(
struct drm_device *dev,
void *
data,
1473 struct drm_file *file_priv);
1475 extern int drm_agp_info_ioctl(
struct drm_device *dev,
void *
data,
1476 struct drm_file *file_priv);
1478 extern int drm_agp_alloc_ioctl(
struct drm_device *dev,
void *
data,
1479 struct drm_file *file_priv);
1481 extern int drm_agp_free_ioctl(
struct drm_device *dev,
void *
data,
1482 struct drm_file *file_priv);
1484 extern int drm_agp_unbind_ioctl(
struct drm_device *dev,
void *
data,
1485 struct drm_file *file_priv);
1487 extern int drm_agp_bind_ioctl(
struct drm_device *dev,
void *
data,
1488 struct drm_file *file_priv);
1492 struct drm_file *file_priv);
1494 struct drm_file *file_priv);
1496 extern struct drm_master *
drm_master_get(
struct drm_master *master);
1516 extern int drm_proc_init(
struct drm_minor *minor,
int minor_id,
1521 #if defined(CONFIG_DEBUG_FS)
1522 extern int drm_debugfs_init(
struct drm_minor *minor,
int minor_id,
1524 extern int drm_debugfs_create_files(
struct drm_info_list *
files,
int count,
1525 struct dentry *root,
struct drm_minor *minor);
1526 extern int drm_debugfs_remove_files(
struct drm_info_list *
files,
int count,
1527 struct drm_minor *minor);
1528 extern int drm_debugfs_cleanup(
struct drm_minor *minor);
1547 struct drm_file *file_priv);
1549 struct drm_file *file_priv);
1563 int drm_prime_add_dma_buf(
struct drm_device *dev,
struct drm_gem_object *obj);
1565 struct drm_gem_object **obj);
1574 struct drm_file *file_priv);
1577 struct drm_file *file_priv);
1581 struct drm_ati_pcigart_info * gart_info);
1583 struct drm_ati_pcigart_info * gart_info);
1591 struct drm_sysfs_class;
1609 struct drm_gem_object *obj,
size_t size);
1611 struct drm_gem_object *obj,
size_t size);
1620 drm_gem_object_reference(
struct drm_gem_object *obj)
1622 kref_get(&obj->refcount);
1626 drm_gem_object_unreference(
struct drm_gem_object *obj)
1633 drm_gem_object_unreference_unlocked(
struct drm_gem_object *obj)
1644 struct drm_gem_object *obj,
1649 drm_gem_object_handle_reference(
struct drm_gem_object *obj)
1651 drm_gem_object_reference(obj);
1656 drm_gem_object_handle_unreference(
struct drm_gem_object *obj)
1670 drm_gem_object_unreference(obj);
1674 drm_gem_object_handle_unreference_unlocked(
struct drm_gem_object *obj)
1690 drm_gem_object_unreference_unlocked(obj);
1697 struct drm_file *filp,
1700 struct drm_file *file_priv);
1702 struct drm_file *file_priv);
1704 struct drm_file *file_priv);
1715 struct drm_map_list *
_entry;
1717 if (_entry->user_token == token)
1730 struct drm_driver *
driver);
1737 if (dev->driver->device_is_agp !=
NULL) {
1738 int err = (*dev->driver->device_is_agp) (dev);
1750 extern int drm_get_pci_dev(
struct pci_dev *pdev,
1752 struct drm_driver *
driver);
1754 #define DRM_PCIE_SPEED_25 1
1755 #define DRM_PCIE_SPEED_50 2
1756 #define DRM_PCIE_SPEED_80 4
1765 struct drm_driver *
driver);