Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Jeffrey Hugo <quic_jhugo@quicinc.com>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: <quic_carlv@quicinc.com>, <quic_yabdulra@quicinc.com>,
	<quic_mattleun@quicinc.com>, <quic_thanson@quicinc.com>,
	<ogabbay@kernel.org>, <lizhi.hou@amd.com>,
	<jacek.lawrynowicz@linux.intel.com>,
	<linux-arm-msm@vger.kernel.org>,
	<dri-devel@lists.freedesktop.org>, <mhi@lists.linux.dev>
Subject: Re: [PATCH 1/7] bus: mhi: host: Refactor BHI/BHIe based firmware loading
Date: Fri, 17 Jan 2025 09:21:18 -0700	[thread overview]
Message-ID: <9c29c3cf-d3b4-1832-960a-a72d003b71d5@quicinc.com> (raw)
In-Reply-To: <20250108052416.cqfoxzvw42me2kub@thinkpad>

On 1/7/2025 10:24 PM, Manivannan Sadhasivam wrote:
> On Fri, Dec 13, 2024 at 02:33:34PM -0700, Jeffrey Hugo wrote:
>> From: Matthew Leung <quic_mattleun@quicinc.com>
>>
>> Refactor the firmware loading code to have distinct helper functions for
>> BHI and BHIe operations. This lays the foundation for separating the
>> firmware loading protocol from the firmware being loaded and the EE it
>> is loaded in.
>>
>> Signed-off-by: Matthew Leung <quic_mattleun@quicinc.com>
>> Reviewed-by: Youssef Samir <quic_yabdulra@quicinc.com>
>> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>> ---
>>   drivers/bus/mhi/host/boot.c | 155 +++++++++++++++++++++++++-----------
>>   1 file changed, 110 insertions(+), 45 deletions(-)
>>
>> diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
>> index e8c92972f9df..e3f3c07166ad 100644
>> --- a/drivers/bus/mhi/host/boot.c
>> +++ b/drivers/bus/mhi/host/boot.c
>> @@ -177,6 +177,37 @@ int mhi_download_rddm_image(struct mhi_controller *mhi_cntrl, bool in_panic)
>>   }
>>   EXPORT_SYMBOL_GPL(mhi_download_rddm_image);
>>   
>> +static inline void mhi_fw_load_error_dump(struct mhi_controller *mhi_cntrl)
> 
> No need to add 'inline' keyword in c files. You can trust the compiler.

Done.

> 
>> +{
>> +	struct device *dev = &mhi_cntrl->mhi_dev->dev;
>> +	rwlock_t *pm_lock = &mhi_cntrl->pm_lock;
>> +	void __iomem *base = mhi_cntrl->bhi;
>> +	int ret;
>> +	u32 val;
>> +	int i;
> 
> int ret, i?

Done.

> 
>> +	struct {
>> +		char *name;
>> +		u32 offset;
>> +	} error_reg[] = {
>> +		{ "ERROR_CODE", BHI_ERRCODE },
>> +		{ "ERROR_DBG1", BHI_ERRDBG1 },
>> +		{ "ERROR_DBG2", BHI_ERRDBG2 },
>> +		{ "ERROR_DBG3", BHI_ERRDBG3 },
>> +		{ NULL },
>> +	};
>> +
>> +	read_lock_bh(pm_lock);
>> +	if (MHI_REG_ACCESS_VALID(mhi_cntrl->pm_state)) {
>> +		for (i = 0; error_reg[i].name; i++) {
>> +			ret = mhi_read_reg(mhi_cntrl, base, error_reg[i].offset, &val);
>> +			if (ret)
>> +				break;
>> +			dev_err(dev, "Reg: %s value: 0x%x\n", error_reg[i].name, val);
>> +		}
>> +	}
>> +	read_unlock_bh(pm_lock);
>> +}
>> +
> 
> [...]
> 
>> +static int mhi_alloc_bhi_buffer(struct mhi_controller *mhi_cntrl,
>> +				struct image_info **image_info,
>> +				size_t alloc_size)
>> +{
>> +	struct image_info *img_info;
>> +	struct mhi_buf *mhi_buf;
>> +	int segments = 1;
>> +
>> +	img_info = kzalloc(sizeof(*img_info), GFP_KERNEL);
>> +	if (!img_info)
>> +		return -ENOMEM;
>> +
>> +	/* Allocate memory for entry */
>> +	img_info->mhi_buf = kcalloc(segments, sizeof(*img_info->mhi_buf),
>> +				    GFP_KERNEL);
> 
> Why do you need kcalloc for only 1 segment?

Symmetry with mhi_alloc_bhie_table().  Will change.

> 
>> +	if (!img_info->mhi_buf)
>> +		goto error_alloc_mhi_buf;
>> +
>> +	/* Allocate and populate vector table */
>> +	mhi_buf = img_info->mhi_buf;
>> +
>> +	mhi_buf->len = alloc_size;
>> +	mhi_buf->buf = dma_alloc_coherent(mhi_cntrl->cntrl_dev, mhi_buf->len,
>> +					  &mhi_buf->dma_addr, GFP_KERNEL);
>> +	if (!mhi_buf->buf)
>> +		goto error_alloc_segment;
>> +
>> +	img_info->bhi_vec = NULL;
>> +	img_info->entries = segments;
>> +	*image_info = img_info;
>> +
>> +	return 0;
>> +
>> +error_alloc_segment:
>> +	kfree(mhi_buf);
>> +error_alloc_mhi_buf:
>> +	kfree(img_info);
>> +
>> +	return -ENOMEM;
>> +}
>> +
>>   int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
>>   			 struct image_info **image_info,
>>   			 size_t alloc_size)
>> @@ -364,9 +422,18 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
>>   	return -ENOMEM;
>>   }
>>   
>> -static void mhi_firmware_copy(struct mhi_controller *mhi_cntrl,
>> -			      const u8 *buf, size_t remainder,
>> -			      struct image_info *img_info)
>> +static void mhi_firmware_copy_bhi(struct mhi_controller *mhi_cntrl,
>> +				  const u8 *buf, size_t size,
>> +				  struct image_info *img_info)
>> +{
>> +	struct mhi_buf *mhi_buf = img_info->mhi_buf;
>> +
>> +	memcpy(mhi_buf->buf, buf, size);
>> +}
>> +
>> +static void mhi_firmware_copy_bhie(struct mhi_controller *mhi_cntrl,
>> +				   const u8 *buf, size_t remainder,
>> +				   struct image_info *img_info)
>>   {
>>   	size_t to_cpy;
>>   	struct mhi_buf *mhi_buf = img_info->mhi_buf;
>> @@ -390,10 +457,9 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl)
>>   	const struct firmware *firmware = NULL;
>>   	struct device *dev = &mhi_cntrl->mhi_dev->dev;
>>   	enum mhi_pm_state new_state;
>> +	struct image_info *image;
>>   	const char *fw_name;
>>   	const u8 *fw_data;
>> -	void *buf;
>> -	dma_addr_t dma_addr;
>>   	size_t size, fw_sz;
>>   	int ret;
>>   
>> @@ -452,17 +518,16 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl)
>>   	fw_sz = firmware->size;
>>   
>>   skip_req_fw:
>> -	buf = dma_alloc_coherent(mhi_cntrl->cntrl_dev, size, &dma_addr,
>> -				 GFP_KERNEL);
>> -	if (!buf) {
>> +	ret = mhi_alloc_bhi_buffer(mhi_cntrl, &image, size);
>> +	if (ret) {
>>   		release_firmware(firmware);
>>   		goto error_fw_load;
>>   	}
>> +	mhi_firmware_copy_bhi(mhi_cntrl, fw_data, size, image);
> 
> Why can't you directly use memcpy here? I know what you want to keep symmetry
> with mhi_firmware_copy_bhie(), but it seems unnecessary to me.
> 
> Adding a comment like "Load the firmware into BHI vec table" is enough.

Just symmetry.  Jarek had the same comment.  Will inline.


  reply	other threads:[~2025-01-17 16:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13 21:33 [PATCH 0/7] accel/qaic: Initial AIC200 support Jeffrey Hugo
2024-12-13 21:33 ` [PATCH 1/7] bus: mhi: host: Refactor BHI/BHIe based firmware loading Jeffrey Hugo
2025-01-07 11:06   ` Jacek Lawrynowicz
2025-01-08  5:24   ` Manivannan Sadhasivam
2025-01-17 16:21     ` Jeffrey Hugo [this message]
2024-12-13 21:33 ` [PATCH 2/7] bus: mhi: host: Add a policy to enable image transfer via BHIe in PBL Jeffrey Hugo
2025-01-07 11:12   ` Jacek Lawrynowicz
2025-01-08  5:42   ` Manivannan Sadhasivam
2025-01-17 16:45     ` Jeffrey Hugo
2024-12-13 21:33 ` [PATCH 3/7] accel/qaic: Allocate an exact number of MSIs Jeffrey Hugo
2024-12-13 23:43   ` Lizhi Hou
2024-12-13 21:33 ` [PATCH 4/7] accel/qaic: Add support for MSI-X Jeffrey Hugo
2024-12-13 23:49   ` Lizhi Hou
2024-12-13 21:33 ` [PATCH 5/7] accel/qaic: Mask out SR-IOV PCI resources Jeffrey Hugo
2024-12-14  0:20   ` Lizhi Hou
2024-12-13 21:33 ` [PATCH 6/7] accel/qaic: Add config structs for supported cards Jeffrey Hugo
2024-12-14  0:35   ` Lizhi Hou
2024-12-20 17:15     ` Jeffrey Hugo
2024-12-20 18:08       ` Lizhi Hou
2024-12-13 21:33 ` [PATCH 7/7] accel/qaic: Add AIC200 support Jeffrey Hugo
2024-12-14  0:49   ` Lizhi Hou
2024-12-20 17:26     ` Jeffrey Hugo
2024-12-20 17:33       ` Lizhi Hou
2024-12-20 17:50         ` Jeffrey Hugo
2024-12-20 18:07           ` Lizhi Hou
2024-12-28  0:19   ` kernel test robot

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=9c29c3cf-d3b4-1832-960a-a72d003b71d5@quicinc.com \
    --to=quic_jhugo@quicinc.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jacek.lawrynowicz@linux.intel.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=mhi@lists.linux.dev \
    --cc=ogabbay@kernel.org \
    --cc=quic_carlv@quicinc.com \
    --cc=quic_mattleun@quicinc.com \
    --cc=quic_thanson@quicinc.com \
    --cc=quic_yabdulra@quicinc.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox