From patchwork Mon Sep 28 15:27:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Fedin X-Patchwork-Id: 7278601 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CA68F9F302 for ; Mon, 28 Sep 2015 15:28:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43804206FE for ; Mon, 28 Sep 2015 15:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22571206FA for ; Mon, 28 Sep 2015 15:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934225AbbI1P17 (ORCPT ); Mon, 28 Sep 2015 11:27:59 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:62385 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934119AbbI1P1q (ORCPT ); Mon, 28 Sep 2015 11:27:46 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NVE0019J8A6LS30@mailout4.w1.samsung.com> for kvm@vger.kernel.org; Mon, 28 Sep 2015 16:27:42 +0100 (BST) X-AuditID: cbfec7f4-f79c56d0000012ee-5e-56095c6ee7c1 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id D5.34.04846.E6C59065; Mon, 28 Sep 2015 16:27:42 +0100 (BST) Received: from fedinw7x64.rnd.samsung.ru ([106.109.131.169]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NVE0037289Z1L50@eusync1.samsung.com>; Mon, 28 Sep 2015 16:27:42 +0100 (BST) From: Pavel Fedin To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: Peter Maydell , Marc Zyngier , Andre Przywara Subject: [PATCH v4 6/7] KVM: arm64: Introduce find_reg_by_id() Date: Mon, 28 Sep 2015 18:27:33 +0300 Message-id: <985e479f5f77d349f659b11d4f31d665d65627f0.1443451687.git.p.fedin@samsung.com> X-Mailer: git-send-email 2.4.4 In-reply-to: References: In-reply-to: References: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFLMWRmVeSWpSXmKPExsVy+t/xy7p5MZxhBi2LxS1WzPvJaDFnaqHF x1PH2S3+3vnHZjHnzAMWB1aPNfPWMHrcubaHzeP8pjXMHp83yQWwRHHZpKTmZJalFunbJXBl /J64hrlgqUjFvy8T2BoYDwh0MXJySAiYSLS/3MAGYYtJXLi3Hsjm4hASWMoosWXBGWYIp41J 4vO/PUwgVWwC6hKnv35gAbFFBEwlnv97ywpiMwvUSHzofAQWFxawk3g0YycjiM0ioCqxaN0K sBpegWiJx0v2s0Nsk5O4cn062GZOAXOJDYsbgXo5gJaZSSw5UolDeAIj/wJGhlWMoqmlyQXF Sem5hnrFibnFpXnpesn5uZsYISH2ZQfj4mNWhxgFOBiVeHhnqHOECbEmlhVX5h5ilOBgVhLh 3erLGSbEm5JYWZValB9fVJqTWnyIUZqDRUmcd+6u9yFCAumJJanZqakFqUUwWSYOTqkGxgl7 rLMvT/SUMLMTrTkuKelS5dOVynLg1EYVlctGflPZ/zx7cnBfxr+zzP0rz3sc/8VwdXa5TtSB SxfrXO2N/su9aHu3seOP9Wre3jsel8VKfUpKdngvYQmz3N6hKaFsGut1fOchgVirNaf2vTwl q3xn4qU7RecemM51fLNme6pHGV/u6XdXliuxFGckGmoxFxUnAgCvnrLFLQIAAA== Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to implement vGICv3 CPU interface access, we will need to perform table lookup of system registers. We would need both index_to_params() and find_reg() exported for that purpose, but instead we export a single function which combines them both. Signed-off-by: Pavel Fedin Reviewed-by: Andre Przywara --- arch/arm64/kvm/sys_regs.c | 22 +++++++++++++++------- arch/arm64/kvm/sys_regs.h | 4 ++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 39db06dd..713b4fa 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1276,6 +1276,17 @@ static bool index_to_params(u64 id, struct sys_reg_params *params) } } +const struct sys_reg_desc *find_reg_by_id(u64 id, + struct sys_reg_params *params, + const struct sys_reg_desc table[], + unsigned int num) +{ + if (!index_to_params(id, params)) + return NULL; + + return find_reg(params, table, num); +} + /* Decode an index value, and find the sys_reg_desc entry. */ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id) @@ -1403,10 +1414,8 @@ static int get_invariant_sys_reg(u64 id, void __user *uaddr) struct sys_reg_params params; const struct sys_reg_desc *r; - if (!index_to_params(id, ¶ms)) - return -ENOENT; - - r = find_reg(¶ms, invariant_sys_regs, ARRAY_SIZE(invariant_sys_regs)); + r = find_reg_by_id(id, ¶ms, invariant_sys_regs, + ARRAY_SIZE(invariant_sys_regs)); if (!r) return -ENOENT; @@ -1420,9 +1429,8 @@ static int set_invariant_sys_reg(u64 id, void __user *uaddr) int err; u64 val = 0; /* Make sure high bits are 0 for 32-bit regs */ - if (!index_to_params(id, ¶ms)) - return -ENOENT; - r = find_reg(¶ms, invariant_sys_regs, ARRAY_SIZE(invariant_sys_regs)); + r = find_reg_by_id(id, ¶ms, invariant_sys_regs, + ARRAY_SIZE(invariant_sys_regs)); if (!r) return -ENOENT; diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h index 3267518..0646108 100644 --- a/arch/arm64/kvm/sys_regs.h +++ b/arch/arm64/kvm/sys_regs.h @@ -136,6 +136,10 @@ static inline int cmp_sys_reg(const struct sys_reg_desc *i1, return i1->Op2 - i2->Op2; } +const struct sys_reg_desc *find_reg_by_id(u64 id, + struct sys_reg_params *params, + const struct sys_reg_desc table[], + unsigned int num); #define Op0(_x) .Op0 = _x #define Op1(_x) .Op1 = _x