Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41E3DC77B7A for ; Thu, 1 Jun 2023 16:30:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EB85586442; Thu, 1 Jun 2023 18:25:48 +0200 (CEST) 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="J0osaMxM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2D47C86358; Thu, 1 Jun 2023 18:25:18 +0200 (CEST) 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 863C586381 for ; Thu, 1 Jun 2023 18:25:04 +0200 (CEST) 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 e9e14a558f8ab-33b22221da6so3652875ab.1 for ; Thu, 01 Jun 2023 09:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685636686; x=1688228686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/4Omd7MCvTwyYZU7DDO1NUPxhn4Ho55V8F48HKYX4ck=; b=J0osaMxM4sK2eVCqxS7kWpT/EdmYvPa3cB1w8c6o20KEKfzuP0BIfbQOECRNB8O29v vCEHd6oMSaIzyZQmHzzIDDB+BG7Mp/GinKTwUbMQuTT53/+55u6ou2Vw2z0HMfNZSjZb Vca9MVTuuqDvlHvqMpb1m9s7iZ3jI1joMZq2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685636686; x=1688228686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/4Omd7MCvTwyYZU7DDO1NUPxhn4Ho55V8F48HKYX4ck=; b=jfyUEPeuBLjtpyEfcNjCLhbJrUVxq1pb7ofd/YkfzsmFt7piCD6ZrTohaNx5GzmRa1 0HsD28lElI4MUzBrvKJLgTvcVYCQj1hAGTmhNxntdI3X+P0koC2+H+cc9X6sUrPaMFaJ WPTv/D2S+bK3Q0QijHUE6lLwr+uGJA414PmW2ABTwMsyQvUmSClgosyYqfAlaMMOL3fv 9o4fL7kA6LXNHxajELV6F3cBxYJB2C6fPxtNRTCMtlSSWe5FeshhxVw2WkMe2H4QF/W7 4hC7Nz32QHS1pMaraZLtvZgs0TFOKzDVFdhgXVnGHofqEQtjn8dFr09fxwW3CuZzw6e3 DMJQ== X-Gm-Message-State: AC+VfDw3kjASBG9zRu/Wo480oUqISS8OfHmKsBd/Lqo9Ezpx7Zvw4PXF jHblqRdNxCcix47kg7Y2ErYYmWGH7pW7FPDd05o= X-Google-Smtp-Source: ACHHUZ5+JVqeSh5o4udqGvdJPYHKoc5QFEyFPRFM0tJ6/h91olAn3h0TFNSgACeEi+z2DAOXz+2Rzg== X-Received: by 2002:a92:dacd:0:b0:33b:ea2:fe6c with SMTP id o13-20020a92dacd000000b0033b0ea2fe6cmr6557505ilq.24.1685636685913; Thu, 01 Jun 2023 09:24:45 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id l1-20020a922901000000b0033a6e7ee4e3sm3862098ilg.1.2023.06.01.09.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 09:24:45 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [PATCH 23/40] expo: Allow setting the start of the dynamic-ID range Date: Thu, 1 Jun 2023 10:22:47 -0600 Message-ID: <20230601162404.220488-22-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog In-Reply-To: <20230601162404.220488-1-sjg@chromium.org> References: <20230601162404.220488-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Provide a way to set this value so that it is easy to separate the statically allocated IDs (generated by the caller) from those generated dynamically by expo itself. Signed-off-by: Simon Glass --- boot/expo.c | 15 +++++++++++++++ boot/scene.c | 10 ---------- doc/develop/expo.rst | 3 +++ include/expo.h | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index 8b966b6c793c..be11cfd4e946 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -56,6 +56,21 @@ void expo_destroy(struct expo *exp) free(exp); } +uint resolve_id(struct expo *exp, uint id) +{ + if (!id) + id = exp->next_id++; + else if (id >= exp->next_id) + exp->next_id = id + 1; + + return id; +} + +void expo_set_dynamic_start(struct expo *exp, uint dyn_start) +{ + exp->next_id = dyn_start; +} + int expo_str(struct expo *exp, const char *name, uint id, const char *str) { struct expo_string *estr; diff --git a/boot/scene.c b/boot/scene.c index 43c978e6ee80..2ac9bfcdbd52 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -18,16 +18,6 @@ #include #include "scene_internal.h" -uint resolve_id(struct expo *exp, uint id) -{ - if (!id) - id = exp->next_id++; - else if (id >= exp->next_id) - exp->next_id = id + 1; - - return id; -} - int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp) { struct scene *scn; diff --git a/doc/develop/expo.rst b/doc/develop/expo.rst index 32dd7f090307..9565974a28e9 100644 --- a/doc/develop/expo.rst +++ b/doc/develop/expo.rst @@ -85,6 +85,9 @@ or even the IDs of objects. Programmatic creation of many items in a loop can be handled by allocating space in the enum for a maximum number of items, then adding the loop count to the enum values to obtain unique IDs. +Where dynamic IDs are need, use expo_set_dynamic_start() to set the start value, +so that they are allocated above the starting (enum) IDs. + All text strings are stored in a structure attached to the expo, referenced by a text ID. This makes it easier at some point to implement multiple languages or to support Unicode strings. diff --git a/include/expo.h b/include/expo.h index f77ee7085192..b8f5327f2664 100644 --- a/include/expo.h +++ b/include/expo.h @@ -257,6 +257,25 @@ int expo_new(const char *name, void *priv, struct expo **expp); */ void expo_destroy(struct expo *exp); +/** + * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs + * + * It is common for a set of 'static' IDs to be used to refer to objects in the + * expo. These typically use an enum so that they are defined in sequential + * order. + * + * Dynamic IDs (for objects not in the enum) are intended to be used for + * objects to which the code does not need to refer. These are ideally located + * above the static IDs. + * + * Use this function to set the start of the dynamic range, making sure that the + * value is higher than all the statically allocated IDs. + * + * @exp: Expo to update + * @dyn_start: Start ID that expo should use for dynamic allocation + */ +void expo_set_dynamic_start(struct expo *exp, uint dyn_start); + /** * expo_str() - add a new string to an expo * -- 2.41.0.rc0.172.g3f132b7071-goog