All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier-oss@weidmueller.com>
To: u-boot@lists.denx.de, Michal Simek <michal.simek@amd.com>
Cc: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>,
	Adrian Fiergolski <adrian.fiergolski@fastree3d.com>,
	Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	T Karthik Reddy <t.karthik.reddy@xilinx.com>
Subject: [PATCH v2 02/15] firmware: zynqmp: Probe driver before use
Date: Mon, 20 Jun 2022 18:36:37 +0200	[thread overview]
Message-ID: <20220620163650.18756-2-stefan.herbrechtsmeier-oss@weidmueller.com> (raw)
In-Reply-To: <20220620163650.18756-1-stefan.herbrechtsmeier-oss@weidmueller.com>

From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Probe the driver before use to ensure that the driver is always
available and the global data are valid. Initialize the global data
with zero and probe the driver if the global data are still zero. This
allows a usage of the firmware functions from other drivers with
arbitrary order between the drivers.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

---

Changes in v2:
- Call probe only if drivers isn't initialized

 drivers/firmware/firmware-zynqmp.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c
index 341d7cf135..b0cd647aa5 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -26,7 +26,7 @@
 struct zynqmp_power {
 	struct mbox_chan tx_chan;
 	struct mbox_chan rx_chan;
-} zynqmp_power;
+} zynqmp_power = {};
 
 #define NODE_ID_LOCATION	5
 
@@ -79,6 +79,20 @@ int zynqmp_pmufw_node(u32 id)
 	return 0;
 }
 
+static int do_pm_probe(void)
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
+					  DM_DRIVER_GET(zynqmp_power),
+					  &dev);
+	if (ret)
+		debug("%s: Probing device failed: %d\n", __func__, ret);
+
+	return ret;
+}
+
 static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
 {
 	struct zynqmp_ipi_msg msg;
@@ -92,8 +106,11 @@ static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
 	    res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
 		return -EINVAL;
 
-	if (!(zynqmp_power.tx_chan.dev) || !(zynqmp_power.rx_chan.dev))
-		return -EINVAL;
+	if (!(zynqmp_power.tx_chan.dev) || !(zynqmp_power.rx_chan.dev)) {
+		ret = do_pm_probe();
+		if (ret)
+			return ret;
+	}
 
 	debug("%s, Sending IPI message with ID: 0x%0x\n", __func__, req[0]);
 	msg.buf = (u32 *)req;
-- 
2.30.2


  reply	other threads:[~2022-06-20 16:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 16:36 [PATCH v2 01/15] firmware: zynqmp: Check if rx channel dev pointer is valid Stefan Herbrechtsmeier
2022-06-20 16:36 ` Stefan Herbrechtsmeier [this message]
2022-06-20 16:36 ` [PATCH v2 03/15] xilinx: zynqmp: Replace strncat with strlcat Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 04/15] xilinx: zynqmp: Add macro for device type mask Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 05/15] xilinx: zynqmp: Reuse shift macros to define masks Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 06/15] xilinx: zynqmp: Merge device lists Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 07/15] soc: xilinx: zynqmp: Remove redundant checks for zynqmp_mmio_read Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 08/15] soc: xilinx: zynqmp: Add machine identification support Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 09/15] xilinx: cpuinfo: Print soc machine Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 10/15] xilinx: common: Separate display cpu info function Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 11/15] xilinx: zynqmp: make spi flash support optional Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 12/15] tools: zynqmp_psu_init_minimize: Remove low level uart settings Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 13/15] tools: zynqmp_psu_init_minimize: Use CR instead of LF Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 14/15] tools: zynqmp_psu_init_minimize: Move helper functions below header includes Stefan Herbrechtsmeier
2022-06-20 16:36 ` [PATCH v2 15/15] arm64: zynqmp: " Stefan Herbrechtsmeier
2022-06-24 12:42 ` [PATCH v2 01/15] firmware: zynqmp: Check if rx channel dev pointer is valid Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220620163650.18756-2-stefan.herbrechtsmeier-oss@weidmueller.com \
    --to=stefan.herbrechtsmeier-oss@weidmueller.com \
    --cc=adrian.fiergolski@fastree3d.com \
    --cc=ashok.reddy.soma@xilinx.com \
    --cc=jh80.chung@samsung.com \
    --cc=michal.simek@amd.com \
    --cc=stefan.herbrechtsmeier@weidmueller.com \
    --cc=t.karthik.reddy@xilinx.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.