From patchwork Mon Nov 21 16:43:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 23942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1699374wrr; Mon, 21 Nov 2022 08:44:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+znMQ/rdtBte1lNlfv+DdXnZ+cIDQMuyl3uQB8l9/ZTYtwmF6+ld2Z3uU83BhFobM5kGL X-Received: by 2002:a17:907:9856:b0:780:8144:a41f with SMTP id jj22-20020a170907985600b007808144a41fmr16699787ejc.189.1669049070032; Mon, 21 Nov 2022 08:44:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669049070; cv=pass; d=google.com; s=arc-20160816; b=l+fbzCdaxKOnH+7S3XDMITqSWEMDWsCX+n3lrCe7Wf2qMG0k5+cBu0VNJkYgLbtFfF LL0z1wpievGN0k3l8unnbrQSZ6CnLM8vU9I2z5OAOfEIPwDTvlSj5j8j8Y0Fbp5Z+qc3 2YAGkVjEVdeCXnemSjsBs+RLsRrX3rNukMhl90KOqM8WFCiAqJTzra+Z7OQZ7Yd4OWvW zlzkCz/VAL1kLBpQpFMJ0Ko8pYewtAL3U6YE8kvW3r9/0NoDJJo9JgDElT182/+DtTNR faAOL3w3hlwOXKuIw10gWmO1fky8YepHwDUjkU7OpZon84IbX+Vwz0TpRYvuRMtEqXUT V/Jw== 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=v2axPqeESC/l8aE6D21gNNvD9QRikcwKhy3ptffKIg4=; b=n9o5jLHOCV4PzgdAjrVlvRvPoEa8OFwEyjiV3i5op8nc+MLqyrXVfpkwaFfcYVn/Op si9gSm7eF07lNb3LxKn3wN8TZ2fj5fmSlYzKXhOl+yxvvoReaFDFpb6248TBgpMxHbNT Ip2PJNACS+4iUeUXYeNT/SvEWufWso3P9NU+ukq78NFID2DlJ6UJitomLJam2UBEwcNB 7QKxbHUjOu89NPk0io7Yiivjv+TnJOaJkb6aKxebnfs+7NdJrS0+waxggugBuWyE2Yhb /3IbVqUrzf2e9RblTgGr9L9592YGr7TBaO/4WI0Y6LYRGMhYx3ufMoGN59f1EDfApqAf bLRA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=p2RiqX7D; 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 b20-20020aa7df94000000b004697e00bf31si3223260edy.90.2022.11.21.08.44.04; Mon, 21 Nov 2022 08:44:30 -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=p2RiqX7D; 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 S230274AbiKUQnf (ORCPT + 99 others); Mon, 21 Nov 2022 11:43:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbiKUQnZ (ORCPT ); Mon, 21 Nov 2022 11:43:25 -0500 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 05E69BF5B6; Mon, 21 Nov 2022 08:43:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aBK3QMtLO9jOQlpRdspYfpVi6QKBC6QrLKETuGPDGcRHhhLOE6xPUkKC0okcKRhlHrmv/+EzOhdbfVOoJUUnEQoI6L48euNITcI/lwboNwn/NpEr/3mYzf4VKiGRor9Dqm5AOXmzYqv5nAe77fztKNTD0EmkBypEyDOFPO2MxzEcf10f9w+Y+SEaC9wcMIYhWqsr/CNT0r59StpN8tqQyM84v0C9bpgc+r738iTnqbyEOfj+I6XpH8jlu0bppbRTDLOXAg9Yme6qgEQ7FlYVM+85oEfKRi3c+L/InTbm+o27ciAMYICYS2SSsdt9SBezjLAy2wadrAWRT4Y5wJshrQ== 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=v2axPqeESC/l8aE6D21gNNvD9QRikcwKhy3ptffKIg4=; b=lygfDWdcEt4DwqwLz32WKWkOhV9INXE8wd2iSyndlbJkmjHG4P8PUvDZbxiFxv3rO62JvKmMP+EkE8G92HcSrp2QS4pko0ucbaK/TFkA1KgjQk+K5sDIOgJefD0HYzr4hXSgD6AQBCsSmQZs32IxgtYo6gU1cPw7aMRjIq9e5nva82TngdMQX2UfPjIQj7kqGATvcmBDP+r6NdPbupHYNnh2x3y9RUdebobm3IZHUcc3iIFzF8FMRlG2ENHb0uyf5hcnRbeKfJg2slKcdBgQW8Yu8XezYaNk8SXg5WFou6oV9QfVgq44ZHqKUFzuzT2Dd75828Tw5z/L+gjkgckDAQ== 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=v2axPqeESC/l8aE6D21gNNvD9QRikcwKhy3ptffKIg4=; b=p2RiqX7Dnrtqs5loSFomC1IrUHeSaqSQYYvYpaoW0ZuGRx7FVz8+pkE5XaU9YdCD6OoqHQ2GJ7WEOuz7iH2cx++3pwy7Mp7dsy6JYPYFzfmQe2wj6K8K7ni4i2y7V7RiY9VUfygdD6GcUAG8u4Gdv5hvyzAhGaxDoiOe+iLLuPM= Received: from BN8PR07CA0017.namprd07.prod.outlook.com (2603:10b6:408:ac::30) by DM4PR12MB5246.namprd12.prod.outlook.com (2603:10b6:5:399::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Mon, 21 Nov 2022 16:43:15 +0000 Received: from BN8NAM11FT114.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ac:cafe::ef) by BN8PR07CA0017.outlook.office365.com (2603:10b6:408:ac::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15 via Frontend Transport; Mon, 21 Nov 2022 16:43:15 +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 BN8NAM11FT114.mail.protection.outlook.com (10.13.177.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5834.8 via Frontend Transport; Mon, 21 Nov 2022 16:43:15 +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; Mon, 21 Nov 2022 10:43:14 -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; Mon, 21 Nov 2022 10:43:13 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [RESEND PATCH RFC V4 1/3] of: dynamic: Add interfaces for creating device node dynamically Date: Mon, 21 Nov 2022 08:43:02 -0800 Message-ID: <1669048984-56394-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> References: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT114:EE_|DM4PR12MB5246:EE_ X-MS-Office365-Filtering-Correlation-Id: 43aed840-f991-415f-16ca-08dacbdf7c98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sJOEplWJtwhDVGlD5zDFRCdjwfZLXIZCBN6QWunttPQ0/eX2CZXYdC/tRL4Ovse+bhjiV8Cg+l/EaAxhXvWYcxMGDi5a0G2TqmIF/w4uI3FOwBzfYS5i2tkX+lsfEnYKSsxeTReB79mbXjvEn4yCc99Exdg81QUsmbHCox6285Kn/SI/uSyYfyc5mA/MPsOIC4A46LhG2Oj2ZCuoP3dKOuNjO6OgJy49yi++GY+dr4i1Qk9gobxLrhhosm7v38Z2UdAkGz+AlXKL9qX7Y95y6Nx+o02Judz1sRMG2At99T5Dqd4zTCOwFPqLvfhWl+6rFUIZgEtcxDFWm5MdFC7LOYksltIULnFzNu5yib/26FWZAGCAogXtp/8J6MulJ6ewG+bGrt7GeidUjLadQO050fbGjdcLjGASUlf2q1M68PuL6UrvucukK/vZCAxdc3cFok0JXJ/S36+M4gxMWs1s/OWw5+zLUIDM/1GSDpzonBTmMsH4aiJdSjzkyrlpRwjtfsrOXmV29Fzw3c6qScrTWCGCR69+5aOuAKtrScZsD3ENSV5hxfj8r+K9vu4SoYCZswCrOkHEsENYnHLhCzLFmuEpo8a529ya0H+HPuu6xR31j/EDwO0egAK8mln6WT87PsWERGoSaSIMXrqNS+fSwafwwxLRJQHqHuYhnVkqUcTL+EsdEBBV3H0jNwA67wKlonKUhBgHNPibfB8yHWdAPLmOEk5VIxk/DJ3bUHVCoqs= 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)(39860400002)(136003)(451199015)(40470700004)(36840700001)(46966006)(86362001)(36756003)(82310400005)(4326008)(70586007)(40460700003)(40480700001)(41300700001)(70206006)(2616005)(426003)(47076005)(186003)(5660300002)(8676002)(8936002)(336012)(6666004)(478600001)(26005)(316002)(44832011)(110136005)(82740400003)(54906003)(81166007)(356005)(83380400001)(36860700001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 16:43:15.4365 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43aed840-f991-415f-16ca-08dacbdf7c98 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: BN8NAM11FT114.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5246 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?1750124797388222743?= X-GMAIL-MSGID: =?utf-8?q?1750124797388222743?= 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 --- drivers/of/dynamic.c | 187 +++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 24 ++++++ 2 files changed, 211 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index cd3821a6444f..71d53c81b396 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -461,6 +461,72 @@ 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(*cset), 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); + kfree(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 +1000,124 @@ 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; + + prop.name = (char *)prop_name; + prop.length = sizeof(u32) * sz; + prop.value = (void *)array; + + return of_changeset_add_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_u32_array); diff --git a/include/linux/of.h b/include/linux/of.h index 766d002bddb9..ba31036f0876 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 Mon Nov 21 16:43:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 23944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1701221wrr; Mon, 21 Nov 2022 08:47:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6hK6PevPde5cFUrL/R7cTUDPwpLlPMrdk511dg5GaOsN8z0UqmkDcGXjK9W/VGkMq8K/0C X-Received: by 2002:a17:906:79c4:b0:778:e3e2:8311 with SMTP id m4-20020a17090679c400b00778e3e28311mr1310997ejo.342.1669049278032; Mon, 21 Nov 2022 08:47:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669049278; cv=pass; d=google.com; s=arc-20160816; b=tDCLSl9Oq+kmomy8rThz4vJBeE3ReDwZx7mSlynqUUdBimE5IXtggryMNAMeEgeCvA 2CCo/SMND8jFchWfNGlUb3xRtWOB61yRgBc5JOiFpo8GO1t8SG8xdOnMhkUKMBOWTpHy uBiI5CejRdI3X8XYrU4iDzM2yyrQbJVd0JNLv9a8En+U94afNpLo4H2ZSnMNT3edWAtc YvKiMtu29XTkylQrJfunkgNl90aaS21rQusakMKJbTpo2Hg4deZf0BbmlVyiMXA/VRp9 CTUxmh72u3VyuxjZfqtw6gO3zTGlUtNO27VTRc4H8LPbBHvasa9fB+dsdJIUZQTlzA81 19Vw== 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=dJIodgobuFSEiYutNZJPpoYNjCH+jxg0AXEvGGQuU24=; b=boK/3bONsozSR5L72+VlLMJJQEbgvA0p/YZe44Ato5WnhFc2rZ+EH6m6XyFPhkZFIY ZlyntKQsutRJfA8lxjRa7bO4wQxHlYsQpsP552JRZ5DYWHmQp11LAHILINGBbj/dxmql oWTuktHpV/167BpYLN+pA3JXRa39Gf+QDnCCvgcXiuHytcVXe4J/NKsjfaG3jEMyo88h 5WbV/KRrCAOMfSrRy8HVl86jLsbkcqKKwllv+OUAsuF+XQqoNX/aS0MQsKkGAQZUg9Y9 kTXPhbBHXsT8uyEyzNK6wORrrH2ApSZu1gYZWksAt4NdUmNyS4vNUoLWALLbeor95X78 OOqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=eR52sJuH; 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 hd16-20020a170907969000b00780af308970si7485026ejc.185.2022.11.21.08.47.32; Mon, 21 Nov 2022 08:47:58 -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=eR52sJuH; 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 S230376AbiKUQnn (ORCPT + 99 others); Mon, 21 Nov 2022 11:43:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbiKUQn0 (ORCPT ); Mon, 21 Nov 2022 11:43:26 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 272911D65D; Mon, 21 Nov 2022 08:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bR8keTTIn3qj1eY2+ynA0I/W59G9x0EoCY0i2+OEt/a8rN65FYDLgSl4zxG3TdVNOoLdHNu3stHrVdx4+4JKOa2kay0e4vfetqu0Hdj8/LNUXj3uwKiHUvTaYmhUzfBN1ynicbAUMLU3k+iU+tTowAwR+0S95iU/Z5R6yePNZElMMbTnoFG7a/a6ZlHROA6jHGo5yiaDjGrk09X88jKtRcoxXMO8WuHpv5JLX1zJTjYpzH0CoNEDeFz4jaZc9Sbu0RiBFVtIcS7Roorj2L9vmeET86Rne2/YMY3esDs4YVSyPtOeYVxZGkvNZrxWOoMAAtxENJ4CdRGuvVskcggeDQ== 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=dJIodgobuFSEiYutNZJPpoYNjCH+jxg0AXEvGGQuU24=; b=AOAoEJb3KWHVW45FkybtwsSirZoDxVuDsz9kw7/PA1Gdjv9sIjDnSQsIBeXZJo9YD8drNJ81A6B/69QM/CWwmQhzXAOYtZ5NL5oKKe//TyWbGsrvD0z2tx9bddYYuUpj+4wPzbBodHwHCgtXhsqQMqtDTtLrxaU1iIIKzcnhObWtVIy6aM1qnjy8/Iufvqt7BZRo2SudgmbFYK/FftloINEfmo9pQB0478U7gLp1h3I3FFbwmc0ySMn/RYhDqiMFY/6HGZ1Y23Xim+dlgadNIYYH9ME225CKMfWSPRAXlBP1LLBNbU0w59nMiOAnMcvMBiasq5KcXVtlCtZAstukNg== 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=dJIodgobuFSEiYutNZJPpoYNjCH+jxg0AXEvGGQuU24=; b=eR52sJuHSEPaGhf3thjkacVh+mI7jTN1dYOEBaOL6ArFB2T22lcmESk9wt0EdLVwT0vI/YjiVWbKgPteVJIiwgmogZ8nwJgVDit2dYml4A21zNnWcJ2zJRf7qd5qBbvMI+hqhph2Z3iGLtgIuaUjhCE2dXJfKP9YEz90qMbZcMs= Received: from BN0PR04CA0005.namprd04.prod.outlook.com (2603:10b6:408:ee::10) by BL1PR12MB5125.namprd12.prod.outlook.com (2603:10b6:208:309::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Mon, 21 Nov 2022 16:43:16 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ee:cafe::f8) by BN0PR04CA0005.outlook.office365.com (2603:10b6:408:ee::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15 via Frontend Transport; Mon, 21 Nov 2022 16:43:16 +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 BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5834.8 via Frontend Transport; Mon, 21 Nov 2022 16:43:16 +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; Mon, 21 Nov 2022 10:43:16 -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; Mon, 21 Nov 2022 10:43:15 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [RESEND PATCH RFC V4 2/3] PCI: Create device tree node for selected devices Date: Mon, 21 Nov 2022 08:43:03 -0800 Message-ID: <1669048984-56394-3-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> References: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT065:EE_|BL1PR12MB5125:EE_ X-MS-Office365-Filtering-Correlation-Id: 38c3decd-8c42-4af3-2b01-08dacbdf7d62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iaHcEP9sK1A4xNqM4qZHdCW2SFdB2RrbJHr3ltRS+lvXEqJdK233mMNuhRqN13nd0dbfsZdhitp+hVcdbdhE9lnFsfZ4V9X4c6uIROqQmkeOHYta8Vf5PpvJXw/zROznMS2cEmhMshAfHXl7E7xxdPV1BdKFl4Eodco3HUzMBRb2WfUjkqYybM56RdWv9RvvOQjMV5170820D/eZOgd9C1FWUkjQN6jejl+hmnJWSZsh4pcY2a5SJQKjlMyjfdHpPE8xxnL2BCqyAqNzOzMSWTMAMw7KYtutfcs+PlLY50iBYeKaZuY+KfFUUEyXJwN1qUiahxr+s/vbKPUXnxyRAjXVv8zDLKFbtPFTI2XelRQEVmCCKCNyrd+zCRdSYOD3BLD6ZHwSKXmlFOOr8oD+YhJ/lHHQ8sg0lAVBdI1DuYeJAYrqZjz2e3voAWW9ngV0MIBchF/lWyO+B5LZDV1sW5vzEV3EV0NHMQz7TRrr74TyZrXdUUrdegeUYMiL1k0dxDLAE1cnIEQ7KDYPBoXRKlAyL8ISLbnNEFIzfB8C4FVHvncnfoOp+JcIVivKq+W9tO4qAddqxoCAPnzK91/DUFmiYaJf3BBe/QOsFyfuwfQ7svwYHqbLz9dLRuLXJx2k2BO9AZ0gWSBiHKcMg00ku/yM9OrENU9srGCECjIkjpoW9/6DBdLBXOGI+An8bLV3n0zuDqRGVVW8BucmVm1GBJwSYrZ2bYRlz8G5im+KLfA= 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)(39860400002)(136003)(451199015)(40470700004)(36840700001)(46966006)(86362001)(36756003)(82310400005)(4326008)(70586007)(40460700003)(40480700001)(41300700001)(70206006)(2616005)(426003)(47076005)(186003)(5660300002)(8676002)(8936002)(336012)(6666004)(478600001)(26005)(316002)(44832011)(30864003)(110136005)(82740400003)(54906003)(81166007)(356005)(83380400001)(36860700001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 16:43:16.7608 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38c3decd-8c42-4af3-2b01-08dacbdf7d62 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: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5125 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?1750125016195759782?= X-GMAIL-MSGID: =?utf-8?q?1750125016195759782?= 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 --- 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 | 256 ++++++++++++++++++++++++++++++++++++ drivers/pci/pci-driver.c | 3 +- drivers/pci/pci.h | 19 +++ drivers/pci/remove.c | 1 + 9 files changed, 368 insertions(+), 3 deletions(-) create mode 100644 drivers/pci/of_property.c diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 55c028af4bd9..126c31b79718 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -198,6 +198,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 "Device tree node 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 3cef835b375f..8507cc32b61d 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -316,6 +316,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 e9cf318e6670..eeaf44169bfd 100644 --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -230,8 +230,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..fb60b04f0b93 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 (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 *dt_node; + + dt_node = pci_device_to_OF_node(pdev); + if (!dt_node || !of_node_check_flag(dt_node, OF_DYNAMIC)) + return; + pdev->dev.of_node = NULL; + + of_destroy_node(dt_node); +} + +void of_pci_make_dev_node(struct pci_dev *pdev) +{ + struct device_node *parent, *dt_node = NULL; + const char *pci_type = "dev"; + struct of_changeset *cset; + const char *full_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) + parent = pdev->bus->dev.of_node; + else + parent = pdev->bus->self->dev.of_node; + if (!parent) + return; + + if (pci_is_bridge(pdev)) + pci_type = "pci"; + + full_name = kasprintf(GFP_KERNEL, "%pOF/%s@%x,%x", parent, pci_type, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + if (!full_name) + goto failed; + + dt_node = of_create_node(parent, full_name, &cset); + if (!dt_node) + goto failed; + kfree(full_name); + + ret = of_pci_add_properties(pdev, cset, dt_node); + if (ret) + goto failed; + + ret = of_changeset_apply(cset); + if (ret) + goto failed; + + pdev->dev.of_node = dt_node; + + return; + +failed: + if (dt_node) + of_destroy_node(dt_node); + kfree(full_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..cc66fa7517e0 --- /dev/null +++ b/drivers/pci/of_property.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022, Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include "pci.h" + +struct of_pci_addr_pair { + __be32 phys_hi; + __be32 phys_mid; + __be32 phys_lo; + __be32 size_hi; + __be32 size_lo; +}; + +struct of_pci_range { + __be32 child_addr_hi; + __be32 child_addr_mid; + __be32 child_addr_lo; + __be32 parent_addr_hi; + __be32 parent_addr_mid; + __be32 parent_addr_lo; + __be32 size_hi; + __be32 size_lo; +}; + +#define OF_PCI_ADDR_SPACE_CONFIG 0x0 +#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) + +#define OF_PCI_ADDRESS_CELLS 3 +#define OF_PCI_SIZE_CELLS 2 + +enum of_pci_prop_compatible { + PROP_COMPAT_PCI_VVVV_DDDD, + PROP_COMPAT_PCICLASS_CCSSPP, + PROP_COMPAT_PCICLASS_CCSS, + PROP_COMPAT_NUM, +}; + +static int of_pci_prop_device_type(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + return of_changeset_add_prop_string(ocs, np, "device_type", "pci"); +} + +static int of_pci_prop_address_cells(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + return of_changeset_add_prop_u32(ocs, np, "#address_cells", + OF_PCI_ADDRESS_CELLS); +} + +static int of_pci_prop_size_cells(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + return of_changeset_add_prop_u32(ocs, np, "#size_cells", + OF_PCI_SIZE_CELLS); +} + +static int of_pci_set_addr_flags(struct resource *res, u32 *addr_hi) +{ + 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; + + *addr_hi &= ~(OF_PCI_ADDR_FIELD_SS | OF_PCI_ADDR_FIELD_PREFETCH); + if (res->flags & IORESOURCE_PREFETCH) + *addr_hi |= OF_PCI_ADDR_FIELD_PREFETCH; + + *addr_hi |= 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[PCI_BRIDGE_RESOURCE_NUM]; + struct resource *res; + int i = 0, j, ret; + u64 val64; + u32 val; + + res = &pdev->resource[PCI_BRIDGE_RESOURCES]; + for (j = 0; j < PCI_BRIDGE_RESOURCE_NUM; j++) { + if (!resource_size(&res[j])) + continue; + + val = OF_PCI_ADDR_FIELD_NONRELOC; + if (of_pci_set_addr_flags(&res[j], &val)) + continue; + + rp[i].parent_addr_hi = cpu_to_be32(val); + + val64 = res[j].start; + rp[i].parent_addr_mid = + cpu_to_be32(FIELD_GET(OF_PCI_ADDR_HI, val64)); + rp[i].parent_addr_lo = + cpu_to_be32(FIELD_GET(OF_PCI_ADDR_LO, val64)); + + val64 = resource_size(&res[j]); + rp[i].size_hi = cpu_to_be32(FIELD_GET(OF_PCI_SIZE_HI, val64)); + rp[i].size_lo = cpu_to_be32(FIELD_GET(OF_PCI_SIZE_LO, val64)); + + rp[i].child_addr_hi = rp[i].parent_addr_hi; + rp[i].child_addr_mid = rp[i].parent_addr_mid; + rp[i].child_addr_lo = rp[i].parent_addr_lo; + i++; + } + + ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp, + i * sizeof(*rp) / sizeof(u32)); + + 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 reg_val, base_addr; + resource_size_t sz; + + reg = kzalloc(sizeof(*reg) * (PCI_STD_NUM_BARS + 1), GFP_KERNEL); + if (!reg) + return -ENOMEM; + + reg_val = FIELD_PREP(OF_PCI_ADDR_FIELD_SS, OF_PCI_ADDR_SPACE_CONFIG) | + 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)); + reg[0].phys_hi = cpu_to_be32(reg_val); + + 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_set_addr_flags(&pdev->resource[resno], ®_val); + if (!ret) + continue; + + reg_val &= ~OF_PCI_ADDR_FIELD_REG; + reg_val |= FIELD_PREP(OF_PCI_ADDR_FIELD_REG, base_addr); + reg[i].phys_hi = cpu_to_be32(reg_val); + reg[i].size_hi = cpu_to_be32(FIELD_GET(OF_PCI_SIZE_HI, sz)); + reg[i].size_lo = cpu_to_be32(FIELD_GET(OF_PCI_SIZE_LO, 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; +} + +static int (*of_pci_endpoint_props[])(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) = { + of_pci_prop_reg, + of_pci_prop_compatible, + NULL +}; + +static int (*of_pci_bridge_props[])(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) = { + of_pci_prop_device_type, + of_pci_prop_address_cells, + of_pci_prop_size_cells, + of_pci_prop_ranges, + of_pci_prop_reg, + of_pci_prop_compatible, + NULL +}; + +int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + int (**prop_func)(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np); + int i, ret; + + if (pci_is_bridge(pdev)) + prop_func = of_pci_bridge_props; + else + prop_func = of_pci_endpoint_props; + + for (i = 0; prop_func[i]; i++) { + ret = prop_func[i](pdev, ocs, np); + if (ret) { + /* + * The added properties will be released when the + * changeset is destroyed. + */ + return ret; + } + } + + return 0; +} diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 49238ddd39ee..1540c4c9a770 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -1628,7 +1628,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 785f31086313..bd81dc4ca04f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -678,6 +678,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 4c54c75050dc..0eaa9d9a3609 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 Mon Nov 21 16:43:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 23943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1699731wrr; Mon, 21 Nov 2022 08:45:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4R+d7sM6NWo8p4gz3Wh6ka2p/ZOUPHxhz31kYByESu5aM/XvBKd7UDdEs3MpbtPtbFW8NV X-Received: by 2002:a17:906:7f92:b0:783:7020:53a7 with SMTP id f18-20020a1709067f9200b00783702053a7mr15896805ejr.736.1669049112629; Mon, 21 Nov 2022 08:45:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669049112; cv=pass; d=google.com; s=arc-20160816; b=v5lxRVZwkG+GCHBeinFEay8GbE/C6LLf2hkJgEJIua6wUpnp+WIqKsQ2z0aF5jkWDR DSDl9/HwZtwYzQw+GpXV6iLw+vlaotks1FY+UQLwSf9qcoEglcoPNyGXqShEwRaa7yQc BBCBOtq0BUWpxWeT8A3YTVvpJshFBzHV3/24ibnyHlY5CiwSJlBrqIWADCtkIB9pGKsD EPvzRbaHBcTlTh+URSI9eHUaZ6josJp0+gyJIOWQ+mHpNno9WSWtbx1yZhTChtSrMmpz zRlubioCEUIvhVOtzXTjTxjLrsTOEMpZ+u6uauQWfFlQt8w1u7IetvIKU5LP41aWHfZE H0xA== 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=4kE3EEoROF8TRC85LHQNVGLLOGk4/ncwzq/kMy+zm2w=; b=Dm0ZSkS0qIqaX/QqGuY2X7soQ8c9vIUoWObcsx1MlIGoEQFtGhHlHbpmiODjBRwNNn h8OMpNMsgyUPn+g5JaxaWLLdtUjqpJTFNSyuxAXZNK0nuyz2kepnG2Or97ozEjRkbofQ qzrHm/JEtxltL1g/C8iT87aw9/0zVg896s5Rb710BNrn+cEUD8SGP0xDz4nOXU1UDRcI hh3AtDdTyfXh/spU5lReT7RM5PsdmiY+46ZRUAubrHXdIMtROJ985LvLD61c73SEU3bV 1dr69qJPtFqSK2Fujk6HafsTkWMbFLgZB5zh8Rh3m3Ez2DeLSoUDFOITq5HE3KKMMtWQ AcBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=E8pI1yVC; 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 du3-20020a17090772c300b007aeab6a1174si10115796ejc.633.2022.11.21.08.44.47; Mon, 21 Nov 2022 08:45:12 -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=E8pI1yVC; 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 S230315AbiKUQnj (ORCPT + 99 others); Mon, 21 Nov 2022 11:43:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbiKUQn0 (ORCPT ); Mon, 21 Nov 2022 11:43:26 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2080.outbound.protection.outlook.com [40.107.94.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76EA1C622E; Mon, 21 Nov 2022 08:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=blUcgX8mY8WgrFpMcPGcDzXunG3i7Y18ZFQ0Fc/IPLNc34J3CXCPtk8AypBFkPqTcu/U68PEPLI0ljQNpHuzoBRlB7EgEhmEqAcgCBNQO4ZfuUKkRSk3eOW7O8mtfa8Bmnp9aL6Qd4lf2TRmOufKdxgEYUGKnc00N6urZi/SW5ubRgRa/qkpGjx6VvSALg3dZD4p2O6//nN5Co7B3k76qdDLUTUaC5fQByS9VBv8RbobBv2AInA9RkMFdQ3A5bnTH5dKVwb4SmIAtpotFajq2wYDs8XgPupLhuKRC3XjfoQy8nDFasxRTAK/TJU9rg0uqiDgDSamtudhKDJut/BDhw== 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=4kE3EEoROF8TRC85LHQNVGLLOGk4/ncwzq/kMy+zm2w=; b=aiqrNXjXVK5KK820565dIhPUcUBPOKp5NSgMHHGRd6esVJ3l6lOHKhGD3271pPyVB4fWrXAhVLkK4g/PnkaffDCQDaKTsSEjmfoG73kKDJAUcqBHqJWB6MlpLpXAVuyDe7Z6U4D/7uvXmKbUiYSI2xhPKn7n+k6plESGeSQqSyVY60ftrSpEmQXvN2ulsa7fboIEf7D9vOv2ivGVqGspcOo0zriv1tbwo7n7cBEw0AH84TA9D/QaKeYrlZfpOsOiQVY0MXZ2JxwiARDKzUY38XLASSjJfEhE7dKPNAafFADULYfL0fH0Q4IC/lzvwDfPo1NgCRTDm7hKWO+rqqXbFg== 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=4kE3EEoROF8TRC85LHQNVGLLOGk4/ncwzq/kMy+zm2w=; b=E8pI1yVC+a5tLYPFdwGwlhEiiUOX4PTi/zVtRD/OF7kAlszNxA4XitoT9nbihDLupx7jvd+bO7teO/ADNQHk1U9wrZ6GX6ZLAy/ArUVO5gYGiuzrLUd5pIHix5LjDvQwqc4W2PY0Hog4wn2tYkqimYA65h2vPjevaHCtkhcDz9A= Received: from BN8PR12CA0013.namprd12.prod.outlook.com (2603:10b6:408:60::26) by MW4PR12MB6876.namprd12.prod.outlook.com (2603:10b6:303:208::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.11; Mon, 21 Nov 2022 16:43:18 +0000 Received: from BN8NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::d9) by BN8PR12CA0013.outlook.office365.com (2603:10b6:408:60::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15 via Frontend Transport; Mon, 21 Nov 2022 16:43:18 +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 BN8NAM11FT055.mail.protection.outlook.com (10.13.177.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5834.8 via Frontend Transport; Mon, 21 Nov 2022 16:43:18 +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; Mon, 21 Nov 2022 10:43:17 -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; Mon, 21 Nov 2022 10:43:16 -0600 From: Lizhi Hou To: , , , , , CC: Lizhi Hou , , , , , , , Subject: [RESEND PATCH RFC V4 3/3] PCI: Add PCI quirks to generate device tree node for Xilinx Alveo U50 Date: Mon, 21 Nov 2022 08:43:04 -0800 Message-ID: <1669048984-56394-4-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> References: <1669048984-56394-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT055:EE_|MW4PR12MB6876:EE_ X-MS-Office365-Filtering-Correlation-Id: b53e4737-aa55-478d-bf90-08dacbdf7e27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c2SRC6cXPmWJL2P78fPjrvq+7BzHrIncOSANufEQEK4ogCDq9mAkZQy6aUxdS2n/KNHdSLA091eQMrrHBCC93x7vgmDFzHDaLZ2wfDODh0QLpnTPb/gajdQPMgKGEyE064WHwO62jhgIcG32Z2YKzMT3GL32LlPj6/cwY9bpUSRleDffthOL5TAWJSnM88wYB4k/kHTKEhBhBEOlZAGRD1xflyo/osIO4BEdHkJG5IiH2jKblZltQauh3L715Bo8DSdxsONE8gX0cjKB63Y+0Ntgo3hx+msS+dK7L1Pq4Tn7vKBnNAbLKHoFYBgpp5mCSubE7fn1eyrdVI0FKF6Y7q8/LjF2Ozqq0mxiCrZVUypaTFPb7Qgvx+mi9IvkEnaqOXWy2yeR9mhGUlalqA0OcSx7NEdSXnDpgRLX2lvKfHEmOuMFzwSTxuBUP4WvKwiZJyeBruVZPmnTqkiKO6F/74EIbh94gt/HSzOmNvuYXLm290SCR6yzm/gMh5utKkTCTEBMazgNT0r3dqNhYtKd2SwXKD0/8ASFHQq14XF0S35wZxO2XiY1bCpsQOPKHBOHXB0c3uwQvxulJbfo/P1h4wOxiWdKH93UgIfJZPwuzxPJoSv0OmeR0b1VGgD5I7kWeLBJZaxJeM7UZqhAjpRR6xFnFcWjI85CGT51SHYANkTq+Y22zCqJ57Ih/gmAxGAZCimespkHnRo0IX1YfQF3RDIM31TexRMnE64Kpn7muOw= 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)(396003)(346002)(136003)(376002)(39860400002)(451199015)(46966006)(36840700001)(40470700004)(36756003)(478600001)(5660300002)(44832011)(336012)(47076005)(40460700003)(70586007)(4326008)(8676002)(426003)(70206006)(26005)(54906003)(316002)(110136005)(2616005)(8936002)(82310400005)(356005)(36860700001)(81166007)(82740400003)(41300700001)(186003)(2906002)(40480700001)(86362001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 16:43:18.0557 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b53e4737-aa55-478d-bf90-08dacbdf7e27 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: BN8NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6876 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?1750124842442575241?= X-GMAIL-MSGID: =?utf-8?q?1750124842442575241?= 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 --- drivers/pci/quirks.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 4944798e75b5..5d76932f59ec 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5956,3 +5956,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b1, aspm_l1_acceptable_latency DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c0, aspm_l1_acceptable_latency); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c1, aspm_l1_acceptable_latency); #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);