From patchwork Thu Jul 27 19:29:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinh Nguyen X-Patchwork-Id: 127131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1328951vqo; Thu, 27 Jul 2023 12:50:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGUMLaZWNuXAtq3vYxIc0mZrVMpxRBTrf1OJtpXggQDy5BWMQBJwhVEj6uATVTRokdHJ9n4 X-Received: by 2002:a17:906:309a:b0:993:ecc1:a7f2 with SMTP id 26-20020a170906309a00b00993ecc1a7f2mr164278ejv.39.1690487427384; Thu, 27 Jul 2023 12:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690487427; cv=none; d=google.com; s=arc-20160816; b=ofjhMYQhrq2yrEzq6v4RmBeE5jEoTDmG01a9WHlThdzXmOcVl72CZmVgb3z4teurpR vV4r9p7EI6FO1LJBB5u0tWqnNKqqHI4CO7OIH70iTsDN+4Czurk7BS+ei7BVqnh021V7 7+oVmRIRA77/NyEbCfh4Vj6pRSf08bX0miSzZOrPCGsrJai0FNTgyt6PeS2QXQhXLxJK 7+3VM7818AE7ZY14gdZPjlkUQgrH5CVt0cZ+0KiKaAUtp3ACx4y3AAyztMaPp7sFRYUL a32S7xOSsUXH/U8nkkG6EYjefob04/paNBxMgMCaqHqSmGcYAtO9ma2vGClFwrPwMCxK JB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3Ippe2BEVIbcQLnnuaL1n4PCvZUXO7PhjjBYfIXP49s=; fh=ty2ZbszbzXOpTYNlEf9N7Usg8wvpX1UuI4kvMcqV1ic=; b=fVBgrb09q3zu3CutzDC6JdJtx8/gzBoV9kNHqe12sINCDS24eTACtyUqHTDsSERiOm g3kuc9Fq22BIebYmSR6hotTSQt9hVu6ixnF+Sj9JYWkj4iXMBWtwJ7cnOqDeqP0vWEfM YX6Ien2eXQxrPautxhfTDo8euKZaGDkAZWG5WcS0ThqaTQSzbrCPM00u4GIAtNmvdhkO sEnpPZrK6FSsLiM4GPuJOO32mD17lA4UpPOK60Go+l6if0nrX/d760+AHTpxIky3iZqf aclLhvG03ge69GUKWS6TJ/DCpGeYo9WO5oOvje2JgY33nO9zFR2tbriSOKV9eLU8bB6i aTIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GVuadQkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rk21-20020a170907215500b0098902d18096si684876ejb.244.2023.07.27.12.50.01; Thu, 27 Jul 2023 12:50:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GVuadQkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbjG0T3W (ORCPT + 99 others); Thu, 27 Jul 2023 15:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbjG0T3V (ORCPT ); Thu, 27 Jul 2023 15:29:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9762D68 for ; Thu, 27 Jul 2023 12:29:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72D1061F28 for ; Thu, 27 Jul 2023 19:29:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76FF6C433C9; Thu, 27 Jul 2023 19:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690486158; bh=lDhVJhw+KoLFGQn+Fi5lzz+hMTbWiRN+4uj9W/oH9LY=; h=From:To:Cc:Subject:Date:From; b=GVuadQkhNIsq6IxZ4MpiOUeEeHca8gkDzTq1bKTx7cCSTH4zyy1eCm+2XHGVIIjpw hRGo6mNG9wKB9/ojYMnxaiqLFYq1CnCd9eneSeehG1LGcpkx2pHhcHMUW1E0ucBEkx HgEAk+WRHnamez3k4i4jUWywHJyDFRB+opGzy1dsYzgGGBIZyzqrIjHKPAf7pBQISV Jbfi8tWsA9W/7yvhLjoh0WTeQxLDoer+pmpdInkYd9rgXTKrK+B+zMWK4cF/+upGzs gXxM8cYJvi7qZ4+nN2/SP9zfU9+c99gCsO1DQhw3TRKXxvFjTUrI66jk7Jpr5I/bQ1 4YXeWH+Ywn6vg== From: Dinh Nguyen To: gregkh@linuxfoundation.org Cc: dinguyen@kernel.org, linux-kernel@vger.kernel.org, Teh Wen Ping , Kah Jing Lee Subject: [PATCH 1/2] firmware: stratix10-svc: Generic Mailbox Command Date: Thu, 27 Jul 2023 14:29:06 -0500 Message-Id: <20230727192907.982070-1-dinguyen@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772604544491623732 X-GMAIL-MSGID: 1772604544491623732 From: Teh Wen Ping Add generic mailbox command that can support SDM command. User can use this command to send SDM mailbox command. User have to specified an input file which contain the command data and an output file for SDM response to be copied over. Signed-off-by: Teh Wen Ping Signed-off-by: Kah Jing Lee Signed-off-by: Dinh Nguyen --- drivers/firmware/stratix10-svc.c | 18 +++++++++++++ include/linux/firmware/intel/stratix10-smc.h | 25 +++++++++++++++++++ .../firmware/intel/stratix10-svc-client.h | 5 ++++ 3 files changed, 48 insertions(+) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c index 2d674126160f..260695a8a9e6 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -37,6 +37,7 @@ #define SVC_NUM_CHANNEL 3 #define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 200 #define FPGA_CONFIG_STATUS_TIMEOUT_SEC 30 +#define BYTE_TO_WORD_SIZE 4 /* stratix10 service layer clients */ #define STRATIX10_RSU "stratix10-rsu" @@ -361,6 +362,13 @@ static void svc_thread_recv_status_ok(struct stratix10_svc_data *p_data, cb_data->kaddr2 = svc_pa_to_va(res.a2); cb_data->kaddr3 = &res.a3; break; + case COMMAND_MBOX_SEND_CMD: + cb_data->status = BIT(SVC_STATUS_OK); + cb_data->kaddr1 = &res.a1; + /* SDM return size in u8. Convert size to u32 word */ + res.a2 = res.a2 * BYTE_TO_WORD_SIZE; + cb_data->kaddr2 = &res.a2; + break; default: pr_warn("it shouldn't happen\n"); break; @@ -534,6 +542,15 @@ static int svc_normal_to_secure_thread(void *data) a1 = 0; a2 = 0; break; + case COMMAND_MBOX_SEND_CMD: + a0 = INTEL_SIP_SMC_MBOX_SEND_CMD; + a1 = pdata->arg[0]; + a2 = (unsigned long)pdata->paddr; + a3 = (unsigned long)pdata->size / BYTE_TO_WORD_SIZE; + a4 = pdata->arg[1]; + a5 = (unsigned long)pdata->paddr_output; + a6 = (unsigned long)pdata->size_output / BYTE_TO_WORD_SIZE; + break; default: pr_warn("it shouldn't happen\n"); break; @@ -597,6 +614,7 @@ static int svc_normal_to_secure_thread(void *data) case COMMAND_FCS_DATA_ENCRYPTION: case COMMAND_FCS_DATA_DECRYPTION: case COMMAND_FCS_RANDOM_NUMBER_GEN: + case COMMAND_MBOX_SEND_CMD: cbdata->status = BIT(SVC_STATUS_INVALID_PARAM); cbdata->kaddr1 = NULL; cbdata->kaddr2 = NULL; diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/firmware/intel/stratix10-smc.h index a718f853d457..ee80ca4bb0d0 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -466,6 +466,31 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_FIRMWARE_VERSION \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FIRMWARE_VERSION) +/** + * SMC call protocol for Mailbox, starting FUNCID from 60 + * + * Call register usage: + * a0 INTEL_SIP_SMC_MBOX_SEND_CMD + * a1 mailbox command code + * a2 physical address that contain mailbox command data (not include header) + * a3 mailbox command data size in word + * a4 set to 0 for CASUAL, set to 1 for URGENT + * a5 physical address for secure firmware to put response data + * (not include header) + * a6 maximum size in word of physical address to store response data + * a7 not used + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK, INTEL_SIP_SMC_STATUS_REJECTED or + * INTEL_SIP_SMC_STATUS_ERROR + * a1 mailbox error code + * a2 response data length in word + * a3 not used + */ +#define INTEL_SIP_SMC_FUNCID_MBOX_SEND_CMD 60 + #define INTEL_SIP_SMC_MBOX_SEND_CMD \ + INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_MBOX_SEND_CMD) + /** * Request INTEL_SIP_SMC_SVC_VERSION * diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/linux/firmware/intel/stratix10-svc-client.h index 0c16037fd08d..60ed82112680 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -118,6 +118,9 @@ struct stratix10_svc_chan; * @COMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version, * return status is SVC_STATUS_OK * + * @COMMAND_MBOX_SEND_CMD: send generic mailbox command, return status is + * SVC_STATUS_OK or SVC_STATUS_ERROR + * * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status * return status is SVC_STATUS_OK or SVC_STATUS_ERROR * @@ -164,6 +167,8 @@ enum stratix10_svc_command_code { COMMAND_FCS_RANDOM_NUMBER_GEN, /* for general status poll */ COMMAND_POLL_SERVICE_STATUS = 40, + /* for generic mailbox send command */ + COMMAND_MBOX_SEND_CMD = 100, /* Non-mailbox SMC Call */ COMMAND_SMC_SVC_VERSION = 200, }; From patchwork Thu Jul 27 19:29:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinh Nguyen X-Patchwork-Id: 127132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1328964vqo; Thu, 27 Jul 2023 12:50:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgwjlz+wYg35qqYmtAG52SOn9MW7neEYXiQiJbUHFRuBDQqLOb0NbCbF0mR8X7veO3R/Kc X-Received: by 2002:a17:906:13:b0:99b:4aa3:6480 with SMTP id 19-20020a170906001300b0099b4aa36480mr157700eja.40.1690487429008; Thu, 27 Jul 2023 12:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690487428; cv=none; d=google.com; s=arc-20160816; b=x6Lga8UnCS19dEjyyBMEYfb/T2iRe34Man+9kbMH2PhQu/D7DNTM6lrvEvgf/VwZAC yxC/Ghdbg2caoLu3sRsR1E4i9vodlpIV2JVnCtYQNQ+z9baIQvAUXCNQBAme8wvrZw7l lWE3l1anFGF1quo5jzeXlT1+LOLb5O7KXlchU7jEx2dGJviY1O4pcz2QKmV0ljpvDFVK ToUXNDV/L3hyDQXeJfrJdUNRLGrYEpHT1seWg+R+EjMzt1jjzfpL/Dwfr6WyQm0u6en4 unCxhw7nSn3fxerI8dO08WOnM3wNY16uAwjdtssZKYc03KvS0zkCK11661zH6aaFyELw zOMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gaHLLPzz/3OVBfDC5lCg9i5f4Xrrr9TLZkMW1y6RTEk=; fh=yXY/MnILacWF2pcYZiP0dMJJeSgonMsAdVKtVcN5rSg=; b=lV6KCT2zjtmt70cjsWzF2smrBl+Bn4hlDbD5JxVzhA79q7SJXkkiDLYW/4ftILqso5 PQ6ai/Ge4rcC7du3bLbjxf0Y9BE6jnMlaRJUbGa+rN+yxfS7TkCl7D4BZ2lHdN1aC3mc gGZeXEhzywkssRXJz8+jf/x+KW8uvhajcacp6ARB70DwfRd2xuLy8xR0qfxbm9y3kdru Zmusx1Su3ac9jTEp3CJTeZgcvBKBdJ/Fr0Gp2VNxbWTxNYx3V853hWB/+k7CKfy87/PP UKzNJES5XR+f5BakoEL7mRwQdhkL8AK+umUvyn4eWXDg08sNNwL4bcDt4VuzIAMsNTM4 OoBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DxBUh9rj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g24-20020a1709064e5800b00993860a6d3fsi1548984ejw.281.2023.07.27.12.50.03; Thu, 27 Jul 2023 12:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DxBUh9rj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231867AbjG0T3Y (ORCPT + 99 others); Thu, 27 Jul 2023 15:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbjG0T3W (ORCPT ); Thu, 27 Jul 2023 15:29:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95062D6A for ; Thu, 27 Jul 2023 12:29:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E7AE61F2B for ; Thu, 27 Jul 2023 19:29:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47498C433CA; Thu, 27 Jul 2023 19:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690486159; bh=dmGXyNt+lqnv2hCeUuEJ/gcKECOxbpShSy2v9Z2fCmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxBUh9rjGD86sB1b7nL7hTcThLtlHjz7UGiZEkQVozGLyK352Csyf1Ce/8Z/IyKUz NdB/y+uz1CmU+CHuRs7xctjmVIQFWp6b4Ly5S7vy7wMpPp8xzPc1AiHAcVJ7lKB746 jf+FEOTcmWYw4P1vxh9guNbtjnzMVvLnXJtbXQcrx96WLEcDjfQvJDxOabhICU3b4q ZB6+Qs04Bf24s92qkkYdgzK7FH7++gRPVLMMxwCoa4EUOorqPcVijbY+S8jKVe7w4T GwFMnPrMYQ4HJ04Y7/CBGe+XrrJM9zC/ND4JkMCZuYIoIQ0NJ14yTmatHmAp/4LhHI jxgPP9efmjT6A== From: Dinh Nguyen To: gregkh@linuxfoundation.org Cc: dinguyen@kernel.org, linux-kernel@vger.kernel.org, Radu Bacrau , Kah Jing Lee Subject: [PATCH 2/2] firmware: stratix10-rsu: query spt addresses Date: Thu, 27 Jul 2023 14:29:07 -0500 Message-Id: <20230727192907.982070-2-dinguyen@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230727192907.982070-1-dinguyen@kernel.org> References: <20230727192907.982070-1-dinguyen@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772604546378915926 X-GMAIL-MSGID: 1772604546378915926 From: Radu Bacrau Extend Intel Remote System Update (RSU) driver to get SPT (Sub-Partition Table) addresses. The query SPT address can be used to determine if the RSU QSPI layout is 32kB or 64kB aligned. The alignment can be determined by minus the upper with the lower of the SPT addresses. This patch depends on patch: firmware: stratix10-svc: Generic Mailbox Command Signed-off-by: Radu Bacrau Signed-off-by: Kah Jing Lee Signed-off-by: Dinh Nguyen --- drivers/firmware/stratix10-rsu.c | 100 ++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/stratix10-rsu.c b/drivers/firmware/stratix10-rsu.c index e51c95f8d445..fbc54533ad99 100644 --- a/drivers/firmware/stratix10-rsu.c +++ b/drivers/firmware/stratix10-rsu.c @@ -34,6 +34,10 @@ #define INVALID_RETRY_COUNTER 0xFF #define INVALID_DCMF_VERSION 0xFF #define INVALID_DCMF_STATUS 0xFFFFFFFF +#define INVALID_SPT_ADDRESS 0x0 + +#define RSU_GET_SPT_CMD 0x5A +#define RSU_GET_SPT_RESP_LEN (4 * sizeof(unsigned int)) typedef void (*rsu_callback)(struct stratix10_svc_client *client, struct stratix10_svc_cb_data *data); @@ -59,6 +63,9 @@ typedef void (*rsu_callback)(struct stratix10_svc_client *client, * @dcmf_status.dcmf3: dcmf3 status * @retry_counter: the current image's retry counter * @max_retry: the preset max retry value + * @spt0_address: address of spt0 + * @spt1_address: address of spt1 + * @get_spt_response_buf: response from sdm for get_spt command */ struct stratix10_rsu_priv { struct stratix10_svc_chan *chan; @@ -90,6 +97,11 @@ struct stratix10_rsu_priv { unsigned int retry_counter; unsigned int max_retry; + + unsigned long spt0_address; + unsigned long spt1_address; + + unsigned int *get_spt_response_buf; }; /** @@ -259,6 +271,36 @@ static void rsu_dcmf_status_callback(struct stratix10_svc_client *client, complete(&priv->completion); } +static void rsu_get_spt_callback(struct stratix10_svc_client *client, + struct stratix10_svc_cb_data *data) +{ + struct stratix10_rsu_priv *priv = client->priv; + unsigned long *mbox_err = (unsigned long *)data->kaddr1; + unsigned long *resp_len = (unsigned long *)data->kaddr2; + + if (data->status != BIT(SVC_STATUS_OK) || (*mbox_err) || + (*resp_len != RSU_GET_SPT_RESP_LEN)) + goto error; + + priv->spt0_address = priv->get_spt_response_buf[0]; + priv->spt0_address <<= 32; + priv->spt0_address |= priv->get_spt_response_buf[1]; + + priv->spt1_address = priv->get_spt_response_buf[2]; + priv->spt1_address <<= 32; + priv->spt1_address |= priv->get_spt_response_buf[3]; + + goto complete; + +error: + dev_err(client->dev, "failed to get SPTs\n"); + +complete: + stratix10_svc_free_memory(priv->chan, priv->get_spt_response_buf); + priv->get_spt_response_buf = NULL; + complete(&priv->completion); +} + /** * rsu_send_msg() - send a message to Intel service layer * @priv: pointer to rsu private data @@ -288,6 +330,14 @@ static int rsu_send_msg(struct stratix10_rsu_priv *priv, if (arg) msg.arg[0] = arg; + if (command == COMMAND_MBOX_SEND_CMD) { + msg.arg[1] = 0; + msg.payload = NULL; + msg.payload_length = 0; + msg.payload_output = priv->get_spt_response_buf; + msg.payload_length_output = RSU_GET_SPT_RESP_LEN; + } + ret = stratix10_svc_send(priv->chan, &msg); if (ret < 0) goto status_done; @@ -572,6 +622,34 @@ static ssize_t notify_store(struct device *dev, return count; } +static ssize_t spt0_address_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct stratix10_rsu_priv *priv = dev_get_drvdata(dev); + + if (!priv) + return -ENODEV; + + if (priv->spt0_address == INVALID_SPT_ADDRESS) + return -EIO; + + return scnprintf(buf, PAGE_SIZE, "0x%08lx\n", priv->spt0_address); +} + +static ssize_t spt1_address_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct stratix10_rsu_priv *priv = dev_get_drvdata(dev); + + if (!priv) + return -ENODEV; + + if (priv->spt1_address == INVALID_SPT_ADDRESS) + return -EIO; + + return scnprintf(buf, PAGE_SIZE, "0x%08lx\n", priv->spt1_address); +} + static DEVICE_ATTR_RO(current_image); static DEVICE_ATTR_RO(fail_image); static DEVICE_ATTR_RO(state); @@ -590,6 +668,8 @@ static DEVICE_ATTR_RO(dcmf2_status); static DEVICE_ATTR_RO(dcmf3_status); static DEVICE_ATTR_WO(reboot_image); static DEVICE_ATTR_WO(notify); +static DEVICE_ATTR_RO(spt0_address); +static DEVICE_ATTR_RO(spt1_address); static struct attribute *rsu_attrs[] = { &dev_attr_current_image.attr, @@ -610,6 +690,8 @@ static struct attribute *rsu_attrs[] = { &dev_attr_dcmf3_status.attr, &dev_attr_reboot_image.attr, &dev_attr_notify.attr, + &dev_attr_spt0_address.attr, + &dev_attr_spt1_address.attr, NULL }; @@ -639,11 +721,13 @@ static int stratix10_rsu_probe(struct platform_device *pdev) priv->dcmf_version.dcmf1 = INVALID_DCMF_VERSION; priv->dcmf_version.dcmf2 = INVALID_DCMF_VERSION; priv->dcmf_version.dcmf3 = INVALID_DCMF_VERSION; - priv->max_retry = INVALID_RETRY_COUNTER; priv->dcmf_status.dcmf0 = INVALID_DCMF_STATUS; priv->dcmf_status.dcmf1 = INVALID_DCMF_STATUS; priv->dcmf_status.dcmf2 = INVALID_DCMF_STATUS; priv->dcmf_status.dcmf3 = INVALID_DCMF_STATUS; + priv->max_retry = INVALID_RETRY_COUNTER; + priv->spt0_address = INVALID_SPT_ADDRESS; + priv->spt1_address = INVALID_SPT_ADDRESS; mutex_init(&priv->lock); priv->chan = stratix10_svc_request_channel_byname(&priv->client, @@ -693,6 +777,20 @@ static int stratix10_rsu_probe(struct platform_device *pdev) stratix10_svc_free_channel(priv->chan); } + priv->get_spt_response_buf = + stratix10_svc_allocate_memory(priv->chan, RSU_GET_SPT_RESP_LEN); + + if (IS_ERR(priv->get_spt_response_buf)) { + dev_err(dev, "failed to allocate get spt buffer\n"); + } else { + ret = rsu_send_msg(priv, COMMAND_MBOX_SEND_CMD, + RSU_GET_SPT_CMD, rsu_get_spt_callback); + if (ret) { + dev_err(dev, "Error, getting SPT table %i\n", ret); + stratix10_svc_free_channel(priv->chan); + } + } + return ret; }