From patchwork Fri Jul 28 17:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 127804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp596465vqg; Fri, 28 Jul 2023 10:46:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+bhmdq7Fxkmn+rlpNuD+OEYEpmyUMbjuNb7Antw/4UrttaaSZgAJr+9KGCYzaEBXDid7N X-Received: by 2002:a17:907:7854:b0:957:2e48:5657 with SMTP id lb20-20020a170907785400b009572e485657mr46266ejc.68.1690566399529; Fri, 28 Jul 2023 10:46:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690566399; cv=pass; d=google.com; s=arc-20160816; b=0QfimhPh69FDQ9Qfvab+S9QNjiMG5wcakwr4q3Mcz7QIh5nk+bh8AnTOwfijrXKPJx Ogl0LwSKHmVg91UHuMWNiNetJh8fUVBjH2ezMwBCMHC0W0mggGfGJhQtPwyE1Eyj4B+M CdGyWV/SaBBWOS22KlRN+REkIgIsaysibARbcHW/HV0xrNlpQWndci8cc8UAAs0WOidz //g5q3urj7+PgBGU4Dfz2Ia4MNBJ0E8p8yDlZ/wfBi7XOBTxmibGAz1ZRG36bpkoT3tN hJiL0KmnU51EAc+hecca3WNnKS1vasUn2CPQgCylxCnv2efYbJ+EKVYbgaAkI02aveQa Sujg== ARC-Message-Signature: i=2; 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=Mb8fk3c6owXtbs0RJr9UCcTG6YiCOgLA8W5ZtA7S1NI=; fh=4woVYSlX/aH5Dx7feWWKhyl2lja0215bDfHlt4737xg=; b=HA8V9Hup3eiMv+zpMyok4dQ2BEN0dsoOswKeKbhP557XXaO2rtnhmCek393UY0UWON lWsvWIEkpS2MOurCtM5g00E15tjN6EPLREjZeYcFHJ4YPcR0Hp4WTYt9ub408n3pq8pl Y4YxItvL0Aps2Z2rI6BPhEp9bm8K2IqXjK2LiPG180R+wFZS4L1dqo5bAHMjn2Gsx9cY h8UxZVl4anXJ7tfMkjY8J5yLsrZhhNHkxgZ2nukVtcTBwQHSpyHM5YNe/MYAl0L3Qetm Ecswl5HeSUoq5o6yn/fCgbSy3pAA8070mLvZpt4UTibe8eK/RZxSguW691DNPLZ3aFhv rWCg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=gKWJSoQa; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay21-20020a170906d29500b009980c2658e0si3100905ejb.763.2023.07.28.10.46.15; Fri, 28 Jul 2023 10:46:39 -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=@amd.com header.s=selector1 header.b=gKWJSoQa; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235935AbjG1RHR (ORCPT + 99 others); Fri, 28 Jul 2023 13:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234758AbjG1RHK (ORCPT ); Fri, 28 Jul 2023 13:07:10 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2087.outbound.protection.outlook.com [40.107.94.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 267BBB5; Fri, 28 Jul 2023 10:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kfn9C2wYX5vprDHLalt/JcVa2fqn64VU0tKXlJkwyW1kxxXAI80gy6eY0SSZYGrJ1FE4q0M53YbVh7fXuJfNgLB2NqHvIztcgm8G0TQLFAon+wvfCEEWUX0ghwLbSqI2+SA9vWaCNG5qRJtdl+beMhkQnaDB+jydXcuEG/un3+LW03PdE7FmNHqIroi9GlhbHMEDDDPlkmuIBX376206Ho7zEZKE9TMnEWDJHKWni5q94oRY4wyq4CiVaZlZHPTi8R25jiK+1iTgk/vDaCTtaXqv9+7fPIv8mshDmP9AG/jmKRsMTs+a2WN2QVSA67gaVuS3PyFP+KjCL52Wm9eAxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mb8fk3c6owXtbs0RJr9UCcTG6YiCOgLA8W5ZtA7S1NI=; b=We/XeERDNM8dWEdNo1pF8TO74rnPAZ87J0aYelAGWC+NwXjAHTDJPVi0opWX3a8+IXsWlYkrEOUvnWAm7Oe1PcNP31i/crhW/qnAGNGoJHDossXTFK8j9VmbK3h/pwYi+cd4RDKRwVaEQcDAcvSGIGdE7r3pk6pWU9Dl0UHDjiXGxT9dz/EazZFgMRUKtJZY/jn8G0D+8rDj3/bvl7b4grbMI7QnNOyhOpvYmJkM8QdgZUjIk9q27LBhaZXx9EOS9bNDef1VWYpUL/Z0Fif2gDnKQDItvC+BOzp0WDQffufWN3/+fgYcPODWwh69F1vboi31+w7y6XP0y86Gwi6gMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mb8fk3c6owXtbs0RJr9UCcTG6YiCOgLA8W5ZtA7S1NI=; b=gKWJSoQaSchbyyeho+FDfRSzqrF4yteEDKDz9xlfaIaPWCz+aMcLcWfLcJcmDTlqE+9u3wgrzhADpGj+zmOhB94kg0Igmtn8yYKEC+7hRzxExaxaMFiomAw/U8UBQdJyiYiOTQsoxIBQg4MWNMV//MUud5ORhXeL389E2CICGhI= Received: from BN9PR03CA0437.namprd03.prod.outlook.com (2603:10b6:408:113::22) by PH8PR12MB6842.namprd12.prod.outlook.com (2603:10b6:510:1c9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 17:07:04 +0000 Received: from BN8NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:408:113:cafe::b5) by BN9PR03CA0437.outlook.office365.com (2603:10b6:408:113::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT112.mail.protection.outlook.com (10.13.176.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.35 via Frontend Transport; Fri, 28 Jul 2023 17:07:04 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:02 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:01 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 28 Jul 2023 12:07:01 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH V12 1/5] of: dynamic: Add interfaces for creating device node dynamically Date: Fri, 28 Jul 2023 10:06:54 -0700 Message-ID: <1690564018-11142-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> References: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT112:EE_|PH8PR12MB6842:EE_ X-MS-Office365-Filtering-Correlation-Id: 449d302c-5e18-4264-6162-08db8f8d1131 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xtYO3PNkEcrZqNy2d68cqFrC7yO2OUF+r+d1+AzR1MUWxQWQfzr6SZwCyJmCw92HdSh+IHTAwYkBOdY/ldMnI6+ImFqYp0tKHtFGZIkT+WdSlmiIYGO3eQKPaYDhyFjy7ws5TjeWJx/LDmoY0Sv+9w0LY9+0u7JVCy3puGtxwuMc5HNLmJOa4x9kYIfI4fJGmmY/PnNoIWkf4ZzjCcaKpOhMYu3+x9hwwcqi9oJ6t9aE9JNxTQ+QrEnxAgirRsW44YUdLlpShQ79q8HW5o0KxbfPhFrwVCU505vgBwkCWEywrdovg4vtb6DJj+LftVL+sEucT6J9/tcpGXnFo70lJB25AgAG3Z8ZdOVfgwZ5pY/YAohD5zsTau3XM9vl88/dXIMmXBdl1CX6tIVO/mjdyNa+nwuHs3wySg6tenOlGdXt65crDM5hSpeo4y7ySZd6SvaMfQP04cWUrmWBe/cFLAhw5gp725xFlxzvUYAXjPmAH5aoAw0Fbn0fRrLhNsp3zXhdh/q285iPXn1wdUstgUI/R1S4jWvYcCa8hD8bpAC/MWY9KtnbE44haItyWdMVgtjQXUB0W8VLs5aQpchwLzdv96c4ehmbVdVQROpVZIoOChbGKde9JsT7RpUmGrbgGQGeo1pECHn3tQCxH4gv+kpwhRvq3FYRoEKbCpPKF+/osHwUd/EdvxtLGjuPkuzjrT00nguBkjfh9652eEzE5JTNoiPm9lX9pNwH8p+XAvuBZTf+wNsIlmR7lRQE238UVjnm4KqjyAH5PvE9ltOTSw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(346002)(136003)(376002)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(2906002)(66574015)(426003)(83380400001)(6666004)(2616005)(36756003)(336012)(186003)(44832011)(5660300002)(86362001)(47076005)(36860700001)(40460700003)(8676002)(41300700001)(316002)(8936002)(26005)(356005)(70586007)(4326008)(70206006)(478600001)(40480700001)(110136005)(54906003)(81166007)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 17:07:04.4354 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 449d302c-5e18-4264-6162-08db8f8d1131 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6842 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772687353228623087 X-GMAIL-MSGID: 1772687353228623087 of_changeset_create_node() creates device node dynamically and attaches the newly created node to a changeset. Expand of_changeset APIs to handle specific types of properties. of_changeset_add_prop_string() of_changeset_add_prop_string_array() of_changeset_add_prop_u32_array() Signed-off-by: Clément Léger Signed-off-by: Lizhi Hou --- drivers/of/dynamic.c | 164 ++++++++++++++++++++++++++++++++++++++++++ drivers/of/unittest.c | 19 ++++- include/linux/of.h | 23 ++++++ 3 files changed, 205 insertions(+), 1 deletion(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index e311d406b170..9259cebda4d6 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -487,6 +487,38 @@ struct device_node *__of_node_dup(const struct device_node *np, return NULL; } +/** + * of_changeset_create_node - Dynamically create a device node and attach to + * a given changeset. + * + * @parent: Pointer to parent device node + * @full_name: Node full name + * @cset: Pointer to changeset + * + * Return: Pointer to the created device node or NULL in case of an error. + */ +struct device_node *of_changeset_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset *cset) +{ + struct device_node *np; + int ret; + + np = __of_node_dup(NULL, full_name); + if (!np) + return NULL; + np->parent = parent; + + ret = of_changeset_attach_node(cset, np); + if (ret) { + of_node_put(np); + return NULL; + } + + return np; +} +EXPORT_SYMBOL(of_changeset_create_node); + static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) { if (ce->action == OF_RECONFIG_ATTACH_NODE && @@ -960,3 +992,135 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action, return 0; } EXPORT_SYMBOL_GPL(of_changeset_action); + +static int of_changeset_add_prop_helper(struct of_changeset *ocs, + struct device_node *np, + const struct property *pp) +{ + struct property *new_pp; + int ret; + + new_pp = __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + return -ENOMEM; + + ret = of_changeset_add_property(ocs, np, new_pp); + if (ret) { + kfree(new_pp->name); + kfree(new_pp->value); + kfree(new_pp); + } + + return ret; +} + +/** + * of_changeset_add_prop_string - Add a string property to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @str: pointer to null terminated string + * + * Create a string property and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str) +{ + struct property prop; + + prop.name = (char *)prop_name; + prop.length = strlen(str) + 1; + prop.value = (void *)str; + + return of_changeset_add_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_string); + +/** + * of_changeset_add_prop_string_array - Add a string list property to + * a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @str_array: pointer to an array of null terminated strings + * @sz: number of string array elements + * + * Create a string list property and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_string_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const char **str_array, size_t sz) +{ + struct property prop; + int i, ret; + char *vp; + + prop.name = (char *)prop_name; + + prop.length = 0; + for (i = 0; i < sz; i++) + prop.length += strlen(str_array[i]) + 1; + + prop.value = kmalloc(prop.length, GFP_KERNEL); + if (!prop.value) + return -ENOMEM; + + vp = prop.value; + for (i = 0; i < sz; i++) { + vp += snprintf(vp, (char *)prop.value + prop.length - vp, "%s", + str_array[i]) + 1; + } + ret = of_changeset_add_prop_helper(ocs, np, &prop); + kfree(prop.value); + + return ret; +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_string_array); + +/** + * of_changeset_add_prop_u32_array - Add a property of 32 bit integers + * property to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @array: pointer to an array of 32 bit integers + * @sz: number of array elements + * + * Create a property of 32 bit integers and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_u32_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const u32 *array, size_t sz) +{ + struct property prop; + __be32 *val; + int i, ret; + + val = kcalloc(sz, sizeof(__be32), GFP_KERNEL); + if (!val) + return -ENOMEM; + + for (i = 0; i < sz; i++) + val[i] = cpu_to_be32(array[i]); + prop.name = (char *)prop_name; + prop.length = sizeof(u32) * sz; + prop.value = (void *)val; + + ret = of_changeset_add_prop_helper(ocs, np, &prop); + kfree(val); + + return ret; +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_u32_array); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index a406a12eb208..d2b286d32db0 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -802,7 +802,9 @@ static void __init of_unittest_changeset(void) struct property *ppname_n21, pname_n21 = { .name = "name", .length = 3, .value = "n21" }; struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; struct property *ppremove; - struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np; + struct device_node *n1, *n2, *n21, *n22, *nchangeset, *nremove, *parent, *np; + static const char * const str_array[] = { "str1", "str2", "str3" }; + const u32 u32_array[] = { 1, 2, 3 }; struct of_changeset chgset; n1 = __of_node_dup(NULL, "n1"); @@ -857,6 +859,17 @@ static void __init of_unittest_changeset(void) unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n"); unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); + n22 = of_changeset_create_node(n2, "n22", &chgset); + unittest(n22, "fail create n22\n"); + unittest(!of_changeset_add_prop_string(&chgset, n22, "prop-str", "abcd"), + "fail add prop prop-str"); + unittest(!of_changeset_add_prop_string_array(&chgset, n22, "prop-str-array", + (const char **)str_array, + ARRAY_SIZE(str_array)), + "fail add prop prop-str-array"); + unittest(!of_changeset_add_prop_u32_array(&chgset, n22, "prop-u32-array", + u32_array, ARRAY_SIZE(u32_array)), + "fail add prop prop-u32-array"); unittest(!of_changeset_apply(&chgset), "apply failed\n"); @@ -866,6 +879,9 @@ static void __init of_unittest_changeset(void) unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), "'%pOF' not added\n", n21); of_node_put(np); + unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n22")), + "'%pOF' not added\n", n22); + of_node_put(np); unittest(!of_changeset_revert(&chgset), "revert failed\n"); @@ -874,6 +890,7 @@ static void __init of_unittest_changeset(void) of_node_put(n1); of_node_put(n2); of_node_put(n21); + of_node_put(n22); #endif } diff --git a/include/linux/of.h b/include/linux/of.h index 6ecde0515677..82d0a476ec75 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1580,6 +1580,29 @@ static inline int of_changeset_update_property(struct of_changeset *ocs, { return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); } + +struct device_node *of_changeset_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset *cset); +int of_changeset_add_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str); +int of_changeset_add_prop_string_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const char **str_array, size_t sz); +int of_changeset_add_prop_u32_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const u32 *array, size_t sz); +static inline int of_changeset_add_prop_u32(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const u32 val) +{ + return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); +} + #else /* CONFIG_OF_DYNAMIC */ static inline int of_reconfig_notifier_register(struct notifier_block *nb) { From patchwork Fri Jul 28 17:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 127779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp588359vqg; Fri, 28 Jul 2023 10:30:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlF4bOrtl/7+Mbj/7gpOI8Q/i08zeyI4r0ucMIor0NItMan0GsuG9k0bsobJbWgEVzXmGxPS X-Received: by 2002:a05:6a00:b4e:b0:67f:48a2:5d9f with SMTP id p14-20020a056a000b4e00b0067f48a25d9fmr3273330pfo.11.1690565443805; Fri, 28 Jul 2023 10:30:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690565443; cv=pass; d=google.com; s=arc-20160816; b=aNjFsKbpsIBcBJb5aqgKGxXBbdqmr+Mz8o02L02VBYmUvmoJUQ/HPOo4CCHzGcEnrE H53jPucPXACQJiXa/HXrBXKmluo7NHXszkg6Ezg55vZUROhoqG/nq/iduuleG7wobD68 2HjXUeiRony/5l+sSRnMwK92xGveNph4+gvSuURlo+rX/gle6grtHsDJ+eOvqEz4kTm5 2oSMAhRMC9wJRPzDahbNGvjrCzmm6aPlsO+tqTz49p1iZ8p9FR18XSpPzyZmJrNofJkA RoGL9fcWZ/1/QRrHDLbHdI2QnuB1GqduEDjJ+iJXhLHkaU77mBLZeSSU6M0G3B9KxSSC jOzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=79dkGWcSIrhJEKzd6bcfhZO6P7zkHLTsROnq2ABASVY=; fh=7qEUnvroiVGqNbV2BsznAhWWl5a9gsasDQnJyIlYZRk=; b=aKkRFi08PnGOF5SYEKAKVoKZjqNE2tiWdtdDSeuj57QHBEbXyaNZdrP/MX0Mz7dXWR oBhqkJtTHblTfsaeyiqJy2TD3gqy1bVpFoNXA/Zx7a/xclPgE5TOYRuKHJlNdX++HKjI 8Jz2M4HUByzFwmENppss4SLa9Szro4NtduOsEhOMktiEMeKwUOBxX4B9IpucbJwURXPG ok/Mo8RD4B5mCSXDjJ9KDlLHFducWaQT0gcdWWVjLPvrEzdIWwGxFGtLFSDJdL950YAg FOtRWNiqrYiKl5rJw04eaxIFAWC9ll1M4ShGn8vUKvwU0d0IfZTFSavwu+GHWczP9nBb meFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=AaA4dJ4g; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n127-20020a632785000000b00563e6fb302esi3460171pgn.735.2023.07.28.10.30.30; Fri, 28 Jul 2023 10:30:43 -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=@amd.com header.s=selector1 header.b=AaA4dJ4g; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236233AbjG1RHn (ORCPT + 99 others); Fri, 28 Jul 2023 13:07:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235717AbjG1RHP (ORCPT ); Fri, 28 Jul 2023 13:07:15 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE27135AD; Fri, 28 Jul 2023 10:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0rH/kQv4IFakW+Q1LtCP/6kxqYF0EUD3X5lR7bx0e+KCJuQMFYFnkyGRjmucxpGGwn0noP1r1Bhs0pS0uoYVsIusjQIu/CGrK3udOy0WH346qnt0UoMVRBaOZ7K4OZz8OuBqDvIEyUThFJnZWjO54gn4n+rkh5HY5KeCFWVnLn8j0PJKdisL4YBe5P6E83onf/m+778hWCohr7fpaWmNZ6itqnmO4waGf2/9pWwWmKGAVoP6vh8/I7gTXTtEYDGOI9Vbx//H+BJ3qHhEcLLki+ri069A0w4rojX5X7257zGxDrWsvDJxTuD5iVd+DXk37Zc8Sn1wF3p1hxM3HbmOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=79dkGWcSIrhJEKzd6bcfhZO6P7zkHLTsROnq2ABASVY=; b=nzRBVOi8Qt/AS6JQOoPUXuYxfsAu8LxuILaK0HD8pc//j0elvkQRSaASSYpe5VYh4b3KrP1lac0FGkxfIXyxyB4lJ3IZeuaqqBTLcGqMhZPA+9rZ5tv2cX2mSlBPFX3jHTV0tR13tK50mc9uxftOK6jIWjNiQkh5N9Qv4rxoarnBtfGy58su+JZ7xBg+ykClphmbz2yijp6D8p9wX4wi+D6Rpw97XndA4AYBCzz3TkG0A/yDev7vrcaaM4o0YtY65zeoIfN/wed97nFnFDA1QSDGOR/5LqhwsHT2HAPfkH7k27bhHBlU6Lo29FzpwndSXRgsEr6C2fU2DmkO7wy2ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=79dkGWcSIrhJEKzd6bcfhZO6P7zkHLTsROnq2ABASVY=; b=AaA4dJ4gRI8CGHOrpboQSYpkBhEzImi7ZYto4Ic6cSM5exIpIN15xypLHAlh+pFiJ+z1/zcwm2eqD3mOXGV1FVZbr2CZ7p6QHGUqT9eaucopK1pGwb09u+bOyzNQTVVjYxNm25lS3zuI4FmcriGGYnWnSKJWCJ13lEdtXJxXDm4= Received: from CYZPR17CA0023.namprd17.prod.outlook.com (2603:10b6:930:8c::29) by BY5PR12MB4952.namprd12.prod.outlook.com (2603:10b6:a03:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 17:07:03 +0000 Received: from CY4PEPF0000EE36.namprd05.prod.outlook.com (2603:10b6:930:8c:cafe::58) by CYZPR17CA0023.outlook.office365.com (2603:10b6:930:8c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.34 via Frontend Transport; Fri, 28 Jul 2023 17:07:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE36.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:03 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:02 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:02 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 28 Jul 2023 12:07:01 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V12 2/5] PCI: Create device tree node for bridge Date: Fri, 28 Jul 2023 10:06:55 -0700 Message-ID: <1690564018-11142-3-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> References: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE36:EE_|BY5PR12MB4952:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e201777-98c1-44eb-c19e-08db8f8d109e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aQsD9De8P8M1h8UvAvQtG6TnMA6CrkSFkNTs5G9EbH/owevqmJICBgpfM364YL0ORaJqh+hKPVKmKAN1yYqQBWwMfILuUhd3NJZzj8DoxbCRMzJIJOF2mGKsKwsE5fen1rl8okOVYBnaARIrKfw39E5jvQo4DNaBuy31HI9rb5PjRQgTcGN84duNuh6tNpgYeeNnPuug189fh1lp6IgkIsea+Z3NAWfe3EsjLFCYid/EBqtnk1q5s7n9zlp5jlX/5mtsLo7YsYWo+rkvVWPwBREg7viG34ZLMOWsIeyBel5rYHlcID4YqTa9Zo/Pb+ekLkaV4JXzfv+DlOWxLEs4R+f5Ac0hE8C5iphrXDjEs9GVr+Xe8QvP0u6l34g5PS+vY4+uXc58XyIXgMkCpOxoIe63MI0bw4uiXBiHcFJvy+ugfVbVtz7KpE7UTxURFDx1/LyogtKKu2pDY4EBcdaFOcj5PAsw4Kj9Ha6XbvQO+B67U7bTfh2Q6BggDNZv1nNAfeOv0roiGou9RVtOtWdCSJFRoOWXRkmBm92EZorgPun5ChKbV6DjYkPrO0xuZ+52gHaCAn2f2H8wsNJAHkodaQjfav/oqZ6QFpYUnDqm22ZxsQUp2FtCHiR1e9rKWTPuVYpn8S2eW/48zUPMk/yKhUDCudlgfM7EFaK5ChCD+p2LLUYn6wqy6sTQX44qmNDxIWOGKUDs99pMQdMDfyMtdgQsQAr1XHDhc04BYTtFVLxspEGsx9Tl6ygMfFx6D3Sr0+q7Tjlkwyj9GIuvNliz1w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(136003)(346002)(396003)(82310400008)(451199021)(40470700004)(46966006)(36840700001)(316002)(26005)(8936002)(41300700001)(40460700003)(54906003)(110136005)(81166007)(82740400003)(4326008)(70206006)(356005)(478600001)(70586007)(8676002)(40480700001)(30864003)(6666004)(36756003)(2616005)(2906002)(426003)(36860700001)(86362001)(83380400001)(47076005)(186003)(44832011)(336012)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 17:07:03.3964 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e201777-98c1-44eb-c19e-08db8f8d109e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE36.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4952 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772686351045887930 X-GMAIL-MSGID: 1772686351045887930 The PCI endpoint device such as Xilinx Alveo PCI card maps the register spaces from multiple hardware peripherals to its PCI BAR. Normally, the PCI core discovers devices and BARs using the PCI enumeration process. There is no infrastructure to discover the hardware peripherals that are present in a PCI device, and which can be accessed through the PCI BARs. Apparently, the device tree framework requires a device tree node for the PCI device. Thus, it can generate the device tree nodes for hardware peripherals underneath. Because PCI is self discoverable bus, there might not be a device tree node created for PCI devices. Furthermore, if the PCI device is hot pluggable, when it is plugged in, the device tree nodes for its parent bridges are required. Add support to generate device tree node for PCI bridges. Add an of_pci_make_dev_node() interface that can be used to create device tree node for PCI devices. Add a PCI_DYNAMIC_OF_NODES config option. When the option is turned on, the kernel will generate device tree nodes for PCI bridges unconditionally. Initially, add the basic properties for the dynamically generated device tree nodes which include #address-cells, #size-cells, device_type, compatible, ranges, reg. Acked-by: Bjorn Helgaas Signed-off-by: Lizhi Hou --- drivers/pci/Kconfig | 12 ++ drivers/pci/Makefile | 1 + drivers/pci/bus.c | 2 + drivers/pci/of.c | 79 +++++++++ drivers/pci/of_property.c | 355 ++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 12 ++ drivers/pci/remove.c | 1 + 7 files changed, 462 insertions(+) create mode 100644 drivers/pci/of_property.c diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 3c07d8d214b3..49bd09c7dd0a 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -194,6 +194,18 @@ config PCI_HYPERV The PCI device frontend driver allows the kernel to import arbitrary PCI devices from a PCI backend to support PCI driver domains. +config PCI_DYNAMIC_OF_NODES + bool "Create Device tree nodes for PCI devices" + depends on OF + select OF_DYNAMIC + help + This option enables support for generating device tree nodes for some + PCI devices. Thus, the driver of this kind can load and overlay + flattened device tree for its downstream devices. + + Once this option is selected, the device tree nodes will be generated + for all PCI bridges. + choice prompt "PCI Express hierarchy optimization setting" default PCIE_BUS_DEFAULT diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 2680e4c92f0a..cc8b4e01e29d 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o obj-$(CONFIG_VGA_ARB) += vgaarb.o obj-$(CONFIG_PCI_DOE) += doe.o +obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/ diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 5bc81cc0a2de..ab7d06cd0099 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -340,6 +340,8 @@ void pci_bus_add_device(struct pci_dev *dev) */ pcibios_bus_add_device(dev); pci_fixup_device(pci_fixup_final, dev); + if (pci_is_bridge(dev)) + of_pci_make_dev_node(dev); pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); pci_bridge_d3_update(dev); diff --git a/drivers/pci/of.c b/drivers/pci/of.c index e51219f9f523..ec132fbf5c69 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -611,6 +611,85 @@ int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) return pci_parse_request_of_pci_ranges(dev, bridge); } +#ifdef CONFIG_PCI_DYNAMIC_OF_NODES + +void of_pci_remove_node(struct pci_dev *pdev) +{ + struct device_node *np; + + np = pci_device_to_OF_node(pdev); + if (!np || !of_node_check_flag(np, OF_DYNAMIC)) + return; + pdev->dev.of_node = NULL; + + of_changeset_revert(np->data); + of_changeset_destroy(np->data); + of_node_put(np); +} + +void of_pci_make_dev_node(struct pci_dev *pdev) +{ + struct device_node *ppnode, *np = NULL; + const char *pci_type; + struct of_changeset *cset; + const char *name; + int ret; + + /* + * If there is already a device tree node linked to this device, + * return immediately. + */ + if (pci_device_to_OF_node(pdev)) + return; + + /* Check if there is device tree node for parent device */ + if (!pdev->bus->self) + ppnode = pdev->bus->dev.of_node; + else + ppnode = pdev->bus->self->dev.of_node; + if (!ppnode) + return; + + if (pci_is_bridge(pdev)) + pci_type = "pci"; + else + pci_type = "dev"; + + name = kasprintf(GFP_KERNEL, "%s@%x,%x", pci_type, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + if (!name) + return; + + cset = kmalloc(sizeof(*cset), GFP_KERNEL); + if (!cset) + goto failed; + of_changeset_init(cset); + + np = of_changeset_create_node(ppnode, name, cset); + if (!np) + goto failed; + np->data = cset; + + ret = of_pci_add_properties(pdev, cset, np); + if (ret) + goto failed; + + ret = of_changeset_apply(cset); + if (ret) + goto failed; + + pdev->dev.of_node = np; + kfree(name); + + return; + +failed: + if (np) + of_node_put(np); + kfree(name); +} +#endif + #endif /* CONFIG_PCI */ /** diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c new file mode 100644 index 000000000000..710ec35ba4a1 --- /dev/null +++ b/drivers/pci/of_property.c @@ -0,0 +1,355 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022-2023, Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include +#include "pci.h" + +#define OF_PCI_ADDRESS_CELLS 3 +#define OF_PCI_SIZE_CELLS 2 +#define OF_PCI_MAX_INT_PIN 4 + +struct of_pci_addr_pair { + u32 phys_addr[OF_PCI_ADDRESS_CELLS]; + u32 size[OF_PCI_SIZE_CELLS]; +}; + +/* + * Each entry in the ranges table is a tuple containing the child address, + * the parent address, and the size of the region in the child address space. + * Thus, for PCI, in each entry parent address is an address on the primary + * side and the child address is the corresponding address on the secondary + * side. + */ +struct of_pci_range { + u32 child_addr[OF_PCI_ADDRESS_CELLS]; + u32 parent_addr[OF_PCI_ADDRESS_CELLS]; + u32 size[OF_PCI_SIZE_CELLS]; +}; + +#define OF_PCI_ADDR_SPACE_IO 0x1 +#define OF_PCI_ADDR_SPACE_MEM32 0x2 +#define OF_PCI_ADDR_SPACE_MEM64 0x3 + +#define OF_PCI_ADDR_FIELD_NONRELOC BIT(31) +#define OF_PCI_ADDR_FIELD_SS GENMASK(25, 24) +#define OF_PCI_ADDR_FIELD_PREFETCH BIT(30) +#define OF_PCI_ADDR_FIELD_BUS GENMASK(23, 16) +#define OF_PCI_ADDR_FIELD_DEV GENMASK(15, 11) +#define OF_PCI_ADDR_FIELD_FUNC GENMASK(10, 8) +#define OF_PCI_ADDR_FIELD_REG GENMASK(7, 0) + +enum of_pci_prop_compatible { + PROP_COMPAT_PCI_VVVV_DDDD, + PROP_COMPAT_PCICLASS_CCSSPP, + PROP_COMPAT_PCICLASS_CCSS, + PROP_COMPAT_NUM, +}; + +static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr, + u32 reg_num, u32 flags, bool reloc) +{ + prop[0] = FIELD_PREP(OF_PCI_ADDR_FIELD_BUS, pdev->bus->number) | + FIELD_PREP(OF_PCI_ADDR_FIELD_DEV, PCI_SLOT(pdev->devfn)) | + FIELD_PREP(OF_PCI_ADDR_FIELD_FUNC, PCI_FUNC(pdev->devfn)); + prop[0] |= flags | reg_num; + if (!reloc) { + prop[0] |= OF_PCI_ADDR_FIELD_NONRELOC; + prop[1] = upper_32_bits(addr); + prop[2] = lower_32_bits(addr); + } +} + +static int of_pci_get_addr_flags(struct resource *res, u32 *flags) +{ + u32 ss; + + if (res->flags & IORESOURCE_IO) + ss = OF_PCI_ADDR_SPACE_IO; + else if (res->flags & IORESOURCE_MEM_64) + ss = OF_PCI_ADDR_SPACE_MEM64; + else if (res->flags & IORESOURCE_MEM) + ss = OF_PCI_ADDR_SPACE_MEM32; + else + return -EINVAL; + + *flags = 0; + if (res->flags & IORESOURCE_PREFETCH) + *flags |= OF_PCI_ADDR_FIELD_PREFETCH; + + *flags |= FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss); + + return 0; +} + +static int of_pci_prop_bus_range(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + u32 bus_range[] = { pdev->subordinate->busn_res.start, + pdev->subordinate->busn_res.end }; + + return of_changeset_add_prop_u32_array(ocs, np, "bus-range", bus_range, + ARRAY_SIZE(bus_range)); +} + +static int of_pci_prop_ranges(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_pci_range *rp; + struct resource *res; + int i, j, ret; + u32 flags, num; + u64 val64; + + if (pci_is_bridge(pdev)) { + num = PCI_BRIDGE_RESOURCE_NUM; + res = &pdev->resource[PCI_BRIDGE_RESOURCES]; + } else { + num = PCI_STD_NUM_BARS; + res = &pdev->resource[PCI_STD_RESOURCES]; + } + + rp = kcalloc(num, sizeof(*rp), GFP_KERNEL); + if (!rp) + return -ENOMEM; + + for (i = 0, j = 0; j < num; j++) { + if (!resource_size(&res[j])) + continue; + + if (of_pci_get_addr_flags(&res[j], &flags)) + continue; + + val64 = res[j].start; + of_pci_set_address(pdev, rp[i].parent_addr, val64, 0, flags, + false); + if (pci_is_bridge(pdev)) { + memcpy(rp[i].child_addr, rp[i].parent_addr, + sizeof(rp[i].child_addr)); + } else { + /* + * For endpoint device, the lower 64-bits of child + * address is always zero. + */ + rp[i].child_addr[0] = j; + } + + val64 = resource_size(&res[j]); + rp[i].size[0] = upper_32_bits(val64); + rp[i].size[1] = lower_32_bits(val64); + + i++; + } + + ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp, + i * sizeof(*rp) / sizeof(u32)); + kfree(rp); + + return ret; +} + +static int of_pci_prop_reg(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_pci_addr_pair reg = { 0 }; + + /* configuration space */ + of_pci_set_address(pdev, reg.phys_addr, 0, 0, 0, true); + + return of_changeset_add_prop_u32_array(ocs, np, "reg", (u32 *)®, + sizeof(reg) / sizeof(u32)); +} + +static int of_pci_prop_interrupts(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + int ret; + u8 pin; + + ret = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin); + if (ret != 0) + return ret; + + if (!pin) + return 0; + + return of_changeset_add_prop_u32(ocs, np, "interrupts", (u32)pin); +} + +static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_phandle_args out_irq[OF_PCI_MAX_INT_PIN]; + u32 i, addr_sz[OF_PCI_MAX_INT_PIN], map_sz = 0; + __be32 laddr[OF_PCI_ADDRESS_CELLS] = { 0 }; + u32 int_map_mask[] = { 0xffff00, 0, 0, 7 }; + struct device_node *pnode; + struct pci_dev *child; + u32 *int_map, *mapp; + int ret; + u8 pin; + + pnode = pci_device_to_OF_node(pdev->bus->self); + if (!pnode) + pnode = pci_bus_to_OF_node(pdev->bus); + + if (!pnode) { + pci_err(pdev, "failed to get parent device node"); + return -EINVAL; + } + + laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); + for (pin = 1; pin <= OF_PCI_MAX_INT_PIN; pin++) { + i = pin - 1; + out_irq[i].np = pnode; + out_irq[i].args_count = 1; + out_irq[i].args[0] = pin; + ret = of_irq_parse_raw(laddr, &out_irq[i]); + if (ret) { + pci_err(pdev, "parse irq %d failed, ret %d", pin, ret); + continue; + } + ret = of_property_read_u32(out_irq[i].np, "#address-cells", + &addr_sz[i]); + if (ret) + addr_sz[i] = 0; + } + + list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { + for (pin = 1; pin <= OF_PCI_MAX_INT_PIN; pin++) { + i = pci_swizzle_interrupt_pin(child, pin) - 1; + map_sz += 5 + addr_sz[i] + out_irq[i].args_count; + } + } + + int_map = kcalloc(map_sz, sizeof(u32), GFP_KERNEL); + mapp = int_map; + + list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { + for (pin = 1; pin <= OF_PCI_MAX_INT_PIN; pin++) { + *mapp = (child->bus->number << 16) | + (child->devfn << 8); + mapp += OF_PCI_ADDRESS_CELLS; + *mapp = pin; + mapp++; + i = pci_swizzle_interrupt_pin(child, pin) - 1; + *mapp = out_irq[i].np->phandle; + mapp++; + if (addr_sz[i]) { + ret = of_property_read_u32_array(out_irq[i].np, + "reg", mapp, + addr_sz[i]); + if (ret) + goto failed; + } + mapp += addr_sz[i]; + memcpy(mapp, out_irq[i].args, + out_irq[i].args_count * sizeof(u32)); + mapp += out_irq[i].args_count; + } + } + + ret = of_changeset_add_prop_u32_array(ocs, np, "interrupt-map", int_map, + map_sz); + if (ret) + goto failed; + + ret = of_changeset_add_prop_u32(ocs, np, "#interrupt-cells", 1); + if (ret) + goto failed; + + ret = of_changeset_add_prop_u32_array(ocs, np, "interrupt-map-mask", + int_map_mask, + ARRAY_SIZE(int_map_mask)); + if (ret) + goto failed; + + kfree(int_map); + return 0; + +failed: + kfree(int_map); + return ret; +} + +static int of_pci_prop_compatible(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + const char *compat_strs[PROP_COMPAT_NUM] = { 0 }; + int i, ret; + + compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] = + kasprintf(GFP_KERNEL, "pci%x,%x", pdev->vendor, pdev->device); + compat_strs[PROP_COMPAT_PCICLASS_CCSSPP] = + kasprintf(GFP_KERNEL, "pciclass,%06x", pdev->class); + compat_strs[PROP_COMPAT_PCICLASS_CCSS] = + kasprintf(GFP_KERNEL, "pciclass,%04x", pdev->class >> 8); + + ret = of_changeset_add_prop_string_array(ocs, np, "compatible", + compat_strs, PROP_COMPAT_NUM); + for (i = 0; i < PROP_COMPAT_NUM; i++) + kfree(compat_strs[i]); + + return ret; +} + +int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + int ret; + + /* + * The added properties will be released when the + * changeset is destroyed. + */ + if (pci_is_bridge(pdev)) { + ret = of_changeset_add_prop_string(ocs, np, "device_type", + "pci"); + if (ret) + return ret; + + ret = of_pci_prop_bus_range(pdev, ocs, np); + if (ret) + return ret; + + ret = of_pci_prop_intr_map(pdev, ocs, np); + if (ret) + return ret; + } + + ret = of_pci_prop_ranges(pdev, ocs, np); + if (ret) + return ret; + + ret = of_changeset_add_prop_u32(ocs, np, "#address-cells", + OF_PCI_ADDRESS_CELLS); + if (ret) + return ret; + + ret = of_changeset_add_prop_u32(ocs, np, "#size-cells", + OF_PCI_SIZE_CELLS); + if (ret) + return ret; + + ret = of_pci_prop_reg(pdev, ocs, np); + if (ret) + return ret; + + ret = of_pci_prop_compatible(pdev, ocs, np); + if (ret) + return ret; + + ret = of_pci_prop_interrupts(pdev, ocs, np); + if (ret) + return ret; + + return 0; +} diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index a4c397434057..ba717bdd700d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -679,6 +679,18 @@ static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_br #endif /* CONFIG_OF */ +struct of_changeset; + +#ifdef CONFIG_PCI_DYNAMIC_OF_NODES +void of_pci_make_dev_node(struct pci_dev *pdev); +void of_pci_remove_node(struct pci_dev *pdev); +int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np); +#else +static inline void of_pci_make_dev_node(struct pci_dev *pdev) { } +static inline void of_pci_remove_node(struct pci_dev *pdev) { } +#endif + #ifdef CONFIG_PCIEAER void pci_no_aer(void); void pci_aer_init(struct pci_dev *dev); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d68aee29386b..d749ea8250d6 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -22,6 +22,7 @@ static void pci_stop_dev(struct pci_dev *dev) device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); + of_pci_remove_node(dev); pci_dev_assign_added(dev, false); } From patchwork Fri Jul 28 17:06:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 127785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp590898vqg; Fri, 28 Jul 2023 10:35:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHr01GDN2lR51RlO7rH/TaoUzRYOsX+NSoUdE9xnGARcYaIeFzbh4ko4bF7BpjwNM365AMn X-Received: by 2002:a17:903:1cb:b0:1bb:8931:ee94 with SMTP id e11-20020a17090301cb00b001bb8931ee94mr1920348plh.67.1690565717439; Fri, 28 Jul 2023 10:35:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690565717; cv=pass; d=google.com; s=arc-20160816; b=H/fcg4bAjPpksjYYM2SGFqoJW7c87AAKhAVNVimvpP2tsgFIZJnOUeiHqrnD/4MTfU 7EA7IeH8D6tngX8h8zVhZ9FWELlOoMH2NzECl+8op3sbfYBaCnEgGYT+rYI+uuFIVALa b8ARG82vcems2QipYYvqfb1OEMLJkNMcY7TMuaes4367KPsCPdc7AF0oqtsryVzaTl3A Cla+t73tbaU6ndqveo2geD694Xp2Slv111dTYcozl9iXtJhrTSuoNTe32FlpPDBcwIgV mFl2oVZyVPJ0Y12Birt0CGqVMy+RAyqoxWNr0ohF+OVxMtwIJptwdgYCwR/vMqLevsO8 qNYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LsNs3+RFfiY/iKi6qTA8+Ipu+qkjh/WS4+AwQNiyk+A=; fh=7qEUnvroiVGqNbV2BsznAhWWl5a9gsasDQnJyIlYZRk=; b=fd0kH1yGyryB1l3xOK6U3pU3yODEJfl68SpCsiBaAOre9cECUrxFhb8Vycr79HKfkq 0fCJh6F5yDRKckIwxVHKKkfdWoCQA9mYXhdTCUCasQBfT8C8LzMOqp5xGRxAE0fbaFNp X2Mye2ClYhfocTco3fn79ZLngOy2Q0HJUx0ef4OkO4D3E/Q3MnU1eWZgDPlAwtKsaIwL RR2tSxdtg21GgepnNEjqkisPGN/H5RZe/PBAUuNUDKk1Vm56ec3K+zI6tU/CoRpPCVMX JST8LR4SHn66MjuDSwpp46iS/UpPPFu7Al/t815+fkjZlWeoJde1NQRzRY+W0B99Lkd7 NFKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=zWqHwggt; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a17090a4f4300b00267ee6ef3ccsi4952821pjl.137.2023.07.28.10.35.04; Fri, 28 Jul 2023 10:35:17 -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=@amd.com header.s=selector1 header.b=zWqHwggt; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236196AbjG1RHc (ORCPT + 99 others); Fri, 28 Jul 2023 13:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234437AbjG1RHP (ORCPT ); Fri, 28 Jul 2023 13:07:15 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2087.outbound.protection.outlook.com [40.107.93.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A8133A8B; Fri, 28 Jul 2023 10:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DctaeYjkBAYxMcj/66f2YY+vk6VhegDIkZXT6igXsVIr7NAkQPc9RtA2ef/FWLKbZhXyE5Tc3DO/zxMwdZ1xshMMhNxL1Am9Aw3HRXeWGfNtlV83TnLAlZfnxXWHn0HESvFXGTTOU/lC9BpKi2zeGHUItDzpjBokYumm89jy57Bp63gAxTnofjNHvtK4IArawqTOJx0q26ls3u7pt51We2t2eJnd8mwPIGT1Sn4aZSggfwadWUfwEjssJmf7BMhCz4Zpq80gkNzzp26K3V6MVXrv1k7EQ35sCsXW5mkjg1w66PD6uSI0+fx0lHGGYVMgdwVqoSvLnLHbpgTUXqbFXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LsNs3+RFfiY/iKi6qTA8+Ipu+qkjh/WS4+AwQNiyk+A=; b=QWazV1XSA7uT+WcU7AY5WtAzduzBWwCBCJW1qXos2Y7g/cUknwK96ozM84JX/tEfxq1pj8zmdF36KOZ2CH0kS4DM0GiavLYp1A2EqTeA5WgSbNnMN3+sK0oXG9SnHq8KHJLev/eV2W8T3z/s/Jum/VS9o9LkllVsCGW+3PjnWek1fA+FFQuSFPKMM/4FJVvjz4kljhIUIUlcyR8rsx8hIciGQlcl03D85GLmJf05b7H7tqFCoItS3DgXfkkIXonnzEANn/LktCD4QxlqKVpFiczsV81KkykdXBF2opDlCg0aIrrceIrkSOrhwUoMg0wYengK2S19dbqZmdGe+SuZdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LsNs3+RFfiY/iKi6qTA8+Ipu+qkjh/WS4+AwQNiyk+A=; b=zWqHwggtE7W72lEI4il9zT0LqK+AGLLZ1HAL46Kc+CdHMqn5l53uNtv97dyR6v5sMTTvsqVeSN7Y2XG4ujMB/eNJsNKGxwoBIT1mTalWNcaCFXwkNsNYV7FD/9cyb01ttT56n+rm5ysNPwMnqJ9ZpDSuOazMUW1iwIKg80Mugu8= Received: from BN9PR03CA0437.namprd03.prod.outlook.com (2603:10b6:408:113::22) by IA1PR12MB6331.namprd12.prod.outlook.com (2603:10b6:208:3e3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 17:07:05 +0000 Received: from BN8NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:408:113:cafe::b5) by BN9PR03CA0437.outlook.office365.com (2603:10b6:408:113::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT112.mail.protection.outlook.com (10.13.176.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.35 via Frontend Transport; Fri, 28 Jul 2023 17:07:05 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:03 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:03 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 28 Jul 2023 12:07:02 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V12 3/5] PCI: Add quirks to generate device tree node for Xilinx Alveo U50 Date: Fri, 28 Jul 2023 10:06:56 -0700 Message-ID: <1690564018-11142-4-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> References: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT112:EE_|IA1PR12MB6331:EE_ X-MS-Office365-Filtering-Correlation-Id: 07cede8a-8736-4c7b-f901-08db8f8d118b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /DZnJOtALtgKYB0YxUjDt2KTiR03XL7meyqPTeuwo84FAlN68xgDxXKrVXpwJ9ZlsTmTg+94uEgUYm8z18Gz0fNaxyD+v/+6+DncD4l7kkd7y8U9ZNE2ZqSZ5AkLkwY3abp0T7TZb55O9LaVeaCGUa0E2VYOAWq05s1vR1FFlTZlDucGJumKTFTQCAVHPQ/yFbMofLdI0IU5sZCMdJU1ndlgTbm1jlzjQhoisELx3ZpN9ojRF8Zs9A7BVsWlyXo/XmA1uPZ4O5wZH95tU+r7D/0dl9G9wxn9rSMuAgI2xavtIs1eTlqglKG6NTANf9uUD56YW0AXuWGiuwfHbiMu0MrAsT0eR8bWLUT0/vvg+4iVIbeOMmnUJXp5EvygeSHSQ45J+yf2BKyJRhzoUYJ+S2vP//zVgjFO713TWjlhmxBLVeZeUYm8sjpej6ZobB2dalnTQzrc+oJybQ/NP+tb/VxdxFIch1ppGRfTaGxVj9eqzzSEHoCJ0Df/dGti/BjVAdKR9ZaT4bT5W+ZqyMLSJr3B0DKV3kVp2LBdRKVyYQN6QxDthfZu35bMUUO8sGP5eASn1fE1HaIZLAkMF9L0SXgnMikzQzejTShpBzdEIkoWohYfeDS4T4PZZchv5r5riryfT+FkP7QimgHJuabAWMAhBknu1wXK/AHUtjAC3uJKOCYdIzAcdxiKvNNSlN/PO7ZZOGVveN1/pjGKjF7VTLgT/gFqg0AQat3Aqv/5YK/ZzfI8RWHD0aJkrvSgWaw5coa8OYpc6yIRphw5nAOxhA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(136003)(396003)(346002)(82310400008)(451199021)(36840700001)(40470700004)(46966006)(2906002)(316002)(8936002)(8676002)(40460700003)(5660300002)(44832011)(41300700001)(36756003)(40480700001)(86362001)(6666004)(426003)(81166007)(54906003)(82740400003)(478600001)(356005)(26005)(186003)(336012)(110136005)(2616005)(70206006)(70586007)(36860700001)(47076005)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 17:07:05.0135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 07cede8a-8736-4c7b-f901-08db8f8d118b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6331 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772686637644914694 X-GMAIL-MSGID: 1772686637644914694 The Xilinx Alveo U50 PCI card exposes multiple hardware peripherals on its PCI BAR. The card firmware provides a flattened device tree to describe the hardware peripherals on its BARs. This allows U50 driver to load the flattened device tree and generate the device tree node for hardware peripherals underneath. To generate device tree node for U50 card, add PCI quirks to call of_pci_make_dev_node() for U50. Acked-by: Bjorn Helgaas Signed-off-by: Lizhi Hou --- drivers/pci/quirks.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 321156ca273d..6c0e7b6bbdd1 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6138,3 +6138,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); #endif + +/* + * For a PCI device with multiple downstream devices, its driver may use + * a flattened device tree to describe the downstream devices. + * To overlay the flattened device tree, the PCI device and all its ancestor + * devices need to have device tree nodes on system base device tree. Thus, + * before driver probing, it might need to add a device tree node as the final + * fixup. + */ +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node); +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node); From patchwork Fri Jul 28 17:06:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 127818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp616301vqg; Fri, 28 Jul 2023 11:24:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEwG3J3yzFS8AC60z0Ku4ipLSPJRdSqfGDRxahaRkYHk5dqxa67w+Z+eWV8swe9yzImZUjQ X-Received: by 2002:a17:902:988e:b0:1bb:14e7:4fdf with SMTP id s14-20020a170902988e00b001bb14e74fdfmr2478775plp.22.1690568682518; Fri, 28 Jul 2023 11:24:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690568682; cv=pass; d=google.com; s=arc-20160816; b=f0MoktaShTOzguhKcyOdkiFULxC1QiZPHX60eAa3kY4/lNetn3Uvlf+lal65Hk5U/4 tbbPFF6VASG/rMGvwZXJVikYBlWqS37uPCJR24duEg/BL+9RLRzWYD64CLSt95q33mSu Xb21Kbu8rAaIwWRBNu315wMgtb7KEv5DSAFROiCvi9ZVPNDaRm7POEh3BOsLuFvR33iE RGmnnE/2W9VcpKYTykUNDYfMrxHFzBJuZzzzsEqHzEB8wB09zuzFJ5b5rI361ytM6cwU thlIczC+m0IX+BZSTOanEt5ddMCKeNfzZPsVH7AmsLRWa328OYKVVvuiCPgd2pGhPhgy f0vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wBJs1W1gsz26MzBL1ZYcPD7bjCpk2QNv3lOk5FogfDE=; fh=7qEUnvroiVGqNbV2BsznAhWWl5a9gsasDQnJyIlYZRk=; b=lfsJetRkrCEm/b2bvkOFc3kr4U1+/8HIrS0kEaVVaR04jhkmmqLCWkpbp8MRZGsc5X khxgNDTfFthGI/NyAk6a76MlC8nye3dkeiY1Hg7qconb2NgjEzpNteLG1BXUjG1BeNMx Gfj98X56I0XE1d0BZ/3z7Y9VpT1yvrOXtwYt1W8R/bxKRkOpmryotQGWanMztmHBrnTI d/r9vaRH34Gwx4ZyYLU5r4MvLq9wQ7m05gTbIhFsn7271z9fp2FDtWH0cwNPml5+SvvR Ux9yVyKOqUcmPWVQZfoOo0PgTw5zK7gyjVVUqCl4BtWQFOssAFqX8fPs7tQXFze3PFB0 OT/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=htm2EfPP; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p16-20020a170902e75000b001b8944aa0d8si3441300plf.463.2023.07.28.11.24.29; Fri, 28 Jul 2023 11:24:42 -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=@amd.com header.s=selector1 header.b=htm2EfPP; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235708AbjG1RHV (ORCPT + 99 others); Fri, 28 Jul 2023 13:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235081AbjG1RHK (ORCPT ); Fri, 28 Jul 2023 13:07:10 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2075.outbound.protection.outlook.com [40.107.94.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6326635A8; Fri, 28 Jul 2023 10:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JwsRE2thnRynzXCIfuAbQwvBCujMLskfOYgJccvSyvcEKbSomrfQJyHVLBx9iz0/b1ABiuFHKyqGqVcgLlstTORZjqYE+HaLae4oRR+Z/LcIKBYl2H+BXMEULP86rbFilxtwJPZg4Ui+bdFg/d4jq766ZHa32n/TWyikOlKXckW/VJyd1z8EJlE68dMW9bt4cUPin9fpJ6ZlG2XNDIH0e29+ymQQHTIGeo3GAhUCzYSOto4TcsYNTU2AIF5b11ABB+NW61ZhibB16hB7bCMzAVv/J/bs31QronCVF2zSUMyyehkWVHyZ9E5HCqXPF3BxAZKRUl91dUlyre8qAFh7GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wBJs1W1gsz26MzBL1ZYcPD7bjCpk2QNv3lOk5FogfDE=; b=Th8YZYwhqJDF4SmaftDyLVVVhIdD0+27W3ZX0QnGrT2jfi0zYsOpEtDczxFtggG+k8W15M2l7hOVO8HinmLjBtFSsqNLmVwqBrti5Bpo1Ppr6Gin5LobTEom/AYW8kwUg78SOH2Gnqa2HvejuOVmDJvA+88PrKha8qZgEu3nN85wf8ighoFsUtg956D619M4AfJN9L6HZwS/o9ehLYqQmAsiXs59Ahp3ejKhQb9QqTEFMh8OxEuQ80MAJgIRsa9pgQVua/IGw89NK2v7Zd/1oYA/b5qNEaZnvyv+Nzdqsh813NEsUKtD/Ehcr2i9f1qUxPFARA5hnmyTV7Lx75MMHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wBJs1W1gsz26MzBL1ZYcPD7bjCpk2QNv3lOk5FogfDE=; b=htm2EfPPPwnIPAirnny/134iXkrFShVE6asZQ8xUyIXCCxny+4qiWZsqj15j3LqjVrKX0Qdkm5Ksjdp0nHB369GBroMOBzS/GbK/e2L+2xwjYl9rOtoZlynRlC9SOI5T40/094SKW2ac26PoOytaNln+UDJrECE1jcstCa0PI6Q= Received: from DM6PR03CA0060.namprd03.prod.outlook.com (2603:10b6:5:100::37) by BN9PR12MB5322.namprd12.prod.outlook.com (2603:10b6:408:103::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 17:07:05 +0000 Received: from CY4PEPF0000EE31.namprd05.prod.outlook.com (2603:10b6:5:100:cafe::f5) by DM6PR03CA0060.outlook.office365.com (2603:10b6:5:100::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE31.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:05 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:04 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:04 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 28 Jul 2023 12:07:03 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V12 4/5] of: overlay: Extend of_overlay_fdt_apply() to specify the target node Date: Fri, 28 Jul 2023 10:06:57 -0700 Message-ID: <1690564018-11142-5-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> References: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE31:EE_|BN9PR12MB5322:EE_ X-MS-Office365-Filtering-Correlation-Id: d2436211-d3d2-4a08-53ae-08db8f8d1197 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l8t8DXCHGUoIgzGm/jhfenhwnDPngUBz8KovGPZDcwX7DF+Fpf022Hkl0L6lLZYF/Jc2XifKC6YPMtGI9i4eXi+472RSSg1y7EABjOyzp8hU2y72wefn4qrS8RMij6eQcE9uMgIjAPY8PZw1dViC4N5FsTJvp9SVoHaela72c4f5uyX616uD15H4WcG/fLo2DIZ+GEvCKBx7u6bg2F56kGR7lzM+loLfaxTPsYJNTCEM36wHQAd95WhKl28ccCipaqFkdB4pJHHSKUNtd7+mWPBOMijbc2KeK0kEw7kQwS2dcWHOxogkj9dexfWEVrd3Zjt3GMzt277zd1sMJujEgcCVL/iwe6JTvUC+xOQfSM1VWyI1h88ZFCoxhdfXj3jN8Qp5fRnqsF7IElUelYZj/H27B8eVqjjk6B6hUYWxTcq9c/JiMfAy7TzX4dSfMx84q8Vz7Hj0gtO2prup9yYhLHure9Cfsx8tfB/UpQR1OJolcF48UEakLS0THklEBHFIIZ4guG5HG/Vznn7LOFOf3j3ZNjAFIYBgYRRYAL79QW5GH4CKceNp0hK9MO/1gADoMeuIXq6hYjskzHDXK+gz70CqcaLQTnljsJmUuN4HTcmLMA5L4ZYCOBpKo8X3GmB23RmLQ0wD2ndkfBPljtmDtjdNv/wVFyf70o+A/6TG6DMKCnPdhnK7nhVC95xHI6u9a4oEyubE9VX766aOChCEXklAngpMsubn2VCFnCCpvZUUiBMiAyrEgdEcIVvOOTcVFeGB5MSDQSLDipP+3ec4ZA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(346002)(136003)(82310400008)(451199021)(46966006)(36840700001)(40470700004)(86362001)(356005)(36756003)(40460700003)(2906002)(40480700001)(110136005)(54906003)(478600001)(82740400003)(81166007)(336012)(36860700001)(426003)(26005)(186003)(2616005)(47076005)(41300700001)(44832011)(8676002)(316002)(6666004)(70206006)(70586007)(5660300002)(4326008)(83380400001)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 17:07:05.0254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2436211-d3d2-4a08-53ae-08db8f8d1197 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE31.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5322 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772689747230225720 X-GMAIL-MSGID: 1772689747230225720 Currently, in an overlay fdt fragment, it needs to specify the exact location in base DT. In another word, when the fdt fragment is generated, the base DT location for the fragment is already known. There is new use case that the base DT location is unknown when fdt fragment is generated. For example, the add-on device provide a fdt overlay with its firmware to describe its downstream devices. Because it is add-on device which can be plugged to different systems, its firmware will not be able to know the overlay location in base DT. Instead, the device driver will load the overlay fdt and apply it to base DT at runtime. In this case, of_overlay_fdt_apply() needs to be extended to specify the target node for device driver to apply overlay fdt. int overlay_fdt_apply(..., struct device_node *base); Signed-off-by: Lizhi Hou --- drivers/of/overlay.c | 42 +++++++++++++++++++++++++++++++----------- drivers/of/unittest.c | 3 ++- include/linux/of.h | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 7feb643f1370..6f3ae30c878d 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -682,9 +682,11 @@ static int build_changeset(struct overlay_changeset *ovcs) * 1) "target" property containing the phandle of the target * 2) "target-path" property containing the path of the target */ -static struct device_node *find_target(struct device_node *info_node) +static struct device_node *find_target(struct device_node *info_node, + struct device_node *target_base) { struct device_node *node; + char *target_path; const char *path; u32 val; int ret; @@ -700,10 +702,23 @@ static struct device_node *find_target(struct device_node *info_node) ret = of_property_read_string(info_node, "target-path", &path); if (!ret) { - node = of_find_node_by_path(path); - if (!node) - pr_err("find target, node: %pOF, path '%s' not found\n", - info_node, path); + if (target_base) { + target_path = kasprintf(GFP_KERNEL, "%pOF%s", target_base, path); + if (!target_path) + return NULL; + node = of_find_node_by_path(target_path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, target_path); + } + kfree(target_path); + } else { + node = of_find_node_by_path(path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, path); + } + } return node; } @@ -715,6 +730,7 @@ static struct device_node *find_target(struct device_node *info_node) /** * init_overlay_changeset() - initialize overlay changeset from overlay tree * @ovcs: Overlay changeset to build + * @target_base: Point to the target node to apply overlay * * Initialize @ovcs. Populate @ovcs->fragments with node information from * the top level of @overlay_root. The relevant top level nodes are the @@ -725,7 +741,8 @@ static struct device_node *find_target(struct device_node *info_node) * detected in @overlay_root. On error return, the caller of * init_overlay_changeset() must call free_overlay_changeset(). */ -static int init_overlay_changeset(struct overlay_changeset *ovcs) +static int init_overlay_changeset(struct overlay_changeset *ovcs, + struct device_node *target_base) { struct device_node *node, *overlay_node; struct fragment *fragment; @@ -786,7 +803,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs) fragment = &fragments[cnt]; fragment->overlay = overlay_node; - fragment->target = find_target(node); + fragment->target = find_target(node, target_base); if (!fragment->target) { of_node_put(fragment->overlay); ret = -EINVAL; @@ -877,6 +894,7 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * * of_overlay_apply() - Create and apply an overlay changeset * @ovcs: overlay changeset + * @base: point to the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -900,7 +918,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * the caller of of_overlay_apply() must call free_overlay_changeset(). */ -static int of_overlay_apply(struct overlay_changeset *ovcs) +static int of_overlay_apply(struct overlay_changeset *ovcs, + struct device_node *base) { int ret = 0, ret_revert, ret_tmp; @@ -908,7 +927,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) if (ret) goto out; - ret = init_overlay_changeset(ovcs); + ret = init_overlay_changeset(ovcs, base); if (ret) goto out; @@ -952,6 +971,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) * @overlay_fdt: pointer to overlay FDT * @overlay_fdt_size: number of bytes in @overlay_fdt * @ret_ovcs_id: pointer for returning created changeset id + * @base: pointer for the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -967,7 +987,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) */ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ret_ovcs_id) + int *ret_ovcs_id, struct device_node *base) { void *new_fdt; void *new_fdt_align; @@ -1037,7 +1057,7 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, } ovcs->overlay_mem = overlay_mem; - ret = of_overlay_apply(ovcs); + ret = of_overlay_apply(ovcs, base); /* * If of_overlay_apply() error, calling free_overlay_changeset() may * result in a memory leak if the apply partly succeeded, so do NOT diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index d2b286d32db0..7bff6c4cb653 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3478,7 +3478,8 @@ static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id) if (!size) pr_err("no overlay data for %s\n", overlay_name); - ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id); + ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id, + NULL); if (ovcs_id) *ovcs_id = info->ovcs_id; if (ret < 0) diff --git a/include/linux/of.h b/include/linux/of.h index 82d0a476ec75..5fe5257a7ab7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1668,7 +1668,7 @@ struct of_overlay_notify_data { #ifdef CONFIG_OF_OVERLAY int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ovcs_id); + int *ovcs_id, struct device_node *target_base); int of_overlay_remove(int *ovcs_id); int of_overlay_remove_all(void); From patchwork Fri Jul 28 17:06:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 127774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp587943vqg; Fri, 28 Jul 2023 10:30:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQyaqv53/RiydHH+RcE0TO8ywcOx2w4j0ndFFNWE0DcKUPgXGIZ5uzQL+vMZviembZTEiF X-Received: by 2002:a17:903:41cb:b0:1b3:d6c8:7008 with SMTP id u11-20020a17090341cb00b001b3d6c87008mr2434994ple.57.1690565409382; Fri, 28 Jul 2023 10:30:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690565409; cv=pass; d=google.com; s=arc-20160816; b=bx6D720ocT2JOEiQLntOm6mCqXf75R5m058nH2guCD8bM4V1dH8OBvO0v5PRAWIQl2 Y6jwauw6p190uK79nCEpKBZbVSEE/0vkCikEPzIF/ocz9vcIdxfZvH6AEfTQnN9k1cVZ yZefiKJfLQOwHWu7ga5Nu2AeENhPb6mOM63sVo/2+lfPxF4g5KZjFp9n5dl5k+fdNhV1 jIcgItvWziyUWkaScWfTj6+CbvCcRZKX+Q8SfiGWrEZY/iAlGARbCf9N7cYqDaB1OBSz bknJQk4uJCTKvDkKdcuHPvUEQXF12c0eH1N+bGcdBbPuUpeLbf9s45n0r8JtDpjuy6oC NrHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OjXllyAyHppdTnvS6sbsaIuNb2aA8ZEh9Ydwdm5jURs=; fh=7qEUnvroiVGqNbV2BsznAhWWl5a9gsasDQnJyIlYZRk=; b=f1hjqEopNQChjMd+Vm/9TwZgHgq+WQaxFv4Rk5Fs7khJYo2nntKZF21ZHOE7LuQx0v Nwlu3uJJnAiRKkkwY3xOfj8rc6v+oPnsUNp8o9uQschPEII2+BMoh3DjtZPSjus6yjbK t/lHB7lbgL6ZjcYIerHw6Xn6ardXvr5WqUP1ZABsY/W22T2WEF+yCRSiFAO+bK6tNNen JliqvL+zla03jBiksAgPaqLON/4UE2VCjRvdEAakUpV/sGpqTXR6xEsLzGn9Sgb1PltJ WGBpWXO1kvi6LxxD9BtKHrud5btI6ANZ0R/3tZSx4NGs/2gLQGGvP1+T8GVWmacczRN8 nseQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=EFUbJG9K; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a170902788700b001b828f8dd13si3235840pll.340.2023.07.28.10.29.56; Fri, 28 Jul 2023 10:30:09 -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=@amd.com header.s=selector1 header.b=EFUbJG9K; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbjG1RH2 (ORCPT + 99 others); Fri, 28 Jul 2023 13:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235680AbjG1RHM (ORCPT ); Fri, 28 Jul 2023 13:07:12 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69B4235B3; Fri, 28 Jul 2023 10:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mopTpLgaOiroz8rOlFFX7y3sPp5/kOLFdvbzJ1NIkGuk3pTzHmovw33zqp7E/OS7y8nRnM7BzpTss+RVymR07naCRolTdQFkPTz3xDZowe0nwr0343ycY9t8zVzIlfVAbjW6Trdt2OqVG0XJgOxf4YthWaq7cvX8xXtIYQYxclNjh800X7BNFkRveeaNgfinMAa1xiyVPcqI+XOma+Kxsd/Nfd2azo4AyMFoKa0UA6Th+rJK7ajqJWVatW+s0ixzqQFw8kyTzL2ioxgR8iBUsZU/r7l9Fnl6+A/gTGROfsTb/ylvboE0gUC2qSZsyeOEmKAyiwwzF4NM1jvRON+e6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OjXllyAyHppdTnvS6sbsaIuNb2aA8ZEh9Ydwdm5jURs=; b=InuHw61G6CsutH+UXg/1MWONbPG8lpBGe4v/K3aN6xmdNCuTsJGOtoS4l31y2ukVltRt5yN+43tXBElXVU8G2wuR71A2EsmXBIDvg+IN0cP6+zPYUFWKm4TOLS3nWkB0WxaeW5f/yIE3a4gisJcno0tbtIuSxU/OWIozCgE92MgtBjwj9slDXY533OHsVmR+hO6LT8NzFTqQJ3+IV7Ott+srtlPVXVOJeZbQBE/F8xkSXLFm5BBU9lcw4/xtZGho7/js+LM4uDSQBFUvViJeFga7X9mqQsNjHZI4kNn7gH98gBRZQNmwEonmZkkob3hVpU1TyJmW/pV4DyaehOqZbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OjXllyAyHppdTnvS6sbsaIuNb2aA8ZEh9Ydwdm5jURs=; b=EFUbJG9KKRTslf9HZ4HIcX259sg24MKDsfL02Pmx6OTt9Z+Z5d80ty/N9rfexusQh6BGcYbpklxrYBf/+bRteYcZ7YBq13SzegB1F5DpfmhNLvi9DjxiLBpLlGhfQjYJ7nYuUYD75n5t7Ael2qooz/hUtUkr6m2vZlD6JsaNyCo= Received: from BN6PR17CA0047.namprd17.prod.outlook.com (2603:10b6:405:75::36) by DS7PR12MB5935.namprd12.prod.outlook.com (2603:10b6:8:7e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 17:07:06 +0000 Received: from BN8NAM11FT086.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::c) by BN6PR17CA0047.outlook.office365.com (2603:10b6:405:75::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT086.mail.protection.outlook.com (10.13.176.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Fri, 28 Jul 2023 17:07:06 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:05 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:07:05 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 28 Jul 2023 12:07:04 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V12 5/5] of: unittest: Add pci_dt_testdrv pci driver Date: Fri, 28 Jul 2023 10:06:58 -0700 Message-ID: <1690564018-11142-6-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> References: <1690564018-11142-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT086:EE_|DS7PR12MB5935:EE_ X-MS-Office365-Filtering-Correlation-Id: ac3f8f50-99ce-458c-b70c-08db8f8d124a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N6v/B8iZJXozmoDHTLqBYRwwLsmSLFwwhVdDQvrVx3ydQw0hZ2CfkygFz/ydA1a8OH082ffx/42P9gf6286fmRSfHdEaKnPIo+h8t45KE1TVjRoLFYN/6m0SPiVyulNCHk1fruvCM5RZGr81C/8yhASJvd1xIWwcO/EPp7NgUmC/PfT6A70a7oD3Kl8ZW+vX+7tP1ssoVOvkQmYFhi+WoI3p0ac136eTAd2gxzqS3SE1KMjT3jgWhpkvlcZURZ8cE0r3upyelTzQkqZ0uuj3CcPzx1HNp2luEDHEvyuGrelZ4ZtFWHhEzhY1+XocW9e+hgqp5Bu6v2Bx0bEBkgDnGbFejUvZuwuU9waGjHNo4qv34aUm+ZVRx2+yF4z31mqvhBtNpz3ZLmLzY4iX7T8Q2RgoPUHyFPwkAclJOC7MATchc0haYWy+dbS1Jfq1m+MYb4LoZvvJ6fee4wmenEqkxPquCRbtYQtEvg6qVSmXKBod8GUjazNwdxWZomFhP1qL/6UCW4i/jcWSGE/KE3XAIBoSfoR2kSbN/i70mUJtzPrF9tikXq9m2WgQT7T+en52cvkHkmFsQyEvUuhNE5SrPHtwJ2WmTe13VSUqTPygrgCtp/TTLrF8o4U7DL91QjPkXCNxKecTDpgpDUAlpnywpizr5P2yKR8KeXLgY5KIFDUJ7a9SoWHNygteJ8V2W/3bKB4qlZ460Fzc2E5LvFRWApLsPefChoNlE2JAHZKAMAACAogq3YLrAPaCJm5RZHeFDABHHIp7JBD1HuHCpVwtVg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(396003)(39860400002)(82310400008)(451199021)(46966006)(36840700001)(40470700004)(110136005)(54906003)(6666004)(478600001)(83380400001)(36860700001)(40480700001)(36756003)(86362001)(40460700003)(2906002)(47076005)(336012)(2616005)(82740400003)(186003)(26005)(70206006)(426003)(70586007)(81166007)(316002)(5660300002)(44832011)(41300700001)(8936002)(8676002)(356005)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 17:07:06.2635 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac3f8f50-99ce-458c-b70c-08db8f8d124a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT086.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5935 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772686315027685110 X-GMAIL-MSGID: 1772686315027685110 pci_dt_testdrv is bound to QEMU PCI Test Device. It reads overlay_pci_node fdt fragment and apply it to Test Device. Then it calls of_platform_default_populate() to populate the platform devices. Tested-by: Herve Codina Signed-off-by: Lizhi Hou --- drivers/of/unittest-data/Makefile | 3 +- .../of/unittest-data/overlay_pci_node.dtso | 22 ++ drivers/of/unittest.c | 189 ++++++++++++++++++ drivers/pci/quirks.c | 1 + 4 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index ea5f4da68e23..1aa875088159 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -32,7 +32,8 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtbo.o \ overlay_gpio_02b.dtbo.o \ overlay_gpio_03.dtbo.o \ overlay_gpio_04a.dtbo.o \ - overlay_gpio_04b.dtbo.o + overlay_gpio_04b.dtbo.o \ + overlay_pci_node.dtbo.o # enable creation of __symbols__ node DTC_FLAGS_overlay += -@ diff --git a/drivers/of/unittest-data/overlay_pci_node.dtso b/drivers/of/unittest-data/overlay_pci_node.dtso new file mode 100644 index 000000000000..c05e52e9e44a --- /dev/null +++ b/drivers/of/unittest-data/overlay_pci_node.dtso @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/ { + fragment@0 { + target-path=""; + __overlay__ { + #address-cells = <3>; + #size-cells = <2>; + pci-ep-bus@0 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x0 0x0 0x0 0x1000>; + reg = <0 0 0 0 0>; + unittest-pci@100 { + compatible = "unittest-pci"; + reg = <0x100 0x200>; + }; + }; + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7bff6c4cb653..f9895ea832f3 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -3324,6 +3325,7 @@ OVERLAY_INFO_EXTERN(overlay_gpio_02b); OVERLAY_INFO_EXTERN(overlay_gpio_03); OVERLAY_INFO_EXTERN(overlay_gpio_04a); OVERLAY_INFO_EXTERN(overlay_gpio_04b); +OVERLAY_INFO_EXTERN(overlay_pci_node); OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node); OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop); OVERLAY_INFO_EXTERN(overlay_bad_phandle); @@ -3359,6 +3361,7 @@ static struct overlay_info overlays[] = { OVERLAY_INFO(overlay_gpio_03, 0), OVERLAY_INFO(overlay_gpio_04a, 0), OVERLAY_INFO(overlay_gpio_04b, 0), + OVERLAY_INFO(overlay_pci_node, 0), OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL), OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL), OVERLAY_INFO(overlay_bad_phandle, -EINVAL), @@ -3729,6 +3732,191 @@ static inline __init void of_unittest_overlay_high_level(void) {} #endif +#ifdef CONFIG_PCI_DYNAMIC_OF_NODES + +int of_unittest_pci_dev_num; +int of_unittest_pci_child_num; + +/* + * PCI device tree node test driver + */ +static const struct pci_device_id testdrv_pci_ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, 0x5), }, /* PCI_VENDOR_ID_REDHAT */ + { 0, } +}; + +static int testdrv_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct overlay_info *info; + struct device_node *dn; + int ret, ovcs_id; + u32 size; + + dn = pdev->dev.of_node; + if (!dn) { + dev_err(&pdev->dev, "does not find bus endpoint"); + return -EINVAL; + } + + for (info = overlays; info && info->name; info++) { + if (!strcmp(info->name, "overlay_pci_node")) + break; + } + if (!info || !info->name) { + dev_err(&pdev->dev, "no overlay data for overlay_pci_node"); + return -ENODEV; + } + + size = info->dtbo_end - info->dtbo_begin; + ret = of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn); + of_node_put(dn); + if (ret) + return ret; + + of_platform_default_populate(dn, NULL, &pdev->dev); + pci_set_drvdata(pdev, (void *)(uintptr_t)ovcs_id); + + return 0; +} + +static void testdrv_remove(struct pci_dev *pdev) +{ + int ovcs_id = (int)(uintptr_t)pci_get_drvdata(pdev); + + of_platform_depopulate(&pdev->dev); + of_overlay_remove(&ovcs_id); +} + +static struct pci_driver testdrv_driver = { + .name = "pci_dt_testdrv", + .id_table = testdrv_pci_ids, + .probe = testdrv_probe, + .remove = testdrv_remove, +}; + +static int unittest_pci_probe(struct platform_device *pdev) +{ + struct resource *res; + struct device *dev; + u64 exp_addr; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + dev = &pdev->dev; + while (dev && !dev_is_pci(dev)) + dev = dev->parent; + if (!dev) { + pr_err("unable to find parent device\n"); + return -ENODEV; + } + + exp_addr = pci_resource_start(to_pci_dev(dev), 0) + 0x100; + unittest(res->start == exp_addr, "Incorrect translated address %llx, expected %llx\n", + (u64)res->start, exp_addr); + + of_unittest_pci_child_num++; + + return 0; +} + +static const struct of_device_id unittest_pci_of_match[] = { + { .compatible = "unittest-pci" }, + { } +}; + +static struct platform_driver unittest_pci_driver = { + .probe = unittest_pci_probe, + .driver = { + .name = "unittest-pci", + .of_match_table = unittest_pci_of_match, + }, +}; + +static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add) +{ + struct device_node *pnp, *np = NULL; + struct device *child_dev; + char *path = NULL; + const __be32 *reg; + int rc = 0; + + pnp = pdev->dev.of_node; + unittest(pnp, "Failed creating PCI dt node\n"); + if (!pnp) + return -ENODEV; + + if (add) { + path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp); + np = of_find_node_by_path(path); + unittest(np, "Failed to get unittest-pci node under PCI node\n"); + if (!np) { + rc = -ENODEV; + goto failed; + } + + reg = of_get_property(np, "reg", NULL); + unittest(reg, "Failed to get reg property\n"); + if (!reg) + rc = -ENODEV; + } else { + path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp); + np = of_find_node_by_path(path); + unittest(!np, "Child device tree node is not removed\n"); + child_dev = device_find_any_child(&pdev->dev); + unittest(!child_dev, "Child device is not removed\n"); + } + +failed: + kfree(path); + if (np) + of_node_put(np); + + return rc; +} + +static void __init of_unittest_pci_node(void) +{ + struct pci_dev *pdev = NULL; + int rc; + + rc = pci_register_driver(&testdrv_driver); + unittest(!rc, "Failed to register pci test driver; rc = %d\n", rc); + if (rc) + return; + + rc = platform_driver_register(&unittest_pci_driver); + if (unittest(!rc, "Failed to register unittest pci driver\n")) { + pci_unregister_driver(&testdrv_driver); + return; + } + + while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) { + of_unittest_pci_node_verify(pdev, true); + of_unittest_pci_dev_num++; + } + if (pdev) + pci_dev_put(pdev); + + unittest(of_unittest_pci_dev_num, + "No test PCI device been found. Please run QEMU with '-device pci-testdev'\n"); + unittest(of_unittest_pci_dev_num == of_unittest_pci_child_num, + "Child device number %d is not expected %d", of_unittest_pci_child_num, + of_unittest_pci_dev_num); + + platform_driver_unregister(&unittest_pci_driver); + pci_unregister_driver(&testdrv_driver); + + while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) + of_unittest_pci_node_verify(pdev, false); + if (pdev) + pci_dev_put(pdev); +} +#else +static void __init of_unittest_pci_node(void) { } +#endif + static int __init of_unittest(void) { struct device_node *np; @@ -3779,6 +3967,7 @@ static int __init of_unittest(void) of_unittest_platform_populate(); of_unittest_overlay(); of_unittest_lifecycle(); + of_unittest_pci_node(); /* Double check linkage after removing testcase data */ of_unittest_check_tree_linkage(); diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 6c0e7b6bbdd1..a8223ff52939 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6149,3 +6149,4 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); */ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node); DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node); +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node);