From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 377C93277A9 for ; Fri, 19 Dec 2025 12:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766145947; cv=none; b=lmOJLpgCza1kz6EWSLYo4M/UDo4JUKCIiN3jJyPX6Ovy4Pw1VsBZwBo02JLnQ+FswnnhIVmcGolYEPfoYuwpDxQ9MawkBOVf8S4PAmQtkgDKm02dJYlJeqGGPSLI5jyne/QMZHS+yJh9wIu2PM6YPgMzqnJgypkSidqNPVTP5JM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766145947; c=relaxed/simple; bh=sE6lssge5bgd1qdgt2mO4nYBxODxtSrGyDYpLcfCeDo=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=ed7opRxQhT1UMBgPcD88RtrXaVgqk1Wk2a1DcFVn49jBt3OBdQxQNXYo8Eyu1NKCgs4lb03nuAmBIeSYp/U3o+sAK31eUWnTVnIma6DjZ0dqoPf1uRob+Qw1p4pAJJZ1KCjgnrZL4piDOAcKwY2aDzsqJ/g49yv/FHO+rbyNFVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=U/iMW0MW; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=dnhJXUZw; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="U/iMW0MW"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="dnhJXUZw" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BJBdD5j3700752 for ; Fri, 19 Dec 2025 12:05:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ye/VHs9xlBhvGfu8YVFrAtTe4Mu9EMO/b02keiixSbg=; b=U/iMW0MWM6SSHR17 LOmih3pFkPl1VYx1iFwynrUp3mnYLHcxjZQ/3AskgbVoE929h4cdHwLEp1tvTDe0 +THuqS04RedMZ7pihjDp8gelNymR5PWhVupYOo5vmgiFIOsSeCeAKpIeqb6o5Ep2 6pwV/aoYdTia0xjKKmq/EEnCArNJvNv6JUrFp13HlcW0RWyPoicb6mS8Nrv4VcsF f0F0R30QIv7akaKxHEKl3/X1JswGqT6gIkNOTYjFyxu7FcDZ27FEPNTHSENAQ6c0 VfF+DsS7mq+WpnqC1/nnlB7TwetB6+hqBZhhCvteg+JNrZsjzRf4WJ9X62cq0bsx HrTx6Q== Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4b4r2ejgft-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 19 Dec 2025 12:05:45 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4f1e17aa706so7435951cf.2 for ; Fri, 19 Dec 2025 04:05:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1766145944; x=1766750744; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=ye/VHs9xlBhvGfu8YVFrAtTe4Mu9EMO/b02keiixSbg=; b=dnhJXUZwrlqmsP092YPRGDDlfji1aJ3lVVapQ1y2nhUiYIemDM2BxNBV0xMLixRn2T k2WZv7pNhxmBT0JyhqlQM1tU9aVLmfr17lhr4qWzDDoGNcG7OrtsqLDpiQeTB8Nc7kEF Y/7ZWcva67PkyM+X5tYcB7G0nlEVfYRL/uKr8Sd9A5xgUEOQHtY9iNyyPBZEYOItXSzU 9A7X84gokLg+htzqD4jtl5GKaq3vsdOTilKUXznTIBn94le2QqkVB03MeeFM0nUlTDaN Jt/zif1qKNHHozQ/Ex3yVgX/pOqqcJttVzvGuGVUFApQxK1ZdDHeCvI2Nz8hI2b9wt1N nsoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766145944; x=1766750744; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ye/VHs9xlBhvGfu8YVFrAtTe4Mu9EMO/b02keiixSbg=; b=aHFdHdhw2mQ2PE1EWkZlcWx9yOxFc/vgGzYErdu4hBFdyp0HAe7Lfjq9NeAsxmdXpw dtRD0gw7vtf7U8CFw1mRGBxZsVB+h5KQKMYvmkO6ClOaPLtKlG1TZaqFBAsMKdLs/+zV yLyUFVD2fKzoDFj5exXKdOyXiYbCHkQNhkRCvhcOiU5eLk3Fkbo4oTmr0QcBEbN5TRMM VK9Mq9MXDHo5x4VBtly5CIrEhOQgcE8zooOn/xUut9mmCEbDFcDIbweCphk+pqMz9y/7 6VN2xRiwwYk3lwKjncTIEWzlGZcc5+wdW6IQQ6d30gxDdKe9NlDzsqNBr8g4aBya6Epr eJ4g== X-Forwarded-Encrypted: i=1; AJvYcCWCQCGyfQMW3EdrLYNBSXS19SArFLeo1BcNNlYq1oe9XE0SUu+vgYqwlVhI30M0vKFNkvxpzNID7Mn3BWc=@vger.kernel.org X-Gm-Message-State: AOJu0YzanyDPzSS/U4LM/JsXhaX+sQhb3Q/HDupvnROlXKgwth1h+rV8 taNpi2CYdltsCFdD3HUL9jyO3KuJbCa4eFVYinaVUDc1s3GJ1Xephj0AXxVVhLf6f9fK+JDkLy1 8SlHEyDxHzUBqBTdQTyLFPxl+R7exSWsB/djgRc8pc/y+AU5Bth9SbKwVO5q1WXX/Ze8= X-Gm-Gg: AY/fxX5lvVGUlLIpb0fWD4D5izaWw8IaqfshDkJB7Fj93AeCoY0D9gO4PlL/sSiZn/O 2WhOYJOYFh5kTPnAiJBCy9FvOXSVYvS4Yb+seHhNdbpNb9JEePw1rjIRI3APSQrj7oYYXH0jUH/ 7J2pweoKY/xiKj6M+0DYexjsJuyNFGtdaWEEeJbQX8h7qKM2ltkGsgSZKy+d+eU5XijVvReNuoW aX62+VfLTI6q2vcRZIoX0V1EdM9QX1g5jUnjvyhnFIlWmQmfbLYqf48SYiUl+JsIHxKElOdeUBc zSDefrouIipx4KlYTBH63urBOV0ib/2sZYY//N3iFOryh7YA9FHmbvFhsyoV7DtL/4Vv3bsYKEg rTxGjTW7tJhrti6Ly3g9DkYDNyfiqKLz8Sp36zLgZuykL57rhTH4W+FZavs2R/9u6iA== X-Received: by 2002:a05:622a:1982:b0:4ee:1718:dec8 with SMTP id d75a77b69052e-4f4abcee273mr26138671cf.3.1766145944383; Fri, 19 Dec 2025 04:05:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzfMOuSFJ/OJ64vZEqDhf9U59LZhw8Cjqpg04L/6xahb/kAkvh1Fyc0HDbUNbC180mQH0aaQ== X-Received: by 2002:a05:622a:1982:b0:4ee:1718:dec8 with SMTP id d75a77b69052e-4f4abcee273mr26138161cf.3.1766145943850; Fri, 19 Dec 2025 04:05:43 -0800 (PST) Received: from [192.168.119.72] (078088045245.garwolin.vectranet.pl. [78.88.45.245]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f4ef2bsm212467466b.68.2025.12.19.04.05.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Dec 2025 04:05:43 -0800 (PST) Message-ID: Date: Fri, 19 Dec 2025 13:05:41 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Konrad Dybcio Subject: Re: [PATCH 2/2] mtd: devices: Add Qualcomm SCM storage driver To: Junhao Xie , Bjorn Andersson , Konrad Dybcio Cc: Xilin Wu , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rodrigo Vivi , Tomas Winkler , Raag Jadav , Krzysztof Kozlowski , Geert Uytterhoeven , Alexander Usyskin , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mtd@lists.infradead.org References: <20251218180205.930961-1-bigfoot@radxa.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: tJ5EKqRRmZ4zwYivJM0y4_GM4g5rJL7x X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjE5MDEwMCBTYWx0ZWRfXxWCPg9/ne3yB /+TvsJmRQodIjMmD/F8VcseJBX1p/AizDLOS2u+oKr3R0rwBRR/v25pZ17TV+Uxixbk0StyHP0a 0VrfsfW1PH+0tiq+Wxnl1lM+bm5fFDFDFd0q62hdB2+e3NLkmGjRCaFpa6Nf4/5AO5/E4xk7PSV 1JRY5uMUPiaA9OE59yf6d+sZOJ8LQXIyMB5bY2BMmK7NOJYGDbuWEY/DFCgyNHMqsTDttCkFceu oxmeC1LclhbLj4h+z8by4+XUmWpQm77SEfG5Tf2aTg9cyxDO5MkNwCAuk3cEjvTJBhO/xlMh16H ORJ08YzwRe2USRMGyx9XG3GnghngBnCYo7ANtyGioOA2S4wmS1gDEKYr1G4RtzvvbVoQDv9bbNA Y9Q2C/nTwu9NgiQ6xvAGMUl6Pqw6e96ddwVmdnhTYa7Lhe2LVrRSYgdFxJJLJ03UTsZcw9+kWzF 42VvSnnkvH3RKMsTbJA== X-Proofpoint-ORIG-GUID: tJ5EKqRRmZ4zwYivJM0y4_GM4g5rJL7x X-Authority-Analysis: v=2.4 cv=EabFgfmC c=1 sm=1 tr=0 ts=69453f99 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=FpWmc02/iXfjRdCD7H54yg==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ksxQWNrZAAAA:8 a=5rMr7QXivSIVLOAxuCIA:9 a=QEXdDO2ut3YA:10 a=a_PwQJl-kcHnX1M80qC6:22 a=l7WU34MJF0Z5EO9KEJC3:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-19_03,2025-12-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 suspectscore=0 priorityscore=1501 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512190100 On 12/18/25 7:02 PM, Junhao Xie wrote: > Add MTD driver for accessing storage devices managed by Qualcomm's > TrustZone firmware. On some platforms, BIOS/firmware storage (typically > SPI NOR flash) is not directly accessible from the non-secure world and > all operations must go through SCM (Secure Channel Manager) calls. > > Signed-off-by: Junhao Xie > Tested-by: Xilin Wu > --- [...] > +struct qcom_scm_storage { > + struct device *dev; > + struct mutex lock; /* Protects SCM storage operations */ > + struct mtd_info mtd; > + struct qcom_scm_storage_info info; > + size_t buffer_size; > + u8 *buffer; > +}; > + > +static int qcom_scm_storage_erase(struct mtd_info *mtd, > + struct erase_info *instr) > +{ > + struct qcom_scm_storage *host = > + container_of(mtd, struct qcom_scm_storage, mtd); > + > + if (instr->addr % host->info.block_size || > + instr->len % host->info.block_size) While it's the same value, it seems like mtd->erasesize would be "idiomatic" here > + return -EINVAL; > + > + guard(mutex)(&host->lock); > + > + return qcom_scm_storage_send_cmd(QCOM_SCM_STORAGE_SPINOR, > + QCOM_SCM_STORAGE_ERASE, > + instr->addr / host->info.block_size, > + 0, instr->len); > +} > + > +static int qcom_scm_storage_read(struct mtd_info *mtd, > + loff_t from, size_t len, > + size_t *retlen, u_char *buf) > +{ > + struct qcom_scm_storage *host = > + container_of(mtd, struct qcom_scm_storage, mtd); Feel free to unwrap this line > + size_t block_size = host->info.block_size; > + loff_t block_start, block_off, lba; > + size_t chunk, to_read; > + int ret = 0; This initialization seems unnecessary [...] > +static int qcom_scm_storage_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct qcom_scm_storage *host; > + int ret; > + > + host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); > + if (!host) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, host); > + host->dev = dev; > + > + ret = devm_mutex_init(dev, &host->lock); > + if (ret) > + return ret; > + > + host->buffer_size = SZ_256K; Should this just be = host->info->page_size? [...] > + dev_info(dev, "scm storage 0x%llx registered with size %llu bytes\n", > + host->info.serial_num, host->mtd.size); dev_dbg()? Konrad