Lines Matching full:hsp

17 #include <dt-bindings/mailbox/tegra186-hsp.h>
56 struct tegra_hsp *hsp; member
132 static inline u32 tegra_hsp_readl(struct tegra_hsp *hsp, unsigned int offset) in tegra_hsp_readl() argument
134 return readl(hsp->regs + offset); in tegra_hsp_readl()
137 static inline void tegra_hsp_writel(struct tegra_hsp *hsp, u32 value, in tegra_hsp_writel() argument
140 writel(value, hsp->regs + offset); in tegra_hsp_writel()
165 __tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in __tegra_hsp_doorbell_get() argument
169 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
177 tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in tegra_hsp_doorbell_get() argument
182 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
183 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_get()
184 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
191 struct tegra_hsp *hsp = data; in tegra_hsp_doorbell_irq() local
195 db = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_irq()
202 spin_lock(&hsp->lock); in tegra_hsp_doorbell_irq()
204 for_each_set_bit(master, &value, hsp->mbox_db.num_chans) { in tegra_hsp_doorbell_irq()
207 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_irq()
223 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
230 struct tegra_hsp *hsp = data; in tegra_hsp_shared_irq() local
234 status = tegra_hsp_readl(hsp, HSP_INT_IR) & hsp->mask; in tegra_hsp_shared_irq()
239 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
240 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
250 spin_lock(&hsp->lock); in tegra_hsp_shared_irq()
252 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_shared_irq()
253 tegra_hsp_writel(hsp, hsp->mask, in tegra_hsp_shared_irq()
254 HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_shared_irq()
256 spin_unlock(&hsp->lock); in tegra_hsp_shared_irq()
265 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
266 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
276 tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, in tegra_hsp_doorbell_create() argument
283 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); in tegra_hsp_doorbell_create()
287 offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; in tegra_hsp_doorbell_create()
288 offset += index * hsp->soc->reg_stride; in tegra_hsp_doorbell_create()
290 db->channel.regs = hsp->regs + offset; in tegra_hsp_doorbell_create()
291 db->channel.hsp = hsp; in tegra_hsp_doorbell_create()
293 db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL); in tegra_hsp_doorbell_create()
297 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_create()
298 list_add_tail(&db->list, &hsp->doorbells); in tegra_hsp_doorbell_create()
299 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_create()
316 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup() local
323 "invalid master ID %u for HSP channel\n", in tegra_hsp_doorbell_startup()
328 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_startup()
340 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
346 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
354 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown() local
359 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_shutdown()
363 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
369 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
464 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data() local
473 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
475 hsp->mask |= BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_send_data()
476 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_send_data()
478 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
514 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup() local
530 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
533 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
535 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
537 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
539 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
541 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
557 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown() local
560 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
569 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
572 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
574 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
576 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
578 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
591 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_db); in tegra_hsp_db_xlate() local
599 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
602 db = tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_db_xlate()
609 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
622 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
630 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_sm); in tegra_hsp_sm_xlate() local
637 !hsp->shared_irqs || index >= hsp->num_sm) in tegra_hsp_sm_xlate()
640 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
643 if (!hsp->soc->has_128_bit_mb) in tegra_hsp_sm_xlate()
659 static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp) in tegra_hsp_add_doorbells() argument
661 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
665 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
676 static int tegra_hsp_add_mailboxes(struct tegra_hsp *hsp, struct device *dev) in tegra_hsp_add_mailboxes() argument
680 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
682 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
685 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
686 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
690 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
691 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
692 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
699 static int tegra_hsp_request_shared_irq(struct tegra_hsp *hsp) in tegra_hsp_request_shared_irq() argument
704 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
705 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
709 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
710 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
712 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
717 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
720 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
722 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
727 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
728 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
737 struct tegra_hsp *hsp; in tegra_hsp_probe() local
742 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
743 if (!hsp) in tegra_hsp_probe()
746 hsp->dev = &pdev->dev; in tegra_hsp_probe()
747 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
748 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
749 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
751 hsp->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_hsp_probe()
752 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
753 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
755 value = tegra_hsp_readl(hsp, HSP_INT_DIMENSIONING); in tegra_hsp_probe()
756 hsp->num_sm = (value >> hsp->soc->sm_shift) & hsp->soc->sm_mask; in tegra_hsp_probe()
757 hsp->num_ss = (value >> hsp->soc->ss_shift) & hsp->soc->ss_mask; in tegra_hsp_probe()
758 hsp->num_as = (value >> hsp->soc->as_shift) & hsp->soc->as_mask; in tegra_hsp_probe()
759 hsp->num_db = (value >> hsp->soc->db_shift) & hsp->soc->db_mask; in tegra_hsp_probe()
760 hsp->num_si = (value >> hsp->soc->si_shift) & hsp->soc->si_mask; in tegra_hsp_probe()
764 hsp->doorbell_irq = err; in tegra_hsp_probe()
766 if (hsp->num_si > 0) { in tegra_hsp_probe()
769 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
770 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
772 if (!hsp->shared_irqs) in tegra_hsp_probe()
775 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
784 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
792 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
793 hsp->shared_irqs = NULL; in tegra_hsp_probe()
798 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
799 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
800 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
801 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
803 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
804 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
806 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
809 if (hsp->doorbell_irq) { in tegra_hsp_probe()
810 err = tegra_hsp_add_doorbells(hsp); in tegra_hsp_probe()
818 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
826 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
827 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
828 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
829 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
831 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
832 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
834 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
837 if (hsp->shared_irqs) { in tegra_hsp_probe()
838 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
846 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
853 platform_set_drvdata(pdev, hsp); in tegra_hsp_probe()
855 if (hsp->doorbell_irq) { in tegra_hsp_probe()
856 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
858 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
862 hsp->doorbell_irq, err); in tegra_hsp_probe()
867 if (hsp->shared_irqs) { in tegra_hsp_probe()
868 err = tegra_hsp_request_shared_irq(hsp); in tegra_hsp_probe()
873 lockdep_register_key(&hsp->lock_key); in tegra_hsp_probe()
874 lockdep_set_class(&hsp->lock, &hsp->lock_key); in tegra_hsp_probe()
881 struct tegra_hsp *hsp = platform_get_drvdata(pdev); in tegra_hsp_remove() local
883 lockdep_unregister_key(&hsp->lock_key); in tegra_hsp_remove()
888 struct tegra_hsp *hsp = dev_get_drvdata(dev); in tegra_hsp_resume() local
892 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
897 if (hsp->mailboxes) { in tegra_hsp_resume()
898 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
899 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
988 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
989 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
990 { .compatible = "nvidia,tegra234-hsp", .data = &tegra234_hsp_soc },
991 { .compatible = "nvidia,tegra264-hsp", .data = &tegra264_hsp_soc },
997 .name = "tegra-hsp",