From nobody Fri Dec 26 05:32:04 2025 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 5914E3A1CE; Tue, 9 Jan 2024 15:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="H/maQxAJ" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409D9PtL004504; Tue, 9 Jan 2024 15:48:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=Wwb0cQdRwzb6IPZJywCuG9Qf/mkN1A+F0LzgpowMaVY=; b=H/ maQxAJlWSMr9DhPXJjouY8wJUGClVOr7fOTJUdUq4e3uGD+lCN42K7oGdACQ0BQJ 7DIOVwjCLMcqBsj/n0OXp3tlAcrNZYaG7H91BJi6YS92M4E8Y3vV5iTAa3sjYWY5 4skFYMR43BHSxzuK3efJpV+Y/d2W1qbFm3JN9Hl5d9XhfKe4D2MYCiUAt0QNuEM+ zCWGXDBEUDqnDLwOnk9W7jGoRjk/fKHrSxbldLTuHDbCuDAOjLiR0Z0bKKAEMhhg 2eO20k+otkSdvSa0Wfn+tGoRvvUFmUmsy5RsR6wkdS27PcI+EcdxD7XNaP2Dk5ta LA15La759SN12FE83iqw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgq2yt33b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:48:46 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FmiS4025870 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:48:44 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:48:39 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha , Bagas Sanjaya Subject: [PATCH v7 01/12] docs: qcom: Add qualcomm minidump guide Date: Tue, 9 Jan 2024 21:01:49 +0530 Message-ID: <20240109153200.12848-2-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: kNvkYXRckz9KkCX63ogIm2nopdZ1sJR8 X-Proofpoint-ORIG-GUID: kNvkYXRckz9KkCX63ogIm2nopdZ1sJR8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 clxscore=1011 priorityscore=1501 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Add the qualcomm minidump guide for the users which tries to cover the dependency, API use and the way to test and collect minidump on Qualcomm supported SoCs. Signed-off-by: Mukesh Ojha Reviewed-by: Bagas Sanjaya --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/qcom_minidump.rst | 318 ++++++++++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 Documentation/admin-guide/qcom_minidump.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index fb40a1f6f79e..edab05fc4653 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -121,6 +121,7 @@ configure specific aspects of kernel behavior to your l= iking. pm/index pmf pnp + qcom_minidump rapidio ras rtc diff --git a/Documentation/admin-guide/qcom_minidump.rst b/Documentation/ad= min-guide/qcom_minidump.rst new file mode 100644 index 000000000000..2a057612422b --- /dev/null +++ b/Documentation/admin-guide/qcom_minidump.rst @@ -0,0 +1,318 @@ +Qualcomm Minidump Feature +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +Introduction +------------ + +Minidump is a best effort mechanism to collect useful and predefined +data for post-mortem debugging on a Qualcomm System on chip(SoCs). + +Minidump is built on the premise that a hardware or software component +on the SoC has encountered an unexpected fault. This means that data +collected by Minidump can not be assumed to be correct or Minidump +collection itself could fail. + +Qualcomm SoCs in engineering mode provides mechanism for generating +complete RAM dump for both kernel/non-kernel crashes for postmortem +debugging however, on a end user product taking complete RAM dump at +the time of failure has substantial storage requirement as well as it +is time consuming to transfer them electronically. To encounter this +problem, Minidump was introduced in Qualcomm boot firmware that provides +a way to collect selected region in the final RAM dump which is less +in size compared to complete RAM dump. + +Qualcomm SoCs contains Application Processor SubSystem(APSS) and its +co-processor like Audio Digital Signal Process(ADSP), Compute DSP(CDSP), +MODEM running their operating system or firmware can register their +selected region in their respective table called SubSystem table of +content (SS-ToC) and the addresses of these tables is further maintained +in a separate table called Global Table of Content (G-ToC) inside separate +region maintaied inside RAM called Shared memory(SMEM). More about shared +memory can be found inside ``driver/soc/qcom/smem.c`` under doc section +and it is briefly discussed in later section. + +It is to note that SubSystems, Remote processors and co-processors have +same meaning in this document and been used interchangeably. + +High level design +----------------- +:: + + +-----------------------------------------------+ + | RAM +-------------+ | + | | SS0-ToC| | + | +----------------+ +----------------+ | | + | |Shared memory | | SS1-ToC| | | + | |(SMEM) | | | | | + | | | +-->|--------+ | | | + | |G-ToC | | | SS-ToC \ | | | + | |+-------------+ | | | +-----------+ | | | + | ||-------------| | | | |-----------| | | | + | || SS0-ToC | | | +-|<|SS1 region1| | | | + | ||-------------| | | | | |-----------| | | | + | || SS1-ToC |-|>+ | | |SS1 region2| | | | + | ||-------------| | | | |-----------| | | | + | || SS2-ToC | | | | | ... | | | | + | ||-------------| | | | |-----------| | | | + | || ... | | |-|<|SS1 regionN| | | | + | ||-------------| | | | |-----------| | | | + | || SSn-ToC | | | | +-----------+ | | | + | |+-------------+ | | | | | | + | | | | |----------------| | | + | | | +>| regionN | | | + | | | | |----------------| | | + | +----------------+ | | | | | + | | |----------------| | | + | +>| region1 | | | + | |----------------| | | + | | | | | + | |----------------|-+ | + | | region5 | | + | |----------------| | + | | | | + | Region information +----------------+ | + | +---------------+ | + | |region name | | + | |---------------| | + | |region address | | + | |---------------| | + | |region size | | + | +---------------+ | + +-----------------------------------------------+ + +G-ToC: Global table of contents +SSX-ToC: SubSystem X table of contents + X is an integer in the range of 0 to 10 + Older boot firmware has kept this limit to 10 + however, in newer firmware this number is expected to change + +SSX-MSn: SubSystem memory segments numbered from 0 to n + For APSS, n is limited to 200 from older boot firmware + + Older boot firmware statically allocates 300 as total number of + supported region across all SubSystem in Minidump table out of + which, APSS limit is kept to 201. In future, this limitation + from boot firmware might get removed by allocating the region + dynamically. APSS Minidump kernel driver keeping this limit to + 201 to be compatible with older boot firmware. + +SMEM is a section of RAM reserved by boot firmware and is the backbone of +Minidump functionality to work. It is also a medium of inter processor +communication and a way where boot firmware can prepare something for +upcoming operating system usage. + +Qualcomm SoCs boot firmware must reserve an area of RAM as SMEM prior to +handling over control to the run-time operating system. It creates SMEM +partition for Minidump with ``SBL_MINIDUMP_SMEM_ID`` and creates an array +of pointers called Global table of content (G-ToC) at the start of this +partition. Each index of this array is uniquely assigned to each SubSystem +like for APSS it is 0 while for ADSP, CDSP, MODEM it is 5, 7 and 3 respect= ively. +points to their table of segments called SS-ToC to be included in the Mini= dump. + +From the diagram above, Global Table of Contents (G-ToC) enumerates a fixed +size number of SubSystem Table of Contents (SS-ToC) structures. Each +SS-ToC contains a list of SubSystem Memory Segments which are named +according to the containing SS-ToC hence, SSX-MSn where "X" denotes the +SubSystem index of the containing SSX-ToC and "n" denotes an individual +Memory segment within the SubSystem. Hence, SS0-MS0 belongs to SS0-ToC +whereas SS1-MS0 belongs to SS1-ToC. Segment structure contains name, +base address, size of a Segment to be dumped. + +The Application Processor SubSystem (APSS) runs the Linux kernel and is +therefore not responsible for assembling Minidump data. One of the other +system agents in the SoC will be responsible for capturing the Minidump +data during system reset. Typically one of the SoC Digital Signal +Processors (DSP) will be used for this purpose. During reset, the DSP will +walk the G-ToC, SSX-ToCs and SSX-MSns either., dump the regions as binary +blob into storage or pushed outside to the attached host machine via USB +(more described in Dump collection section below). + +Qualcomm Remote Processor Minidump support +------------------------------------------ + +Linux Kernel support recovery and coredump collection on remote processor +failure through remoteproc framework and in this document, remote processo= rs +meant for ADSP, CDSP, MODEM etc. Qualcomm remoteproc driver has support for +collecting Minidump for remote processors as well where each remote proces= sor +has their unique statically assigned descriptor in the G-ToC which is +represented via ``minidump_id`` in ``driver/remoteproc/qcom_q6v5_pas.c`` +and it helps getting further information about valid registered region from +firmware and later collecting via remoteproc coredump framework. + +Qualcomm APSS Minidump kernel driver concept +-------------------------------------------- + +Qualcomm APSS Minidump kernel driver adds the capability to add Linux +region to be dumped as part of Minidump collection. Shared memory +driver creates platform device for Minidump driver and on Minidump +driver probe it gets the G-ToC address (``struct minidump_global_toc``) +by querying Minidump SMEM ID ``SBL_MINIDUMP_SMEM_ID`` as one of parameter +to ``qcom_smem_get`` function. Further, driver uses APSS Minidump unique +descriptor or index i.e., 0 to get APSS SubSystem ToC and fills up the +fields of ``struct minidump_subsystem`` and allocates memory for Segment +array of structure ``struct minidump_region`` of size compatible with +boot firmware (default size is 201). This really means that total 201 +APSS regions can be registered for APSS alone and the Minidump kernel +driver provides ``qcom_minidump_region_register`` and +``qcom_minidump_region_unregister`` function to register and unregister +APSS minidump region. Example usage explained in later section. + +To simplify post-mortem debugging, APSS driver registers the first region +as an ELF header that gets updated each time a new region gets registered. +and rest 200 region can be used by other APSS Minidump driver client. + +The solution supports extracting the Minidump produced either over USB +or stored to an attached storage device, if not configured default mode +is USB more described in Dump collection section. + +How a kernel client driver can register region with minidump +------------------------------------------------------------ + +A client driver can use ``qcom_minidump_region_register`` API's to register +and ``qcom_minidump_region_unregister`` to unregister their region from +minidump driver. + +A client needs to fill their region by filling ``qcom_minidump_region`` +structure object which consists of the region name, region's virtual +and physical address and its size. + + .. code-block:: c + + #include + [...] + + + [... inside a function ...] + struct qcom_minidump_region region; + + [...] + + client_mem_region =3D kzalloc(region_size, GFP_KERNEL); + if (!client_mem_region) + return -ENOMEM; + + [... Just write a pattern ...] + memset(client_mem_region, 0xAB, region_size); + + [... Fill up the region object ...] + strlcpy(region.name, "REGION_A", sizeof(region.name)); + region.virt_addr =3D client_mem_region; + region.phys_addr =3D virt_to_phys(client_mem_region); + region.size =3D region_size; + + ret =3D qcom_minidump_region_register(®ion); + if (ret < 0) { + pr_err("failed to add region in minidump: err: %d\n", ret); + return ret; + } + + [...] + + +Testing +------- + +Existing Qualcomm SoCs already supports collecting complete RAM dump (also +called full dump) can be configured by writing appropriate value to Qualco= mm's +top control and status register (tcsr) in ``driver/firmware/qcom_scm.c``. +Complete RAM dump on system failure is where entire RAM snapshot is pushed= out +to Host computer attached to SoC via USB similar to one of the way will be +used for Minidump described later in Dump collection section. Complete RAM +dump entirely get controlled from Qualcomm boot firmware and is not related +to Minidump or SMEM except the fact that same register is used to configure +one of the mode. + +SCM device Tree bindings required to support download mode +For example (sm8450) :: + + / { + + [...] + + firmware { + scm: scm { + compatible =3D "qcom,scm-sm8450", "qcom,scm"; + [... tcsr register ... ] + qcom,dload-mode =3D <&tcsr 0x13000>; + + [...] + }; + }; + + [...] + + soc: soc@0 { + + [...] + + tcsr: syscon@1fc0000 { + compatible =3D "qcom,sm8450-tcsr", "syscon"; + reg =3D <0x0 0x1fc0000 0x0 0x30000>; + }; + + [...] + }; + [...] + + }; + +A kernel command line parameter is provided to facilitate selection of +dump mode also called download mode. Boot firmware configures download +mode to be full dump even before Linux boots up however, one need to pass +``qcom_scm.download_mode=3D"mini"`` to switch the default download mode +to Minidump. Similarly ``"full"`` need to be passed to set the download +mode to full dump and passing ``"full,mini"`` will set the download mode +where both Minidump along with fulldump will be collected on system failure +however, this mode will only work if dump need to collected via USB more +about this described in Dump collection section. + +Writing to sysfs node can also be used to set the mode to minidump:: + + echo "mini" > /sys/module/qcom_scm/parameter/download_mode + +Once the download mode is set, any kind of crash will make the device coll= ect +respective dump as per the set download mode. + +Dump collection +--------------- +:: + + +-----------+ + | | + | | +------+ + | | | | + | | +--+---+ Product(Qualcomm SoC) + +-----------+ | + |+++++++++++|<------------+ + |+++++++++++| usb cable + +-----------+ + x86_64 PC + +The solution supports a product running with Qualcomm SoC (where minidump) +is supported from the firmware) connected to x86_64 host PC running PCAT +tool. It supports downloading the minidump produced from product to the +host PC over USB or to save the minidump to the product attached storage +device(UFS/eMMC/SD Card) into minidump dedicated partition. + +By default, dumps are downloaded via USB to the attached x86_64 PC running +PCAT (Qualcomm tool) software. Upon download, we will see a set of binary +blobs starting with name ``md_*`` in PCAT configured directory in x86_64 +machine, so for above example from the client it will be ``md_REGION_A.BIN= ``. +This binary blob depends on region content to determine whether it needs +external parser support to get the content of the region, so for simple +plain ASCII text we don't need any parsing and the content can be seen +just opening the binary file. + +To collect the dump to attached storage type, one needs to write appropria= te +value to IMEM register, in that case dumps are collected in rawdump +partition on the product device itself. + +One needs to read the entire rawdump partition and pull out content to +save it onto the attached x86_64 machine over USB. Later, this rawdump +can be passed to another tool (``dexter.exe`` [Qualcomm tool]) which +converts this into the similar binary blobs which we have got it when +download type was set to USB, i.e. a set of registered regions as blobs +and their name starts with ``md_*``. + +Replacing the ``dexter.exe`` with some open source tool can be added as fu= ture +scope of this document. --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 A94BA3A1B6; Tue, 9 Jan 2024 15:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="G46hrEjW" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409D8mNP017701; Tue, 9 Jan 2024 15:48:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=2v3QDfazX4eyBKkaMk652ercOJKOzQ4uh2xawUw2qLY=; b=G4 6hrEjWQajaK0ZMaP8LN1a9IaG1Mn7lep6gx3K++oTZdzBDmVmJOmmi95OUZGFwV9 0kWwNmr+ch+UdEFGE4AmhpadKvxjb7x1AsYzfq8MMO2GDjIGb2HbUMkfU/Tyn+vX H9q2c1FjS+t903gnVQQFba7qkVxQQxWzxwM+lWxoeA6utwTimeBvLN4jOiKeUPbW upljh6bd7URdM+mgRbxxlSlQRXFZJ58wPyKRMG04yfojAcNEtFo39fUI2bhgyvYP EEfMjIqKMcJUgqSFWmXqT+UQRRafl1piCQG/e3wcF9yj25ayMCxtNv4N5/ntSVQ5 2ttceXxkMK5bmQ8LamYg== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgwsjsc8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:48:51 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FmoQt013151 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:48:50 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:48:45 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 02/12] soc: qcom: Add qcom_rproc_minidump module Date: Tue, 9 Jan 2024 21:01:50 +0530 Message-ID: <20240109153200.12848-3-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: sKEQQD_yPO6hYDkuPQpUze0jLpABbV6G X-Proofpoint-ORIG-GUID: sKEQQD_yPO6hYDkuPQpUze0jLpABbV6G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 adultscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Add qcom_rproc_minidump module in a preparation to remove minidump specific code from driver/remoteproc/qcom_common.c and provide needed exported API, this as well helps to abstract minidump specific data layout from qualcomm's remoteproc driver. It is just a copying of qcom_minidump() functionality from driver/remoteproc/qcom_common.c into a separate file under qcom_rproc_minidump(). Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/Kconfig | 10 ++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qcom_minidump_internal.h | 64 +++++++++++++ drivers/soc/qcom/qcom_rproc_minidump.c | 111 ++++++++++++++++++++++ include/soc/qcom/qcom_minidump.h | 23 +++++ 5 files changed, 209 insertions(+) create mode 100644 drivers/soc/qcom/qcom_minidump_internal.h create mode 100644 drivers/soc/qcom/qcom_rproc_minidump.c create mode 100644 include/soc/qcom/qcom_minidump.h diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index c6ca4de42586..1f81746131fc 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -268,4 +268,14 @@ config QCOM_INLINE_CRYPTO_ENGINE tristate select QCOM_SCM =20 +config QCOM_RPROC_MINIDUMP + tristate "QCOM Remoteproc Minidump Support" + depends on ARCH_QCOM || COMPILE_TEST + depends on QCOM_SMEM + help + Enablement of core minidump feature is controlled from boot firmware + side, so if it is enabled from firmware, this config allow linux to + query predefined minidump segments associated with the remote processor + and check its validity and end up collecting the dump on remote process= or + crash during its recovery. endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 05b3d54e8dc9..aabb361d4b2e 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -34,3 +34,4 @@ obj-$(CONFIG_QCOM_KRYO_L2_ACCESSORS) +=3D kryo-l2-accesso= rs.o obj-$(CONFIG_QCOM_ICC_BWMON) +=3D icc-bwmon.o qcom_ice-objs +=3D ice.o obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) +=3D qcom_ice.o +obj-$(CONFIG_QCOM_RPROC_MINIDUMP) +=3D qcom_rproc_minidump.o diff --git a/drivers/soc/qcom/qcom_minidump_internal.h b/drivers/soc/qcom/q= com_minidump_internal.h new file mode 100644 index 000000000000..71709235b196 --- /dev/null +++ b/drivers/soc/qcom/qcom_minidump_internal.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _QCOM_MINIDUMP_INTERNAL_H_ +#define _QCOM_MINIDUMP_INTERNAL_H_ + +#define MAX_NUM_OF_SS 10 +#define MAX_REGION_NAME_LENGTH 16 +#define SBL_MINIDUMP_SMEM_ID 602 +#define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' <= < 0) +#define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' <= < 0) +#define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << = 0) + +/** + * struct minidump_region - Minidump region + * @name : Name of the region to be dumped + * @seq_num: : Use to differentiate regions with same name. + * @valid : This entry to be dumped (if set to 1) + * @address : Physical address of region to be dumped + * @size : Size of the region + */ +struct minidump_region { + char name[MAX_REGION_NAME_LENGTH]; + __le32 seq_num; + __le32 valid; + __le64 address; + __le64 size; +}; + +/** + * struct minidump_subsystem - Subsystem's SMEM Table of content + * @status : Subsystem toc init status + * @enabled : if set to 1, this region would be copied during coredump + * @encryption_status: Encryption status for this subsystem + * @encryption_required : Decides to encrypt the subsystem regions or not + * @region_count : Number of regions added in this subsystem toc + * @regions_baseptr : regions base pointer of the subsystem + */ +struct minidump_subsystem { + __le32 status; + __le32 enabled; + __le32 encryption_status; + __le32 encryption_required; + __le32 region_count; + __le64 regions_baseptr; +}; + +/** + * struct minidump_global_toc - Global Table of Content + * @status : Global Minidump init status + * @md_revision : Minidump revision + * @enabled : Minidump enable status + * @subsystems : Array of subsystems toc + */ +struct minidump_global_toc { + __le32 status; + __le32 md_revision; + __le32 enabled; + struct minidump_subsystem subsystems[MAX_NUM_OF_SS]; +}; + +#endif /* _QCOM_MINIDUMP_INTERNAL_H_ */ diff --git a/drivers/soc/qcom/qcom_rproc_minidump.c b/drivers/soc/qcom/qcom= _rproc_minidump.c new file mode 100644 index 000000000000..9bc84cc2536f --- /dev/null +++ b/drivers/soc/qcom/qcom_rproc_minidump.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_minidump_internal.h" + +static void qcom_minidump_cleanup(struct rproc *rproc) +{ + struct rproc_dump_segment *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) { + list_del(&entry->node); + kfree(entry->priv); + kfree(entry); + } +} + +static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump= _subsystem *subsystem, + void (*rproc_dumpfn_t)(struct rproc *rproc, struct rproc_dump_segment *= segment, + void *dest, size_t offset, size_t size)) +{ + struct minidump_region __iomem *ptr; + struct minidump_region region; + int seg_cnt, i; + dma_addr_t da; + size_t size; + char *name; + + if (WARN_ON(!list_empty(&rproc->dump_segments))) { + dev_err(&rproc->dev, "dump segment list already populated\n"); + return -EUCLEAN; + } + + seg_cnt =3D le32_to_cpu(subsystem->region_count); + ptr =3D ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr), + seg_cnt * sizeof(struct minidump_region)); + if (!ptr) + return -EFAULT; + + for (i =3D 0; i < seg_cnt; i++) { + memcpy_fromio(®ion, ptr + i, sizeof(region)); + if (le32_to_cpu(region.valid) =3D=3D MINIDUMP_REGION_VALID) { + name =3D kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL); + if (!name) { + iounmap(ptr); + return -ENOMEM; + } + da =3D le64_to_cpu(region.address); + size =3D le64_to_cpu(region.size); + rproc_coredump_add_custom_segment(rproc, da, size, rproc_dumpfn_t, name= ); + } + } + + iounmap(ptr); + return 0; +} + +void qcom_rproc_minidump(struct rproc *rproc, unsigned int minidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)) +{ + int ret; + struct minidump_subsystem *subsystem; + struct minidump_global_toc *toc; + + /* Get Global minidump ToC*/ + toc =3D qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL); + + /* check if global table pointer exists and init is set */ + if (IS_ERR(toc) || !toc->status) { + dev_err(&rproc->dev, "Minidump TOC not found in SMEM\n"); + return; + } + + /* Get subsystem table of contents using the minidump id */ + subsystem =3D &toc->subsystems[minidump_id]; + + /** + * Collect minidump if SS ToC is valid and segment table + * is initialized in memory and encryption status is set. + */ + if (subsystem->regions_baseptr =3D=3D 0 || + le32_to_cpu(subsystem->status) !=3D 1 || + le32_to_cpu(subsystem->enabled) !=3D MINIDUMP_SS_ENABLED || + le32_to_cpu(subsystem->encryption_status) !=3D MINIDUMP_SS_ENCR_DONE)= { + dev_err(&rproc->dev, "Minidump not ready, skipping\n"); + return; + } + + ret =3D qcom_add_minidump_segments(rproc, subsystem, rproc_dumpfn_t); + if (ret) { + dev_err(&rproc->dev, "Failed with error: %d while adding minidump entrie= s\n", ret); + goto clean_minidump; + } + rproc_coredump_using_sections(rproc); +clean_minidump: + qcom_minidump_cleanup(rproc); +} +EXPORT_SYMBOL_GPL(qcom_rproc_minidump); + +MODULE_DESCRIPTION("Qualcomm remoteproc minidump(smem) helper module"); +MODULE_LICENSE("GPL"); diff --git a/include/soc/qcom/qcom_minidump.h b/include/soc/qcom/qcom_minid= ump.h new file mode 100644 index 000000000000..cd87caef919d --- /dev/null +++ b/include/soc/qcom/qcom_minidump.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _QCOM_MINIDUMP_H_ +#define _QCOM_MINIDUMP_H_ + +struct rproc; +struct rproc_dump_segment; + +#if IS_ENABLED(CONFIG_QCOM_RPROC_MINIDUMP) +void qcom_rproc_minidump(struct rproc *rproc, unsigned int minidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)); +#else +static inline void qcom_rproc_minidump(struct rproc *rproc, unsigned int m= inidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)) { } +#endif /* CONFIG_QCOM_RPROC_MINIDUMP */ +#endif /* _QCOM_MINIDUMP_H_ */ --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 E7CD53A1B6; Tue, 9 Jan 2024 15:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="JFriXJ/9" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409DgLZQ023930; Tue, 9 Jan 2024 15:48:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=+iz/KDghEOECmAX5bp6ac8UBJUPavfQUj6HKKlQ4FLY=; b=JF riXJ/9qcYez9WklVi/zwXZlD8P/GYg9D8KHZrMUX6MJefSmAFeHOCfpStMph0b3Q dnhfYiqgcJm5ti7j4lTiUxs7htcOzSzfzIP4aXn+nbp/p4D4j0e1LOEOKUy9mgvj YoSuIJ8MFh9nKxD7LfgnFsu5tw+9IVjK5H2ku9Js/vW5d4/DpwEnGsyPmSScLQI0 hbUU/sI92PE8Rxriyc+dTdPPwh14Ncrk5hc+24uth6rHeo4FDtihj422bW7HaDSK lVCpX6mHRON9B+fROlNs3zt1O6w4ccNymYCQY7oQ5aM8QFP9UquSdr4OXPp2Jmyy Zj1toBr3lWLgBO3vuZKA== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgwx39b60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:48:56 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FmtA5014822 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:48:55 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:48:50 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 03/12] remoteproc: qcom_q6v5_pas: Use qcom_rproc_minidump() Date: Tue, 9 Jan 2024 21:01:51 +0530 Message-ID: <20240109153200.12848-4-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YnB6-3xPgUB8NenYlPRyfhNEqcGEi2Zm X-Proofpoint-ORIG-GUID: YnB6-3xPgUB8NenYlPRyfhNEqcGEi2Zm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 impostorscore=0 clxscore=1015 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Now, as all the minidump specific data structure is moved to minidump specific files and implementation wise qcom_rproc_minidump() and qcom_minidump() exactly same and the name qcom_rproc_minidump make more sense as it happen to collect the minidump for the remoteproc processors. So, let's use qcom_rproc_minidump() and we will be removing qcom_minidump() and minidump related stuff from driver/remoteproc/qcom_common.c . Signed-off-by: Mukesh Ojha --- drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/qcom_q6v5_pas.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 48845dc8fa85..cea960749e2c 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -166,6 +166,7 @@ config QCOM_PIL_INFO =20 config QCOM_RPROC_COMMON tristate + select QCOM_RPROC_MINIDUMP =20 config QCOM_Q6V5_COMMON tristate diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q= 6v5_pas.c index a9dd58608052..21e2e8eb0b2f 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 #include "qcom_common.h" #include "qcom_pil_info.h" @@ -131,7 +132,7 @@ static void adsp_minidump(struct rproc *rproc) if (rproc->dump_conf =3D=3D RPROC_COREDUMP_DISABLED) return; =20 - qcom_minidump(rproc, adsp->minidump_id, adsp_segment_dump); + qcom_rproc_minidump(rproc, adsp->minidump_id, adsp_segment_dump); } =20 static int adsp_pds_enable(struct qcom_adsp *adsp, struct device **pds, --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 DA9D53A1D8; Tue, 9 Jan 2024 15:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="cijEWpHO" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409FQVQV030892; Tue, 9 Jan 2024 15:49:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=E5ZBEKhML5zzIDJkNKeCZoNN28sYgImgOcEqdeDbsz8=; b=ci jEWpHOzXx9fPrSJ4UC10y+WgeqKETeS+752LqvzHqh8lFH76+54d5tEnvZ50NYBU iydYjqqKY8w4w+GZk8yWp7IP0EpNzQcAdU0+Y/wiLiDso7/XQtLflAl6GJJEBZ2T dm1bq+UxP5kXg7PC0XRWcjMnGIRY8zA1qFzYFaAzHZ5VQQ1XsBeEqTl0E8PDNDz5 +/qWBGfjPzEQAbNLDCMXDGHYd4y3e6gu65SB1Zf/IJ7JVFT3fYMzLD0HYq+AEic1 RLI/B7l8eOZJQE/HnymX3F3Qa5AyGNxjeF8fdJ1+wUxO7+V3z1XhWUDBoewzsTVQ V4RK6ElqBk4pQDtViKog== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh85t0452-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:01 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409Fn0Pk025971 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:00 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:48:55 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 04/12] remoteproc: qcom: Remove minidump related data from qcom_common.c Date: Tue, 9 Jan 2024 21:01:52 +0530 Message-ID: <20240109153200.12848-5-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: -qYE_dguHlcuhW1XXpLZCfMPP1O4lKhE X-Proofpoint-GUID: -qYE_dguHlcuhW1XXpLZCfMPP1O4lKhE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" As minidump specific data structure and functions move under config QCOM_RPROC_MINIDUMP, so remove minidump specific data from driver/remoteproc/qcom_common.c . Signed-off-by: Mukesh Ojha --- drivers/remoteproc/qcom_common.c | 160 ------------------------------- 1 file changed, 160 deletions(-) diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_com= mon.c index 03e5f5d533eb..085fd73fa23a 100644 --- a/drivers/remoteproc/qcom_common.c +++ b/drivers/remoteproc/qcom_common.c @@ -17,7 +17,6 @@ #include #include #include -#include =20 #include "remoteproc_internal.h" #include "qcom_common.h" @@ -26,61 +25,6 @@ #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev) #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev) =20 -#define MAX_NUM_OF_SS 10 -#define MAX_REGION_NAME_LENGTH 16 -#define SBL_MINIDUMP_SMEM_ID 602 -#define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' << = 0) -#define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' << = 0) -#define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << 0) - -/** - * struct minidump_region - Minidump region - * @name : Name of the region to be dumped - * @seq_num: : Use to differentiate regions with same name. - * @valid : This entry to be dumped (if set to 1) - * @address : Physical address of region to be dumped - * @size : Size of the region - */ -struct minidump_region { - char name[MAX_REGION_NAME_LENGTH]; - __le32 seq_num; - __le32 valid; - __le64 address; - __le64 size; -}; - -/** - * struct minidump_subsystem - Subsystem's SMEM Table of content - * @status : Subsystem toc init status - * @enabled : if set to 1, this region would be copied during coredump - * @encryption_status: Encryption status for this subsystem - * @encryption_required : Decides to encrypt the subsystem regions or not - * @region_count : Number of regions added in this subsystem toc - * @regions_baseptr : regions base pointer of the subsystem - */ -struct minidump_subsystem { - __le32 status; - __le32 enabled; - __le32 encryption_status; - __le32 encryption_required; - __le32 region_count; - __le64 regions_baseptr; -}; - -/** - * struct minidump_global_toc - Global Table of Content - * @status : Global Minidump init status - * @md_revision : Minidump revision - * @enabled : Minidump enable status - * @subsystems : Array of subsystems toc - */ -struct minidump_global_toc { - __le32 status; - __le32 md_revision; - __le32 enabled; - struct minidump_subsystem subsystems[MAX_NUM_OF_SS]; -}; - struct qcom_ssr_subsystem { const char *name; struct srcu_notifier_head notifier_list; @@ -90,110 +34,6 @@ struct qcom_ssr_subsystem { static LIST_HEAD(qcom_ssr_subsystem_list); static DEFINE_MUTEX(qcom_ssr_subsys_lock); =20 -static void qcom_minidump_cleanup(struct rproc *rproc) -{ - struct rproc_dump_segment *entry, *tmp; - - list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) { - list_del(&entry->node); - kfree(entry->priv); - kfree(entry); - } -} - -static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump= _subsystem *subsystem, - void (*rproc_dumpfn_t)(struct rproc *rproc, struct rproc_dump_segment *= segment, - void *dest, size_t offset, size_t size)) -{ - struct minidump_region __iomem *ptr; - struct minidump_region region; - int seg_cnt, i; - dma_addr_t da; - size_t size; - char *name; - - if (WARN_ON(!list_empty(&rproc->dump_segments))) { - dev_err(&rproc->dev, "dump segment list already populated\n"); - return -EUCLEAN; - } - - seg_cnt =3D le32_to_cpu(subsystem->region_count); - ptr =3D ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr), - seg_cnt * sizeof(struct minidump_region)); - if (!ptr) - return -EFAULT; - - for (i =3D 0; i < seg_cnt; i++) { - memcpy_fromio(®ion, ptr + i, sizeof(region)); - if (le32_to_cpu(region.valid) =3D=3D MINIDUMP_REGION_VALID) { - name =3D kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL); - if (!name) { - iounmap(ptr); - return -ENOMEM; - } - da =3D le64_to_cpu(region.address); - size =3D le64_to_cpu(region.size); - rproc_coredump_add_custom_segment(rproc, da, size, rproc_dumpfn_t, name= ); - } - } - - iounmap(ptr); - return 0; -} - -void qcom_minidump(struct rproc *rproc, unsigned int minidump_id, - void (*rproc_dumpfn_t)(struct rproc *rproc, - struct rproc_dump_segment *segment, void *dest, size_t offset, - size_t size)) -{ - int ret; - struct minidump_subsystem *subsystem; - struct minidump_global_toc *toc; - - /* Get Global minidump ToC*/ - toc =3D qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL); - - /* check if global table pointer exists and init is set */ - if (IS_ERR(toc) || !toc->status) { - dev_err(&rproc->dev, "Minidump TOC not found in SMEM\n"); - return; - } - - /* Get subsystem table of contents using the minidump id */ - subsystem =3D &toc->subsystems[minidump_id]; - - /** - * Collect minidump if SS ToC is valid and segment table - * is initialized in memory and encryption status is set. - */ - if (subsystem->regions_baseptr =3D=3D 0 || - le32_to_cpu(subsystem->status) !=3D 1 || - le32_to_cpu(subsystem->enabled) !=3D MINIDUMP_SS_ENABLED) { - return rproc_coredump(rproc); - } - - if (le32_to_cpu(subsystem->encryption_status) !=3D MINIDUMP_SS_ENCR_DONE)= { - dev_err(&rproc->dev, "Minidump not ready, skipping\n"); - return; - } - - /** - * Clear out the dump segments populated by parse_fw before - * re-populating them with minidump segments. - */ - rproc_coredump_cleanup(rproc); - - ret =3D qcom_add_minidump_segments(rproc, subsystem, rproc_dumpfn_t); - if (ret) { - dev_err(&rproc->dev, "Failed with error: %d while adding minidump entrie= s\n", ret); - goto clean_minidump; - } - rproc_coredump_using_sections(rproc); -clean_minidump: - qcom_minidump_cleanup(rproc); -} -EXPORT_SYMBOL_GPL(qcom_minidump); - static int glink_subdev_start(struct rproc_subdev *subdev) { struct qcom_rproc_glink *glink =3D to_glink_subdev(subdev); --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 498863A8C8; Tue, 9 Jan 2024 15:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FzZ/FmJq" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409D9CUU018828; Tue, 9 Jan 2024 15:49:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=aS6EMqOjnuywpra94CwxUYtjZZkevwG1w1EtemlEeVo=; b=Fz Z/FmJqsMEP4gb24vMeQHSxELuOrnsSPrkH/JEEXrPAIJF5OIv+xEXUhBzEKCRHL1 2UIjDqpFgXdYHpQGVEIEp6t9EnTATWWUAuGPf2sVuKy06OFdvc0xLw7pIr9MlaUE R2ACkUbPJw5OqzSY2HRm9xQNYkxwsAZKj/W/MT2RndWsdyWsKdjh9Olzw2Gq8Eos 7th6vpFDp/njvDp7iLJiavaHw4tuZ3c1YGp9ZMX1MMJjWL1OtWdHvfR5biElG/aJ 0TNoFf2Gg/Sx0EZ08TE/QfqYnjCf8GDaFdVe+kMvY2zL7Ua+/8ifu1acyW51mFLg umCTSAmtpgHYcIbW5o9w== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh3me0nvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:06 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409Fn6Eq014936 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:06 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:01 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 05/12] init: export linux_banner data variable Date: Tue, 9 Jan 2024 21:01:53 +0530 Message-ID: <20240109153200.12848-6-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: FOnrTxNT32hWHdVH3BUjIki5V-tzzJbX X-Proofpoint-GUID: FOnrTxNT32hWHdVH3BUjIki5V-tzzJbX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 suspectscore=0 impostorscore=0 clxscore=1015 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Some debug loadable module like minidump is interested in knowing the kernel version against which it is being build. Let's export linux_banner. Signed-off-by: Mukesh Ojha --- include/linux/init.h | 3 +++ init/version-timestamp.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/linux/init.h b/include/linux/init.h index 3fa3f6241350..023e7f08d26a 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -145,6 +145,9 @@ extern char *saved_command_line; extern unsigned int saved_command_line_len; extern unsigned int reset_devices; =20 +/* Defined in init/version-timestamp.c */ +extern const char linux_banner[]; + /* used by init/main.c */ void setup_arch(char **); void prepare_namespace(void); diff --git a/init/version-timestamp.c b/init/version-timestamp.c index 043cbf80a766..a48f2c19e5d7 100644 --- a/init/version-timestamp.c +++ b/init/version-timestamp.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 struct uts_namespace init_uts_ns =3D { .ns.count =3D REFCOUNT_INIT(2), @@ -28,3 +29,5 @@ struct uts_namespace init_uts_ns =3D { const char linux_banner[] =3D "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n"; + +EXPORT_SYMBOL_GPL(linux_banner); --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 4A9003B795; Tue, 9 Jan 2024 15:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="MqUsWwoa" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409EkOOD019701; Tue, 9 Jan 2024 15:49:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=X3Upbxn+EoSBnFoRUV2X40+BGVj9JFG4Yv+8MPA1Kss=; b=Mq UsWwoa3sPF3cI+Avl6Zu2QWWno0HBG6Q/NHGe0BjJwUxgiBZzyqy3RNojCB60VSy zWe9CiWkhXtxFc2NcPu2q/vKwd1z0UvMpyWv6GuzD8AJrc12sk75/lx+Mp9GbETc joy2seup9GQRgdjA+02fEEGmrhkWXkCQy2+Y6LRadwGkTVx9cXUSpqCwpoEb+fLB KG4w2jdjEgURRaF+ENAPRaZ+PpJ7MbFTaPniq2Oo2FWvY5JeRwMLpNmnVuRv189B /QrbAvlSROSVv2ppY6afpeSF5ZGSqS0hPAp2zoel1RobF5dv+CGuZiZ3Oxis5tYo uhwX3v5uPcYZ7qlr70Lg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh85t045b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:13 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FnBQH002165 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:11 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:06 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 06/12] soc: qcom: Add Qualcomm APSS minidump kernel driver Date: Tue, 9 Jan 2024 21:01:54 +0530 Message-ID: <20240109153200.12848-7-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: tpt7Y_7jfkn4ckHZUHU6UdCu2QI-XuyG X-Proofpoint-GUID: tpt7Y_7jfkn4ckHZUHU6UdCu2QI-XuyG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Minidump is a best effort mechanism to collect useful and predefined data for first level of debugging on end user devices running on Qualcomm SoCs. It is built on the premise that System on Chip (SoC) or subsystem part of SoC crashes, due to a range of hardware and software bugs. Hence, the ability to collect accurate data is only a best-effort. The data collected could be invalid or corrupted, data collection itself could fail, and so on. Qualcomm devices in engineering mode provides a mechanism for generating full system ramdumps for post mortem debugging. But in some cases it's however not feasible to capture the entire content of RAM. The minidump mechanism provides the means for selecting region should be included in the ramdump. The solution supports extracting the ramdump/minidump produced either over USB or stored to an attached storage device. The core of minidump feature is part of Qualcomm's boot firmware code. It initializes shared memory (SMEM), which is a part of DDR and allocates a small section of it to minidump table i.e also called global table of content (G-ToC). Each subsystem (APSS, ADSP, ...) has their own table of segments to be included in the minidump, all references from a descriptor in SMEM (G-ToC). Each segment/region has some details like name, physical address and it's size etc. and it could be anywhere scattered in the DDR. qcom_minidump(core or frontend) driver adds the capability to add inux region to be dumped as part of ram dump collection. It provides appropriate symbol to register/unregister client regions. To simplify post mortem debugging, it creates and maintain an ELF header as first region that gets updated upon registration of a new region. Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/Kconfig | 13 + drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qcom_minidump.c | 606 ++++++++++++++++++++++ drivers/soc/qcom/qcom_minidump_internal.h | 10 + drivers/soc/qcom/smem.c | 20 + include/linux/soc/qcom/smem.h | 2 + include/soc/qcom/qcom_minidump.h | 18 + 7 files changed, 670 insertions(+) create mode 100644 drivers/soc/qcom/qcom_minidump.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 1f81746131fc..56bc0c8a19f9 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -278,4 +278,17 @@ config QCOM_RPROC_MINIDUMP query predefined minidump segments associated with the remote processor and check its validity and end up collecting the dump on remote process= or crash during its recovery. + +config QCOM_MINIDUMP + tristate "QCOM APSS Minidump driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on QCOM_SMEM + help + This config enables linux core infrastructure for Application + processor subsystem (APSS) minidump collection i.e, it enables + Linux clients drivers to register their internal data structures + and debug messages as part of the apss minidump table and when + the SoC is crashed, these selective regions will be dumped + instead of the entire DDR dump. This saves significant amount + of time and/or storage space. endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index aabb361d4b2e..d040fc1ff5a2 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -35,3 +35,4 @@ obj-$(CONFIG_QCOM_ICC_BWMON) +=3D icc-bwmon.o qcom_ice-objs +=3D ice.o obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) +=3D qcom_ice.o obj-$(CONFIG_QCOM_RPROC_MINIDUMP) +=3D qcom_rproc_minidump.o +obj-$(CONFIG_QCOM_MINIDUMP) +=3D qcom_minidump.o diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minid= ump.c new file mode 100644 index 000000000000..c0f76a51d0e8 --- /dev/null +++ b/drivers/soc/qcom/qcom_minidump.c @@ -0,0 +1,606 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_minidump_internal.h" + +/** + * struct minidump_ss_data - Minidump subsystem private data + * @md_ss_toc: Application Subsystem TOC pointer + * @md_regions: Application Subsystem region base pointer + */ +struct minidump_ss_data { + struct minidump_subsystem *md_ss_toc; + struct minidump_region *md_regions; +}; + +/** + * struct minidump_elfhdr - Minidump table elf header + * @ehdr: elf main header + * @shdr: Section header + * @phdr: Program header + * @elf_offset: Section offset in elf + * @strtable_idx: String table current index position + */ +struct minidump_elfhdr { + struct elfhdr *ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + size_t elf_offset; + size_t strtable_idx; +}; + +/** + * struct minidump - Minidump driver data information + * @elf: Minidump elf header + * @dev: Minidump backend device + * @apss_data: APSS driver data + * @md_lock: Lock to protect access to APSS minidump table + */ +struct minidump { + struct minidump_elfhdr elf; + struct device *dev; + struct minidump_ss_data *apss_data; + struct mutex md_lock; +}; + +/* + * In some of the Old Qualcomm devices, boot firmware statically allocates= 300 + * as total number of supported region (including all co-processors) in + * minidump table out of which linux was using 201. In future, this limita= tion + * from boot firmware might get removed by allocating the region dynamical= ly. + * So, keep it compatible with older devices, we can keep the current limi= t for + * Linux to 201. + */ +#define MAX_NUM_ENTRIES 201 +#define MAX_STRTBL_SIZE (MAX_NUM_ENTRIES * MAX_REGION_NAME_LENGTH) + +static struct elf_shdr *elf_shdr_entry_addr(struct elfhdr *ehdr, int idx) +{ + struct elf_shdr *eshdr =3D (struct elf_shdr *)((size_t)ehdr + ehdr->e_sho= ff); + + return &eshdr[idx]; +} + +static struct elf_phdr *elf_phdr_entry_addr(struct elfhdr *ehdr, int idx) +{ + struct elf_phdr *ephdr =3D (struct elf_phdr *)((size_t)ehdr + ehdr->e_pho= ff); + + return &ephdr[idx]; +} + +static char *elf_str_table_start(struct elfhdr *ehdr) +{ + struct elf_shdr *eshdr; + + if (ehdr->e_shstrndx =3D=3D SHN_UNDEF) + return NULL; + + eshdr =3D elf_shdr_entry_addr(ehdr, ehdr->e_shstrndx); + + return (char *)ehdr + eshdr->sh_offset; +} + +static char *elf_lookup_string(struct minidump *md, struct elfhdr *ehdr, i= nt offset) +{ + char *strtab =3D elf_str_table_start(ehdr); + + if (!strtab || (md->elf.strtable_idx < offset)) + return NULL; + + return strtab + offset; +} + +static unsigned int append_str_to_strtable(struct minidump *md, const char= *name) +{ + char *strtab =3D elf_str_table_start(md->elf.ehdr); + unsigned int old_idx =3D md->elf.strtable_idx; + unsigned int ret; + + if (!strtab || !name) + return 0; + + ret =3D old_idx; + old_idx +=3D strscpy((strtab + old_idx), name, MAX_REGION_NAME_LENGTH); + md->elf.strtable_idx =3D old_idx + 1; + + return ret; +} + +static int qcom_md_clear_elfheader(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct elfhdr *ehdr =3D md->elf.ehdr; + struct elf_shdr *shdr; + struct elf_shdr *tmp_shdr; + struct elf_phdr *phdr; + struct elf_phdr *tmp_phdr; + unsigned int phidx; + unsigned int shidx; + unsigned int len; + unsigned int i; + char *shname; + + for (i =3D 0; i < ehdr->e_phnum; i++) { + phdr =3D elf_phdr_entry_addr(ehdr, i); + if (phdr->p_paddr =3D=3D region->phys_addr && + phdr->p_memsz =3D=3D region->size) + break; + } + + if (i =3D=3D ehdr->e_phnum) { + dev_err(md->dev, "Cannot find program header entry in elf\n"); + return -EINVAL; + } + + phidx =3D i; + for (i =3D 0; i < ehdr->e_shnum; i++) { + shdr =3D elf_shdr_entry_addr(ehdr, i); + shname =3D elf_lookup_string(md, ehdr, shdr->sh_name); + if (shname && !strcmp(shname, region->name) && + shdr->sh_addr =3D=3D (elf_addr_t)region->virt_addr && + shdr->sh_size =3D=3D region->size) + break; + } + + if (i =3D=3D ehdr->e_shnum) { + dev_err(md->dev, "Cannot find section header entry in elf\n"); + return -EINVAL; + } + + shidx =3D i; + if (shdr->sh_offset !=3D phdr->p_offset) { + dev_err(md->dev, "Invalid entry details for region: %s\n", region->name); + return -EINVAL; + } + + /* Clear name in string table */ + len =3D strlen(shname) + 1; + memmove(shname, shname + len, md->elf.strtable_idx - shdr->sh_name - len); + md->elf.strtable_idx -=3D len; + + /* Clear program header */ + tmp_phdr =3D elf_phdr_entry_addr(ehdr, phidx); + for (i =3D phidx; i < ehdr->e_phnum - 1; i++) { + tmp_phdr =3D elf_phdr_entry_addr(ehdr, i + 1); + phdr =3D elf_phdr_entry_addr(ehdr, i); + memcpy(phdr, tmp_phdr, sizeof(*phdr)); + phdr->p_offset =3D phdr->p_offset - region->size; + } + memset(tmp_phdr, 0, sizeof(*tmp_phdr)); + ehdr->e_phnum--; + + /* Clear section header */ + tmp_shdr =3D elf_shdr_entry_addr(ehdr, shidx); + for (i =3D shidx; i < ehdr->e_shnum - 1; i++) { + tmp_shdr =3D elf_shdr_entry_addr(ehdr, i + 1); + shdr =3D elf_shdr_entry_addr(ehdr, i); + memcpy(shdr, tmp_shdr, sizeof(*shdr)); + shdr->sh_offset -=3D region->size; + shdr->sh_name -=3D len; + } + + memset(tmp_shdr, 0, sizeof(*tmp_shdr)); + ehdr->e_shnum--; + md->elf.elf_offset -=3D region->size; + + return 0; +} + +static void qcom_md_update_elfheader(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct elfhdr *ehdr =3D md->elf.ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + + shdr =3D elf_shdr_entry_addr(ehdr, ehdr->e_shnum++); + phdr =3D elf_phdr_entry_addr(ehdr, ehdr->e_phnum++); + + shdr->sh_type =3D SHT_PROGBITS; + shdr->sh_name =3D append_str_to_strtable(md, region->name); + shdr->sh_addr =3D (elf_addr_t)region->virt_addr; + shdr->sh_size =3D region->size; + shdr->sh_flags =3D SHF_WRITE; + shdr->sh_offset =3D md->elf.elf_offset; + shdr->sh_entsize =3D 0; + + phdr->p_type =3D PT_LOAD; + phdr->p_offset =3D md->elf.elf_offset; + phdr->p_vaddr =3D (elf_addr_t)region->virt_addr; + phdr->p_paddr =3D region->phys_addr; + phdr->p_filesz =3D phdr->p_memsz =3D region->size; + phdr->p_flags =3D PF_R | PF_W; + md->elf.elf_offset +=3D shdr->sh_size; +} + +static void qcom_md_add_region(struct minidump_ss_data *mdss_data, + const struct qcom_minidump_region *region) +{ + struct minidump_subsystem *mdss_toc =3D mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int region_cnt; + + region_cnt =3D le32_to_cpu(mdss_toc->region_count); + mdr =3D &mdss_data->md_regions[region_cnt]; + strscpy(mdr->name, region->name, sizeof(mdr->name)); + mdr->address =3D cpu_to_le64(region->phys_addr); + mdr->size =3D cpu_to_le64(region->size); + mdr->valid =3D cpu_to_le32(MINIDUMP_REGION_VALID); + region_cnt++; + mdss_toc->region_count =3D cpu_to_le32(region_cnt); +} + +static int qcom_md_get_region_index(struct minidump_ss_data *mdss_data, + const struct qcom_minidump_region *region) +{ + struct minidump_subsystem *mdss_toc =3D mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int i; + unsigned int count; + + count =3D le32_to_cpu(mdss_toc->region_count); + for (i =3D 0; i < count; i++) { + mdr =3D &mdss_data->md_regions[i]; + if (!strcmp(mdr->name, region->name)) + return i; + } + + return -ENOENT; +} + +static int qcom_md_region_unregister(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct minidump_ss_data *mdss_data =3D md->apss_data; + struct minidump_subsystem *mdss_toc =3D mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int region_cnt; + unsigned int idx; + int ret; + + ret =3D qcom_md_get_region_index(mdss_data, region); + if (ret < 0) { + dev_err(md->dev, "%s region is not present\n", region->name); + return ret; + } + + idx =3D ret; + mdr =3D &mdss_data->md_regions[0]; + region_cnt =3D le32_to_cpu(mdss_toc->region_count); + /* + * Left shift all the regions exist after this removed region + * index by 1 to fill the gap and zero out the last region + * present at the end. + */ + memmove(&mdr[idx], &mdr[idx + 1], (region_cnt - idx - 1) * sizeof(*mdr)); + memset(&mdr[region_cnt - 1], 0, sizeof(*mdr)); + region_cnt--; + mdss_toc->region_count =3D cpu_to_le32(region_cnt); + + return 0; +} + +static int qcom_md_region_register(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct minidump_ss_data *mdss_data =3D md->apss_data; + struct minidump_subsystem *mdss_toc =3D mdss_data->md_ss_toc; + unsigned int num_region; + int ret; + + ret =3D qcom_md_get_region_index(mdss_data, region); + if (ret >=3D 0) { + dev_info(md->dev, "%s region is already registered\n", region->name); + return -EEXIST; + } + + /* Check if there is a room for a new entry */ + num_region =3D le32_to_cpu(mdss_toc->region_count); + if (num_region >=3D MAX_NUM_ENTRIES) { + dev_err(md->dev, "maximum region limit %u reached\n", num_region); + return -ENOSPC; + } + + qcom_md_add_region(mdss_data, region); + + return 0; +} + +static bool qcom_minidump_valid_region(const struct qcom_minidump_region *= region) +{ + return region && + strnlen(region->name, MAX_NAME_LENGTH) < MAX_NAME_LENGTH && + region->virt_addr && + region->size && + IS_ALIGNED(region->size, 4); +} + +/** + * qcom_minidump_region_register() - Register region in APSS Minidump tabl= e. + * @region: minidump region. + * + * Return: On success, it returns 0 and negative error value on failure. + */ +static int qcom_minidump_region_register(const struct qcom_minidump_region= *region) +{ + struct minidump *md; + int ret; + + md =3D qcom_smem_minidump_ready(); + if (!md) + return -EPROBE_DEFER; + + if (!qcom_minidump_valid_region(region)) + return -EINVAL; + + mutex_lock(&md->md_lock); + ret =3D qcom_md_region_register(md, region); + if (ret) + goto unlock; + + qcom_md_update_elfheader(md, region); +unlock: + mutex_unlock(&md->md_lock); + return ret; +} + +/** + * qcom_minidump_region_unregister() - Unregister region from APSS Minidum= p table. + * @region: minidump region. + * + * Return: On success, it returns 0 and negative error value on failure. + */ +static int qcom_minidump_region_unregister(const struct qcom_minidump_regi= on *region) +{ + struct minidump *md; + int ret; + + md =3D qcom_smem_minidump_ready(); + if (!md) + return -EPROBE_DEFER; + + if (!qcom_minidump_valid_region(region)) + return -EINVAL; + + mutex_lock(&md->md_lock); + ret =3D qcom_md_region_unregister(md, region); + if (ret) + goto unlock; + + ret =3D qcom_md_clear_elfheader(md, region); +unlock: + mutex_unlock(&md->md_lock); + return ret; +} + +static int qcom_md_add_elfheader(struct minidump *md) +{ + struct qcom_minidump_region elfregion; + struct elfhdr *ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + unsigned int elfh_size; + unsigned int strtbl_off; + unsigned int phdr_off; + unsigned int banner_len; + char *banner; + + banner_len =3D strlen(linux_banner); + /* + * Header buffer contains: + * ELF header, (MAX_NUM_ENTRIES + 4) of Section and Program ELF headers, + * where, 4 additional entries, one for empty header, one for string table + * one for minidump table and one for linux banner. + * + * Linux banner is stored in minidump to aid post mortem tools to determi= ne + * the kernel version. + */ + elfh_size =3D sizeof(*ehdr); + elfh_size +=3D MAX_STRTBL_SIZE; + elfh_size +=3D banner_len + 1; + elfh_size +=3D ((sizeof(*shdr) + sizeof(*phdr)) * (MAX_NUM_ENTRIES + 4)); + elfh_size =3D ALIGN(elfh_size, 4); + + md->elf.ehdr =3D devm_kzalloc(md->dev, elfh_size, GFP_KERNEL); + if (!md->elf.ehdr) + return -ENOMEM; + + ehdr =3D md->elf.ehdr; + /* Assign Section/Program headers offset */ + md->elf.shdr =3D shdr =3D (struct elf_shdr *)(ehdr + 1); + md->elf.phdr =3D phdr =3D (struct elf_phdr *)(shdr + MAX_NUM_ENTRIES); + phdr_off =3D sizeof(*ehdr) + (sizeof(*shdr) * MAX_NUM_ENTRIES); + + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] =3D ELF_CLASS; + ehdr->e_ident[EI_DATA] =3D ELF_DATA; + ehdr->e_ident[EI_VERSION] =3D EV_CURRENT; + ehdr->e_ident[EI_OSABI] =3D ELF_OSABI; + ehdr->e_type =3D ET_CORE; + ehdr->e_machine =3D ELF_ARCH; + ehdr->e_version =3D EV_CURRENT; + ehdr->e_ehsize =3D sizeof(*ehdr); + ehdr->e_phoff =3D phdr_off; + ehdr->e_phentsize =3D sizeof(*phdr); + ehdr->e_shoff =3D sizeof(*ehdr); + ehdr->e_shentsize =3D sizeof(*shdr); + ehdr->e_shstrndx =3D 1; + + md->elf.elf_offset =3D elfh_size; + /* + * The zeroth index of the section header is reserved and is rarely used. + * Set the section header as null (SHN_UNDEF) and move to the next one. + * 2nd Section is String table. + */ + md->elf.strtable_idx =3D 1; + strtbl_off =3D sizeof(*ehdr) + ((sizeof(*phdr) + sizeof(*shdr)) * MAX_NUM= _ENTRIES); + shdr++; + shdr->sh_type =3D SHT_STRTAB; + shdr->sh_offset =3D (elf_addr_t)strtbl_off; + shdr->sh_size =3D MAX_STRTBL_SIZE; + shdr->sh_entsize =3D 0; + shdr->sh_flags =3D 0; + shdr->sh_name =3D append_str_to_strtable(md, "STR_TBL"); + shdr++; + + /* 3rd Section is Linux banner */ + banner =3D (char *)ehdr + strtbl_off + MAX_STRTBL_SIZE; + memcpy(banner, linux_banner, banner_len); + + shdr->sh_type =3D SHT_PROGBITS; + shdr->sh_offset =3D (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE); + shdr->sh_size =3D banner_len + 1; + shdr->sh_addr =3D (elf_addr_t)linux_banner; + shdr->sh_entsize =3D 0; + shdr->sh_flags =3D SHF_WRITE; + shdr->sh_name =3D append_str_to_strtable(md, "linux_banner"); + + phdr->p_type =3D PT_LOAD; + phdr->p_offset =3D (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE); + phdr->p_vaddr =3D (elf_addr_t)linux_banner; + phdr->p_paddr =3D virt_to_phys(linux_banner); + phdr->p_filesz =3D phdr->p_memsz =3D banner_len + 1; + phdr->p_flags =3D PF_R | PF_W; + + /* + * Above are some prdefined sections/program header used + * for debug, update their count here. + */ + ehdr->e_phnum =3D 1; + ehdr->e_shnum =3D 3; + + /* Register ELF header as first region */ + strscpy(elfregion.name, "KELF_HEADER", sizeof(elfregion.name)); + elfregion.virt_addr =3D md->elf.ehdr; + elfregion.phys_addr =3D virt_to_phys(md->elf.ehdr); + elfregion.size =3D elfh_size; + + return qcom_md_region_register(md, &elfregion); +} + +static int qcom_apss_md_table_init(struct minidump *md, + struct minidump_subsystem *mdss_toc) +{ + struct minidump_ss_data *mdss_data; + + mdss_data =3D devm_kzalloc(md->dev, sizeof(*mdss_data), GFP_KERNEL); + if (!mdss_data) + return -ENOMEM; + + mdss_data->md_ss_toc =3D mdss_toc; + mdss_data->md_regions =3D devm_kcalloc(md->dev, MAX_NUM_ENTRIES, + sizeof(*mdss_data->md_regions), + GFP_KERNEL); + if (!mdss_data->md_regions) + return -ENOMEM; + + mdss_toc =3D mdss_data->md_ss_toc; + mdss_toc->regions_baseptr =3D cpu_to_le64(virt_to_phys(mdss_data->md_regi= ons)); + mdss_toc->enabled =3D cpu_to_le32(MINIDUMP_SS_ENABLED); + mdss_toc->status =3D cpu_to_le32(1); + mdss_toc->region_count =3D cpu_to_le32(0); + + /* Tell bootloader not to encrypt the regions of this subsystem */ + mdss_toc->encryption_status =3D cpu_to_le32(MINIDUMP_SS_ENCR_DONE); + mdss_toc->encryption_required =3D cpu_to_le32(MINIDUMP_SS_ENCR_NOTREQ); + + md->apss_data =3D mdss_data; + + return 0; +} + +static void qcom_apss_md_table_exit(struct minidump_ss_data *mdss_data) +{ + memset(mdss_data->md_ss_toc, cpu_to_le32(0), sizeof(*mdss_data->md_ss_toc= )); +} + +static int qcom_apss_minidump_probe(struct platform_device *pdev) +{ + struct minidump_global_toc *mdgtoc; + struct minidump *md; + size_t size; + int ret; + + md =3D devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); + if (!md) + return -ENOMEM; + + md->dev =3D &pdev->dev; + mdgtoc =3D qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, &size); + if (IS_ERR(mdgtoc)) { + ret =3D PTR_ERR(mdgtoc); + return dev_err_probe(md->dev, ret, + "Couldn't find minidump smem item\n"); + } + + if (size < sizeof(*mdgtoc) || !mdgtoc->status) { + ret =3D -EINVAL; + return dev_err_probe(md->dev, ret, + "minidump table is not initialized\n"); + } + + mutex_init(&md->md_lock); + ret =3D qcom_apss_md_table_init(md, &mdgtoc->subsystems[MINIDUMP_APSS_DES= C]); + if (ret) + return dev_err_probe(md->dev, ret, + "apss minidump initialization failed\n"); + + /* First entry would be ELF header */ + ret =3D qcom_md_add_elfheader(md); + if (ret) { + qcom_apss_md_table_exit(md->apss_data); + return dev_err_probe(md->dev, ret, "Failed to add elf header\n"); + } + + platform_set_drvdata(pdev, md); + + return ret; +} + +static void qcom_apss_minidump_remove(struct platform_device *pdev) +{ + struct minidump *md =3D platform_get_drvdata(pdev); + + qcom_apss_md_table_exit(md->apss_data); +} + +static const struct platform_device_id qcom_minidump_id_table[] =3D { + { .name =3D "qcom_minidump_smem" }, + {} +}; +MODULE_DEVICE_TABLE(platform, qcom_minidump_id_table); + +static struct platform_driver qcom_minidump_driver =3D { + .probe =3D qcom_apss_minidump_probe, + .remove_new =3D qcom_apss_minidump_remove, + .driver =3D { + .name =3D "qcom_minidump_smem", + }, + .id_table =3D qcom_minidump_id_table, +}; + +module_platform_driver(qcom_minidump_driver); + +MODULE_DESCRIPTION("Qualcomm APSS minidump driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/soc/qcom/qcom_minidump_internal.h b/drivers/soc/qcom/q= com_minidump_internal.h index 71709235b196..a2aebe5b690a 100644 --- a/drivers/soc/qcom/qcom_minidump_internal.h +++ b/drivers/soc/qcom/qcom_minidump_internal.h @@ -9,10 +9,20 @@ #define MAX_NUM_OF_SS 10 #define MAX_REGION_NAME_LENGTH 16 #define SBL_MINIDUMP_SMEM_ID 602 + #define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' <= < 0) +#define MINIDUMP_REGION_INVALID ('I' << 24 | 'N' << 16 | 'V' << 8 | 'A'= << 0) +#define MINIDUMP_REGION_INIT ('I' << 24 | 'N' << 16 | 'I' << 8 | 'T' <<= 0) +#define MINIDUMP_REGION_NOINIT 0 + +#define MINIDUMP_SS_ENCR_REQ (0 << 24 | 'Y' << 16 | 'E' << 8 | 'S' << 0) +#define MINIDUMP_SS_ENCR_NOTREQ (0 << 24 | 0 << 16 | 'N' << 8 | 'R' << = 0) +#define MINIDUMP_SS_ENCR_START ('S' << 24 | 'T' << 16 | 'R' << 8 | 'T' = << 0) #define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' <= < 0) #define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << = 0) =20 +#define MINIDUMP_APSS_DESC 0 + /** * struct minidump_region - Minidump region * @name : Name of the region to be dumped diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 690afc9a12f4..d6d5f4ade471 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -270,6 +270,7 @@ struct smem_region { * @partitions: list of partitions of current processor/host * @item_count: max accepted item number * @socinfo: platform device pointer + * @minidump: minidump platform device pointer * @num_regions: number of @regions * @regions: list of the memory regions defining the shared memory */ @@ -280,6 +281,7 @@ struct qcom_smem { =20 u32 item_count; struct platform_device *socinfo; + struct platform_device *minidump; struct smem_ptable *ptable; struct smem_partition global_partition; struct smem_partition partitions[SMEM_HOST_COUNT]; @@ -806,6 +808,15 @@ int qcom_smem_get_soc_id(u32 *id) } EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id); =20 +void *qcom_smem_minidump_ready(void) +{ + if (__smem && __smem->minidump) + return platform_get_drvdata(__smem->minidump); + else + return NULL; +} +EXPORT_SYMBOL_GPL(qcom_smem_minidump_ready); + static int qcom_smem_get_sbl_version(struct qcom_smem *smem) { struct smem_header *header; @@ -1184,11 +1195,20 @@ static int qcom_smem_probe(struct platform_device *= pdev) if (IS_ERR(smem->socinfo)) dev_dbg(&pdev->dev, "failed to register socinfo device\n"); =20 + smem->minidump =3D platform_device_register_data(&pdev->dev, "qcom_minidu= mp_smem", + PLATFORM_DEVID_NONE, NULL, + 0); + if (IS_ERR(smem->minidump)) { + dev_dbg(&pdev->dev, "failed to register minidump device\n"); + smem->minidump =3D NULL; + } + return 0; } =20 static void qcom_smem_remove(struct platform_device *pdev) { + platform_device_unregister(__smem->minidump); platform_device_unregister(__smem->socinfo); =20 hwspin_lock_free(__smem->hwlock); diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h index a36a3b9d4929..08288360a55e 100644 --- a/include/linux/soc/qcom/smem.h +++ b/include/linux/soc/qcom/smem.h @@ -14,4 +14,6 @@ phys_addr_t qcom_smem_virt_to_phys(void *p); =20 int qcom_smem_get_soc_id(u32 *id); =20 +void *qcom_smem_minidump_ready(void); + #endif diff --git a/include/soc/qcom/qcom_minidump.h b/include/soc/qcom/qcom_minid= ump.h index cd87caef919d..9fdf9e9d0af3 100644 --- a/include/soc/qcom/qcom_minidump.h +++ b/include/soc/qcom/qcom_minidump.h @@ -6,6 +6,24 @@ #ifndef _QCOM_MINIDUMP_H_ #define _QCOM_MINIDUMP_H_ =20 +#define MAX_NAME_LENGTH 12 + +/** + * struct qcom_minidump_region - APSS Minidump region information + * + * @name: Entry name, Minidump will dump binary with this name. + * @virt_addr: Virtual address of the entry. + * @phys_addr: Physical address of the entry to dump. + * @size: Number of byte to dump from @address location, + * and it should be 4 byte aligned. + */ +struct qcom_minidump_region { + char name[MAX_NAME_LENGTH]; + void *virt_addr; + phys_addr_t phys_addr; + size_t size; +}; + struct rproc; struct rproc_dump_segment; =20 --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 567FF3B797; Tue, 9 Jan 2024 15:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FFEHIHGT" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409EVLGE004844; Tue, 9 Jan 2024 15:49:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=vnRoE3vtWb9uvqpMk6n0V18KbeM0DmXEdUzBw5s6GuQ=; b=FF EHIHGT5/TgtMVexqQLBxKTAY4gnTaiZPi+ldSO9e/SsKofN59iDbRUml8w2d7WXa c0FE2M3xdC1vpQJ18DambkSfDTeJOKbLVOfMptgmjiDlrzRGU9bVSRelM3ZAYcL8 1e0x0ocrIMdDGOdI5gP3Us2AUZVC5snRLLcueZztMZ2zM5CwVe3VFkbBz9lctpq8 hoIn0L4L4seDrWhGfOosu0yLPaOojloB9j+9VfJxBbJOeJWFwb+Mm7PcGdRHFNBW vg/ta3Nk6vAJx1hRb9a3jUxbpjAgwzAUbwF6eOBBrGSssmHPnXb7XOCLZM0YrEvS qA5ugWBxpheqvnWXLqiw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgw1k1e95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:18 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FnHQI013819 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:17 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:12 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 07/12] MAINTAINERS: Add entry for minidump related files Date: Tue, 9 Jan 2024 21:01:55 +0530 Message-ID: <20240109153200.12848-8-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: ji_jXzeJME51OsgKB4eX5UcKoknkTY0i X-Proofpoint-ORIG-GUID: ji_jXzeJME51OsgKB4eX5UcKoknkTY0i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 impostorscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxlogscore=902 lowpriorityscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Add the entries into maintainer file for all the minidump related modules. Signed-off-by: Mukesh Ojha --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index fa67e2624723..4049bb4a1f8c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18162,6 +18162,16 @@ S: Maintained F: Documentation/devicetree/bindings/regulator/vqmmc-ipq4019-regulator.yaml F: drivers/regulator/vqmmc-ipq4019-regulator.c =20 +QUALCOMM MINIDUMP DRIVER +M: Mukesh Ojha +L: linux-arm-msm@vger.kernel.org +S: Maintained +F: Documentation/admin-guide/qcom_minidump.rst +F: drivers/soc/qcom/qcom_rproc_minidump.c +F: drivers/soc/qcom/qcom_minidump.c +F: drivers/soc/qcom/qcom_ramoops_minidump.c + + QUALCOMM NAND CONTROLLER DRIVER M: Manivannan Sadhasivam L: linux-mtd@lists.infradead.org --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 15DD43BB4D; Tue, 9 Jan 2024 15:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QyYIjM0g" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409Er2tg000860; Tue, 9 Jan 2024 15:49:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=liHucfX2xMzQKqbz5UJBmDnlLnI/IKgbK0PiZ9KXaXw=; b=Qy YIjM0gxsfFsJBG7LrBhgKmAZL6DFvq8jv9JptWS1iamyZRnsPJJiyXM/qrq9WPHc mHHKgIzyJj/yHnYffTAbZxAk76lEAh3MrzjQ3NEIVJdxrD63jsKyTzvygftwB1Ja knSkZ//hxyPOqva9Nb2dkY4MwV03dbLxPwY4Q2cjFfaVJXvJmn3e8bP+nGDIgB+8 TjBVHIl5xOTeC+FjHeSc/711zbx7O/btGDjwUHCTxBhyW7COPyVbvzbn4taenmj5 9XxkLZHnut+y7UdDLXU3Wih6hj6s9zFBrVmMlCbJ4utfZXkGbeF903lVpYNvwRQD SFDIUH4D4HQv64xy6ttg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh3me0nwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:23 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FnMUm002592 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:22 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:17 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 08/12] pstore/ram: Add dynamic ramoops region support through commandline Date: Tue, 9 Jan 2024 21:01:56 +0530 Message-ID: <20240109153200.12848-9-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: BI1su_t4u_jaBjZDhL9SBdoZbjVXvq7R X-Proofpoint-GUID: BI1su_t4u_jaBjZDhL9SBdoZbjVXvq7R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 suspectscore=0 impostorscore=0 clxscore=1015 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This may not be required for something like Qualcomm's minidump which is interested in knowing addresses of ramoops region but it does not put hard requirement of address being fixed as most of it's SoC does not support warm reset and does not use pstorefs at all instead it has firmware way of collecting ramoops region if it gets to know the address and register it with apss minidump table which is sitting in shared memory region in DDR and firmware will have access to these table during reset and collects it on crash of SoC. So, add the support of reserving ramoops region to be dynamically allocated early during boot if it is request through command line via 'dyn_ramoops_size=3D' and fill up reserved resource structure and export the structure, so that it can be read by ramoops driver. Signed-off-by: Mukesh Ojha --- Documentation/admin-guide/ramoops.rst | 23 +++++++++- fs/pstore/Kconfig | 15 ++++++ fs/pstore/ram.c | 66 +++++++++++++++++++++++++-- include/linux/pstore_ram.h | 5 ++ init/main.c | 2 + 5 files changed, 107 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/ramoops.rst b/Documentation/admin-gu= ide/ramoops.rst index e9f85142182d..517b00981e99 100644 --- a/Documentation/admin-guide/ramoops.rst +++ b/Documentation/admin-guide/ramoops.rst @@ -33,6 +33,13 @@ memory are implementation defined, and won't work on man= y ARMs such as omaps. Setting ``mem_type=3D2`` attempts to treat the memory region as normal mem= ory, which enables full cache on it. This can improve the performance. =20 +Ramoops supports its memory to be allocated dynamically during early boot +for plaforms that does not have support for warm boot i.e., no assurance +of Ram content will be preserved across boot and for these platform +giving static Ramoops memory is not necessary as it has separate backend +mechanism to retrieve ramoops content on system failure. More about +how to enable Dynamic ramoops in ``Setting the parameters`` A.b section. + The memory area is divided into ``record_size`` chunks (also rounded down = to power of two) and each kmesg dump writes a ``record_size`` chunk of information. @@ -59,7 +66,7 @@ Setting the parameters =20 Setting the ramoops parameters can be done in several different manners: =20 - A. Use the module parameters (which have the names of the variables descr= ibed + A.a Use the module parameters (which have the names of the variables des= cribed as before). For quick debugging, you can also reserve parts of memory dur= ing boot and then use the reserved memory for ramoops. For example, assuming a machine with > 128 MB of memory, the following kernel command line will t= ell @@ -68,6 +75,20 @@ Setting the ramoops parameters can be done in several di= fferent manners: =20 mem=3D128M ramoops.mem_address=3D0x8000000 ramoops.ecc=3D1 =20 + A.b Ramoops memory can be also be dynamically reserve by Kernel and in s= uch + scenario ``mem_address`` i.e, Ramoops base address can be anywhere in the= RAM + instead of being fixed and predefined. A separate command line option + ``dyn_ramoops_size=3D`` and kernel config CONFIG_PSTORE_DYNAMIC_RAM= OOPS + is provided to facilitate Dynamic Ramoops memory reservation during early= boot. + The command line option and the config should only be used in the presenc= e of + separate backend which knows how to recover Dynamic Ramoops region otherw= ise + regular ramoops functionality will be impacted. + ``mem_size`` should not be used if Dynamic Ramoops support is requested a= nd if + both are given ``mem_size`` value is overwritten with ``dyn_ramoops_size`= ` value + i.e, Dynamic Ramoops takes precedence:: + + dyn_ramoops_size=3D2M ramoops.console_size=3D2097152 + B. Use Device Tree bindings, as described in ``Documentation/devicetree/bindings/reserved-memory/ramoops.yaml``. For example:: diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index 3acc38600cd1..2f2bb483fd85 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -81,6 +81,21 @@ config PSTORE_RAM =20 For more information, see Documentation/admin-guide/ramoops.rst. =20 +config PSTORE_DYNAMIC_RAMOOPS + bool "Reserve ramoops region dynamically" + select PSTORE_RAM + help + This enables the dynamic reservation of ramoops region for a special ca= se + where there is no requirement to access the logs from pstorefs on next = boot + instead there is separate backend mechanism like minidump present which= has + awareness about the dynamic ramoops region and can recover the logs. Th= is is + enabled via command line parameter dyn_ramoops_size=3D and should= not be + used in absence of separate backend which knows how to recover this dyn= amic + region. + + Note whenever this config is selected ramoops driver will be build stat= ically + into kernel. + config PSTORE_ZONE tristate depends on PSTORE diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 88b34fdbf759..795a8300631e 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -20,6 +20,7 @@ #include #include #include +#include #include =20 #include "internal.h" @@ -103,6 +104,59 @@ struct ramoops_context { }; =20 static struct platform_device *dummy; +static struct resource dyn_ramoops_res =3D { + .name =3D "ramoops", + .start =3D 0, + .end =3D 0, + .flags =3D IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, + .desc =3D IORES_DESC_NONE, +}; +static int dyn_ramoops_size; + +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS +static int __init parse_dyn_ramoops_size(char *p) +{ + char *tmp; + + dyn_ramoops_size =3D memparse(p, &tmp); + if (p =3D=3D tmp) { + pr_err("ramoops: memory size expected\n"); + dyn_ramoops_size =3D 0; + return -EINVAL; + } + + return 0; +} +early_param("dyn_ramoops_size", parse_dyn_ramoops_size); + +/* + * setup_dynamic_ramoops() - reserves memory for dynamic ramoops + * + * This enable dynamic reserve memory support for ramoops through + * command line. + */ +void __init setup_dynamic_ramoops(void) +{ + unsigned long long ramoops_base; + unsigned long long ramoops_size; + + if (!dyn_ramoops_size) + return; + + ramoops_base =3D memblock_phys_alloc_range(dyn_ramoops_size, SMP_CACHE_BY= TES, + 0, MEMBLOCK_ALLOC_NOLEAKTRACE); + if (!ramoops_base) { + pr_err("cannot allocate ramoops dynamic memory (size:0x%llx).\n", + ramoops_size); + dyn_ramoops_size =3D 0; + return; + } + + dyn_ramoops_res.start =3D ramoops_base; + dyn_ramoops_res.end =3D ramoops_base + dyn_ramoops_size - 1; + insert_resource(&iomem_resource, &dyn_ramoops_res); +} +#endif =20 static int ramoops_pstore_open(struct pstore_info *psi) { @@ -915,13 +969,19 @@ static void __init ramoops_register_dummy(void) =20 /* * Prepare a dummy platform data structure to carry the module - * parameters. If mem_size isn't set, then there are no module - * parameters, and we can skip this. + * parameters. + * + * dyn_ramoops_size takes precedence over mem_size if it is + * enabled and valid. */ - if (!mem_size) + if (!dyn_ramoops_size && !mem_size) return; =20 pr_info("using module parameters\n"); + if (dyn_ramoops_size) { + mem_size =3D dyn_ramoops_size; + mem_address =3D dyn_ramoops_res.start; + } =20 memset(&pdata, 0, sizeof(pdata)); pdata.mem_size =3D mem_size; diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 9d65ff94e216..1efff7a38333 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,4 +39,9 @@ struct ramoops_platform_data { struct persistent_ram_ecc_info ecc_info; }; =20 +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS +void __init setup_dynamic_ramoops(void); +#else +static inline void __init setup_dynamic_ramoops(void) {} +#endif #endif diff --git a/init/main.c b/init/main.c index f0b7e21ac67f..9d9fb27a2176 100644 --- a/init/main.c +++ b/init/main.c @@ -100,6 +100,7 @@ #include #include #include +#include #include =20 #include @@ -896,6 +897,7 @@ void start_kernel(void) pr_notice("%s", linux_banner); early_security_init(); setup_arch(&command_line); + setup_dynamic_ramoops(); setup_boot_config(); setup_command_line(command_line); setup_nr_cpu_ids(); --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 EA63C3BB2E; Tue, 9 Jan 2024 15:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="I6o3oXq+" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409DBsxI018744; Tue, 9 Jan 2024 15:49:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=MTcfyMqknt6++95kJjKTMmtXngwvVsrJUhfP77MXY0I=; b=I6 o3oXq+Bi0U4uQZRPeTJt1iOecUBDZyEaGyf/5cZJFHC8REXIQdrzjaomvfquUvnA DzfjVrBNWfaJyritv2yZB72kqD9NG6503EhJU4gLSeaVCTaX4oPsZzugxeyPrafJ uLJ53qfbvRTvtRn5exAeSS09SD99E+yWmBBKdi6dCSxk96lxFnxP6vv22ZPHTC/2 h1IsTA2UTbh6bEqKpx5MzCJV0yci2rsWIwcz7Tg8Y7LopGHFpL3nSLJmbHGPi4KX mlHd76i1+5O13iFyz4MFgIFheh3hLwI0nBJrs2fkzr458cCogELktff7Y2J2cvVC j2YHgo2qANAqyX3v2RSQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh3g68pys-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:29 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FnR1p015521 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:28 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:22 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 09/12] pstore/ram: Add ramoops information notifier support Date: Tue, 9 Jan 2024 21:01:57 +0530 Message-ID: <20240109153200.12848-10-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YjPBnxDZ1Jix9De12XW_FBmhIQSklWiX X-Proofpoint-ORIG-GUID: YjPBnxDZ1Jix9De12XW_FBmhIQSklWiX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 phishscore=0 clxscore=1015 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Client like minidump is interested in knowing ramoops individual zone addresses and their size so that it could register them with its table. Let's introduce a info notifier in ramoops which gets called when ramoops driver probes successfully and it passes the ramoops region information to the passed callback by the client and If the call for ramoops ready register comes after ramoops probe than call the callback directly. Signed-off-by: Mukesh Ojha --- fs/pstore/ram.c | 115 +++++++++++++++++++++++++++++++++++++ include/linux/pstore_ram.h | 12 ++++ 2 files changed, 127 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 795a8300631e..c0f8bf90219f 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include =20 #include "internal.h" #include "ram_internal.h" @@ -101,6 +103,19 @@ struct ramoops_context { unsigned int ftrace_read_cnt; unsigned int pmsg_read_cnt; struct pstore_info pstore; + struct blocking_notifier_head ramoops_notifiers; + bool ramoops_ready; + /* + * Lock to serialize access to ramoops_ready and to not + * miss any ongoing notifier registration while ramoops + * probe is in progress. + */ + struct mutex lock; +}; + +struct ramoops_backend { + struct notifier_block nb; + int (*fn)(const char *, int, void *, phys_addr_t paddr, size_t size); }; =20 static struct platform_device *dummy; @@ -501,6 +516,8 @@ static struct ramoops_context oops_cxt =3D { .write_user =3D ramoops_pstore_write_user, .erase =3D ramoops_pstore_erase, }, + .ramoops_notifiers =3D BLOCKING_NOTIFIER_INIT(oops_cxt.ramoops_notifiers), + .lock =3D __MUTEX_INITIALIZER(oops_cxt.lock), }; =20 static void ramoops_free_przs(struct ramoops_context *cxt) @@ -666,6 +683,99 @@ static int ramoops_init_prz(const char *name, return 0; } =20 +static int __ramoops_info_notifier(struct ramoops_context *cxt, + int (*fn)(const char *, int, + void *, phys_addr_t, size_t)) +{ + struct persistent_ram_zone *prz; + int ret; + int i; + + for (i =3D 0; i < cxt->max_dump_cnt; i++) { + prz =3D cxt->dprzs[i]; + ret =3D fn("dmesg", i, prz->vaddr, prz->paddr, prz->size); + if (ret < 0) + goto err; + } + + if (cxt->console_size) { + prz =3D cxt->cprz; + ret =3D fn("console", 0, prz->vaddr, prz->paddr, prz->size); + if (ret < 0) + goto err; + } + + for (i =3D 0; i < cxt->max_ftrace_cnt; i++) { + prz =3D cxt->fprzs[i]; + ret =3D fn("ftrace", i, prz->vaddr, prz->paddr, prz->size); + if (ret < 0) + goto err; + } + + if (cxt->pmsg_size) { + prz =3D cxt->mprz; + ret =3D fn("pmsg", 0, prz->vaddr, prz->paddr, prz->size); + if (ret < 0) + goto err; + } + +err: + return ret; +} + +static int ramoops_info_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct ramoops_backend *b_info =3D container_of(nb, struct ramoops_backen= d, nb); + struct ramoops_context *cxt =3D data; + + return __ramoops_info_notifier(cxt, b_info->fn); +} + +void *register_ramoops_info_notifier(int (*fn)(const char *, int, + void *, phys_addr_t, size_t)) +{ + struct ramoops_context *cxt =3D &oops_cxt; + struct ramoops_backend *b_info; + + mutex_lock(&cxt->lock); + /* + * There is no need to register callback if ramoops probe + * is already done instead, call the callback directly + */ + if (cxt->ramoops_ready) { + mutex_unlock(&cxt->lock); + __ramoops_info_notifier(cxt, fn); + return NULL; + } + + b_info =3D kzalloc(sizeof(*b_info), GFP_KERNEL); + if (!b_info) { + b_info =3D ERR_PTR(-ENOMEM); + goto out; + } + + b_info->fn =3D fn; + b_info->nb.notifier_call =3D ramoops_info_notifier; + blocking_notifier_chain_register(&cxt->ramoops_notifiers, &b_info->nb); + +out: + mutex_unlock(&cxt->lock); + return b_info; +} +EXPORT_SYMBOL_GPL(register_ramoops_info_notifier); + +void unregister_ramoops_info_notifier(void *b_info) +{ + struct ramoops_context *cxt =3D &oops_cxt; + struct ramoops_backend *tmp =3D b_info; + + mutex_lock(&cxt->lock); + blocking_notifier_chain_unregister(&cxt->ramoops_notifiers, &tmp->nb); + mutex_unlock(&cxt->lock); +} +EXPORT_SYMBOL_GPL(unregister_ramoops_info_notifier); + /* Read a u32 from a dt property and make sure it's safe for an int. */ static int ramoops_parse_dt_u32(struct platform_device *pdev, const char *propname, @@ -915,6 +1025,11 @@ static int ramoops_probe(struct platform_device *pdev) ramoops_pmsg_size =3D pdata->pmsg_size; ramoops_ftrace_size =3D pdata->ftrace_size; =20 + mutex_lock(&cxt->lock); + cxt->ramoops_ready =3D true; + mutex_unlock(&cxt->lock); + blocking_notifier_call_chain(&cxt->ramoops_notifiers, 0, cxt); + pr_info("using 0x%lx@0x%llx, ecc: %d\n", cxt->size, (unsigned long long)cxt->phys_addr, cxt->ecc_info.ecc_size); diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 1efff7a38333..5e472a132d33 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,6 +39,18 @@ struct ramoops_platform_data { struct persistent_ram_ecc_info ecc_info; }; =20 +#if IS_ENABLED(CONFIG_PSTORE_RAM) +void *register_ramoops_info_notifier(int (*fn)(const char *name, int id, + void *vaddr, phys_addr_t paddr, + size_t size)); +void unregister_ramoops_info_notifier(void *); +#else +void *register_ramoops_info_notifier(int (*fn)(const char *name, int id, + void *vaddr, phys_addr_t paddr, + size_t size)) { } +void unregister_ramoops_info_notifier(void *) { } +#endif + #ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS void __init setup_dynamic_ramoops(void); #else --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 4D0B13C464; Tue, 9 Jan 2024 15:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ZCdZWWKB" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409FDnQ7018236; Tue, 9 Jan 2024 15:49:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=vjk2Urixu2/24Wsx4Wue00+ZuZNr9bHOHHjk7+a7zW4=; b=ZC dZWWKBAUQB66a5T0lVHq2MGWHEs/abSry1VZJk6xYyBiRpwhG8eoS2QmWE71+4e0 iUiUbXuNNut+anKJyJLsX0BuNbhb86Bikb3WLEV9TvC31Szd6xpymclLWcCUYU2u RhDJR1REY+2xgLOe1A9dipnXNEM7T4S9w+xFHKeJ92NFDiptqo97JsaG0QdCg1ly 4Vn+tbCDIaErP84aGTeRY/XGlt3woZKw5aVVW8vRBVCNHp2mEbzL2TI0CXl0MmLh LTDJrWa1mpUF+V25cbojnwMxoS1uxoXfQblK+rMygcNXvEKxdqetd8CbaiRiFx54 SqifK1dJTCrDFrTLFqvQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgw1k1e9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:34 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FnXfW027104 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:33 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:28 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 10/12] soc: qcom: register ramoops region with APSS minidump Date: Tue, 9 Jan 2024 21:01:58 +0530 Message-ID: <20240109153200.12848-11-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: h4HEgvBOae1pmWhu9AhKKUv83a4KTTzS X-Proofpoint-ORIG-GUID: h4HEgvBOae1pmWhu9AhKKUv83a4KTTzS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 impostorscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Register ramoops region with APSS minidump so that these region gets captured on system crash. Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/qcom_minidump.c | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minid= ump.c index c0f76a51d0e8..c847cca1d999 100644 --- a/drivers/soc/qcom/qcom_minidump.c +++ b/drivers/soc/qcom/qcom_minidump.c @@ -18,8 +18,10 @@ #include #include #include +#include #include #include +#include #include =20 #include "qcom_minidump_internal.h" @@ -56,12 +58,20 @@ struct minidump_elfhdr { * @dev: Minidump backend device * @apss_data: APSS driver data * @md_lock: Lock to protect access to APSS minidump table + * @work: Minidump work for any required execution in process context. */ struct minidump { struct minidump_elfhdr elf; struct device *dev; struct minidump_ss_data *apss_data; struct mutex md_lock; + struct work_struct work; +}; + +static LIST_HEAD(apss_md_rlist); +struct md_region_list { + struct qcom_minidump_region md_region; + struct list_head list; }; =20 /* @@ -530,6 +540,52 @@ static int qcom_apss_md_table_init(struct minidump *md, return 0; } =20 +static int register_ramoops_region(const char *name, int id, void *vaddr, + phys_addr_t paddr, size_t size) +{ + struct qcom_minidump_region *md_region; + struct md_region_list *mdr_list; + int ret; + + mdr_list =3D kzalloc(sizeof(*mdr_list), GFP_KERNEL); + if (!mdr_list) + return -ENOMEM; + + md_region =3D &mdr_list->md_region; + scnprintf(md_region->name, sizeof(md_region->name), "K%s%d", name, id); + md_region->virt_addr =3D vaddr; + md_region->phys_addr =3D paddr; + md_region->size =3D size; + ret =3D qcom_minidump_region_register(md_region); + if (ret < 0) { + pr_err("failed to register region in minidump: err: %d\n", ret); + return ret; + } + + list_add(&mdr_list->list, &apss_md_rlist); + + return 0; +} + +static void register_ramoops_minidump_cb(struct work_struct *work) +{ + register_ramoops_info_notifier(register_ramoops_region); +} + +static void qcom_ramoops_minidump_unregister(void) +{ + struct md_region_list *mdr_list; + struct md_region_list *tmp; + + list_for_each_entry_safe(mdr_list, tmp, &apss_md_rlist, list) { + struct qcom_minidump_region *region; + + region =3D &mdr_list->md_region; + qcom_minidump_region_unregister(region); + list_del(&mdr_list->list); + } +} + static void qcom_apss_md_table_exit(struct minidump_ss_data *mdss_data) { memset(mdss_data->md_ss_toc, cpu_to_le32(0), sizeof(*mdss_data->md_ss_toc= )); @@ -575,6 +631,22 @@ static int qcom_apss_minidump_probe(struct platform_de= vice *pdev) =20 platform_set_drvdata(pdev, md); =20 + /* + * Use separate context for registering ramoops region via workqueue + * as minidump probe can get called in same context of platform device + * register call from smem driver and further call to qcom_smem_minidump_= ready() + * can return -EPROBE_DEFER as __smem->minidump is not yet initialised be= cause + * of same context. + * + * qcom_apss_minidump_probe() + * register_ramoops_minidump_cb() + * register_ramoops_region() + * qcom_minidump_region_register() + * qcom_smem_minidump_ready() + */ + INIT_WORK(&md->work, register_ramoops_minidump_cb); + schedule_work(&md->work); + return ret; } =20 @@ -582,6 +654,9 @@ static void qcom_apss_minidump_remove(struct platform_d= evice *pdev) { struct minidump *md =3D platform_get_drvdata(pdev); =20 + flush_work(&md->work); + qcom_ramoops_minidump_unregister(); + unregister_ramoops_info_notifier(register_ramoops_minidump_cb); qcom_apss_md_table_exit(md->apss_data); } =20 --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 BA8733C464; Tue, 9 Jan 2024 15:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="h3Wxd6/s" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409EBBbX025695; Tue, 9 Jan 2024 15:49:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=pvWii2rG+ndwgTJlbNXZ3/D8TNknZYK59hpEwt0qOHE=; b=h3 Wxd6/sEqKe89E3v4VuATpLRVS1FbKZvv8nqutR7iJfDK+VJnnK2xmkoQ6fzzfIQk T/U+bmoSf4HuiM+LI3rAU56jAI93In7bXUcLHFhMmX1YJqhX0TfPLLWIbSBE/FYs 2MjXlQRcYrZ15mQ3UiRGpZb9eHm4BV5dJWoUD5P1fLEVoPKSQ3YTVu1msERnUhC7 KXpVaH6CBWbV2imDpqx/LbHiAPOXoFXJJ9hnu/wrkjhz3Z+uxaMqDWd0tnAmbrqu 3XTUyhRwJQ9lqCAYiRZT+j4bDl929Ew78AuQqn11gLaymSYGECyXFDNhJhNFSUu5 HiB7O7HUIWuO9Wl6JrDw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgq2yt34v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:39 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FncqF026862 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:38 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:33 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 11/12] firmware: qcom_scm: Refactor code to support multiple dload mode Date: Tue, 9 Jan 2024 21:01:59 +0530 Message-ID: <20240109153200.12848-12-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WsjlKhOlPT_EQ5fqYc_rUEJ7XFv-j9Mn X-Proofpoint-ORIG-GUID: WsjlKhOlPT_EQ5fqYc_rUEJ7XFv-j9Mn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Currently on Qualcomm SoC, download_mode is enabled if CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT is selected. Refactor the code such that it supports multiple download modes and drop CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT config instead, give interface to set the download mode from module parameter. Signed-off-by: Mukesh Ojha --- drivers/firmware/qcom/Kconfig | 11 ------ drivers/firmware/qcom/qcom_scm.c | 58 +++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 3f05d9854ddf..3bbbaef145ad 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -9,17 +9,6 @@ menu "Qualcomm firmware drivers" config QCOM_SCM tristate =20 -config QCOM_SCM_DOWNLOAD_MODE_DEFAULT - bool "Qualcomm download mode enabled by default" - depends on QCOM_SCM - help - A device with "download mode" enabled will upon an unexpected - warm-restart enter a special debug mode that allows the user to - "download" memory content over USB for offline postmortem analysis. - The feature can be enabled/disabled on the kernel command line. - - Say Y here to enable "download mode" by default. - config QCOM_QSEECOM bool "Qualcomm QSEECOM interface driver" depends on QCOM_SCM=3Dy diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_= scm.c index 037e69285b67..1f819f6e14b3 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,8 +27,7 @@ =20 #include "qcom_scm.h" =20 -static bool download_mode =3D IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEF= AULT); -module_param(download_mode, bool, 0); +static u32 download_mode; =20 struct qcom_scm { struct device *dev; @@ -129,6 +129,11 @@ static const char * const qcom_scm_convention_names[] = =3D { [SMC_CONVENTION_LEGACY] =3D "smc legacy", }; =20 +static const char * const download_mode_name[] =3D { + [QCOM_DLOAD_NODUMP] =3D "off", + [QCOM_DLOAD_FULLDUMP] =3D "full", +}; + static struct qcom_scm *__scm; =20 static int qcom_scm_clk_enable(void) @@ -528,19 +533,18 @@ static int __qcom_scm_set_dload_mode(struct device *d= ev, bool enable) return qcom_scm_call_atomic(__scm->dev, &desc, NULL); } =20 -static void qcom_scm_set_download_mode(bool enable) +static void qcom_scm_set_download_mode(u32 download_mode) { - u32 val =3D enable ? QCOM_DLOAD_FULLDUMP : QCOM_DLOAD_NODUMP; int ret =3D 0; =20 if (__scm->dload_mode_addr) { ret =3D qcom_scm_io_rmw(__scm->dload_mode_addr, QCOM_DLOAD_MASK, - FIELD_PREP(QCOM_DLOAD_MASK, val)); + FIELD_PREP(QCOM_DLOAD_MASK, download_mode)); } else if (__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_BOOT, QCOM_SCM_BOOT_SET_DLOAD_MODE)) { - ret =3D __qcom_scm_set_dload_mode(__scm->dev, enable); + ret =3D __qcom_scm_set_dload_mode(__scm->dev, !!download_mode); } else { dev_err(__scm->dev, "No available mechanism for setting download mode\n"); @@ -1842,6 +1846,42 @@ static irqreturn_t qcom_scm_irq_handler(int irq, voi= d *data) return IRQ_HANDLED; } =20 +static int get_download_mode(char *buffer, const struct kernel_param *kp) +{ + if (download_mode >=3D ARRAY_SIZE(download_mode_name)) + return sysfs_emit(buffer, "unknown mode\n"); + + return sysfs_emit(buffer, "%s\n", download_mode_name[download_mode]); +} + +static int set_download_mode(const char *val, const struct kernel_param *k= p) +{ + u32 old =3D download_mode; + int ret; + + ret =3D sysfs_match_string(download_mode_name, val); + if (ret < 0) { + download_mode =3D old; + pr_err("qcom_scm: unknown download mode: %s\n", val); + return -EINVAL; + } + + download_mode =3D ret; + if (__scm) + qcom_scm_set_download_mode(download_mode); + + return 0; +} + +static const struct kernel_param_ops download_mode_param_ops =3D { + .get =3D get_download_mode, + .set =3D set_download_mode, +}; + +module_param_cb(download_mode, &download_mode_param_ops, NULL, 0644); +MODULE_PARM_DESC(download_mode, + "download mode: off/full are acceptable values"); + static int qcom_scm_probe(struct platform_device *pdev) { struct qcom_scm *scm; @@ -1906,12 +1946,12 @@ static int qcom_scm_probe(struct platform_device *p= dev) __get_convention(); =20 /* - * If requested enable "download mode", from this point on warmboot + * If "download mode" is requested, from this point on warmboot * will cause the boot stages to enter download mode, unless * disabled below by a clean shutdown/reboot. */ if (download_mode) - qcom_scm_set_download_mode(true); + qcom_scm_set_download_mode(download_mode); =20 =20 /* @@ -1939,7 +1979,7 @@ static int qcom_scm_probe(struct platform_device *pde= v) static void qcom_scm_shutdown(struct platform_device *pdev) { /* Clean shutdown, disable download mode to allow normal restart */ - qcom_scm_set_download_mode(false); + qcom_scm_set_download_mode(QCOM_DLOAD_NODUMP); } =20 static const struct of_device_id qcom_scm_dt_match[] =3D { --=20 2.43.0.254.ga26002b62827 From nobody Fri Dec 26 05:32:04 2025 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 5575A3C680; Tue, 9 Jan 2024 15:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FPQB6KzN" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409FIPFo014357; Tue, 9 Jan 2024 15:49:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=fnJrBuwLFJ/UXvXpdCRsGVSdYl9Zj+aZGlDGzF+ZLlI=; b=FP QB6KzN5gqpzElBKHva36onYgUUxsqJowLPNP6f/8vnWRNU78iMJymF5WwkbfOJ9Z SHQzFLb7E/tbpvQoG494EYW49b1KMrluUGsB03LFKMFQSd6/2QuIczOQPA+VpdEH zNaQBZ3SkbEvMaLy373CLwPZyA7Iytw0laQRlagoKLPPNeCeS5hpu43Foxfl/op9 JPZVWeT9JRwEG27gfGb6cmzihkyLJGXBPh/4Fks4B5uSJYiZhZaZ2orQBdVWeX8L 8ISk6rSv9RzSkaCur5Dok/2iW93KRWUS2tONasJeKlj747iks19fyI193WehxaLZ 1vTS9D1fpSWg2pRYuf0A== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vh85t046b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:44 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409Fnixi014555 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:44 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:38 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 12/12] firmware/qcom: qcom_scm: Add multiple download mode support Date: Tue, 9 Jan 2024 21:02:00 +0530 Message-ID: <20240109153200.12848-13-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: _lqIZxPcOC8jmYudadi2saGw-os2malp X-Proofpoint-GUID: _lqIZxPcOC8jmYudadi2saGw-os2malp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Currently, scm driver only supports full dump when download mode is selected. Add support to enable minidump as well as enable it along with fulldump. Signed-off-by: Mukesh Ojha --- drivers/firmware/qcom/qcom_scm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_= scm.c index 1f819f6e14b3..6bf1d4b8c837 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -120,6 +120,8 @@ static const u8 qcom_scm_cpu_warm_bits[QCOM_SCM_BOOT_MA= X_CPUS] =3D { enum qcom_dload_mode { QCOM_DLOAD_NODUMP =3D 0, QCOM_DLOAD_FULLDUMP =3D 1, + QCOM_DLOAD_MINIDUMP =3D 2, + QCOM_DLOAD_BOTHDUMP =3D 3, }; =20 static const char * const qcom_scm_convention_names[] =3D { @@ -132,6 +134,8 @@ static const char * const qcom_scm_convention_names[] = =3D { static const char * const download_mode_name[] =3D { [QCOM_DLOAD_NODUMP] =3D "off", [QCOM_DLOAD_FULLDUMP] =3D "full", + [QCOM_DLOAD_MINIDUMP] =3D "mini", + [QCOM_DLOAD_BOTHDUMP] =3D "full,mini", }; =20 static struct qcom_scm *__scm; @@ -1880,7 +1884,7 @@ static const struct kernel_param_ops download_mode_pa= ram_ops =3D { =20 module_param_cb(download_mode, &download_mode_param_ops, NULL, 0644); MODULE_PARM_DESC(download_mode, - "download mode: off/full are acceptable values"); + "download mode: off/full/mini/full,mini are acceptable values"); =20 static int qcom_scm_probe(struct platform_device *pdev) { --=20 2.43.0.254.ga26002b62827