All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vince Hsu <vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Alexandre Courbot <gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Thierry Reding
	<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Peter De Schrijver
	<pdeschrijver-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	"linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [RFC PATCH 2/9] memory: tegra: add mc flush support
Date: Mon, 2 Mar 2015 19:09:55 +0800	[thread overview]
Message-ID: <54F44503.10703@nvidia.com> (raw)
In-Reply-To: <CAAVeFu+1dS-RXOEg0jmUcP907uErpOv687k=4FBJiGfKytMWPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi,

On 03/02/2015 05:29 PM, Alexandre Courbot wrote:
> On Mon, Mar 2, 2015 at 5:54 PM, Vince Hsu <vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> wrote:
>>>> +int tegra_mc_flush(struct tegra_mc_swgroup *sg)
>>>> +{
>>>> +       struct tegra_mc *mc;
>>>> +       const struct tegra_mc_hotreset *client;
>>>> +       int i;
>>>> +
>>>> +       if (!sg || !sg->mc)
>>>> +               return -EINVAL;;
>>>> +
>>>> +       mc = sg->mc;
>>>> +       if (!mc->soc->ops || !mc->soc->ops->flush)
>>>> +               return -EINVAL;;
>>>> +
>>>> +       client = mc->soc->hotresets;
>>>> +
>>>> +       for (i = 0; i < mc->soc->num_hotresets; i++, client++) {
>>>> +               if (sg->id == client->swgroup)
>>>> +                       return mc->soc->ops->flush(mc, client);
>>>> +       }
>>>> +
>>>> +       return -EINVAL;
>>>> +}
>>>> +EXPORT_SYMBOL(tegra_mc_flush);
>>>> +
>>>> +int tegra_mc_flush_done(struct tegra_mc_swgroup *sg)
>>>> +{
>>>> +       struct tegra_mc *mc;
>>>> +       const struct tegra_mc_hotreset *client;
>>>> +       int i;
>>>> +
>>>> +       if (!sg || !sg->mc)
>>>> +               return -EINVAL;;
>>>> +
>>>> +       mc = sg->mc;
>>>> +       if (!mc->soc->ops || !mc->soc->ops->flush)
>>>> +               return -EINVAL;;
>>>> +
>>>> +       client = mc->soc->hotresets;
>>>> +
>>>> +       for (i = 0; i < mc->soc->num_hotresets; i++, client++) {
>>>> +               if (sg->id == client->swgroup)
>>>> +                       return mc->soc->ops->flush_done(mc, client);
>>>> +       }
>>>> +
>>>> +       return -EINVAL;
>>>> +}
>>>> +EXPORT_SYMBOL(tegra_mc_flush_done);
>>> These functions are identical, excepted for the callback they are
>>> invoking. Could you merge the common part into a function that returns
>>> the right client to call the callback on, or ERR_PTR(-EINVAL) in case
>>> of failure?
>> I couldn't think of a clever way to do this. Any ideas? :)
> How about something like this (warning: might now be that great, untested):
>
> /* Have this in your .h and use it in your tegra_mc_ops struct */
> typedef int (*mc_op)(struct tegra_mc *mc,
>               const struct tegra_mc_hotreset *hotreset)
>
> static int __tegra_mc_op(struct tegra_mc_swgroup *sg, mc_op op)
> {
>         struct tegra_mc *mc;
>         const struct tegra_mc_hotreset *client;
>         int i;
>
>         mc = sg->mc;
>         client = mc->soc->hotresets;
>
>         for (i = 0; i < mc->soc->num_hotresets; i++, client++) {
>                 if (sg->id == client->swgroup)
>                         return op(mc, client);
>         }
>
>         return -EINVAL;
> }
>
> #define tegra_mc_op(sg, op)                                               \
>      ((!sg || !sg->mc || !sg->mc->soc->ops || sg->mc->soc->ops->op) ?  \
>          -EINVAL :                                                 \
>          __tegra_mc_op(sg, sg->mc->soc->ops->op));
>
> int tegra_mc_flush(struct tegra_mc_swgroup *sg)
> {
>         return tegra_mc_op(sg, flush);
> }
> EXPORT_SYMBOL(tegra_mc_flush);
>
> int tegra_mc_flush_done(struct tegra_mc_swgroup *sg)
> {
>         return tegra_mc_op(sg, flush_done);
> }
> EXPORT_SYMBOL(tegra_mc_flush_done);
Thanks for the example! Will use this idea and remove the double 
semicolon below.

Thanks,
Vince

>
>
> Actually when writing this code I found two other issues:
>
>>>> +int tegra_mc_flush_done(struct tegra_mc_swgroup *sg)
>>>> +{
>>>> +       struct tegra_mc *mc;
>>>> +       const struct tegra_mc_hotreset *client;
>>>> +       int i;
>>>> +
>>>> +       if (!sg || !sg->mc)
>>>> +               return -EINVAL;;
> Double ; (also in tegra_mc_flush)
>
>>>> +
>>>> +       mc = sg->mc;
>>>> +       if (!mc->soc->ops || !mc->soc->ops->flush)
> Should be ops->flush_done?

  parent reply	other threads:[~2015-03-02 11:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14  6:19 [RFC PATCH 0/9] Add generic PM domain support for Tegra SoC Vince Hsu
     [not found] ` <1421216372-8025-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-01-14  6:19   ` [RFC PATCH 1/9] reset: add of_reset_control_get_by_index() Vince Hsu
     [not found]     ` <1421216372-8025-2-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-02-12  8:56       ` Alexandre Courbot
     [not found]         ` <CAAVeFuJDfG7skRgyEt1p+NJ1x=s5rtfkL9JV1DR_Df0E=CGjuA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-02  8:52           ` Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 2/9] memory: tegra: add mc flush support Vince Hsu
     [not found]     ` <1421216372-8025-3-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-02-12  8:56       ` Alexandre Courbot
     [not found]         ` <CAAVeFuLx5fr_kQonRZzTgsw-wND==jNwvMs9LkzhWrE0rRQ76w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-02  8:54           ` Vince Hsu
     [not found]             ` <54F42549.5040202-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-03-02  9:29               ` Alexandre Courbot
     [not found]                 ` <CAAVeFu+1dS-RXOEg0jmUcP907uErpOv687k=4FBJiGfKytMWPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-02 11:09                   ` Vince Hsu [this message]
2015-03-03  8:03                   ` Alexandre Courbot
     [not found]                     ` <CAAVeFuJqa-4DqM8W2yXLUS9brfE8VgxT03FEQLSoKh26EddE8w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-03  8:09                       ` Vince Hsu
     [not found]                         ` <54F56C26.1020202-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-03-03  8:14                           ` Alexandre Courbot
     [not found]                             ` <CAAVeFuLfJJz92PdkjO1je-Hwz5smbzFKZ9=EipQ0qJTod1Xp2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-03  8:18                               ` Vince Hsu
     [not found]                                 ` <54F56E4E.9070004-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-03-03  8:31                                   ` Alexandre Courbot
     [not found]                                     ` <CAAVeFuK1ZSdBLc5p0xQkcOeGBB2MNtT+k0wg45MdO5bO=YgnnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-03  8:59                                       ` Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 3/9] memory: tegra: add flush operation for Tegra124 memory clients Vince Hsu
     [not found]     ` <1421216372-8025-4-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-02-12  8:56       ` Alexandre Courbot
     [not found]         ` <CAAVeFuLgT+PPUGR68BE=ac97FyjfmtTHCZqvMoHAwNV8x8KP6w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-02  8:54           ` Vince Hsu
     [not found]             ` <54F42559.7060901-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-03-02  9:06               ` Alexandre Courbot
2015-01-14  6:19   ` [RFC PATCH 4/9] soc: tegra: pmc: Add generic PM domain support Vince Hsu
     [not found]     ` <1421216372-8025-5-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2015-02-12  8:56       ` Alexandre Courbot
     [not found]         ` <CAAVeFuKAk44_ohL=0Qb47wwK5-8rxjvxExjQbfrshjc1J_zZug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-02  8:55           ` Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 5/9] ARM: tegra: add PM domain device nodes to Tegra124 DT Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 6/9] ARM: tegra: add GPU power supply to Jetson TK1 DT Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 7/9] drm/tegra: dc: remove the power sequence from driver Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 8/9] PCI: tegra: " Vince Hsu
2015-01-14  6:19   ` [RFC PATCH 9/9] ata: ahci_tegra: remove " Vince Hsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54F44503.10703@nvidia.com \
    --to=vinceh-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=pdeschrijver-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.