From patchwork Wed Apr 10 12:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ayaka X-Patchwork-Id: 10893813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EE9217EF for ; Wed, 10 Apr 2019 12:42:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1026828908 for ; Wed, 10 Apr 2019 12:42:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0394F26B39; Wed, 10 Apr 2019 12:42:58 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 96E2028908 for ; Wed, 10 Apr 2019 12:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SOpuGIuBSyVldA69le8UHyladBxf6fkwXzIjV10AeBE=; b=QKGoazkMsxxulv D9cA2RZfQdtASoBghxbHUCvt9SovUYSaDjMZzpvGV205kZDYZDTll4LBSqbAYjnurXyPWbNEKeExf Oq/I6EFyJfDpkgifwl6gRF95ob57X5gaFx5EMoBnWpwUmsmesfv0PtY1d0WWhB4HL25BNgDDY45Xw 4YYcy3nqEc4FFxx4i7bStl3PLQPK/abDk9agVU2+q/HYu3mGgsXrsntHfzovjgcPHbXoDiOnlCpqp 54xzqsuP2rJkAv1/N3mMJ0/wd65lM8qK/mkH4/9RXUGuFyWquX6fQ03jJdguhgccS4jqPdc1drlEw eZcqg7f1K+25V50EdGyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hECZ5-0002eg-Bu; Wed, 10 Apr 2019 12:42:55 +0000 Received: from kozue.soulik.info ([2001:19f0:7000:8404:5054:ff:fe75:428f]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hECYz-0002d7-4B for linux-rockchip@lists.infradead.org; Wed, 10 Apr 2019 12:42:53 +0000 Received: from misaki.sumomo.pri (unknown [IPv6:2001:470:b30d:2:c604:15ff:0:401]) by kozue.soulik.info (Postfix) with ESMTPA id 4E2481014EA; Wed, 10 Apr 2019 21:43:36 +0900 (JST) From: ayaka To: linux-media@vger.kernel.org Subject: [PATCH v3 2/9] rockchip: mpp: rkvdec: rbsp Date: Wed, 10 Apr 2019 20:42:19 +0800 Message-Id: <20190410124226.8612-3-ayaka@soulik.info> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190410124226.8612-1-ayaka@soulik.info> References: <20190410124226.8612-1-ayaka@soulik.info> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190410_054249_842319_F012BEA3 X-CRM114-Status: GOOD ( 11.44 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: paul.kocialkowski@bootlin.com, maxime.ripard@bootlin.com, joro@8bytes.org, Randy Li , jernej.skrabec@gmail.com, nicolas@ndufresne.ca, hverkuil@xs4all.nl, linux-rockchip@lists.infradead.org, thomas.petazzoni@bootlin.com, groeck@chromium.org, mchehab@kernel.org, ezequiel@collabora.com, posciak@chromium.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Randy Li It is a bit writer. Signed-off-by: Randy Li --- drivers/staging/rockchip-mpp/rkvdec/rbsp.c | 96 ++++++++++++++++++++++ drivers/staging/rockchip-mpp/rkvdec/rbsp.h | 30 +++++++ 2 files changed, 126 insertions(+) create mode 100644 drivers/staging/rockchip-mpp/rkvdec/rbsp.c create mode 100644 drivers/staging/rockchip-mpp/rkvdec/rbsp.h diff --git a/drivers/staging/rockchip-mpp/rkvdec/rbsp.c b/drivers/staging/rockchip-mpp/rkvdec/rbsp.c new file mode 100644 index 000000000000..3fbc50e9bca1 --- /dev/null +++ b/drivers/staging/rockchip-mpp/rkvdec/rbsp.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2012 Vista Silicon S.L. + * Copyright (C) 2019 Randy Li + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include + +#include "rbsp.h" + +int rbsp_init(struct rbsp *rbsp, void *buf, int size, int bit_pos) +{ + if (!buf) + return -EINVAL; + if (DIV_ROUND_UP(bit_pos, 32) >= size) + return -EINVAL; + + rbsp->buf = buf; + rbsp->size = size >> 2; + rbsp->pos = bit_pos; + + return 0; +} + +static inline int rbsp_read_bit(struct rbsp *rbsp) +{ + int shift = rbsp->pos % 32; + int ofs = rbsp->pos++ / 32; + + if (ofs >= rbsp->size) + return -EINVAL; + + return (rbsp->buf[ofs] >> shift) & 1; +} + +static inline int rbsp_write_bit(struct rbsp *rbsp, int bit) +{ + int shift = rbsp->pos % 32; + int ofs = rbsp->pos++ / 32; + + if (ofs >= rbsp->size) + return -EINVAL; + + rbsp->buf[ofs] &= ~(1 << shift); + rbsp->buf[ofs] |= bit << shift; + + return 0; +} + +int rbsp_write_bits(struct rbsp *rbsp, int num, int value) +{ + int shift = rbsp->pos % 32; + int ofs = rbsp->pos / 32; + + if (ofs >= rbsp->size) + return -EINVAL; + + if (num + shift >= 32) { + u32 lbits = 32 - shift; + u32 hbits = num + shift - 32; + + rbsp->buf[ofs] &= ~(((1 << lbits) - 1) << shift); + rbsp->buf[ofs] |= value << shift; + + value >>= (32 - shift); + rbsp->buf[ofs + 1] &= ~(((1 << hbits) - 1)); + rbsp->buf[ofs + 1] |= value; + } else { + rbsp->buf[ofs] &= ~(((1 << num) - 1) << shift); + rbsp->buf[ofs] |= value << shift; + } + + rbsp->pos += num; + + return 0; +} + +int rbsp_write_flag(struct rbsp *rbsp, int value) +{ + if (value) + return rbsp_write_bit(rbsp, BIT(0)); + else + return rbsp_write_bit(rbsp, 0); +} diff --git a/drivers/staging/rockchip-mpp/rkvdec/rbsp.h b/drivers/staging/rockchip-mpp/rkvdec/rbsp.h new file mode 100644 index 000000000000..d87c582bfd41 --- /dev/null +++ b/drivers/staging/rockchip-mpp/rkvdec/rbsp.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2012 Vista Silicon S.L. + * Copyright (C) 2019 Randy Li + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef _RBSP_H_ +#define _RBSP_H_ + +struct rbsp { + u32 *buf; + int size; + int pos; +}; + +int rbsp_init(struct rbsp *rbsp, void *buf, int size, int bit_pos); +int rbsp_write_flag(struct rbsp *rbsp, int bit); +int rbsp_write_bits(struct rbsp *rbsp, int num, int value); + +#endif