[PATCH 4/9] mci: add RPMB support

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Mar 17 08:18:32 PDT 2025


Hello Sascha,

On 3/12/25 13:16, Sascha Hauer wrote:
> +
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen)
> +{
> +	/*
> +	 * Whoever crafted the data supplied to this function knows how to
> +	 * format the PRMB frames and which response is expected. If
> +	 * there's some unexpected mismatch it's more helpful to report an
> +	 * error immediately than trying to guess what was the intention
> +	 * and possibly just delay an eventual error which will be harder
> +	 * to track down.
> +	 */
> +	void *rpmb_data = NULL;
> +	int ret;
> +
> +	mci_blk_part_switch(mci->rpmb_part);
> +
> +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {

Even if alignment happens to be correct, there is no guarantee that
there is no other data sharing a cache line.

Let's just return an error for the unaligned case instead and expect
users to align the request.

Thanks,
Ahmad

> +		/* Memory alignment is required by MMC driver */
> +		rpmb_data = dma_alloc(reqlen);
> +		if (!rpmb_data)
> +			return -ENOMEM;
> +
> +		memcpy(rpmb_data, req, reqlen);
> +		req = rpmb_data;
> +	}
> +
> +	ret = rpmb_route_frames(mci, req, reqlen, rsp, rsplen);
> +
> +	free(rpmb_data);
> +
> +	return ret;
> +}
> diff --git a/include/mci.h b/include/mci.h
> index 08a3e46f7d..ec0390eedf 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -736,6 +736,9 @@ int mmc_select_timing(struct mci *mci);
>  int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
>  int mci_blk_part_switch(struct mci_part *part);
>  int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
> +struct mci *mci_get_rpmb_dev(void);
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen);
>  
>  static inline bool mmc_card_hs200(struct mci *mci)
>  {
> 




More information about the barebox mailing list