aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2011-05-24 03:45:06 -0400
committerTony Lindgren <tony@atomide.com>2011-05-24 03:45:06 -0400
commit9b28b11e2a648f07c8481b9666ccf1c088e1ab74 (patch)
treeac3db2d4ae69e393d8423bb8c9304c75023dc805 /drivers/video
parentb7679ab3f70482ff4b75a8c735c8224ebedb6020 (diff)
parent99aa18278e867574d72201b806f82ace07d4804b (diff)
Merge branch 'for_2.6.40/pm-cleanup' of ssh://master.kernel.org/pub/scm/linux/kernel/git/khilman/linux-omap-pm into omap-for-linus
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/fbmem.c223
1 files changed, 148 insertions, 75 deletions
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index e0c2284924b6..5aac00eb1830 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -42,9 +42,34 @@
42 42
43#define FBPIXMAPSIZE (1024 * 8) 43#define FBPIXMAPSIZE (1024 * 8)
44 44
45static DEFINE_MUTEX(registration_lock);
45struct fb_info *registered_fb[FB_MAX] __read_mostly; 46struct fb_info *registered_fb[FB_MAX] __read_mostly;
46int num_registered_fb __read_mostly; 47int num_registered_fb __read_mostly;
47 48
49static struct fb_info *get_fb_info(unsigned int idx)
50{
51 struct fb_info *fb_info;
52
53 if (idx >= FB_MAX)
54 return ERR_PTR(-ENODEV);
55
56 mutex_lock(&registration_lock);
57 fb_info = registered_fb[idx];
58 if (fb_info)
59 atomic_inc(&fb_info->count);
60 mutex_unlock(&registration_lock);
61
62 return fb_info;
63}
64
65static void put_fb_info(struct fb_info *fb_info)
66{
67 if (!atomic_dec_and_test(&fb_info->count))
68 return;
69 if (fb_info->fbops->fb_destroy)
70 fb_info->fbops->fb_destroy(fb_info);
71}
72
48int lock_fb_info(struct fb_info *info) 73int lock_fb_info(struct fb_info *info)
49{ 74{
50 mutex_lock(&info->lock); 75 mutex_lock(&info->lock);
@@ -647,6 +672,7 @@ int fb_show_logo(struct fb_info *info, int rotate) { return 0; }
647 672
648static void *fb_seq_start(struct seq_file *m, loff_t *pos) 673static void *fb_seq_start(struct seq_file *m, loff_t *pos)
649{ 674{
675 mutex_lock(&registration_lock);
650 return (*pos < FB_MAX) ? pos : NULL; 676 return (*pos < FB_MAX) ? pos : NULL;
651} 677}
652 678
@@ -658,6 +684,7 @@ static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos)
658 684
659static void fb_seq_stop(struct seq_file *m, void *v) 685static void fb_seq_stop(struct seq_file *m, void *v)
660{ 686{
687 mutex_unlock(&registration_lock);
661} 688}
662 689
663static int fb_seq_show(struct seq_file *m, void *v) 690static int fb_seq_show(struct seq_file *m, void *v)
@@ -690,13 +717,30 @@ static const struct file_operations fb_proc_fops = {
690 .release = seq_release, 717 .release = seq_release,
691}; 718};
692 719
693static ssize_t 720/*
694fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 721 * We hold a reference to the fb_info in file->private_data,
722 * but if the current registered fb has changed, we don't
723 * actually want to use it.
724 *
725 * So look up the fb_info using the inode minor number,
726 * and just verify it against the reference we have.
727 */
728static struct fb_info *file_fb_info(struct file *file)
695{ 729{
696 unsigned long p = *ppos;
697 struct inode *inode = file->f_path.dentry->d_inode; 730 struct inode *inode = file->f_path.dentry->d_inode;
698 int fbidx = iminor(inode); 731 int fbidx = iminor(inode);
699 struct fb_info *info = registered_fb[fbidx]; 732 struct fb_info *info = registered_fb[fbidx];
733
734 if (info != file->private_data)
735 info = NULL;
736 return info;
737}
738
739static ssize_t
740fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
741{
742 unsigned long p = *ppos;
743 struct fb_info *info = file_fb_info(file);
700 u8 *buffer, *dst; 744 u8 *buffer, *dst;
701 u8 __iomem *src; 745 u8 __iomem *src;
702 int c, cnt = 0, err = 0; 746 int c, cnt = 0, err = 0;
@@ -761,9 +805,7 @@ static ssize_t
761fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 805fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
762{ 806{
763 unsigned long p = *ppos; 807 unsigned long p = *ppos;
764 struct inode *inode = file->f_path.dentry->d_inode; 808 struct fb_info *info = file_fb_info(file);
765 int fbidx = iminor(inode);
766 struct fb_info *info = registered_fb[fbidx];
767 u8 *buffer, *src; 809 u8 *buffer, *src;
768 u8 __iomem *dst; 810 u8 __iomem *dst;
769 int c, cnt = 0, err = 0; 811 int c, cnt = 0, err = 0;
@@ -1141,10 +1183,10 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
1141 1183
1142static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1184static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1143{ 1185{
1144 struct inode *inode = file->f_path.dentry->d_inode; 1186 struct fb_info *info = file_fb_info(file);
1145 int fbidx = iminor(inode);
1146 struct fb_info *info = registered_fb[fbidx];
1147 1187
1188 if (!info)
1189 return -ENODEV;
1148 return do_fb_ioctl(info, cmd, arg); 1190 return do_fb_ioctl(info, cmd, arg);
1149} 1191}
1150 1192
@@ -1265,12 +1307,13 @@ static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd,
1265static long fb_compat_ioctl(struct file *file, unsigned int cmd, 1307static long fb_compat_ioctl(struct file *file, unsigned int cmd,
1266 unsigned long arg) 1308 unsigned long arg)
1267{ 1309{
1268 struct inode *inode = file->f_path.dentry->d_inode; 1310 struct fb_info *info = file_fb_info(file);
1269 int fbidx = iminor(inode); 1311 struct fb_ops *fb;
1270 struct fb_info *info = registered_fb[fbidx];
1271 struct fb_ops *fb = info->fbops;
1272 long ret = -ENOIOCTLCMD; 1312 long ret = -ENOIOCTLCMD;
1273 1313
1314 if (!info)
1315 return -ENODEV;
1316 fb = info->fbops;
1274 switch(cmd) { 1317 switch(cmd) {
1275 case FBIOGET_VSCREENINFO: 1318 case FBIOGET_VSCREENINFO:
1276 case FBIOPUT_VSCREENINFO: 1319 case FBIOPUT_VSCREENINFO:
@@ -1303,16 +1346,18 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
1303static int 1346static int
1304fb_mmap(struct file *file, struct vm_area_struct * vma) 1347fb_mmap(struct file *file, struct vm_area_struct * vma)
1305{ 1348{
1306 int fbidx = iminor(file->f_path.dentry->d_inode); 1349 struct fb_info *info = file_fb_info(file);
1307 struct fb_info *info = registered_fb[fbidx]; 1350 struct fb_ops *fb;
1308 struct fb_ops *fb = info->fbops;
1309 unsigned long off; 1351 unsigned long off;
1310 unsigned long start; 1352 unsigned long start;
1311 u32 len; 1353 u32 len;
1312 1354
1355 if (!info)
1356 return -ENODEV;
1313 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) 1357 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1314 return -EINVAL; 1358 return -EINVAL;
1315 off = vma->vm_pgoff << PAGE_SHIFT; 1359 off = vma->vm_pgoff << PAGE_SHIFT;
1360 fb = info->fbops;
1316 if (!fb) 1361 if (!fb)
1317 return -ENODEV; 1362 return -ENODEV;
1318 mutex_lock(&info->mm_lock); 1363 mutex_lock(&info->mm_lock);
@@ -1361,14 +1406,16 @@ __releases(&info->lock)
1361 struct fb_info *info; 1406 struct fb_info *info;
1362 int res = 0; 1407 int res = 0;
1363 1408
1364 if (fbidx >= FB_MAX) 1409 info = get_fb_info(fbidx);
1365 return -ENODEV; 1410 if (!info) {
1366 info = registered_fb[fbidx];
1367 if (!info)
1368 request_module("fb%d", fbidx); 1411 request_module("fb%d", fbidx);
1369 info = registered_fb[fbidx]; 1412 info = get_fb_info(fbidx);
1370 if (!info) 1413 if (!info)
1371 return -ENODEV; 1414 return -ENODEV;
1415 }
1416 if (IS_ERR(info))
1417 return PTR_ERR(info);
1418
1372 mutex_lock(&info->lock); 1419 mutex_lock(&info->lock);
1373 if (!try_module_get(info->fbops->owner)) { 1420 if (!try_module_get(info->fbops->owner)) {
1374 res = -ENODEV; 1421 res = -ENODEV;
@@ -1386,6 +1433,8 @@ __releases(&info->lock)
1386#endif 1433#endif
1387out: 1434out:
1388 mutex_unlock(&info->lock); 1435 mutex_unlock(&info->lock);
1436 if (res)
1437 put_fb_info(info);
1389 return res; 1438 return res;
1390} 1439}
1391 1440
@@ -1401,6 +1450,7 @@ __releases(&info->lock)
1401 info->fbops->fb_release(info,1); 1450 info->fbops->fb_release(info,1);
1402 module_put(info->fbops->owner); 1451 module_put(info->fbops->owner);
1403 mutex_unlock(&info->lock); 1452 mutex_unlock(&info->lock);
1453 put_fb_info(info);
1404 return 0; 1454 return 0;
1405} 1455}
1406 1456
@@ -1487,8 +1537,10 @@ static bool fb_do_apertures_overlap(struct apertures_struct *gena,
1487 return false; 1537 return false;
1488} 1538}
1489 1539
1540static int do_unregister_framebuffer(struct fb_info *fb_info);
1541
1490#define VGA_FB_PHYS 0xA0000 1542#define VGA_FB_PHYS 0xA0000
1491void remove_conflicting_framebuffers(struct apertures_struct *a, 1543static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
1492 const char *name, bool primary) 1544 const char *name, bool primary)
1493{ 1545{
1494 int i; 1546 int i;
@@ -1510,43 +1562,32 @@ void remove_conflicting_framebuffers(struct apertures_struct *a,
1510 printk(KERN_INFO "fb: conflicting fb hw usage " 1562 printk(KERN_INFO "fb: conflicting fb hw usage "
1511 "%s vs %s - removing generic driver\n", 1563 "%s vs %s - removing generic driver\n",
1512 name, registered_fb[i]->fix.id); 1564 name, registered_fb[i]->fix.id);
1513 unregister_framebuffer(registered_fb[i]); 1565 do_unregister_framebuffer(registered_fb[i]);
1514 } 1566 }
1515 } 1567 }
1516} 1568}
1517EXPORT_SYMBOL(remove_conflicting_framebuffers);
1518 1569
1519/** 1570static int do_register_framebuffer(struct fb_info *fb_info)
1520 * register_framebuffer - registers a frame buffer device
1521 * @fb_info: frame buffer info structure
1522 *
1523 * Registers a frame buffer device @fb_info.
1524 *
1525 * Returns negative errno on error, or zero for success.
1526 *
1527 */
1528
1529int
1530register_framebuffer(struct fb_info *fb_info)
1531{ 1571{
1532 int i; 1572 int i;
1533 struct fb_event event; 1573 struct fb_event event;
1534 struct fb_videomode mode; 1574 struct fb_videomode mode;
1535 1575
1536 if (num_registered_fb == FB_MAX)
1537 return -ENXIO;
1538
1539 if (fb_check_foreignness(fb_info)) 1576 if (fb_check_foreignness(fb_info))
1540 return -ENOSYS; 1577 return -ENOSYS;
1541 1578
1542 remove_conflicting_framebuffers(fb_info->apertures, fb_info->fix.id, 1579 do_remove_conflicting_framebuffers(fb_info->apertures, fb_info->fix.id,
1543 fb_is_primary_device(fb_info)); 1580 fb_is_primary_device(fb_info));
1544 1581
1582 if (num_registered_fb == FB_MAX)
1583 return -ENXIO;
1584
1545 num_registered_fb++; 1585 num_registered_fb++;
1546 for (i = 0 ; i < FB_MAX; i++) 1586 for (i = 0 ; i < FB_MAX; i++)
1547 if (!registered_fb[i]) 1587 if (!registered_fb[i])
1548 break; 1588 break;
1549 fb_info->node = i; 1589 fb_info->node = i;
1590 atomic_set(&fb_info->count, 1);
1550 mutex_init(&fb_info->lock); 1591 mutex_init(&fb_info->lock);
1551 mutex_init(&fb_info->mm_lock); 1592 mutex_init(&fb_info->mm_lock);
1552 1593
@@ -1592,36 +1633,14 @@ register_framebuffer(struct fb_info *fb_info)
1592 return 0; 1633 return 0;
1593} 1634}
1594 1635
1595 1636static int do_unregister_framebuffer(struct fb_info *fb_info)
1596/**
1597 * unregister_framebuffer - releases a frame buffer device
1598 * @fb_info: frame buffer info structure
1599 *
1600 * Unregisters a frame buffer device @fb_info.
1601 *
1602 * Returns negative errno on error, or zero for success.
1603 *
1604 * This function will also notify the framebuffer console
1605 * to release the driver.
1606 *
1607 * This is meant to be called within a driver's module_exit()
1608 * function. If this is called outside module_exit(), ensure
1609 * that the driver implements fb_open() and fb_release() to
1610 * check that no processes are using the device.
1611 */
1612
1613int
1614unregister_framebuffer(struct fb_info *fb_info)
1615{ 1637{
1616 struct fb_event event; 1638 struct fb_event event;
1617 int i, ret = 0; 1639 int i, ret = 0;
1618 1640
1619 i = fb_info->node; 1641 i = fb_info->node;
1620 if (!registered_fb[i]) { 1642 if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
1621 ret = -EINVAL; 1643 return -EINVAL;
1622 goto done;
1623 }
1624
1625 1644
1626 if (!lock_fb_info(fb_info)) 1645 if (!lock_fb_info(fb_info))
1627 return -ENODEV; 1646 return -ENODEV;
@@ -1629,16 +1648,14 @@ unregister_framebuffer(struct fb_info *fb_info)
1629 ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event); 1648 ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
1630 unlock_fb_info(fb_info); 1649 unlock_fb_info(fb_info);
1631 1650
1632 if (ret) { 1651 if (ret)
1633 ret = -EINVAL; 1652 return -EINVAL;
1634 goto done;
1635 }
1636 1653
1637 if (fb_info->pixmap.addr && 1654 if (fb_info->pixmap.addr &&
1638 (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT)) 1655 (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
1639 kfree(fb_info->pixmap.addr); 1656 kfree(fb_info->pixmap.addr);
1640 fb_destroy_modelist(&fb_info->modelist); 1657 fb_destroy_modelist(&fb_info->modelist);
1641 registered_fb[i]=NULL; 1658 registered_fb[i] = NULL;
1642 num_registered_fb--; 1659 num_registered_fb--;
1643 fb_cleanup_device(fb_info); 1660 fb_cleanup_device(fb_info);
1644 device_destroy(fb_class, MKDEV(FB_MAJOR, i)); 1661 device_destroy(fb_class, MKDEV(FB_MAJOR, i));
@@ -1646,9 +1663,65 @@ unregister_framebuffer(struct fb_info *fb_info)
1646 fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event); 1663 fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
1647 1664
1648 /* this may free fb info */ 1665 /* this may free fb info */
1649 if (fb_info->fbops->fb_destroy) 1666 put_fb_info(fb_info);
1650 fb_info->fbops->fb_destroy(fb_info); 1667 return 0;
1651done: 1668}
1669
1670void remove_conflicting_framebuffers(struct apertures_struct *a,
1671 const char *name, bool primary)
1672{
1673 mutex_lock(&registration_lock);
1674 do_remove_conflicting_framebuffers(a, name, primary);
1675 mutex_unlock(&registration_lock);
1676}
1677EXPORT_SYMBOL(remove_conflicting_framebuffers);
1678
1679/**
1680 * register_framebuffer - registers a frame buffer device
1681 * @fb_info: frame buffer info structure
1682 *
1683 * Registers a frame buffer device @fb_info.
1684 *
1685 * Returns negative errno on error, or zero for success.
1686 *
1687 */
1688int
1689register_framebuffer(struct fb_info *fb_info)
1690{
1691 int ret;
1692
1693 mutex_lock(&registration_lock);
1694 ret = do_register_framebuffer(fb_info);
1695 mutex_unlock(&registration_lock);
1696
1697 return ret;
1698}
1699
1700/**
1701 * unregister_framebuffer - releases a frame buffer device
1702 * @fb_info: frame buffer info structure
1703 *
1704 * Unregisters a frame buffer device @fb_info.
1705 *
1706 * Returns negative errno on error, or zero for success.
1707 *
1708 * This function will also notify the framebuffer console
1709 * to release the driver.
1710 *
1711 * This is meant to be called within a driver's module_exit()
1712 * function. If this is called outside module_exit(), ensure
1713 * that the driver implements fb_open() and fb_release() to
1714 * check that no processes are using the device.
1715 */
1716int
1717unregister_framebuffer(struct fb_info *fb_info)
1718{
1719 int ret;
1720
1721 mutex_lock(&registration_lock);
1722 ret = do_unregister_framebuffer(fb_info);
1723 mutex_unlock(&registration_lock);
1724
1652 return ret; 1725 return ret;
1653} 1726}
1654 1727