Advertisement
Guest User

nvidia-kernel-3.10.patch

a guest
Jul 4th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.57 KB | None | 0 0
  1. diff -ur kernel-3.10.0-1-ARCH.orig/nv-i2c.c kernel-3.10.0-1-ARCH/nv-i2c.c
  2. --- kernel-3.10.0-1-ARCH.orig/nv-i2c.c 2013-07-03 19:11:07.562343340 +0300
  3. +++ kernel-3.10.0-1-ARCH/nv-i2c.c 2013-07-03 19:08:39.011903056 +0300
  4. @@ -243,21 +243,14 @@
  5. BOOL NV_API_CALL nv_i2c_del_adapter(nv_state_t *nv, void *data)
  6. {
  7. struct i2c_adapter *pI2cAdapter = (struct i2c_adapter *)data;
  8. - int osstatus = 0;
  9. - BOOL wasReleased = FALSE;
  10.  
  11. if (!pI2cAdapter) return FALSE;
  12.  
  13. // attempt release with the OS
  14. - osstatus = i2c_del_adapter(pI2cAdapter);
  15. + i2c_del_adapter(pI2cAdapter);
  16. + os_free_mem(pI2cAdapter);
  17.  
  18. - if (!osstatus)
  19. - {
  20. - os_free_mem(pI2cAdapter);
  21. - wasReleased = TRUE;
  22. - }
  23. -
  24. - return wasReleased;
  25. + return TRUE;
  26. }
  27.  
  28. #else // (defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE))
  29. Only in kernel-3.10.0-1-ARCH: nv-i2c.c.orig
  30. diff -ur kernel-3.10.0-1-ARCH.orig/nv-procfs.c kernel-3.10.0-1-ARCH/nv-procfs.c
  31. --- kernel-3.10.0-1-ARCH.orig/nv-procfs.c 2013-07-03 19:11:07.562343340 +0300
  32. +++ kernel-3.10.0-1-ARCH/nv-procfs.c 2013-07-03 19:08:39.015236414 +0300
  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,121 +424,80 @@
  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. - return len;
  383. + return 0;
  384. }
  385.  
  386. static int
  387. -nv_procfs_read_registry(
  388. - char *page,
  389. - char **start,
  390. - off_t off,
  391. - int count,
  392. - int *eof,
  393. - void *data
  394. -)
  395. +nv_procfs_open_params(
  396. + struct inode *inode,
  397. + struct file *file
  398. +)
  399. {
  400. - nv_state_t *nv = data;
  401. - nv_linux_state_t *nvl = NULL;
  402. - char *registry_keys;
  403. + return single_open(file, nv_procfs_show_params, NULL);
  404. +}
  405.  
  406. - if (nv != NULL)
  407. - nvl = NV_GET_NVL_FROM_NV_STATE(nv);
  408. - registry_keys = ((nvl != NULL) ?
  409. - nvl->registry_keys : nv_registry_keys);
  410. +static const struct file_operations nv_procfs_params_fops = {
  411. + .owner = THIS_MODULE,
  412. + .open = nv_procfs_open_params,
  413. + .read = seq_read,
  414. + .llseek = seq_lseek,
  415. + .release = single_release,
  416. +};
  417.  
  418. - *eof = 1;
  419. - return sprintf(page, "Binary: \"%s\"\n", registry_keys);
  420. -}
  421.  
  422. static int
  423. -nv_procfs_write_registry(
  424. - struct file *file,
  425. - const char *buffer,
  426. - unsigned long count,
  427. - void *data
  428. +nv_procfs_show_text_file(
  429. + struct seq_file *m,
  430. + void *v
  431. )
  432. {
  433. - int status = 0;
  434. - nv_file_private_t *nvfp = NV_GET_FILE_PRIVATE(file);
  435. - char *proc_buffer;
  436. - unsigned long bytes_left;
  437. -
  438. - down(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  439. -
  440. - bytes_left = (NV_PROC_WRITE_BUFFER_SIZE - nvfp->off - 1);
  441. + seq_printf(m, "%s", (char *)m->private);
  442.  
  443. - if (count == 0)
  444. - {
  445. - status = -EINVAL;
  446. - goto done;
  447. - }
  448. - else if ((bytes_left == 0) || (count > bytes_left))
  449. - {
  450. - status = -ENOSPC;
  451. - goto done;
  452. - }
  453. -
  454. - proc_buffer = &((char *)nvfp->data)[nvfp->off];
  455. -
  456. - if (copy_from_user(proc_buffer, buffer, count))
  457. - {
  458. - nv_printf(NV_DBG_ERRORS, "NVRM: failed to copy in proc data!\n");
  459. - status = -EFAULT;
  460. - }
  461. - else
  462. - {
  463. - nvfp->proc_data = data;
  464. - nvfp->off += count;
  465. - }
  466. -
  467. -done:
  468. - up(&nvfp->fops_sp_lock[NV_FOPS_STACK_INDEX_PROCFS]);
  469. -
  470. - return ((status < 0) ? status : (int)count);
  471. + return 0;
  472. }
  473.  
  474. static int
  475. -nv_procfs_read_text_file(
  476. - char *page,
  477. - char **start,
  478. - off_t off,
  479. - int count,
  480. - int *eof,
  481. - void *data
  482. +nv_procfs_open_text_file(
  483. + struct inode *inode,
  484. + struct file *file
  485. )
  486. {
  487. - *eof = 1;
  488. - return sprintf(page, "%s", (char *)data);
  489. + return single_open(file, nv_procfs_show_text_file, PDE_DATA(inode));
  490. }
  491.  
  492. +static const struct file_operations nv_procfs_text_fops = {
  493. + .owner = THIS_MODULE,
  494. + .open = nv_procfs_open_text_file,
  495. + .read = seq_read,
  496. + .llseek = seq_lseek,
  497. + .release = single_release,
  498. +};
  499. +
  500. static void
  501. nv_procfs_add_text_file(
  502. struct proc_dir_entry *parent,
  503. @@ -468,22 +505,7 @@
  504. const char *text
  505. )
  506. {
  507. - NV_CREATE_PROC_FILE(filename, parent,
  508. - nv_procfs_read_text_file, NULL, NULL, (void *)text);
  509. -}
  510. -
  511. -static void nv_procfs_unregister_all(struct proc_dir_entry *entry)
  512. -{
  513. - while (entry)
  514. - {
  515. - struct proc_dir_entry *next = entry->next;
  516. - if (entry->subdir)
  517. - nv_procfs_unregister_all(entry->subdir);
  518. - remove_proc_entry(entry->name, entry->parent);
  519. - if (entry == proc_nvidia)
  520. - break;
  521. - entry = next;
  522. - }
  523. + proc_create_data(filename, NV_PROC_RO, parent, &nv_procfs_text_fops, (void *)text);
  524. }
  525. #endif
  526.  
  527. @@ -512,26 +534,11 @@
  528. if (!proc_nvidia)
  529. goto failed;
  530.  
  531. - entry = NV_CREATE_PROC_FILE("params", proc_nvidia,
  532. - nv_procfs_read_params, NULL, NULL, NULL);
  533. + entry = proc_create("params", NV_PROC_RO, proc_nvidia, &nv_procfs_params_fops);
  534. if (!entry)
  535. goto failed;
  536.  
  537. - /*
  538. - * entry->proc_fops originally points to a constant
  539. - * structure, so to add more methods for the
  540. - * binary registry write path, we need to replace the
  541. - * said entry->proc_fops with a new fops structure.
  542. - * However, in preparation for this, we need to preserve
  543. - * the procfs read() and write() operations.
  544. - */
  545. - nv_procfs_registry_fops.read = entry->proc_fops->read;
  546. - nv_procfs_registry_fops.write = entry->proc_fops->write;
  547. -
  548. - entry = NV_CREATE_PROC_FILE("registry", proc_nvidia,
  549. - nv_procfs_read_registry,
  550. - nv_procfs_write_registry,
  551. - &nv_procfs_registry_fops, NULL);
  552. + entry = proc_create("registry", NV_PROC_RW, proc_nvidia, &nv_procfs_registry_fops);
  553. if (!entry)
  554. goto failed;
  555.  
  556. @@ -552,8 +559,7 @@
  557.  
  558. nv_procfs_add_text_file(proc_nvidia_patches, "README", __README_patches);
  559.  
  560. - entry = NV_CREATE_PROC_FILE("version", proc_nvidia,
  561. - nv_procfs_read_version, NULL, NULL, NULL);
  562. + entry = proc_create("version", NV_PROC_RO, proc_nvidia, &nv_procfs_version_fops);
  563. if (!entry)
  564. goto failed;
  565.  
  566. @@ -570,15 +576,11 @@
  567. if (!proc_nvidia_gpu)
  568. goto failed;
  569.  
  570. - entry = NV_CREATE_PROC_FILE("information", proc_nvidia_gpu,
  571. - nv_procfs_read_gpu_info, NULL, NULL, nv);
  572. + entry = proc_create_data("information", NV_PROC_RO, proc_nvidia_gpu, &nv_procfs_gpu_info_fops, nv);
  573. if (!entry)
  574. goto failed;
  575.  
  576. - entry = NV_CREATE_PROC_FILE("registry", proc_nvidia_gpu,
  577. - nv_procfs_read_registry,
  578. - nv_procfs_write_registry,
  579. - &nv_procfs_registry_fops, nv);
  580. + entry = proc_create_data("registry", NV_PROC_RW, proc_nvidia_gpu, &nv_procfs_registry_fops, nv);
  581. if (!entry)
  582. goto failed;
  583. }
  584. @@ -586,7 +588,7 @@
  585. return 0;
  586. #if defined(CONFIG_PROC_FS)
  587. failed:
  588. - nv_procfs_unregister_all(proc_nvidia);
  589. + remove_proc_subtree("nvidia", proc_nvidia);
  590. return -1;
  591. #endif
  592. }
  593. @@ -594,6 +596,6 @@
  594. void nv_unregister_procfs(void)
  595. {
  596. #if defined(CONFIG_PROC_FS)
  597. - nv_procfs_unregister_all(proc_nvidia);
  598. + remove_proc_subtree("nvidia", proc_nvidia);
  599. #endif
  600. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement