Lines Matching full:hsp

17 #include <dt-bindings/mailbox/tegra186-hsp.h>
58 struct tegra_hsp *hsp; member
134 static inline u32 tegra_hsp_readl(struct tegra_hsp *hsp, unsigned int offset) in tegra_hsp_readl() argument
136 return readl(hsp->regs + offset); in tegra_hsp_readl()
139 static inline void tegra_hsp_writel(struct tegra_hsp *hsp, u32 value, in tegra_hsp_writel() argument
142 writel(value, hsp->regs + offset); in tegra_hsp_writel()
167 __tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in __tegra_hsp_doorbell_get() argument
171 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
179 tegra_hsp_doorbell_get(struct tegra_hsp *hsp, unsigned int master) in tegra_hsp_doorbell_get() argument
184 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
185 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_get()
186 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
193 struct tegra_hsp *hsp = data; in tegra_hsp_doorbell_irq() local
197 db = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_irq()
204 spin_lock(&hsp->lock); in tegra_hsp_doorbell_irq()
206 for_each_set_bit(master, &value, hsp->mbox_db.num_chans) { in tegra_hsp_doorbell_irq()
209 db = __tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_doorbell_irq()
225 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
232 struct tegra_hsp *hsp = data; in tegra_hsp_shared_irq() local
236 status = tegra_hsp_readl(hsp, HSP_INT_IR) & hsp->mask; in tegra_hsp_shared_irq()
241 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
242 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
252 spin_lock(&hsp->lock); in tegra_hsp_shared_irq()
254 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_shared_irq()
255 tegra_hsp_writel(hsp, hsp->mask, in tegra_hsp_shared_irq()
256 HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_shared_irq()
258 spin_unlock(&hsp->lock); in tegra_hsp_shared_irq()
267 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
268 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
278 tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, in tegra_hsp_doorbell_create() argument
285 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); in tegra_hsp_doorbell_create()
289 offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; in tegra_hsp_doorbell_create()
290 offset += index * hsp->soc->reg_stride; in tegra_hsp_doorbell_create()
292 db->channel.regs = hsp->regs + offset; in tegra_hsp_doorbell_create()
293 db->channel.hsp = hsp; in tegra_hsp_doorbell_create()
295 db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL); in tegra_hsp_doorbell_create()
299 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_create()
300 list_add_tail(&db->list, &hsp->doorbells); in tegra_hsp_doorbell_create()
301 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_create()
318 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup() local
325 "invalid master ID %u for HSP channel\n", in tegra_hsp_doorbell_startup()
330 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_startup()
342 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
348 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
356 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown() local
361 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_shutdown()
365 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
371 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
466 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data() local
475 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
477 hsp->mask |= BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_send_data()
478 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_send_data()
480 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
516 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup() local
532 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
535 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
537 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
539 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
541 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
543 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
559 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown() local
562 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
571 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
574 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
576 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
578 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
580 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
593 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_db); in tegra_hsp_db_xlate() local
601 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
604 db = tegra_hsp_doorbell_get(hsp, master); in tegra_hsp_db_xlate()
611 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
624 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
632 struct tegra_hsp *hsp = container_of(mbox, struct tegra_hsp, mbox_sm); in tegra_hsp_sm_xlate() local
639 !hsp->shared_irqs || index >= hsp->num_sm) in tegra_hsp_sm_xlate()
642 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
645 if (!hsp->soc->has_128_bit_mb) in tegra_hsp_sm_xlate()
661 static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp) in tegra_hsp_add_doorbells() argument
663 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
667 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
678 static int tegra_hsp_add_mailboxes(struct tegra_hsp *hsp, struct device *dev) in tegra_hsp_add_mailboxes() argument
682 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
684 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
687 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
688 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
692 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
693 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
694 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
701 static int tegra_hsp_request_shared_irq(struct tegra_hsp *hsp) in tegra_hsp_request_shared_irq() argument
706 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
707 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
711 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
712 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
714 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
719 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
722 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
724 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
729 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
730 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
739 struct tegra_hsp *hsp; in tegra_hsp_probe() local
744 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
745 if (!hsp) in tegra_hsp_probe()
748 hsp->dev = &pdev->dev; in tegra_hsp_probe()
749 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
750 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
751 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
753 hsp->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_hsp_probe()
754 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
755 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
757 value = tegra_hsp_readl(hsp, HSP_INT_DIMENSIONING); in tegra_hsp_probe()
758 hsp->num_sm = (value >> hsp->soc->sm_shift) & hsp->soc->sm_mask; in tegra_hsp_probe()
759 hsp->num_ss = (value >> hsp->soc->ss_shift) & hsp->soc->ss_mask; in tegra_hsp_probe()
760 hsp->num_as = (value >> hsp->soc->as_shift) & hsp->soc->as_mask; in tegra_hsp_probe()
761 hsp->num_db = (value >> hsp->soc->db_shift) & hsp->soc->db_mask; in tegra_hsp_probe()
762 hsp->num_si = (value >> hsp->soc->si_shift) & hsp->soc->si_mask; in tegra_hsp_probe()
766 hsp->doorbell_irq = err; in tegra_hsp_probe()
768 if (hsp->num_si > 0) { in tegra_hsp_probe()
771 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
772 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
774 if (!hsp->shared_irqs) in tegra_hsp_probe()
777 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
786 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
794 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
795 hsp->shared_irqs = NULL; in tegra_hsp_probe()
800 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
801 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
802 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
803 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
805 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
806 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
808 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
811 if (hsp->doorbell_irq) { in tegra_hsp_probe()
812 err = tegra_hsp_add_doorbells(hsp); in tegra_hsp_probe()
820 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
828 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
829 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
830 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
831 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
833 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
834 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
836 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
839 if (hsp->shared_irqs) { in tegra_hsp_probe()
840 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
848 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
855 platform_set_drvdata(pdev, hsp); in tegra_hsp_probe()
857 if (hsp->doorbell_irq) { in tegra_hsp_probe()
858 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
860 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
864 hsp->doorbell_irq, err); in tegra_hsp_probe()
869 if (hsp->shared_irqs) { in tegra_hsp_probe()
870 err = tegra_hsp_request_shared_irq(hsp); in tegra_hsp_probe()
875 lockdep_register_key(&hsp->lock_key); in tegra_hsp_probe()
876 lockdep_set_class(&hsp->lock, &hsp->lock_key); in tegra_hsp_probe()
883 struct tegra_hsp *hsp = platform_get_drvdata(pdev); in tegra_hsp_remove() local
885 lockdep_unregister_key(&hsp->lock_key); in tegra_hsp_remove()
890 struct tegra_hsp *hsp = dev_get_drvdata(dev); in tegra_hsp_resume() local
894 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
899 if (hsp->mailboxes) { in tegra_hsp_resume()
900 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
901 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
990 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
991 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
992 { .compatible = "nvidia,tegra234-hsp", .data = &tegra234_hsp_soc },
993 { .compatible = "nvidia,tegra264-hsp", .data = &tegra264_hsp_soc },
999 .name = "tegra-hsp",