Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp312099rwe; Wed, 31 Aug 2022 03:20:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6d4UoOo1tJFl1f1tt4je65VDhBuD5ze7vP88I2vfA7kENk1sIRGyeQlBvYiJCq6CD8RdbU X-Received: by 2002:a17:907:970c:b0:741:748b:6dac with SMTP id jg12-20020a170907970c00b00741748b6dacmr10738663ejc.479.1661941231159; Wed, 31 Aug 2022 03:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661941231; cv=none; d=google.com; s=arc-20160816; b=KTUErFAkPNZ1Dgn2+aNz92++azyJ3GJT+ouOh2bgCEoMbNFwSEDhmzJnaRqcQh2iE5 rvmvca/eZNP0TVDnMtlqcEZgVcToLqAMwqWdCW3J2I//oXwvQ5nNnR4782Qbczj5s9At +1piIW/u/5XfCkJE+SJfAghtxw2qQaakUMboQwgh4qkyzgluJbmov9OCcJEtulM9U/cN r4/e5tJ1JYI9dyd6abqqmiiXtCyNKaqVZ3nLqK6PojnsQdAbzO75bJppNAplVSAJ3Mhn 2AiBAl0U3e2SfEXjADOWDonAf8ZGwdDnchj6ftiRxf/upb1EIPGAHgJvus/MWzBRNm/E m2qQ== 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:subject:cc:to:from:date; bh=bLg0OxSzczJ+1BMIEDTE5Y6LEAR2oImh0ZOyeeZFx6Q=; b=mLYezDTWKcJNIT5yy9viwJw/59WYK09+i4ot1Lohi2Zq6LHT9sEy733kDp5rrPiCyH wqAdON45K1LA+VdgWmSn5jA8pfLUrjkUc6ztVycGBKjCzP+B6elQPYe4Tc7aSnxMEB+Y XXvR80qkvCZUkM9+VEJYLuOqZEkWepamo9Qe7/HPGrvCSsjRgUJQylTUpyWx4LsET6+L UFJeqgylDUCxEagpT74TqNbPKMPvvF0A75tZqgAUAYAhpNvIVuhCWEDBb6yMq1e3BI+G PB5zbPGN0ih9oIvhaGZPPsLBhS28joP7tCIJfxaePaH4tOLybfdKApj2LkFsxSPmiryA GzAg== 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 p11-20020a056402500b00b00447e8ccf579si11677322eda.568.2022.08.31.03.20.05; Wed, 31 Aug 2022 03:20:31 -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 S229837AbiHaKIM (ORCPT + 99 others); Wed, 31 Aug 2022 06:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbiHaKIJ (ORCPT ); Wed, 31 Aug 2022 06:08:09 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55494CCD7E; Wed, 31 Aug 2022 03:08:08 -0700 (PDT) Received: from fraeml737-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MHfsd6qZTz682Y2; Wed, 31 Aug 2022 18:04:21 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by fraeml737-chm.china.huawei.com (10.206.15.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 31 Aug 2022 12:08:06 +0200 Received: from localhost (10.202.226.42) 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.2375.24; Wed, 31 Aug 2022 11:08:05 +0100 Date: Wed, 31 Aug 2022 11:08:04 +0100 From: Jonathan Cameron To: Robert Richter CC: Alison Schofield , Vishal Verma , Ira Weiny , Ben Widawsky , Dan Williams , , , Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown Subject: Re: [PATCH 05/15] cxl/acpi: Add probe function to detect restricted CXL hosts in RCD mode Message-ID: <20220831110804.00003812@huawei.com> In-Reply-To: <20220831081603.3415-6-rrichter@amd.com> References: <20220831081603.3415-1-rrichter@amd.com> <20220831081603.3415-6-rrichter@amd.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.42] X-ClientProxiedBy: lhrpeml100004.china.huawei.com (7.191.162.219) 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,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 On Wed, 31 Aug 2022 10:15:53 +0200 Robert Richter wrote: > Restricted CXL device (RCD) mode (formerly CXL 1.1) uses a different > enumeration scheme other than CXL VH (formerly CXL 2.0). In RCD mode a > host/device (RCH-RCD) pair shows up as a legal PCIe hierarchy with an > ACPI host bridge ("PNP0A08" or "ACPI0016" HID) and RCiEP connected to > it with a description of the CXL device. > > Add function cxl_restricted_host_probe() to probe RCD enumerated > devices. The function implements a loop that detects all CXL capable > ACPI PCI root bridges in the system (RCD mode only). The iterator > function cxl_find_next_rch() is introduced to walk through all of the > CXL hosts. The loop will then enable all CXL devices connected to the > host. For now, only implement an empty loop with an iterator that > returns all pci host bridges in the system. > > The probe function is triggered by adding an own root device for RCHs. > This is different to CXL VH where an ACPI "ACPI0017" root device > exists. Its detection starts the CXL host detection. In RCD mode such > a device does not necessarily exists, so solve this by creating a > plain platform device that is not an ACPI device and is root only for > RCHs. If I read this correctly that platform device is created whether or not there are any cxl devices in the system? Can we create it only if we find some devices that will be placed under it later? Jonathan > > Signed-off-by: Robert Richter > --- > drivers/cxl/acpi.c | 71 +++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 70 insertions(+), 1 deletion(-) > > diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c > index 31e104f0210f..a19e3154dd44 100644 > --- a/drivers/cxl/acpi.c > +++ b/drivers/cxl/acpi.c > @@ -312,6 +312,33 @@ static int add_root_nvdimm_bridge(struct device *match, void *data) > return 1; > } > > +struct pci_host_bridge *cxl_find_next_rch(struct pci_host_bridge *host) > +{ > + struct pci_bus *bus = host ? host->bus : NULL; > + > + while ((bus = pci_find_next_bus(bus)) != NULL) { > + host = bus ? to_pci_host_bridge(bus->bridge) : NULL; > + if (!host) > + continue; > + > + dev_dbg(&host->dev, "PCI bridge found\n"); > + > + return host; > + } > + > + return NULL; > +} > + > +static int __init cxl_restricted_host_probe(struct platform_device *pdev) > +{ > + struct pci_host_bridge *host = NULL; > + > + while ((host = cxl_find_next_rch(host)) != NULL) { > + } > + > + return 0; > +} > + > static struct lock_class_key cxl_root_key; > > static void cxl_acpi_lock_reset_class(void *dev) > @@ -445,6 +472,13 @@ static int cxl_acpi_probe(struct platform_device *pdev) > struct acpi_device *adev = ACPI_COMPANION(host); > struct cxl_cfmws_context ctx; > > + /* > + * For RCH (CXL 1.1 hosts) the probe is triggered by a plain > + * platform dev which does not have an acpi companion. > + */ > + if (!adev) > + return cxl_restricted_host_probe(pdev); > + > device_lock_set_class(&pdev->dev, &cxl_root_key); > rc = devm_add_action_or_reset(&pdev->dev, cxl_acpi_lock_reset_class, > &pdev->dev); > @@ -518,6 +552,7 @@ MODULE_DEVICE_TABLE(acpi, cxl_acpi_ids); > > static const struct platform_device_id cxl_test_ids[] = { > { "cxl_acpi" }, > + { "cxl_root" }, > { }, > }; > MODULE_DEVICE_TABLE(platform, cxl_test_ids); > @@ -531,7 +566,41 @@ static struct platform_driver cxl_acpi_driver = { > .id_table = cxl_test_ids, > }; > > -module_platform_driver(cxl_acpi_driver); > +static void cxl_acpi_device_release(struct device *dev) { } Why the empty release? Perhaps introduce this only when it does something. > + > +static struct platform_device cxl_acpi_device = { > + .name = "cxl_root", > + .id = PLATFORM_DEVID_NONE, > + .dev = { > + .release = cxl_acpi_device_release, > + } > +}; > + > +static int __init cxl_host_init(void) > +{ > + int rc; > + > + /* Kick off restricted host (CXL 1.1) detection */ > + rc = platform_device_register(&cxl_acpi_device); > + if (rc) { > + platform_device_put(&cxl_acpi_device); > + return rc; > + } > + rc = platform_driver_register(&cxl_acpi_driver); > + if (rc) > + platform_device_unregister(&cxl_acpi_device); > + return rc; > +} > + > +static void __exit cxl_host_exit(void) > +{ > + platform_driver_unregister(&cxl_acpi_driver); > + platform_device_unregister(&cxl_acpi_device); > +} > + > +module_init(cxl_host_init); > +module_exit(cxl_host_exit); > + > MODULE_LICENSE("GPL v2"); > MODULE_IMPORT_NS(CXL); > MODULE_IMPORT_NS(ACPI);