From patchwork Sat Dec 19 17:40:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1418755 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=XWkY9AFL; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CytRY17t6z9sVm for ; Sun, 20 Dec 2020 04:45:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6279182E26; Sat, 19 Dec 2020 18:41:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="XWkY9AFL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31E4D82CFD; Sat, 19 Dec 2020 18:41:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 942C982886 for ; Sat, 19 Dec 2020 18:40:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x133.google.com with SMTP id v3so5205691ilo.5 for ; Sat, 19 Dec 2020 09:40:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YrDXUoyy+Pq8LnziVA6HzjO0HW2HQEQbK5FDvoXLICU=; b=XWkY9AFLUBbzk++7KzPE4Ugs706c/cJxD+lCty3dPh569wXV29bSzzS3wTQgtdXsen YrBPl5Lmvu5jsiW1/csuK8EI13oMfYSbyWCAOBG8X/pE9J16uRduhfQb2UYhgVHN64u2 zQBx+cIdpnaqrzJLzE8tR6nVLDqWEBopoyo2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YrDXUoyy+Pq8LnziVA6HzjO0HW2HQEQbK5FDvoXLICU=; b=dFMFdjoar0Ow1xGCs/0gRLcAGd/Lpsd0n5LLPBYZm5QJOmn87gM1zlL05CptvWc757 ZuHxcTHweYgFKJIG93T3aPFT2GpVl1ezkOUK2n2aR7HfNknxpyTXm4kPqZJwe8ed4j+o YXmtiG98+e82Ph7vm9OKdmRdeK5Re8sViDOIgUEsE0LL3qo4NbLC5byYLw5ccYwi4MFm 4AOFqSbcTUr5tcIqVcFKwZkmq7mNmj3f4MT1GVImDo4JD2CCTM2MNs9J8H6JrvvxGizE rn1Hbothpu+t9eAb8/QeGLRbUlcDwHr9Z9CUQFCzy8KB8/Hnm2bHFG5DJtDYI+HNOZi4 vteA== X-Gm-Message-State: AOAM5339FJOy5bC1JNLFnjkWHoIrm4/R9KN7TSLVmJe4jdT2VCSgPoRj MXAgzG43d0OIRL6iBm3QxFepB+BnMv2+dB7o X-Google-Smtp-Source: ABdhPJxbgIWsLgNlPmk4fYoe9l8xQkjM7+YSlm81xPsXH8ArOOCRPRC0ySEM6J1MjkNjYinf0tX4LA== X-Received: by 2002:a05:6e02:1bcb:: with SMTP id x11mr8948450ilv.32.1608399656104; Sat, 19 Dec 2020 09:40:56 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id n10sm9781962ila.69.2020.12.19.09.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 09:40:55 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Baruch Siach , Bin Meng , Heinrich Schuchardt , Marek Vasut , Masahiro Yamada , Pavel Herrmann , Peng Fan , Wolfgang Wallner Subject: [PATCH 25/26] dm: core: Allow the uclass list to move Date: Sat, 19 Dec 2020 10:40:17 -0700 Message-Id: <20201219174018.1114146-24-sjg@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201219174018.1114146-1-sjg@chromium.org> References: <20201219174018.1114146-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean At present the uclass list head is in global_data. This is convenient but with the new of-platdata we need the list head to be declared by the generated code. Change this over to be a pointer. Provide a 'static' version in global_data to retain the current behaviour. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/device.c | 4 ++-- drivers/core/root.c | 7 ++++--- drivers/core/uclass.c | 4 ++-- include/asm-generic/global_data.h | 8 +++++++- include/dm/device-internal.h | 1 + test/dm/core.c | 6 +++--- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 6a9bee093d0..aeab3836ed7 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -613,7 +613,7 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) struct udevice *dev; int ret; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret || dev) { @@ -1032,7 +1032,7 @@ int dev_disable_by_path(const char *path) if (!of_live_active()) return -ENOSYS; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret) break; diff --git a/drivers/core/root.c b/drivers/core/root.c index 2a5ebec27d8..3adbc94eb94 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -45,8 +45,8 @@ void dm_fixup_for_gd_move(struct global_data *new_gd) { /* The sentinel node has moved, so update things that point to it */ if (gd->dm_root) { - new_gd->uclass_root.next->prev = &new_gd->uclass_root; - new_gd->uclass_root.prev->next = &new_gd->uclass_root; + new_gd->uclass_root->next->prev = new_gd->uclass_root; + new_gd->uclass_root->prev->next = new_gd->uclass_root; } } @@ -136,7 +136,8 @@ int dm_init(bool of_live) dm_warn("Virtual root driver already exists!\n"); return -EINVAL; } - INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); + gd->uclass_root = &DM_UCLASS_ROOT_S_NON_CONST; + INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST); if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) { fix_drivers(); diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e773e34833e..cdb975d5b31 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -33,7 +33,7 @@ struct uclass *uclass_find(enum uclass_id key) * node to the start of the list, or creating a linear array mapping * id to node. */ - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { if (uc->uc_drv->id == key) return uc; } @@ -84,7 +84,7 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) uc->uc_drv = uc_drv; INIT_LIST_HEAD(&uc->sibling_node); INIT_LIST_HEAD(&uc->dev_head); - list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST); + list_add(&uc->sibling_node, DM_UCLASS_ROOT_NON_CONST); if (uc_drv->init) { ret = uc_drv->init(uc); diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 87d827d0f43..b63575919f0 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -194,7 +194,13 @@ struct global_data { /** * @uclass_root: head of core tree */ - struct list_head uclass_root; + struct list_head uclass_root_s; + /** + * @uclass_root: pointer to head of core tree, if uclasses are in + * read-only memory and cannot be adjusted to use @uclass_root as a + * list head. + */ + struct list_head *uclass_root; # if CONFIG_IS_ENABLED(OF_PLATDATA) /** Dynamic info about the driver */ struct driver_rt *dm_driver_rt; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 03b092bdf7d..639bbd293d9 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -288,6 +288,7 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr); /* Cast away any volatile pointer */ #define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root) #define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root) +#define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s) /* device resource management */ #ifdef CONFIG_DEVRES diff --git a/test/dm/core.c b/test/dm/core.c index 565896ed504..580d171e30e 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -116,14 +116,14 @@ static int dm_test_autobind(struct unit_test_state *uts) * device with no children. */ ut_assert(dms->root); - ut_asserteq(1, list_count_items(&gd->uclass_root)); + ut_asserteq(1, list_count_items(gd->uclass_root)); ut_asserteq(0, list_count_items(&gd->dm_root->child_head)); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); ut_assertok(dm_scan_plat(false)); /* We should have our test class now at least, plus more children */ - ut_assert(1 < list_count_items(&gd->uclass_root)); + ut_assert(1 < list_count_items(gd->uclass_root)); ut_assert(0 < list_count_items(&gd->dm_root->child_head)); /* Our 3 dm_test_infox children should be bound to the test uclass */ @@ -1073,7 +1073,7 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) struct udevice *dev; struct uclass *uc; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { list_for_each_entry(dev, &uc->dev_head, uclass_node) { if (dev->seq_ == -1) printf("Device '%s' has no seq (%d)\n",