Lines Matching +full:shared +full:- +full:interrupt

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
7 #include <linux/interrupt.h>
18 * This driver implements the Qualcomm Shared Memory State Machine, a mechanism
21 * The implementation is based on two sections of shared memory; the first
26 * read-write, while the rest should be considered read-only.
33 * The subscription matrix is laid out in entry-major order:
39 * A third, optional, shared memory region might contain information regarding
45 * Shared memory identifiers, used to acquire handles to respective memory
62 * struct qcom_smsm - smsm driver context
71 * @lock: spinlock for read-modify-write of the outgoing state
94 * struct smsm_entry - per remote processor entry context
95 * @smsm: back-reference to driver context
119 * struct smsm_host - representation of a remote host
120 * @ipc_regmap: regmap for outgoing interrupt
121 * @ipc_offset: offset in @ipc_regmap for outgoing interrupt
122 * @ipc_bit: bit in @ipc_regmap + @ipc_offset for outgoing interrupt
131 * smsm_update_bits() - change bit in outgoing entry and inform subscribers
149 spin_lock_irqsave(&smsm->lock, flags); in smsm_update_bits()
152 val = orig = readl(smsm->local_state); in smsm_update_bits()
159 spin_unlock_irqrestore(&smsm->lock, flags); in smsm_update_bits()
164 writel(val, smsm->local_state); in smsm_update_bits()
165 spin_unlock_irqrestore(&smsm->lock, flags); in smsm_update_bits()
171 for (host = 0; host < smsm->num_hosts; host++) { in smsm_update_bits()
172 hostp = &smsm->hosts[host]; in smsm_update_bits()
174 val = readl(smsm->subscription + host); in smsm_update_bits()
175 if (val & changes && hostp->ipc_regmap) { in smsm_update_bits()
176 regmap_write(hostp->ipc_regmap, in smsm_update_bits()
177 hostp->ipc_offset, in smsm_update_bits()
178 BIT(hostp->ipc_bit)); in smsm_update_bits()
191 * smsm_intr() - cascading IRQ handler for SMSM
195 * This function cascades an incoming interrupt from a remote system, based on
206 val = readl(entry->remote_state); in smsm_intr()
207 changed = val ^ xchg(&entry->last_value, val); in smsm_intr()
209 for_each_set_bit(i, entry->irq_enabled, 32) { in smsm_intr()
214 if (test_bit(i, entry->irq_rising)) { in smsm_intr()
215 irq_pin = irq_find_mapping(entry->domain, i); in smsm_intr()
219 if (test_bit(i, entry->irq_falling)) { in smsm_intr()
220 irq_pin = irq_find_mapping(entry->domain, i); in smsm_intr()
230 * smsm_mask_irq() - un-subscribe from cascades of IRQs of a certain staus bit
233 * This un-subscribes the local CPU from interrupts upon changes to the defines
240 struct qcom_smsm *smsm = entry->smsm; in smsm_mask_irq()
243 if (entry->subscription) { in smsm_mask_irq()
244 val = readl(entry->subscription + smsm->local_host); in smsm_mask_irq()
246 writel(val, entry->subscription + smsm->local_host); in smsm_mask_irq()
249 clear_bit(irq, entry->irq_enabled); in smsm_mask_irq()
253 * smsm_unmask_irq() - subscribe to cascades of IRQs of a certain status bit
263 struct qcom_smsm *smsm = entry->smsm; in smsm_unmask_irq()
266 /* Make sure our last cached state is up-to-date */ in smsm_unmask_irq()
267 if (readl(entry->remote_state) & BIT(irq)) in smsm_unmask_irq()
268 set_bit(irq, &entry->last_value); in smsm_unmask_irq()
270 clear_bit(irq, &entry->last_value); in smsm_unmask_irq()
272 set_bit(irq, entry->irq_enabled); in smsm_unmask_irq()
274 if (entry->subscription) { in smsm_unmask_irq()
275 val = readl(entry->subscription + smsm->local_host); in smsm_unmask_irq()
277 writel(val, entry->subscription + smsm->local_host); in smsm_unmask_irq()
282 * smsm_set_irq_type() - updates the requested IRQ type for the cascading
283 * @irqd: consumer interrupt handle
292 return -EINVAL; in smsm_set_irq_type()
295 set_bit(irq, entry->irq_rising); in smsm_set_irq_type()
297 clear_bit(irq, entry->irq_rising); in smsm_set_irq_type()
300 set_bit(irq, entry->irq_falling); in smsm_set_irq_type()
302 clear_bit(irq, entry->irq_falling); in smsm_set_irq_type()
315 return -EINVAL; in smsm_get_irqchip_state()
317 val = readl(entry->remote_state); in smsm_get_irqchip_state()
332 * smsm_irq_map() - sets up a mapping for a cascaded IRQ
341 struct smsm_entry *entry = d->host_data; in smsm_irq_map()
356 * smsm_parse_ipc() - parses a qcom,ipc-%d device tree property
361 * outgoing interrupts to a remote host - identified by @host_id.
366 struct device_node *node = smsm->dev->of_node; in smsm_parse_ipc()
367 struct smsm_host *host = &smsm->hosts[host_id]; in smsm_parse_ipc()
371 snprintf(key, sizeof(key), "qcom,ipc-%d", host_id); in smsm_parse_ipc()
376 host->ipc_regmap = syscon_node_to_regmap(syscon); in smsm_parse_ipc()
378 if (IS_ERR(host->ipc_regmap)) in smsm_parse_ipc()
379 return PTR_ERR(host->ipc_regmap); in smsm_parse_ipc()
381 ret = of_property_read_u32_index(node, key, 1, &host->ipc_offset); in smsm_parse_ipc()
383 dev_err(smsm->dev, "no offset in %s\n", key); in smsm_parse_ipc()
384 return -EINVAL; in smsm_parse_ipc()
387 ret = of_property_read_u32_index(node, key, 2, &host->ipc_bit); in smsm_parse_ipc()
389 dev_err(smsm->dev, "no bit in %s\n", key); in smsm_parse_ipc()
390 return -EINVAL; in smsm_parse_ipc()
397 * smsm_inbound_entry() - parse DT and set up an entry representing a remote system
411 dev_err(smsm->dev, "failed to parse smsm interrupt\n"); in smsm_inbound_entry()
412 return -EINVAL; in smsm_inbound_entry()
415 ret = devm_request_threaded_irq(smsm->dev, irq, in smsm_inbound_entry()
420 dev_err(smsm->dev, "failed to request interrupt\n"); in smsm_inbound_entry()
424 entry->domain = irq_domain_add_linear(node, 32, &smsm_irq_ops, entry); in smsm_inbound_entry()
425 if (!entry->domain) { in smsm_inbound_entry()
426 dev_err(smsm->dev, "failed to add irq_domain\n"); in smsm_inbound_entry()
427 return -ENOMEM; in smsm_inbound_entry()
434 * smsm_get_size_info() - parse the optional memory segment for sizes
437 * Attempt to acquire the number of hosts and entries from the optional shared
455 if (IS_ERR(info) && PTR_ERR(info) != -ENOENT) { in smsm_get_size_info()
456 if (PTR_ERR(info) != -EPROBE_DEFER) in smsm_get_size_info()
457 dev_err(smsm->dev, "unable to retrieve smsm size info\n"); in smsm_get_size_info()
460 dev_warn(smsm->dev, "no smsm size info, using defaults\n"); in smsm_get_size_info()
461 smsm->num_entries = SMSM_DEFAULT_NUM_ENTRIES; in smsm_get_size_info()
462 smsm->num_hosts = SMSM_DEFAULT_NUM_HOSTS; in smsm_get_size_info()
466 smsm->num_entries = info->num_entries; in smsm_get_size_info()
467 smsm->num_hosts = info->num_hosts; in smsm_get_size_info()
469 dev_dbg(smsm->dev, in smsm_get_size_info()
471 smsm->num_entries, smsm->num_hosts); in smsm_get_size_info()
488 smsm = devm_kzalloc(&pdev->dev, sizeof(*smsm), GFP_KERNEL); in qcom_smsm_probe()
490 return -ENOMEM; in qcom_smsm_probe()
491 smsm->dev = &pdev->dev; in qcom_smsm_probe()
492 spin_lock_init(&smsm->lock); in qcom_smsm_probe()
498 smsm->entries = devm_kcalloc(&pdev->dev, in qcom_smsm_probe()
499 smsm->num_entries, in qcom_smsm_probe()
502 if (!smsm->entries) in qcom_smsm_probe()
503 return -ENOMEM; in qcom_smsm_probe()
505 smsm->hosts = devm_kcalloc(&pdev->dev, in qcom_smsm_probe()
506 smsm->num_hosts, in qcom_smsm_probe()
509 if (!smsm->hosts) in qcom_smsm_probe()
510 return -ENOMEM; in qcom_smsm_probe()
512 for_each_child_of_node(pdev->dev.of_node, local_node) { in qcom_smsm_probe()
513 if (of_find_property(local_node, "#qcom,smem-state-cells", NULL)) in qcom_smsm_probe()
517 dev_err(&pdev->dev, "no state entry\n"); in qcom_smsm_probe()
518 return -EINVAL; in qcom_smsm_probe()
521 of_property_read_u32(pdev->dev.of_node, in qcom_smsm_probe()
522 "qcom,local-host", in qcom_smsm_probe()
523 &smsm->local_host); in qcom_smsm_probe()
526 for (id = 0; id < smsm->num_hosts; id++) { in qcom_smsm_probe()
534 smsm->num_entries * sizeof(u32)); in qcom_smsm_probe()
535 if (ret < 0 && ret != -EEXIST) { in qcom_smsm_probe()
536 dev_err(&pdev->dev, "unable to allocate shared state entry\n"); in qcom_smsm_probe()
542 dev_err(&pdev->dev, "Unable to acquire shared state entry\n"); in qcom_smsm_probe()
547 /* Acquire the list of interrupt mask vectors */ in qcom_smsm_probe()
548 size = smsm->num_entries * smsm->num_hosts * sizeof(u32); in qcom_smsm_probe()
550 if (ret < 0 && ret != -EEXIST) { in qcom_smsm_probe()
551 dev_err(&pdev->dev, "unable to allocate smsm interrupt mask\n"); in qcom_smsm_probe()
557 dev_err(&pdev->dev, "unable to acquire shared memory interrupt mask\n"); in qcom_smsm_probe()
563 smsm->local_state = states + smsm->local_host; in qcom_smsm_probe()
564 smsm->subscription = intr_mask + smsm->local_host * smsm->num_hosts; in qcom_smsm_probe()
567 smsm->state = qcom_smem_state_register(local_node, &smsm_state_ops, smsm); in qcom_smsm_probe()
568 if (IS_ERR(smsm->state)) { in qcom_smsm_probe()
569 dev_err(smsm->dev, "failed to register qcom_smem_state\n"); in qcom_smsm_probe()
570 ret = PTR_ERR(smsm->state); in qcom_smsm_probe()
575 for_each_available_child_of_node(pdev->dev.of_node, node) { in qcom_smsm_probe()
576 if (!of_property_read_bool(node, "interrupt-controller")) in qcom_smsm_probe()
580 if (ret || id >= smsm->num_entries) { in qcom_smsm_probe()
581 dev_err(&pdev->dev, "invalid reg of entry\n"); in qcom_smsm_probe()
583 ret = -EINVAL; in qcom_smsm_probe()
586 entry = &smsm->entries[id]; in qcom_smsm_probe()
588 entry->smsm = smsm; in qcom_smsm_probe()
589 entry->remote_state = states + id; in qcom_smsm_probe()
592 entry->subscription = intr_mask + id * smsm->num_hosts; in qcom_smsm_probe()
593 writel(0, entry->subscription + smsm->local_host); in qcom_smsm_probe()
607 for (id = 0; id < smsm->num_entries; id++) in qcom_smsm_probe()
608 if (smsm->entries[id].domain) in qcom_smsm_probe()
609 irq_domain_remove(smsm->entries[id].domain); in qcom_smsm_probe()
611 qcom_smem_state_unregister(smsm->state); in qcom_smsm_probe()
622 for (id = 0; id < smsm->num_entries; id++) in qcom_smsm_remove()
623 if (smsm->entries[id].domain) in qcom_smsm_remove()
624 irq_domain_remove(smsm->entries[id].domain); in qcom_smsm_remove()
626 qcom_smem_state_unregister(smsm->state); in qcom_smsm_remove()
641 .name = "qcom-smsm",
647 MODULE_DESCRIPTION("Qualcomm Shared Memory State Machine driver");