Lines Matching +full:tegra186 +full:- +full:bpmp
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
18 #include <dt-bindings/mailbox/tegra186-hsp.h>
111 return readl(hsp->regs + offset); in tegra_hsp_readl()
117 writel(value, hsp->regs + offset); in tegra_hsp_writel()
123 return readl(channel->regs + offset); in tegra_hsp_channel_readl()
129 writel(value, channel->regs + offset); in tegra_hsp_channel_writel()
136 value = tegra_hsp_channel_readl(&db->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_can_ring()
146 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
147 if (entry->master == master) in __tegra_hsp_doorbell_get()
159 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
161 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
176 value = tegra_hsp_channel_readl(&db->channel, HSP_DB_PENDING); in tegra_hsp_doorbell_irq()
177 tegra_hsp_channel_writel(&db->channel, value, HSP_DB_PENDING); in tegra_hsp_doorbell_irq()
179 spin_lock(&hsp->lock); in tegra_hsp_doorbell_irq()
181 for_each_set_bit(master, &value, hsp->mbox_db.num_chans) { in tegra_hsp_doorbell_irq()
190 * In that case, db->channel.chan will still be NULL here and in tegra_hsp_doorbell_irq()
196 if (db && db->channel.chan) in tegra_hsp_doorbell_irq()
197 mbox_chan_received_data(db->channel.chan, NULL); in tegra_hsp_doorbell_irq()
200 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
212 status = tegra_hsp_readl(hsp, HSP_INT_IR) & hsp->mask; in tegra_hsp_shared_irq()
217 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
218 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
220 if (mb->producer) { in tegra_hsp_shared_irq()
223 * the next message. These interrupts are level- in tegra_hsp_shared_irq()
228 spin_lock(&hsp->lock); in tegra_hsp_shared_irq()
230 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_shared_irq()
231 tegra_hsp_writel(hsp, hsp->mask, in tegra_hsp_shared_irq()
232 HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_shared_irq()
234 spin_unlock(&hsp->lock); in tegra_hsp_shared_irq()
236 mbox_chan_txdone(mb->channel.chan, 0); in tegra_hsp_shared_irq()
243 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
244 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
246 if (!mb->producer) { in tegra_hsp_shared_irq()
247 value = tegra_hsp_channel_readl(&mb->channel, in tegra_hsp_shared_irq()
251 mbox_chan_received_data(mb->channel.chan, msg); in tegra_hsp_shared_irq()
262 tegra_hsp_channel_writel(&mb->channel, 0x0, in tegra_hsp_shared_irq()
278 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); in tegra_hsp_doorbell_create()
280 return ERR_PTR(-ENOMEM); in tegra_hsp_doorbell_create()
282 offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; in tegra_hsp_doorbell_create()
285 db->channel.regs = hsp->regs + offset; in tegra_hsp_doorbell_create()
286 db->channel.hsp = hsp; in tegra_hsp_doorbell_create()
288 db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL); in tegra_hsp_doorbell_create()
289 db->master = master; in tegra_hsp_doorbell_create()
290 db->index = index; in tegra_hsp_doorbell_create()
292 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_create()
293 list_add_tail(&db->list, &hsp->doorbells); in tegra_hsp_doorbell_create()
294 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_create()
296 return &db->channel; in tegra_hsp_doorbell_create()
301 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_send_data()
303 tegra_hsp_channel_writel(&db->channel, 1, HSP_DB_TRIGGER); in tegra_hsp_doorbell_send_data()
310 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_startup()
311 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup()
316 if (db->master >= chan->mbox->num_chans) { in tegra_hsp_doorbell_startup()
317 dev_err(chan->mbox->dev, in tegra_hsp_doorbell_startup()
319 db->master); in tegra_hsp_doorbell_startup()
320 return -EINVAL; in tegra_hsp_doorbell_startup()
325 return -ENODEV; in tegra_hsp_doorbell_startup()
328 * On simulation platforms the BPMP hasn't had a chance yet to mark in tegra_hsp_doorbell_startup()
333 return -ENODEV; in tegra_hsp_doorbell_startup()
335 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
337 value = tegra_hsp_channel_readl(&ccplex->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_startup()
338 value |= BIT(db->master); in tegra_hsp_doorbell_startup()
339 tegra_hsp_channel_writel(&ccplex->channel, value, HSP_DB_ENABLE); in tegra_hsp_doorbell_startup()
341 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
348 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_shutdown()
349 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown()
358 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
360 value = tegra_hsp_channel_readl(&ccplex->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_shutdown()
361 value &= ~BIT(db->master); in tegra_hsp_doorbell_shutdown()
362 tegra_hsp_channel_writel(&ccplex->channel, value, HSP_DB_ENABLE); in tegra_hsp_doorbell_shutdown()
364 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
375 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_send_data()
376 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data()
380 if (WARN_ON(!mb->producer)) in tegra_hsp_mailbox_send_data()
381 return -EPERM; in tegra_hsp_mailbox_send_data()
387 tegra_hsp_channel_writel(&mb->channel, value, HSP_SM_SHRD_MBOX); in tegra_hsp_mailbox_send_data()
390 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
392 hsp->mask |= BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_send_data()
393 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_send_data()
395 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
403 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_flush()
404 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_flush()
419 return -ETIME; in tegra_hsp_mailbox_flush()
424 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_startup()
425 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_startup()
426 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup()
429 chan->txdone_method = TXDONE_BY_IRQ; in tegra_hsp_mailbox_startup()
437 * EMPTY interrupts are level-triggered, so keeping EMPTY interrupts in tegra_hsp_mailbox_startup()
442 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
444 if (mb->producer) in tegra_hsp_mailbox_startup()
445 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
447 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
449 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
451 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
453 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
454 if (mb->producer) in tegra_hsp_mailbox_startup()
467 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_shutdown()
468 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_shutdown()
469 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown()
472 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
473 if (mb->producer) in tegra_hsp_mailbox_shutdown()
481 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
483 if (mb->producer) in tegra_hsp_mailbox_shutdown()
484 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
486 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
488 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
490 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
504 unsigned int type = args->args[0], master = args->args[1]; in tegra_hsp_db_xlate()
505 struct tegra_hsp_channel *channel = ERR_PTR(-ENODEV); in tegra_hsp_db_xlate()
511 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
512 return ERR_PTR(-ENODEV); in tegra_hsp_db_xlate()
516 channel = &db->channel; in tegra_hsp_db_xlate()
521 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
523 for (i = 0; i < mbox->num_chans; i++) { in tegra_hsp_db_xlate()
524 chan = &mbox->chans[i]; in tegra_hsp_db_xlate()
525 if (!chan->con_priv) { in tegra_hsp_db_xlate()
526 channel->chan = chan; in tegra_hsp_db_xlate()
527 chan->con_priv = db; in tegra_hsp_db_xlate()
534 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
536 return chan ?: ERR_PTR(-EBUSY); in tegra_hsp_db_xlate()
543 unsigned int type = args->args[0], index; in tegra_hsp_sm_xlate()
546 index = args->args[1] & TEGRA_HSP_SM_MASK; in tegra_hsp_sm_xlate()
548 if (type != TEGRA_HSP_MBOX_TYPE_SM || !hsp->shared_irqs || in tegra_hsp_sm_xlate()
549 index >= hsp->num_sm) in tegra_hsp_sm_xlate()
550 return ERR_PTR(-ENODEV); in tegra_hsp_sm_xlate()
552 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
554 if ((args->args[1] & TEGRA_HSP_SM_FLAG_TX) == 0) in tegra_hsp_sm_xlate()
555 mb->producer = false; in tegra_hsp_sm_xlate()
557 mb->producer = true; in tegra_hsp_sm_xlate()
559 return mb->channel.chan; in tegra_hsp_sm_xlate()
564 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
567 while (map->name) { in tegra_hsp_add_doorbells()
568 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
569 map->master, map->index); in tegra_hsp_add_doorbells()
583 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
585 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
586 return -ENOMEM; in tegra_hsp_add_mailboxes()
588 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
589 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
591 mb->index = i; in tegra_hsp_add_mailboxes()
593 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
594 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
595 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
596 mb->channel.chan->con_priv = mb; in tegra_hsp_add_mailboxes()
607 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
608 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
612 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
613 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
615 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
620 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
623 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
625 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
630 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
631 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
632 return -ENOENT; in tegra_hsp_request_shared_irq()
646 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
648 return -ENOMEM; in tegra_hsp_probe()
650 hsp->dev = &pdev->dev; in tegra_hsp_probe()
651 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
652 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
653 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
656 hsp->regs = devm_ioremap_resource(&pdev->dev, res); in tegra_hsp_probe()
657 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
658 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
661 hsp->num_sm = (value >> HSP_nSM_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
662 hsp->num_ss = (value >> HSP_nSS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
663 hsp->num_as = (value >> HSP_nAS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
664 hsp->num_db = (value >> HSP_nDB_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
665 hsp->num_si = (value >> HSP_nSI_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
669 hsp->doorbell_irq = err; in tegra_hsp_probe()
671 if (hsp->num_si > 0) { in tegra_hsp_probe()
674 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
675 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
677 if (!hsp->shared_irqs) in tegra_hsp_probe()
678 return -ENOMEM; in tegra_hsp_probe()
680 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
685 return -ENOMEM; in tegra_hsp_probe()
689 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
697 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
698 hsp->shared_irqs = NULL; in tegra_hsp_probe()
703 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
704 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
705 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
706 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
708 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
709 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
711 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
712 return -ENOMEM; in tegra_hsp_probe()
714 if (hsp->doorbell_irq) { in tegra_hsp_probe()
717 dev_err(&pdev->dev, "failed to add doorbells: %d\n", in tegra_hsp_probe()
723 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
725 dev_err(&pdev->dev, "failed to register doorbell mailbox: %d\n", in tegra_hsp_probe()
731 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
732 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
733 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
734 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
736 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
737 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
739 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
740 return -ENOMEM; in tegra_hsp_probe()
742 if (hsp->shared_irqs) { in tegra_hsp_probe()
743 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
745 dev_err(&pdev->dev, "failed to add mailboxes: %d\n", in tegra_hsp_probe()
751 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
753 dev_err(&pdev->dev, "failed to register shared mailbox: %d\n", in tegra_hsp_probe()
760 if (hsp->doorbell_irq) { in tegra_hsp_probe()
761 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
763 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
765 dev_err(&pdev->dev, in tegra_hsp_probe()
767 hsp->doorbell_irq, err); in tegra_hsp_probe()
772 if (hsp->shared_irqs) { in tegra_hsp_probe()
787 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
788 if (db && db->channel.chan) in tegra_hsp_resume()
789 tegra_hsp_doorbell_startup(db->channel.chan); in tegra_hsp_resume()
792 if (hsp->mailboxes) { in tegra_hsp_resume()
793 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
794 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
796 if (mb->channel.chan->cl) in tegra_hsp_resume()
797 tegra_hsp_mailbox_startup(mb->channel.chan); in tegra_hsp_resume()
810 { "bpmp", TEGRA_HSP_DB_MASTER_BPMP, HSP_DB_BPMP, },
825 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
826 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
832 .name = "tegra-hsp",