Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp162775pxj; Wed, 23 Jun 2021 18:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqPH7m/1goLY0bdJCR52MTb7xMPsAVSMyCdVELt5kJnv5+YrcYthlWpTIzmY8rcv9QKBbW X-Received: by 2002:a17:907:2625:: with SMTP id aq5mr2856538ejc.373.1624498922072; Wed, 23 Jun 2021 18:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624498922; cv=none; d=google.com; s=arc-20160816; b=cLkHwkreIvlc59PGaYh9NezmUPr8yTAYLFErxSOqR4DaoDbZ+ZvVnoXckpHke4bN9H kPiSq3+O6eUypKFWMn6k9S1hMXVyCb/rHYGMiED2KS7qx65a0pitt66mn0yLAJwyCcFA Ym3BdNFcDq4y6DF3/soFjmodgrM3kvJcmBI7oI3T6tbhYQWZNAsy2Zsj/HmT3K0OVraV SE94xtOz1YzY6Zn0jPt4Bq/Sg0TA+Um+O5jw/+LXpkP2G529A7AbrgArXY/M7QiqfMbe TCWkgLCUcRSW6xX6tArhcU1fHED6onxIrSZpo754LG3SCSIC5ipgwFupB788F1hHg3xu N0Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=yI3e/Gu3C1XFzHKSbqNPbf1CCTNnFkPDqm9J9JbEZ68=; b=ciZZXCzp+/BuWOVtIMlljTDot4KpjwaJpwbtw+QdwEA+/d4AaTV9gXLbCdiv/kOlrm tUsxSKBYzHqc7CL5J7G1rr+f3ZYijqzqu+GCu8Z/ikW1Zx5E+SUcykImb1bGHZDYz5Kk eOGH3ZrXs2VbLwSbi9YRR4tXFs9ugp/H3rYnLW8sXBiJfv3tfvurXHOIf5OEJkUxzRyn 7c6W6rI0CRIve8QFpAGfsodlGSM2cLnHrPKbE+AXQuRBqa/7t6EWFPawrZlFBAouFnDj ZvzGAszleS77EPfy7a6rAqBtz04KFIuOtxu1itThaaigOsHxchgpXfyl3sOFXarV5OFI zcsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ar8si1404284ejc.69.2021.06.23.18.41.39; Wed, 23 Jun 2021 18:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbhFXBjY (ORCPT + 99 others); Wed, 23 Jun 2021 21:39:24 -0400 Received: from mga17.intel.com ([192.55.52.151]:8652 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbhFXBjU (ORCPT ); Wed, 23 Jun 2021 21:39:20 -0400 IronPort-SDR: MxXL87sGau7DiMEcoUm85KSi9QnEPGB+8ce7u9nNogZlxHPoYIyEtkdI6vzIYixfDih6TAPMpo eOvaQBueThGA== X-IronPort-AV: E=McAfee;i="6200,9189,10024"; a="187757001" X-IronPort-AV: E=Sophos;i="5.83,295,1616482800"; d="scan'208";a="187757001" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2021 18:37:02 -0700 IronPort-SDR: cvc+siIfh4TAMuNpmyeuOsZBVASGzAWlG0EFxKoiT8JMH+I6CX7vkQNfnJ7QXIX7c9OXRqAXQq pWzpYIQPhVyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,295,1616482800"; d="scan'208";a="490928489" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by fmsmga002.fm.intel.com with ESMTP; 23 Jun 2021 18:37:02 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: eranian@google.com, namhyung@kernel.org, acme@kernel.org, jolsa@redhat.com, ak@linux.intel.com, Kan Liang Subject: [PATCH 5/7] perf/x86/intel/uncore: Factor out snr_uncore_mmio_map() Date: Wed, 23 Jun 2021 18:22:07 -0700 Message-Id: <1624497729-158864-6-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1624497729-158864-1-git-send-email-kan.liang@linux.intel.com> References: <1624497729-158864-1-git-send-email-kan.liang@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang The IMC free-running counters on Sapphire Rapids server are also accessed by MMIO, which is similar to the previous platforms, SNR and ICX. The only difference is the device ID of the device which contains BAR address. Factor out snr_uncore_mmio_map() which ioremap the MMIO space. It can be reused in the following patch for SPR. Use the snr_uncore_mmio_map() in the icx_uncore_imc_freerunning_init_box(). There is no box_ctl for the free-running counters. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- arch/x86/events/intel/uncore_snbep.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c index a4f436a..2696657 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -4792,13 +4792,15 @@ int snr_uncore_pci_init(void) return 0; } -static struct pci_dev *snr_uncore_get_mc_dev(int id) +#define SNR_MC_DEVICE_ID 0x3451 + +static struct pci_dev *snr_uncore_get_mc_dev(unsigned int device, int id) { struct pci_dev *mc_dev = NULL; int pkg; while (1) { - mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3451, mc_dev); + mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, device, mc_dev); if (!mc_dev) break; pkg = uncore_pcibus_to_dieid(mc_dev->bus); @@ -4808,16 +4810,17 @@ static struct pci_dev *snr_uncore_get_mc_dev(int id) return mc_dev; } -static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box, - unsigned int box_ctl, int mem_offset) +static int snr_uncore_mmio_map(struct intel_uncore_box *box, + unsigned int box_ctl, int mem_offset, + unsigned int device) { - struct pci_dev *pdev = snr_uncore_get_mc_dev(box->dieid); + struct pci_dev *pdev = snr_uncore_get_mc_dev(device, box->dieid); struct intel_uncore_type *type = box->pmu->type; resource_size_t addr; u32 pci_dword; if (!pdev) - return; + return -ENODEV; pci_read_config_dword(pdev, SNR_IMC_MMIO_BASE_OFFSET, &pci_dword); addr = (pci_dword & SNR_IMC_MMIO_BASE_MASK) << 23; @@ -4830,16 +4833,25 @@ static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box, box->io_addr = ioremap(addr, type->mmio_map_size); if (!box->io_addr) { pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name); - return; + return -EINVAL; } - writel(IVBEP_PMON_BOX_CTL_INT, box->io_addr); + return 0; +} + +static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box, + unsigned int box_ctl, int mem_offset, + unsigned int device) +{ + if (!snr_uncore_mmio_map(box, box_ctl, mem_offset, device)) + writel(IVBEP_PMON_BOX_CTL_INT, box->io_addr); } static void snr_uncore_mmio_init_box(struct intel_uncore_box *box) { __snr_uncore_mmio_init_box(box, uncore_mmio_box_ctl(box), - SNR_IMC_MMIO_MEM0_OFFSET); + SNR_IMC_MMIO_MEM0_OFFSET, + SNR_MC_DEVICE_ID); } static void snr_uncore_mmio_disable_box(struct intel_uncore_box *box) @@ -5413,7 +5425,8 @@ static void icx_uncore_imc_init_box(struct intel_uncore_box *box) int mem_offset = (box->pmu->pmu_idx / ICX_NUMBER_IMC_CHN) * ICX_IMC_MEM_STRIDE + SNR_IMC_MMIO_MEM0_OFFSET; - __snr_uncore_mmio_init_box(box, box_ctl, mem_offset); + __snr_uncore_mmio_init_box(box, box_ctl, mem_offset, + SNR_MC_DEVICE_ID); } static struct intel_uncore_ops icx_uncore_mmio_ops = { @@ -5483,7 +5496,8 @@ static void icx_uncore_imc_freerunning_init_box(struct intel_uncore_box *box) int mem_offset = box->pmu->pmu_idx * ICX_IMC_MEM_STRIDE + SNR_IMC_MMIO_MEM0_OFFSET; - __snr_uncore_mmio_init_box(box, uncore_mmio_box_ctl(box), mem_offset); + snr_uncore_mmio_map(box, uncore_mmio_box_ctl(box), + mem_offset, SNR_MC_DEVICE_ID); } static struct intel_uncore_ops icx_uncore_imc_freerunning_ops = { -- 2.7.4