Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2862985rwb; Mon, 7 Aug 2023 04:58:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgF5TVKzfMId3IhcNSwYzTH5zsJtJJDztMIvbg2plh+8fQc5MrQrrrBoMaWBLvAuiTnHSP X-Received: by 2002:a05:6a00:3984:b0:682:3126:961a with SMTP id fi4-20020a056a00398400b006823126961amr9148674pfb.5.1691409517263; Mon, 07 Aug 2023 04:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691409517; cv=none; d=google.com; s=arc-20160816; b=U0D3T5dXdXGyMxpE5Dyynzi96+wXqJE71ZCwYQlwE+UYHL0Rpr5blIKEe+bTugkU8j QU14D7KHXQiNvfqjNx/uRGsBFqn0jXOakwMvgY1Bd2T6PyDleJlfnYxKfZdl+dfI9a7E csOnUc8QaMKv2KKTs3MS6hxnL7VqJcLa3hXnHyyQ1a8PpaBnAKZODyIJI4BxzJ3CYIzX GI8qJOz3ofjSLNbHDZlrpnXpwBk/1L4zUH6jIv52+bHODvleHdE+LqJv7g5cLda35m/3 uhnlNDvjUypopzGeaGiqF+PJSaAqeEaw4fJBql+sqKSJsxwll1VVtswXwa5PM0mVwaaJ RKWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4tVoX28GTGtCUXdSQaBJtaWNWRKg0UVBLfIJI4oLwi0=; fh=5Esu3Aw3eQe/onMQG16jDDk0qOPqptm1CGTR8vTUji4=; b=OLUWszff4BwbOPDjeB3bT4WpwF5ovNKFWnjRjOBNTonzdY2eLRbHXUZt6bYGxN3L1G jfg2QAFNxd95kg2sr0305a8mnVDua4cXZqGcPsWIjqkvSxVLVgj3NivRUus39UxX6sPE ur3i6QGtSp0AQlG9Edj/w7WqpImXM7K1uw76v+nnyH9ndB4Kq9PpTrJDSjILJRUWrJwo l4yoe5aI8fhhwwrBl5h11i4lHpuXlUe/Shh5N3y7hw3JGF1xJhl0n8G+g8Ik4nmN7Xo8 nw00A2HUKzE0lHZ53QNdxv0Cv7YvOY8uVD1NL+mERKYrJ/toK9KEw/4ZyixLDMCWZLCY CrQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ov+++bUk; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a63610a000000b005638b026f6bsi5392777pgb.522.2023.08.07.04.58.26; Mon, 07 Aug 2023 04:58:37 -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=@redhat.com header.s=mimecast20190719 header.b=Ov+++bUk; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbjHGLDo (ORCPT + 99 others); Mon, 7 Aug 2023 07:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjHGLDa (ORCPT ); Mon, 7 Aug 2023 07:03:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E524E170A for ; Mon, 7 Aug 2023 04:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691406136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4tVoX28GTGtCUXdSQaBJtaWNWRKg0UVBLfIJI4oLwi0=; b=Ov+++bUkj5yfbWNk8gHzYpx3K5cU6xlyE2nBtWFqjGYrovui20x8EKnNlKynwiN+Zg7kMM xTOeZwAQXz+ZWPejU3qlzP5IetL4D1b51+ZFmQX5VpCqyXacBRHTzRm/RlT14MQkDhr2T7 IEnSu4A3HruUI8C2Es9IE2TzUNft2Ok= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-yWqcvidoO3Cav3T6VqYd1Q-1; Mon, 07 Aug 2023 07:02:14 -0400 X-MC-Unique: yWqcvidoO3Cav3T6VqYd1Q-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-521a38098faso2917226a12.2 for ; Mon, 07 Aug 2023 04:02:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691406133; x=1692010933; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4tVoX28GTGtCUXdSQaBJtaWNWRKg0UVBLfIJI4oLwi0=; b=CvX5upt81HOZdXJaY9StyZmtR8WWn6JZZrhZ1u+5prC39nUgQI63sVn5dFQOsrNhPt z3c4oykOWfipPkGEdDkEF93VToJhd5QxxC5PDOkUK2hMQe4MvG/L7QR92vYxglT5QAoK zOiQ7NBZ1x+qCFWaGimAO41hM4CUyOpYmtm/K/E1bUn9IDar9I7YLPz48arRmy//uiMq Gmq1NPqUk/3faFCA9QIVNpU5Yt2FJr5uti0UccDFjna0BGDTyf2kNbcwux8s7ComCknb T5i8m5K5v4kvEUyLPUNDx7YkawtyYwHrgmrWOV6rMYmuBGdJoIyYEZNtSowqGIxPp5vd x8eA== X-Gm-Message-State: AOJu0YwbMO6oh+JEHG+49F1TKPp4ZQvC94GiNKUdERG0jtvCK1IOe10w n34x1no16uNtuCQm3cqbv00by8A0C2/q7F8p5K6W96EPvnNmYWag/4/8MVuStkhXI5CARusioyH ngJbINyvLzj6hvZIjGgdRP2t/ X-Received: by 2002:aa7:da91:0:b0:523:f29:a912 with SMTP id q17-20020aa7da91000000b005230f29a912mr5825498eds.21.1691406133631; Mon, 07 Aug 2023 04:02:13 -0700 (PDT) X-Received: by 2002:aa7:da91:0:b0:523:f29:a912 with SMTP id q17-20020aa7da91000000b005230f29a912mr5825448eds.21.1691406133282; Mon, 07 Aug 2023 04:02:13 -0700 (PDT) Received: from [10.40.98.142] ([78.108.130.194]) by smtp.gmail.com with ESMTPSA id t10-20020aa7d4ca000000b005226f281bc5sm5036828edr.25.2023.08.07.04.02.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Aug 2023 04:02:12 -0700 (PDT) Message-ID: <145d7375-0e58-b7cf-6240-5d8bc16b0344@redhat.com> Date: Mon, 7 Aug 2023 13:02:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH net-next v2 1/5] platform/x86: intel_pmc_core: Add IPC mailbox accessor function and add SoC register access Content-Language: en-US To: Choong Yong Liang , Rajneesh Bhardwaj , David E Box , Mark Gross , Jose Abreu , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?UTF-8?Q?Marek_Beh=c3=ban?= , Jean Delvare , Guenter Roeck , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Richard Cochran , Philipp Zabel , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Wong Vee Khee , Jon Hunter , Jesse Brandeburg , Shenwei Wang , Andrey Konovalov , Jochen Henneberg Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, bpf@vger.kernel.org, Voon Wei Feng , Tan Tee Min , Michael Sit Wei Hong , Lai Peter Jun Ann References: <20230804084527.2082302-1-yong.liang.choong@linux.intel.com> <20230804084527.2082302-2-yong.liang.choong@linux.intel.com> From: Hans de Goede In-Reply-To: <20230804084527.2082302-2-yong.liang.choong@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 Hi David, On 8/4/23 10:45, Choong Yong Liang wrote: > From: "David E. Box" > > - Exports intel_pmc_core_ipc() for host access to the PMC IPC mailbox > - Add support to use IPC command allows host to access SoC registers > through PMC firmware that are otherwise inaccessible to the host due to > security policies. > > Signed-off-by: David E. Box > Signed-off-by: Chao Qin > Signed-off-by: Choong Yong Liang The new exported intel_pmc_core_ipc() function does not seem to depend on any existing PMC code. IMHO it would be better to put this in a new .c file under arch/x86/platform/intel/ this is where similar helpers like the iosf_mbi functions also live. This also avoids Kconfig complications. Currently the drivers/platform/x86/intel/pmc/core.c code is only build if CONFIG_X86_PLATFORM_DEVICES and CONFIG_INTEL_PMC_CORE are both set. So if a driver wants to make sure this is enabled by selecting them then it needs to select both. Talking about Kconfig: #if IS_ENABLED(CONFIG_INTEL_PMC_CORE) int intel_pmc_core_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf); #else static inline int intel_pmc_core_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf) { return -ENODEV; } #endif /* CONFIG_INTEL_PMC_CORE */ Notice that CONFIG_INTEL_PMC_CORE is a tristate, so pmc might be build as a module where as a consumer of intel_pmc_core_ipc() might end up builtin in which case this will not work without extra Kconfig protection. And if you are going to add extra Kconfig you might just as well select or depend on INTEL_PMC_CORE and drop the #if . Regards, Hans > --- > MAINTAINERS | 1 + > drivers/platform/x86/intel/pmc/core.c | 60 +++++++++++++++++++ > .../linux/platform_data/x86/intel_pmc_core.h | 41 +++++++++++++ > 3 files changed, 102 insertions(+) > create mode 100644 include/linux/platform_data/x86/intel_pmc_core.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 069e176d607a..8a034dee9da9 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -10648,6 +10648,7 @@ L: platform-driver-x86@vger.kernel.org > S: Maintained > F: Documentation/ABI/testing/sysfs-platform-intel-pmc > F: drivers/platform/x86/intel/pmc/ > +F: linux/platform_data/x86/intel_pmc_core.h > > INTEL PMIC GPIO DRIVERS > M: Andy Shevchenko > diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c > index 5a36b3f77bc5..6fb1b0f453d8 100644 > --- a/drivers/platform/x86/intel/pmc/core.c > +++ b/drivers/platform/x86/intel/pmc/core.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -28,6 +29,8 @@ > > #include "core.h" > > +#define PMC_IPCS_PARAM_COUNT 7 > + > /* Maximum number of modes supported by platfoms that has low power mode capability */ > const char *pmc_lpm_modes[] = { > "S0i2.0", > @@ -53,6 +56,63 @@ const struct pmc_bit_map msr_map[] = { > {} > }; > > +int intel_pmc_core_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf) > +{ > + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > + union acpi_object params[PMC_IPCS_PARAM_COUNT] = { > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + {.type = ACPI_TYPE_INTEGER,}, > + }; > + struct acpi_object_list arg_list = { PMC_IPCS_PARAM_COUNT, params }; > + union acpi_object *obj; > + int status; > + > + if (!ipc_cmd || !rbuf) > + return -EINVAL; > + > + /* > + * 0: IPC Command > + * 1: IPC Sub Command > + * 2: Size > + * 3-6: Write Buffer for offset > + */ > + params[0].integer.value = ipc_cmd->cmd; > + params[1].integer.value = ipc_cmd->sub_cmd; > + params[2].integer.value = ipc_cmd->size; > + params[3].integer.value = ipc_cmd->wbuf[0]; > + params[4].integer.value = ipc_cmd->wbuf[1]; > + params[5].integer.value = ipc_cmd->wbuf[2]; > + params[6].integer.value = ipc_cmd->wbuf[3]; > + > + status = acpi_evaluate_object(NULL, "\\IPCS", &arg_list, &buffer); > + if (ACPI_FAILURE(status)) > + return -ENODEV; > + > + obj = buffer.pointer; > + /* Check if the number of elements in package is 5 */ > + if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 5) { > + const union acpi_object *objs = obj->package.elements; > + > + if ((u8)objs[0].integer.value != 0) > + return -EINVAL; > + > + rbuf[0] = objs[1].integer.value; > + rbuf[1] = objs[2].integer.value; > + rbuf[2] = objs[3].integer.value; > + rbuf[3] = objs[4].integer.value; > + } else { > + return -EINVAL; > + } > + > + return 0; > +} > +EXPORT_SYMBOL(intel_pmc_core_ipc); > + > static inline u32 pmc_core_reg_read(struct pmc *pmc, int reg_offset) > { > return readl(pmc->regbase + reg_offset); > diff --git a/include/linux/platform_data/x86/intel_pmc_core.h b/include/linux/platform_data/x86/intel_pmc_core.h > new file mode 100644 > index 000000000000..9bb3394fedcf > --- /dev/null > +++ b/include/linux/platform_data/x86/intel_pmc_core.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Intel Core SoC Power Management Controller Header File > + * > + * Copyright (c) 2023, Intel Corporation. > + * All Rights Reserved. > + * > + * Authors: Choong Yong Liang > + * David E. Box > + */ > +#ifndef INTEL_PMC_CORE_H > +#define INTEL_PMC_CORE_H > + > +#define IPC_SOC_REGISTER_ACCESS 0xAA > +#define IPC_SOC_SUB_CMD_READ 0x00 > +#define IPC_SOC_SUB_CMD_WRITE 0x01 > + > +struct pmc_ipc_cmd { > + u32 cmd; > + u32 sub_cmd; > + u32 size; > + u32 wbuf[4]; > +}; > + > +#if IS_ENABLED(CONFIG_INTEL_PMC_CORE) > +/** > + * intel_pmc_core_ipc() - PMC IPC Mailbox accessor > + * @ipc_cmd: struct pmc_ipc_cmd prepared with input to send > + * @rbuf: Allocated u32[4] array for returned IPC data > + * > + * Return: 0 on success. Non-zero on mailbox error > + */ > +int intel_pmc_core_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf); > +#else > +static inline int intel_pmc_core_ipc(struct pmc_ipc_cmd *ipc_cmd, u32 *rbuf) > +{ > + return -ENODEV; > +} > +#endif /* CONFIG_INTEL_PMC_CORE */ > + > +#endif /* INTEL_PMC_CORE_H */