From patchwork Fri Jun 10 05:03:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 633504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rQqr81Z3Nz9sD3 for ; Fri, 10 Jun 2016 15:05:44 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rQqr80mb3zDqHH for ; Fri, 10 Jun 2016 15:05:44 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rQqqM63sXzDqPP for ; Fri, 10 Jun 2016 15:05:03 +1000 (AEST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5A53qPf052375 for ; Fri, 10 Jun 2016 01:05:02 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0a-001b2d01.pphosted.com with ESMTP id 23fm5xu0um-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Jun 2016 01:05:01 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Jun 2016 15:04:59 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Jun 2016 15:04:56 +1000 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: gwshan@linux.vnet.ibm.com X-IBM-RcptTo: skiboot@lists.ozlabs.org Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 283E22CE805C for ; Fri, 10 Jun 2016 15:04:51 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5A54jdg7602516 for ; Fri, 10 Jun 2016 15:04:45 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u5A54e1H024888 for ; Fri, 10 Jun 2016 15:04:40 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u5A54bQm024687; Fri, 10 Jun 2016 15:04:40 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id C8D6CA0192; Fri, 10 Jun 2016 15:03:56 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id C68AFE3B1A; Fri, 10 Jun 2016 15:03:56 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id AC3EE942CA3; Fri, 10 Jun 2016 15:03:56 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Fri, 10 Jun 2016 15:03:36 +1000 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1465535032-26749-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1465535032-26749-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16061005-0040-0000-0000-000001B049DE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16061005-0041-0000-0000-000009D76CCF Message-Id: <1465535032-26749-8-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-10_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606100058 Subject: [Skiboot] [PATCH v12 07/23] core/fdt: Introduce opal_get_device_tree() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This introduces OPAL API opal_get_device_tree() to get the device sub-tree. It's going to be used in PCI hot add path. Signed-off-by: Gavin Shan Reviewed-by: Andrew Donnellan --- core/fdt.c | 40 +++++++++++++++++++++++++++++++ doc/opal-api/opal-get-device-tree-118.txt | 24 +++++++++++++++++++ include/opal-api.h | 3 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 doc/opal-api/opal-get-device-tree-118.txt diff --git a/core/fdt.c b/core/fdt.c index 71149fe..a22a840 100644 --- a/core/fdt.c +++ b/core/fdt.c @@ -216,3 +216,43 @@ void *create_dtb(const struct dt_node *root, bool exclusive) return fdt; } + +static int64_t opal_get_device_tree(uint32_t phandle, + uint64_t buf, uint64_t len) +{ + struct dt_node *root; + void *fdt = (void *)buf; + uint32_t old_last_phandle; + int64_t totalsize; + int ret; + + root = dt_find_by_phandle(dt_root, phandle); + if (!root) + return OPAL_PARAMETER; + + if (!fdt) { + fdt = create_dtb(root, true); + if (!fdt) + return OPAL_INTERNAL_ERROR; + totalsize = fdt_totalsize(fdt); + free(fdt); + return totalsize; + } + + if (!len) + return OPAL_PARAMETER; + + fdt_error = 0; + old_last_phandle = last_phandle; + ret = __create_dtb(fdt, len, root, true); + if (ret) { + last_phandle = old_last_phandle; + if (ret == -FDT_ERR_NOSPACE) + return OPAL_NO_MEM; + + return OPAL_EMPTY; + } + + return OPAL_SUCCESS; +} +opal_call(OPAL_GET_DEVICE_TREE, opal_get_device_tree, 3); diff --git a/doc/opal-api/opal-get-device-tree-118.txt b/doc/opal-api/opal-get-device-tree-118.txt new file mode 100644 index 0000000..235a321 --- /dev/null +++ b/doc/opal-api/opal-get-device-tree-118.txt @@ -0,0 +1,24 @@ +OPAL_GET_DEVICE_TREE +-------------------- + +Get device sub-tree + +Parameters: + uint32_t phandle: root device node phandle of the device sub-tree + uint64_t buf: FDT blob buffer or NULL + uint64_t len: length of the FDT blob buffer + +Calling: + +Retrieve device sub-tree. The root node's phandle is identified by @phandle. +The typical use is for the kernel to update its device tree following a change +in hardware (e.g. PCI hotplug). + +Return Codes: + +FDT blob size - returned FDT blob buffer size when @buf is NULL +OPAL_SUCCESS - FDT blob is created successfully +OPAL_PARAMETER - invalid argument @phandle or @len +OPAL_INTERNAL_ERROR - failure creating FDT blob when calculating its size +OPAL_NO_MEM - not enough room in buffer for device sub-tree +OPAL_EMPTY - failure creating FDT blob diff --git a/include/opal-api.h b/include/opal-api.h index 0b7b0bb..41af0e5 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -163,7 +163,8 @@ #define OPAL_LEDS_SET_INDICATOR 115 #define OPAL_CEC_REBOOT2 116 #define OPAL_CONSOLE_FLUSH 117 -#define OPAL_LAST 117 +#define OPAL_GET_DEVICE_TREE 118 +#define OPAL_LAST 118 /* Device tree flags */