Guest User

Untitled

a guest
Nov 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. static int reset_amdgpu_vega(struct pci_dev *dev, int probe) {
  2. #define AMDGPU_MAX_USEC_TIMEOUT 100000
  3. #define MP0_BASE 0x16000
  4. #define mmMP0_SMN_C2PMSG_33 ((MP0_BASE + 0x0061) * 4)
  5. #define mmMP0_SMN_C2PMSG_64 ((MP0_BASE + 0x0080) * 4)
  6. #define mmMP0_SMN_C2PMSG_81 ((MP0_BASE + 0x0091) * 4)
  7.  
  8. resource_size_t rmmio_base, rmmio_size;
  9. void __iomem *rmmio;
  10. int ret;
  11. int i;
  12. uint32_t val;
  13.  
  14. if (probe)
  15. return 0;
  16.  
  17. pci_clear_master(dev);
  18. pci_save_state(dev);
  19.  
  20. rmmio_base = pci_resource_start(dev, 5);
  21. rmmio_size = pci_resource_len(dev, 5);
  22. rmmio = ioremap(rmmio_base, rmmio_size);
  23. if (rmmio == NULL) {
  24. printk(KERN_ERR
  25. "[reset_amdgpu_vega] failed to ioremap the device\n");
  26. ret = -ENOMEM;
  27. goto out;
  28. }
  29. #if 0
  30. /* check the sign of life register to see if we even need to reset */
  31. if (!readl(rmmio + mmMP0_SMN_C2PMSG_81)) {
  32. printk(KERN_INFO
  33. "[reset_amdgpu_vega] psp is not running\n");
  34. ret = 0;
  35. goto out_unmap;
  36. }
  37.  
  38. /* ensure the PSP is working */
  39. ret = -EINVAL;
  40. for(i = 0; i < AMDGPU_MAX_USEC_TIMEOUT; i++) {
  41. val = readl(rmmio + mmMP0_SMN_C2PMSG_64);
  42. if ((val & 0x8000FFFF) == 0x80000000) {
  43. ret = 0;
  44. break;
  45. }
  46. udelay(1);
  47. }
  48. if (ret) {
  49. printk(KERN_ERR
  50. "[reset_amdgpu_vega] psp is not working correctly\n");
  51. goto out_unmap;
  52. }
  53. #endif
  54. /* send the mode 1 reset command */
  55. writel(0x70000, rmmio + mmMP0_SMN_C2PMSG_64);
  56.  
  57. mdelay(1000);
  58.  
  59. /* wait for the reset to complete */
  60. ret = -EINVAL;
  61. for(i = 0; i < AMDGPU_MAX_USEC_TIMEOUT; i++) {
  62. val = readl(rmmio + mmMP0_SMN_C2PMSG_33);
  63. if ((val & 0x80000000) == 0x80000000) {
  64. ret = 0;
  65. break;
  66. }
  67. udelay(1);
  68. }
  69. if (ret) {
  70. printk(KERN_ERR "[reset_amdgpu_vega] reset failed\n");
  71. goto out_unmap;
  72. }
  73.  
  74. pcie_flr(dev);
  75.  
  76. ret = 0;
  77. printk(KERN_INFO "[reset_amdgpu_vega] reset success\n");
  78.  
  79. out_unmap:
  80. iounmap(rmmio);
  81. out:
  82. pci_restore_state(dev);
  83. return ret;
  84. }
Add Comment
Please, Sign In to add comment