Linux Audio

Check our new training course

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