linux-3.10-proc.diff 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. diff -Nur common/lib/modules/fglrx/build_mod/drmP.h common-r1/lib/modules/fglrx/build_mod/drmP.h
  2. --- common/lib/modules/fglrx/build_mod/drmP.h 2013-05-15 09:26:23.555752577 +0300
  3. +++ common-r1/lib/modules/fglrx/build_mod/drmP.h 2013-05-16 10:39:17.496212055 +0300
  4. @@ -901,10 +901,6 @@
  5. int DRM(stub_unregister)(int minor);
  6. /* Proc support (drm_proc.h) */
  7. -extern struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev,
  8. - int minor,
  9. - struct proc_dir_entry *root,
  10. - struct proc_dir_entry **dev_root);
  11. extern int DRM(proc_cleanup)(int minor,
  12. struct proc_dir_entry *root,
  13. struct proc_dir_entry *dev_root);
  14. diff -Nur common/lib/modules/fglrx/build_mod/drm_proc.h common-r1/lib/modules/fglrx/build_mod/drm_proc.h
  15. --- common/lib/modules/fglrx/build_mod/drm_proc.h 2013-05-15 09:26:23.555752577 +0300
  16. +++ common-r1/lib/modules/fglrx/build_mod/drm_proc.h 2013-05-19 02:16:16.584406160 +0300
  17. @@ -75,61 +75,6 @@
  18. #define DRM_PROC_ENTRIES (sizeof(DRM(proc_list))/sizeof(DRM(proc_list)[0]))
  19. /**
  20. - * Initialize the DRI proc filesystem for a device.
  21. - *
  22. - * \param dev DRM device.
  23. - * \param minor device minor number.
  24. - * \param root DRI proc dir entry.
  25. - * \param dev_root resulting DRI device proc dir entry.
  26. - * \return root entry pointer on success, or NULL on failure.
  27. - *
  28. - * Create the DRI proc root entry "/proc/ati", the device proc root entry
  29. - * "/proc/ati/%minor%/", and each entry in proc_list as
  30. - * "/proc/ati/%minor%/%name%".
  31. - */
  32. -struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev, int minor,
  33. - struct proc_dir_entry *root,
  34. - struct proc_dir_entry **dev_root)
  35. -{
  36. - struct proc_dir_entry *ent;
  37. - int i, j;
  38. - char name[64];
  39. -
  40. - if (!minor) root = create_proc_entry("dri", S_IFDIR, NULL);
  41. - if (!root) {
  42. - DRM_ERROR("Cannot create /proc/ati\n");
  43. - return NULL;
  44. - }
  45. -
  46. - sprintf(name, "%d", minor);
  47. - *dev_root = create_proc_entry(name, S_IFDIR, root);
  48. - if (!*dev_root) {
  49. - DRM_ERROR("Cannot create /proc/ati/%s\n", name);
  50. - return NULL;
  51. - }
  52. -
  53. - for (i = 0; i < DRM_PROC_ENTRIES; i++) {
  54. - ent = create_proc_entry(DRM(proc_list)[i].name,
  55. - S_IFREG|S_IRUGO, *dev_root);
  56. - if (!ent) {
  57. - DRM_ERROR("Cannot create /proc/ati/%s/%s\n",
  58. - name, DRM(proc_list)[i].name);
  59. - for (j = 0; j < i; j++)
  60. - remove_proc_entry(DRM(proc_list)[i].name,
  61. - *dev_root);
  62. - remove_proc_entry(name, root);
  63. - if (!minor) remove_proc_entry("dri", NULL);
  64. - return NULL;
  65. - }
  66. - ent->read_proc = DRM(proc_list)[i].f;
  67. - ent->data = dev;
  68. - }
  69. -
  70. - return root;
  71. -}
  72. -
  73. -
  74. -/**
  75. * Cleanup the proc filesystem resources.
  76. *
  77. * \param minor device minor number.
  78. diff -Nur common/lib/modules/fglrx/build_mod/firegl_public.c common-r1/lib/modules/fglrx/build_mod/firegl_public.c
  79. --- common/lib/modules/fglrx/build_mod/firegl_public.c 2013-05-15 09:26:23.545752925 +0300
  80. +++ common-r1/lib/modules/fglrx/build_mod/firegl_public.c 2013-05-19 03:07:10.236552522 +0300
  81. @@ -583,6 +583,202 @@
  82. { "NULL", NULL, NULL} // Terminate List!!!
  83. };
  84. +
  85. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
  86. +typedef int (read_proc_t)(char *page, char **start, off_t off, int count, int *eof, void *data);
  87. +typedef int (write_proc_t)(struct file *file, const char __user *buffer, unsigned long count, void *data);
  88. +#else
  89. +#define PDE_DATA(inode) (PDE((inode))->data)
  90. +#endif
  91. +
  92. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
  93. +typedef struct {
  94. + read_proc_t *read_func;
  95. + write_proc_t *write_func;
  96. + void *data;
  97. +} gentoo_proc_wrapper_t;
  98. +
  99. +#define GENTOO_PROC_WRAPPER_OVERFLOW_MAGIC 939750305
  100. +
  101. +static ssize_t gentoo_proc_wrapper_read (struct file *myfile, char __user *buffer, size_t count, loff_t *offset) {
  102. + int is_eof=0, retval;
  103. + char *start, *usebuffer=NULL;
  104. + gentoo_proc_wrapper_t* wrapper_data=(gentoo_proc_wrapper_t*)(myfile->private_data);
  105. + if (PAGE_SIZE<*offset) {
  106. + printk(KERN_ERR "Trying to read beyond 4k on proc\n");
  107. + return -EIO;
  108. + }
  109. + //printk(KERN_NOTICE " call with: dev %p, func %p\n", wrapper_data->data, wrapper_data->read_func);
  110. +
  111. + usebuffer=kmalloc(2*PAGE_SIZE, GFP_KERNEL);
  112. + if (!usebuffer)
  113. + return -ENOMEM;
  114. + ((u32*)usebuffer)[1024]=GENTOO_PROC_WRAPPER_OVERFLOW_MAGIC;
  115. +
  116. + retval=wrapper_data->read_func(usebuffer, &start, *offset, count, &is_eof, wrapper_data->data);
  117. +
  118. + BUG_ON(GENTOO_PROC_WRAPPER_OVERFLOW_MAGIC != ((u32*)usebuffer)[1024]);
  119. +
  120. + if (0 > retval)
  121. + {
  122. + printk(KERN_ERR "Proc read failed with %d", retval);
  123. + goto out;
  124. + }
  125. +
  126. + if (copy_to_user(buffer, start, retval)) {
  127. + printk(KERN_NOTICE "copy to user failed in amd drivers proc code\n");
  128. + retval=-EFAULT;
  129. + goto out;
  130. + }
  131. + *offset+=retval;
  132. +
  133. +out:
  134. + if (usebuffer)
  135. + kfree(usebuffer);
  136. + return retval;
  137. +}
  138. +static ssize_t gentoo_proc_wrapper_write (struct file *myfile, const char __user *buffer, size_t count, loff_t *offset) {
  139. + gentoo_proc_wrapper_t* wrapper_data=(gentoo_proc_wrapper_t*)(myfile->private_data);
  140. + int retval=0;
  141. + void *usebuffer=NULL;
  142. +
  143. + BUG_ON(*offset);
  144. + if (!wrapper_data->write_func)
  145. + return -EPERM;
  146. +
  147. + usebuffer=kmalloc(count, GFP_KERNEL);
  148. + if (!usebuffer)
  149. + return -ENOMEM;
  150. + if (copy_from_user(usebuffer, buffer, count)) {
  151. + printk(KERN_NOTICE "copy from user failed in amd drivers proc code\n");
  152. + retval=-EFAULT;
  153. + goto out;
  154. + }
  155. +
  156. + retval=wrapper_data->write_func(myfile, buffer, count, wrapper_data->data);
  157. + *offset+=retval;
  158. +out:
  159. + if (usebuffer)
  160. + kfree(usebuffer);
  161. + return retval;
  162. +}
  163. +static int gentoo_proc_wrapper_open(struct inode *myinode, struct file *myfile) {
  164. + myfile->private_data=PDE_DATA(myinode);
  165. + return generic_file_open(myinode, myfile);
  166. +}
  167. +struct file_operations gentoo_proc_fops = {
  168. + .read=gentoo_proc_wrapper_read,
  169. + .write=gentoo_proc_wrapper_write,
  170. + .open=gentoo_proc_wrapper_open,
  171. +};
  172. +
  173. +static void *gentoo_proc_wrapper_data(read_proc_t *reader, write_proc_t *writer, void *mydata) {
  174. + gentoo_proc_wrapper_t *retval=kmalloc(sizeof(gentoo_proc_wrapper_t), GFP_KERNEL);
  175. + if (!retval)
  176. + return retval;
  177. + retval->read_func=reader;
  178. + retval->write_func=writer;
  179. + retval->data=mydata;
  180. + return retval;
  181. +}
  182. +
  183. +static struct proc_dir_entry *firegl_proc_init( device_t *dev,
  184. + int minor,
  185. + struct proc_dir_entry *root,
  186. + struct proc_dir_entry **dev_root,
  187. + kcl_proc_list_t *proc_list ) // proc_list must be terminated!
  188. +{
  189. + struct proc_dir_entry *ent;
  190. + char name[64];
  191. + kcl_proc_list_t *list = proc_list;
  192. + void *tempdata;
  193. + KCL_DEBUG1(FN_FIREGL_PROC, "minor %d, proc_list 0x%08lx\n", minor, (unsigned long)proc_list);
  194. + if (!minor)
  195. + {
  196. + root = proc_mkdir("ati", NULL);
  197. + }
  198. +
  199. + if (!root)
  200. + {
  201. + KCL_DEBUG_ERROR("Cannot create /proc/ati\n");
  202. + return NULL;
  203. + }
  204. +
  205. + if (minor == 0)
  206. + {
  207. + // Global major debice number entry
  208. + tempdata=gentoo_proc_wrapper_data((read_proc_t*)firegl_major_proc_read, NULL, NULL);
  209. + if (!tempdata)
  210. + return NULL;
  211. + ent = proc_create_data("major", S_IFREG|S_IRUGO, root, &gentoo_proc_fops, tempdata);
  212. + if (!ent)
  213. + {
  214. + remove_proc_entry("ati", NULL);
  215. + KCL_DEBUG_ERROR("Cannot create /proc/ati/major\n");
  216. + return NULL;
  217. + }
  218. + }
  219. +
  220. + sprintf(name, "%d", minor);
  221. + *dev_root = proc_mkdir(name, root);
  222. + if (!*dev_root) {
  223. + remove_proc_entry("major", root);
  224. + remove_proc_entry("ati", NULL);
  225. + KCL_DEBUG_ERROR("Cannot create /proc/ati/%s\n", name);
  226. + return NULL;
  227. + }
  228. +
  229. + while (list->f || list->fops)
  230. + {
  231. + struct file_operations *my_fops = &gentoo_proc_fops;
  232. + if (list->fops)
  233. + {
  234. + my_fops = (struct file_operations*)list->fops;
  235. + tempdata=(dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev);
  236. + }
  237. + else {
  238. + BUG_ON(!list->f);
  239. + tempdata=gentoo_proc_wrapper_data((read_proc_t*)list->f, NULL, (dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev) );
  240. + if (!tempdata)
  241. + return NULL;
  242. + }
  243. + //printk(KERN_NOTICE "name %s, dev %p, func %p, data %p\n", list->name, (dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev), list->f, tempdata);
  244. + ent = proc_create_data(list->name, S_IFREG|S_IRUGO, *dev_root, my_fops, tempdata);
  245. +
  246. + if (!ent)
  247. + {
  248. + KCL_DEBUG_ERROR("Cannot create /proc/ati/%s/%s\n", name, list->name);
  249. + while (proc_list != list)
  250. + {
  251. + remove_proc_entry(proc_list->name, *dev_root);
  252. + proc_list++;
  253. + }
  254. + remove_proc_entry(name, root);
  255. + if (!minor)
  256. + {
  257. + remove_proc_entry("major", root);
  258. + remove_proc_entry("ati", NULL);
  259. + }
  260. + return NULL;
  261. + }
  262. +
  263. + list++;
  264. + }
  265. +
  266. + if (minor == 0)
  267. + {
  268. + // Global debug entry, only create it once
  269. + tempdata=gentoo_proc_wrapper_data((read_proc_t*)firegl_debug_proc_read_wrap, (write_proc_t*)firegl_debug_proc_write_wrap, dev);
  270. + if (!tempdata)
  271. + return NULL;
  272. + ent=proc_create_data("debug", S_IFREG|S_IRUGO, root, &gentoo_proc_fops, tempdata);
  273. + if (!ent)
  274. + return NULL;
  275. + }
  276. +
  277. + return root;
  278. +}
  279. +#else
  280. static struct proc_dir_entry *firegl_proc_init( device_t *dev,
  281. int minor,
  282. struct proc_dir_entry *root,
  283. @@ -677,6 +873,7 @@
  284. return root;
  285. }
  286. +#endif
  287. static int firegl_proc_cleanup( int minor,
  288. struct proc_dir_entry *root,