From patchwork Tue Apr 21 04:16:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1273921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 495qzb5nc0z9sSM for ; Tue, 21 Apr 2020 14:17:47 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Pp+XF4Ls; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 495qzb1QwnzDqt0 for ; Tue, 21 Apr 2020 14:17:47 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 495qz05fzBzDqsy for ; Tue, 21 Apr 2020 14:17:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Pp+XF4Ls; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 495qz03BYWz9sSM; Tue, 21 Apr 2020 14:17:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1587442636; bh=dny91tSmFeMsFTlQPADy7wOZZWjSmd2/2umorIWS7tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pp+XF4Ls32T/rddyoS8IRiRJhXzJP9OMgjhFh6ta/2MG/Gpg5F4eRRJMeysvOa/oo 9Q6crZLKKr5Zv+HbpnQOnMT4Nzz84QCXpUfxqqhAoThI/SvN2lFJPQYN+Mi1ozZEhN nYtSRTIZxWcMUJ9nZuUr+xYUmHmGc2QpR4gtQ48r/cOtp2HpRbEMOfDpJsNzZw/L8w uI6Nre9KtvRvR8lyYWfJGPO9TWZdbjPjJr13zmAnT+n9leuyCc4T3+5xT3JXUd8iYU mI5+qZCfRUhA7OFK2qRQczvJGpWlfMW0pBhLXZAZquOOtJzEdxPcRwsAsSHmew7aO0 PmOxCWpu/aRHA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Tue, 21 Apr 2020 14:16:41 +1000 Message-Id: <20200421041655.82856-6-amitay@ozlabs.org> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200421041655.82856-1-amitay@ozlabs.org> References: <20200421041655.82856-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 05/19] libpdbg: Use PDBG_BACKEND_DRIVER to specify drivers to load X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" When PDBG_BACKEND_DTB is specified, backend may not be set. This means only the drivers registered with PDBG_DEFAULT_BACKEND will be loaded. To be able to match backend specific drivers for targets in system tree, use the backend specified in PDBG_BACKEND_DRIVER environment variable. Signed-off-by: Amitay Isaacs --- libpdbg/hwunit.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c index 074ddef..3d6a05d 100644 --- a/libpdbg/hwunit.c +++ b/libpdbg/hwunit.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -70,12 +71,44 @@ static const struct hw_unit_info *find_compatible(enum pdbg_backend backend, return NULL; } +static enum pdbg_backend get_backend_driver(void) +{ + const char *tmp; + enum pdbg_backend backend = PDBG_DEFAULT_BACKEND; + + tmp = getenv("PDBG_BACKEND_DRIVER"); + if (tmp) { + if (!strcmp(tmp, "fsi")) + backend = PDBG_BACKEND_FSI; + else if (!strcmp(tmp, "i2c")) + backend = PDBG_BACKEND_I2C; + else if (!strcmp(tmp, "kernel")) + backend = PDBG_BACKEND_KERNEL; + else if (!strcmp(tmp, "fake")) + backend = PDBG_BACKEND_FAKE; + else if (!strcmp(tmp, "host")) + backend = PDBG_BACKEND_HOST; + else if (!strcmp(tmp, "cronus")) + backend = PDBG_BACKEND_CRONUS; + } + + return backend; +} + const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat_list, uint32_t len) { - const struct hw_unit_info *p; + const struct hw_unit_info *p = NULL; + enum pdbg_backend backend = pdbg_get_backend(); + + if (backend == PDBG_DEFAULT_BACKEND) { + backend = get_backend_driver(); + if (backend != PDBG_DEFAULT_BACKEND) + p = find_compatible(backend, compat_list, len); + } else { + p = find_compatible(backend, compat_list, len); + } - p = find_compatible(pdbg_get_backend(), compat_list, len); if (!p) p = find_compatible(PDBG_DEFAULT_BACKEND, compat_list, len);