Advertisement
Guest User

patchnv319.32_3.10

a guest
Jul 6th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.41 KB | None | 0 0
  1. --- kernel/nv-i2c.c 2013-06-20 00:50:51.000000000 +0400
  2. +++ kernel/nv-i2c.c 2013-07-06 17:54:03.000000000 +0400
  3. @@ -311,8 +311,6 @@
  4. BOOL NV_API_CALL nv_i2c_del_adapter(nv_state_t *nv, void *data)
  5. {
  6. struct i2c_adapter *pI2cAdapter = (struct i2c_adapter *)data;
  7. - int osstatus = 0;
  8. - BOOL wasReleased = FALSE;
  9.  
  10. #if defined(KERNEL_2_4)
  11. if (!NV_WEAK_SYMBOL_PRESENT(i2c_add_adapter))
  12. @@ -324,15 +322,10 @@
  13. if (!pI2cAdapter) return FALSE;
  14.  
  15. // attempt release with the OS
  16. - osstatus = i2c_del_adapter(pI2cAdapter);
  17. + i2c_del_adapter(pI2cAdapter);
  18. + os_free_mem(pI2cAdapter);
  19.  
  20. - if (!osstatus)
  21. - {
  22. - os_free_mem(pI2cAdapter);
  23. - wasReleased = TRUE;
  24. - }
  25. -
  26. - return wasReleased;
  27. + return TRUE;
  28. }
  29.  
  30. #else // (defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE))
  31. --- kernel/nv-procfs.c 2013-06-20 00:50:52.000000000 +0400
  32. +++ kernel/nv-procfs.c 2013-07-06 17:54:33.000000000 +0400
  33. @@ -60,60 +60,41 @@
  34. __entry; \
  35. })
  36.  
  37. -#define NV_CREATE_PROC_FILE(name,parent,__read_proc, \
  38. - __write_proc,__fops,__data) \
  39. - ({ \
  40. - struct proc_dir_entry *__entry; \
  41. - int __mode = (S_IFREG | S_IRUGO); \
  42. - if ((NvUPtr)(__write_proc) != 0) \
  43. - __mode |= S_IWUSR; \
  44. - __entry = NV_CREATE_PROC_ENTRY(name, __mode, parent); \
  45. - if (__entry != NULL) \
  46. - { \
  47. - if ((NvUPtr)(__read_proc) != 0) \
  48. - __entry->read_proc = (__read_proc); \
  49. - if ((NvUPtr)(__write_proc) != 0) \
  50. - { \
  51. - __entry->write_proc = (__write_proc); \
  52. - __entry->proc_fops = (__fops); \
  53. - } \
  54. - __entry->data = (__data); \
  55. - } \
  56. - __entry; \
  57. - })
  58. +#define NV_PROC_RW (S_IFREG|S_IRUGO|S_IWUSR)
  59. +#define NV_PROC_RO (S_IFREG|S_IRUGO)
  60.  
  61. #define NV_CREATE_PROC_DIR(name,parent) \
  62. ({ \
  63. struct proc_dir_entry *__entry; \
  64. int __mode = (S_IFDIR | S_IRUGO | S_IXUGO); \
  65. - __entry = NV_CREATE_PROC_ENTRY(name, __mode, parent); \
  66. + __entry = proc_mkdir_mode(name, __mode, parent); \
  67. __entry; \
  68. })
  69.  
  70. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,9,255)
  71. +static inline void *PDE_DATA(const struct inode *inode) {
  72. + return PDE(inode)->data;
  73. +}
  74. +#endif
  75. +
  76. #define NV_PROC_WRITE_BUFFER_SIZE (64 * RM_PAGE_SIZE)
  77.  
  78. static int
  79. -nv_procfs_read_gpu_info(
  80. - char *page,
  81. - char **start,
  82. - off_t off,
  83. - int count,
  84. - int *eof,
  85. - void *data
  86. +nv_procfs_show_gpu_info(
  87. + struct seq_file *m,
  88. + void *v
  89. )
  90. {
  91. - nv_state_t *nv = data;
  92. + nv_state_t *nv = m->private;
  93. nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
  94. struct pci_dev *dev = nvl->dev;
  95. char *type, *fmt, tmpstr[NV_DEVICE_NAME_LENGTH];
  96. - int len = 0, status;
  97. + int status;
  98. NvU8 *uuid;
  99. NvU32 vbios_rev1, vbios_rev2, vbios_rev3, vbios_rev4, vbios_rev5;
  100. NvU32 fpga_rev1, fpga_rev2, fpga_rev3;
  101. nv_stack_t *sp = NULL;
  102.  
  103. - *eof = 1;
  104. -
  105. NV_KMEM_CACHE_ALLOC_STACK(sp);
  106. if (sp == NULL)
  107. {
  108. @@ -134,31 +115,31 @@
  109. if (rm_get_device_name(sp, nv, dev->device, dev->subsystem_vendor,
  110. dev->subsystem_device, NV_DEVICE_NAME_LENGTH,
  111. tmpstr) != RM_OK)
  112. - {
  113. + {
  114. strcpy (tmpstr, "Unknown");
  115. }
  116. }
  117.  
  118. - len += sprintf(page+len, "Model: \t\t %s\n", tmpstr);
  119. - len += sprintf(page+len, "IRQ: \t\t %d\n", nv->interrupt_line);
  120. + seq_printf(m, "Model: \t\t %s\n", tmpstr);
  121. + seq_printf(m, "IRQ: \t\t %d\n", nv->interrupt_line);
  122.  
  123. if (NV_IS_GVI_DEVICE(nv))
  124. {
  125. status = rm_gvi_get_firmware_version(sp, nv, &fpga_rev1, &fpga_rev2,
  126. &fpga_rev3);
  127. if (status != RM_OK)
  128. - len += sprintf(page+len, "Firmware: \t ????.??.??\n");
  129. + seq_printf(m, "Firmware: \t ????.??.??\n");
  130. else
  131. {
  132. fmt = "Firmware: \t %x.%x.%x\n";
  133. - len += sprintf(page+len, fmt, fpga_rev1, fpga_rev2, fpga_rev3);
  134. + seq_printf(m, fmt, fpga_rev1, fpga_rev2, fpga_rev3);
  135. }
  136. }
  137. else
  138. {
  139. if (rm_get_gpu_uuid(sp, nv, &uuid, NULL) == RM_OK)
  140. {
  141. - len += sprintf(page+len, "GPU UUID: \t %s\n", (char *)uuid);
  142. + seq_printf(m, "GPU UUID: \t %s\n", (char *)uuid);
  143. os_free_mem(uuid);
  144. }
  145.  
  146. @@ -166,12 +147,12 @@
  147. &vbios_rev3, &vbios_rev4,
  148. &vbios_rev5) != RM_OK)
  149. {
  150. - len += sprintf(page+len, "Video BIOS: \t ??.??.??.??.??\n");
  151. + seq_printf(m, "Video BIOS: \t ??.??.??.??.??\n");
  152. }
  153. else
  154. {
  155. fmt = "Video BIOS: \t %02x.%02x.%02x.%02x.%02x\n";
  156. - len += sprintf(page+len, fmt, vbios_rev1, vbios_rev2, vbios_rev3,
  157. + seq_printf(m, fmt, vbios_rev1, vbios_rev2, vbios_rev3,
  158. vbios_rev4, vbios_rev5);
  159. }
  160. }
  161. @@ -180,12 +161,12 @@
  162. type = "PCIe";
  163. else
  164. type = "PCI";
  165. - len += sprintf(page+len, "Bus Type: \t %s\n", type);
  166. + seq_printf(m, "Bus Type: \t %s\n", type);
  167.  
  168. - len += sprintf(page+len, "DMA Size: \t %d bits\n",
  169. + seq_printf(m, "DMA Size: \t %d bits\n",
  170. nv_count_bits(dev->dma_mask));
  171. - len += sprintf(page+len, "DMA Mask: \t 0x%llx\n", dev->dma_mask);
  172. - len += sprintf(page+len, "Bus Location: \t %04x:%02x.%02x.%x\n",
  173. + seq_printf(m, "DMA Mask: \t 0x%llx\n", dev->dma_mask);
  174. + seq_printf(m, "Bus Location: \t %04x:%02x.%02x.%x\n",
  175. nv->domain, nv->bus, nv->slot, PCI_FUNC(dev->devfn));
  176. #if defined(DEBUG)
  177. do
  178. @@ -193,7 +174,7 @@
  179. int j;
  180. for (j = 0; j < NV_GPU_NUM_BARS; j++)
  181. {
  182. - len += sprintf(page+len, "BAR%u: \t\t 0x%llx (%lluMB)\n",
  183. + seq_printf(m, "BAR%u: \t\t 0x%llx (%lluMB)\n",
  184. j, nv->bars[j].address, (nv->bars[j].size >> 20));
  185. }
  186. } while (0);
  187. @@ -201,26 +182,120 @@
  188.  
  189. NV_KMEM_CACHE_FREE_STACK(sp);
  190.  
  191. - return len;
  192. + return 0;
  193. }
  194.  
  195. static int
  196. -nv_procfs_read_version(
  197. - char *page,
  198. - char **start,
  199. - off_t off,
  200. - int count,
  201. - int *eof,
  202. - void *data
  203. +nv_procfs_open_gpu_info(
  204. + struct inode *inode,
  205. + struct file *file
  206. +)
  207. +{
  208. + return single_open(file, nv_procfs_show_gpu_info, PDE_DATA(inode));
  209. +}
  210. +
  211. +static const struct file_operations nv_procfs_gpu_info_fops = {
  212. + .owner = THIS_MODULE,
  213. + .open = nv_procfs_open_gpu_info,
  214. + .read = seq_read,
  215. + .llseek = seq_lseek,
  216. + .release = single_release,
  217. +};
  218. +
  219. +static int
  220. +nv_procfs_show_version(
  221. + struct seq_file *m,
  222. + void *v
  223. +)
  224. +{
  225. + seq_printf(m, "NVRM version: %s\n", pNVRM_ID);
  226. + seq_printf(m, "GCC version: %s\n", NV_COMPILER);
  227. +
  228. + return 0;
  229. +}
  230. +
  231. +static int
  232. +nv_procfs_open_version(
  233. + struct inode *inode,
  234. + struct file *file
  235. +)
  236. +{
  237. + return single_open(file, nv_procfs_show_version, NULL);
  238. +}
  239. +
  240. +static const struct file_operations nv_procfs_version_fops = {
  241. + .owner = THIS_MODULE,
  242. + .open = nv_procfs_open_version,
  243. + .read = seq_read,
  244. + .llseek = seq_lseek,
  245. + .release = single_release,
  246. +};
  247. +
  248. +static int
  249. +nv_procfs_show_registry(
  250. + struct seq_file *m,
  251. + void *v
  252. +)
  253. +{
  254. + nv_state_t *nv = m->private;
  255. + nv_linux_state_t *nvl = NULL;
  256. + char *registry_keys;
  257. +
  258. + if (nv != NULL)
  259. + nvl = NV_GET_NVL_FROM_NV_STATE(nv);
  260. + registry_keys = ((nvl != NULL) ?
  261. + nvl->registry_keys : nv_registry_keys);
  262. +
  263. + seq_printf(m, "Binary: \"%s\"\n", registry_keys);
  264. +
  265. + return 0;
  266. +}
  267. +
  268. +static ssize_t
  269. +nv_procfs_write_registry(
  270. + struct file *file,
  271. + const char __user *buffer,
  272. + size_t count,
  273. + loff_t *pos
  274. )
  275. {
  276. - int len = 0;
  277. - *eof = 1;
  278. + int status = 0;
  279. + nv_file_private_t *nvfp = NV_GET_FILE_PRIVATE(file);
  280. + char *proc_buffer;
  281. + unsigned long bytes_left;
  282. +
  283. + down(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  284. +
  285. + bytes_left = (NV_PROC_WRITE_BUFFER_SIZE - nvfp->off - 1);
  286. +
  287. + if (count == 0)
  288. + {
  289. + status = -EINVAL;
  290. + goto done;
  291. + }
  292. + else if ((bytes_left == 0) || (count > bytes_left))
  293. + {
  294. + status = -ENOSPC;
  295. + goto done;
  296. + }
  297. +
  298. + proc_buffer = &((char *)nvfp->data)[nvfp->off];
  299. +
  300. + if (copy_from_user(proc_buffer, buffer, count))
  301. + {
  302. + nv_printf(NV_DBG_ERRORS, "NVRM: failed to copy in proc data!\n");
  303. + status = -EFAULT;
  304. + }
  305. + else
  306. + {
  307. + nvfp->proc_data = PDE_DATA(file->f_inode);
  308. + nvfp->off += count;
  309. + }
  310.  
  311. - len += sprintf(page+len, "NVRM version: %s\n", pNVRM_ID);
  312. - len += sprintf(page+len, "GCC version: %s\n", NV_COMPILER);
  313. +done:
  314. + up(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  315.  
  316. - return len;
  317. + return ((status < 0) ? status : count);
  318. }
  319.  
  320. static int
  321. @@ -233,7 +308,7 @@
  322. nv_stack_t *sp = NULL;
  323.  
  324. if (0 == (file->f_mode & FMODE_WRITE))
  325. - return 0;
  326. + return single_open(file, nv_procfs_show_registry, PDE_DATA(inode));
  327.  
  328. nvfp = nv_alloc_file_private();
  329. if (nvfp == NULL)
  330. @@ -282,6 +357,9 @@
  331. RM_STATUS rm_status;
  332. int rc = 0;
  333.  
  334. + if (0 == (file->f_mode & FMODE_WRITE))
  335. + return single_release(inode, file);
  336. +
  337. nvfp = NV_GET_FILE_PRIVATE(file);
  338. if (nvfp == NULL)
  339. return 0;
  340. @@ -346,122 +424,81 @@
  341. return rc;
  342. }
  343.  
  344. -static struct file_operations nv_procfs_registry_fops = {
  345. +static const struct file_operations nv_procfs_registry_fops = {
  346. .open = nv_procfs_open_registry,
  347. + .read = seq_read,
  348. + .llseek = seq_lseek,
  349. + .write = nv_procfs_write_registry,
  350. .release = nv_procfs_close_registry,
  351. };
  352.  
  353. static int
  354. -nv_procfs_read_params(
  355. - char *page,
  356. - char **start,
  357. - off_t off,
  358. - int count,
  359. - int *eof,
  360. - void *data
  361. +nv_procfs_show_params(
  362. + struct seq_file *m,
  363. + void *v
  364. )
  365. {
  366. unsigned int i;
  367. - int len = 0;
  368. nv_parm_t *entry;
  369.  
  370. - *eof = 1;
  371.  
  372. for (i = 0; (entry = &nv_parms[i])->name != NULL; i++)
  373. - len += sprintf(page+len, "%s: %u\n", entry->name, *entry->data);
  374. + seq_printf(m, "%s: %u\n", entry->name, *entry->data);
  375.  
  376. - len += sprintf(page+len, "RegistryDwords: \"%s\"\n",
  377. + seq_printf(m, "RegistryDwords: \"%s\"\n",
  378. (NVreg_RegistryDwords != NULL) ? NVreg_RegistryDwords : "");
  379. - len += sprintf(page+len, "RmMsg: \"%s\"\n",
  380. + seq_printf(m, "RmMsg: \"%s\"\n",
  381. (NVreg_RmMsg != NULL) ? NVreg_RmMsg : "");
  382.  
  383. - return len;
  384. + return 0;
  385. }
  386.  
  387. static int
  388. -nv_procfs_read_registry(
  389. - char *page,
  390. - char **start,
  391. - off_t off,
  392. - int count,
  393. - int *eof,
  394. - void *data
  395. -)
  396. +nv_procfs_open_params(
  397. + struct inode *inode,
  398. + struct file *file
  399. +)
  400. {
  401. - nv_state_t *nv = data;
  402. - nv_linux_state_t *nvl = NULL;
  403. - char *registry_keys;
  404. + return single_open(file, nv_procfs_show_params, NULL);
  405. +}
  406.  
  407. - if (nv != NULL)
  408. - nvl = NV_GET_NVL_FROM_NV_STATE(nv);
  409. - registry_keys = ((nvl != NULL) ?
  410. - nvl->registry_keys : nv_registry_keys);
  411. +static const struct file_operations nv_procfs_params_fops = {
  412. + .owner = THIS_MODULE,
  413. + .open = nv_procfs_open_params,
  414. + .read = seq_read,
  415. + .llseek = seq_lseek,
  416. + .release = single_release,
  417. +};
  418.  
  419. - *eof = 1;
  420. - return sprintf(page, "Binary: \"%s\"\n", registry_keys);
  421. -}
  422.  
  423. static int
  424. -nv_procfs_write_registry(
  425. - struct file *file,
  426. - const char *buffer,
  427. - unsigned long count,
  428. - void *data
  429. +nv_procfs_show_text_file(
  430. + struct seq_file *m,
  431. + void *v
  432. )
  433. {
  434. - int status = 0;
  435. - nv_file_private_t *nvfp = NV_GET_FILE_PRIVATE(file);
  436. - char *proc_buffer;
  437. - unsigned long bytes_left;
  438. -
  439. - down(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  440. -
  441. - bytes_left = (NV_PROC_WRITE_BUFFER_SIZE - nvfp->off - 1);
  442. + seq_printf(m, "%s", (char *)m->private);
  443.  
  444. - if (count == 0)
  445. - {
  446. - status = -EINVAL;
  447. - goto done;
  448. - }
  449. - else if ((bytes_left == 0) || (count > bytes_left))
  450. - {
  451. - status = -ENOSPC;
  452. - goto done;
  453. - }
  454. -
  455. - proc_buffer = &((char *)nvfp->data)[nvfp->off];
  456. -
  457. - if (copy_from_user(proc_buffer, buffer, count))
  458. - {
  459. - nv_printf(NV_DBG_ERRORS, "NVRM: failed to copy in proc data!\n");
  460. - status = -EFAULT;
  461. - }
  462. - else
  463. - {
  464. - nvfp->proc_data = data;
  465. - nvfp->off += count;
  466. - }
  467. -
  468. -done:
  469. - up(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  470. -
  471. - return ((status < 0) ? status : (int)count);
  472. + return 0;
  473. }
  474.  
  475. static int
  476. -nv_procfs_read_text_file(
  477. - char *page,
  478. - char **start,
  479. - off_t off,
  480. - int count,
  481. - int *eof,
  482. - void *data
  483. +nv_procfs_open_text_file(
  484. + struct inode *inode,
  485. + struct file *file
  486. )
  487. {
  488. - *eof = 1;
  489. - return sprintf(page, "%s", (char *)data);
  490. + return single_open(file, nv_procfs_show_text_file, PDE_DATA(inode));
  491. }
  492.  
  493. +static const struct file_operations nv_procfs_text_fops = {
  494. + .owner = THIS_MODULE,
  495. + .open = nv_procfs_open_text_file,
  496. + .read = seq_read,
  497. + .llseek = seq_lseek,
  498. + .release = single_release,
  499. +};
  500. +
  501. static void
  502. nv_procfs_add_text_file(
  503. struct proc_dir_entry *parent,
  504. @@ -469,22 +506,7 @@
  505. const char *text
  506. )
  507. {
  508. - NV_CREATE_PROC_FILE(filename, parent,
  509. - nv_procfs_read_text_file, NULL, NULL, (void *)text);
  510. -}
  511. -
  512. -static void nv_procfs_unregister_all(struct proc_dir_entry *entry)
  513. -{
  514. - while (entry)
  515. - {
  516. - struct proc_dir_entry *next = entry->next;
  517. - if (entry->subdir)
  518. - nv_procfs_unregister_all(entry->subdir);
  519. - remove_proc_entry(entry->name, entry->parent);
  520. - if (entry == proc_nvidia)
  521. - break;
  522. - entry = next;
  523. - }
  524. + proc_create_data(filename, NV_PROC_RO, parent, &nv_procfs_text_fops, (void *)text);
  525. }
  526. #endif
  527.  
  528. @@ -513,26 +535,11 @@
  529. if (!proc_nvidia)
  530. goto failed;
  531.  
  532. - entry = NV_CREATE_PROC_FILE("params", proc_nvidia,
  533. - nv_procfs_read_params, NULL, NULL, NULL);
  534. + entry = proc_create("params", NV_PROC_RO, proc_nvidia, &nv_procfs_params_fops);
  535. if (!entry)
  536. goto failed;
  537.  
  538. - /*
  539. - * entry->proc_fops originally points to a constant
  540. - * structure, so to add more methods for the
  541. - * binary registry write path, we need to replace the
  542. - * said entry->proc_fops with a new fops structure.
  543. - * However, in preparation for this, we need to preserve
  544. - * the procfs read() and write() operations.
  545. - */
  546. - nv_procfs_registry_fops.read = entry->proc_fops->read;
  547. - nv_procfs_registry_fops.write = entry->proc_fops->write;
  548. -
  549. - entry = NV_CREATE_PROC_FILE("registry", proc_nvidia,
  550. - nv_procfs_read_registry,
  551. - nv_procfs_write_registry,
  552. - &nv_procfs_registry_fops, NULL);
  553. + entry = proc_create("registry", NV_PROC_RW, proc_nvidia, &nv_procfs_registry_fops);
  554. if (!entry)
  555. goto failed;
  556.  
  557. @@ -553,8 +560,7 @@
  558.  
  559. nv_procfs_add_text_file(proc_nvidia_patches, "README", __README_patches);
  560.  
  561. - entry = NV_CREATE_PROC_FILE("version", proc_nvidia,
  562. - nv_procfs_read_version, NULL, NULL, NULL);
  563. + entry = proc_create("version", NV_PROC_RO, proc_nvidia, &nv_procfs_version_fops);
  564. if (!entry)
  565. goto failed;
  566.  
  567. @@ -571,15 +577,11 @@
  568. if (!proc_nvidia_gpu)
  569. goto failed;
  570.  
  571. - entry = NV_CREATE_PROC_FILE("information", proc_nvidia_gpu,
  572. - nv_procfs_read_gpu_info, NULL, NULL, nv);
  573. + entry = proc_create_data("information", NV_PROC_RO, proc_nvidia_gpu, &nv_procfs_gpu_info_fops, nv);
  574. if (!entry)
  575. goto failed;
  576.  
  577. - entry = NV_CREATE_PROC_FILE("registry", proc_nvidia_gpu,
  578. - nv_procfs_read_registry,
  579. - nv_procfs_write_registry,
  580. - &nv_procfs_registry_fops, nv);
  581. + entry = proc_create_data("registry", NV_PROC_RW, proc_nvidia_gpu, &nv_procfs_registry_fops, nv);
  582. if (!entry)
  583. goto failed;
  584. }
  585. @@ -587,7 +589,7 @@
  586. return 0;
  587. #if defined(CONFIG_PROC_FS)
  588. failed:
  589. - nv_procfs_unregister_all(proc_nvidia);
  590. + remove_proc_subtree("nvidia", proc_nvidia);
  591. return -1;
  592. #endif
  593. }
  594. @@ -595,6 +597,6 @@
  595. void nv_unregister_procfs(void)
  596. {
  597. #if defined(CONFIG_PROC_FS)
  598. - nv_procfs_unregister_all(proc_nvidia);
  599. + remove_proc_subtree("nvidia", proc_nvidia);
  600. #endif
  601. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement