Lines Matching full:bpmp

18 #include <soc/tegra/bpmp.h>
19 #include <soc/tegra/bpmp-abi.h>
22 #include "bpmp-private.h"
31 struct tegra_bpmp *bpmp = channel->bpmp; in channel_to_ops() local
33 return bpmp->soc->ops; in channel_to_ops()
40 struct tegra_bpmp *bpmp; in tegra_bpmp_get() local
42 np = of_parse_phandle(dev->of_node, "nvidia,bpmp", 0); in tegra_bpmp_get()
50 bpmp = platform_get_drvdata(pdev); in tegra_bpmp_get()
51 if (!bpmp) { in tegra_bpmp_get()
56 return bpmp; in tegra_bpmp_get()
60 void tegra_bpmp_put(struct tegra_bpmp *bpmp) in tegra_bpmp_put() argument
62 if (bpmp) in tegra_bpmp_put()
63 put_device(bpmp->dev); in tegra_bpmp_put()
70 struct tegra_bpmp *bpmp = channel->bpmp; in tegra_bpmp_channel_get_thread_index() local
74 count = bpmp->soc->channels.thread.count; in tegra_bpmp_channel_get_thread_index()
76 index = channel - channel->bpmp->threaded_channels; in tegra_bpmp_channel_get_thread_index()
107 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout; in tegra_bpmp_wait_response()
153 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout; in tegra_bpmp_wait_request_channel_free()
182 static int tegra_bpmp_ring_doorbell(struct tegra_bpmp *bpmp) in tegra_bpmp_ring_doorbell() argument
184 return bpmp->soc->ops->ring_doorbell(bpmp); in tegra_bpmp_ring_doorbell()
207 struct tegra_bpmp *bpmp = channel->bpmp; in tegra_bpmp_channel_read() local
218 spin_lock_irqsave(&bpmp->lock, flags); in tegra_bpmp_channel_read()
220 clear_bit(index, bpmp->threaded.allocated); in tegra_bpmp_channel_read()
221 spin_unlock_irqrestore(&bpmp->lock, flags); in tegra_bpmp_channel_read()
224 up(&bpmp->threaded.lock); in tegra_bpmp_channel_read()
243 tegra_bpmp_write_threaded(struct tegra_bpmp *bpmp, unsigned int mrq, in tegra_bpmp_write_threaded() argument
246 unsigned long timeout = bpmp->soc->channels.thread.timeout; in tegra_bpmp_write_threaded()
247 unsigned int count = bpmp->soc->channels.thread.count; in tegra_bpmp_write_threaded()
253 err = down_timeout(&bpmp->threaded.lock, usecs_to_jiffies(timeout)); in tegra_bpmp_write_threaded()
257 spin_lock_irqsave(&bpmp->lock, flags); in tegra_bpmp_write_threaded()
259 index = find_first_zero_bit(bpmp->threaded.allocated, count); in tegra_bpmp_write_threaded()
265 channel = &bpmp->threaded_channels[index]; in tegra_bpmp_write_threaded()
272 set_bit(index, bpmp->threaded.allocated); in tegra_bpmp_write_threaded()
279 set_bit(index, bpmp->threaded.busy); in tegra_bpmp_write_threaded()
281 spin_unlock_irqrestore(&bpmp->lock, flags); in tegra_bpmp_write_threaded()
285 clear_bit(index, bpmp->threaded.allocated); in tegra_bpmp_write_threaded()
287 spin_unlock_irqrestore(&bpmp->lock, flags); in tegra_bpmp_write_threaded()
288 up(&bpmp->threaded.lock); in tegra_bpmp_write_threaded()
308 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp, in tegra_bpmp_transfer_atomic() argument
320 if (bpmp->suspended) { in tegra_bpmp_transfer_atomic()
321 /* Reset BPMP IPC channels during resume based on flags passed */ in tegra_bpmp_transfer_atomic()
323 tegra_bpmp_resume(bpmp->dev); in tegra_bpmp_transfer_atomic()
328 channel = bpmp->tx_channel; in tegra_bpmp_transfer_atomic()
330 spin_lock(&bpmp->atomic_tx_lock); in tegra_bpmp_transfer_atomic()
335 spin_unlock(&bpmp->atomic_tx_lock); in tegra_bpmp_transfer_atomic()
339 spin_unlock(&bpmp->atomic_tx_lock); in tegra_bpmp_transfer_atomic()
341 err = tegra_bpmp_ring_doorbell(bpmp); in tegra_bpmp_transfer_atomic()
354 int tegra_bpmp_transfer(struct tegra_bpmp *bpmp, in tegra_bpmp_transfer() argument
367 if (bpmp->suspended) { in tegra_bpmp_transfer()
368 /* Reset BPMP IPC channels during resume based on flags passed */ in tegra_bpmp_transfer()
370 tegra_bpmp_resume(bpmp->dev); in tegra_bpmp_transfer()
375 channel = tegra_bpmp_write_threaded(bpmp, msg->mrq, msg->tx.data, in tegra_bpmp_transfer()
380 err = tegra_bpmp_ring_doorbell(bpmp); in tegra_bpmp_transfer()
384 timeout = usecs_to_jiffies(bpmp->soc->channels.thread.timeout); in tegra_bpmp_transfer()
395 static struct tegra_bpmp_mrq *tegra_bpmp_find_mrq(struct tegra_bpmp *bpmp, in tegra_bpmp_find_mrq() argument
400 list_for_each_entry(entry, &bpmp->mrqs, list) in tegra_bpmp_find_mrq()
411 struct tegra_bpmp *bpmp = channel->bpmp; in tegra_bpmp_mrq_return() local
437 err = tegra_bpmp_ring_doorbell(bpmp); in tegra_bpmp_mrq_return()
444 static void tegra_bpmp_handle_mrq(struct tegra_bpmp *bpmp, in tegra_bpmp_handle_mrq() argument
451 spin_lock(&bpmp->lock); in tegra_bpmp_handle_mrq()
453 entry = tegra_bpmp_find_mrq(bpmp, mrq); in tegra_bpmp_handle_mrq()
455 spin_unlock(&bpmp->lock); in tegra_bpmp_handle_mrq()
462 spin_unlock(&bpmp->lock); in tegra_bpmp_handle_mrq()
465 int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq, in tegra_bpmp_request_mrq() argument
474 entry = devm_kzalloc(bpmp->dev, sizeof(*entry), GFP_KERNEL); in tegra_bpmp_request_mrq()
478 spin_lock_irqsave(&bpmp->lock, flags); in tegra_bpmp_request_mrq()
483 list_add(&entry->list, &bpmp->mrqs); in tegra_bpmp_request_mrq()
485 spin_unlock_irqrestore(&bpmp->lock, flags); in tegra_bpmp_request_mrq()
491 void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq, void *data) in tegra_bpmp_free_mrq() argument
496 spin_lock_irqsave(&bpmp->lock, flags); in tegra_bpmp_free_mrq()
498 entry = tegra_bpmp_find_mrq(bpmp, mrq); in tegra_bpmp_free_mrq()
503 devm_kfree(bpmp->dev, entry); in tegra_bpmp_free_mrq()
506 spin_unlock_irqrestore(&bpmp->lock, flags); in tegra_bpmp_free_mrq()
510 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq) in tegra_bpmp_mrq_is_supported() argument
527 err = tegra_bpmp_transfer(bpmp, &msg); in tegra_bpmp_mrq_is_supported()
550 static int tegra_bpmp_ping(struct tegra_bpmp *bpmp) in tegra_bpmp_ping() argument
573 err = tegra_bpmp_transfer_atomic(bpmp, &msg); in tegra_bpmp_ping()
578 dev_dbg(bpmp->dev, in tegra_bpmp_ping()
587 static int tegra_bpmp_get_firmware_tag_old(struct tegra_bpmp *bpmp, char *tag, in tegra_bpmp_get_firmware_tag_old() argument
600 virt = dma_alloc_coherent(bpmp->dev, TAG_SZ, &phys, in tegra_bpmp_get_firmware_tag_old()
614 err = tegra_bpmp_transfer_atomic(bpmp, &msg); in tegra_bpmp_get_firmware_tag_old()
620 dma_free_coherent(bpmp->dev, TAG_SZ, virt, phys); in tegra_bpmp_get_firmware_tag_old()
625 static int tegra_bpmp_get_firmware_tag(struct tegra_bpmp *bpmp, char *tag, in tegra_bpmp_get_firmware_tag() argument
628 if (tegra_bpmp_mrq_is_supported(bpmp, MRQ_QUERY_FW_TAG)) { in tegra_bpmp_get_firmware_tag()
642 err = tegra_bpmp_transfer(bpmp, &msg); in tegra_bpmp_get_firmware_tag()
653 return tegra_bpmp_get_firmware_tag_old(bpmp, tag, size); in tegra_bpmp_get_firmware_tag()
666 void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp) in tegra_bpmp_handle_rx() argument
672 channel = bpmp->rx_channel; in tegra_bpmp_handle_rx()
673 count = bpmp->soc->channels.thread.count; in tegra_bpmp_handle_rx()
674 busy = bpmp->threaded.busy; in tegra_bpmp_handle_rx()
679 tegra_bpmp_handle_mrq(bpmp, mrq, channel); in tegra_bpmp_handle_rx()
682 spin_lock(&bpmp->lock); in tegra_bpmp_handle_rx()
687 channel = &bpmp->threaded_channels[i]; in tegra_bpmp_handle_rx()
695 spin_unlock(&bpmp->lock); in tegra_bpmp_handle_rx()
700 struct tegra_bpmp *bpmp; in tegra_bpmp_probe() local
705 bpmp = devm_kzalloc(&pdev->dev, sizeof(*bpmp), GFP_KERNEL); in tegra_bpmp_probe()
706 if (!bpmp) in tegra_bpmp_probe()
709 bpmp->soc = of_device_get_match_data(&pdev->dev); in tegra_bpmp_probe()
710 bpmp->dev = &pdev->dev; in tegra_bpmp_probe()
712 INIT_LIST_HEAD(&bpmp->mrqs); in tegra_bpmp_probe()
713 spin_lock_init(&bpmp->lock); in tegra_bpmp_probe()
715 bpmp->threaded.count = bpmp->soc->channels.thread.count; in tegra_bpmp_probe()
716 sema_init(&bpmp->threaded.lock, bpmp->threaded.count); in tegra_bpmp_probe()
718 size = BITS_TO_LONGS(bpmp->threaded.count) * sizeof(long); in tegra_bpmp_probe()
720 bpmp->threaded.allocated = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in tegra_bpmp_probe()
721 if (!bpmp->threaded.allocated) in tegra_bpmp_probe()
724 bpmp->threaded.busy = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in tegra_bpmp_probe()
725 if (!bpmp->threaded.busy) in tegra_bpmp_probe()
728 spin_lock_init(&bpmp->atomic_tx_lock); in tegra_bpmp_probe()
729 bpmp->tx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->tx_channel), in tegra_bpmp_probe()
731 if (!bpmp->tx_channel) in tegra_bpmp_probe()
734 bpmp->rx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->rx_channel), in tegra_bpmp_probe()
736 if (!bpmp->rx_channel) in tegra_bpmp_probe()
739 bpmp->threaded_channels = devm_kcalloc(&pdev->dev, bpmp->threaded.count, in tegra_bpmp_probe()
740 sizeof(*bpmp->threaded_channels), in tegra_bpmp_probe()
742 if (!bpmp->threaded_channels) in tegra_bpmp_probe()
745 platform_set_drvdata(pdev, bpmp); in tegra_bpmp_probe()
747 err = bpmp->soc->ops->init(bpmp); in tegra_bpmp_probe()
751 err = tegra_bpmp_request_mrq(bpmp, MRQ_PING, in tegra_bpmp_probe()
752 tegra_bpmp_mrq_handle_ping, bpmp); in tegra_bpmp_probe()
756 err = tegra_bpmp_ping(bpmp); in tegra_bpmp_probe()
758 dev_err(&pdev->dev, "failed to ping BPMP: %d\n", err); in tegra_bpmp_probe()
762 err = tegra_bpmp_get_firmware_tag(bpmp, tag, sizeof(tag)); in tegra_bpmp_probe()
775 err = tegra_bpmp_init_clocks(bpmp); in tegra_bpmp_probe()
781 err = tegra_bpmp_init_resets(bpmp); in tegra_bpmp_probe()
787 err = tegra_bpmp_init_powergates(bpmp); in tegra_bpmp_probe()
792 err = tegra_bpmp_init_debugfs(bpmp); in tegra_bpmp_probe()
799 tegra_bpmp_free_mrq(bpmp, MRQ_PING, bpmp); in tegra_bpmp_probe()
801 if (bpmp->soc->ops->deinit) in tegra_bpmp_probe()
802 bpmp->soc->ops->deinit(bpmp); in tegra_bpmp_probe()
809 struct tegra_bpmp *bpmp = dev_get_drvdata(dev); in tegra_bpmp_suspend() local
811 bpmp->suspended = true; in tegra_bpmp_suspend()
818 struct tegra_bpmp *bpmp = dev_get_drvdata(dev); in tegra_bpmp_resume() local
820 bpmp->suspended = false; in tegra_bpmp_resume()
822 if (bpmp->soc->ops->resume) in tegra_bpmp_resume()
823 return bpmp->soc->ops->resume(bpmp); in tegra_bpmp_resume()
884 { .compatible = "nvidia,tegra186-bpmp", .data = &tegra186_soc },
887 { .compatible = "nvidia,tegra210-bpmp", .data = &tegra210_soc },
894 .name = "tegra-bpmp",