Advertisement
Guest User

Untitled

a guest
Dec 19th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. diff --git a/arch/arm/include/asm/arch-apple/rtkit.h b/arch/arm/include/asm/arch-apple/rtkit.h
  2. index 05a34e1e8f..c3d60323bc 100644
  3. --- a/arch/arm/include/asm/arch-apple/rtkit.h
  4. +++ b/arch/arm/include/asm/arch-apple/rtkit.h
  5. @@ -13,3 +13,5 @@ extern phys_addr_t apple_rtkit_phys_addr;
  6.  
  7. int apple_rtkit_init(struct mbox_chan *, int,
  8. int (*)(void *, phys_addr_t, phys_size_t), void *);
  9. +
  10. +int apple_rtkit_shutdown(struct mbox_chan *);
  11. diff --git a/arch/arm/mach-apple/rtkit.c b/arch/arm/mach-apple/rtkit.c
  12. index 2f2c1ee9fa..7e998022ee 100644
  13. --- a/arch/arm/mach-apple/rtkit.c
  14. +++ b/arch/arm/mach-apple/rtkit.c
  15. @@ -28,7 +28,7 @@
  16. #define APPLE_RTKIT_MGMT_STARTEP_EP GENMASK(39, 32)
  17. #define APPLE_RTKIT_MGMT_STARTEP_FLAG BIT(1)
  18.  
  19. -#define APPLE_RTKIT_MGMT_PWR_STATE_ACK 7
  20. +#define APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE_ACK 7
  21.  
  22. #define APPLE_RTKIT_MGMT_EPMAP 8
  23. #define APPLE_RTKIT_MGMT_EPMAP_LAST BIT(51)
  24. @@ -77,6 +77,8 @@ int apple_rtkit_init(struct mbox_chan *chan, int wakeup,
  25.  
  26. /* EP0_WAIT_HELLO */
  27. ret = mbox_recv(chan, &msg, 10000);
  28. + if (ret < 0)
  29. + return ret;
  30.  
  31. endpoint = msg.msg1;
  32. msgtype = FIELD_GET(APPLE_RTKIT_MGMT_TYPE, msg.msg0);
  33. @@ -115,6 +117,8 @@ int apple_rtkit_init(struct mbox_chan *chan, int wakeup,
  34. wait_epmap:
  35. /* EP0_WAIT_EPMAP */
  36. ret = mbox_recv(chan, &msg, 10000);
  37. + if (ret < 0)
  38. + return ret;
  39.  
  40. endpoint = msg.msg1;
  41. msgtype = FIELD_GET(APPLE_RTKIT_MGMT_TYPE, msg.msg0);
  42. @@ -135,7 +139,8 @@ wait_epmap:
  43. }
  44.  
  45. /* EP0_SEND_EPACK */
  46. - reply = FIELD_PREP(APPLE_RTKIT_MGMT_TYPE, APPLE_RTKIT_MGMT_EPMAP_REPLY);
  47. + reply = FIELD_PREP(APPLE_RTKIT_MGMT_TYPE, APPLE_RTKIT_MGMT_EPMAP_REPLY) |
  48. + FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, base);
  49. if (msg.msg0 & APPLE_RTKIT_MGMT_EPMAP_LAST)
  50. reply |= APPLE_RTKIT_MGMT_EPMAP_LAST;
  51. else
  52. @@ -213,16 +218,47 @@ wait_epmap:
  53. printf("%s: unexpected endpoint %d\n", __func__, endpoint);
  54. return -EINVAL;
  55. }
  56. - if (msgtype != APPLE_RTKIT_MGMT_PWR_STATE_ACK) {
  57. + if (msgtype != APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE_ACK) {
  58. printf("%s: unexpected message type %d\n", __func__, msgtype);
  59. return -EINVAL;
  60. }
  61.  
  62. - /* EP0_SEND_PWRACK */
  63. - msg.msg0 = 0x00b0000000000020;
  64. - msg.msg1 = APPLE_RTKIT_EP_MGMT;
  65. - mbox_send(chan, &msg);
  66. + /* Here we should be sending a message to set the AP power state. But
  67. + if we do, we can't shut everything back down without crashing RTKit. We
  68. + don't need it anyway, because we don't start up the syslogs. */
  69. }
  70.  
  71. return 0;
  72. }
  73. +
  74. +int apple_rtkit_shutdown(struct mbox_chan *chan)
  75. +{
  76. + struct apple_mbox_msg msg;
  77. + int ret;
  78. + int endpoint;
  79. + int msgtype;
  80. +
  81. + msg.msg0 = 0x0060000000000010;
  82. + msg.msg1 = APPLE_RTKIT_EP_MGMT;
  83. + mbox_send(chan, &msg);
  84. +
  85. + ret = mbox_recv(chan, &msg, 100000);
  86. + if (ret < 0)
  87. + return ret;
  88. +
  89. + endpoint = msg.msg1;
  90. + msgtype = FIELD_GET(APPLE_RTKIT_MGMT_TYPE, msg.msg0);
  91. + if (endpoint != APPLE_RTKIT_EP_MGMT) {
  92. + printf("%s: unexpected endpoint %d\n", __func__, endpoint);
  93. + return -EINVAL;
  94. + }
  95. + if (msgtype != APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE_ACK) {
  96. + printf("%s: unexpected message type %d\n", __func__, msgtype);
  97. + return -EINVAL;
  98. + }
  99. +
  100. + /* Here we should be sending a message to set the AP power state. But
  101. + since we didn't during init, doing so here would crash RTKit. */
  102. +
  103. + return 0;
  104. +}
  105. diff --git a/drivers/nvme/nvme_apple.c b/drivers/nvme/nvme_apple.c
  106. index f25a4c885a..0b4ddfe255 100644
  107. --- a/drivers/nvme/nvme_apple.c
  108. +++ b/drivers/nvme/nvme_apple.c
  109. @@ -137,6 +137,18 @@ static int apple_nvme_probe(struct udevice *dev)
  110. return nvme_init(dev);
  111. }
  112.  
  113. +static int apple_nvme_remove(struct udevice *dev)
  114. +{
  115. + struct apple_nvme_priv *priv = dev_get_priv(dev);
  116. +
  117. + int ret = apple_rtkit_shutdown(&priv->chan);
  118. + if (ret < 0)
  119. + return ret;
  120. +
  121. + return 0;
  122. +}
  123. +
  124. +
  125. static const struct udevice_id apple_nvme_ids[] = {
  126. { .compatible = "apple,t8103-ans-nvme" },
  127. { /* sentinel */ }
  128. @@ -148,4 +160,6 @@ U_BOOT_DRIVER(apple_nvme) = {
  129. .of_match = apple_nvme_ids,
  130. .priv_auto = sizeof(struct apple_nvme_priv),
  131. .probe = apple_nvme_probe,
  132. + .remove = apple_nvme_remove,
  133. + .flags = DM_FLAG_OS_PREPARE,
  134. };
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement