From patchwork Thu Jun 29 17:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 114390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9802546vqr; Thu, 29 Jun 2023 10:38:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4cCXqw1R4wG5qEEw2zWh4OYrjcmnR6Vx/NSlhFzyuiXnlf+DSfstVZPO5oQlIf+p23Kdm6 X-Received: by 2002:a05:6a20:440d:b0:111:fba0:bd3b with SMTP id ce13-20020a056a20440d00b00111fba0bd3bmr428296pzb.1.1688060308276; Thu, 29 Jun 2023 10:38:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688060308; cv=pass; d=google.com; s=arc-20160816; b=nwurDpiS7MbmTfdH5j4sGq3nRgu2CKE8tWMUvT3vT6z17mwdEWP5C0kUTqM6TzcO6z peMxtaqaXoCtDUUKQ6cVKPuBI0b2opbyErPRmxrpQVJTA+/fkAKgqym7OHvvydxPwgsE 0qMvOnf/tydlWSKqEW9gfC1QZBY0lCLK8XBjSlugY9HxarjlpEfMMLGeTEMzRgaFRiDo /cxKpgDQainQBJLl1enJJP6SniTrDKZ8rJWSbjBgIjHyzDv26mU3tGeIt2MJyCFJzyZR ycDSJN792418PECQ1I8sXjmIpc54bb2ATKZvTOvp/psOpBLtRzELZDXT46kTnvgBhJwb qaSQ== 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=GewLlpz3XfsZc+5THxZsHXFYOBx/SLC7l1DprcjQmJQ=; fh=AT5si2m776ncveJnRAE+WaVvhiXzUOkMtUWFXtn2w5Q=; b=Zu/ubKTKfH4YFP1hh1gy/Pkzu/aZAfHGBotNZLHtHg5ucApS1HTRe3XkgndYdYZM90 TUbH5qFTS2CBa5q07ZqQoO0YBB7XPeww7/0CAsk/shj12GB5eX/m0c5qLO/7XRq3FP3x +m7Pocl9sFp98QCj/EgK8gbVkTk4WpG6xK/IcHWndbW9zk9VSoX3VY1Xxe2fjbGEXGov 1FKeDKkhXXOFnZZW0Vzv3/FFmo4ZGljccOc6qnS1xAYpEVdwTIRbphOq8xHUmpchWltu GVzV2yLRHHLxD0viGSKlQGne+omXxLvoDhXJ5rg/6Rq93xmQwCm6wLpEjywNERn9CFXz KJHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=blTgEeSz; 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 x69-20020a638648000000b0053fa2f589aesi10860752pgd.884.2023.06.29.10.38.13; Thu, 29 Jun 2023 10:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=blTgEeSz; 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 S232260AbjF2Rbt (ORCPT + 99 others); Thu, 29 Jun 2023 13:31:49 -0400 Received: from mail-bn8nam11on2040.outbound.protection.outlook.com ([40.107.236.40]:37070 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231768AbjF2Rbf (ORCPT ); Thu, 29 Jun 2023 13:31:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VMOpgZ2wqVcePZ7SVakmUoUJYdFgbUS7XsE7j4/P1tJmyOcVJoo7bsKIDUjsye7SGf8iAczKu0YIHOjSRAkqKABNb4kbkGU1BeqyaWDEcqOJ/A2SygRPO1CF9R4l6jFSn7CexlcuC0iAksYyW3teg+JBUmF0TxJa2CTKXhxx7wj4hhXVF3dUxHuKyn+8zC/FMzTy2D0t1vDWOD8W2IWtDStK7p50901tNRjhIH18o/QyYyFpDETMRfpesJqvp7E9WKFYBiyIMPFimNWNLc0LeamwpeqO61b4nayYn4KY1n2lezjpoLKRp1Eo6v69fsNHZ2eGZ08Qk11arzfpkYzDEw== 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=GewLlpz3XfsZc+5THxZsHXFYOBx/SLC7l1DprcjQmJQ=; b=idLt/mLyUQ8Ubxmax/XdZzNIE1uWGWxxfrsL1AYfFZB+EH7I/R/8+83YPK+BAAPlwgPpydnax6zVj1+DXHFVYoZb3wWW++6+iqXJ+IvXx5+pcd/QcpWy+dxLi8oKYafq1vi1sXDeuYvH7LxJXdHzZncvOdsjaRkMZQc/vVogux9c2aJrB0Nk7BbRelpeqkL7QcatR+bnkev1SEs38+1d2AVb1c5Z105hSOSIlyyWyvle+d6XamtNBxmKEJhlT0kNpJQ2wPYmJ6lKWMgzleaJaFN8pSThRMxmPRTN5OcBhPWi6xyR+CosylkrwnLrYFUY74veXkweJh1bQuWH/04qNA== 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=GewLlpz3XfsZc+5THxZsHXFYOBx/SLC7l1DprcjQmJQ=; b=blTgEeSzBnILJAke3jdphrsDa7XJmImcJcD0BLZQG4bdpgS6Zg7cpQQlQy64UQ31ljcJUiGL8sFcNlNBCKOU5u2/SMI3KLRCnGkk8KkBVWdstoxaZL9JDKS2mCV2We95mf0JdLuWHd7SQSA8QfrPMiVL9zJW4uQLjs1dBnMHGo8= Received: from BN9PR03CA0962.namprd03.prod.outlook.com (2603:10b6:408:109::7) by CH2PR12MB4859.namprd12.prod.outlook.com (2603:10b6:610:62::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Thu, 29 Jun 2023 17:31:30 +0000 Received: from BN8NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::41) by BN9PR03CA0962.outlook.office365.com (2603:10b6:408:109::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.34 via Frontend Transport; Thu, 29 Jun 2023 17:31:30 +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 BN8NAM11FT006.mail.protection.outlook.com (10.13.177.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.49 via Frontend Transport; Thu, 29 Jun 2023 17:31:30 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 12:31:30 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 12:31:29 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 29 Jun 2023 12:31:29 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH V10 1/5] of: dynamic: Add interfaces for creating device node dynamically Date: Thu, 29 Jun 2023 10:19:46 -0700 Message-ID: <1688059190-4225-2-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> References: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT006:EE_|CH2PR12MB4859:EE_ X-MS-Office365-Filtering-Correlation-Id: cbee17b4-3de7-4ee6-d7c4-08db78c6ad0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TgUVj1JImKQR/zcp2jdLfdZb6Qm6WfOUTWKyNWNWIK4rvmIE1zoCKN9agdQCS304CbfAl9/61Cruh/pKYcs0GaEER0j81ec7ZTk/FyeFF9M/FNeZIOTLz2PtFMZndpAsAZvCdUzuadx0zF9GdiyQ5QSH9WnXWdE22eTAYPFG0PMXffxgstmOOv/vTa94wUyV3FHIdsEloGmipFwxawW647GGNS5gJcdr/CvGx5voTiSf0DObCJ3Yv2qJHu0RLvlG33RIPbmu6R2StunJFPkIWZh0Mj2e0jtvl12Cbluh8d29o/IiRhHuQtt75taBM0kvosujI+R2QwA4VctL9Jfmg5gETvZOH2ibRHxguCM25UYsQ69MfYA61CGD2sEaVYjaAepzO8xcWADol2aaMc6RZt0EA1sp+BnnlMI3iSrrhf36pD98HjgE4K1UNhr7RVD7yUAc1yVigDS7YZ/MSiSYhIpCGUr3MdG6Ih7rzaaw3IOaPQj+d/DnaesRCXwRq4501idQu7rhaNVOFbA7igpfhaUeAqT4+tR4TghxzqR8q4Bd2cxoaqL7OUIafgH+YT8dr/73ZECrOsUJbuFOuB0yGQuMlVzWPwbnfJkrLZEGWKF+REddXms6FpaA+NId/RKgPajlcY84uSgoAzxVOSOL1EFAQTq9Y1XM64cJNYX7oo6FRdXzxS4cItAHmFSL1TmSHdKcXOYkVN/sQotyB1nZFg03NiKiVMZwRLMVzeZH1Vhw4ahYkrOI/DMz6okOWo8cwoTFRjYqZ6GiGRTD6d8sjg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(136003)(376002)(396003)(451199021)(46966006)(40470700004)(36840700001)(82310400005)(36860700001)(2906002)(8676002)(36756003)(41300700001)(356005)(44832011)(40460700003)(316002)(5660300002)(70206006)(86362001)(4326008)(40480700001)(8936002)(70586007)(82740400003)(81166007)(66574015)(186003)(26005)(47076005)(83380400001)(6666004)(2616005)(54906003)(478600001)(110136005)(426003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 17:31:30.4877 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbee17b4-3de7-4ee6-d7c4-08db78c6ad0e 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: BN8NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4859 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?1770059525954646589?= X-GMAIL-MSGID: =?utf-8?q?1770059525954646589?= of_changeset_create_node() creates device node dynamically and attaches the newly created node to a changeset. Expand of_changeset APIs to handle specific types of properties. of_changeset_add_empty_prop() of_changeset_add_prop_string() of_changeset_add_prop_string_array() of_changeset_add_prop_u32_array() Signed-off-by: Clément Léger Signed-off-by: Lizhi Hou --- drivers/of/dynamic.c | 187 ++++++++++++++++++++++++++++++++++++++++++ drivers/of/unittest.c | 19 ++++- include/linux/of.h | 26 ++++++ 3 files changed, 231 insertions(+), 1 deletion(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index e311d406b170..4d0720a09be7 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -487,6 +487,38 @@ struct device_node *__of_node_dup(const struct device_node *np, return NULL; } +/** + * of_changeset_create_node - Dynamically create a device node and attach to + * a given changeset. + * + * @parent: Pointer to parent device node + * @full_name: Node full name + * @cset: Pointer to changeset + * + * Return: Pointer to the created device node or NULL in case of an error. + */ +struct device_node *of_changeset_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset *cset) +{ + struct device_node *np; + int ret; + + np = __of_node_dup(NULL, full_name); + if (!np) + return NULL; + np->parent = parent; + + ret = of_changeset_attach_node(cset, np); + if (ret) { + of_node_put(np); + return NULL; + } + + return np; +} +EXPORT_SYMBOL(of_changeset_create_node); + static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) { if (ce->action == OF_RECONFIG_ATTACH_NODE && @@ -960,3 +992,158 @@ 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_empty_prop - Add an empty property to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * + * Create an empty property and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_empty_prop(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name) +{ + struct property prop = { 0 }; + + prop.name = (char *)prop_name; + + return of_changeset_add_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_add_empty_prop); + +/** + * of_changeset_add_prop_string - Add a string property to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @str: pointer to null terminated string + * + * Create a string property and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str) +{ + struct property prop; + + prop.name = (char *)prop_name; + prop.length = strlen(str) + 1; + prop.value = (void *)str; + + return of_changeset_add_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_string); + +/** + * of_changeset_add_prop_string_array - Add a string list property to + * a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @str_array: pointer to an array of null terminated strings + * @sz: number of string array elements + * + * Create a string list property and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_string_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const char **str_array, size_t sz) +{ + struct property prop; + int i, ret; + char *vp; + + prop.name = (char *)prop_name; + + prop.length = 0; + for (i = 0; i < sz; i++) + prop.length += strlen(str_array[i]) + 1; + + prop.value = kmalloc(prop.length, GFP_KERNEL); + if (!prop.value) + return -ENOMEM; + + vp = prop.value; + for (i = 0; i < sz; i++) { + vp += snprintf(vp, (char *)prop.value + prop.length - vp, "%s", + str_array[i]) + 1; + } + ret = of_changeset_add_prop_helper(ocs, np, &prop); + kfree(prop.value); + + return ret; +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_string_array); + +/** + * of_changeset_add_prop_u32_array - Add a property of 32 bit integers + * property to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be added + * @array: pointer to an array of 32 bit integers + * @sz: number of array elements + * + * Create a property of 32 bit integers and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_add_prop_u32_array(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, + const u32 *array, size_t sz) +{ + struct property prop; + __be32 *val; + int i, ret; + + val = kcalloc(sz, sizeof(__be32), GFP_KERNEL); + if (!val) + return -ENOMEM; + + for (i = 0; i < sz; i++) + val[i] = cpu_to_be32(array[i]); + prop.name = (char *)prop_name; + prop.length = sizeof(u32) * sz; + prop.value = (void *)val; + + ret = of_changeset_add_prop_helper(ocs, np, &prop); + kfree(val); + + return ret; +} +EXPORT_SYMBOL_GPL(of_changeset_add_prop_u32_array); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 2191c0136531..1193a574fa36 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -802,7 +802,9 @@ static void __init of_unittest_changeset(void) struct property *ppname_n21, pname_n21 = { .name = "name", .length = 3, .value = "n21" }; struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; struct property *ppremove; - struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np; + struct device_node *n1, *n2, *n21, *n22, *nchangeset, *nremove, *parent, *np; + static const char * const str_array[] = { "str1", "str2", "str3" }; + const u32 u32_array[] = { 1, 2, 3 }; struct of_changeset chgset; n1 = __of_node_dup(NULL, "n1"); @@ -857,6 +859,17 @@ static void __init of_unittest_changeset(void) unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n"); unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); + n22 = of_changeset_create_node(n2, "n22", &chgset); + unittest(n22, "fail create n22\n"); + unittest(!of_changeset_add_prop_string(&chgset, n22, "prop-str", "abcd"), + "fail add prop prop-str"); + unittest(!of_changeset_add_prop_string_array(&chgset, n22, "prop-str-array", + (const char **)str_array, + ARRAY_SIZE(str_array)), + "fail add prop prop-str-array"); + unittest(!of_changeset_add_prop_u32_array(&chgset, n22, "prop-u32-array", + u32_array, ARRAY_SIZE(u32_array)), + "fail add prop prop-u32-array"); unittest(!of_changeset_apply(&chgset), "apply failed\n"); @@ -866,6 +879,9 @@ static void __init of_unittest_changeset(void) unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), "'%pOF' not added\n", n21); of_node_put(np); + unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n22")), + "'%pOF' not added\n", n22); + of_node_put(np); unittest(!of_changeset_revert(&chgset), "revert failed\n"); @@ -874,6 +890,7 @@ static void __init of_unittest_changeset(void) of_node_put(n1); of_node_put(n2); of_node_put(n21); + of_node_put(n22); #endif } diff --git a/include/linux/of.h b/include/linux/of.h index 6ecde0515677..703152181a44 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1580,6 +1580,32 @@ static inline int of_changeset_update_property(struct of_changeset *ocs, { return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); } + +struct device_node *of_changeset_create_node(struct device_node *parent, + const char *full_name, + struct of_changeset *cset); +int of_changeset_add_empty_prop(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name); +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 Thu Jun 29 17:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 114389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9802289vqr; Thu, 29 Jun 2023 10:38:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42/+/eJoRcEiMz+JEhrCOXUaqk3408YG4gcsqD128ofEybXFgvFGkDdcVNqlTQTuSe7bUR X-Received: by 2002:a17:903:1105:b0:1b3:ebda:654e with SMTP id n5-20020a170903110500b001b3ebda654emr45458057plh.5.1688060282153; Thu, 29 Jun 2023 10:38:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688060282; cv=pass; d=google.com; s=arc-20160816; b=YFxCTf5kbTV+N/R2lkUIlv9pOu6k/l9M0IGYkgWYBcmcUm6LUrNxFXqrJn4UtIxIpx XE26uvpbqX1mXC/GPDD4G3UYZ+rxTlXhN3uHTwSPvECuz9t1kQg08EGSjBH/ZM/+dJ48 FGU2J8G4TNFHd9Q5MaYInOlIt7aQKm+NGS9twIzClxR7DLQEqTD1D6OX1UjtGZfeYGNY 6fToEBtdxSbfOrX9au0IrcqrCAm6sdNxXLRzlLHDuvLCkYjl3Vqvl2jK1bezD/TLpBgg Ybq0vsG0RvlhgPidgc+Y+4e0XKwQQ/vI3UpXVLI2eZcOcSA5jrsVzurbhBeTkZChUAtO 6y6A== 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=QT1uNLWJ3yvts8S0GG3k3zEXGxHXnUF2KyS64kd+gko=; fh=Dp1cBGMGbwAqoabrudJCB/xGaYuol06NcbmMGQv1HC4=; b=KKRbCVE6TdKGlm3C9cMZ8RoViR6IcJbWiSUJ8FT4pf5MCbDFfewiOcM6HrFohO4XvP Vc6csFuoKUQsgOEn0Q9oaHY0lmvAYO/wknCDK47+Y6BTgCTVE980hOlvp5FpnhC+Q9Es bRiq24fSqzXK+ojCOYieCvPAIW6Ra0iVdPAvGcTQ5eCvgFULw692ERR7xj1dW1ElTVEd huYW3j62YibvHh/1z0QyS380MC/D7YHWJ1e5t/juwd4wclagRy+sVVA/TN9DxlVKzA/3 4mqgKCsAgHvmbKbLeBOy8ciiOAbcHVQlFKS2WTX+yKQOreRl2Qx4c4pOOUjvuQWJuVq+ /TAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=e+vtumF4; 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 u12-20020a17090282cc00b001b8039317cesi7673097plz.301.2023.06.29.10.37.47; Thu, 29 Jun 2023 10:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=e+vtumF4; 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 S232166AbjF2Rbj (ORCPT + 99 others); Thu, 29 Jun 2023 13:31:39 -0400 Received: from mail-dm6nam10on2063.outbound.protection.outlook.com ([40.107.93.63]:45953 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229873AbjF2Rbe (ORCPT ); Thu, 29 Jun 2023 13:31:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fc94RFQLM1LL1e3Sf9mY/u4RrleI1SGh50HQussoskY1HQToYIKMkm+GfeyH0RYAdMDZmGBmXnFy0s42SvCW7kWhZY+PFDzYufhz1Wt16aAUsjRfdODyrE5ti4v6I9ISJO2SohDhKBj/ZZd+CaQeHwtoFGD1NKCooyEcF6szyeml+L4aaQaPFrdEb+AeMXJyNzUu7rHYlHgud0FU5qKmPBHMLZGKNLdF9QbaDEELV9EQ/I2WFA7pNmOl5NQx+V0j2MPjzb4JUz8t81t7SMXi2iw4XH+69RFgX9Ts5Q/Npzbi6970C+JYKHR7EUkazCj1NwAXlrRR21MMevzqCv7b9A== 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=QT1uNLWJ3yvts8S0GG3k3zEXGxHXnUF2KyS64kd+gko=; b=nz/qy1FdFePXq0n+a1wKWmTJ+uwmEmhWLp+S+iQsT8wmGv0PxCF1NhIJXOgpHgB+d9XWQ0hQS1lDrTUF1KWGefICahYfpkc2u8OWTvftknMfHl46VySMm5KH3KbtCgaLiy+Xlh6PBC9+iWnUCmK4AGnNufWY2tKtSXvcUVEwdpUC+krkteZs1li8FvrHjTMkgqoKqYuQIuq6ZsELw6D3Us/vqt4kfBDGyAvNtEbld7q+7pKBAaZ306UhM3OdW1BZTcAf1bUPAVGqLepTqxGOGoSBgVqP5JaGqyTBRntcJsz4NIbetXKlJ5aT5S0SJJ4hLJFmTC3IEbTG5LQd3DYTGw== 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=QT1uNLWJ3yvts8S0GG3k3zEXGxHXnUF2KyS64kd+gko=; b=e+vtumF4+4t2kZsAVltYAI8dliq2DCSEdiD7/7gy24+n6UObEPDO8yuCgQE0JrY8AHL9iPxnuo5IGVsfHVENNBySC1SIlyzd8K5BlRn+eLtGwLXhgFSY/ehj1lGZdbYPPNsENyFT7u/TBvUHRdWiG4VXC5ZU+RptCtrrx89yAAk= Received: from BN9PR03CA0233.namprd03.prod.outlook.com (2603:10b6:408:f8::28) by MN0PR12MB6080.namprd12.prod.outlook.com (2603:10b6:208:3c8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Thu, 29 Jun 2023 17:31:31 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f8:cafe::91) by BN9PR03CA0233.outlook.office365.com (2603:10b6:408:f8::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Thu, 29 Jun 2023 17:31:31 +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 BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.48 via Frontend Transport; Thu, 29 Jun 2023 17:31:31 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 12:31:31 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 12:31:30 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 29 Jun 2023 12:31:30 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V10 2/5] PCI: Create device tree node for bridge Date: Thu, 29 Jun 2023 10:19:47 -0700 Message-ID: <1688059190-4225-3-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> References: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|MN0PR12MB6080:EE_ X-MS-Office365-Filtering-Correlation-Id: 8172302e-a68c-416a-e5b0-08db78c6ada5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 94+xg5/GolJ/jBZxFzSQcD85NesWzrP09TC2OynhrGD2wO5vRgXmIQzJziMOI86EApqZSTHuE6AOz3iNh4C71/dhCombWWYit4TGg+h6/NaGz94aeRasOrboaAiGTmMyTcJs8QYOVXP7NnGbdxzmrlacdVoBtlAaBKjiSh7CAt6D2RFdwFH5lh4uCM8Zd3l7FcD899rya6V/IZZQSgca6psdcipmL8p2NiluFDy5TpaC7Y7qhbtOF4Bbdlze8Q+O3fuD8BGxniP5jmUBUK7oln3vGuLtN7CEO9bVSpNbpGqksiR9SzD5uxNFYBCK0QgvgfuIi07wsb98Mp42rWUFeji42yfK16HIkNVUPcp7FfJ4NXKQiZaCMKoWld6l+L6cKT2G0zvRHEoMT1C19HfLy3/XzDaJt2plzjC6eNQJmka8Skm/Av5CVkGH1L6Zpf0j+D1Jj+PMPjGffezQnRgEXuVsnfcFF1Jz/tYKpPbP9WlgEZsxPYCPWs9YoP1zeueTwXOxzZGdCWLJRnbUDaaLgnnZh/JzMYkbsTAsfUAjAC2XsN1q2s2p6rnGIYz62XZJHkGFG4s7CC8fXeuFq7Io7Pgh9XfqlwIM+IQih85sfKJXKylZ6rc9zc9A4sEK6W1ok+vMlQubzE9o4RxLegvb5wc1SyNI1z97T00H30H1IaiQkltYiimxJShKvUthIVCIfHwdqO5+zG36YdhjcoI+FQxV0GPtApFNcvvc5uCjWNtnWK/Pfc1zzD/Bsjidaq01Len6O1V8dq36w9WI6+4E/A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(36840700001)(46966006)(40470700004)(70206006)(40480700001)(40460700003)(426003)(336012)(47076005)(83380400001)(2906002)(186003)(30864003)(2616005)(316002)(36860700001)(70586007)(54906003)(4326008)(6666004)(110136005)(478600001)(26005)(44832011)(5660300002)(8936002)(8676002)(41300700001)(356005)(81166007)(82740400003)(82310400005)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 17:31:31.4932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8172302e-a68c-416a-e5b0-08db78c6ada5 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: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6080 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?1770059498245604963?= X-GMAIL-MSGID: =?utf-8?q?1770059498245604963?= The PCI endpoint device such as Xilinx Alveo PCI card maps the register spaces from multiple hardware peripherals to its PCI BAR. Normally, the PCI core discovers devices and BARs using the PCI enumeration process. There is no infrastructure to discover the hardware peripherals that are present in a PCI device, and which can be accessed through the PCI BARs. Apparently, the device tree framework requires a device tree node for the PCI device. Thus, it can generate the device tree nodes for hardware peripherals underneath. Because PCI is self discoverable bus, there might not be a device tree node created for PCI devices. Furthermore, if the PCI device is hot pluggable, when it is plugged in, the device tree nodes for its parent bridges are required. Add support to generate device tree node for PCI bridges. Add an of_pci_make_dev_node() interface that can be used to create device tree node for PCI devices. Add a PCI_DYNAMIC_OF_NODES config option. When the option is turned on, the kernel will generate device tree nodes for PCI bridges unconditionally. Initially, add the basic properties for the dynamically generated device tree nodes which include #address-cells, #size-cells, device_type, compatible, ranges, reg. Signed-off-by: Lizhi Hou --- drivers/pci/Kconfig | 12 ++ drivers/pci/Makefile | 1 + drivers/pci/bus.c | 2 + drivers/pci/of.c | 88 ++++++++++++++ drivers/pci/of_property.c | 235 ++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 15 +++ drivers/pci/remove.c | 1 + 7 files changed, 354 insertions(+) create mode 100644 drivers/pci/of_property.c diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 9309f2469b41..7264a5cee6bf 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 device tree nodes for PCI devices" + depends on OF + select OF_DYNAMIC + help + This option enables support for generating device tree nodes for some + PCI devices. Thus, the driver of this kind can load and overlay + flattened device tree for its downstream devices. + + Once this option is selected, the device tree nodes will be generated + for all PCI bridges. + choice prompt "PCI Express hierarchy optimization setting" default PCIE_BUS_DEFAULT diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 2680e4c92f0a..cc8b4e01e29d 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_PCI_P2PDMA) += p2pdma.o obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o obj-$(CONFIG_VGA_ARB) += vgaarb.o obj-$(CONFIG_PCI_DOE) += doe.o +obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/ diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 5bc81cc0a2de..ab7d06cd0099 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -340,6 +340,8 @@ void pci_bus_add_device(struct pci_dev *dev) */ pcibios_bus_add_device(dev); pci_fixup_device(pci_fixup_final, dev); + if (pci_is_bridge(dev)) + of_pci_make_dev_node(dev); pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); pci_bridge_d3_update(dev); diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 2c25f4fa0225..9786ae407948 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -487,6 +487,15 @@ 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 IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES) + /* + * Interrupt mapping is not supported for dynamic + * generated bridge node. Thus, set ppnode to NULL + * to do standard swizzling. + */ + if (of_property_present(ppnode, "dynamic")) + ppnode = NULL; +#endif } /* @@ -617,6 +626,85 @@ 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_changeset_revert(np->data); + of_changeset_destroy(np->data); + of_node_put(np); +} + +void of_pci_make_dev_node(struct pci_dev *pdev) +{ + struct device_node *ppnode, *np = NULL; + const char *pci_type; + struct of_changeset *cset; + const char *name; + int ret; + + /* + * If there is already a device tree node linked to this device, + * return immediately. + */ + if (pci_device_to_OF_node(pdev)) + return; + + /* Check if there is device tree node for parent device */ + if (!pdev->bus->self) + ppnode = pdev->bus->dev.of_node; + else + ppnode = pdev->bus->self->dev.of_node; + if (!ppnode) + return; + + if (pci_is_bridge(pdev)) + pci_type = "pci"; + else + pci_type = "dev"; + + name = kasprintf(GFP_KERNEL, "%s@%x,%x", pci_type, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + if (!name) + return; + + cset = kmalloc(sizeof(*cset), GFP_KERNEL); + if (!cset) + goto failed; + of_changeset_init(cset); + + np = of_changeset_create_node(ppnode, name, cset); + if (!np) + goto failed; + np->data = cset; + + ret = of_pci_add_properties(pdev, cset, np); + if (ret) + goto failed; + + ret = of_changeset_apply(cset); + if (ret) + goto failed; + + pdev->dev.of_node = np; + kfree(name); + + return; + +failed: + if (np) + of_node_put(np); + kfree(name); +} +#endif + #endif /* CONFIG_PCI */ /** diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c new file mode 100644 index 000000000000..1432f9eed3af --- /dev/null +++ b/drivers/pci/of_property.c @@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022-2023, 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]; +}; + +/* + * Each entry in the ranges table is a tuple containing the child address, + * the parent address, and the size of the region in the child address space. + * Thus, for PCI, in each entry parent address is an address on the primary + * side and the child address is the corresponding address on the secondary + * side. + */ +struct of_pci_range { + u32 child_addr[OF_PCI_ADDRESS_CELLS]; + u32 parent_addr[OF_PCI_ADDRESS_CELLS]; + u32 size[OF_PCI_SIZE_CELLS]; +}; + +#define OF_PCI_ADDR_SPACE_IO 0x1 +#define OF_PCI_ADDR_SPACE_MEM32 0x2 +#define OF_PCI_ADDR_SPACE_MEM64 0x3 + +#define OF_PCI_ADDR_FIELD_NONRELOC BIT(31) +#define OF_PCI_ADDR_FIELD_SS GENMASK(25, 24) +#define OF_PCI_ADDR_FIELD_PREFETCH BIT(30) +#define OF_PCI_ADDR_FIELD_BUS GENMASK(23, 16) +#define OF_PCI_ADDR_FIELD_DEV GENMASK(15, 11) +#define OF_PCI_ADDR_FIELD_FUNC GENMASK(10, 8) +#define OF_PCI_ADDR_FIELD_REG GENMASK(7, 0) + +enum of_pci_prop_compatible { + PROP_COMPAT_PCI_VVVV_DDDD, + PROP_COMPAT_PCICLASS_CCSSPP, + PROP_COMPAT_PCICLASS_CCSS, + PROP_COMPAT_NUM, +}; + +static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr, + u32 reg_num, u32 flags, bool reloc) +{ + prop[0] = FIELD_PREP(OF_PCI_ADDR_FIELD_BUS, pdev->bus->number) | + FIELD_PREP(OF_PCI_ADDR_FIELD_DEV, PCI_SLOT(pdev->devfn)) | + FIELD_PREP(OF_PCI_ADDR_FIELD_FUNC, PCI_FUNC(pdev->devfn)); + prop[0] |= flags | reg_num; + if (!reloc) { + prop[0] |= OF_PCI_ADDR_FIELD_NONRELOC; + prop[1] = upper_32_bits(addr); + prop[2] = lower_32_bits(addr); + } +} + +static int of_pci_get_addr_flags(struct resource *res, u32 *flags) +{ + u32 ss; + + if (res->flags & IORESOURCE_IO) + ss = OF_PCI_ADDR_SPACE_IO; + else if (res->flags & IORESOURCE_MEM_64) + ss = OF_PCI_ADDR_SPACE_MEM64; + else if (res->flags & IORESOURCE_MEM) + ss = OF_PCI_ADDR_SPACE_MEM32; + else + return -EINVAL; + + *flags = 0; + if (res->flags & IORESOURCE_PREFETCH) + *flags |= OF_PCI_ADDR_FIELD_PREFETCH; + + *flags |= FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss); + + return 0; +} + +static int of_pci_prop_bus_range(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + u32 bus_range[] = { pdev->subordinate->busn_res.start, + pdev->subordinate->busn_res.end }; + + return of_changeset_add_prop_u32_array(ocs, np, "bus-range", bus_range, + ARRAY_SIZE(bus_range)); +} + +static int of_pci_prop_ranges(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_pci_range *rp; + struct resource *res; + u32 flags, num; + int i, j, ret; + u64 val64; + + if (pci_is_bridge(pdev)) { + num = PCI_BRIDGE_RESOURCE_NUM; + res = &pdev->resource[PCI_BRIDGE_RESOURCES]; + } else { + num = PCI_STD_NUM_BARS; + res = &pdev->resource[PCI_STD_RESOURCES]; + } + + rp = kcalloc(num, sizeof(*rp), GFP_KERNEL); + if (!rp) + return -ENOMEM; + + for (i = 0, j = 0; j < num; j++) { + if (!resource_size(&res[j])) + continue; + + if (of_pci_get_addr_flags(&res[j], &flags)) + continue; + + val64 = res[j].start; + of_pci_set_address(pdev, rp[i].parent_addr, val64, 0, flags, + false); + if (pci_is_bridge(pdev)) { + memcpy(rp[i].child_addr, rp[i].parent_addr, + sizeof(rp[i].child_addr)); + } else { + /* + * For endpoint device, the lower 64-bits of child + * address is always zero. + */ + rp[i].child_addr[0] = j; + } + + val64 = resource_size(&res[j]); + rp[i].size[0] = upper_32_bits(val64); + rp[i].size[1] = lower_32_bits(val64); + + i++; + } + + ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp, + i * sizeof(*rp) / sizeof(u32)); + kfree(rp); + + return ret; +} + +static int of_pci_prop_reg(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + struct of_pci_addr_pair reg = { 0 }; + + /* configuration space */ + of_pci_set_address(pdev, reg.phys_addr, 0, 0, 0, true); + + return of_changeset_add_prop_u32_array(ocs, np, "reg", (u32 *)®, + sizeof(reg) / sizeof(u32)); +} + +static int of_pci_prop_compatible(struct pci_dev *pdev, + struct of_changeset *ocs, + struct device_node *np) +{ + const char *compat_strs[PROP_COMPAT_NUM] = { 0 }; + int i, ret; + + compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] = + kasprintf(GFP_KERNEL, "pci%x,%x", pdev->vendor, pdev->device); + compat_strs[PROP_COMPAT_PCICLASS_CCSSPP] = + kasprintf(GFP_KERNEL, "pciclass,%06x", pdev->class); + compat_strs[PROP_COMPAT_PCICLASS_CCSS] = + kasprintf(GFP_KERNEL, "pciclass,%04x", pdev->class >> 8); + + ret = of_changeset_add_prop_string_array(ocs, np, "compatible", + compat_strs, PROP_COMPAT_NUM); + for (i = 0; i < PROP_COMPAT_NUM; i++) + kfree(compat_strs[i]); + + return ret; +} + +int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np) +{ + int ret; + /* + * The added properties will be released when the + * changeset is destroyed. + */ + if (pci_is_bridge(pdev)) { + ret = of_changeset_add_prop_string(ocs, np, "device_type", + "pci"); + if (ret) + return ret; + + ret = of_pci_prop_bus_range(pdev, ocs, np); + if (ret) + return ret; + } + + ret = of_changeset_add_empty_prop(ocs, np, "dynamic"); + if (ret) + return ret; + + ret = of_pci_prop_ranges(pdev, ocs, np); + if (ret) + return ret; + + ret = of_changeset_add_prop_u32(ocs, np, "#address-cells", + OF_PCI_ADDRESS_CELLS); + if (ret) + return ret; + + ret = of_changeset_add_prop_u32(ocs, np, "#size-cells", + OF_PCI_SIZE_CELLS); + if (ret) + return ret; + + ret = of_pci_prop_reg(pdev, ocs, np); + if (ret) + return ret; + + ret = of_pci_prop_compatible(pdev, ocs, np); + if (ret) + return ret; + + return 0; +} diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 2475098f6518..686836afee1c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -678,6 +678,21 @@ static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_br #endif /* CONFIG_OF */ +struct of_changeset; + +#ifdef CONFIG_PCI_DYNAMIC_OF_NODES +void of_pci_make_dev_node(struct pci_dev *pdev); +void of_pci_remove_node(struct pci_dev *pdev); +int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, + struct device_node *np); +#else +static inline void +of_pci_make_dev_node(struct pci_dev *pdev) { } + +static inline void +of_pci_remove_node(struct pci_dev *pdev) { } +#endif + #ifdef CONFIG_PCIEAER void pci_no_aer(void); void pci_aer_init(struct pci_dev *dev); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d68aee29386b..d749ea8250d6 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -22,6 +22,7 @@ static void pci_stop_dev(struct pci_dev *dev) device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); + of_pci_remove_node(dev); pci_dev_assign_added(dev, false); } From patchwork Thu Jun 29 17:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 114385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9801716vqr; Thu, 29 Jun 2023 10:36:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPfNZf7R/TPRJ1m5bcOj9ccW/NQobWYYH119rXom1Y2BYTkVVxdW4ZM2iG7x37FFPGrpPZ X-Received: by 2002:a17:90a:be16:b0:262:c2a1:c029 with SMTP id a22-20020a17090abe1600b00262c2a1c029mr170585pjs.2.1688060214610; Thu, 29 Jun 2023 10:36:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688060214; cv=pass; d=google.com; s=arc-20160816; b=db6vG9VcykP+urIHAzueP6CAehj5fDDSuHDCIM0FkpYlOBrrY7f1ACrBEnylsVVVFE z52wZEcpQneLsHQ61ebEoAJBN3aFqLyXa9nP6MBxfr5AthhuO7slPQgMHqSmIlfUBxY1 n68465hcbLvomYSl7mFM1NH8nw9P14ItLWx6zf3aas5ODC6p4lZSf9hJOvWtkuuwd5Az kltjyZa0fJF2X/OVD+qFimhGv3betVUagp0SaIIwgcbErnBFHi6gxlYg2gVRvkM8xeFO bjL0lzXmARhwHDtI0VBw08eBGDirACUkGqLfPHrRJ1mj2wOdDDrlHYtUg0y7JVRF0/sw HTZA== 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=fo7Bu/GzrPUkr5dkLA3jBt/YqWwxSRIJBa4m8KooXlw=; fh=Dp1cBGMGbwAqoabrudJCB/xGaYuol06NcbmMGQv1HC4=; b=iPZN2T0LYtOVIXsc9djwur9R+0gVO3Mrvs2vPclrV4tLkjq/bIspK6C/GlHqUVQeJK NX5k+2MHiY6Q6xIgfnssEq9rM9nfVS4hDCi6FNnYGOJH4+I53Yy5TWN/jRBVOjg+3GTJ 7k82uqgH+LJTmeUv7uWUT8BVVvUFmkrkZ1yLze0cBhs8vsPtZqKRwsytNWBfziUUL7la XpkPGrDZWaIPwWBTk3YbqG2wB1LQc2WOnN6vLc/rpL6IG6GYOZl/5xhVvjfKP2xCfhHY BsYBZudn4e/5TzwarpUeUbzB1rSzB2LR0zJVZcolnAiVvnJZHAuCRImC/kFN7QoN16n+ qzDg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=MiZ0Swu3; 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 r17-20020a632b11000000b005538d9fe498si11335343pgr.414.2023.06.29.10.36.38; Thu, 29 Jun 2023 10:36:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=MiZ0Swu3; 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 S232287AbjF2Rbx (ORCPT + 99 others); Thu, 29 Jun 2023 13:31:53 -0400 Received: from mail-sn1nam02on2044.outbound.protection.outlook.com ([40.107.96.44]:7495 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231883AbjF2Rbh (ORCPT ); Thu, 29 Jun 2023 13:31:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PihOkmm85XGZ4AeuTON5JtRwwbdMTgazc/VaXVx4dbcuV9WcxYJkk/9S9c6415NHHxa0lW5vbecvnnOkHgRCxlGSKqzNG3mfQdyDK/Ujj9DxB6C7gs8sBMoIM4/owSN1hmo/ye/niNBzh5s8RVlJmtXJzqS2rt8MOFNX5NFvcZ4LCT1DNL1jMdT5O0uFpfyFW2xqLXggR7yEm6c1y2GJTkUfFAbzFsZ3UFAmMXltVaF3GafdTYAO4jJBq7V682ys5bPEQIEPH1cF/x94AGd9mvV0kC6RXpBBaiV6h77Gt4DyO8ogE3RLdDHyhmhT8g4Yi8xkWEUXVkAebMdlBrY+Cw== 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=fo7Bu/GzrPUkr5dkLA3jBt/YqWwxSRIJBa4m8KooXlw=; b=hZP5ZKJyneJeHFJh3PmXYEBjPAhYFdx3ISjZ+uxBORbtkRBNtZydZOn7yxC9RxVBU52HvMwRi2rGL8WvxGscOLl+LE1J22e87I+9zACwdBIZt41vmjU+9YSF8XjjLFZhC+rCCZjZVdqfvt6Z7+7YcD/82clT8EDurv0OI6EXqkqeDFiFTs+bGTfH7cfYP/0DBUw6c0xG9A4axLQE8KZjshmzPa+FRJj7tXiRfoA1Ur7LzRyR8M+x9qT+dOn/ID77AI6l+4FWNGQr/Nl/DMdIo81Ix4UhpxcJH0fGbgdf/aVrDpWHQFu2TeZYRlp2++4Pue+c7TrpzGVM/P/HodB0Ew== 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=fo7Bu/GzrPUkr5dkLA3jBt/YqWwxSRIJBa4m8KooXlw=; b=MiZ0Swu3JDlQElI+JnS5vEeKn71sw7FH4STglwWlifCre79VxGnnmluEggx77R4o3JYpOPHt56mzC+GO5nu0BMM9RTEiMVObk75bPmcgLG3qOYEWqdTkaTM/O5HLhIJ4ysodxrIse60Lo7rVKYpHEPCXy2VMnWPQQK6S9Y+BWLE= Received: from BN6PR17CA0059.namprd17.prod.outlook.com (2603:10b6:405:75::48) by LV2PR12MB5728.namprd12.prod.outlook.com (2603:10b6:408:17c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Thu, 29 Jun 2023 17:31:32 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::70) by BN6PR17CA0059.outlook.office365.com (2603:10b6:405:75::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Thu, 29 Jun 2023 17:31:32 +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 BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.49 via Frontend Transport; Thu, 29 Jun 2023 17:31:32 +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.2507.23; Thu, 29 Jun 2023 12:31:31 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 29 Jun 2023 12:31:30 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V10 3/5] PCI: Add quirks to generate device tree node for Xilinx Alveo U50 Date: Thu, 29 Jun 2023 10:19:48 -0700 Message-ID: <1688059190-4225-4-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> References: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT048:EE_|LV2PR12MB5728:EE_ X-MS-Office365-Filtering-Correlation-Id: 7204f461-03f0-486f-7269-08db78c6adf7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +kqDKYx0gW1uKfPSXqYUfzk30d3SgUKtWbxr+LzhQG+fb0W2bjaKsRaOb58ByRo/OndrUtNM76ttKMfEsHE1AJk+/y7isXuXYlYfGnGSysPlBLWoIfgcNQrqLGeFLpendhEeYI1U+aJAOoQnB3GeYtFJsyso2o4ltqvCPnMpbNBhjWSPTBLHB54Su0rrtWZOQjb0R4tPaH6D6PwHkk9/5OmJjnI7PaMYxZrVBaQcV9S3up06dcO+DV9wWOT5aVSYFWaRnWSF7lwkNLLhBCnxIOyyP2lohLZes3szcPD5s+ETmlq8muByNkaOcn1ZfoF1s3CjAO21A80wSMw12mSai8lVbIKneBgiSLib05fP4LQyz4O07J/2Bg2Q55FggTLPfWyeNxD6yZ1E5gycwT7PE6vOyPYloXT117UPk6hdfuH47hMRKfg5rGYzVtUqGJwjOPiKBDCr4rcCrMhqXGA4LEUzFqlGq1jzhed7AEKeOESlYnfy6/XkRDMNDwAagjtnuMFmQGAeq/QQefKaDRear4aXP3eKCSka8rE++V3+kUmtvgdKVbtoWA7AmD6unOQrCFrJBt1v7DMhHeM8KEojgeJBzsAeJrazsXMMOZecj+tUHbl98I+Ov1agfMMcnFAe7YMZ756AjNc8fREejKEAvlfmYuDnNrPXcJEmKije2wR1n10bzCOZfflcsyjX22ReRCqZ6geBYn0uEnDjSOSNm3zfQrcANsQkpoMorSgCK5kMxX/N/LcaQQQuyXfNCANU9skXjBTANUwbCWwBFp3hiA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(396003)(136003)(346002)(451199021)(36840700001)(40470700004)(46966006)(82310400005)(36860700001)(26005)(36756003)(82740400003)(70206006)(41300700001)(44832011)(86362001)(47076005)(356005)(40480700001)(8676002)(4326008)(81166007)(70586007)(8936002)(40460700003)(316002)(110136005)(5660300002)(186003)(6666004)(2906002)(2616005)(478600001)(54906003)(426003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 17:31:32.0121 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7204f461-03f0-486f-7269-08db78c6adf7 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: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5728 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?1770059427370507463?= X-GMAIL-MSGID: =?utf-8?q?1770059427370507463?= The Xilinx Alveo U50 PCI card exposes multiple hardware peripherals on its PCI BAR. The card firmware provides a flattened device tree to describe the hardware peripherals on its BARs. This allows U50 driver to load the flattened device tree and generate the device tree node for hardware peripherals underneath. To generate device tree node for U50 card, add PCI quirks to call of_pci_make_dev_node() for U50. Signed-off-by: Lizhi Hou Acked-by: Bjorn Helgaas --- drivers/pci/quirks.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index c525867760bf..7776012eb03f 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6041,3 +6041,15 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); #endif + +/* + * For a PCI device with multiple downstream devices, its driver may use + * a flattened device tree to describe the downstream devices. + * + * To overlay the flattened device tree, the PCI device and all its ancestor + * devices need to have device tree nodes on system base device tree. Thus, + * before driver probing, it might need to add a device tree node as the final + * fixup. + */ +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node); +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node); From patchwork Thu Jun 29 17:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 114386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9801966vqr; Thu, 29 Jun 2023 10:37:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlHLrAHNvWNc9MvSeNYtOMRqiSwnnwiKku65+ZPixg+9kUPlbTsOy8At8i8oUgYXwiiLXOBr X-Received: by 2002:aa7:980a:0:b0:677:bb4c:c321 with SMTP id e10-20020aa7980a000000b00677bb4cc321mr698052pfl.0.1688060245102; Thu, 29 Jun 2023 10:37:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688060245; cv=pass; d=google.com; s=arc-20160816; b=MSSzJg3M8eRO2nVo4JWN2NaR0XhgGYrVb5fhRe+LhWiodGCDsIkE4plgKRbsP+xER/ dlWWijNn8nmHbpygRXk9KeT3EdSXfjovVvFoz7pOsStHNc3UI26tYXXeueRH+dxI7ebI aPDymoBNLCj55YTBUdoUp8/aHTPd1Oa+MY5E6yhsP8nb8fBuop4qNt7XbHwpc0tndy7C T2Ce705qVsSSSCc63aMtXwQtAxiy80oQ8ZMiuNI+66HqFKRJ/8tR6oWia8VbzOKz4DhX Ktf4N3bVfc9lLzmLb4hrhiEznvM/tltDo3KQ5KmXZWEjTmF9gCYRQvRGXKbIZpWOG6pS OhEg== 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=hkO4axAxsQcsEdDXAFikKnXxzjh1KpezGHQRB3mLF7s=; fh=Dp1cBGMGbwAqoabrudJCB/xGaYuol06NcbmMGQv1HC4=; b=U54Mfl1OwvdkkdKHF4hYy6m38pLJBoPQ0yHqXq3qEeDsZSrunJY7R5vaiNEteRmz44 BB99g7LOnA+7WcmXTvyTqszJGl+bVkCHV/7/+ah2cmyjqum5htcOjhhrkHSOSpWZ1pNk CQ+xaO1twethNxw+zdX4cHfhd7h5BahQwTAzencRTqDEk3u5vVaRc6ktoeW5T+iii/vG UctTGzU2U7LdFCNa4ddIkV420QO3DubT1v0ro+cBJW1kl4kuilL54/p1k4ot0i65sahU RhAYUjSMb9CgVtLTCIPYCrTtCpNCniNx2SJVfzspm9SNzv9KUY372uA499PBBwBDuWMI +ozQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ZvqO82d1; 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 x4-20020a63db44000000b00534784002afsi11133895pgi.807.2023.06.29.10.37.07; Thu, 29 Jun 2023 10:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ZvqO82d1; 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 S232246AbjF2Rbp (ORCPT + 99 others); Thu, 29 Jun 2023 13:31:45 -0400 Received: from mail-mw2nam12on2068.outbound.protection.outlook.com ([40.107.244.68]:53963 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231634AbjF2Rbf (ORCPT ); Thu, 29 Jun 2023 13:31:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PhlwkRqxOgLSJPY07AzKfy9LpvhOgS4esEs8calgcniRTQ6U+8jH9LQ1g85bX/NUBOw+WJC8Bv0R45l0X3IqD3KZTnWGLQgkckZXnALAVIyJ2Nr2hecn6YkvxaqYaCm40WnbM0LHicb5ZGrxj1vEuVlT8KmwNneG9WCvF+9kyYUUcIqs4CFmqoqch1RyQEmugubNJydoVs2WDUhMYHnqvnNkhaAm0fILxRRDWHXNn4PYgTeBI2CMNt8BpsRa2sz7cVIX35C0+r3aynk0MnvsmJKeKn+zaVLSatAimxWE9bW+Us4QJpTmtsNV/kghs/LkV1W4rJNV4jlFHvlvJRy+ng== 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=hkO4axAxsQcsEdDXAFikKnXxzjh1KpezGHQRB3mLF7s=; b=L40zSDCoUf6LmE3/zrHCCeKeO0ixPqtfWSxGxQlLQegfvva1YryzVk5mEFroImc0n3jXhE3BZ+ZoUHy6l0JVD259fzTNimd2rLTi8sR+MJYW0vwjGV01Ml7ymjk2ajgh9WFx0vAvFKy7Tu30dpSSN8rvNqQc3WAdobShnF87PYH7+3LXrFVvTButLAs9qAbOWG58WpqPiOtfq2RgFeGRufBZSdqys7faai/QT+zhh9PATbFHNU/zpiJd1rDxGnmQyCw7FdzOuf+McdS6g+UXNbrZ0R4oVS2CqtcAXlclUFul9O9IGFn9cTUp2UV+O5Ai+TdCD2DwhIOCf9fs/6DFnw== 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=hkO4axAxsQcsEdDXAFikKnXxzjh1KpezGHQRB3mLF7s=; b=ZvqO82d1qrHvRWVs3dROzEaJQsxaeL6NVxMnv4lToNJsROpjkhOUgwRh6hd914wGmT5lefsqRbNOENTEWKcSnlwjl7N15GgtjO4sZZVDoxNdSX7fpl199g8PEa00dgJybE7rJ5mhV6WehNi/GMMblFSIMiCMyJfhkX8hY/mlxpo= Received: from BN6PR17CA0050.namprd17.prod.outlook.com (2603:10b6:405:75::39) by CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.15; Thu, 29 Jun 2023 17:31:32 +0000 Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::14) by BN6PR17CA0050.outlook.office365.com (2603:10b6:405:75::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Thu, 29 Jun 2023 17:31:32 +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 BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.49 via Frontend Transport; Thu, 29 Jun 2023 17:31:32 +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.2507.23; Thu, 29 Jun 2023 12:31:32 -0500 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 29 Jun 2023 12:31:31 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V10 4/5] of: overlay: Extend of_overlay_fdt_apply() to specify the target node Date: Thu, 29 Jun 2023 10:19:49 -0700 Message-ID: <1688059190-4225-5-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> References: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT048:EE_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: 3671aa4f-4c64-40d0-f5d9-08db78c6ae5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VtgPQMcURl0YV1ycqfPw5SOWMR4mVkRP/14Hhy81tSE63xnxwqieDNPnUcCDiObnhMbEoS7HNe57TOFxdjTCT7Ifc73nyVXptvbj98pLlicO9Ti3Ix0T8HKd/R9/ZKmCShA1PpNbx7E8hlL6ihrsOK/Vx3qc3HnKzfWgAQ0H5uxerxd2NX8+fBSHuw2Biq8Ahtgkp5Y489B5xznuFK5k889l9UCliQgW8CrhDSpTXNPjKThTcwjr1j0G/n+E6BBkf42YNuMgDGI4JNCBdUlirfrpCbhMLVhiGC2KFmb9ifVY+93uuWKMdpYIqR+Ku1ibgjccTVfJEAHroY7PhByusX13f8LffXSNzdwFxcYJmU2Uu6AqJ1chARZu7DnX0NGZ/ERpeTc20SuQ6dmLEqT3RPerj+h3JhezM0U2tFqALePHCk07JwLnjlPOfkvDCjdgJOSUC/Vob1gLVMp0Qm98FcFmTSG01Lb0z3Zg188gHRIpVWJRz/BLC6XtBFNVwNF9NX4dsWeQgdCwcrr228wkG9g8MohY/rbSe2EYHZx6MwhTVUX4XWesyIpA4yJ5T7qQ9zn1OLdkV3aLfE3i6xEsgfYAm5HswQcoPrtE3o/usLQ2Hz2cUU2KmeMwcBkwwFgiZcN8GCqTsrFrkA9gTRdnUQae/w1R2mA2TULNbGgkpQ7bLzR5YdQ9jdyo+ZWe5A3L6QeAsTCT3Tl7gLsf/l+gsDotest6+UNpNCk2xUAfYxk2em8QxPUfbrjCpXCyPeW6ITh5J/ilPv1VEtZkmMJ68A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(39860400002)(396003)(376002)(451199021)(40470700004)(46966006)(36840700001)(40460700003)(82310400005)(356005)(6666004)(82740400003)(2616005)(81166007)(83380400001)(26005)(186003)(336012)(426003)(47076005)(36860700001)(40480700001)(41300700001)(110136005)(86362001)(54906003)(316002)(2906002)(36756003)(70206006)(70586007)(4326008)(44832011)(5660300002)(8936002)(478600001)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 17:31:32.6839 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3671aa4f-4c64-40d0-f5d9-08db78c6ae5d 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: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 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?1770059459912367803?= X-GMAIL-MSGID: =?utf-8?q?1770059459912367803?= Currently, in an overlay fdt fragment, it needs to specify the exact location in base DT. In another word, when the fdt fragment is generated, the base DT location for the fragment is already known. There is new use case that the base DT location is unknown when fdt fragment is generated. For example, the add-on device provide a fdt overlay with its firmware to describe its downstream devices. Because it is add-on device which can be plugged to different systems, its firmware will not be able to know the overlay location in base DT. Instead, the device driver will load the overlay fdt and apply it to base DT at runtime. In this case, of_overlay_fdt_apply() needs to be extended to specify the target node for device driver to apply overlay fdt. int overlay_fdt_apply(..., struct device_node *base); Signed-off-by: Lizhi Hou --- drivers/of/overlay.c | 42 +++++++++++++++++++++++++++++++----------- drivers/of/unittest.c | 3 ++- include/linux/of.h | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 7feb643f1370..6f3ae30c878d 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -682,9 +682,11 @@ static int build_changeset(struct overlay_changeset *ovcs) * 1) "target" property containing the phandle of the target * 2) "target-path" property containing the path of the target */ -static struct device_node *find_target(struct device_node *info_node) +static struct device_node *find_target(struct device_node *info_node, + struct device_node *target_base) { struct device_node *node; + char *target_path; const char *path; u32 val; int ret; @@ -700,10 +702,23 @@ static struct device_node *find_target(struct device_node *info_node) ret = of_property_read_string(info_node, "target-path", &path); if (!ret) { - node = of_find_node_by_path(path); - if (!node) - pr_err("find target, node: %pOF, path '%s' not found\n", - info_node, path); + if (target_base) { + target_path = kasprintf(GFP_KERNEL, "%pOF%s", target_base, path); + if (!target_path) + return NULL; + node = of_find_node_by_path(target_path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, target_path); + } + kfree(target_path); + } else { + node = of_find_node_by_path(path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, path); + } + } return node; } @@ -715,6 +730,7 @@ static struct device_node *find_target(struct device_node *info_node) /** * init_overlay_changeset() - initialize overlay changeset from overlay tree * @ovcs: Overlay changeset to build + * @target_base: Point to the target node to apply overlay * * Initialize @ovcs. Populate @ovcs->fragments with node information from * the top level of @overlay_root. The relevant top level nodes are the @@ -725,7 +741,8 @@ static struct device_node *find_target(struct device_node *info_node) * detected in @overlay_root. On error return, the caller of * init_overlay_changeset() must call free_overlay_changeset(). */ -static int init_overlay_changeset(struct overlay_changeset *ovcs) +static int init_overlay_changeset(struct overlay_changeset *ovcs, + struct device_node *target_base) { struct device_node *node, *overlay_node; struct fragment *fragment; @@ -786,7 +803,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs) fragment = &fragments[cnt]; fragment->overlay = overlay_node; - fragment->target = find_target(node); + fragment->target = find_target(node, target_base); if (!fragment->target) { of_node_put(fragment->overlay); ret = -EINVAL; @@ -877,6 +894,7 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * * of_overlay_apply() - Create and apply an overlay changeset * @ovcs: overlay changeset + * @base: point to the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -900,7 +918,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * the caller of of_overlay_apply() must call free_overlay_changeset(). */ -static int of_overlay_apply(struct overlay_changeset *ovcs) +static int of_overlay_apply(struct overlay_changeset *ovcs, + struct device_node *base) { int ret = 0, ret_revert, ret_tmp; @@ -908,7 +927,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) if (ret) goto out; - ret = init_overlay_changeset(ovcs); + ret = init_overlay_changeset(ovcs, base); if (ret) goto out; @@ -952,6 +971,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) * @overlay_fdt: pointer to overlay FDT * @overlay_fdt_size: number of bytes in @overlay_fdt * @ret_ovcs_id: pointer for returning created changeset id + * @base: pointer for the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -967,7 +987,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) */ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ret_ovcs_id) + int *ret_ovcs_id, struct device_node *base) { void *new_fdt; void *new_fdt_align; @@ -1037,7 +1057,7 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, } ovcs->overlay_mem = overlay_mem; - ret = of_overlay_apply(ovcs); + ret = of_overlay_apply(ovcs, base); /* * If of_overlay_apply() error, calling free_overlay_changeset() may * result in a memory leak if the apply partly succeeded, so do NOT diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1193a574fa36..4a0774954b93 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3506,7 +3506,8 @@ static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id) if (!size) pr_err("no overlay data for %s\n", overlay_name); - ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id); + ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id, + NULL); if (ovcs_id) *ovcs_id = info->ovcs_id; if (ret < 0) diff --git a/include/linux/of.h b/include/linux/of.h index 703152181a44..c989a5400da4 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1671,7 +1671,7 @@ struct of_overlay_notify_data { #ifdef CONFIG_OF_OVERLAY int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ovcs_id); + int *ovcs_id, struct device_node *target_base); int of_overlay_remove(int *ovcs_id); int of_overlay_remove_all(void); From patchwork Thu Jun 29 17:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 114387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9801974vqr; Thu, 29 Jun 2023 10:37:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6S+zJm8puSAbapljY1fNPzxbcD7e8u+TMgTCUlR0AZT43/5pjxAE7UWhF/PDtab/vxCTc4 X-Received: by 2002:a05:6a21:6d82:b0:11f:985e:ae2c with SMTP id wl2-20020a056a216d8200b0011f985eae2cmr522306pzb.3.1688060245723; Thu, 29 Jun 2023 10:37:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688060245; cv=pass; d=google.com; s=arc-20160816; b=KxaaDGu5/lL+Pves9z2+gk/r6cfTSEhaG3S/yVJ+5AA4p7zrnOuJQzJv/Hw098dF9+ /Q4uCV+7T1/t9IQFMhgB9pY1p/jBKru4FL0UvccrNb9YXuOWBNqd4pB/kJ6DT3x1+gu3 Wk34pIFLlcPoXO2dgkzhr/h/tA41gli5IEDyntAtk/RcENEqVlSJo52vurL3AI26/vl5 0lhoN0+41qf5/FkMFXMVs9jr41bg9XIIwFWRInCRQzVODaDPdzmTmK+Gubm1co9XhCjC 6GFkeqc/mQbEbPA9qkQ5at1fITv7387t81g+eky73eFzCjxoeOW2pza5wLOhQ/opbgyJ DF8g== 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=GnXGVADUDbzD5PUDX8Q7921oY36OEu3Owz9DxYFzUR0=; fh=Dp1cBGMGbwAqoabrudJCB/xGaYuol06NcbmMGQv1HC4=; b=F3OW8Ja/NcyBJpM6LU/CN0oWnIOjCI+VnshfgAWD51YIf8n9dPe1KR6ne6xeTUxRXu 7AVFAYTULUe2MSKS4tQDq+yzmBavgKxgqhQoC/7ahhmeQHenVjRIQLfjitg8yj1FFncb jWhRELHRWn7nSKsdDOlD3ethY4Bvw16sJmF+Cc4Imj9fuoK2MBOS1pJbhz85RM5NFliU ozKpeR0PuE3Wz8sxX59uHRjTaWmwt12D9ljiBbnPlOViLFCAEJcXDKOpUeJcoVVfbDI7 sjtfqlxW2CGx5LdUdSQdfG0vrCCM1yQWCi15e6u49gkfvk81/v+yEN2p1G5CIl+h3lor 3keQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=yVPayezT; 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 m64-20020a632643000000b005533ded45c5si11675186pgm.17.2023.06.29.10.37.11; Thu, 29 Jun 2023 10:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=yVPayezT; 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 S232302AbjF2Rb7 (ORCPT + 99 others); Thu, 29 Jun 2023 13:31:59 -0400 Received: from mail-bn8nam12on2072.outbound.protection.outlook.com ([40.107.237.72]:3168 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231989AbjF2Rbh (ORCPT ); Thu, 29 Jun 2023 13:31:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BVVOk1mtcGw3hAgS6IeM992xx825vQU5dq2N/IRGDiiQj8g8qiHurX7sVleScNcgREh9quD0jSu7XA6v0Qu41S3SWomrXPvnoQcGk+FbEl9/FDxuOq5RySowIgLgPbBbG12K2GzsuCOGkfNLwpLz0nyu/A9Q07NsIgaFH0I0talKIW8Y/4wlfNelyofDTCtkBK++/DRbU7fuOVc24qTXB1Nroiil8E4DUF8nvPGCT4OANxbDZrEUHptH7FPU5LrPAUBCnc9h8c3xUKM1M8oBmrfDLb7jQbBDfPwHuoGUH0IUXkHjc113w+5z8WMfU/Wo06F+LUkM5XyfeEI76L8a8g== 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=GnXGVADUDbzD5PUDX8Q7921oY36OEu3Owz9DxYFzUR0=; b=kKavPJ40VFHCC+z8gIQ60VkgBUiEMkL32vF3W7AVivXqkEQ5o9JWmqKZLYQaDk2xz9koNyFUIzw9XCr81i0IFyIFKNKRP1oAapYvaBNu2to9HrKlqiPSqyFqgQJyKa3vupfqntOBs1C8fbeHnKTHnYse55abHi3u+YSSdf/r9JSdPh7xlI4yQJYKS+Gw+dCdxiF8plK7EvAVYptN3JbQBzZ0y+KIc4rkPtfsfCZ5vGLg7vtuLTaY1Qw2o3fvYq9dF9E+eM7eMfQBqI+6HfVCYV++S1ikSvX5D96enPNtu8FSc4I+cFSnm8rG9u0Gk91H2BPTr+OZop0Vrl+DLrlIbA== 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=GnXGVADUDbzD5PUDX8Q7921oY36OEu3Owz9DxYFzUR0=; b=yVPayezT9ePW6CCBbheTnJ5KQ5xBenDgLaasdpnZoZkvB3J4Cvf3mClL3aH9D8SswICPo431WglCdP8VGMCg3OcZVIxKxQFe1JRyzM0/IF0ZJ6rRXYVJfu6tTbNwx8ynij0ZVH6u99znhpWYC6OpbriibEcY36pW/tQB1jEAsYk= Received: from BN9PR03CA0199.namprd03.prod.outlook.com (2603:10b6:408:f9::24) by BY5PR12MB4273.namprd12.prod.outlook.com (2603:10b6:a03:212::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Thu, 29 Jun 2023 17:31:34 +0000 Received: from BN8NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::73) by BN9PR03CA0199.outlook.office365.com (2603:10b6:408:f9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Thu, 29 Jun 2023 17:31:33 +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 BN8NAM11FT041.mail.protection.outlook.com (10.13.177.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.49 via Frontend Transport; Thu, 29 Jun 2023 17:31:33 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 12:31:33 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 29 Jun 2023 10:31:33 -0700 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Thu, 29 Jun 2023 12:31:32 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V10 5/5] of: unittest: Add pci_dt_testdrv pci driver Date: Thu, 29 Jun 2023 10:19:50 -0700 Message-ID: <1688059190-4225-6-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> References: <1688059190-4225-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT041:EE_|BY5PR12MB4273:EE_ X-MS-Office365-Filtering-Correlation-Id: ef37c43e-595c-460f-7834-08db78c6af09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LneLKef9rbblLYYrbqceX8HoGJYYS5cXmbnJ35drsFITq/5+KorlfrNk8OU9EhyY5lAfDziwimPoKQ67XEhgaUJ+S5/wFzuxghyYWD5gsSRp9ZcudhZrRdJKNlnlKQ7ob7y+zL3goDfv/IsgXwGlMBnJ2HD1Sp2wASAJsVo14hl8yIN2lUSFkKQh1j6o3M8lmkO8kCiTmrq42bz61nwVXchIslT4VfMYoN+1PUyZnb7YZlkdnfBrSsgDdrKOajbqizBCrpkSrWhTgZt11Wj/zPh1U0t/eDjYuXfkDaS8+mAxEY/QDGtkZc92BDF0QlrNEXSfbYo0JgwUwk7VEWG5JyGUPalFReLB6MyZMLeuLkRiAC3WTExjl4/klZlituymShvDU1KiBW8RRm24SLUQDsjjmokyyoySSX22dgx6lvlOshoMGFTQo+ER34BUZXIpJifVZxsLTzXm5x9azoC0TVSu74SxTUZDhBZ7hA4JHiNMzcgTNC3MeypoOU9upLljYVdBeR+mahY4oMHlOraihs2jZt/Q40zQaaBW5/YCQfyc/OLidtDRpleGNeSymGhmltPada9/SAfMlemg3rHFvWStcyyf6mXFMAPKNNWBP+FJtR9x8NHgJjnxhLi9nGKvQwnhka9VHR/xKRf74w4TSsN5FxObcnupxN7e/xgeXT7EMBe1Pq6klHdy1SoSmmiUSIaBL7t1GKaM70vQBs6OMAI+H7fpBF3+tdVjCyc/d3gkKaW97LIPEma3g41W+XVJQtwC8Iv+eobtJm88O9x3rg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199021)(36840700001)(46966006)(40470700004)(36756003)(82310400005)(36860700001)(81166007)(40480700001)(70206006)(40460700003)(82740400003)(356005)(86362001)(44832011)(5660300002)(316002)(41300700001)(4326008)(8936002)(8676002)(70586007)(47076005)(478600001)(186003)(2906002)(26005)(336012)(426003)(83380400001)(110136005)(6666004)(54906003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 17:31:33.8079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef37c43e-595c-460f-7834-08db78c6af09 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: BN8NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4273 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?1770059460248763000?= X-GMAIL-MSGID: =?utf-8?q?1770059460248763000?= pci_dt_testdrv is bound to QEMU PCI Test Device. It reads overlay_pci_node fdt fragment and apply it to Test Device. Then it calls of_platform_default_populate() to populate the platform devices. Signed-off-by: Lizhi Hou --- drivers/of/unittest-data/Makefile | 3 +- .../of/unittest-data/overlay_pci_node.dtso | 22 ++ drivers/of/unittest.c | 189 ++++++++++++++++++ drivers/pci/quirks.c | 1 + 4 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index ea5f4da68e23..1aa875088159 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -32,7 +32,8 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtbo.o \ overlay_gpio_02b.dtbo.o \ overlay_gpio_03.dtbo.o \ overlay_gpio_04a.dtbo.o \ - overlay_gpio_04b.dtbo.o + overlay_gpio_04b.dtbo.o \ + overlay_pci_node.dtbo.o # enable creation of __symbols__ node DTC_FLAGS_overlay += -@ diff --git a/drivers/of/unittest-data/overlay_pci_node.dtso b/drivers/of/unittest-data/overlay_pci_node.dtso new file mode 100644 index 000000000000..c05e52e9e44a --- /dev/null +++ b/drivers/of/unittest-data/overlay_pci_node.dtso @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/ { + fragment@0 { + target-path=""; + __overlay__ { + #address-cells = <3>; + #size-cells = <2>; + pci-ep-bus@0 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x0 0x0 0x0 0x1000>; + reg = <0 0 0 0 0>; + unittest-pci@100 { + compatible = "unittest-pci"; + reg = <0x100 0x200>; + }; + }; + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 4a0774954b93..ead54e47c063 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -3352,6 +3353,7 @@ OVERLAY_INFO_EXTERN(overlay_gpio_02b); OVERLAY_INFO_EXTERN(overlay_gpio_03); OVERLAY_INFO_EXTERN(overlay_gpio_04a); OVERLAY_INFO_EXTERN(overlay_gpio_04b); +OVERLAY_INFO_EXTERN(overlay_pci_node); OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node); OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop); OVERLAY_INFO_EXTERN(overlay_bad_phandle); @@ -3387,6 +3389,7 @@ static struct overlay_info overlays[] = { OVERLAY_INFO(overlay_gpio_03, 0), OVERLAY_INFO(overlay_gpio_04a, 0), OVERLAY_INFO(overlay_gpio_04b, 0), + OVERLAY_INFO(overlay_pci_node, 0), OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL), OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL), OVERLAY_INFO(overlay_bad_phandle, -EINVAL), @@ -3757,6 +3760,191 @@ static inline __init void of_unittest_overlay_high_level(void) {} #endif +#ifdef CONFIG_PCI_DYNAMIC_OF_NODES + +int of_unittest_pci_dev_num; +int of_unittest_pci_child_num; + +/* + * PCI device tree node test driver + */ +static const struct pci_device_id testdrv_pci_ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, 0x5), }, /* PCI_VENDOR_ID_REDHAT */ + { 0, } +}; + +static int testdrv_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct overlay_info *info; + struct device_node *dn; + int ret, ovcs_id; + u32 size; + + dn = pdev->dev.of_node; + if (!dn) { + dev_err(&pdev->dev, "does not find bus endpoint"); + return -EINVAL; + } + + for (info = overlays; info && info->name; info++) { + if (!strcmp(info->name, "overlay_pci_node")) + break; + } + if (!info || !info->name) { + dev_err(&pdev->dev, "no overlay data for overlay_pci_node"); + return -ENODEV; + } + + size = info->dtbo_end - info->dtbo_begin; + ret = of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn); + of_node_put(dn); + if (ret) + return ret; + + of_platform_default_populate(dn, NULL, &pdev->dev); + pci_set_drvdata(pdev, (void *)(uintptr_t)ovcs_id); + + return 0; +} + +static void testdrv_remove(struct pci_dev *pdev) +{ + int ovcs_id = (int)(uintptr_t)pci_get_drvdata(pdev); + + of_platform_depopulate(&pdev->dev); + of_overlay_remove(&ovcs_id); +} + +static struct pci_driver testdrv_driver = { + .name = "pci_dt_testdrv", + .id_table = testdrv_pci_ids, + .probe = testdrv_probe, + .remove = testdrv_remove, +}; + +static int unittest_pci_probe(struct platform_device *pdev) +{ + struct resource *res; + struct device *dev; + u64 exp_addr; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + dev = &pdev->dev; + while (dev && !dev_is_pci(dev)) + dev = dev->parent; + if (!dev) { + pr_err("unable to find parent device\n"); + return -ENODEV; + } + + exp_addr = pci_resource_start(to_pci_dev(dev), 0) + 0x100; + unittest(res->start == exp_addr, "Incorrect translated address %llx, expected %llx\n", + (u64)res->start, exp_addr); + + of_unittest_pci_child_num++; + + return 0; +} + +static const struct of_device_id unittest_pci_of_match[] = { + { .compatible = "unittest-pci" }, + { } +}; + +static struct platform_driver unittest_pci_driver = { + .probe = unittest_pci_probe, + .driver = { + .name = "unittest-pci", + .of_match_table = unittest_pci_of_match, + }, +}; + +static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add) +{ + struct device_node *pnp, *np = NULL; + struct device *child_dev; + char *path = NULL; + const __be32 *reg; + int rc = 0; + + pnp = pdev->dev.of_node; + unittest(pnp, "Failed creating PCI dt node\n"); + if (!pnp) + return -ENODEV; + + if (add) { + path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp); + np = of_find_node_by_path(path); + unittest(np, "Failed to get unittest-pci node under PCI node\n"); + if (!np) { + rc = -ENODEV; + goto failed; + } + + reg = of_get_property(np, "reg", NULL); + unittest(reg, "Failed to get reg property\n"); + if (!reg) + rc = -ENODEV; + } else { + path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp); + np = of_find_node_by_path(path); + unittest(!np, "Child device tree node is not removed\n"); + child_dev = device_find_any_child(&pdev->dev); + unittest(!child_dev, "Child device is not removed\n"); + } + +failed: + kfree(path); + if (np) + of_node_put(np); + + return rc; +} + +static void __init of_unittest_pci_node(void) +{ + struct pci_dev *pdev = NULL; + int rc; + + rc = pci_register_driver(&testdrv_driver); + unittest(!rc, "Failed to register pci test driver; rc = %d\n", rc); + if (rc) + return; + + rc = platform_driver_register(&unittest_pci_driver); + if (unittest(!rc, "Failed to register unittest pci driver\n")) { + pci_unregister_driver(&testdrv_driver); + return; + } + + while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) { + of_unittest_pci_node_verify(pdev, true); + of_unittest_pci_dev_num++; + } + if (pdev) + pci_dev_put(pdev); + + unittest(of_unittest_pci_dev_num, + "No test PCI device been found. Please run QEMU with '-device pci-testdev'\n"); + unittest(of_unittest_pci_dev_num == of_unittest_pci_child_num, + "Child device number %d is not expected %d", of_unittest_pci_child_num, + of_unittest_pci_dev_num); + + platform_driver_unregister(&unittest_pci_driver); + pci_unregister_driver(&testdrv_driver); + + while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) + of_unittest_pci_node_verify(pdev, false); + if (pdev) + pci_dev_put(pdev); +} +#else +static void __init of_unittest_pci_node(void) { } +#endif + static int __init of_unittest(void) { struct device_node *np; @@ -3807,6 +3995,7 @@ static int __init of_unittest(void) of_unittest_platform_populate(); of_unittest_overlay(); of_unittest_lifecycle(); + of_unittest_pci_node(); /* Double check linkage after removing testcase data */ of_unittest_check_tree_linkage(); diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 7776012eb03f..24860e1b76d4 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6053,3 +6053,4 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); */ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node); DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node); +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node);