acpi_parking_protocol.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/mm.h>
  21. #include <linux/types.h>
  22. #include <asm/cpu_ops.h>
  23. struct parking_protocol_mailbox {
  24. __le32 cpu_id;
  25. __le32 reserved;
  26. __le64 entry_point;
  27. };
  28. struct cpu_mailbox_entry {
  29. struct parking_protocol_mailbox __iomem *mailbox;
  30. phys_addr_t mailbox_addr;
  31. u8 version;
  32. u8 gic_cpu_id;
  33. };
  34. static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];
  35. void __init acpi_set_mailbox_entry(int cpu,
  36. struct acpi_madt_generic_interrupt *p)
  37. {
  38. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  39. cpu_entry->mailbox_addr = p->parked_address;
  40. cpu_entry->version = p->parking_version;
  41. cpu_entry->gic_cpu_id = p->cpu_interface_number;
  42. }
  43. bool acpi_parking_protocol_valid(int cpu)
  44. {
  45. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  46. return cpu_entry->mailbox_addr && cpu_entry->version;
  47. }
  48. static int acpi_parking_protocol_cpu_init(unsigned int cpu)
  49. {
  50. pr_debug("%s: ACPI parked addr=%llx\n", __func__,
  51. cpu_mailbox_entries[cpu].mailbox_addr);
  52. return 0;
  53. }
  54. static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)
  55. {
  56. return 0;
  57. }
  58. static int acpi_parking_protocol_cpu_boot(unsigned int cpu)
  59. {
  60. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  61. struct parking_protocol_mailbox __iomem *mailbox;
  62. u32 cpu_id;
  63. /*
  64. * Map mailbox memory with attribute device nGnRE (ie ioremap -
  65. * this deviates from the parking protocol specifications since
  66. * the mailboxes are required to be mapped nGnRnE; the attribute
  67. * discrepancy is harmless insofar as the protocol specification
  68. * is concerned).
  69. * If the mailbox is mistakenly allocated in the linear mapping
  70. * by FW ioremap will fail since the mapping will be prevented
  71. * by the kernel (it clashes with the linear mapping attributes
  72. * specifications).
  73. */
  74. mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
  75. if (!mailbox)
  76. return -EIO;
  77. cpu_id = readl_relaxed(&mailbox->cpu_id);
  78. /*
  79. * Check if firmware has set-up the mailbox entry properly
  80. * before kickstarting the respective cpu.
  81. */
  82. if (cpu_id != ~0U) {
  83. iounmap(mailbox);
  84. return -ENXIO;
  85. }
  86. /*
  87. * stash the mailbox address mapping to use it for further FW
  88. * checks in the postboot method
  89. */
  90. cpu_entry->mailbox = mailbox;
  91. /*
  92. * We write the entry point and cpu id as LE regardless of the
  93. * native endianness of the kernel. Therefore, any boot-loaders
  94. * that read this address need to convert this address to the
  95. * Boot-Loader's endianness before jumping.
  96. */
  97. writeq_relaxed(__pa_symbol(secondary_entry), &mailbox->entry_point);
  98. writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);
  99. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  100. return 0;
  101. }
  102. static void acpi_parking_protocol_cpu_postboot(void)
  103. {
  104. int cpu = smp_processor_id();
  105. struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
  106. struct parking_protocol_mailbox __iomem *mailbox = cpu_entry->mailbox;
  107. u64 entry_point;
  108. entry_point = readq_relaxed(&mailbox->entry_point);
  109. /*
  110. * Check if firmware has cleared the entry_point as expected
  111. * by the protocol specification.
  112. */
  113. WARN_ON(entry_point);
  114. }
  115. const struct cpu_operations acpi_parking_protocol_ops = {
  116. .name = "parking-protocol",
  117. .cpu_init = acpi_parking_protocol_cpu_init,
  118. .cpu_prepare = acpi_parking_protocol_cpu_prepare,
  119. .cpu_boot = acpi_parking_protocol_cpu_boot,
  120. .cpu_postboot = acpi_parking_protocol_cpu_postboot
  121. };