From patchwork Tue Oct 10 05:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 115336 Delivered-To: patches@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3355631qgn; Mon, 9 Oct 2017 22:34:35 -0700 (PDT) X-Received: by 10.101.78.5 with SMTP id r5mr6747609pgt.94.1507613675593; Mon, 09 Oct 2017 22:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507613675; cv=none; d=google.com; s=arc-20160816; b=iZ+CMvREBi3mViyGOVIxSv8ruKaGPCbPJWHftzIfZOExOuhzI+B6CdBSpR9Yh/s/RC M2SXF4tjHGc+JKYCpZJgEFBcW2uACJ9DwO/ZbmxDlVM63O9Lh3HaV73kuBzyq+wKBjuW HZ01jg1P8MoOcrwRSL0xfp90kyhEvaHkXhfBEmmGQZtrR+i/hFSINlH0/+6lmceMdS4Q 2fvRQIomJhs/bYCpEmU4HkKexXE4hfOSlv9NG+y9Gnig3nnM4u6QGnHVS5nL/YxRLvZx +DPng+R3vtdghcfChCPHe/4PgcGt8+LZNIbKBj4bEwobKo1IrP0EPScrzrfl4fA0p7kx LSWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=O4yjzLdC+7aZu4JokVh8d7qW7Hg1i4eWnODOmX7qS/0=; b=I959niU2tz0vyHjSiS7PiI2/3fsSiANxCLNoUU+QgGi4qTPQoFiteX1uIgsiM5EwJm dhqjaQWCkYqeKvaznLXUOQBaCZHiXNdSQb4OTGBs+8BzQOhOKpdu9Ufb37G/f1qxH/GQ ig6Rc4s7GTV1ZqbGtvdFKe4NwEmNP2wHlhO9h4VAPh+cES913z6q7pXzsFB3lV1MrGxw vETPSvu2P5vBXjU5+BRDY0pYXz1h8Ag4hPlrhe77hovEy3T9BSpv1y0xWPYWTwjk4Q8e JZg0HbJLX0+ozHmsV7R+9w1G7qdE2UyL5uF00xhH5lb2WKidM21v2UASCZDLh2t8J10J U7iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NyDLGW/y; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 61sor1496058plb.119.2017.10.09.22.34.35 for (Google Transport Security); Mon, 09 Oct 2017 22:34:35 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NyDLGW/y; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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; bh=O4yjzLdC+7aZu4JokVh8d7qW7Hg1i4eWnODOmX7qS/0=; b=NyDLGW/yj8b2fAw+j4e61uW0p6h5/BRrbyxc9wYfPbDCQ9zT/CQJ8JMtzaiW0qxrLD 63/Z+qIr01HavR799nOltero7gLhOngXwIOfiDwd+6kT+12kfDhVYbeyuSmYsqrJh/WW 0MUdHqeTFHxqGq7IysQHNITm5dKw7/358RBsY= 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; bh=O4yjzLdC+7aZu4JokVh8d7qW7Hg1i4eWnODOmX7qS/0=; b=oFHxcD2MBTVRagzpE/EZW4HcVxUwstDGd5ySNI5oVlMwWim5S+MfidwDT+3s7L9t9j TH8ygbc7PmVLpvsDdOeiJOrlvGoN7+7rikY83Pv+33gNtSWEDr1+mlm1AjFMeMMX/sfK 36fGleOeS66K1kOsKjUZAC1/d7aiEQyhYykN+R+W2UwTkb9HWxkj5Yow2AM589RHsJPU gUwAKirvXT1ZqBF69tTxe+SEt1FuZlTaCTA+5rqMZLbvEv5v56sGkvAZ7WPbil2qkvFn N4yLfs5cGx8uIaPrbX0sGI8cMRb5oiEu9knIDOz0DmSV4c6BHqLql2fgws11JurrhqjJ mE6A== X-Gm-Message-State: AMCzsaWy6dc0Yn+D3CECBf7jEKcwsHrlyry6pRuNMsPTKBWTiOozxjvO JGk03cRe5yZl3tcF0lGHaCEAAM+2 X-Google-Smtp-Source: AOwi7QBTmcC0cRbzSOod498ivx3ysT4WxMJ8hh+k46L1aioldIdpq3MvWyqCsTaBc1x06G+V9232Lw== X-Received: by 10.84.241.201 with SMTP id t9mr11117237plm.154.1507613675287; Mon, 09 Oct 2017 22:34:35 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id b16sm9603595pfe.58.2017.10.09.22.34.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 22:34:34 -0700 (PDT) From: John Stultz To: lkml Cc: Dmitry Shmidt , Rob Herring , Mark Rutland , Frank Rowand , devicetree@vger.kernel.org, John Stultz Subject: [RFC][PATCH 2/3] of: overlay_mgr: Add ability to apply through sysfs entry Date: Mon, 9 Oct 2017 22:34:19 -0700 Message-Id: <1507613660-27236-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507613660-27236-1-git-send-email-john.stultz@linaro.org> References: <1507613660-27236-1-git-send-email-john.stultz@linaro.org> From: Dmitry Shmidt Allow pre-defined overlay_mgr DT fragments to be enabled on the fly by writing to: /sys/devices/platform/overlay_mgr/current_overlay Cc: Rob Herring Cc: Mark Rutland Cc: Frank Rowand Cc: Dmitry Shmidt Cc: devicetree@vger.kernel.org Signed-off-by: Dmitry Shmidt [jstultz: Slightly reworded commit message] Signed-off-by: John Stultz --- drivers/of/overlay_mgr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) -- 2.7.4 diff --git a/drivers/of/overlay_mgr.c b/drivers/of/overlay_mgr.c index 1fdeb0a..5a082be 100644 --- a/drivers/of/overlay_mgr.c +++ b/drivers/of/overlay_mgr.c @@ -18,10 +18,14 @@ #include #include #include +#include static char *of_overlay_dt_entry; module_param_named(overlay_dt_entry, of_overlay_dt_entry, charp, 0644); +static char *of_overlay_dt_apply; +DEFINE_MUTEX(of_overlay_mgr_mutex); + static int of_overlay_mgr_apply_overlay(struct device_node *onp) { int ret; @@ -61,8 +65,56 @@ static int of_overlay_mgr_apply_dt(struct device *dev, char *dt_entry) return 0; } +static ssize_t current_overlay_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + size_t len; + + mutex_lock(&of_overlay_mgr_mutex); + if (!of_overlay_dt_apply) { + mutex_unlock(&of_overlay_mgr_mutex); + return 0; + } + len = strlen(of_overlay_dt_apply); + if (len >= PAGE_SIZE) + len = PAGE_SIZE - 1; + memcpy(buf, of_overlay_dt_apply, len + 1); + mutex_unlock(&of_overlay_mgr_mutex); + return len; +} + +static ssize_t current_overlay_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + mutex_lock(&of_overlay_mgr_mutex); + kfree(of_overlay_dt_apply); + of_overlay_dt_apply = kmalloc(size, GFP_KERNEL); + if (!of_overlay_dt_apply) { + pr_err("overlay_mgr: fail to allocate memory\n"); + mutex_unlock(&of_overlay_mgr_mutex); + return 0; + } + memcpy(of_overlay_dt_apply, buf, size); + of_overlay_dt_apply[size - 1] = '\0'; + + if (of_overlay_mgr_apply_dt(dev, of_overlay_dt_apply)) { + kfree(of_overlay_dt_apply); + of_overlay_dt_apply = NULL; + size = 0; + } + mutex_unlock(&of_overlay_mgr_mutex); + return size; +} + +static DEVICE_ATTR(current_overlay, 0644, current_overlay_show, + current_overlay_store); + static int of_overlay_mgr_probe(struct platform_device *pdev) { + if (device_create_file(&pdev->dev, &dev_attr_current_overlay)) + pr_err("overlay_mgr: fail to register apply entry\n"); + if (!of_overlay_dt_entry) return 0; of_overlay_mgr_apply_dt(&pdev->dev, of_overlay_dt_entry);