From patchwork Thu Jan 4 16:36:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 10145145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6DFC6034B for ; Thu, 4 Jan 2018 16:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEAC628732 for ; Thu, 4 Jan 2018 16:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A21CD2876B; Thu, 4 Jan 2018 16:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F7AC28732 for ; Thu, 4 Jan 2018 16:38:24 +0000 (UTC) Received: from localhost ([::1]:49537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8X9-0003N5-CV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Jan 2018 11:38:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Vz-0002UG-QV for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:37:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX8Vw-00017p-2p for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:37:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX8Vv-00016C-Qo for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:37:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE0D48FAB1; Thu, 4 Jan 2018 16:37:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63A205DC19; Thu, 4 Jan 2018 16:37:04 +0000 (UTC) From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 18:36:48 +0200 Message-Id: <20180104163652.65450-2-marcel@redhat.com> In-Reply-To: <20180104163652.65450-1-marcel@redhat.com> References: <20180104163652.65450-1-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 04 Jan 2018 16:37:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH V4 1/5] pci/shpc: Move function to generic header file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, mst@redhat.com, f4bug@amsat.org, yuval.shaia@oracle.com, pbonzini@redhat.com, marcel@redhat.com, imammedo@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Yuval Shaia This function should be declared in generic header file so we can utilize it. Signed-off-by: Yuval Shaia Signed-off-by: Marcel Apfelbaum --- hw/pci/shpc.c | 13 ++----------- include/qemu/host-utils.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 69fc14b218..a8462d48bb 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/host-utils.h" #include "qemu/range.h" #include "qemu/error-report.h" #include "hw/pci/shpc.h" @@ -122,16 +123,6 @@ #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1) #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1) -static int roundup_pow_of_two(int x) -{ - x |= (x >> 1); - x |= (x >> 2); - x |= (x >> 4); - x |= (x >> 8); - x |= (x >> 16); - return x + 1; -} - static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk) { uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot); @@ -656,7 +647,7 @@ int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, int shpc_bar_size(PCIDevice *d) { - return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS)); + return pow2roundup32(SHPC_SLOT_REG(SHPC_MAX_SLOTS)); } void shpc_cleanup(PCIDevice *d, MemoryRegion *bar) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 5ac621cf1f..9fadb3f1ba 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -400,6 +400,16 @@ static inline uint64_t pow2ceil(uint64_t value) return 0x8000000000000000ull >> (n - 1); } +static inline int pow2roundup32(int x) +{ + x |= (x >> 1); + x |= (x >> 2); + x |= (x >> 4); + x |= (x >> 8); + x |= (x >> 16); + return x + 1; +} + /** * urshift - 128-bit Unsigned Right Shift. * @plow: in/out - lower 64-bit integer.