// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2015, Sony Mobile Communications AB. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*/
/* * The Shared Memory Point to Point (SMP2P) protocol facilitates communication * of a single 32-bit value between two processors. Each value has a single * writer (the local side) and a single reader (the remote side). Values are * uniquely identified in the system by the directed edge (local processor ID * to remote processor ID) and a string identifier. * * Each processor is responsible for creating the outgoing SMEM items and each * item is writable by the local processor and readable by the remote * processor. By using two separate SMEM items that are single-reader and * single-writer, SMP2P does not require any remote locking mechanisms. * * The driver uses the Linux GPIO and interrupt framework to expose a virtual * GPIO for each outbound entry and a virtual interrupt controller for each * inbound entry.
*/
/** * struct smp2p_smem_item - in memory communication structure * @magic: magic number * @version: version - must be 1 * @features: features flag - currently unused * @local_pid: processor id of sending end * @remote_pid: processor id of receiving end * @total_entries: number of entries - always SMP2P_MAX_ENTRY * @valid_entries: number of allocated entries * @flags: * @entries: individual communication entries * @entries.name: name of the entry * @entries.value: content of the entry
*/ struct smp2p_smem_item {
u32 magic;
u8 version; unsigned features:24;
u16 local_pid;
u16 remote_pid;
u16 total_entries;
u16 valid_entries;
u32 flags;
/** * struct smp2p_entry - driver context matching one entry * @node: list entry to keep track of allocated entries * @smp2p: reference to the device driver context * @name: name of the entry, to match against smp2p_smem_item * @value: pointer to smp2p_smem_item entry value * @last_value: last handled value * @domain: irq_domain for inbound entries * @irq_enabled:bitmap to track enabled irq bits * @irq_rising: bitmap to mark irq bits for rising detection * @irq_falling:bitmap to mark irq bits for falling detection * @state: smem state handle * @lock: spinlock to protect read-modify-write of the value
*/ struct smp2p_entry { struct list_head node; struct qcom_smp2p *smp2p;
/** * struct qcom_smp2p - device driver context * @dev: device driver handle * @in: pointer to the inbound smem item * @out: pointer to the outbound smem item * @smem_items: ids of the two smem items * @valid_entries: already scanned inbound entries * @ssr_ack_enabled: SMP2P_FEATURE_SSR_ACK feature is supported and was enabled * @ssr_ack: current cached state of the local ack bit * @negotiation_done: whether negotiating finished * @local_pid: processor id of the inbound edge * @remote_pid: processor id of the outbound edge * @ipc_regmap: regmap for the outbound ipc * @ipc_offset: offset within the regmap * @ipc_bit: bit in regmap@offset to kick to signal remote processor * @mbox_client: mailbox client handle * @mbox_chan: apcs ipc mailbox channel handle * @inbound: list of inbound entries * @outbound: list of outbound entries
*/ struct qcom_smp2p { struct device *dev;
/* Match newly created entries */ for (i = smp2p->valid_entries; i < in->valid_entries; i++) {
list_for_each_entry(entry, &smp2p->inbound, node) {
memcpy(buf, in->entries[i].name, sizeof(buf)); if (!strcmp(buf, entry->name)) {
entry->value = &in->entries[i].value; break;
}
}
}
smp2p->valid_entries = i;
/* Fire interrupts based on any value changes */
list_for_each_entry(entry, &smp2p->inbound, node) { /* Ignore entries not yet allocated by the remote side */ if (!entry->value) continue;
val = readl(entry->value);
status = val ^ entry->last_value;
entry->last_value = val;
trace_smp2p_notify_in(entry, status, val);
/* No changes of this entry? */ if (!status) continue;
for_each_set_bit(i, entry->irq_enabled, 32) { if (!(status & BIT(i))) continue;
/** * qcom_smp2p_intr() - interrupt handler for incoming notifications * @irq: unused * @data: smp2p driver context * * Handle notifications from the remote side to handle newly allocated entries * or any changes to the state bits of existing entries. * * Return: %IRQ_HANDLED
*/ static irqreturn_t qcom_smp2p_intr(int irq, void *data)
{ struct smp2p_smem_item *in; struct qcom_smp2p *smp2p = data; unsignedint smem_id = smp2p->smem_items[SMP2P_INBOUND]; unsignedint pid = smp2p->remote_pid; bool ack_restart;
size_t size;
in = smp2p->in;
/* Acquire smem item, if not already found */ if (!in) {
in = qcom_smem_get(pid, smem_id, &size); if (IS_ERR(in)) {
dev_err(smp2p->dev, "Unable to acquire remote smp2p item\n"); goto out;
}
smp2p->in = in;
}
if (!smp2p->negotiation_done)
qcom_smp2p_negotiate(smp2p);
if (smp2p->negotiation_done) {
ack_restart = qcom_smp2p_check_ssr(smp2p);
qcom_smp2p_notify_in(smp2p);
/* Allocate an entry from the smem item */
strscpy(buf, entry->name, SMP2P_MAX_ENTRY_NAME);
memcpy(out->entries[out->valid_entries].name, buf, SMP2P_MAX_ENTRY_NAME);
/* Make the logical entry reference the physical value */
entry->value = &out->entries[out->valid_entries].value;
out->valid_entries++;
entry->state = qcom_smem_state_register(node, &smp2p_state_ops, entry); if (IS_ERR(entry->state)) {
dev_err(smp2p->dev, "failed to register qcom_smem_state\n"); return PTR_ERR(entry->state);
}
ret = qcom_smem_alloc(pid, smem_id, sizeof(*out)); if (ret < 0 && ret != -EEXIST) return dev_err_probe(smp2p->dev, ret, "unable to allocate local smp2p item\n");
out = qcom_smem_get(pid, smem_id, NULL); if (IS_ERR(out)) {
dev_err(smp2p->dev, "Unable to acquire local smp2p item\n"); return PTR_ERR(out);
}
ret = of_property_read_string(node, "qcom,entry-name", &entry->name); if (ret < 0) goto unwind_interfaces;
if (of_property_read_bool(node, "interrupt-controller")) {
ret = qcom_smp2p_inbound_entry(smp2p, entry, node); if (ret < 0) goto unwind_interfaces;
list_add(&entry->node, &smp2p->inbound);
} else {
ret = qcom_smp2p_outbound_entry(smp2p, entry, node); if (ret < 0) goto unwind_interfaces;
list_add(&entry->node, &smp2p->outbound);
}
}
/* Kick the outgoing edge after allocating entries */
qcom_smp2p_kick(smp2p);
ret = devm_request_threaded_irq(&pdev->dev, irq,
NULL, qcom_smp2p_intr,
IRQF_ONESHOT,
NULL, (void *)smp2p); if (ret) {
dev_err(&pdev->dev, "failed to request interrupt\n"); goto unwind_interfaces;
}
/* * Treat smp2p interrupt as wakeup source, but keep it disabled * by default. User space can decide enabling it depending on its * use cases. For example if remoteproc crashes and device wants * to handle it immediatedly (e.g. to not miss phone calls) it can * enable wakeup source from user space, while other devices which * do not have proper autosleep feature may want to handle it with * other wakeup events (e.g. Power button) instead waking up immediately.
*/
device_set_wakeup_capable(&pdev->dev, true);
ret = dev_pm_set_wake_irq(&pdev->dev, irq); if (ret) goto set_wake_irq_fail;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.