firmware: tegra: Changes for v6.5-rc1

This adds support for using system memory as shared memory between the
 CPU and the BPMP, which will be needed for Tegra264 support.
 -----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCAAxFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAmSDRD0THHRyZWRpbmdA
 bnZpZGlhLmNvbQAKCRDdI6zXfz6zoc7MEAC7nU4P96tevI2AyS4b2LCPW/Rk969y
 PSHxZQuewhGysy+zmwrxy+dpJ0ONfD6ae8lQ1p0XXITDC2Z5yHJASgmbuxznS4gl
 OVn3PjB+GXVLYbz3B2HZW/lPN/t6w3mDcjmH3XJ5wuGdlV0PAJy4V9I+WJIKFAGq
 m26NpfkwsQnC99weCQd8F6/m+tAU54bLBULipv/nv6pbBoc7222+PGiC4dXrTR32
 WZiSiqcKXpweMeGcPRiKXokgvn2PphbawQxQf9Ejh9ufWpB3ddrWHniY5obv8Vnj
 MBYXsL1QVoGo/d1FXbFgw2Vx4F9FXZQh3YHIR3dFf57ytwhZHwqKFFJSL4LoA1bH
 CD+IDrtgXte+mo6VcoPXbkaPNmMEzLRRLSqOoKsWnQHadhF5PGoDLSZ8yb3/QME+
 PP7VgLRgvLP8u7aY6+foNktBrY9KJfXvZa9YXOISHz5CNtXNuc0rBw0wTTdnSt/v
 VYbDP+5s++8fWFr/dd+q2NaZxGoM6ZUNDsVMn1g9AFnYxEKc7KVn6XJVijFWeqFu
 TkPDLfvp0/x+6lwTYa19s7w2cTB+fUPKIqlpWR66QZ+MZb76RRE0Ymp+hCleK6PY
 5nn/7UpfP38RS+EoL11zedcQ329MgLmrBNWjAzpJEdLGCDkEIZRw7pXg1P2EWsJS
 f8gyVgb5O2RGYw==
 =fwZn
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEiK/NIGsWEZVxh/FrYKtH/8kJUicFAmSTU7cACgkQYKtH/8kJ
 UieF4xAA43v/+kPsHfZoBhzM+DlLQUQhsQMzIrH/xncDd+Pw8zvtxGIpQy4Ubq/c
 kORhtyVHiIiDzFa6zg9pb24YIBAm3irkVIq9bBUlrCaWT5ias32FGyvZjaSwqhC1
 MyeRZ4GT9AkJ0SucAS8sGy0VcP3r+utfeXzimXb46kXXKX4styMn5QDMbzwjJN2x
 RJd6PhzE0rleujQ8/YfTKwdIc6I8i+RM2LdoAK/AVnSeVBkFciWGsqxydEmdlSiD
 a06N075zOBK+GW4DNF/IrxcAyk3Q7FrCNDRrkJABN/DTG0EYGwZSFuBquE2TweGc
 5+HwDAjFZnuOZsqqfAb0jWsprkGhEa7Ahur45W48I/Iyfo1ZkxZjn/yFgJVbYw8V
 V/7Rfe9mI09SAVR2qRYiQcUGhhGK/ityuNk5xTY8xr/ob3EO17UibwX0s0FiPfX6
 kq8SL4LWKoy4azDNtm1+Xdew5cAqWFZhxLXgwlXuym7FUoSotzP/aMCujM4tno/p
 Hc5ZtlVPyAJQbRz4YoWEANU2FLUUkq1FOZ4n8IF9hQ8AZIQ5Ujc7p4MY8o6gqByn
 4JW0+Vw9tF9fl1Y/kUkjSdsUryt0bFlBEdJK101tFHpTLDRqMd4IbWDmtRP0rRsC
 iYYv/16JU49Eez4fYflEbDGvAVfn1L0C3Tey7jhwToLzxUVbkhc=
 =3AXn
 -----END PGP SIGNATURE-----

Merge tag 'tegra-for-6.5-firmware' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux into soc/drivers

firmware: tegra: Changes for v6.5-rc1

This adds support for using system memory as shared memory between the
CPU and the BPMP, which will be needed for Tegra264 support.

* tag 'tegra-for-6.5-firmware' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux:
  firmware: tegra: bpmp: Add support for DRAM MRQ GSCs

Link: https://lore.kernel.org/r/20230609193620.2275240-2-thierry.reding@gmail.com
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2023-06-21 21:47:02 +02:00
commit b161ec3d38
2 changed files with 147 additions and 61 deletions

View File

@ -4,7 +4,9 @@
*/
#include <linux/genalloc.h>
#include <linux/io.h>
#include <linux/mailbox_client.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <soc/tegra/bpmp.h>
@ -18,7 +20,10 @@ struct tegra186_bpmp {
struct {
struct gen_pool *pool;
void __iomem *virt;
union {
void __iomem *sram;
void *dram;
};
dma_addr_t phys;
} tx, rx;
@ -118,8 +123,13 @@ static int tegra186_bpmp_channel_init(struct tegra_bpmp_channel *channel,
queue_size = tegra_ivc_total_queue_size(message_size);
offset = queue_size * index;
iosys_map_set_vaddr_iomem(&rx, priv->rx.virt + offset);
iosys_map_set_vaddr_iomem(&tx, priv->tx.virt + offset);
if (priv->rx.pool) {
iosys_map_set_vaddr_iomem(&rx, priv->rx.sram + offset);
iosys_map_set_vaddr_iomem(&tx, priv->tx.sram + offset);
} else {
iosys_map_set_vaddr(&rx, priv->rx.dram + offset);
iosys_map_set_vaddr(&tx, priv->tx.dram + offset);
}
err = tegra_ivc_init(channel->ivc, NULL, &rx, priv->rx.phys + offset, &tx,
priv->tx.phys + offset, 1, message_size, tegra186_bpmp_ivc_notify,
@ -158,18 +168,72 @@ static void mbox_handle_rx(struct mbox_client *client, void *data)
tegra_bpmp_handle_rx(bpmp);
}
static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
static void tegra186_bpmp_teardown_channels(struct tegra_bpmp *bpmp)
{
struct tegra186_bpmp *priv;
struct tegra186_bpmp *priv = bpmp->priv;
unsigned int i;
for (i = 0; i < bpmp->threaded.count; i++) {
if (!bpmp->threaded_channels[i].bpmp)
continue;
tegra186_bpmp_channel_cleanup(&bpmp->threaded_channels[i]);
}
tegra186_bpmp_channel_cleanup(bpmp->rx_channel);
tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
if (priv->tx.pool) {
gen_pool_free(priv->tx.pool, (unsigned long)priv->tx.sram, 4096);
gen_pool_free(priv->rx.pool, (unsigned long)priv->rx.sram, 4096);
}
}
static int tegra186_bpmp_dram_init(struct tegra_bpmp *bpmp)
{
struct tegra186_bpmp *priv = bpmp->priv;
struct device_node *np;
struct resource res;
size_t size;
int err;
priv = devm_kzalloc(bpmp->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
np = of_parse_phandle(bpmp->dev->of_node, "memory-region", 0);
if (!np)
return -ENODEV;
bpmp->priv = priv;
priv->parent = bpmp;
err = of_address_to_resource(np, 0, &res);
if (err < 0) {
dev_warn(bpmp->dev, "failed to parse memory region: %d\n", err);
return err;
}
size = resource_size(&res);
if (size < SZ_8K) {
dev_warn(bpmp->dev, "DRAM region must be larger than 8 KiB\n");
return -EINVAL;
}
priv->tx.phys = res.start;
priv->rx.phys = res.start + SZ_4K;
priv->tx.dram = devm_memremap(bpmp->dev, priv->tx.phys, size,
MEMREMAP_WC);
if (IS_ERR(priv->tx.dram)) {
err = PTR_ERR(priv->tx.dram);
dev_warn(bpmp->dev, "failed to map DRAM region: %d\n", err);
return err;
}
priv->rx.dram = priv->tx.dram + SZ_4K;
return 0;
}
static int tegra186_bpmp_sram_init(struct tegra_bpmp *bpmp)
{
struct tegra186_bpmp *priv = bpmp->priv;
int err;
priv->tx.pool = of_gen_pool_get(bpmp->dev->of_node, "shmem", 0);
if (!priv->tx.pool) {
@ -177,8 +241,9 @@ static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
return -EPROBE_DEFER;
}
priv->tx.virt = (void __iomem *)gen_pool_dma_alloc(priv->tx.pool, 4096, &priv->tx.phys);
if (!priv->tx.virt) {
priv->tx.sram = (void __iomem *)gen_pool_dma_alloc(priv->tx.pool, 4096,
&priv->tx.phys);
if (!priv->tx.sram) {
dev_err(bpmp->dev, "failed to allocate from TX pool\n");
return -ENOMEM;
}
@ -190,22 +255,45 @@ static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
goto free_tx;
}
priv->rx.virt = (void __iomem *)gen_pool_dma_alloc(priv->rx.pool, 4096, &priv->rx.phys);
if (!priv->rx.virt) {
priv->rx.sram = (void __iomem *)gen_pool_dma_alloc(priv->rx.pool, 4096,
&priv->rx.phys);
if (!priv->rx.sram) {
dev_err(bpmp->dev, "failed to allocate from RX pool\n");
err = -ENOMEM;
goto free_tx;
}
return 0;
free_tx:
gen_pool_free(priv->tx.pool, (unsigned long)priv->tx.sram, 4096);
return err;
}
static int tegra186_bpmp_setup_channels(struct tegra_bpmp *bpmp)
{
unsigned int i;
int err;
err = tegra186_bpmp_dram_init(bpmp);
if (err == -ENODEV) {
err = tegra186_bpmp_sram_init(bpmp);
if (err < 0)
return err;
}
err = tegra186_bpmp_channel_init(bpmp->tx_channel, bpmp,
bpmp->soc->channels.cpu_tx.offset);
if (err < 0)
goto free_rx;
return err;
err = tegra186_bpmp_channel_init(bpmp->rx_channel, bpmp,
bpmp->soc->channels.cpu_rx.offset);
if (err < 0)
goto cleanup_tx_channel;
if (err < 0) {
tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
return err;
}
for (i = 0; i < bpmp->threaded.count; i++) {
unsigned int index = bpmp->soc->channels.thread.offset + i;
@ -213,9 +301,43 @@ static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
err = tegra186_bpmp_channel_init(&bpmp->threaded_channels[i],
bpmp, index);
if (err < 0)
goto cleanup_channels;
break;
}
if (err < 0)
tegra186_bpmp_teardown_channels(bpmp);
return err;
}
static void tegra186_bpmp_reset_channels(struct tegra_bpmp *bpmp)
{
unsigned int i;
/* reset message channels */
tegra186_bpmp_channel_reset(bpmp->tx_channel);
tegra186_bpmp_channel_reset(bpmp->rx_channel);
for (i = 0; i < bpmp->threaded.count; i++)
tegra186_bpmp_channel_reset(&bpmp->threaded_channels[i]);
}
static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
{
struct tegra186_bpmp *priv;
int err;
priv = devm_kzalloc(bpmp->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->parent = bpmp;
bpmp->priv = priv;
err = tegra186_bpmp_setup_channels(bpmp);
if (err < 0)
return err;
/* mbox registration */
priv->mbox.client.dev = bpmp->dev;
priv->mbox.client.rx_callback = mbox_handle_rx;
@ -226,63 +348,27 @@ static int tegra186_bpmp_init(struct tegra_bpmp *bpmp)
if (IS_ERR(priv->mbox.channel)) {
err = PTR_ERR(priv->mbox.channel);
dev_err(bpmp->dev, "failed to get HSP mailbox: %d\n", err);
goto cleanup_channels;
tegra186_bpmp_teardown_channels(bpmp);
return err;
}
tegra186_bpmp_channel_reset(bpmp->tx_channel);
tegra186_bpmp_channel_reset(bpmp->rx_channel);
for (i = 0; i < bpmp->threaded.count; i++)
tegra186_bpmp_channel_reset(&bpmp->threaded_channels[i]);
tegra186_bpmp_reset_channels(bpmp);
return 0;
cleanup_channels:
for (i = 0; i < bpmp->threaded.count; i++) {
if (!bpmp->threaded_channels[i].bpmp)
continue;
tegra186_bpmp_channel_cleanup(&bpmp->threaded_channels[i]);
}
tegra186_bpmp_channel_cleanup(bpmp->rx_channel);
cleanup_tx_channel:
tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
free_rx:
gen_pool_free(priv->rx.pool, (unsigned long)priv->rx.virt, 4096);
free_tx:
gen_pool_free(priv->tx.pool, (unsigned long)priv->tx.virt, 4096);
return err;
}
static void tegra186_bpmp_deinit(struct tegra_bpmp *bpmp)
{
struct tegra186_bpmp *priv = bpmp->priv;
unsigned int i;
mbox_free_channel(priv->mbox.channel);
for (i = 0; i < bpmp->threaded.count; i++)
tegra186_bpmp_channel_cleanup(&bpmp->threaded_channels[i]);
tegra186_bpmp_channel_cleanup(bpmp->rx_channel);
tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
gen_pool_free(priv->rx.pool, (unsigned long)priv->rx.virt, 4096);
gen_pool_free(priv->tx.pool, (unsigned long)priv->tx.virt, 4096);
tegra186_bpmp_teardown_channels(bpmp);
}
static int tegra186_bpmp_resume(struct tegra_bpmp *bpmp)
{
unsigned int i;
/* reset message channels */
tegra186_bpmp_channel_reset(bpmp->tx_channel);
tegra186_bpmp_channel_reset(bpmp->rx_channel);
for (i = 0; i < bpmp->threaded.count; i++)
tegra186_bpmp_channel_reset(&bpmp->threaded_channels[i]);
tegra186_bpmp_reset_channels(bpmp);
return 0;
}

View File

@ -735,6 +735,8 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
if (!bpmp->threaded_channels)
return -ENOMEM;
platform_set_drvdata(pdev, bpmp);
err = bpmp->soc->ops->init(bpmp);
if (err < 0)
return err;
@ -758,8 +760,6 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "firmware: %.*s\n", (int)sizeof(tag), tag);
platform_set_drvdata(pdev, bpmp);
err = of_platform_default_populate(pdev->dev.of_node, NULL, &pdev->dev);
if (err < 0)
goto free_mrq;