diff options
Diffstat (limited to 'include/drm/drmP.h')
-rw-r--r-- | include/drm/drmP.h | 120 |
1 files changed, 91 insertions, 29 deletions
diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 2f3b3a00b7a3..4c9461a4f9e6 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h | |||
@@ -9,6 +9,7 @@ | |||
9 | /* | 9 | /* |
10 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. | 10 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
11 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. | 11 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
12 | * Copyright (c) 2009-2010, Code Aurora Forum. | ||
12 | * All rights reserved. | 13 | * All rights reserved. |
13 | * | 14 | * |
14 | * Permission is hereby granted, free of charge, to any person obtaining a | 15 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -48,9 +49,9 @@ | |||
48 | #include <linux/proc_fs.h> | 49 | #include <linux/proc_fs.h> |
49 | #include <linux/init.h> | 50 | #include <linux/init.h> |
50 | #include <linux/file.h> | 51 | #include <linux/file.h> |
52 | #include <linux/platform_device.h> | ||
51 | #include <linux/pci.h> | 53 | #include <linux/pci.h> |
52 | #include <linux/jiffies.h> | 54 | #include <linux/jiffies.h> |
53 | #include <linux/smp_lock.h> /* For (un)lock_kernel */ | ||
54 | #include <linux/dma-mapping.h> | 55 | #include <linux/dma-mapping.h> |
55 | #include <linux/mm.h> | 56 | #include <linux/mm.h> |
56 | #include <linux/cdev.h> | 57 | #include <linux/cdev.h> |
@@ -144,6 +145,7 @@ extern void drm_ut_debug_printk(unsigned int request_level, | |||
144 | #define DRIVER_IRQ_VBL2 0x800 | 145 | #define DRIVER_IRQ_VBL2 0x800 |
145 | #define DRIVER_GEM 0x1000 | 146 | #define DRIVER_GEM 0x1000 |
146 | #define DRIVER_MODESET 0x2000 | 147 | #define DRIVER_MODESET 0x2000 |
148 | #define DRIVER_USE_PLATFORM_DEVICE 0x4000 | ||
147 | 149 | ||
148 | /***********************************************************************/ | 150 | /***********************************************************************/ |
149 | /** \name Begin the DRM... */ | 151 | /** \name Begin the DRM... */ |
@@ -303,14 +305,16 @@ struct drm_ioctl_desc { | |||
303 | unsigned int cmd; | 305 | unsigned int cmd; |
304 | int flags; | 306 | int flags; |
305 | drm_ioctl_t *func; | 307 | drm_ioctl_t *func; |
308 | unsigned int cmd_drv; | ||
306 | }; | 309 | }; |
307 | 310 | ||
308 | /** | 311 | /** |
309 | * Creates a driver or general drm_ioctl_desc array entry for the given | 312 | * Creates a driver or general drm_ioctl_desc array entry for the given |
310 | * ioctl, for use by drm_ioctl(). | 313 | * ioctl, for use by drm_ioctl(). |
311 | */ | 314 | */ |
312 | #define DRM_IOCTL_DEF(ioctl, _func, _flags) \ | 315 | |
313 | [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags} | 316 | #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \ |
317 | [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl} | ||
314 | 318 | ||
315 | struct drm_magic_entry { | 319 | struct drm_magic_entry { |
316 | struct list_head head; | 320 | struct list_head head; |
@@ -403,6 +407,8 @@ struct drm_pending_event { | |||
403 | struct drm_event *event; | 407 | struct drm_event *event; |
404 | struct list_head link; | 408 | struct list_head link; |
405 | struct drm_file *file_priv; | 409 | struct drm_file *file_priv; |
410 | pid_t pid; /* pid of requester, no guarantee it's valid by the time | ||
411 | we deliver the event, for tracing only */ | ||
406 | void (*destroy)(struct drm_pending_event *event); | 412 | void (*destroy)(struct drm_pending_event *event); |
407 | }; | 413 | }; |
408 | 414 | ||
@@ -606,7 +612,7 @@ struct drm_gem_object { | |||
606 | struct kref refcount; | 612 | struct kref refcount; |
607 | 613 | ||
608 | /** Handle count of this object. Each handle also holds a reference */ | 614 | /** Handle count of this object. Each handle also holds a reference */ |
609 | struct kref handlecount; | 615 | atomic_t handle_count; /* number of handles on this object */ |
610 | 616 | ||
611 | /** Related drm device */ | 617 | /** Related drm device */ |
612 | struct drm_device *dev; | 618 | struct drm_device *dev; |
@@ -802,7 +808,6 @@ struct drm_driver { | |||
802 | */ | 808 | */ |
803 | int (*gem_init_object) (struct drm_gem_object *obj); | 809 | int (*gem_init_object) (struct drm_gem_object *obj); |
804 | void (*gem_free_object) (struct drm_gem_object *obj); | 810 | void (*gem_free_object) (struct drm_gem_object *obj); |
805 | void (*gem_free_object_unlocked) (struct drm_gem_object *obj); | ||
806 | 811 | ||
807 | /* vga arb irq handler */ | 812 | /* vga arb irq handler */ |
808 | void (*vgaarb_irq)(struct drm_device *dev, bool state); | 813 | void (*vgaarb_irq)(struct drm_device *dev, bool state); |
@@ -823,6 +828,7 @@ struct drm_driver { | |||
823 | int num_ioctls; | 828 | int num_ioctls; |
824 | struct file_operations fops; | 829 | struct file_operations fops; |
825 | struct pci_driver pci_driver; | 830 | struct pci_driver pci_driver; |
831 | struct platform_device *platform_device; | ||
826 | /* List of devices hanging off this driver */ | 832 | /* List of devices hanging off this driver */ |
827 | struct list_head device_list; | 833 | struct list_head device_list; |
828 | }; | 834 | }; |
@@ -1015,12 +1021,16 @@ struct drm_device { | |||
1015 | 1021 | ||
1016 | struct drm_agp_head *agp; /**< AGP data */ | 1022 | struct drm_agp_head *agp; /**< AGP data */ |
1017 | 1023 | ||
1024 | struct device *dev; /**< Device structure */ | ||
1018 | struct pci_dev *pdev; /**< PCI device structure */ | 1025 | struct pci_dev *pdev; /**< PCI device structure */ |
1019 | int pci_vendor; /**< PCI vendor id */ | 1026 | int pci_vendor; /**< PCI vendor id */ |
1020 | int pci_device; /**< PCI device id */ | 1027 | int pci_device; /**< PCI device id */ |
1021 | #ifdef __alpha__ | 1028 | #ifdef __alpha__ |
1022 | struct pci_controller *hose; | 1029 | struct pci_controller *hose; |
1023 | #endif | 1030 | #endif |
1031 | |||
1032 | struct platform_device *platformdev; /**< Platform device struture */ | ||
1033 | |||
1024 | struct drm_sg_mem *sg; /**< Scatter gather memory */ | 1034 | struct drm_sg_mem *sg; /**< Scatter gather memory */ |
1025 | int num_crtcs; /**< Number of CRTCs on this device */ | 1035 | int num_crtcs; /**< Number of CRTCs on this device */ |
1026 | void *dev_private; /**< device private data */ | 1036 | void *dev_private; /**< device private data */ |
@@ -1060,22 +1070,36 @@ struct drm_device { | |||
1060 | 1070 | ||
1061 | }; | 1071 | }; |
1062 | 1072 | ||
1063 | static inline int drm_dev_to_irq(struct drm_device *dev) | ||
1064 | { | ||
1065 | return dev->pdev->irq; | ||
1066 | } | ||
1067 | |||
1068 | static __inline__ int drm_core_check_feature(struct drm_device *dev, | 1073 | static __inline__ int drm_core_check_feature(struct drm_device *dev, |
1069 | int feature) | 1074 | int feature) |
1070 | { | 1075 | { |
1071 | return ((dev->driver->driver_features & feature) ? 1 : 0); | 1076 | return ((dev->driver->driver_features & feature) ? 1 : 0); |
1072 | } | 1077 | } |
1073 | 1078 | ||
1074 | #ifdef __alpha__ | 1079 | static inline int drm_dev_to_irq(struct drm_device *dev) |
1075 | #define drm_get_pci_domain(dev) dev->hose->index | 1080 | { |
1076 | #else | 1081 | if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) |
1077 | #define drm_get_pci_domain(dev) 0 | 1082 | return platform_get_irq(dev->platformdev, 0); |
1078 | #endif | 1083 | else |
1084 | return dev->pdev->irq; | ||
1085 | } | ||
1086 | |||
1087 | static inline int drm_get_pci_domain(struct drm_device *dev) | ||
1088 | { | ||
1089 | if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) | ||
1090 | return 0; | ||
1091 | |||
1092 | #ifndef __alpha__ | ||
1093 | /* For historical reasons, drm_get_pci_domain() is busticated | ||
1094 | * on most archs and has to remain so for userspace interface | ||
1095 | * < 1.4, except on alpha which was right from the beginning | ||
1096 | */ | ||
1097 | if (dev->if_version < 0x10004) | ||
1098 | return 0; | ||
1099 | #endif /* __alpha__ */ | ||
1100 | |||
1101 | return pci_domain_nr(dev->pdev->bus); | ||
1102 | } | ||
1079 | 1103 | ||
1080 | #if __OS_HAS_AGP | 1104 | #if __OS_HAS_AGP |
1081 | static inline int drm_core_has_AGP(struct drm_device *dev) | 1105 | static inline int drm_core_has_AGP(struct drm_device *dev) |
@@ -1138,6 +1162,7 @@ extern long drm_compat_ioctl(struct file *filp, | |||
1138 | extern int drm_lastclose(struct drm_device *dev); | 1162 | extern int drm_lastclose(struct drm_device *dev); |
1139 | 1163 | ||
1140 | /* Device support (drm_fops.h) */ | 1164 | /* Device support (drm_fops.h) */ |
1165 | extern struct mutex drm_global_mutex; | ||
1141 | extern int drm_open(struct inode *inode, struct file *filp); | 1166 | extern int drm_open(struct inode *inode, struct file *filp); |
1142 | extern int drm_stub_open(struct inode *inode, struct file *filp); | 1167 | extern int drm_stub_open(struct inode *inode, struct file *filp); |
1143 | extern int drm_fasync(int fd, struct file *filp, int on); | 1168 | extern int drm_fasync(int fd, struct file *filp, int on); |
@@ -1149,6 +1174,7 @@ extern int drm_release(struct inode *inode, struct file *filp); | |||
1149 | extern int drm_mmap(struct file *filp, struct vm_area_struct *vma); | 1174 | extern int drm_mmap(struct file *filp, struct vm_area_struct *vma); |
1150 | extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma); | 1175 | extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma); |
1151 | extern void drm_vm_open_locked(struct vm_area_struct *vma); | 1176 | extern void drm_vm_open_locked(struct vm_area_struct *vma); |
1177 | extern void drm_vm_close_locked(struct vm_area_struct *vma); | ||
1152 | extern resource_size_t drm_core_get_map_ofs(struct drm_local_map * map); | 1178 | extern resource_size_t drm_core_get_map_ofs(struct drm_local_map * map); |
1153 | extern resource_size_t drm_core_get_reg_ofs(struct drm_device *dev); | 1179 | extern resource_size_t drm_core_get_reg_ofs(struct drm_device *dev); |
1154 | extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); | 1180 | extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); |
@@ -1273,10 +1299,6 @@ extern int drm_freebufs(struct drm_device *dev, void *data, | |||
1273 | extern int drm_mapbufs(struct drm_device *dev, void *data, | 1299 | extern int drm_mapbufs(struct drm_device *dev, void *data, |
1274 | struct drm_file *file_priv); | 1300 | struct drm_file *file_priv); |
1275 | extern int drm_order(unsigned long size); | 1301 | extern int drm_order(unsigned long size); |
1276 | extern resource_size_t drm_get_resource_start(struct drm_device *dev, | ||
1277 | unsigned int resource); | ||
1278 | extern resource_size_t drm_get_resource_len(struct drm_device *dev, | ||
1279 | unsigned int resource); | ||
1280 | 1302 | ||
1281 | /* DMA support (drm_dma.h) */ | 1303 | /* DMA support (drm_dma.h) */ |
1282 | extern int drm_dma_setup(struct drm_device *dev); | 1304 | extern int drm_dma_setup(struct drm_device *dev); |
@@ -1351,8 +1373,11 @@ extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data, | |||
1351 | struct drm_master *drm_master_create(struct drm_minor *minor); | 1373 | struct drm_master *drm_master_create(struct drm_minor *minor); |
1352 | extern struct drm_master *drm_master_get(struct drm_master *master); | 1374 | extern struct drm_master *drm_master_get(struct drm_master *master); |
1353 | extern void drm_master_put(struct drm_master **master); | 1375 | extern void drm_master_put(struct drm_master **master); |
1354 | extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent, | 1376 | extern int drm_get_pci_dev(struct pci_dev *pdev, |
1355 | struct drm_driver *driver); | 1377 | const struct pci_device_id *ent, |
1378 | struct drm_driver *driver); | ||
1379 | extern int drm_get_platform_dev(struct platform_device *pdev, | ||
1380 | struct drm_driver *driver); | ||
1356 | extern void drm_put_dev(struct drm_device *dev); | 1381 | extern void drm_put_dev(struct drm_device *dev); |
1357 | extern int drm_put_minor(struct drm_minor **minor); | 1382 | extern int drm_put_minor(struct drm_minor **minor); |
1358 | extern unsigned int drm_debug; | 1383 | extern unsigned int drm_debug; |
@@ -1428,15 +1453,19 @@ extern void drm_sysfs_connector_remove(struct drm_connector *connector); | |||
1428 | /* Graphics Execution Manager library functions (drm_gem.c) */ | 1453 | /* Graphics Execution Manager library functions (drm_gem.c) */ |
1429 | int drm_gem_init(struct drm_device *dev); | 1454 | int drm_gem_init(struct drm_device *dev); |
1430 | void drm_gem_destroy(struct drm_device *dev); | 1455 | void drm_gem_destroy(struct drm_device *dev); |
1456 | void drm_gem_object_release(struct drm_gem_object *obj); | ||
1431 | void drm_gem_object_free(struct kref *kref); | 1457 | void drm_gem_object_free(struct kref *kref); |
1432 | void drm_gem_object_free_unlocked(struct kref *kref); | ||
1433 | struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, | 1458 | struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, |
1434 | size_t size); | 1459 | size_t size); |
1435 | void drm_gem_object_handle_free(struct kref *kref); | 1460 | int drm_gem_object_init(struct drm_device *dev, |
1461 | struct drm_gem_object *obj, size_t size); | ||
1462 | void drm_gem_object_handle_free(struct drm_gem_object *obj); | ||
1436 | void drm_gem_vm_open(struct vm_area_struct *vma); | 1463 | void drm_gem_vm_open(struct vm_area_struct *vma); |
1437 | void drm_gem_vm_close(struct vm_area_struct *vma); | 1464 | void drm_gem_vm_close(struct vm_area_struct *vma); |
1438 | int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); | 1465 | int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); |
1439 | 1466 | ||
1467 | #include "drm_global.h" | ||
1468 | |||
1440 | static inline void | 1469 | static inline void |
1441 | drm_gem_object_reference(struct drm_gem_object *obj) | 1470 | drm_gem_object_reference(struct drm_gem_object *obj) |
1442 | { | 1471 | { |
@@ -1453,8 +1482,12 @@ drm_gem_object_unreference(struct drm_gem_object *obj) | |||
1453 | static inline void | 1482 | static inline void |
1454 | drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) | 1483 | drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) |
1455 | { | 1484 | { |
1456 | if (obj != NULL) | 1485 | if (obj != NULL) { |
1457 | kref_put(&obj->refcount, drm_gem_object_free_unlocked); | 1486 | struct drm_device *dev = obj->dev; |
1487 | mutex_lock(&dev->struct_mutex); | ||
1488 | kref_put(&obj->refcount, drm_gem_object_free); | ||
1489 | mutex_unlock(&dev->struct_mutex); | ||
1490 | } | ||
1458 | } | 1491 | } |
1459 | 1492 | ||
1460 | int drm_gem_handle_create(struct drm_file *file_priv, | 1493 | int drm_gem_handle_create(struct drm_file *file_priv, |
@@ -1465,7 +1498,7 @@ static inline void | |||
1465 | drm_gem_object_handle_reference(struct drm_gem_object *obj) | 1498 | drm_gem_object_handle_reference(struct drm_gem_object *obj) |
1466 | { | 1499 | { |
1467 | drm_gem_object_reference(obj); | 1500 | drm_gem_object_reference(obj); |
1468 | kref_get(&obj->handlecount); | 1501 | atomic_inc(&obj->handle_count); |
1469 | } | 1502 | } |
1470 | 1503 | ||
1471 | static inline void | 1504 | static inline void |
@@ -1474,12 +1507,15 @@ drm_gem_object_handle_unreference(struct drm_gem_object *obj) | |||
1474 | if (obj == NULL) | 1507 | if (obj == NULL) |
1475 | return; | 1508 | return; |
1476 | 1509 | ||
1510 | if (atomic_read(&obj->handle_count) == 0) | ||
1511 | return; | ||
1477 | /* | 1512 | /* |
1478 | * Must bump handle count first as this may be the last | 1513 | * Must bump handle count first as this may be the last |
1479 | * ref, in which case the object would disappear before we | 1514 | * ref, in which case the object would disappear before we |
1480 | * checked for a name | 1515 | * checked for a name |
1481 | */ | 1516 | */ |
1482 | kref_put(&obj->handlecount, drm_gem_object_handle_free); | 1517 | if (atomic_dec_and_test(&obj->handle_count)) |
1518 | drm_gem_object_handle_free(obj); | ||
1483 | drm_gem_object_unreference(obj); | 1519 | drm_gem_object_unreference(obj); |
1484 | } | 1520 | } |
1485 | 1521 | ||
@@ -1489,12 +1525,17 @@ drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj) | |||
1489 | if (obj == NULL) | 1525 | if (obj == NULL) |
1490 | return; | 1526 | return; |
1491 | 1527 | ||
1528 | if (atomic_read(&obj->handle_count) == 0) | ||
1529 | return; | ||
1530 | |||
1492 | /* | 1531 | /* |
1493 | * Must bump handle count first as this may be the last | 1532 | * Must bump handle count first as this may be the last |
1494 | * ref, in which case the object would disappear before we | 1533 | * ref, in which case the object would disappear before we |
1495 | * checked for a name | 1534 | * checked for a name |
1496 | */ | 1535 | */ |
1497 | kref_put(&obj->handlecount, drm_gem_object_handle_free); | 1536 | |
1537 | if (atomic_dec_and_test(&obj->handle_count)) | ||
1538 | drm_gem_object_handle_free(obj); | ||
1498 | drm_gem_object_unreference_unlocked(obj); | 1539 | drm_gem_object_unreference_unlocked(obj); |
1499 | } | 1540 | } |
1500 | 1541 | ||
@@ -1526,6 +1567,9 @@ static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, | |||
1526 | 1567 | ||
1527 | static __inline__ int drm_device_is_agp(struct drm_device *dev) | 1568 | static __inline__ int drm_device_is_agp(struct drm_device *dev) |
1528 | { | 1569 | { |
1570 | if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) | ||
1571 | return 0; | ||
1572 | |||
1529 | if (dev->driver->device_is_agp != NULL) { | 1573 | if (dev->driver->device_is_agp != NULL) { |
1530 | int err = (*dev->driver->device_is_agp) (dev); | 1574 | int err = (*dev->driver->device_is_agp) (dev); |
1531 | 1575 | ||
@@ -1539,7 +1583,10 @@ static __inline__ int drm_device_is_agp(struct drm_device *dev) | |||
1539 | 1583 | ||
1540 | static __inline__ int drm_device_is_pcie(struct drm_device *dev) | 1584 | static __inline__ int drm_device_is_pcie(struct drm_device *dev) |
1541 | { | 1585 | { |
1542 | return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP); | 1586 | if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) |
1587 | return 0; | ||
1588 | else | ||
1589 | return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP); | ||
1543 | } | 1590 | } |
1544 | 1591 | ||
1545 | static __inline__ void drm_core_dropmap(struct drm_local_map *map) | 1592 | static __inline__ void drm_core_dropmap(struct drm_local_map *map) |
@@ -1547,6 +1594,21 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map) | |||
1547 | } | 1594 | } |
1548 | 1595 | ||
1549 | #include "drm_mem_util.h" | 1596 | #include "drm_mem_util.h" |
1597 | |||
1598 | static inline void *drm_get_device(struct drm_device *dev) | ||
1599 | { | ||
1600 | if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) | ||
1601 | return dev->platformdev; | ||
1602 | else | ||
1603 | return dev->pdev; | ||
1604 | } | ||
1605 | |||
1606 | extern int drm_platform_init(struct drm_driver *driver); | ||
1607 | extern int drm_pci_init(struct drm_driver *driver); | ||
1608 | extern int drm_fill_in_dev(struct drm_device *dev, | ||
1609 | const struct pci_device_id *ent, | ||
1610 | struct drm_driver *driver); | ||
1611 | int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type); | ||
1550 | /*@}*/ | 1612 | /*@}*/ |
1551 | 1613 | ||
1552 | #endif /* __KERNEL__ */ | 1614 | #endif /* __KERNEL__ */ |