From patchwork Mon Nov 30 01:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1407930 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=RmypYzOC; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4CkpGn58lJz9sTc for ; Mon, 30 Nov 2020 12:55:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 25D7582611; Mon, 30 Nov 2020 02:55:42 +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="RmypYzOC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D2262827B6; Mon, 30 Nov 2020 02:54:56 +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=-3.5 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-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 C780082633 for ; Mon, 30 Nov 2020 02:54:41 +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-io1-xd44.google.com with SMTP id k3so2317482ioq.4 for ; Sun, 29 Nov 2020 17:54:41 -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=HxSUmt6sA073KBq0i0gSj0Z7y+wiF6hI0pCnDBdbocQ=; b=RmypYzOCg1DYiDCagp6vx3H42atjTVPgK9q/YUYcnnbItrSrjI0ZJOPIB1WA7FtjYC YiI8Z2LM6m1cxCBoDEu3aKD8KEWj8CHY/Y+N9Z3BPZW88zD5qGHty7s8s8bh8lB2Nyp8 fCqWv0hmLfT8S6NkxwNYI6eeQNQk2xrEe+j+w= 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=HxSUmt6sA073KBq0i0gSj0Z7y+wiF6hI0pCnDBdbocQ=; b=OA+FEosU6zu1UtxXBoUGhdy14G1ec7XyN5nhlNgB5GOasJqnGsmCo4gm9yEetScJTN q3dcWzk/Gs2VyTifH1ZSnD3CQCr4VxUCPR1iPDkzKfK2Y2mPkBRqcaq4/IH2LbU40fDm kfyYnpDsTpvDBxgzamTphAusLF5zHwsaBdPYlw0utZ4vxXsdxMBSo19zWRW5z846eeH2 7IKD2ZMAeNkP8eTpFh0Rof9AzCsgzqdtBHio0aGkv8w3P4S8dYwIq6FI6bXrYgCQIs7J 1iEo4wY5mth2Lw93VfGC0nyAvMa6qSG1I2O7GRfQaVAshcQPjuz33jM3KPFlkZmaENgY DfrQ== X-Gm-Message-State: AOAM5316rWLpZywiOTJrhj8l0Ov+Q4F73POgRqZ8/MW1eWQeBzyNOqq9 6WYGayWJz4cZjDAz4ENsqooX5pkmLZVGyA== X-Google-Smtp-Source: ABdhPJz9BHr/kUfVOLh/6C39uWbZdvX4b0JL4AH84e0Y5IkeNdXSoZU+zID+d9nnOc1Dyi9N53laLw== X-Received: by 2002:a6b:8b4d:: with SMTP id n74mr8739857iod.121.1606701280295; Sun, 29 Nov 2020 17:54:40 -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 q5sm6543341ilg.62.2020.11.29.17.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 17:54:39 -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 05/27] dm: core: Add a new sequence number for devices Date: Sun, 29 Nov 2020 18:53:40 -0700 Message-Id: <20201130015402.2328621-4-sjg@chromium.org> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog In-Reply-To: <20201130015402.2328621-1-sjg@chromium.org> References: <20201130015402.2328621-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 each device has two sequence numbers, with 'req_seq' being set up at bind time and 'seq' at probe time. The idea is that devices can 'request' a sequence number and then the conflicts are resolved when the device is probed. This makes things complicated in a few cases, since we don't really know what the sequence number will end up being. We want to honour the bind-time requests if at all possible, but in fact the only source of these at present is the devicetree aliases. Since we have the devicetree available at bind time, we may as well just use it, in the hope that the required processing will turn out to be useful later (i.e. the device actually gets used). Add a new 'sqq' member, the bind-time sequence number. It operates in parallel to the old values for now. All devices get a valid sqq value, i.e. it is never -1. Drop an #ifdef while we are here. Signed-off-by: Simon Glass --- drivers/core/device.c | 22 ++++++++++++----- drivers/core/root.c | 21 +++++++++++++--- drivers/core/uclass.c | 40 +++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 2 ++ include/dm/device.h | 8 +++++++ include/dm/uclass.h | 8 +++++++ 6 files changed, 92 insertions(+), 9 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 5febdb67503..2f449b3e8fa 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -41,6 +41,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, struct udevice *dev; struct uclass *uc; int size, ret = 0; + bool auto_seq = false; if (devp) *devp = NULL; @@ -73,6 +74,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, dev->seq = -1; dev->req_seq = -1; + dev->sqq = -1; if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) && (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) { /* @@ -84,16 +86,24 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, */ if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { - if (uc->uc_drv->name && ofnode_valid(node)) + if (uc->uc_drv->name && ofnode_valid(node)) { + dev_read_alias_seq(dev, &dev->sqq); dev_read_alias_seq(dev, &dev->req_seq); -#if CONFIG_IS_ENABLED(OF_PRIOR_STAGE) - if (dev->req_seq == -1) - dev->req_seq = - uclass_find_next_free_req_seq(uc); -#endif + } + if (CONFIG_IS_ENABLED(OF_PRIOR_STAGE)) { + if (dev->req_seq == -1) { + auto_seq = true; + dev->req_seq = + uclass_find_next_free_req_seq( + uc); + } + } } else { + auto_seq = true; dev->req_seq = uclass_find_next_free_req_seq(uc); } + if (auto_seq && !(gd->flags & GD_FLG_DM_NO_SEQ)) + dev->sqq = uclass_find_next_free_req_seq(uc); } if (drv->platdata_auto_alloc_size) { diff --git a/drivers/core/root.c b/drivers/core/root.c index 6f8168bb92d..66aabc4b19b 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -308,25 +308,40 @@ int dm_init_and_scan(bool pre_reloc_only) debug("dm_init() failed: %d\n", ret); return ret; } + gd->flags |= GD_FLG_DM_NO_SEQ; ret = dm_scan_platdata(pre_reloc_only); if (ret) { debug("dm_scan_platdata() failed: %d\n", ret); - return ret; + goto fail; } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { ret = dm_extended_scan(pre_reloc_only); if (ret) { debug("dm_extended_scan() failed: %d\n", ret); - return ret; + goto fail; } } ret = dm_scan_other(pre_reloc_only); if (ret) - return ret; + goto fail; + + /* + * Now that all the alisas have been used to claim sequence numbers, we + * can allocate every non-aliased device a sequence number + */ + uclass_alloc_all_seqs(); + + /* + * From now on, assign sequence numbers when binding, to ensure that + * every new device has a sequence number too + */ + gd->flags &= ~GD_FLG_DM_NO_SEQ; return 0; +fail: + return ret; } #ifdef CONFIG_ACPIGEN diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index cdf0674cd82..d4de88bfb57 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -288,6 +288,46 @@ int uclass_find_next_free_req_seq(struct uclass *uc) return max + 1; } +static int uclass_find_first_free_seq(struct uclass *uc) +{ + struct udevice *dev; + bool in_use = true; + int cur; + + /* Increment cur until we get to a value not used in the devices */ + for (cur = 0; in_use;) { + in_use = false; + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (dev->sqq == cur) { + in_use = true; + cur++; + break; + } + } + } + + return cur; +} + +static void uclass_alloc_seqs(struct uclass *uc) +{ + struct udevice *dev; + + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (dev->sqq == -1) + dev->sqq = uclass_find_first_free_seq(uc); + } +} + +void uclass_alloc_all_seqs(void) +{ + struct uclass *uc; + + list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + uclass_alloc_seqs(uc); + } +} + int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 87d827d0f43..0179567a2bb 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -547,6 +547,8 @@ enum gd_flags { * @GD_FLG_SMP_READY: SMP initialization is complete */ GD_FLG_SMP_READY = 0x40000, + /** @GD_FLG_DM_NO_SEQ: Don't assign devices a sequence number on bind */ + GD_FLG_DM_NO_SEQ = 0x80000, }; #endif /* __ASSEMBLY__ */ diff --git a/include/dm/device.h b/include/dm/device.h index 9a171e523f3..80cd0955362 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -131,6 +131,13 @@ enum { * @child_head: List of children of this device * @sibling_node: Next device in list of all devices * @flags: Flags for this device DM_FLAG_... + * @sqq: Allocated sequence number for this device (-1 = none). This is set up + * when the device is bound and is unique within the device's uclass. If the + * device has an alias in the devicetree then that is used to set the sequence + * number. Otherwise, the next available number is used. Sequence numbers are + * used by certain commands that need device to be numbered (e.g. 'mmc dev') + * + * The following two fields are deprecated: * @req_seq: Requested sequence number for this device (-1 = any) * @seq: Allocated sequence number for this device (-1 = none). This is set up * when the device is probed and will be unique within the device's uclass. @@ -156,6 +163,7 @@ struct udevice { struct list_head child_head; struct list_head sibling_node; uint32_t flags; + int sqq; int req_seq; int seq; #ifdef CONFIG_DEVRES diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 71883043046..d1906236976 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -380,6 +380,14 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, */ int uclass_resolve_seq(struct udevice *dev); +/** + * uclass_alloc_all_seqs() - Make sure that all devices have sequence numbers + * + * This updates any sequence numbers that are unallocated (set to -1) to the + * next available number in the uclass, above all existing numbers + */ +void uclass_alloc_all_seqs(void); + /** * uclass_id_foreach_dev() - Helper function to iteration through devices *