From patchwork Thu May 14 20:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11549741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEF0B59D for ; Thu, 14 May 2020 20:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2DE320727 for ; Thu, 14 May 2020 20:40:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="itfwljKE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727951AbgENUkZ (ORCPT ); Thu, 14 May 2020 16:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727839AbgENUkZ (ORCPT ); Thu, 14 May 2020 16:40:25 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30C80C061A0F for ; Thu, 14 May 2020 13:40:25 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id p21so1751842pgm.13 for ; Thu, 14 May 2020 13:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=orFzK+6AOl9Sz0N2w3p5SSg3SPmMkMh0jb6dZXjNAFs=; b=itfwljKE6dCaMRKBfaZdVJiDDpQn+H0q3OXHX0xEW0fAzV9TtKcwxa9k1icTMbgtZ0 A9k5X9GRE6zHz1wJCAzI89aHn7KR/PTPtPxV3J2e+VHBcFhOErNlUKDVywPVq20aPhZ2 vhFniAOOlpLdUP11cqpognmTQA0TE5CHef7034Z14rpHGwtzLEvhED6S46TaQoG9wPTJ Q36C/kBerR+9jXx0XTSbivpZx1ADQI3vOxWoQ2hrggQ6AjtserhKuzhX23jLf6qOg0T4 CUfXaDJXbTG6wfe38nGgPUIikJDfRuFMczF4O+C0ftU03AgK+/ME+/xArEdUgQa8CuZz SsLA== 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=orFzK+6AOl9Sz0N2w3p5SSg3SPmMkMh0jb6dZXjNAFs=; b=c/cGN8Vl78dEGOLknHtCHC6HBDZTppSzx7YjKrrNCJ0b08ixfcZYwK9QiQpheGEeXT QT3chXbkeGABCH2ovbO0id9cD6oJE9uv/6oG2gEwEfNMvfesrge7kL0zcQ7e/KFr2DlO 2WVv5AxMVucdC0/CuIL/isYd2nBwrRLt2tvY792pCragrbpGkLnivHD9IZqh6csTceFR v/hG9QvlFiiugvnbmbXTYelyMNhr1HVUamZzwH8jXAb2HR0/CyF7/A3/ixi/5dyPvbSV zMXEAlAp/OnuHO6fBUFCSdbdKPfiRvH8u67XQ/r04VW6+qbfLbteKGxBUOF9R6X00RqF fMEQ== X-Gm-Message-State: AOAM5315QBekoRTyRZiWdxmqGCoG3cyO6JvDQYUnKov0QMOP6R1GPB1F RZnMGRlgpXuYNWHGPWBGf+r4ng== X-Google-Smtp-Source: ABdhPJwmToiAUSfM51heHoivdVVzk95N7v0Ac6EJD2j0gDVBAEZT/9rq66kWhN1DDxZLb2zR4zRESA== X-Received: by 2002:a65:5186:: with SMTP id h6mr5926004pgq.453.1589488824707; Thu, 14 May 2020 13:40:24 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id d124sm76062pfa.98.2020.05.14.13.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 13:40:24 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/2] rpmsg: core: Add wildcard match for name service Date: Thu, 14 May 2020 14:40:21 -0600 Message-Id: <20200514204022.24233-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514204022.24233-1-mathieu.poirier@linaro.org> References: <20200514204022.24233-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Adding the capability to supplement the base definition published by an rpmsg_driver with a postfix description so that it is possible for several entity to use the same service. Signed-off-by: Mathieu Poirier Acked-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_core.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index a6361cad608b..5e01e8dede6b 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -399,7 +399,25 @@ ATTRIBUTE_GROUPS(rpmsg_dev); static inline int rpmsg_id_match(const struct rpmsg_device *rpdev, const struct rpmsg_device_id *id) { - return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0; + size_t len = min_t(size_t, strlen(id->name), RPMSG_NAME_SIZE); + + /* + * Allow for wildcard matches. For example if rpmsg_driver::id_table + * is: + * + * static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { + * { .name = "rpmsg-client-sample" }, + * { }, + * } + * + * Then it is possible to support "rpmsg-client-sample*", i.e: + * rpmsg-client-sample + * rpmsg-client-sample_instance0 + * rpmsg-client-sample_instance1 + * ... + * rpmsg-client-sample_instanceX + */ + return strncmp(id->name, rpdev->id.name, len) == 0; } /* match rpmsg channel and rpmsg driver */ From patchwork Thu May 14 20:40:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11549739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA19A59D for ; Thu, 14 May 2020 20:40:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CF8320734 for ; Thu, 14 May 2020 20:40:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="N/j6Xr/H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726090AbgENUk2 (ORCPT ); Thu, 14 May 2020 16:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728031AbgENUk0 (ORCPT ); Thu, 14 May 2020 16:40:26 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52B3DC061A0E for ; Thu, 14 May 2020 13:40:26 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id b12so1649612plz.13 for ; Thu, 14 May 2020 13:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LYKG+gPEFw9rTlwwtHvknuJBiWyt3JtNpuAesPtjSaQ=; b=N/j6Xr/HTfj8RV8QAidBt37S2c0i7E8uRZ5YJyOWAw499sJ1EUXrzu7F4WT6GJPlF9 aeglZhU5PjNKvdjCSd2awrbNLLETqgHIHx19k+IVrKiS8Tk6NUnmX5CM1dKWk2u0SMgB y6FGMqKjH2SgpD5Yahx8ew98VV7QDHTOw2Xo6Oi4ImEKpsJnbMd9eZyWGdur2e2uOofd VyhruT5IxF/g2Ue3cp4pf4Zro4LVRz9wDp7T8ItGA2FVlfQaJtEmH5quBKya/NEtvpD4 bBhlgG9DtStnwfsI5PYYAmv1XKfftHn2iOZYzad2FNkkuK0a7SUUYjyfZh8iufZ0TVM2 aWnQ== 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=LYKG+gPEFw9rTlwwtHvknuJBiWyt3JtNpuAesPtjSaQ=; b=HKVVQOISH5gHI4gPuxMN+GDPXt6EdF/j9esmCvCwthIRcv9IG9nXH33Km9/FddcEbE xWH0GHCpyhx16CKf9WUFCqu7QGbj9O74mGTNqgt2AlLiOsGrRf+J5tXgpwaha84Gjf6R jast5WCaiRviDVwCRlV323Apa4WmR5JCRYa79ggFODqaZjwYrBtOsf7vitB4Xeuefb4/ VI6dX5TTz4vV+PcI9CC/x6rjZWial02zAeDKEDhJqpp9Mt6rMEwZdojVg1y6n/lrc02b jKJHJUhLmOKR1WA17cUcDTn+21EfnFDL/8N/21HZ7tZekPTrO19aP7B9GDLBcJhni7K4 T4Sw== X-Gm-Message-State: AOAM5335HMMg+4nutGDIN/IuXk3Nl7EekFe0XgZepKw/y5JU751YtFed WWF+XB/1Tiq3ghBifktZIxM4Zg== X-Google-Smtp-Source: ABdhPJw0BRcE+Hcz9YmDGTnJ+mTJbIMDLAj4d1Ig+s808slxOgxGDQocpMaaLrHWrevAeUO6c1cEgg== X-Received: by 2002:a17:902:c213:: with SMTP id 19mr374929pll.172.1589488825761; Thu, 14 May 2020 13:40:25 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id d124sm76062pfa.98.2020.05.14.13.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 13:40:25 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/2] rpmsg: core: Add support to retrieve name extension Date: Thu, 14 May 2020 14:40:22 -0600 Message-Id: <20200514204022.24233-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514204022.24233-1-mathieu.poirier@linaro.org> References: <20200514204022.24233-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org After adding support for rpmsg device name extension, this patch provides a function that returns the extension portion of an rpmsg device name. That way users of the name extension functionality don't have to write the same boiler plate code to extract the information. Suggested-by: Suman Anna ; Signed-off-by: Mathieu Poirier Acked-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_core.c | 95 ++++++++++++++++++++++++++++++++++++++ include/linux/rpmsg.h | 13 ++++++ 2 files changed, 108 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 5e01e8dede6b..9583eb936607 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -439,6 +439,101 @@ static int rpmsg_dev_match(struct device *dev, struct device_driver *drv) return of_driver_match_device(dev, drv); } +/** + * rpmsg_device_get_name_extension() - get the name extension of a rpmsg device + * @rpdev: the rpmsg device to work with + * @skip: how many characters in the extension should be skipped over + * + * With function rpmsg_id_match() allowing for extension of the base driver name + * in order to differentiate services, this function returns the extension part + * of an rpmsg device name. As such and with the following rpmsg driver device + * id table and rpmsg device names: + * + * static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = { + * { .name = "rpmsg-client-sample" }, + * { }, + * } + * + * rpdev1->id.name == "rpmsg-client-sample"; + * rpdev2->id.name == "rpmsg-client-sample_instance0"; + * + * Calling rpmsg_device_get_name_extension() will yields the following: + * + * rpmsg_device_get_name_extension(rpdev1, 0) == NULL; + * rpmsg_device_get_name_extension(rpdev2, 0) == "_instance0"; + * rpmsg_device_get_name_extension(rpdev2, 1) == "instance0"; + * + * + * Return: The name extension if found, NULL if the name of the RPMSG device + * equals the name of the RPMSG driver and an error if no match is + * found or a validation problem has occurred. + */ +const char *rpmsg_device_get_name_extension(struct rpmsg_device *rpdev, + unsigned int skip) +{ + const char *drv_name, *dev_name, *extension; + const struct rpmsg_device_id *ids; + struct device *dev = &rpdev->dev; + struct rpmsg_driver *rpdrv; + bool match = false; + unsigned int i; + + if (!dev->driver) + return ERR_PTR(-EINVAL); + + rpdrv = to_rpmsg_driver(dev->driver); + + /* + * No point in going further if the device doesn't have name or + * the driver doesn't have a table to work with. + */ + if (!rpdev->id.name[0] || !rpdrv->id_table) + return ERR_PTR(-EINVAL); + + ids = rpdrv->id_table; + dev_name = rpdev->id.name; + + /* + * See if any name in the driver's table match the beginning + * of the rpmsg device's name. + */ + for (i = 0; ids[i].name[0]; i++) { + drv_name = ids[i].name; + if (strncmp(drv_name, + dev_name, strlen(drv_name)) == 0) { + match = true; + break; + } + } + + /* + * A match was not found, return an error to differentiate with cases + * where a match was found but the name has no extension (see below). + */ + if (!match) + return ERR_PTR(-ENOENT); + + /* No name extension to return if device and driver are the same */ + if (strlen(dev_name) == strlen(drv_name)) + return NULL; + + /* + * Make sure we were not requested to skip past the end + * of the device name. + */ + if (strlen(drv_name) + skip >= strlen(dev_name)) + return ERR_PTR(-EINVAL); + + /* + * Move past the base name published by the driver and + * skip any extra characters if needed. + */ + extension = dev_name + strlen(drv_name) + skip; + + return extension; +} +EXPORT_SYMBOL(rpmsg_device_get_name_extension); + static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env) { struct rpmsg_device *rpdev = to_rpmsg_device(dev); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe156d1c018..9537b95ad30a 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -135,6 +135,9 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev, + unsigned int skip); + #else static inline int register_rpmsg_device(struct rpmsg_device *dev) @@ -242,6 +245,16 @@ static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, return 0; } +static inline +const char *rpmsg_device_get_name_extension(struct rpmsg_device *dev, + unsigned int skip) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} + #endif /* IS_ENABLED(CONFIG_RPMSG) */ /* use a macro to avoid include chaining to get THIS_MODULE */