acpi_parking_protocol.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * ARM64 ACPI Parking Protocol implementation
  3. *
  4. * Authors: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
  5. * Mark Salter <msalter@redhat.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/acpi.h>
  20. #include <linux/types.h>
  21. #include <asm/cpu_ops.h>
  22. struct parking_protocol_mailbox {
  23. __le32 cpu_id;
  24. __le32 reserved;
  25. __le64 entry_point;
  26. };
  27. struct cpu_mailbox_entry {
  28. struct parking_protocol_mailbox __iomem *mailbox;
  29. phys_addr_t mailbox_addr;
  30. u8 version;
  31. u8 gic_cpu_id;
  32. };
  33. static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];
  34. void __init acpi_set_mailbox_entry(int cpu,
  35. struct acpi_madt_generic_interrupt *p)
  36. {
  37. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  38. cpu_entry->mailbox_addr = p->parked_address;
  39. cpu_entry->version = p->parking_version;
  40. cpu_entry->gic_cpu_id = p->cpu_interface_number;
  41. }
  42. bool acpi_parking_protocol_valid(int cpu)
  43. {
  44. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  45. return cpu_entry->mailbox_addr && cpu_entry->version;
  46. }
  47. static int acpi_parking_protocol_cpu_init(unsigned int cpu)
  48. {
  49. pr_debug("%s: ACPI parked addr=%llx\n", __func__,
  50. cpu_mailbox_entries[cpu].mailbox_addr);
  51. return 0;
  52. }
  53. static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)
  54. {
  55. return 0;
  56. }
  57. static int acpi_parking_protocol_cpu_boot(unsigned int cpu)
  58. {
  59. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  60. struct parking_protocol_mailbox __iomem *mailbox;
  61. __le32 cpu_id;
  62. /*
  63. * Map mailbox memory with attribute device nGnRE (ie ioremap -
  64. * this deviates from the parking protocol specifications since
  65. * the mailboxes are required to be mapped nGnRnE; the attribute
  66. * discrepancy is harmless insofar as the protocol specification
  67. * is concerned).
  68. * If the mailbox is mistakenly allocated in the linear mapping
  69. * by FW ioremap will fail since the mapping will be prevented
  70. * by the kernel (it clashes with the linear mapping attributes
  71. * specifications).
  72. */
  73. mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
  74. if (!mailbox)
  75. return -EIO;
  76. cpu_id = readl_relaxed(&mailbox->cpu_id);
  77. /*
  78. * Check if firmware has set-up the mailbox entry properly
  79. * before kickstarting the respective cpu.
  80. */
  81. if (cpu_id != ~0U) {
  82. iounmap(mailbox);
  83. return -ENXIO;
  84. }
  85. /*
  86. * stash the mailbox address mapping to use it for further FW
  87. * checks in the postboot method
  88. */
  89. cpu_entry->mailbox = mailbox;
  90. /*
  91. * We write the entry point and cpu id as LE regardless of the
  92. * native endianness of the kernel. Therefore, any boot-loaders
  93. * that read this address need to convert this address to the
  94. * Boot-Loader's endianness before jumping.
  95. */
  96. writeq_relaxed(__pa(secondary_entry), &mailbox->entry_point);
  97. writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);
  98. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  99. return 0;
  100. }
  101. static void acpi_parking_protocol_cpu_postboot(void)
  102. {
  103. int cpu = smp_processor_id();
  104. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  105. struct parking_protocol_mailbox __iomem *mailbox = cpu_entry->mailbox;
  106. __le64 entry_point;
  107. entry_point = readl_relaxed(&mailbox->entry_point);
  108. /*
  109. * Check if firmware has cleared the entry_point as expected
  110. * by the protocol specification.
  111. */
  112. WARN_ON(entry_point);
  113. }
  114. const struct cpu_operations acpi_parking_protocol_ops = {
  115. .name = "parking-protocol",
  116. .cpu_init = acpi_parking_protocol_cpu_init,
  117. .cpu_prepare = acpi_parking_protocol_cpu_prepare,
  118. .cpu_boot = acpi_parking_protocol_cpu_boot,
  119. .cpu_postboot = acpi_parking_protocol_cpu_postboot
  120. };