Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp299749imm; Thu, 31 May 2018 00:08:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLnITX0j/B/VURrK3P/WcMvqpvuiZLkF+XJA3X31LkkMJlGLH5EaFviQkuGLDc4vueoN1Gh X-Received: by 2002:a62:303:: with SMTP id 3-v6mr5698805pfd.255.1527750523120; Thu, 31 May 2018 00:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527750523; cv=none; d=google.com; s=arc-20160816; b=nWWh79hNEEnRmAAp6gOqAZ47FjUq/Z8OjVerXRkuOVIld/HQr1lJIdtxkA9MvimoZU qQr/NNMOqx+WJ5ptKh6yPVwRuBWcIw40KRUPJHVh7as/41B24cxTMuRyUwYytw/gyY1k mk2sGt231WmwBhxKbYLsJL03rbBD+/IdRkKisFDWpMstLGoUiAiSMMtrHnyrl/F9i/AM RQ9v+2r+7Zz8ifLkBvqIzHRY7t6mDPdaHLOzSfyThWw1jpCj9DyeJdkuHNYlO3kCbbK5 6Wgs22uytKrQHAb8WE4vzBd4NfIhkqkF1VT/QQ6WHqixe8wNdFWc7eRtvK9ivjaAZauf B4Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=uxeUxw5phQsmhMfANcU8P4ajibuFxSVaAcU7E/LOgdM=; b=guAOufM7aUsvB60vwH2IPMzCfch+UNJ3XFv3pl2CFkWRndbLABMBZ1vjgG98uMabup Pfcgj4BuzawgtCL3mG6T3gk+gBFY2OffqanQh9k3YbkXp/P1uIfRVNdlRQbg999l0dmi vfkpfXnbuFP9EQJW/4vE/vL93Gg9jjUjF40gJu0BhV1MwTDcQzIVgz9VK+WbuBKk7FP0 4OMbweZxea41ot8as51yaYN7qjBywI26FFKxZHePu7p6WHk+BCPMf7V4blNEd1RvZ6yY XPCUqgTVBnaL7AjvE+jF6ISm52CWzJCGEWqXpQV/NbqlZfDRO9NgTtpfnvzbcMq9ZUKu FjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QthAJwS6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1-v6si34703979pld.103.2018.05.31.00.08.28; Thu, 31 May 2018 00:08:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QthAJwS6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754046AbeEaHGY (ORCPT + 99 others); Thu, 31 May 2018 03:06:24 -0400 Received: from mail-vk0-f66.google.com ([209.85.213.66]:41473 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753825AbeEaHGU (ORCPT ); Thu, 31 May 2018 03:06:20 -0400 Received: by mail-vk0-f66.google.com with SMTP id 128-v6so7378425vkf.8 for ; Thu, 31 May 2018 00:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=uxeUxw5phQsmhMfANcU8P4ajibuFxSVaAcU7E/LOgdM=; b=QthAJwS6hFtBe1M22oU64g3KdMN0WEJy3Jo+fim38PffwDz/ucj4Wb3Ck0z0w+bpQ3 ppKEUucmToXGKYKL37DgYDDCZi9qs+mykLdU0CZcnmP73Bl1fkNWJaIEc81uotlN2CvD ra/3W2d7cSk4Hvrl7l4b4q89dLOnYM70pfjVQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=uxeUxw5phQsmhMfANcU8P4ajibuFxSVaAcU7E/LOgdM=; b=RHbGZmeByLU23yLVDjt40R092eexJjCW5p5Dqei5TVhotmLfGjhwQGhN8qop86zkf9 ICrLl+ot1iQq+U/Vt2vKwgC44wNwZal2aE1W+XbnOR7ML9hK0X8yOGYul0jHFEeLByxi xgra0q+q0hNuFs9Re9fN2UZWznetmtcVR/aGDE5tIosrzrqVsVamwa2lezd6AejcfJuj sRc6LihuBirfTly9f1d/ljXYhgkED0YUylLJ0TKa9sydXsd/UhgQqhlOU6XL5FqbfAz6 uX9kIHQ96vUxnR8zMEi1vrkfkg7xq7EhemijHy+UJztxE5P+ZS7/LiWb0qHyR9wbWL6Q upYw== X-Gm-Message-State: ALKqPwfN3QwaB2eiFM7wEjc9cekk3k+3xTvsgu4qSPdUF+w30t2nPYq4 k9+83rf+RohtiZnhKwFKNoUpFIebQ80= X-Received: by 2002:a1f:1f44:: with SMTP id f65-v6mr3408299vkf.147.1527750378838; Thu, 31 May 2018 00:06:18 -0700 (PDT) Received: from mail-vk0-f43.google.com (mail-vk0-f43.google.com. [209.85.213.43]) by smtp.gmail.com with ESMTPSA id l199-v6sm3242181vke.8.2018.05.31.00.06.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 00:06:17 -0700 (PDT) Received: by mail-vk0-f43.google.com with SMTP id 128-v6so7378365vkf.8 for ; Thu, 31 May 2018 00:06:17 -0700 (PDT) X-Received: by 2002:a1f:374b:: with SMTP id e72-v6mr127286vka.155.1527750376815; Thu, 31 May 2018 00:06:16 -0700 (PDT) MIME-Version: 1.0 References: <20180515075859.17217-1-stanimir.varbanov@linaro.org> <20180515075859.17217-13-stanimir.varbanov@linaro.org> <13c7aec1-2bb9-f449-6b7d-7ec93be4ec71@linaro.org> In-Reply-To: <13c7aec1-2bb9-f449-6b7d-7ec93be4ec71@linaro.org> From: Tomasz Figa Date: Thu, 31 May 2018 16:06:05 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 12/29] venus: add common capability parser To: Stanimir Varbanov Cc: Mauro Carvalho Chehab , Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List , linux-arm-msm , vgarodia@codeaurora.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 31, 2018 at 1:21 AM Stanimir Varbanov wrote: > > Hi Tomasz, > > On 05/24/2018 05:16 PM, Tomasz Figa wrote: > > Hi Stanimir, > > > > On Tue, May 15, 2018 at 5:08 PM Stanimir Varbanov < > > [snip] > >> diff --git a/drivers/media/platform/qcom/venus/core.h > > b/drivers/media/platform/qcom/venus/core.h > >> index b5b9a84e9155..fe2d2b9e8af8 100644 > >> --- a/drivers/media/platform/qcom/venus/core.h > >> +++ b/drivers/media/platform/qcom/venus/core.h > >> @@ -57,6 +57,29 @@ struct venus_format { > >> u32 type; > >> }; > > > >> +#define MAX_PLANES 4 > > > > We have VIDEO_MAX_PLANES (=3D=3D 8) already. > > yes, but venus has maximum of 4 > Generally we tend to avoid inventing new constants and so you can see that many drivers just use VIDEO_MAX_PLANES. I can also see drivers that don't, so I guess we can keep it as is. > >> #define IS_V1(core) ((core)->res->hfi_version =3D=3D HFI_VERSION= _1XX) > >> @@ -322,4 +320,18 @@ static inline void *to_hfi_priv(struct venus_core > > *core) > >> return core->priv; > >> } > > > >> +static inline struct venus_caps * > > > > I'd leave the decision whether to inline this or not to the compiler. > > (Although these days the "inline" keyword is just a hint anyway... but > > still just wasted bytes in kernel's git repo.) > > I just followed the other code examples in the kernel and in venus. If > you insist I can drop 'inline'. https://www.kernel.org/doc/html/latest/process/coding-style.html#the-inline= -disease > >> +static void for_each_codec(struct venus_caps *caps, unsigned int > > caps_num, > >> + u32 codecs, u32 domain, func cb, void *data= , > >> + unsigned int size) > >> +{ > >> + struct venus_caps *cap; > >> + unsigned int i; > >> + > >> + for (i =3D 0; i < caps_num; i++) { > >> + cap =3D &caps[i]; > >> + if (cap->valid && cap->domain =3D=3D domain) > > > > Is there any need to check cap->domain =3D=3D domain? We could just ski= p if > > cap->valid. > > yes, we need to check the domain because we can have the same codec for > both domains decoder and encoder but with different capabilities. > Sorry, I guess my comment wasn't clear. The second if below was already checking the domain. > > > > If we want to shorten the code, we could even do (cap->valid || cap->do= main > > !=3D domain) and remove domain check from the if below. > > > >> + continue; > >> + if (cap->codec & codecs && cap->domain =3D=3D domain) Here ^ But generally, if we consider second part of my comment, the problem would disappear. > >> + cb(cap, data, size); > >> + } > >> +} [snip] > >> +static void parse_profile_level(u32 codecs, u32 domain, void *data) > >> +{ > >> + struct hfi_profile_level_supported *pl =3D data; > >> + struct hfi_profile_level *proflevel =3D pl->profile_level; > >> + u32 count =3D pl->profile_count; > >> + > >> + if (count > HFI_MAX_PROFILE_COUNT) > >> + return; > >> + > >> + while (count) { > >> + proflevel =3D (void *)proflevel + sizeof(*proflevel); > > > > Isn=E2=80=99t this just ++proflevel? > > yes > > > > >> + count--; > >> + } > > > > Am I missing something or this function doesn=E2=80=99t to do anything? > > yes, currently it is not used. I'll update it. > I'd say we should just remove it for now and add it only when it is actually needed for something. > > > >> +} > >> + > >> +static void fill_caps(struct venus_caps *cap, void *data, unsigned in= t > > num) > >> +{ > >> + struct hfi_capability *caps =3D data; > >> + unsigned int i; > >> + > > > > Should we have some check to avoid overflowing cap->caps[]? > > No, we checked that below 'num_caps > MAX_CAP_ENTRIES' > Ack. > >> +static void parse_raw_formats(struct venus_core *core, struct venus_i= nst > > *inst, > >> + u32 codecs, u32 domain, void *data) > >> +{ > >> + struct hfi_uncompressed_format_supported *fmt =3D data; > >> + struct hfi_uncompressed_plane_info *pinfo =3D fmt->format_info= ; > >> + struct hfi_uncompressed_plane_constraints *constr; > >> + u32 entries =3D fmt->format_entries; > >> + u32 num_planes; > >> + struct raw_formats rfmts[MAX_FMT_ENTRIES] =3D {}; > >> + unsigned int i =3D 0; > >> + > >> + while (entries) { > >> + num_planes =3D pinfo->num_planes; > >> + > >> + rfmts[i].fmt =3D pinfo->format; > >> + rfmts[i].buftype =3D fmt->buffer_type; > >> + i++; > >> + > >> + if (pinfo->num_planes > MAX_PLANES) > >> + break; > >> + > >> + constr =3D pinfo->plane_format; > >> + > >> + while (pinfo->num_planes) { > >> + constr =3D (void *)constr + sizeof(*constr); > > > > ++constr? > > > >> + pinfo->num_planes--; > >> + } > > > > What is this loop supposed to do? > > It is a leftover for constraints per format and plane. Currently we > don't use them, or at least the values returned by the firmware. > I guess it means we can remove it. :) > > > >> + > >> + pinfo =3D (void *)pinfo + sizeof(*constr) * num_planes= + > >> + 2 * sizeof(u32); > >> + entries--; > >> + } > >> + > >> + for_each_codec(core->caps, ARRAY_SIZE(core->caps), codecs, dom= ain, > >> + fill_raw_fmts, rfmts, i); > >> +} > > [snip] > >> +static void parser_fini(struct venus_core *core, struct venus_inst *i= nst, > >> + u32 codecs, u32 domain) > >> +{ > >> + struct venus_caps *caps =3D core->caps; > >> + struct venus_caps *cap; > >> + u32 dom; > >> + unsigned int i; > >> + > >> + if (core->res->hfi_version !=3D HFI_VERSION_1XX) > >> + return; > > > > Hmm, if the code below is executed only for 1XX, who will set cap->vali= d to > > true for newer versions? > > cap::valid is used only for v1xx. Will add a comment in the structure. > Yes, please. > > > >> + > >> + if (!inst) > >> + return; > >> + > >> + dom =3D inst->session_type; > >> + > >> + for (i =3D 0; i < MAX_CODEC_NUM; i++) { > >> + cap =3D &caps[i]; > >> + if (cap->codec & codecs && cap->domain =3D=3D dom) > >> + cap->valid =3D true; > >> + } > >> +} > >> + > >> +u32 hfi_parser(struct venus_core *core, struct venus_inst *inst, > >> + u32 num_properties, void *buf, u32 size) > >> +{ > >> + unsigned int words_count =3D size >> 2; > >> + u32 *word =3D buf, *data, codecs =3D 0, domain =3D 0; > >> + > >> + if (size % 4) > >> + return HFI_ERR_SYS_INSUFFICIENT_RESOURCES; > >> + > >> + parser_init(core, inst, &codecs, &domain); > >> + > >> + while (words_count) { > >> + data =3D word + 1; > >> + > >> + switch (*word) { > >> + case HFI_PROPERTY_PARAM_CODEC_SUPPORTED: > >> + parse_codecs(core, data); > >> + init_codecs_vcaps(core); > >> + break; > >> + case HFI_PROPERTY_PARAM_MAX_SESSIONS_SUPPORTED: > >> + parse_max_sessions(core, data); > >> + break; > >> + case HFI_PROPERTY_PARAM_CODEC_MASK_SUPPORTED: > >> + parse_codecs_mask(&codecs, &domain, data); > >> + break; > >> + case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED: > >> + parse_raw_formats(core, inst, codecs, domain, > > data); > >> + break; > >> + case HFI_PROPERTY_PARAM_CAPABILITY_SUPPORTED: > >> + parse_caps(core, inst, codecs, domain, data); > >> + break; > >> + case HFI_PROPERTY_PARAM_PROFILE_LEVEL_SUPPORTED: > >> + parse_profile_level(codecs, domain, data); > >> + break; > >> + case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE_SUPPORTED: > >> + parse_alloc_mode(core, inst, codecs, domain, > > data); > >> + break; > >> + default: > > > > Should we perhaps print something to let us know that something > > unrecognized was reported? (Or it is expected that something unrecogniz= ed > > is there?) > > The default case will be very loaded with the data of the structures, so > I don't think a print is a good idea. > Ack. > > > >> + break; > >> + } > >> + > >> + word++; > >> + words_count--; > > > > If data is at |word + 1|, shouldn=E2=80=99t we increment |word| by |1 += |data > > size||? > > yes, that could be possible but the firmware packets are with variable > data length and don't want to make the code so complex. > > The idea is to search for HFI_PROPERTY_PARAM* key numbers. Yes it is not > optimal but this enumeration is happen only once during driver probe. > Hmm, do we have a guarantee that we will never find a value that matches HFI_PROPERTY_PARAM*, but would be actually just some data inside the payload? Best regards, Tomasz