From patchwork Fri Nov 1 06:26:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1187787 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 474C4910B8z9sPF for ; Fri, 1 Nov 2019 17:30:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R3fZxfYu"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 474C485zftzF6bM for ; Fri, 1 Nov 2019 17:30:32 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R3fZxfYu"; dkim-atps=neutral Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 474BzR4bHjzF426 for ; Fri, 1 Nov 2019 17:26:26 +1100 (AEDT) Received: by mail-pf1-x443.google.com with SMTP id c13so6348583pfp.5 for ; Thu, 31 Oct 2019 23:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vHPt0ardHBNX+4ZLd/OLKWAm1qyLd2m5H1uRxVlgqZM=; b=R3fZxfYunAQdPPt3Mnf7yR4KhclnuSxiLoQII3s//rnK74yaRW+/eEYgxtvfTpoNHe diIXPfmhIIXted8CMZgj7T6pWssIHIDA/cR5J9qTesl6AgiIRg4+xqixqbuodf+bK8V1 crGvXh7IGBHhsItPrkc1nd2FxORl2L3ysvLsuRUtgm8gywNA54E/zSyVwRGH4i7hKsX+ I+PpODHIi4fqAgGE2AkJZgSjbw2xb9OQrPHkDGQe/5bPhTCMyTqeOEV+hmJuVqbJEedm Hy2P2eOcfhBctDvfJxQ0bGxsL669TH6jR9gezQ7ivW8agEdWxy7znkqePx91xiqab58W 1cug== 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:mime-version :content-transfer-encoding; bh=vHPt0ardHBNX+4ZLd/OLKWAm1qyLd2m5H1uRxVlgqZM=; b=igEAvKZQDJyhFowoxRhknY8feecHfDQ+bd/3BdpPdtJz3xyqf366BnZB3fZXhfJhbC +4f+F9x5p+Ty5FpJEApx4TZij04cVo+63wdm+CsoRHBBY5MMQq9yErmWDQReNZ4JUq5g nTatjTdUADgVvstWdFhgXZdZMS2SL+4n6HnNAGJjGi/gnwOfeNYPgt9dkfMh2BbnA7ci 3kVVFpQ6neJB2hYZ8vyfDJXUO/TyeOXm0m40+YhkdT6qmu2+B5qXeOynzvEdU8ultXLC 0eXilLULk7VXS26rW/cy9BPO5EEiR5X6bABl035mEEYb5JXhaSELKsA0U4LkaU3Y9F4Y bnLw== X-Gm-Message-State: APjAAAWkRpTw4VoEz01prR3ofEZ3yzxS6bT/th/5EKgP1eQOHwB9SzxV bkf/Tq8DkwcyAVyvHjwADnlugeLHpfI= X-Google-Smtp-Source: APXvYqyRsm/bpSv8NkswBa5SqIRZuC6G8/LsMtnPM3xT3TXA1KLkJkzeTz4z5d6ZH2Xxz45UtPIfFQ== X-Received: by 2002:a63:cf46:: with SMTP id b6mr11350792pgj.90.1572589583059; Thu, 31 Oct 2019 23:26:23 -0700 (PDT) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id z14sm2495204pfq.66.2019.10.31.23.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 23:26:22 -0700 (PDT) From: Oliver O'Halloran To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 1/2] powerpc/powernv: Rework exports to support subnodes Date: Fri, 1 Nov 2019 17:26:10 +1100 Message-Id: <20191101062611.32610-1-oohall@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oliver O'Halloran Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Originally we only had a handful of exported memory ranges, but we'd to export the per-core trace buffers. This results in a lot of files in the exports directory which is a but unfortunate. We can clean things up a bit by turning subnodes into subdirectories of the exports directory. Signed-off-by: Oliver O'Halloran --- arch/powerpc/platforms/powernv/opal.c | 114 +++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 42 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 38e9027..0373da5 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -752,6 +752,75 @@ static ssize_t export_attr_read(struct file *fp, struct kobject *kobj, bin_attr->size); } +static int opal_add_one_export(struct kobject *parent, const char *export_name, + struct device_node *np, const char *prop_name) +{ + struct bin_attribute *attr = NULL; + const char *name = NULL; + u64 vals[2]; + int rc; + + rc = of_property_read_u64_array(np, prop_name, &vals[0], 2); + if (rc) + goto out; + + attr = kzalloc(sizeof(*attr), GFP_KERNEL); + name = kstrdup(export_name, GFP_KERNEL); + if (!name) { + rc = -ENOMEM; + goto out; + } + + sysfs_bin_attr_init(attr); + attr->attr.name = name; + attr->attr.mode = 0400; + attr->read = export_attr_read; + attr->private = __va(vals[0]); + attr->size = vals[1]; + + rc = sysfs_create_bin_file(parent, attr); +out: + if (rc) { + kfree(name); + kfree(attr); + } + + return rc; +} + +static void opal_add_exported_attrs(struct device_node *np, + struct kobject *kobj) +{ + struct device_node *child; + struct property *prop; + + for_each_property_of_node(np, prop) { + int rc; + + if (!strcmp(prop->name, "name") || + !strcmp(prop->name, "phandle")) + continue; + + rc = opal_add_one_export(kobj, prop->name, np, prop->name); + if (rc) { + pr_warn("Unable to add export %pOF/%s, rc = %d!\n", + np, prop->name, rc); + } + } + + for_each_child_of_node(np, child) { + struct kobject *child_kobj; + + child_kobj = kobject_create_and_add(child->name, kobj); + if (!child_kobj) { + pr_err("Unable to create export dir for %pOF\n", child); + continue; + } + + opal_add_exported_attrs(child, child_kobj); + } +} + /* * opal_export_attrs: creates a sysfs node for each property listed in * the device-tree under /ibm,opal/firmware/exports/ @@ -761,12 +830,8 @@ static ssize_t export_attr_read(struct file *fp, struct kobject *kobj, */ static void opal_export_attrs(void) { - struct bin_attribute *attr; struct device_node *np; - struct property *prop; struct kobject *kobj; - u64 vals[2]; - int rc; np = of_find_node_by_path("/ibm,opal/firmware/exports"); if (!np) @@ -779,41 +844,7 @@ static void opal_export_attrs(void) return; } - for_each_property_of_node(np, prop) { - if (!strcmp(prop->name, "name") || !strcmp(prop->name, "phandle")) - continue; - - if (of_property_read_u64_array(np, prop->name, &vals[0], 2)) - continue; - - attr = kzalloc(sizeof(*attr), GFP_KERNEL); - - if (attr == NULL) { - pr_warn("Failed kmalloc for bin_attribute!"); - continue; - } - - sysfs_bin_attr_init(attr); - attr->attr.name = kstrdup(prop->name, GFP_KERNEL); - attr->attr.mode = 0400; - attr->read = export_attr_read; - attr->private = __va(vals[0]); - attr->size = vals[1]; - - if (attr->attr.name == NULL) { - pr_warn("Failed kstrdup for bin_attribute attr.name"); - kfree(attr); - continue; - } - - rc = sysfs_create_bin_file(kobj, attr); - if (rc) { - pr_warn("Error %d creating OPAL sysfs exports/%s file\n", - rc, prop->name); - kfree(attr->attr.name); - kfree(attr); - } - } + opal_add_exported_attrs(np, kobj); of_node_put(np); } @@ -974,11 +1005,10 @@ static int __init opal_init(void) opal_sys_param_init(); /* Setup message log sysfs interface. */ opal_msglog_sysfs_init(); + /* Add all export properties*/ + opal_export_attrs(); } - /* Export all properties */ - opal_export_attrs(); - /* Initialize platform devices: IPMI backend, PRD & flash interface */ opal_pdev_init("ibm,opal-ipmi"); opal_pdev_init("ibm,opal-flash"); From patchwork Fri Nov 1 06:26:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1187786 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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 474C1X5czQz9sRM for ; Fri, 1 Nov 2019 17:28:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F4P6Kk6t"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 474C1X1SXwzF6TP for ; Fri, 1 Nov 2019 17:28:16 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F4P6Kk6t"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 474BzS0ZP9zF440 for ; Fri, 1 Nov 2019 17:26:27 +1100 (AEDT) Received: by mail-pl1-x644.google.com with SMTP id q21so3899447plr.13 for ; Thu, 31 Oct 2019 23:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UNQgjlNrbhy2abB8GmydbZUElcbqCcNHp92SJQGa3WI=; b=F4P6Kk6tNFcBQvcX/s1dZZlwdx95q2b6CbHB0v2fgiMw24fsDfaNWW4/NCQfPrEq5Q mgpmpdK2lxAgX8PODWABvYZ+DNYZJD003B6N5EJHuoSDB6MtiamGpNZ6ekY9GjArk0rD LYWDtzDFRIxfj0Xud/R3ktY0t+LrG3QsqJeLOhotJ/L6I3cxun1y7J0FjnsaxgBndDI3 /X8unlvS/v4XZIpY8JswsAoVfiDai8PSMgS9/b6U7XUlWQ1x2pQXK8feBGm3bhulAGHU J2oRZKpbR+zAyHM0q37geAKBGBmeaVU/IdPKdTFbi2fEtHJ21yNH78lh+x+O/Ny5rt3n qhjg== 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=UNQgjlNrbhy2abB8GmydbZUElcbqCcNHp92SJQGa3WI=; b=S/EwQM6AvjGuBnYo9AbQUxU+kfRYvV2NmtC/eSHpo8E+AEiQVz72FE96EPoIF01J+R xp2NSQCSJkCPXYStMbciaeEMpbwIwwvZpb1kl+0EBpk/Y9eRYl53bxGkzfhc2vOQq8e9 Efnt56LKz2KyehFy0Zdl2qIw9cCtDZlmFFaPJHHIfITXNPRckZ5xM2RmqAQXrULrwo2J yVIoYfvth4p+WV6S+2CcGTuB8kE0IRg8HF5Eq2PpufpuD9rJ/0ecVu40EqDu1Pl89oLG bQUMemwaobb4NDbR7lFX3oCEx4TNNM1KHPkojsUO5bx8b+giNfUEl7lA0bE3Nc1uydBv V/0w== X-Gm-Message-State: APjAAAXG5CjUbBMbk+cJN+D6gFSvFTkjcGQ2pTHRLDCNwO4wiBVn/gbB W6lHvBIAFDyfouQoJAajNF+s4hSj+po= X-Google-Smtp-Source: APXvYqxPT4wi8S/Q7+KiC2XeuxwO+lOfK/ta4SFkikoc/PnSjYO7O1zC0WeMm/Ie36cMNcpZmiYNmw== X-Received: by 2002:a17:902:8a90:: with SMTP id p16mr10938211plo.220.1572589584950; Thu, 31 Oct 2019 23:26:24 -0700 (PDT) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id z14sm2495204pfq.66.2019.10.31.23.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 23:26:24 -0700 (PDT) From: Oliver O'Halloran To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 2/2] powerpc/powernv: Use common code for the symbol_map export Date: Fri, 1 Nov 2019 17:26:11 +1100 Message-Id: <20191101062611.32610-2-oohall@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191101062611.32610-1-oohall@gmail.com> References: <20191101062611.32610-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oliver O'Halloran Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Long before we had a generic way for firmware to export memory ranges of interest we added a special case for the skiboot symbol map. The code is pretty much identical to the generic export so re-use the code. Signed-off-by: Oliver O'Halloran --- v2: Actually compile. --- arch/powerpc/platforms/powernv/opal.c | 48 ++++++++--------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 0373da5..e4ea27d 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -708,42 +708,6 @@ static int opal_sysfs_init(void) return 0; } -static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - return memory_read_from_buffer(buf, count, &off, bin_attr->private, - bin_attr->size); -} - -static struct bin_attribute symbol_map_attr = { - .attr = {.name = "symbol_map", .mode = 0400}, - .read = symbol_map_read -}; - -static void opal_export_symmap(void) -{ - const __be64 *syms; - unsigned int size; - struct device_node *fw; - int rc; - - fw = of_find_node_by_path("/ibm,opal/firmware"); - if (!fw) - return; - syms = of_get_property(fw, "symbol-map", &size); - if (!syms || size != 2 * sizeof(__be64)) - return; - - /* Setup attributes */ - symbol_map_attr.private = __va(be64_to_cpu(syms[0])); - symbol_map_attr.size = be64_to_cpu(syms[1]); - - rc = sysfs_create_bin_file(opal_kobj, &symbol_map_attr); - if (rc) - pr_warn("Error %d creating OPAL symbols file\n", rc); -} - static ssize_t export_attr_read(struct file *fp, struct kobject *kobj, struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) @@ -832,6 +796,7 @@ static void opal_export_attrs(void) { struct device_node *np; struct kobject *kobj; + int rc; np = of_find_node_by_path("/ibm,opal/firmware/exports"); if (!np) @@ -846,6 +811,15 @@ static void opal_export_attrs(void) opal_add_exported_attrs(np, kobj); + /* + * NB: symbol_map existed before the generic export interface so it + * lives under the top level opal_kobj. + */ + rc = opal_add_one_export(opal_kobj, "symbol_map", + np->parent, "symbol-map"); + if (rc) + pr_warn("Error %d creating OPAL symbols file\n", rc); + of_node_put(np); } @@ -991,8 +965,6 @@ static int __init opal_init(void) /* Create "opal" kobject under /sys/firmware */ rc = opal_sysfs_init(); if (rc == 0) { - /* Export symbol map to userspace */ - opal_export_symmap(); /* Setup dump region interface */ opal_dump_region_init(); /* Setup error log interface */