brcm2708: update against latest rpi-3.10.y branch
[openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0144-vc_mem-tidy-up-debug-procfs-code.patch
1 From e9db9a1035224a30ebb6be44e760e57518d19533 Mon Sep 17 00:00:00 2001
2 From: Luke Diamand <luked@broadcom.com>
3 Date: Sat, 28 Dec 2013 07:39:51 +0000
4 Subject: [PATCH 144/174] vc_mem: tidy up debug procfs code
5
6 Remove commented-out procfs code, which was generating
7 a warning and no longer worked. Replace this with
8 equivalent debugfs entries.
9
10 Signed-off-by: Luke Diamand <luked@broadcom.com>
11 ---
12  arch/arm/mach-bcm2708/vc_mem.c | 119 +++++++++++++++++------------------------
13  1 file changed, 49 insertions(+), 70 deletions(-)
14
15 --- a/arch/arm/mach-bcm2708/vc_mem.c
16 +++ b/arch/arm/mach-bcm2708/vc_mem.c
17 @@ -19,7 +19,7 @@
18  #include <linux/cdev.h>
19  #include <linux/mm.h>
20  #include <linux/slab.h>
21 -#include <linux/proc_fs.h>
22 +#include <linux/debugfs.h>
23  #include <asm/uaccess.h>
24  #include <linux/dma-mapping.h>
25  
26 @@ -51,8 +51,9 @@ static struct class *vc_mem_class = NULL
27  static struct cdev vc_mem_cdev;
28  static int vc_mem_inited = 0;
29  
30 -// Proc entry
31 -static struct proc_dir_entry *vc_mem_proc_entry;
32 +#ifdef CONFIG_DEBUG_FS
33 +static struct dentry *vc_mem_debugfs_entry;
34 +#endif
35  
36  /*
37   * Videocore memory addresses and size
38 @@ -280,75 +281,60 @@ static const struct file_operations vc_m
39         .mmap = vc_mem_mmap,
40  };
41  
42 -/****************************************************************************
43 -*
44 -*   vc_mem_proc_read
45 -*
46 -***************************************************************************/
47 -
48 -static int
49 -vc_mem_proc_read(char *buf, char **start, off_t offset, int count, int *eof,
50 -                void *data)
51 +#ifdef CONFIG_DEBUG_FS
52 +static void vc_mem_debugfs_deinit(void)
53  {
54 -       char *p = buf;
55 -
56 -       (void) start;
57 -       (void) count;
58 -       (void) data;
59 -
60 -       if (offset > 0) {
61 -               *eof = 1;
62 -               return 0;
63 -       }
64 -       // Get the videocore memory size first
65 -       vc_mem_get_size();
66 -
67 -       p += sprintf(p, "Videocore memory:\n");
68 -       if (mm_vc_mem_phys_addr != 0)
69 -               p += sprintf(p, "   Physical address: 0x%p\n",
70 -                            (void *) mm_vc_mem_phys_addr);
71 -       else
72 -               p += sprintf(p, "   Physical address: 0x00000000\n");
73 -       p += sprintf(p, "   Length (bytes):   %u\n", mm_vc_mem_size);
74 -
75 -       *eof = 1;
76 -       return p - buf;
77 +       debugfs_remove_recursive(vc_mem_debugfs_entry);
78 +       vc_mem_debugfs_entry = NULL;
79  }
80  
81 -/****************************************************************************
82 -*
83 -*   vc_mem_proc_write
84 -*
85 -***************************************************************************/
86  
87 -static int
88 -vc_mem_proc_write(struct file *file, const char __user * buffer,
89 -                 unsigned long count, void *data)
90 +static int vc_mem_debugfs_init(
91 +       struct device *dev)
92  {
93 -       int rc = -EFAULT;
94 -       char input_str[10];
95 -
96 -       memset(input_str, 0, sizeof (input_str));
97 -
98 -       if (count > sizeof (input_str)) {
99 -               LOG_ERR("%s: input string length too long", __func__);
100 -               goto out;
101 -       }
102 -
103 -       if (copy_from_user(input_str, buffer, count - 1)) {
104 -               LOG_ERR("%s: failed to get input string", __func__);
105 -               goto out;
106 +       vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
107 +       if (!vc_mem_debugfs_entry) {
108 +               dev_warn(dev, "could not create debugfs entry\n");
109 +               return -EFAULT;
110 +       }
111 +
112 +       if (!debugfs_create_x32("vc_mem_phys_addr",
113 +                               0444,
114 +                               vc_mem_debugfs_entry,
115 +                               (u32 *)&mm_vc_mem_phys_addr)) {
116 +               dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
117 +                       __func__);
118 +               goto fail;
119 +       }
120 +
121 +       if (!debugfs_create_x32("vc_mem_size",
122 +                               0444,
123 +                               vc_mem_debugfs_entry,
124 +                               (u32 *)&mm_vc_mem_size)) {
125 +               dev_warn(dev, "%s:could not create vc_mem_size entry\n",
126 +                       __func__);
127 +               goto fail;
128 +       }
129 +
130 +       if (!debugfs_create_x32("vc_mem_base",
131 +                               0444,
132 +                               vc_mem_debugfs_entry,
133 +                               (u32 *)&mm_vc_mem_base)) {
134 +               dev_warn(dev, "%s:could not create vc_mem_base entry\n",
135 +                        __func__);
136 +               goto fail;
137         }
138  
139 -       if (strncmp(input_str, "connect", strlen("connect")) == 0) {
140 -               // Get the videocore memory size from the videocore
141 -               vc_mem_get_size();
142 -       }
143 +       return 0;
144  
145 -      out:
146 -       return rc;
147 +fail:
148 +       vc_mem_debugfs_deinit();
149 +       return -EFAULT;
150  }
151  
152 +#endif /* CONFIG_DEBUG_FS */
153 +
154 +
155  /****************************************************************************
156  *
157  *   vc_mem_init
158 @@ -398,21 +384,14 @@ vc_mem_init(void)
159                 goto out_class_destroy;
160         }
161  
162 -#if 0
163 -       vc_mem_proc_entry = create_proc_entry(DRIVER_NAME, 0444, NULL);
164 -       if (vc_mem_proc_entry == NULL) {
165 -               rc = -EFAULT;
166 -               LOG_ERR("%s: create_proc_entry failed", __func__);
167 -               goto out_device_destroy;
168 -       }
169 -       vc_mem_proc_entry->read_proc = vc_mem_proc_read;
170 -       vc_mem_proc_entry->write_proc = vc_mem_proc_write;
171 +#ifdef CONFIG_DEBUG_FS
172 +       /* don't fail if the debug entries cannot be created */
173 +       vc_mem_debugfs_init(dev);
174  #endif
175  
176         vc_mem_inited = 1;
177         return 0;
178  
179 -      out_device_destroy:
180         device_destroy(vc_mem_class, vc_mem_devnum);
181  
182        out_class_destroy:
183 @@ -441,8 +420,8 @@ vc_mem_exit(void)
184         LOG_DBG("%s: called", __func__);
185  
186         if (vc_mem_inited) {
187 -#if 0
188 -               remove_proc_entry(vc_mem_proc_entry->name, NULL);
189 +#if CONFIG_DEBUG_FS
190 +               vc_mem_debugfs_deinit();
191  #endif
192                 device_destroy(vc_mem_class, vc_mem_devnum);
193                 class_destroy(vc_mem_class);