From patchwork Wed Aug 1 22:53:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 952468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41gpf232t4z9s3Z for ; Thu, 2 Aug 2018 08:59:22 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41gpf13BXfzF1Rb for ; Thu, 2 Aug 2018 08:59:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=erichte@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 41gpdw0d4VzF1Qn for ; Thu, 2 Aug 2018 08:59:15 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w71Mx4rl021699 for ; Wed, 1 Aug 2018 18:59:13 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2kkmwujf8v-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 01 Aug 2018 18:59:13 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 1 Aug 2018 23:54:11 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 1 Aug 2018 23:54:09 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w71Ms83K42401864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 1 Aug 2018 22:54:08 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA2F74C040; Thu, 2 Aug 2018 01:54:19 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 28CCF4C044; Thu, 2 Aug 2018 01:54:19 +0100 (BST) Received: from boston-1.rtp.stglabs.ibm.com (unknown [9.27.30.60]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Aug 2018 01:54:19 +0100 (BST) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Wed, 1 Aug 2018 18:53:47 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801225349.6535-1-erichte@linux.ibm.com> References: <20180801225349.6535-1-erichte@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18080122-0020-0000-0000-000002AF9BEA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080122-0021-0000-0000-000020FBC47A Message-Id: <20180801225349.6535-9-erichte@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-08-01_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1808010233 Subject: [Skiboot] [RFC PATCH 08/10] keystore: add opal_get_next_variable runtime service X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Claudio Carvalho MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The opal_get_next_variable runtime service allows the caller to iterate through a bank, and receive the name and optionally the size of the variable. Each call to opal_get_next_variable will return the next item in the list until the end is reached, where the varname will be set to NULL, and OPAL_EMPTY is returned. Since this runtime service maintains its own state, the caller must be aware of when this function is called, and to OR the section with START_OVER if they wish to reset. NOTE: This runtime service is already slated for a rewrite! I kept this version here since it is a perfect example of reacting to unforseen implementation issues. An alternate implementation has been proposed that takes an additional argument: the name of the previous. This allows for the the caller to maintain the state instead, allowing multiple calls to this service from multiple threads/locations without requiring synchronization. NOTE #2: This commit also introduces a few macros from upstream ccan that are not in the version included in skiboot. Since the proposed rewrite of this function would no longer need the macros, consider them irrelevant to this commit other than to make it compile. Signed-off-by: Eric Richter --- libstb/keystore.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ libstb/keystore.h | 19 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/libstb/keystore.c b/libstb/keystore.c index 8f825f8e..0ddabf5f 100644 --- a/libstb/keystore.c +++ b/libstb/keystore.c @@ -147,6 +147,57 @@ found: opal_call(OPAL_SET_VARIABLE, opal_set_variable, 4); +static int64_t opal_get_next_variable(uint64_t k_varname, uint64_t k_size, uint64_t section) +{ + static struct keystore_variable *active_prev = NULL; + static struct keystore_variable *update_prev = NULL; + struct keystore_variable **prev; // TODO: replace this with a switching macro? + struct list_head *bank; + + uint64_t *size = (uint64_t *) k_size; + + CHECK_KEYSTORE_READY; + + // Operate on each bank separately, but we can alias the value to make it easier + switch(section & (~START_OVER)) { + case ACTIVE_BANK: prev = &active_prev; break; + case UPDATE_QUEUE: prev = &update_prev; break; + default: return OPAL_PARAMETER; + } + + if (section & START_OVER) { + *prev = NULL; + } + + // TODO: This may not be needed anymore if the above is doing the check + bank = GET_BANK(section); + if (!bank) { + return OPAL_PARAMETER; + } + + // If this is the first (fresh) call + if (!(*prev)) { + *prev = list_top(bank, struct keystore_variable, link); + } + // Catch subsequent calls, and incremenet the pointer + else { + *prev = list_next(bank, *prev, link); + } + + // End of the list, or list is empty + if (!(*prev)) { + return OPAL_EMPTY; + } + + strcpy((char*) k_varname, (*prev)->name); + if (size) + *size = (*prev)->data_size; + + return OPAL_SUCCESS; +} +opal_call(OPAL_GET_NEXT_VARIABLE, opal_get_next_variable, 3); + + int keystore_init(void) { int rc; diff --git a/libstb/keystore.h b/libstb/keystore.h index e2eb296c..eaaeb1dd 100644 --- a/libstb/keystore.h +++ b/libstb/keystore.h @@ -35,4 +35,23 @@ struct keystore_variable { char *data; }; + +// TODO: Eventually not depend on these macros here +#define list_typeof(var) typeof(var) + +static inline void *list_entry_or_null(const struct list_head *h, + const struct list_node *n, + size_t off) +{ + if (n == &h->n) + return NULL; + return (char *)n - off; +} + +#define list_next(h, i, member) \ + ((list_typeof(i))list_entry_or_null(list_debug(h), \ + (i)->member.next, \ + list_off_var_((i), member))) + + #endif /* __KEYSTORE_H */