From patchwork Fri Jan 20 03:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 46111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp671904wrn; Thu, 19 Jan 2023 19:08:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDJmhqSofeA/H/vwMmF50weVqYajqG6Bs7mWLkCKnOJiAXI3/dFECHRHEFsYF1XH6EYGip X-Received: by 2002:a17:906:25d8:b0:877:6e2a:a120 with SMTP id n24-20020a17090625d800b008776e2aa120mr6290400ejb.32.1674184099068; Thu, 19 Jan 2023 19:08:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674184099; cv=pass; d=google.com; s=arc-20160816; b=FArzsmvIHh9itc0NS5DVWGP0+2mEHOQsSKnu5QkRxR/ASRSWfhMF7G8J+eIcOY/Fns axXLAHutfj2/7y/Ezk8RXGhkDRc7nDLQYPcUbWiHMI6RLXesZlqDF93OTWCwi/JY1/Zf bVeb1+cMKlROQBxXf/9aSKDwbuReTQ9PZVk60tVLp9CIAj91EZz9NoQ1n5t3TE8wfI/P 9wHD/uCEdot7TPIQdPp5vhQVNKPzjSblKQOKZVi/51lyfrW6pV2vMvxqcp6/CaG2JjcD wgTndnPxT24vrESb/+PYLsOjPlysEES1mVlS1WzvIZtCArdinVtDvxsziXQ3hHUl+SBi /17w== 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=JdlI4F5W5ZYE3228KtQJtCpbKkAXKajzwOx3KdJ2j5Q=; b=XJkqWWXned/8TwNA1n49U4nPZ4tAYeP2v0gxU25TFx/Q1LVQTHBYCSRp62qd1uooVo 5PbMCNvwbzynn8/dRb8No9l6Pxvs8tGJ/6Gtx0hqYss4loRc1tYdHNUBVD51oI5PZz02 KajSvV98iH+pdJoA53lSnBJKVMTk0CUkRQTmRNOiC8Ug619Ute0cwwEprUDvGvglZADS tacdOUIeWqmzFIwIy7MIWBQ0ZgM858K97UuDSsESaxKAAcprSHHdVS/XFDoj0sAUkY0S DlX5BScjmqygJ0sc20vNgk354AnjD1Z+0FjSH46QCvwwzvJg5+P7+ygWTXSvmMODzUQw JNPA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NhM7CUXt; 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 hr26-20020a1709073f9a00b0086bfaaa9edesi20172550ejc.807.2023.01.19.19.07.31; Thu, 19 Jan 2023 19:08:19 -0800 (PST) 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=NhM7CUXt; 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 S229650AbjATDCm (ORCPT + 99 others); Thu, 19 Jan 2023 22:02:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjATDCk (ORCPT ); Thu, 19 Jan 2023 22:02:40 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2078.outbound.protection.outlook.com [40.107.220.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0D9C1CACE; Thu, 19 Jan 2023 19:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LeIhDIf8hwLU3TgVog9hXJIogC/Rmcte7aliFccm/n0RlE3A7dCZ5vtGPcbUPvoR2qt+Ns1eHPSa3+jcjkCwT0xflGwSA7AsJ6bYn1YNN51KA5AT7MyW7pOeTYBwwK99NPigu4WmyKqHTY7LvFtbLIdskyXjINsZF6fyWa83YkReJ5FRREm6ixSJLmhCP9Z9t5DGSZ8Uwl7p5daghPeqjE04Byje/7MtMX2Sy6qkjX7cSKSj8KlaWs2Ne6DUbeVbiaDOYeE39uNN8kK9xtuLt0cWWIe8CGRdLIYYAQaNY9QEtTl4L/XNdWfmv/JPSxfYd14WqMe1xv9Vn+lE1Ccr+w== 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=JdlI4F5W5ZYE3228KtQJtCpbKkAXKajzwOx3KdJ2j5Q=; b=i0xpfqUDvtBy98oZlLG2q9IwqyJmJmjj54SHfmB0ziYHPPPckSL3F5hTzu0jk4TnBSjCvuoVFL8qHlLhAsJQC/wSiqmawj3D4+gbLkG/FujG4njh2Crx7WoSjETtQQs7gmiJA81Rmw4S+z4I037nmurVS2rVbx9ituHddoj+F8MxLqbs/Xz/t9k6tJJrKcYOpfS+BH8g13HU9tKEZ7uX2ZDf9PFT7N+ui+QSwtFHhDqExOS5zEH1bbYtu2Ydi/0rMJrp9R4TQxMYLgXfFe/Puk2c2w5uOA2Kti0dbU/9XIZ2o8tSyXrG9I0g3e8+fLPcHXqAHv2xJZL1zHRXl/eKpw== 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=JdlI4F5W5ZYE3228KtQJtCpbKkAXKajzwOx3KdJ2j5Q=; b=NhM7CUXtSghnkvE+5ccqPQ+GJflDc4lR19en7BuQI806ZHJt1SazZ5As82vVoM2QJ4D2+RhNEO4JwRk8Lznhy+UUD2PwEZK3ZV2c8qFzRdIsvsP969JoAmGe4f8e3OhLtFVZjdwaKTnd/DbqIyM9xqtsVREfErx0P98qRafoJW4= Received: from DS7PR03CA0350.namprd03.prod.outlook.com (2603:10b6:8:55::27) by BN9PR12MB5355.namprd12.prod.outlook.com (2603:10b6:408:104::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26; Fri, 20 Jan 2023 03:02:35 +0000 Received: from DM6NAM11FT087.eop-nam11.prod.protection.outlook.com (2603:10b6:8:55:cafe::5f) by DS7PR03CA0350.outlook.office365.com (2603:10b6:8:55::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26 via Frontend Transport; Fri, 20 Jan 2023 03:02:35 +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 DM6NAM11FT087.mail.protection.outlook.com (10.13.172.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6023.16 via Frontend Transport; Fri, 20 Jan 2023 03:02:35 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.2375.34; Thu, 19 Jan 2023 21:02:35 -0600 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 19 Jan 2023 21:02:34 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [PATCH V7 1/3] of: dynamic: Add interfaces for creating device node dynamically Date: Thu, 19 Jan 2023 19:02:10 -0800 Message-ID: <1674183732-5157-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> References: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT087:EE_|BN9PR12MB5355:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e80d986-4537-4a95-89ed-08dafa92c841 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hnHlHIG2XzM5kNiSba3D1jynMVnOlvQ+i992jvqeQHmYAQa7iAf4nxEb8lCB7NRq6b2UObaCmnSUrrr8sOgv2KS5pmA/NP/YQpHwepRhu5dmBMW8jHg/4qGOmJXF14x95/i34fdAMG16FAQO1wzvL9dFr08ZK5Zqrs/jJm3VwDR/UHhYQ6qna4BAUD3e/qs7NePdNOkAhj8Y3v+F087980qE9BQEDbGOZrvvGiLwv/2r56C7x3qRYmInl0onuxmBZSOFDsw/v8FmekXZzJH15yK9TgEzKDABTbuqGLMjvHNdDv4vVAd6wFG05ZdX+gOWG8A3+D1Pjr9ov5UfxpteWJFGl62EaEqQgAa36PjTD2H7FLvc5vwIZCaVitdfYJFni+p+l01G49ZPTuO0a0RhzrrjvqBYcEUozU7MPXhYogUeskbBJAiY2zEZZ9gXTG0rgbKjrE48jbCP/5XtssxgU7OyamBCtiLNrijjz4ggivFpjfsgGL297ZAPgd2SPoSoQPRVR4OsWgi0aJUiqMA7NhZKXLSI/nHLh/5Y6spnVqc2Yec3yyTvxdXBIvzCLoN+7ehKMQOhsbO+WhBrBx4vapwjWI0f5tWxtXGMoifbczmC4/ot/lHHFMIzDTprNaJhcyBgFJdlh3uFlletEZXiOzPKVDH3PrpkedDh7TR5PVCe+zgqI4Oi59CZaNQhjowkC+q7gBwZR2G5kO9iNXOC3r8TPhcQq9ioD66tesD5x/Q= 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:(13230022)(4636009)(376002)(396003)(346002)(136003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(8936002)(5660300002)(86362001)(40460700003)(316002)(36756003)(6666004)(478600001)(2906002)(66574015)(2616005)(82310400005)(426003)(110136005)(47076005)(336012)(44832011)(70206006)(54906003)(83380400001)(81166007)(70586007)(186003)(4326008)(82740400003)(8676002)(40480700001)(26005)(356005)(36860700001)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2023 03:02:35.7472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e80d986-4537-4a95-89ed-08dafa92c841 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: DM6NAM11FT087.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5355 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755509265761594962?= X-GMAIL-MSGID: =?utf-8?q?1755509265761594962?= of_create_node() creates device node dynamically. The parent device node and full name are required for creating the node. It optionally creates an OF changeset and attaches the newly created node to the changeset. The device node pointer and the changeset pointer can be used to add properties to the device node and apply the node to the base tree. of_destroy_node() frees the device node created by of_create_node(). If an OF changeset was also created for this node, it will destroy the changeset before freeing the device node. 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: Lizhi Hou Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Reviewed-by: Brian Xu Signed-off-by: Clément Léger --- drivers/of/dynamic.c | 197 +++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 24 ++++++ 2 files changed, 221 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index cd3821a6444f..4e211a1d039f 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -461,6 +461,71 @@ struct device_node *__of_node_dup(const struct device_node *np, return NULL; } +/** + * of_create_node - Dynamically create a device node + * + * @parent: Pointer to parent device node + * @full_name: Node full name + * @cset: Pointer to returning changeset + * + * Return: Pointer to the created device node or NULL in case of an error. + */ +struct device_node *of_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset **cset) +{ + struct of_changeset *ocs; + struct device_node *np; + int ret; + + np = __of_node_dup(NULL, full_name); + if (!np) + return NULL; + np->parent = parent; + + if (!cset) + return np; + + ocs = kmalloc(sizeof(*ocs), GFP_KERNEL); + if (!ocs) { + of_node_put(np); + return NULL; + } + + of_changeset_init(ocs); + ret = of_changeset_attach_node(ocs, np); + if (ret) { + of_changeset_destroy(ocs); + of_node_put(np); + kfree(ocs); + return NULL; + } + + np->data = ocs; + *cset = ocs; + + return np; +} +EXPORT_SYMBOL(of_create_node); + +/** + * of_destroy_node - Destroy a dynamically created device node + * + * @np: Pointer to dynamically created device node + * + */ +void of_destroy_node(struct device_node *np) +{ + struct of_changeset *ocs; + + if (np->data) { + ocs = (struct of_changeset *)np->data; + of_changeset_destroy(ocs); + } + of_node_put(np); +} +EXPORT_SYMBOL(of_destroy_node); + static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) { if (ce->action == OF_RECONFIG_ATTACH_NODE && @@ -934,3 +999,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/include/linux/of.h b/include/linux/of.h index 8b9f94386dc3..ebd276d4c4aa 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1505,6 +1505,30 @@ 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_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset **cset); +void of_destroy_node(struct device_node *np); +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 Jan 20 03:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 46110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp670931wrn; Thu, 19 Jan 2023 19:05:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFyrRCaEKBz9PPHEfadFaAm3fzxc5+DSDdcaW9y94vrnTgK+Krp9V9ilWC9bcrntYnNiQH X-Received: by 2002:aa7:cac2:0:b0:497:948b:e8 with SMTP id l2-20020aa7cac2000000b00497948b00e8mr11840642edt.6.1674183941522; Thu, 19 Jan 2023 19:05:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674183941; cv=pass; d=google.com; s=arc-20160816; b=jZtJVtMzQCMTuQo1Bni+eowfelgnKFq0Ye/QuvWzq9eL5W9sWhk57dtKMQ/dSPDG36 tXHRTlGWjO3RADLQaH1Bkwzg0wC7vlXmUJNEX13ucXKt6J2LaSXv0IdZB6PrOIgPuOXE P7aPxco/VWrWk6gbeoKtD1P0WwGo01k1CzU1onjZ1nW1k+WUQqc5Fy4wpLhYzBZYAO9W BIePE++GwkEFbDOOX46t9Sz9Py0vCPbILJdrMv3SzDrQIAIyt+CSieZal7MVFKtATJ6q p3VokUckOkPfGrvlLOUfJ07Iq7srSJlPGrZ0hNQq48gYwrEU1g8VcvBKtlhOhUoLGGul LVDQ== 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=1m7eBRji2yIjZXfssLv7TINtUoj98OWtk8Z1z0OFpMY=; b=L3pn6/d8+aOakr6ThDLn6hlxw20gTbTqgkZqe2bVtyE4vNtP58hTti3IiOmjKCKU7M PiTXMoRijBoySS/PW0wVVFa2Dol3EUQKvz75eom0BuEduSHHwvcEIG42ZzSYzm3xZ5+0 6bZj4s8hTOTeEPPZEuDQJ7SCeHEVk1qNkfAslD8eVflY+u+0WYcLOAhNTlgprzADQlhY Lzo9sHUFrnfSImWNGFh1qUd5i+JtwSn+48WRAU4Y9AGVcE4wWjpTkavlgHtxrmISY6Z4 PcvpCdokdf1qdG1o8x2VInAvIeHCltZgVWI2IIxMAEc+7o396ngba/D7o/SIJlqkfRO8 CNww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="q3N/2KSa"; 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 g34-20020a056402322200b0049dec5403f2si20550869eda.116.2023.01.19.19.05.18; Thu, 19 Jan 2023 19:05:41 -0800 (PST) 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="q3N/2KSa"; 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 S229769AbjATDDg (ORCPT + 99 others); Thu, 19 Jan 2023 22:03:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbjATDDX (ORCPT ); Thu, 19 Jan 2023 22:03:23 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2051.outbound.protection.outlook.com [40.107.223.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B5953561; Thu, 19 Jan 2023 19:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ERG2sEOK1SGHV5hINYPdlaLoE9NJzq4nV/gmkhGDnsR6LWr18SO4Q3018j0e/+K03Z56oySPk6DTgea8LF5psbsY7PyO09PZbedevg8iAb62cv+LgPV6UqfdcNfMYVekxjRpPEcuk6JHs5QJFIusnUa2j3nQv5+UOYgv1vs/c1DDe73oHMnvkC4m7qa93wah1w0d7M8B7rTNthyyLi/0sf6I3rmniHU7qlGbGPFPI4U/eSqHQwzoyUiBPV8ULNN9VV2doxfUnc4YucclRn1MLftvEJymV41+cy2o781gqnVniN9kcMxZRqt5TOQJ7oOvuHmpLEnlkL4RrP4l/nWFAQ== 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=1m7eBRji2yIjZXfssLv7TINtUoj98OWtk8Z1z0OFpMY=; b=DzrepRcrIPc0BGrI0eUoRRGfJQ/XbcfjhdosiRIrYq5b5sA+7AssagkRGUAc64BRqbjCGghKpMcoz1gzRGQ/Vs7WwZGa7zdYBvQ/YzS8g5zqKoHodcd+o8HSFZotEqlJ0kj851ZXuWcjFY0uALAvOzyjVeEPjcSjaOatFwoDs3DRzjy2rRFcgdnVdoalVfGHx35eow9YdHDQM+dumTFSiqBaqBtPXHQRVvDp3vTxZN8C71qS7o0mxEvGmA8uLLHh68okMV9a8a13cXiDHqfD+7ZNMm17cXnH0c1ErWX0aTiHRN+8D44lhP4I2dlUgxfPPoOwN1efx5lLKahquoeJbw== 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=1m7eBRji2yIjZXfssLv7TINtUoj98OWtk8Z1z0OFpMY=; b=q3N/2KSa0rmGkyKA72cCVEZXhvQ8C32Z6RuQ6MOfteqKwLKdtEhIDq7t9C/mJPaPkEdlusOJSO4hmPbXQSK+YSreJW1wEkoM6WGeJVujDh3DNsHCKfM7DnFK8OIwkqD74XOx0h7TAHfvjqBMKfZgWi4GQU359S1+klpVUQaz/3I= Received: from DM6PR11CA0061.namprd11.prod.outlook.com (2603:10b6:5:14c::38) by DM6PR12MB4385.namprd12.prod.outlook.com (2603:10b6:5:2a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26; Fri, 20 Jan 2023 03:03:05 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:14c:cafe::e7) by DM6PR11CA0061.outlook.office365.com (2603:10b6:5:14c::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26 via Frontend Transport; Fri, 20 Jan 2023 03:03: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 DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6023.16 via Frontend Transport; Fri, 20 Jan 2023 03:03:04 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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.2375.34; Thu, 19 Jan 2023 21:02:55 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 19 Jan 2023 19:02:36 -0800 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 19 Jan 2023 21:02:35 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [PATCH V7 2/3] PCI: Create device tree node for selected devices Date: Thu, 19 Jan 2023 19:02:11 -0800 Message-ID: <1674183732-5157-3-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> References: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT068:EE_|DM6PR12MB4385:EE_ X-MS-Office365-Filtering-Correlation-Id: d9db0038-7c8e-4861-5bd7-08dafa92d9af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DqDlArq9PPTHvjkTvnVSZbtfQTJFKY0gOKTDFNS1QJWYyUzhARPYF7bjQvIDmrtUGXRrdeg+TBlICdv5A9PRflC5KCKG/l4qSHW1iPwdE5L5J9vt9nFJ4xawoh8S8ez1kk9bOSv52mfUjQaVBWsadRvBXYC0hl6twabeK18ae/c5Y/E6DAudsyFSv3J2dm63ogMajKcUl0x0Uuve2LVaQalqHCbpvqkONYFrfRA3zZsitIpZ5wYBq9eKBu736uftyXDZOicqt7ZZ+ROuqfCDK+wPZBnHfgviII16jONpHjYeQ1ekaNozbWWY3rXYnkMHpys0Z7DQhM1nWclZbuOhRknL6OpKROh+lPxpQIO1xKAEGaMVPf+fcDJQyuImMDc4VqU/UvIeEqhriZNmjdgCNSnhTbA9ijtNfX7HvdrWb1+99tP0bHYYIJhHImKIjbCQbBawEtVeY/Qb1mRAtabcBgOmflRfHmf02rnC3eERIEoM4fZ5tNRGV78byBbw5iUJoQjxsU0tFcVxI9f+/P7BsJZD7d2G16aFnH291jizMnzELYBktfy6XAyxhGtykST6Mn5/EowJHUo6ZoUPHbM/FdOrO/iJLIPz9NeZWMAJm24c7QNU/rO1E0+wGRdoLM5VRXJvi0M8vdvrfdQ4b/h4gDFLi0u9KvRo5IT5u0TmdL0HEmGmJUYdHx9TR9Q4A1xMv0Q6Q7JgNfSow9PUD8Jt/Z5RW+i15WBp6uHOvrT/OOs= 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:(13230022)(4636009)(346002)(376002)(396003)(136003)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(81166007)(478600001)(356005)(6666004)(82740400003)(186003)(26005)(86362001)(82310400005)(41300700001)(36860700001)(2906002)(83380400001)(2616005)(44832011)(8936002)(30864003)(54906003)(110136005)(316002)(5660300002)(426003)(4326008)(66574015)(70206006)(70586007)(8676002)(336012)(47076005)(40480700001)(40460700003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2023 03:03:04.9882 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9db0038-7c8e-4861-5bd7-08dafa92d9af 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4385 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755509100715337532?= X-GMAIL-MSGID: =?utf-8?q?1755509100715337532?= 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. For Alveo PCI card, the card firmware provides a flattened device tree to describe the hardware peripherals on its BARs. The Alveo card driver can load this flattened device tree and leverage device tree framework to generate platform devices for the hardware peripherals eventually. 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. This patch is to add support to generate device tree node for PCI devices. Added a kernel option. When the option is turned on, the kernel will generate device tree nodes for PCI bridges unconditionally. Initially, the basic properties are added for the dynamically generated device tree nodes. Signed-off-by: Lizhi Hou Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Reviewed-by: Brian Xu Signed-off-by: Clément Léger --- drivers/pci/Kconfig | 12 ++ drivers/pci/Makefile | 1 + drivers/pci/bus.c | 2 + drivers/pci/msi/irqdomain.c | 6 +- drivers/pci/of.c | 71 ++++++++++++ drivers/pci/of_property.c | 212 ++++++++++++++++++++++++++++++++++++ drivers/pci/pci-driver.c | 3 +- drivers/pci/pci.h | 19 ++++ drivers/pci/remove.c | 1 + 9 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 drivers/pci/of_property.c diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 9309f2469b41..24c3107c68cc 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -193,6 +193,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 Devicetree 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 83ae838ceb5f..e913c7fe8630 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -320,6 +320,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/msi/irqdomain.c b/drivers/pci/msi/irqdomain.c index e33bcc872699..cd73d2250305 100644 --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -456,8 +456,10 @@ u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev) pci_for_each_dma_alias(pdev, get_msi_id_cb, &rid); of_node = irq_domain_get_of_node(domain); - rid = of_node ? of_msi_map_id(&pdev->dev, of_node, rid) : - iort_msi_map_id(&pdev->dev, rid); + if (of_node && !of_node_check_flag(of_node, OF_DYNAMIC)) + rid = of_msi_map_id(&pdev->dev, of_node, rid); + else + rid = iort_msi_map_id(&pdev->dev, rid); return rid; } diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 196834ed44fe..cb34a73ac8a3 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -469,6 +469,8 @@ static int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args * } else { /* We found a P2P bridge, check if it has a node */ ppnode = pci_device_to_OF_node(ppdev); + if (ppnode && of_node_check_flag(ppnode, OF_DYNAMIC)) + ppnode = NULL; } /* @@ -599,6 +601,75 @@ int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) return pci_parse_request_of_pci_ranges(dev, bridge); } +#if IS_ENABLED(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_destroy_node(np); +} + +void of_pci_make_dev_node(struct pci_dev *pdev) +{ + struct device_node *ppnode, *np = NULL; + const char *pci_type = "dev"; + 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"; + + name = kasprintf(GFP_KERNEL, "%s@%x,%x", pci_type, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + if (!name) + goto failed; + + np = of_create_node(ppnode, name, &cset); + if (!np) + goto failed; + + 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_destroy_node(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..3d8267aa96e2 --- /dev/null +++ b/drivers/pci/of_property.c @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022, Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include "pci.h" + +#define OF_PCI_ADDRESS_CELLS 3 +#define OF_PCI_SIZE_CELLS 2 + +struct of_pci_addr_pair { + u32 phys_addr[OF_PCI_ADDRESS_CELLS]; + u32 size[OF_PCI_SIZE_CELLS]; +}; + +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) + +#define OF_PCI_ADDR_HI GENMASK_ULL(63, 32) +#define OF_PCI_ADDR_LO GENMASK_ULL(31, 0) +#define OF_PCI_SIZE_HI GENMASK_ULL(63, 32) +#define OF_PCI_SIZE_LO GENMASK_ULL(31, 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] = FIELD_GET(OF_PCI_ADDR_HI, addr); + prop[2] = FIELD_GET(OF_PCI_ADDR_LO, 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_ranges(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_pci_range *rp; + struct resource *res; + int i = 0, j, ret; + u64 val64; + u32 flags; + + rp = kcalloc(PCI_BRIDGE_RESOURCE_NUM, sizeof(*rp), GFP_KERNEL); + if (!rp) + return -ENOMEM; + + res = &pdev->resource[PCI_BRIDGE_RESOURCES]; + for (j = 0; j < PCI_BRIDGE_RESOURCE_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); + memcpy(rp[i].child_addr, rp[i].parent_addr, + sizeof(rp[i].child_addr)); + + val64 = resource_size(&res[j]); + rp[i].size[0] = FIELD_GET(OF_PCI_SIZE_HI, val64); + rp[i].size[1] = FIELD_GET(OF_PCI_SIZE_LO, 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; + int i = 1, resno, ret = 0; + u32 flags, base_addr; + resource_size_t sz; + + reg = kcalloc(PCI_STD_NUM_BARS + 1, sizeof(*reg), GFP_KERNEL); + if (!reg) + return -ENOMEM; + + /* configuration space */ + of_pci_set_address(pdev, reg[0].phys_addr, 0, 0, 0, true); + + base_addr = PCI_BASE_ADDRESS_0; + for (resno = PCI_STD_RESOURCES; resno <= PCI_STD_RESOURCE_END; + resno++, base_addr += 4) { + sz = pci_resource_len(pdev, resno); + if (!sz) + continue; + + ret = of_pci_get_addr_flags(&pdev->resource[resno], &flags); + if (ret) + continue; + + of_pci_set_address(pdev, reg[i].phys_addr, 0, base_addr, flags, + true); + reg[i].size[0] = FIELD_GET(OF_PCI_SIZE_HI, (u64)sz); + reg[i].size[1] = FIELD_GET(OF_PCI_SIZE_LO, (u64)sz); + i++; + } + + ret = of_changeset_add_prop_u32_array(ocs, np, "reg", (u32 *)reg, + i * sizeof(*reg) / sizeof(u32)); + kfree(reg); + + 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 = 0; + + if (pci_is_bridge(pdev)) { + ret |= of_changeset_add_prop_string(ocs, np, "device_type", + "pci"); + ret |= of_changeset_add_prop_u32(ocs, np, "#address-cells", + OF_PCI_ADDRESS_CELLS); + ret |= of_changeset_add_prop_u32(ocs, np, "#size-cells", + OF_PCI_SIZE_CELLS); + ret |= of_pci_prop_ranges(pdev, ocs, np); + } + + ret |= of_pci_prop_reg(pdev, ocs, np); + ret |= of_pci_prop_compatible(pdev, ocs, np); + + /* + * The added properties will be released when the + * changeset is destroyed. + */ + return ret; +} diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index a2ceeacc33eb..995c32728231 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -1634,7 +1634,8 @@ static int pci_dma_configure(struct device *dev) bridge = pci_get_host_bridge_device(to_pci_dev(dev)); if (IS_ENABLED(CONFIG_OF) && bridge->parent && - bridge->parent->of_node) { + bridge->parent->of_node && + !of_node_check_flag(bridge->parent->of_node, OF_DYNAMIC)) { ret = of_dma_configure(dev, bridge->parent->of_node, true); } else if (has_acpi_companion(bridge)) { struct acpi_device *adev = to_acpi_device_node(bridge->fwnode); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9ed3b5550043..ef092af6717d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -681,6 +681,25 @@ 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 /* CONFIG_PCI_DYNAMIC_OF_NODES */ + #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 0145aef1b930..1462f2d9b194 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -23,6 +23,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 Jan 20 03:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 46112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp671931wrn; Thu, 19 Jan 2023 19:08:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQNKR09edXtTyB+zBtl19C2DIuYYImAUeYDa4ZK2F4mlSf7r+xF9Yr9KlFyYk1G+RUMKoN X-Received: by 2002:a17:906:758:b0:84d:12d8:e1e9 with SMTP id z24-20020a170906075800b0084d12d8e1e9mr12610455ejb.41.1674184103360; Thu, 19 Jan 2023 19:08:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674184103; cv=pass; d=google.com; s=arc-20160816; b=nZ3OxF9pLi5NnYrgzIjiOoCIgWPaI/kXZ1SYh6S6akC2fvqNiWnn4Xfq9B1FkCgwUi 10R0mFBZxEv+6faik3yn3HjEsLKJhCmwzkrGe6DcKrzLyAa6oebwXns2OXw1GRu6d3+2 CEgfiPjNIEYqmA6nfSiJUzxVjH1ZKqzavgWHd6kjT1SNnW7Uibni02Le1kYI/2LA9Jmj bVoaCj6lNl+qUFbRkt84ZwGavdyKdmjOF9+PpQjrmt/FnSO4AQujhp15XmY8aHNCKwlS uWB6AadoY+Fyan4qb4unJebfUlb1KS5N+CvT2YZgKZARbz2b73gpM5TcTS4Tz0J9mloi kmEw== 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=NqMruNlZ0Y2993+SE7bM+U6sHCgD2F4Ol08U/JVUCi0=; b=h0t2U8wV5if9kyenp/p3xDUxthOl/nja54K7vBnfFe2B7vKZ49dE6dgV+vlu2AI5Ed vGXuqkV4x2S2qPbVgUaGom3LmGioCAiYRp4ShLSi/eX7xyLKEakZBO+Y9X3HPju6s9H8 YTcqzVcllGlQuLTrXBMkZ+gYeQU8ooiMWZHnRFJ5fff4bvAZT3StKkyZ3owxK4ldqxY5 hEiJb6zxmSDa2i2za53L/1Vdq+9i4Xuc3e2LmKSWmI/qC+DhjuVV5lIbvbF9ly8C+oIm /sy+LvOxF2IiAO8f96dW7ASa5+TVSU3AyNuAgFOc2GxHlHh+JOJ/Nutwjr+W8YtK3spD tMKQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="zI/YH6jH"; 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 fd22-20020a1709072a1600b00871160a1e90si10417295ejc.999.2023.01.19.19.07.37; Thu, 19 Jan 2023 19:08:23 -0800 (PST) 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="zI/YH6jH"; 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 S229847AbjATDDd (ORCPT + 99 others); Thu, 19 Jan 2023 22:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbjATDDW (ORCPT ); Thu, 19 Jan 2023 22:03:22 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4571A8A724; Thu, 19 Jan 2023 19:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R8z7N7i0P8GuJoKzcosA3/QA9Na1tkMoVlx+QOBM1uMHxj5V7mXjSE4YCnRsMPTdWIkeuWQNok/x2vyCPY7dWlkDgkzUkmRCLLtTuK5BuGu3cq4WlrQYuFNfSrybZQgbw7wIZ1lrENnp6qYjbRHpYn/MIDvlAOSDg1RClP/GgbTVhO1MAcf9S5f/XrSZXfJfraGsZF8/TU9A2n49Ug99r0IdQjWyfJi2bm6a3RuPZf8Z1JGyCsVK0qAQU3lzwbzh1a+TDd/KhmV8kpajvk9GJ7gf2aTI0HkTWo+rS+aM50PYUQ1N+xCFmuej4dikZHDFxw5FgAELXtyR0vToUnPUiw== 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=NqMruNlZ0Y2993+SE7bM+U6sHCgD2F4Ol08U/JVUCi0=; b=JQ5iratz1tfjnMpOseLjr6Vg8ns5W2JrQMPFAnfeywVgUGsNP9SQ3n7dSt2QJC46w2i8vQBIdf2lO3N7WYHg0O8TqWtPyPCP5CmfmrhPbiOvlAJvkiJD1k63KRHahfKFjTV3LQcCyecKAWWQs2YytKcSRrcdSuJJ//kE6KQNwXKa4gOSJ3QDh0lIGfaQKRvWwR5lShg1mgY1+vj83DPbNy8cZu6ZZ+VVtI6pK47fwxXgtWua6OuytBXSNbD11jBPdfVvP7BV9blm/6q+PmJrhlIxpRkVUdQBw/bttZPvF7aiik9pdYJRHO7XtNgezo0OQA6txa8ERH5XHZa886f7bQ== 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=NqMruNlZ0Y2993+SE7bM+U6sHCgD2F4Ol08U/JVUCi0=; b=zI/YH6jHvQ4kKhrXDt6JBg9r8QnBgz+lo9gV170aGiZqn3WPg56sj9sj8t3RAkxvBZ0edd7OrSN5ood45RgRgV9Reu40d92MOCrNbBshF6HA5J3qfy8FXgVRYvn5RxsrhLK5CoeBhBGbTAReYHGTjw2U7J02/RY5smCDI5G76Qo= Received: from DM6PR11CA0055.namprd11.prod.outlook.com (2603:10b6:5:14c::32) by BL1PR12MB5143.namprd12.prod.outlook.com (2603:10b6:208:31b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Fri, 20 Jan 2023 03:03:06 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:14c:cafe::25) by DM6PR11CA0055.outlook.office365.com (2603:10b6:5:14c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26 via Frontend Transport; Fri, 20 Jan 2023 03:03: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 DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6023.16 via Frontend Transport; Fri, 20 Jan 2023 03:03:06 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2375.34; Thu, 19 Jan 2023 21:02:55 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 19 Jan 2023 21:02:55 -0600 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 19 Jan 2023 21:02:54 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [PATCH V7 3/3] PCI: Add PCI quirks to generate device tree node for Xilinx Alveo U50 Date: Thu, 19 Jan 2023 19:02:12 -0800 Message-ID: <1674183732-5157-4-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> References: <1674183732-5157-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT068:EE_|BL1PR12MB5143:EE_ X-MS-Office365-Filtering-Correlation-Id: 808fefb5-21e9-4fdf-448b-08dafa92da75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rnA0eannw7ZMzo4XIjUWPspkWBxOZL+1vjr0zvhRhuerI1ZnJRLK5+K0nPQdE3jx4ZKbC43MnA2vmbTHd/49n9GEJcC47Xk4exYC0N83wvyPsQcgyJdFTLgPXsuNFdyK7UaQWrcN8KBfZhl118KAxhMXePLs8MaVMN9UFPr7alfKITVZBMSNRUxfeXcKhH15sD8+nv+TThIq6i9vQeIGaQe9gGfczuMxTcLSSY1n+jZG/pKBavCjY0jrF25qFFvv8ZqThXtJHnzHh9yKExkf6oHZllWfos2GnmysUssONCgHt3B/3Ks1euXJFFYIil7ixF+kM5/oJp1ODjImjRjlFquGIWLrfDmSp4EBcSvE6sfKZ8PO50gm4wjQsDAEPDRJaCgU8s/LiuWTCKxArQGQPcG447KCiwV3RtO2Yi++s5slJniAyLFHFjCyfe/UBUIqSH0Eo8wbGarfS2feKyQKPBabeLYcXEFxK77iO00LQgdlTpAHJI20QmuyiW1nG8opLNbmmqiq6Ck96XIjQeDwfmOSlMCvpDpFKBr2Ljmp9oAVKEScaq54iZQbM0Zut3AFg4XgrEjNse04nJ9tCOFoeVT9NAVgugTTHFm+UpNZQ/1lB/WxfAENVvPGZ5fRvztOto8e9tER1v3WFvra3Q20l7BUJYsyscQUuBTRfLHEGTT47Y2/GwgpbGYpxuRVhpVH7F3rxu8svNXy0sb62FPK3q7L2BAG6lqMMrBJ/grjhZw= 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:(13230022)(4636009)(39860400002)(396003)(346002)(136003)(376002)(451199015)(36840700001)(40470700004)(46966006)(81166007)(70206006)(36860700001)(82740400003)(44832011)(356005)(5660300002)(2906002)(70586007)(8936002)(36756003)(8676002)(40480700001)(4326008)(41300700001)(186003)(26005)(2616005)(40460700003)(82310400005)(336012)(54906003)(426003)(110136005)(6666004)(478600001)(47076005)(316002)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2023 03:03:06.2852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 808fefb5-21e9-4fdf-448b-08dafa92da75 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5143 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755509270360069230?= X-GMAIL-MSGID: =?utf-8?q?1755509270360069230?= 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, added PCI quirks to call of_pci_make_dev_node() for U50. Signed-off-by: Lizhi Hou Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Reviewed-by: Brian Xu Signed-off-by: Clément Léger --- drivers/pci/quirks.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 285acc4aaccc..f184cf51b800 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5992,3 +5992,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 PCI device which have 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);