aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-03-10 17:10:06 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-03-13 16:16:45 -0400
commit647416f9eefe7699754b01b9fc82758fde83248c (patch)
treefaa5376b3b2f37cf5ae4353b1d7a506a88c16454
parent5c67eeb6bf7eef062c835a64b501f3c926712fa5 (diff)
drm/i915: use simple attribute in debugfs routines
This replaces the manual read/write routines in debugfs with the common simple attribute helpers. Doing this gets rid of repeated copy/pasting of copy_from_user and value formatting code. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> [danvet: Squash in follow-up fix from Kees Cook to fix u64 divides on 32bit platforms.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c406
1 files changed, 104 insertions, 302 deletions
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index c92ae7ff4718..26487d18b023 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -866,76 +866,42 @@ static const struct file_operations i915_error_state_fops = {
866 .release = i915_error_state_release, 866 .release = i915_error_state_release,
867}; 867};
868 868
869static ssize_t 869static int
870i915_next_seqno_read(struct file *filp, 870i915_next_seqno_get(void *data, u64 *val)
871 char __user *ubuf,
872 size_t max,
873 loff_t *ppos)
874{ 871{
875 struct drm_device *dev = filp->private_data; 872 struct drm_device *dev = data;
876 drm_i915_private_t *dev_priv = dev->dev_private; 873 drm_i915_private_t *dev_priv = dev->dev_private;
877 char buf[80];
878 int len;
879 int ret; 874 int ret;
880 875
881 ret = mutex_lock_interruptible(&dev->struct_mutex); 876 ret = mutex_lock_interruptible(&dev->struct_mutex);
882 if (ret) 877 if (ret)
883 return ret; 878 return ret;
884 879
885 len = snprintf(buf, sizeof(buf), 880 *val = dev_priv->next_seqno;
886 "next_seqno : 0x%x\n",
887 dev_priv->next_seqno);
888
889 mutex_unlock(&dev->struct_mutex); 881 mutex_unlock(&dev->struct_mutex);
890 882
891 if (len > sizeof(buf)) 883 return 0;
892 len = sizeof(buf);
893
894 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
895} 884}
896 885
897static ssize_t 886static int
898i915_next_seqno_write(struct file *filp, 887i915_next_seqno_set(void *data, u64 val)
899 const char __user *ubuf, 888{
900 size_t cnt, 889 struct drm_device *dev = data;
901 loff_t *ppos)
902{
903 struct drm_device *dev = filp->private_data;
904 char buf[20];
905 u32 val = 1;
906 int ret; 890 int ret;
907 891
908 if (cnt > 0) {
909 if (cnt > sizeof(buf) - 1)
910 return -EINVAL;
911
912 if (copy_from_user(buf, ubuf, cnt))
913 return -EFAULT;
914 buf[cnt] = 0;
915
916 ret = kstrtouint(buf, 0, &val);
917 if (ret < 0)
918 return ret;
919 }
920
921 ret = mutex_lock_interruptible(&dev->struct_mutex); 892 ret = mutex_lock_interruptible(&dev->struct_mutex);
922 if (ret) 893 if (ret)
923 return ret; 894 return ret;
924 895
925 ret = i915_gem_set_seqno(dev, val); 896 ret = i915_gem_set_seqno(dev, val);
926
927 mutex_unlock(&dev->struct_mutex); 897 mutex_unlock(&dev->struct_mutex);
928 898
929 return ret ?: cnt; 899 return ret;
930} 900}
931 901
932static const struct file_operations i915_next_seqno_fops = { 902DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
933 .owner = THIS_MODULE, 903 i915_next_seqno_get, i915_next_seqno_set,
934 .open = simple_open, 904 "next_seqno : 0x%llx\n");
935 .read = i915_next_seqno_read,
936 .write = i915_next_seqno_write,
937 .llseek = default_llseek,
938};
939 905
940static int i915_rstdby_delays(struct seq_file *m, void *unused) 906static int i915_rstdby_delays(struct seq_file *m, void *unused)
941{ 907{
@@ -1697,105 +1663,51 @@ static int i915_dpio_info(struct seq_file *m, void *data)
1697 return 0; 1663 return 0;
1698} 1664}
1699 1665
1700static ssize_t 1666static int
1701i915_wedged_read(struct file *filp, 1667i915_wedged_get(void *data, u64 *val)
1702 char __user *ubuf,
1703 size_t max,
1704 loff_t *ppos)
1705{ 1668{
1706 struct drm_device *dev = filp->private_data; 1669 struct drm_device *dev = data;
1707 drm_i915_private_t *dev_priv = dev->dev_private; 1670 drm_i915_private_t *dev_priv = dev->dev_private;
1708 char buf[80];
1709 int len;
1710 1671
1711 len = snprintf(buf, sizeof(buf), 1672 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
1712 "wedged : %d\n",
1713 atomic_read(&dev_priv->gpu_error.reset_counter));
1714 1673
1715 if (len > sizeof(buf)) 1674 return 0;
1716 len = sizeof(buf);
1717
1718 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1719} 1675}
1720 1676
1721static ssize_t 1677static int
1722i915_wedged_write(struct file *filp, 1678i915_wedged_set(void *data, u64 val)
1723 const char __user *ubuf,
1724 size_t cnt,
1725 loff_t *ppos)
1726{ 1679{
1727 struct drm_device *dev = filp->private_data; 1680 struct drm_device *dev = data;
1728 char buf[20];
1729 int val = 1;
1730 1681
1731 if (cnt > 0) { 1682 DRM_INFO("Manually setting wedged to %llu\n", val);
1732 if (cnt > sizeof(buf) - 1)
1733 return -EINVAL;
1734
1735 if (copy_from_user(buf, ubuf, cnt))
1736 return -EFAULT;
1737 buf[cnt] = 0;
1738
1739 val = simple_strtoul(buf, NULL, 0);
1740 }
1741
1742 DRM_INFO("Manually setting wedged to %d\n", val);
1743 i915_handle_error(dev, val); 1683 i915_handle_error(dev, val);
1744 1684
1745 return cnt; 1685 return 0;
1746} 1686}
1747 1687
1748static const struct file_operations i915_wedged_fops = { 1688DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
1749 .owner = THIS_MODULE, 1689 i915_wedged_get, i915_wedged_set,
1750 .open = simple_open, 1690 "wedged : %llu\n");
1751 .read = i915_wedged_read,
1752 .write = i915_wedged_write,
1753 .llseek = default_llseek,
1754};
1755 1691
1756static ssize_t 1692static int
1757i915_ring_stop_read(struct file *filp, 1693i915_ring_stop_get(void *data, u64 *val)
1758 char __user *ubuf,
1759 size_t max,
1760 loff_t *ppos)
1761{ 1694{
1762 struct drm_device *dev = filp->private_data; 1695 struct drm_device *dev = data;
1763 drm_i915_private_t *dev_priv = dev->dev_private; 1696 drm_i915_private_t *dev_priv = dev->dev_private;
1764 char buf[20];
1765 int len;
1766 1697
1767 len = snprintf(buf, sizeof(buf), 1698 *val = dev_priv->gpu_error.stop_rings;
1768 "0x%08x\n", dev_priv->gpu_error.stop_rings);
1769 1699
1770 if (len > sizeof(buf)) 1700 return 0;
1771 len = sizeof(buf);
1772
1773 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1774} 1701}
1775 1702
1776static ssize_t 1703static int
1777i915_ring_stop_write(struct file *filp, 1704i915_ring_stop_set(void *data, u64 val)
1778 const char __user *ubuf,
1779 size_t cnt,
1780 loff_t *ppos)
1781{ 1705{
1782 struct drm_device *dev = filp->private_data; 1706 struct drm_device *dev = data;
1783 struct drm_i915_private *dev_priv = dev->dev_private; 1707 struct drm_i915_private *dev_priv = dev->dev_private;
1784 char buf[20]; 1708 int ret;
1785 int val = 0, ret;
1786
1787 if (cnt > 0) {
1788 if (cnt > sizeof(buf) - 1)
1789 return -EINVAL;
1790
1791 if (copy_from_user(buf, ubuf, cnt))
1792 return -EFAULT;
1793 buf[cnt] = 0;
1794
1795 val = simple_strtoul(buf, NULL, 0);
1796 }
1797 1709
1798 DRM_DEBUG_DRIVER("Stopping rings 0x%08x\n", val); 1710 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
1799 1711
1800 ret = mutex_lock_interruptible(&dev->struct_mutex); 1712 ret = mutex_lock_interruptible(&dev->struct_mutex);
1801 if (ret) 1713 if (ret)
@@ -1804,16 +1716,12 @@ i915_ring_stop_write(struct file *filp,
1804 dev_priv->gpu_error.stop_rings = val; 1716 dev_priv->gpu_error.stop_rings = val;
1805 mutex_unlock(&dev->struct_mutex); 1717 mutex_unlock(&dev->struct_mutex);
1806 1718
1807 return cnt; 1719 return 0;
1808} 1720}
1809 1721
1810static const struct file_operations i915_ring_stop_fops = { 1722DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
1811 .owner = THIS_MODULE, 1723 i915_ring_stop_get, i915_ring_stop_set,
1812 .open = simple_open, 1724 "0x%08llx\n");
1813 .read = i915_ring_stop_read,
1814 .write = i915_ring_stop_write,
1815 .llseek = default_llseek,
1816};
1817 1725
1818#define DROP_UNBOUND 0x1 1726#define DROP_UNBOUND 0x1
1819#define DROP_BOUND 0x2 1727#define DROP_BOUND 0x2
@@ -1823,46 +1731,23 @@ static const struct file_operations i915_ring_stop_fops = {
1823 DROP_BOUND | \ 1731 DROP_BOUND | \
1824 DROP_RETIRE | \ 1732 DROP_RETIRE | \
1825 DROP_ACTIVE) 1733 DROP_ACTIVE)
1826static ssize_t 1734static int
1827i915_drop_caches_read(struct file *filp, 1735i915_drop_caches_get(void *data, u64 *val)
1828 char __user *ubuf,
1829 size_t max,
1830 loff_t *ppos)
1831{ 1736{
1832 char buf[20]; 1737 *val = DROP_ALL;
1833 int len;
1834
1835 len = snprintf(buf, sizeof(buf), "0x%08x\n", DROP_ALL);
1836 if (len > sizeof(buf))
1837 len = sizeof(buf);
1838 1738
1839 return simple_read_from_buffer(ubuf, max, ppos, buf, len); 1739 return 0;
1840} 1740}
1841 1741
1842static ssize_t 1742static int
1843i915_drop_caches_write(struct file *filp, 1743i915_drop_caches_set(void *data, u64 val)
1844 const char __user *ubuf,
1845 size_t cnt,
1846 loff_t *ppos)
1847{ 1744{
1848 struct drm_device *dev = filp->private_data; 1745 struct drm_device *dev = data;
1849 struct drm_i915_private *dev_priv = dev->dev_private; 1746 struct drm_i915_private *dev_priv = dev->dev_private;
1850 struct drm_i915_gem_object *obj, *next; 1747 struct drm_i915_gem_object *obj, *next;
1851 char buf[20]; 1748 int ret;
1852 int val = 0, ret;
1853
1854 if (cnt > 0) {
1855 if (cnt > sizeof(buf) - 1)
1856 return -EINVAL;
1857
1858 if (copy_from_user(buf, ubuf, cnt))
1859 return -EFAULT;
1860 buf[cnt] = 0;
1861
1862 val = simple_strtoul(buf, NULL, 0);
1863 }
1864 1749
1865 DRM_DEBUG_DRIVER("Dropping caches: 0x%08x\n", val); 1750 DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
1866 1751
1867 /* No need to check and wait for gpu resets, only libdrm auto-restarts 1752 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1868 * on ioctls on -EAGAIN. */ 1753 * on ioctls on -EAGAIN. */
@@ -1900,27 +1785,19 @@ i915_drop_caches_write(struct file *filp,
1900unlock: 1785unlock:
1901 mutex_unlock(&dev->struct_mutex); 1786 mutex_unlock(&dev->struct_mutex);
1902 1787
1903 return ret ?: cnt; 1788 return ret;
1904} 1789}
1905 1790
1906static const struct file_operations i915_drop_caches_fops = { 1791DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
1907 .owner = THIS_MODULE, 1792 i915_drop_caches_get, i915_drop_caches_set,
1908 .open = simple_open, 1793 "0x%08llx\n");
1909 .read = i915_drop_caches_read,
1910 .write = i915_drop_caches_write,
1911 .llseek = default_llseek,
1912};
1913 1794
1914static ssize_t 1795static int
1915i915_max_freq_read(struct file *filp, 1796i915_max_freq_get(void *data, u64 *val)
1916 char __user *ubuf,
1917 size_t max,
1918 loff_t *ppos)
1919{ 1797{
1920 struct drm_device *dev = filp->private_data; 1798 struct drm_device *dev = data;
1921 drm_i915_private_t *dev_priv = dev->dev_private; 1799 drm_i915_private_t *dev_priv = dev->dev_private;
1922 char buf[80]; 1800 int ret;
1923 int len, ret;
1924 1801
1925 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1802 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1926 return -ENODEV; 1803 return -ENODEV;
@@ -1929,42 +1806,23 @@ i915_max_freq_read(struct file *filp,
1929 if (ret) 1806 if (ret)
1930 return ret; 1807 return ret;
1931 1808
1932 len = snprintf(buf, sizeof(buf), 1809 *val = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
1933 "max freq: %d\n", dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER);
1934 mutex_unlock(&dev_priv->rps.hw_lock); 1810 mutex_unlock(&dev_priv->rps.hw_lock);
1935 1811
1936 if (len > sizeof(buf)) 1812 return 0;
1937 len = sizeof(buf);
1938
1939 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
1940} 1813}
1941 1814
1942static ssize_t 1815static int
1943i915_max_freq_write(struct file *filp, 1816i915_max_freq_set(void *data, u64 val)
1944 const char __user *ubuf,
1945 size_t cnt,
1946 loff_t *ppos)
1947{ 1817{
1948 struct drm_device *dev = filp->private_data; 1818 struct drm_device *dev = data;
1949 struct drm_i915_private *dev_priv = dev->dev_private; 1819 struct drm_i915_private *dev_priv = dev->dev_private;
1950 char buf[20]; 1820 int ret;
1951 int val = 1, ret;
1952 1821
1953 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1822 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1954 return -ENODEV; 1823 return -ENODEV;
1955 1824
1956 if (cnt > 0) { 1825 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
1957 if (cnt > sizeof(buf) - 1)
1958 return -EINVAL;
1959
1960 if (copy_from_user(buf, ubuf, cnt))
1961 return -EFAULT;
1962 buf[cnt] = 0;
1963
1964 val = simple_strtoul(buf, NULL, 0);
1965 }
1966
1967 DRM_DEBUG_DRIVER("Manually setting max freq to %d\n", val);
1968 1826
1969 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock); 1827 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
1970 if (ret) 1828 if (ret)
@@ -1973,30 +1831,24 @@ i915_max_freq_write(struct file *filp,
1973 /* 1831 /*
1974 * Turbo will still be enabled, but won't go above the set value. 1832 * Turbo will still be enabled, but won't go above the set value.
1975 */ 1833 */
1976 dev_priv->rps.max_delay = val / GT_FREQUENCY_MULTIPLIER; 1834 do_div(val, GT_FREQUENCY_MULTIPLIER);
1977 1835 dev_priv->rps.max_delay = val;
1978 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER); 1836 gen6_set_rps(dev, val);
1979 mutex_unlock(&dev_priv->rps.hw_lock); 1837 mutex_unlock(&dev_priv->rps.hw_lock);
1980 1838
1981 return cnt; 1839 return 0;
1982} 1840}
1983 1841
1984static const struct file_operations i915_max_freq_fops = { 1842DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
1985 .owner = THIS_MODULE, 1843 i915_max_freq_get, i915_max_freq_set,
1986 .open = simple_open, 1844 "max freq: %llu\n");
1987 .read = i915_max_freq_read,
1988 .write = i915_max_freq_write,
1989 .llseek = default_llseek,
1990};
1991 1845
1992static ssize_t 1846static int
1993i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max, 1847i915_min_freq_get(void *data, u64 *val)
1994 loff_t *ppos)
1995{ 1848{
1996 struct drm_device *dev = filp->private_data; 1849 struct drm_device *dev = data;
1997 drm_i915_private_t *dev_priv = dev->dev_private; 1850 drm_i915_private_t *dev_priv = dev->dev_private;
1998 char buf[80]; 1851 int ret;
1999 int len, ret;
2000 1852
2001 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1853 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2002 return -ENODEV; 1854 return -ENODEV;
@@ -2005,40 +1857,23 @@ i915_min_freq_read(struct file *filp, char __user *ubuf, size_t max,
2005 if (ret) 1857 if (ret)
2006 return ret; 1858 return ret;
2007 1859
2008 len = snprintf(buf, sizeof(buf), 1860 *val = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
2009 "min freq: %d\n", dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER);
2010 mutex_unlock(&dev_priv->rps.hw_lock); 1861 mutex_unlock(&dev_priv->rps.hw_lock);
2011 1862
2012 if (len > sizeof(buf)) 1863 return 0;
2013 len = sizeof(buf);
2014
2015 return simple_read_from_buffer(ubuf, max, ppos, buf, len);
2016} 1864}
2017 1865
2018static ssize_t 1866static int
2019i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt, 1867i915_min_freq_set(void *data, u64 val)
2020 loff_t *ppos)
2021{ 1868{
2022 struct drm_device *dev = filp->private_data; 1869 struct drm_device *dev = data;
2023 struct drm_i915_private *dev_priv = dev->dev_private; 1870 struct drm_i915_private *dev_priv = dev->dev_private;
2024 char buf[20]; 1871 int ret;
2025 int val = 1, ret;
2026 1872
2027 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1873 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2028 return -ENODEV; 1874 return -ENODEV;
2029 1875
2030 if (cnt > 0) { 1876 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
2031 if (cnt > sizeof(buf) - 1)
2032 return -EINVAL;
2033
2034 if (copy_from_user(buf, ubuf, cnt))
2035 return -EFAULT;
2036 buf[cnt] = 0;
2037
2038 val = simple_strtoul(buf, NULL, 0);
2039 }
2040
2041 DRM_DEBUG_DRIVER("Manually setting min freq to %d\n", val);
2042 1877
2043 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock); 1878 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
2044 if (ret) 1879 if (ret)
@@ -2047,33 +1882,25 @@ i915_min_freq_write(struct file *filp, const char __user *ubuf, size_t cnt,
2047 /* 1882 /*
2048 * Turbo will still be enabled, but won't go below the set value. 1883 * Turbo will still be enabled, but won't go below the set value.
2049 */ 1884 */
2050 dev_priv->rps.min_delay = val / GT_FREQUENCY_MULTIPLIER; 1885 do_div(val, GT_FREQUENCY_MULTIPLIER);
2051 1886 dev_priv->rps.min_delay = val;
2052 gen6_set_rps(dev, val / GT_FREQUENCY_MULTIPLIER); 1887 gen6_set_rps(dev, val);
2053 mutex_unlock(&dev_priv->rps.hw_lock); 1888 mutex_unlock(&dev_priv->rps.hw_lock);
2054 1889
2055 return cnt; 1890 return 0;
2056} 1891}
2057 1892
2058static const struct file_operations i915_min_freq_fops = { 1893DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
2059 .owner = THIS_MODULE, 1894 i915_min_freq_get, i915_min_freq_set,
2060 .open = simple_open, 1895 "min freq: %llu\n");
2061 .read = i915_min_freq_read,
2062 .write = i915_min_freq_write,
2063 .llseek = default_llseek,
2064};
2065 1896
2066static ssize_t 1897static int
2067i915_cache_sharing_read(struct file *filp, 1898i915_cache_sharing_get(void *data, u64 *val)
2068 char __user *ubuf,
2069 size_t max,
2070 loff_t *ppos)
2071{ 1899{
2072 struct drm_device *dev = filp->private_data; 1900 struct drm_device *dev = data;
2073 drm_i915_private_t *dev_priv = dev->dev_private; 1901 drm_i915_private_t *dev_priv = dev->dev_private;
2074 char buf[80];
2075 u32 snpcr; 1902 u32 snpcr;
2076 int len, ret; 1903 int ret;
2077 1904
2078 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1905 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2079 return -ENODEV; 1906 return -ENODEV;
@@ -2085,46 +1912,25 @@ i915_cache_sharing_read(struct file *filp,
2085 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); 1912 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2086 mutex_unlock(&dev_priv->dev->struct_mutex); 1913 mutex_unlock(&dev_priv->dev->struct_mutex);
2087 1914
2088 len = snprintf(buf, sizeof(buf), 1915 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
2089 "%d\n", (snpcr & GEN6_MBC_SNPCR_MASK) >>
2090 GEN6_MBC_SNPCR_SHIFT);
2091
2092 if (len > sizeof(buf))
2093 len = sizeof(buf);
2094 1916
2095 return simple_read_from_buffer(ubuf, max, ppos, buf, len); 1917 return 0;
2096} 1918}
2097 1919
2098static ssize_t 1920static int
2099i915_cache_sharing_write(struct file *filp, 1921i915_cache_sharing_set(void *data, u64 val)
2100 const char __user *ubuf,
2101 size_t cnt,
2102 loff_t *ppos)
2103{ 1922{
2104 struct drm_device *dev = filp->private_data; 1923 struct drm_device *dev = data;
2105 struct drm_i915_private *dev_priv = dev->dev_private; 1924 struct drm_i915_private *dev_priv = dev->dev_private;
2106 char buf[20];
2107 u32 snpcr; 1925 u32 snpcr;
2108 int val = 1;
2109 1926
2110 if (!(IS_GEN6(dev) || IS_GEN7(dev))) 1927 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2111 return -ENODEV; 1928 return -ENODEV;
2112 1929
2113 if (cnt > 0) { 1930 if (val > 3)
2114 if (cnt > sizeof(buf) - 1)
2115 return -EINVAL;
2116
2117 if (copy_from_user(buf, ubuf, cnt))
2118 return -EFAULT;
2119 buf[cnt] = 0;
2120
2121 val = simple_strtoul(buf, NULL, 0);
2122 }
2123
2124 if (val < 0 || val > 3)
2125 return -EINVAL; 1931 return -EINVAL;
2126 1932
2127 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %d\n", val); 1933 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
2128 1934
2129 /* Update the cache sharing policy here as well */ 1935 /* Update the cache sharing policy here as well */
2130 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); 1936 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
@@ -2132,16 +1938,12 @@ i915_cache_sharing_write(struct file *filp,
2132 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT); 1938 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2133 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); 1939 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2134 1940
2135 return cnt; 1941 return 0;
2136} 1942}
2137 1943
2138static const struct file_operations i915_cache_sharing_fops = { 1944DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
2139 .owner = THIS_MODULE, 1945 i915_cache_sharing_get, i915_cache_sharing_set,
2140 .open = simple_open, 1946 "%llu\n");
2141 .read = i915_cache_sharing_read,
2142 .write = i915_cache_sharing_write,
2143 .llseek = default_llseek,
2144};
2145 1947
2146/* As the drm_debugfs_init() routines are called before dev->dev_private is 1948/* As the drm_debugfs_init() routines are called before dev->dev_private is
2147 * allocated we need to hook into the minor for release. */ 1949 * allocated we need to hook into the minor for release. */