mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
firmware: arm_scmi: Introduce setup_shmem_iomap
To get the address of shmem could be generalized by introducing setup_shmem_iomap. Then the duplicated code in mailbox.c, optee.c and smc.c could be dropped. Signed-off-by: Peng Fan <peng.fan@nxp.com> [ Cristian: use OF __free and make use of the new helper also in smc.c ] Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Tested-by: Peng Fan <peng.fan@nxp.com> #i.MX95 19x19 EVK Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Message-Id: <20240812173340.3912830-3-cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
This commit is contained in:
parent
e98dba934b
commit
1ebc28e935
@ -351,6 +351,8 @@ bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem,
|
||||
struct scmi_xfer *xfer);
|
||||
bool shmem_channel_free(struct scmi_shared_mem __iomem *shmem);
|
||||
bool shmem_channel_intr_enabled(struct scmi_shared_mem __iomem *shmem);
|
||||
void __iomem *setup_shmem_iomap(struct scmi_chan_info *cinfo, struct device *dev,
|
||||
bool tx, struct resource *res);
|
||||
|
||||
/* declarations for message passing transports */
|
||||
struct scmi_msg_payld;
|
||||
|
@ -178,11 +178,8 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
|
||||
const char *desc = tx ? "Tx" : "Rx";
|
||||
struct device *cdev = cinfo->dev;
|
||||
struct scmi_mailbox *smbox;
|
||||
struct device_node *shmem;
|
||||
int ret, a2p_rx_chan, p2a_chan, p2a_rx_chan, idx = tx ? 0 : 1;
|
||||
int ret, a2p_rx_chan, p2a_chan, p2a_rx_chan;
|
||||
struct mbox_client *cl;
|
||||
resource_size_t size;
|
||||
struct resource res;
|
||||
|
||||
ret = mailbox_chan_validate(cdev, &a2p_rx_chan, &p2a_chan, &p2a_rx_chan);
|
||||
if (ret)
|
||||
@ -195,25 +192,9 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
|
||||
if (!smbox)
|
||||
return -ENOMEM;
|
||||
|
||||
shmem = of_parse_phandle(cdev->of_node, "shmem", idx);
|
||||
if (!of_device_is_compatible(shmem, "arm,scmi-shmem")) {
|
||||
of_node_put(shmem);
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(shmem, 0, &res);
|
||||
of_node_put(shmem);
|
||||
if (ret) {
|
||||
dev_err(cdev, "failed to get SCMI %s shared memory\n", desc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size = resource_size(&res);
|
||||
smbox->shmem = devm_ioremap(dev, res.start, size);
|
||||
if (!smbox->shmem) {
|
||||
dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc);
|
||||
return -EADDRNOTAVAIL;
|
||||
}
|
||||
smbox->shmem = setup_shmem_iomap(cinfo, dev, tx, NULL);
|
||||
if (IS_ERR(smbox->shmem))
|
||||
return PTR_ERR(smbox->shmem);
|
||||
|
||||
cl = &smbox->cl;
|
||||
cl->dev = cdev;
|
||||
|
@ -368,38 +368,11 @@ static int setup_dynamic_shmem(struct device *dev, struct scmi_optee_channel *ch
|
||||
static int setup_static_shmem(struct device *dev, struct scmi_chan_info *cinfo,
|
||||
struct scmi_optee_channel *channel)
|
||||
{
|
||||
struct device_node *np;
|
||||
resource_size_t size;
|
||||
struct resource res;
|
||||
int ret;
|
||||
channel->req.shmem = setup_shmem_iomap(cinfo, dev, true, NULL);
|
||||
if (IS_ERR(channel->req.shmem))
|
||||
return PTR_ERR(channel->req.shmem);
|
||||
|
||||
np = of_parse_phandle(cinfo->dev->of_node, "shmem", 0);
|
||||
if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
|
||||
ret = -ENXIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(np, 0, &res);
|
||||
if (ret) {
|
||||
dev_err(dev, "Failed to get SCMI Tx shared memory\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
size = resource_size(&res);
|
||||
|
||||
channel->req.shmem = devm_ioremap(dev, res.start, size);
|
||||
if (!channel->req.shmem) {
|
||||
dev_err(dev, "Failed to ioremap SCMI Tx shared memory\n");
|
||||
ret = -EADDRNOTAVAIL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
of_node_put(np);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_shmem(struct device *dev, struct scmi_chan_info *cinfo,
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include <linux/ktime.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/processor.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
@ -133,3 +135,42 @@ bool shmem_channel_intr_enabled(struct scmi_shared_mem __iomem *shmem)
|
||||
{
|
||||
return ioread32(&shmem->flags) & SCMI_SHMEM_FLAG_INTR_ENABLED;
|
||||
}
|
||||
|
||||
void __iomem *setup_shmem_iomap(struct scmi_chan_info *cinfo,
|
||||
struct device *dev, bool tx,
|
||||
struct resource *res)
|
||||
{
|
||||
struct device_node *shmem __free(device_node);
|
||||
const char *desc = tx ? "Tx" : "Rx";
|
||||
int ret, idx = tx ? 0 : 1;
|
||||
struct device *cdev = cinfo->dev;
|
||||
struct resource lres = {};
|
||||
resource_size_t size;
|
||||
void __iomem *addr;
|
||||
|
||||
shmem = of_parse_phandle(cdev->of_node, "shmem", idx);
|
||||
if (!shmem)
|
||||
return IOMEM_ERR_PTR(-ENODEV);
|
||||
|
||||
if (!of_device_is_compatible(shmem, "arm,scmi-shmem"))
|
||||
return IOMEM_ERR_PTR(-ENXIO);
|
||||
|
||||
/* Use a local on-stack as a working area when not provided */
|
||||
if (!res)
|
||||
res = &lres;
|
||||
|
||||
ret = of_address_to_resource(shmem, 0, res);
|
||||
if (ret) {
|
||||
dev_err(cdev, "failed to get SCMI %s shared memory\n", desc);
|
||||
return IOMEM_ERR_PTR(ret);
|
||||
}
|
||||
|
||||
size = resource_size(res);
|
||||
addr = devm_ioremap(dev, res->start, size);
|
||||
if (!addr) {
|
||||
dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc);
|
||||
return IOMEM_ERR_PTR(-EADDRNOTAVAIL);
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
@ -130,9 +130,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
|
||||
struct device *cdev = cinfo->dev;
|
||||
unsigned long cap_id = ULONG_MAX;
|
||||
struct scmi_smc *scmi_info;
|
||||
resource_size_t size;
|
||||
struct resource res;
|
||||
struct device_node *np;
|
||||
struct resource res = {};
|
||||
u32 func_id;
|
||||
int ret;
|
||||
|
||||
@ -143,31 +141,16 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
|
||||
if (!scmi_info)
|
||||
return -ENOMEM;
|
||||
|
||||
np = of_parse_phandle(cdev->of_node, "shmem", 0);
|
||||
if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
|
||||
of_node_put(np);
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(np, 0, &res);
|
||||
of_node_put(np);
|
||||
if (ret) {
|
||||
dev_err(cdev, "failed to get SCMI Tx shared memory\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
size = resource_size(&res);
|
||||
scmi_info->shmem = devm_ioremap(dev, res.start, size);
|
||||
if (!scmi_info->shmem) {
|
||||
dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
|
||||
return -EADDRNOTAVAIL;
|
||||
}
|
||||
scmi_info->shmem = setup_shmem_iomap(cinfo, dev, tx, &res);
|
||||
if (IS_ERR(scmi_info->shmem))
|
||||
return PTR_ERR(scmi_info->shmem);
|
||||
|
||||
ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
|
||||
resource_size_t size = resource_size(&res);
|
||||
void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
|
||||
/* The capability-id is kept in last 8 bytes of shmem.
|
||||
* +-------+ <-- 0
|
||||
|
Loading…
Reference in New Issue
Block a user