Lines Matching full:hsp
17 #include <dt-bindings/mailbox/tegra186-hsp.h>
64 struct tegra_hsp *hsp; member
126 static inline u32 tegra_hsp_readl(struct tegra_hsp *hsp, unsigned int offset) in tegra_hsp_readl() argument
128 return readl(hsp->regs + offset); in tegra_hsp_readl()
131 static inline void tegra_hsp_writel(struct tegra_hsp *hsp, u32 value, in tegra_hsp_writel() argument
134 writel(value, hsp->regs + offset); in tegra_hsp_writel()
159 __tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in __tegra_hsp_doorbell_get() argument
163 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
171 tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in tegra_hsp_doorbell_get() argument
176 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
177 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_get()
178 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
185 struct tegra_hsp *hsp = data; in tegra_hsp_doorbell_irq() local
189 db = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_irq()
196 spin_lock(&hsp->lock); in tegra_hsp_doorbell_irq()
198 for_each_set_bit(master, &value, hsp->mbox_db.num_chans) { in tegra_hsp_doorbell_irq()
201 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_irq()
217 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
224 struct tegra_hsp *hsp = data; in tegra_hsp_shared_irq() local
228 status = tegra_hsp_readl(hsp, HSP_INT_IR) & hsp->mask; in tegra_hsp_shared_irq()
233 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
234 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
244 spin_lock(&hsp->lock); in tegra_hsp_shared_irq()
246 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_shared_irq()
247 tegra_hsp_writel(hsp, hsp->mask, in tegra_hsp_shared_irq()
248 HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_shared_irq()
250 spin_unlock(&hsp->lock); in tegra_hsp_shared_irq()
259 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
260 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
270 tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, in tegra_hsp_doorbell_create() argument
277 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); in tegra_hsp_doorbell_create()
281 offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; in tegra_hsp_doorbell_create()
282 offset += index * hsp->soc->reg_stride; in tegra_hsp_doorbell_create()
284 db->channel.regs = hsp->regs + offset; in tegra_hsp_doorbell_create()
285 db->channel.hsp = hsp; in tegra_hsp_doorbell_create()
287 db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL); in tegra_hsp_doorbell_create()
291 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_create()
292 list_add_tail(&db->list, &hsp->doorbells); in tegra_hsp_doorbell_create()
293 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_create()
310 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup() local
317 "invalid master ID %u for HSP channel\n", in tegra_hsp_doorbell_startup()
322 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_startup()
334 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
340 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
348 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown() local
353 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_shutdown()
357 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
363 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
456 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data() local
465 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
467 hsp->mask |= BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_send_data()
468 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_send_data()
470 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
506 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup() local
522 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
525 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
527 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
529 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
531 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
533 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
549 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown() local
552 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
561 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
564 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
566 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
568 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
570 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
583 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_db); in tegra_hsp_db_xlate() local
591 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
594 db = tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_db_xlate()
601 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
614 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
622 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_sm); in tegra_hsp_sm_xlate() local
629 !hsp->shared_irqs || index >= hsp->num_sm) in tegra_hsp_sm_xlate()
632 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
635 if (!hsp->soc->has_128_bit_mb) in tegra_hsp_sm_xlate()
651 static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp) in tegra_hsp_add_doorbells() argument
653 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
657 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
668 static int tegra_hsp_add_mailboxes(struct tegra_hsp *hsp, struct device *dev) in tegra_hsp_add_mailboxes() argument
672 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
674 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
677 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
678 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
682 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
683 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
684 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
691 static int tegra_hsp_request_shared_irq(struct tegra_hsp *hsp) in tegra_hsp_request_shared_irq() argument
696 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
697 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
701 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
702 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
704 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
709 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
712 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
714 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
719 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
720 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
729 struct tegra_hsp *hsp; in tegra_hsp_probe() local
734 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
735 if (!hsp) in tegra_hsp_probe()
738 hsp->dev = &pdev->dev; in tegra_hsp_probe()
739 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
740 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
741 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
743 hsp->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_hsp_probe()
744 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
745 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
747 value = tegra_hsp_readl(hsp, HSP_INT_DIMENSIONING); in tegra_hsp_probe()
748 hsp->num_sm = (value >> HSP_nSM_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
749 hsp->num_ss = (value >> HSP_nSS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
750 hsp->num_as = (value >> HSP_nAS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
751 hsp->num_db = (value >> HSP_nDB_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
752 hsp->num_si = (value >> HSP_nSI_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
756 hsp->doorbell_irq = err; in tegra_hsp_probe()
758 if (hsp->num_si > 0) { in tegra_hsp_probe()
761 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
762 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
764 if (!hsp->shared_irqs) in tegra_hsp_probe()
767 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
776 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
784 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
785 hsp->shared_irqs = NULL; in tegra_hsp_probe()
790 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
791 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
792 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
793 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
795 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
796 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
798 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
801 if (hsp->doorbell_irq) { in tegra_hsp_probe()
802 err = tegra_hsp_add_doorbells(hsp); in tegra_hsp_probe()
810 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
818 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
819 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
820 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
821 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
823 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
824 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
826 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
829 if (hsp->shared_irqs) { in tegra_hsp_probe()
830 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
838 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
845 platform_set_drvdata(pdev, hsp); in tegra_hsp_probe()
847 if (hsp->doorbell_irq) { in tegra_hsp_probe()
848 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
850 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
854 hsp->doorbell_irq, err); in tegra_hsp_probe()
859 if (hsp->shared_irqs) { in tegra_hsp_probe()
860 err = tegra_hsp_request_shared_irq(hsp); in tegra_hsp_probe()
865 lockdep_register_key(&hsp->lock_key); in tegra_hsp_probe()
866 lockdep_set_class(&hsp->lock, &hsp->lock_key); in tegra_hsp_probe()
873 struct tegra_hsp *hsp = platform_get_drvdata(pdev); in tegra_hsp_remove() local
875 lockdep_unregister_key(&hsp->lock_key); in tegra_hsp_remove()
880 struct tegra_hsp *hsp = dev_get_drvdata(dev); in tegra_hsp_resume() local
884 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
889 if (hsp->mailboxes) { in tegra_hsp_resume()
890 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
891 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
940 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
941 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
942 { .compatible = "nvidia,tegra234-hsp", .data = &tegra234_hsp_soc },
943 { .compatible = "nvidia,tegra264-hsp", .data = &tegra264_hsp_soc },
949 .name = "tegra-hsp",