Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2525922rwl; Thu, 13 Apr 2023 07:35:47 -0700 (PDT) X-Google-Smtp-Source: AKy350aaduhXri6fNtOUZMMTQ3TjbkBDB/ajKXe9LG780HCWtLmSvhYZp949qKKSHi1wQAFR2VJg X-Received: by 2002:a17:906:20d6:b0:94e:6102:63f5 with SMTP id c22-20020a17090620d600b0094e610263f5mr3474148ejc.23.1681396546818; Thu, 13 Apr 2023 07:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681396546; cv=none; d=google.com; s=arc-20160816; b=nBfaPqc1h9S4eK4wnYHaClBj/5gpNrGvY9yylw+GkgVLcAgvHfrZ0ireAbtVLku6YJ s/XP+3pECqhau9AbR25P9tGcLKPia+FxHjl3RC0/k2FXFVIZ182uFpI/74VSLxHmaDis 7cs16FQePVvG96awz3eeK6irQnTSKYanoOvN41yMvi2VAzTUHTsibRtv3kpUdrxz+ibq gIlwRFrZQ+RkfxdeTH9WVy9/js7xOMf4dsrEG65QZxLn5J7IA5GP7EUdcJZcWqhIxzkS S/WhAbBsGWTQ0+0CIPuU6FT+MP1swiDEAIWLQlfdu6rbigSjKmDHSq9HkjbeL0v3uhNS HYow== 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; bh=NloLM4q4O9jCkD8up5LqpVc9Uqo9tx2DRqS0bM7DJMQ=; b=Purdt3OjE3uwbpDWioey439qxfJ6aSO7qlpNIS48gW02X8+0xjSDVVZsksS9E3MNBv rF7JTy2y7KpucwStDqh1D7Gn39PqZzN1J81YxDUbcNaBqJ9rXzKf2tvF8ZGxdvJ3EWGN HnXEK+3S5n1LfkVdftOS3ePEN+icd3AIfJjuRMJrZgl/3jBnNTFX7EuzlAiMaX+YWrhV 21P1RcGOLm3CmNcS7GmmLe5DxWt4FMvCkFqFTtOf88hkM1iKLtjLWpPh+4LyLvzpCRxV h3kgJL8bBZwBlFNF+poE9onAcN61YiDh6wdVAjYLTn0NTzJh9X+RGBDkGd0swCrlIX3e 2NIQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a170907914400b0094e3dbde3cdsi1831642ejs.178.2023.04.13.07.35.21; Thu, 13 Apr 2023 07:35:46 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbjDMO1W (ORCPT + 99 others); Thu, 13 Apr 2023 10:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjDMO1U (ORCPT ); Thu, 13 Apr 2023 10:27:20 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D460A9EE0; Thu, 13 Apr 2023 07:27:19 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Py20N0l6Xz6J7JS; Thu, 13 Apr 2023 22:24:52 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 13 Apr 2023 15:27:17 +0100 From: Jonathan Cameron To: Liang Kan , , , , CC: , , , , , , Davidlohr Bueso , Dave Jiang Subject: [PATCH v6 2/5] cxl: Add functions to get an instance of / count regblocks of a given type Date: Thu, 13 Apr 2023 15:26:14 +0100 Message-ID: <20230413142617.15995-3-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230413142617.15995-1-Jonathan.Cameron@huawei.com> References: <20230413142617.15995-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 Until the recently release CXL 3.0 specification, there was only ever one instance of any given register block pointed to by the Register Block Locator DVSEC. Now, the specification allows for multiple CXL PMU instances, each with their own register block. To enable this add cxl_find_regblock_instance() that takes an index parameter and use that to implement cxl_count_regblock() and cxl_find_regblock(). Signed-off-by: Jonathan Cameron --- v6: No change Dropped RBs as significant refactor for v5. v5: Thanks to Dan Williams, - As there is only one case of repeated regblocks so far keep cxl_find_regblock() as finding the first instance but implement it using a new cxl_find_regblock_instance() function, also used to implement the counting function. --- drivers/cxl/core/regs.c | 59 ++++++++++++++++++++++++++++++++++++----- drivers/cxl/cxl.h | 3 +++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c index 1476a0299c9b..4b9672db867d 100644 --- a/drivers/cxl/core/regs.c +++ b/drivers/cxl/core/regs.c @@ -286,20 +286,23 @@ static bool cxl_decode_regblock(struct pci_dev *pdev, u32 reg_lo, u32 reg_hi, } /** - * cxl_find_regblock() - Locate register blocks by type + * cxl_find_regblock_instance() - Locate a register block by type / index * @pdev: The CXL PCI device to enumerate. * @type: Register Block Indicator id * @map: Enumeration output, clobbered on error + * @index: Index into which particular instance of a regblock wanted in the + * order found in register locator DVSEC. * * Return: 0 if register block enumerated, negative error code otherwise * * A CXL DVSEC may point to one or more register blocks, search for them - * by @type. + * by @type and @index. */ -int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type, - struct cxl_register_map *map) +int cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_type type, + struct cxl_register_map *map, int index) { u32 regloc_size, regblocks; + int instance = 0; int regloc, i; map->resource = CXL_RESOURCE_NONE; @@ -323,15 +326,59 @@ int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type, if (!cxl_decode_regblock(pdev, reg_lo, reg_hi, map)) continue; - if (map->reg_type == type) - return 0; + if (map->reg_type == type) { + if (index == instance) + return 0; + instance++; + } } map->resource = CXL_RESOURCE_NONE; return -ENODEV; } +EXPORT_SYMBOL_NS_GPL(cxl_find_regblock_instance, CXL); + +/** + * cxl_find_regblock() - Locate register blocks by type + * @pdev: The CXL PCI device to enumerate. + * @type: Register Block Indicator id + * @map: Enumeration output, clobbered on error + * + * Return: 0 if register block enumerated, negative error code otherwise + * + * A CXL DVSEC may point to one or more register blocks, search for them + * by @type. + */ +int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type, + struct cxl_register_map *map) +{ + return cxl_find_regblock_instance(pdev, type, map, 0); +} EXPORT_SYMBOL_NS_GPL(cxl_find_regblock, CXL); +/** + * cxl_count_regblock() - Count instances of a given regblock type. + * @pdev: The CXL PCI device to enumerate. + * @type: Register Block Indicator id + * + * Some regblocks may be repeated. Count how many instances. + * + * Return: count of matching regblocks. + */ +int cxl_count_regblock(struct pci_dev *pdev, enum cxl_regloc_type type) +{ + struct cxl_register_map map; + int rc, count = 0; + + while (1) { + rc = cxl_find_regblock_instance(pdev, type, &map, count); + if (rc) + return count; + count++; + } +} +EXPORT_SYMBOL_NS_GPL(cxl_count_regblock, CXL); + resource_size_t cxl_rcrb_to_component(struct device *dev, resource_size_t rcrb, enum cxl_rcrb which) diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 044a92d9813e..f6e2a9ea5f41 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -260,6 +260,9 @@ int cxl_map_device_regs(struct device *dev, struct cxl_device_regs *regs, struct cxl_register_map *map); enum cxl_regloc_type; +int cxl_count_regblock(struct pci_dev *pdev, enum cxl_regloc_type type); +int cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_type type, + struct cxl_register_map *map, int index); int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type, struct cxl_register_map *map); -- 2.37.2