Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3361342rwo; Fri, 4 Aug 2023 03:53:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEL6qt9H+Hs5qzNehVh2eTJOhADpavx446jAHxvOU4sJDNc4AOiuh6EPsRZv2nX1v4nPg5S X-Received: by 2002:a05:6871:613:b0:1be:ca9e:a65 with SMTP id w19-20020a056871061300b001beca9e0a65mr1513385oan.58.1691146384225; Fri, 04 Aug 2023 03:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691146384; cv=none; d=google.com; s=arc-20160816; b=Fix0u2RKkD7neWrtY2Tt/xRUMGzijdzO43mjIxfhAaqFg8CFWP5UThAHoTUAI1PYCW K5N8VhD1lVgc7FUHZNtG8KW/RRkr0iyhXIsfxii5VOC7OIQTB/lLgvgWTwON1ROMbP97 iJHLQJgLBuf6fKRPiAOXQzxziNcr6RGJS6sG/reodQpBuppIyOvfTKrCw6Kw8o4+RjYY gk6VvfUm2E8jU53qL8m/32gXVMqqvWfSF6nfoqm1H4ELtQ084KOQ1SQVfA0xrn7pmj5j rh5K9cEOAA8mmeEjeOT1oDStka4Be69A/bVPcwx30V4R54k6m07XPO6XSQMimuPNCTk7 it/A== 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=T7l3lDSYYELaaEKkbn9dJmisv2dnzonPupYb2Fv7NCk=; fh=wc77EpfutEP0n0zOBBdJZHlKlpGafhRmvKP/2XqASX4=; b=H3xBMEEGkPKUc2wSOgSGi+hnFYkvp6q+Hy4Nk25pnTYvIym6n26jGRIPWrCrhfwJBp bZJDWO70Tq6dfJB0G4q4afohrKJJwtRsgZt/Jte5HxiZAyCl7c5X8zKp4zwnJ1y0ALx3 xlbNm/BMHYSOtS+t1WZNlCR/X5uCiyfm1rhZ8J5HUKpUT9T3f/Cy7ORHdGwXB9B8HHcJ N77XQ+6RPsnW6VwUMsngfYyL9v+25qcmbDtcOEhCDHp3NFnEP3zg910v4yEy0oBy2zyF KrKcyp7b88i30BVV4olTenmbuuxbdvCmB3BhpSvYRApJj/eH/iuY3CWCvP8wMVTpOnaW izxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XjD1puV7; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a17090ad48800b0025c1ff9cd67si1686215pju.184.2023.08.04.03.52.51; Fri, 04 Aug 2023 03:53:04 -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=@intel.com header.s=Intel header.b=XjD1puV7; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjHDIrV (ORCPT + 99 others); Fri, 4 Aug 2023 04:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjHDIrJ (ORCPT ); Fri, 4 Aug 2023 04:47:09 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BA049EB; Fri, 4 Aug 2023 01:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691138827; x=1722674827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kGt94uchbGNgCTOyUJqO1F4CC7iK2MkSjUEctU7dhGs=; b=XjD1puV7+eb4l+Rap9JU1JQPHaelVv6h32nO1QVw8L63zLsyBGfsOa19 hHINJLn10sEawUK3VHzanYa7+hEpFlsXf+hQOkJdgH4K7+S0hGyZRH/L5 ZUJaSPG4asnfdvnCaFi2hSHAIVaPCga7H+2Xjj7s3PQHgHqTSoQnRmPSD oNc7HQx1Q1TS9Shu/So3Fd1gCBOM2JaH1gmbeV/u1ECHgNOu4xaVXf4LC wfrdmLf1fPPGtkTZDXaTnI+roDri+aZ8Git+kUpl5YGmvkQcO7FvbAq22 8vHlpSYA4e6qVQLEOBB1XNfgW2F38y0i7kvsHZrcr+LEvQ1gaHWhkd3t+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="456478343" X-IronPort-AV: E=Sophos;i="6.01,254,1684825200"; d="scan'208";a="456478343" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2023 01:47:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="765017898" X-IronPort-AV: E=Sophos;i="6.01,254,1684825200"; d="scan'208";a="765017898" Received: from yongliang-ubuntu20-ilbpg12.png.intel.com ([10.88.229.33]) by orsmga001.jf.intel.com with ESMTP; 04 Aug 2023 01:46:55 -0700 From: Choong Yong Liang To: Rajneesh Bhardwaj , David E Box , Hans de Goede , Mark Gross , Jose Abreu , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?UTF-8?q?Marek=20Beh=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 , Revanth Kumar Uppala , 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 Subject: [PATCH net-next v2 1/5] platform/x86: intel_pmc_core: Add IPC mailbox accessor function and add SoC register access Date: Fri, 4 Aug 2023 16:45:23 +0800 Message-Id: <20230804084527.2082302-2-yong.liang.choong@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230804084527.2082302-1-yong.liang.choong@linux.intel.com> References: <20230804084527.2082302-1-yong.liang.choong@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 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 --- 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 */ -- 2.25.1