Lines Matching +full:remote +full:- +full:pid

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
25 * of a single 32-bit value between two processors. Each value has a single
26 * writer (the local side) and a single reader (the remote side). Values are
28 * to remote processor ID) and a string identifier.
31 * item is writable by the local processor and readable by the remote
32 * processor. By using two separate SMEM items that are single-reader and
33 * single-writer, SMP2P does not require any remote locking mechanisms.
51 * struct smp2p_smem_item - in memory communication structure
53 * @version: version - must be 1
54 * @features: features flag - currently unused
57 * @total_entries: number of entries - always SMP2P_MAX_ENTRY
81 * struct smp2p_entry - driver context matching one entry
92 * @lock: spinlock to protect read-modify-write of the value
116 * struct qcom_smp2p - device driver context
129 * @ipc_bit: bit in regmap@offset to kick to signal remote processor
168 if (smp2p->mbox_chan) { in qcom_smp2p_kick()
169 mbox_send_message(smp2p->mbox_chan, NULL); in qcom_smp2p_kick()
170 mbox_client_txdone(smp2p->mbox_chan, 0); in qcom_smp2p_kick()
172 regmap_write(smp2p->ipc_regmap, smp2p->ipc_offset, BIT(smp2p->ipc_bit)); in qcom_smp2p_kick()
178 struct smp2p_smem_item *in = smp2p->in; in qcom_smp2p_check_ssr()
181 if (!smp2p->ssr_ack_enabled) in qcom_smp2p_check_ssr()
184 restart = in->flags & BIT(SMP2P_FLAGS_RESTART_DONE_BIT); in qcom_smp2p_check_ssr()
186 return restart != smp2p->ssr_ack; in qcom_smp2p_check_ssr()
191 struct smp2p_smem_item *out = smp2p->out; in qcom_smp2p_do_ssr_ack()
194 smp2p->ssr_ack = !smp2p->ssr_ack; in qcom_smp2p_do_ssr_ack()
196 val = out->flags & ~BIT(SMP2P_FLAGS_RESTART_ACK_BIT); in qcom_smp2p_do_ssr_ack()
197 if (smp2p->ssr_ack) in qcom_smp2p_do_ssr_ack()
199 out->flags = val; in qcom_smp2p_do_ssr_ack()
206 struct smp2p_smem_item *out = smp2p->out; in qcom_smp2p_negotiate()
207 struct smp2p_smem_item *in = smp2p->in; in qcom_smp2p_negotiate()
209 if (in->version == out->version) { in qcom_smp2p_negotiate()
210 out->features &= in->features; in qcom_smp2p_negotiate()
212 if (out->features & SMP2P_FEATURE_SSR_ACK) in qcom_smp2p_negotiate()
213 smp2p->ssr_ack_enabled = true; in qcom_smp2p_negotiate()
215 smp2p->negotiation_done = true; in qcom_smp2p_negotiate()
229 in = smp2p->in; in qcom_smp2p_notify_in()
232 for (i = smp2p->valid_entries; i < in->valid_entries; i++) { in qcom_smp2p_notify_in()
233 list_for_each_entry(entry, &smp2p->inbound, node) { in qcom_smp2p_notify_in()
234 memcpy(buf, in->entries[i].name, sizeof(buf)); in qcom_smp2p_notify_in()
235 if (!strcmp(buf, entry->name)) { in qcom_smp2p_notify_in()
236 entry->value = &in->entries[i].value; in qcom_smp2p_notify_in()
241 smp2p->valid_entries = i; in qcom_smp2p_notify_in()
244 list_for_each_entry(entry, &smp2p->inbound, node) { in qcom_smp2p_notify_in()
245 /* Ignore entries not yet allocated by the remote side */ in qcom_smp2p_notify_in()
246 if (!entry->value) in qcom_smp2p_notify_in()
249 val = readl(entry->value); in qcom_smp2p_notify_in()
251 status = val ^ entry->last_value; in qcom_smp2p_notify_in()
252 entry->last_value = val; in qcom_smp2p_notify_in()
258 for_each_set_bit(i, entry->irq_enabled, 32) { in qcom_smp2p_notify_in()
262 if ((val & BIT(i) && test_bit(i, entry->irq_rising)) || in qcom_smp2p_notify_in()
263 (!(val & BIT(i)) && test_bit(i, entry->irq_falling))) { in qcom_smp2p_notify_in()
264 irq_pin = irq_find_mapping(entry->domain, i); in qcom_smp2p_notify_in()
272 * qcom_smp2p_intr() - interrupt handler for incoming notifications
276 * Handle notifications from the remote side to handle newly allocated entries
283 unsigned int smem_id = smp2p->smem_items[SMP2P_INBOUND]; in qcom_smp2p_intr()
284 unsigned int pid = smp2p->remote_pid; in qcom_smp2p_intr() local
288 in = smp2p->in; in qcom_smp2p_intr()
292 in = qcom_smem_get(pid, smem_id, &size); in qcom_smp2p_intr()
294 dev_err(smp2p->dev, in qcom_smp2p_intr()
295 "Unable to acquire remote smp2p item\n"); in qcom_smp2p_intr()
299 smp2p->in = in; in qcom_smp2p_intr()
302 if (!smp2p->negotiation_done) in qcom_smp2p_intr()
305 if (smp2p->negotiation_done) { in qcom_smp2p_intr()
322 clear_bit(irq, entry->irq_enabled); in smp2p_mask_irq()
330 set_bit(irq, entry->irq_enabled); in smp2p_unmask_irq()
339 return -EINVAL; in smp2p_set_irq_type()
342 set_bit(irq, entry->irq_rising); in smp2p_set_irq_type()
344 clear_bit(irq, entry->irq_rising); in smp2p_set_irq_type()
347 set_bit(irq, entry->irq_falling); in smp2p_set_irq_type()
349 clear_bit(irq, entry->irq_falling); in smp2p_set_irq_type()
365 struct smp2p_entry *entry = d->host_data; in smp2p_irq_map()
384 entry->domain = irq_domain_add_linear(node, 32, &smp2p_irq_ops, entry); in qcom_smp2p_inbound_entry()
385 if (!entry->domain) { in qcom_smp2p_inbound_entry()
386 dev_err(smp2p->dev, "failed to add irq_domain\n"); in qcom_smp2p_inbound_entry()
387 return -ENOMEM; in qcom_smp2p_inbound_entry()
400 spin_lock_irqsave(&entry->lock, flags); in smp2p_update_bits()
401 val = orig = readl(entry->value); in smp2p_update_bits()
404 writel(val, entry->value); in smp2p_update_bits()
405 spin_unlock_irqrestore(&entry->lock, flags); in smp2p_update_bits()
408 qcom_smp2p_kick(entry->smp2p); in smp2p_update_bits()
421 struct smp2p_smem_item *out = smp2p->out; in qcom_smp2p_outbound_entry()
425 strlcpy(buf, entry->name, SMP2P_MAX_ENTRY_NAME); in qcom_smp2p_outbound_entry()
426 memcpy(out->entries[out->valid_entries].name, buf, SMP2P_MAX_ENTRY_NAME); in qcom_smp2p_outbound_entry()
429 entry->value = &out->entries[out->valid_entries].value; in qcom_smp2p_outbound_entry()
431 out->valid_entries++; in qcom_smp2p_outbound_entry()
433 entry->state = qcom_smem_state_register(node, &smp2p_state_ops, entry); in qcom_smp2p_outbound_entry()
434 if (IS_ERR(entry->state)) { in qcom_smp2p_outbound_entry()
435 dev_err(smp2p->dev, "failed to register qcom_smem_state\n"); in qcom_smp2p_outbound_entry()
436 return PTR_ERR(entry->state); in qcom_smp2p_outbound_entry()
445 unsigned smem_id = smp2p->smem_items[SMP2P_OUTBOUND]; in qcom_smp2p_alloc_outbound_item()
446 unsigned pid = smp2p->remote_pid; in qcom_smp2p_alloc_outbound_item() local
449 ret = qcom_smem_alloc(pid, smem_id, sizeof(*out)); in qcom_smp2p_alloc_outbound_item()
450 if (ret < 0 && ret != -EEXIST) { in qcom_smp2p_alloc_outbound_item()
451 if (ret != -EPROBE_DEFER) in qcom_smp2p_alloc_outbound_item()
452 dev_err(smp2p->dev, in qcom_smp2p_alloc_outbound_item()
457 out = qcom_smem_get(pid, smem_id, NULL); in qcom_smp2p_alloc_outbound_item()
459 dev_err(smp2p->dev, "Unable to acquire local smp2p item\n"); in qcom_smp2p_alloc_outbound_item()
464 out->magic = SMP2P_MAGIC; in qcom_smp2p_alloc_outbound_item()
465 out->local_pid = smp2p->local_pid; in qcom_smp2p_alloc_outbound_item()
466 out->remote_pid = smp2p->remote_pid; in qcom_smp2p_alloc_outbound_item()
467 out->total_entries = SMP2P_MAX_ENTRY; in qcom_smp2p_alloc_outbound_item()
468 out->valid_entries = 0; in qcom_smp2p_alloc_outbound_item()
469 out->features = SMP2P_ALL_FEATURES; in qcom_smp2p_alloc_outbound_item()
476 out->version = 1; in qcom_smp2p_alloc_outbound_item()
480 smp2p->out = out; in qcom_smp2p_alloc_outbound_item()
488 struct device *dev = smp2p->dev; in smp2p_parse_ipc()
492 syscon = of_parse_phandle(dev->of_node, "qcom,ipc", 0); in smp2p_parse_ipc()
495 return -ENODEV; in smp2p_parse_ipc()
498 smp2p->ipc_regmap = syscon_node_to_regmap(syscon); in smp2p_parse_ipc()
500 if (IS_ERR(smp2p->ipc_regmap)) in smp2p_parse_ipc()
501 return PTR_ERR(smp2p->ipc_regmap); in smp2p_parse_ipc()
504 ret = of_property_read_u32_index(dev->of_node, key, 1, &smp2p->ipc_offset); in smp2p_parse_ipc()
507 return -EINVAL; in smp2p_parse_ipc()
510 ret = of_property_read_u32_index(dev->of_node, key, 2, &smp2p->ipc_bit); in smp2p_parse_ipc()
513 return -EINVAL; in smp2p_parse_ipc()
528 smp2p = devm_kzalloc(&pdev->dev, sizeof(*smp2p), GFP_KERNEL); in qcom_smp2p_probe()
530 return -ENOMEM; in qcom_smp2p_probe()
532 smp2p->dev = &pdev->dev; in qcom_smp2p_probe()
533 INIT_LIST_HEAD(&smp2p->inbound); in qcom_smp2p_probe()
534 INIT_LIST_HEAD(&smp2p->outbound); in qcom_smp2p_probe()
539 ret = of_property_read_u32_array(pdev->dev.of_node, key, in qcom_smp2p_probe()
540 smp2p->smem_items, 2); in qcom_smp2p_probe()
544 key = "qcom,local-pid"; in qcom_smp2p_probe()
545 ret = of_property_read_u32(pdev->dev.of_node, key, &smp2p->local_pid); in qcom_smp2p_probe()
549 key = "qcom,remote-pid"; in qcom_smp2p_probe()
550 ret = of_property_read_u32(pdev->dev.of_node, key, &smp2p->remote_pid); in qcom_smp2p_probe()
558 smp2p->mbox_client.dev = &pdev->dev; in qcom_smp2p_probe()
559 smp2p->mbox_client.knows_txdone = true; in qcom_smp2p_probe()
560 smp2p->mbox_chan = mbox_request_channel(&smp2p->mbox_client, 0); in qcom_smp2p_probe()
561 if (IS_ERR(smp2p->mbox_chan)) { in qcom_smp2p_probe()
562 if (PTR_ERR(smp2p->mbox_chan) != -ENODEV) in qcom_smp2p_probe()
563 return PTR_ERR(smp2p->mbox_chan); in qcom_smp2p_probe()
565 smp2p->mbox_chan = NULL; in qcom_smp2p_probe()
576 for_each_available_child_of_node(pdev->dev.of_node, node) { in qcom_smp2p_probe()
577 entry = devm_kzalloc(&pdev->dev, sizeof(*entry), GFP_KERNEL); in qcom_smp2p_probe()
579 ret = -ENOMEM; in qcom_smp2p_probe()
584 entry->smp2p = smp2p; in qcom_smp2p_probe()
585 spin_lock_init(&entry->lock); in qcom_smp2p_probe()
587 ret = of_property_read_string(node, "qcom,entry-name", &entry->name); in qcom_smp2p_probe()
593 if (of_property_read_bool(node, "interrupt-controller")) { in qcom_smp2p_probe()
600 list_add(&entry->node, &smp2p->inbound); in qcom_smp2p_probe()
608 list_add(&entry->node, &smp2p->outbound); in qcom_smp2p_probe()
615 ret = devm_request_threaded_irq(&pdev->dev, irq, in qcom_smp2p_probe()
620 dev_err(&pdev->dev, "failed to request interrupt\n"); in qcom_smp2p_probe()
633 device_set_wakeup_capable(&pdev->dev, true); in qcom_smp2p_probe()
635 ret = dev_pm_set_wake_irq(&pdev->dev, irq); in qcom_smp2p_probe()
642 dev_pm_clear_wake_irq(&pdev->dev); in qcom_smp2p_probe()
645 list_for_each_entry(entry, &smp2p->inbound, node) in qcom_smp2p_probe()
646 irq_domain_remove(entry->domain); in qcom_smp2p_probe()
648 list_for_each_entry(entry, &smp2p->outbound, node) in qcom_smp2p_probe()
649 qcom_smem_state_unregister(entry->state); in qcom_smp2p_probe()
651 smp2p->out->valid_entries = 0; in qcom_smp2p_probe()
654 mbox_free_channel(smp2p->mbox_chan); in qcom_smp2p_probe()
659 dev_err(&pdev->dev, "failed to read %s\n", key); in qcom_smp2p_probe()
660 return -EINVAL; in qcom_smp2p_probe()
668 dev_pm_clear_wake_irq(&pdev->dev); in qcom_smp2p_remove()
670 list_for_each_entry(entry, &smp2p->inbound, node) in qcom_smp2p_remove()
671 irq_domain_remove(entry->domain); in qcom_smp2p_remove()
673 list_for_each_entry(entry, &smp2p->outbound, node) in qcom_smp2p_remove()
674 qcom_smem_state_unregister(entry->state); in qcom_smp2p_remove()
676 mbox_free_channel(smp2p->mbox_chan); in qcom_smp2p_remove()
678 smp2p->out->valid_entries = 0; in qcom_smp2p_remove()