Lines Matching full:hsp
18 #include <dt-bindings/mailbox/tegra186-hsp.h>
57 struct tegra_hsp *hsp; member
109 static inline u32 tegra_hsp_readl(struct tegra_hsp *hsp, unsigned int offset) in tegra_hsp_readl() argument
111 return readl(hsp->regs + offset); in tegra_hsp_readl()
114 static inline void tegra_hsp_writel(struct tegra_hsp *hsp, u32 value, in tegra_hsp_writel() argument
117 writel(value, hsp->regs + offset); in tegra_hsp_writel()
142 __tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in __tegra_hsp_doorbell_get() argument
146 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
154 tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in tegra_hsp_doorbell_get() argument
159 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
160 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_get()
161 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
168 struct tegra_hsp *hsp = data; in tegra_hsp_doorbell_irq() local
172 db = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); 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()
184 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_irq()
200 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
207 struct tegra_hsp *hsp = data; in tegra_hsp_shared_irq() local
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()
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()
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()
271 tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, in tegra_hsp_doorbell_create() argument
278 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); 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()
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()
311 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup() local
318 "invalid master ID %u for HSP channel\n", in tegra_hsp_doorbell_startup()
323 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_startup()
335 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
341 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
349 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown() local
354 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_shutdown()
358 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
364 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
376 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data() local
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()
431 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup() local
447 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
450 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
452 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
454 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
456 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
458 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
474 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown() local
477 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
486 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
489 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
491 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
493 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
495 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
508 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_db); in tegra_hsp_db_xlate() local
516 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
519 db = tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_db_xlate()
526 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
539 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
547 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_sm); in tegra_hsp_sm_xlate() local
553 if (type != TEGRA_HSP_MBOX_TYPE_SM || !hsp->shared_irqs || in tegra_hsp_sm_xlate()
554 index >= hsp->num_sm) in tegra_hsp_sm_xlate()
557 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
567 static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp) in tegra_hsp_add_doorbells() argument
569 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
573 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
584 static int tegra_hsp_add_mailboxes(struct tegra_hsp *hsp, struct device *dev) in tegra_hsp_add_mailboxes() argument
588 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
590 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
593 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
594 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
598 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
599 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
600 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
607 static int tegra_hsp_request_shared_irq(struct tegra_hsp *hsp) in tegra_hsp_request_shared_irq() argument
612 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
613 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
617 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
618 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
620 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
625 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
628 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
630 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
635 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
636 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
645 struct tegra_hsp *hsp; in tegra_hsp_probe() local
651 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
652 if (!hsp) in tegra_hsp_probe()
655 hsp->dev = &pdev->dev; in tegra_hsp_probe()
656 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
657 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
658 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
661 hsp->regs = devm_ioremap_resource(&pdev->dev, res); in tegra_hsp_probe()
662 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
663 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
665 value = tegra_hsp_readl(hsp, HSP_INT_DIMENSIONING); in tegra_hsp_probe()
666 hsp->num_sm = (value >> HSP_nSM_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
667 hsp->num_ss = (value >> HSP_nSS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
668 hsp->num_as = (value >> HSP_nAS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
669 hsp->num_db = (value >> HSP_nDB_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
670 hsp->num_si = (value >> HSP_nSI_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
674 hsp->doorbell_irq = err; in tegra_hsp_probe()
676 if (hsp->num_si > 0) { in tegra_hsp_probe()
679 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
680 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
682 if (!hsp->shared_irqs) in tegra_hsp_probe()
685 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
694 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
702 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
703 hsp->shared_irqs = NULL; in tegra_hsp_probe()
708 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
709 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
710 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
711 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
713 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
714 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
716 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
719 if (hsp->doorbell_irq) { in tegra_hsp_probe()
720 err = tegra_hsp_add_doorbells(hsp); in tegra_hsp_probe()
728 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
736 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
737 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
738 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
739 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
741 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
742 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
744 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
747 if (hsp->shared_irqs) { in tegra_hsp_probe()
748 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
756 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
763 platform_set_drvdata(pdev, hsp); in tegra_hsp_probe()
765 if (hsp->doorbell_irq) { in tegra_hsp_probe()
766 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
768 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
772 hsp->doorbell_irq, err); in tegra_hsp_probe()
777 if (hsp->shared_irqs) { in tegra_hsp_probe()
778 err = tegra_hsp_request_shared_irq(hsp); in tegra_hsp_probe()
788 struct tegra_hsp *hsp = dev_get_drvdata(dev); in tegra_hsp_resume() local
792 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
797 if (hsp->mailboxes) { in tegra_hsp_resume()
798 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
799 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
830 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
831 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
837 .name = "tegra-hsp",