OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Stübner <heiko@sntech.de>
To: opensbi@lists.infradead.org
Subject: [PATCH v4 3/5] lib: sbi_pmu: add override for counter data
Date: Thu, 29 Sep 2022 13:54:16 +0200	[thread overview]
Message-ID: <2197780.iZASKD2KPV@diego> (raw)
In-Reply-To: <CAOnJCUKKwy2_WdMKYkFeMnb68ay0FSmuhkiGaKXBqAJyFApoXA@mail.gmail.com>

Am Donnerstag, 29. September 2022, 10:28:57 CEST schrieb Atish Patra:
> On Mon, Sep 26, 2022 at 3:18 AM Heiko Stuebner <heiko@sntech.de> wrote:
> >
> > In general counter-data is auto-detected but some platforms
> > may implement counters in a way that breaks this detection.
> >
> > Implement an abstraction that those platforms can hook into
> > and override the counter-data.
> >
> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > ---
> >  include/sbi/sbi_pmu.h | 8 ++++++++
> >  lib/sbi/sbi_hart.c    | 7 +++++++
> >  lib/sbi/sbi_pmu.c     | 7 +++++++
> >  3 files changed, 22 insertions(+)
> >
> > diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h
> > index c365243..d257b14 100644
> > --- a/include/sbi/sbi_pmu.h
> > +++ b/include/sbi/sbi_pmu.h
> > @@ -78,6 +78,11 @@ struct sbi_pmu_device {
> >          * Custom function returning the machine-specific irq-bit.
> >          */
> >         int (*hw_counter_irq_bit)(void);
> > +
> > +       /**
> > +        * Override autodetected counter data.
> > +        */
> > +       void (*hw_counter_data)(unsigned int *count, unsigned int *bits);
> >  };
> >
> >  /** Get the PMU platform device */
> > @@ -95,6 +100,9 @@ void sbi_pmu_exit(struct sbi_scratch *scratch);
> >  /** Return the pmu irq bit depending on extension existence */
> >  int sbi_pmu_irq_bit(void);
> >
> > +/** Allow non-standard platforms to override probed counter information */
> > +void sbi_pmu_override_counter_data(unsigned int *count, unsigned int *bits);
> > +
> >  /**
> >   * Add the hardware event to counter mapping information. This should be called
> >   * from the platform code to update the mapping table.
> > diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> > index 45fbcde..6506a19 100644
> > --- a/lib/sbi/sbi_hart.c
> > +++ b/lib/sbi/sbi_hart.c
> > @@ -632,6 +632,13 @@ __mhpm_skip:
> >  #undef __check_csr_2
> >  #undef __check_csr
> >
> > +       /**
> > +        * Allow non-standard implementations to override the detected
> > +        * values for number of counters and bits.
> > +        */
> > +       sbi_pmu_override_counter_data(&hfeatures->mhpm_count,
> > +                                     &hfeatures->mhpm_bits);
> > +
> >         /* Detect if hart supports Priv v1.10 */
> >         val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap);
> >         if (!trap.cause)
> > diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
> > index 91d9ccc..c8becf3 100644
> > --- a/lib/sbi/sbi_pmu.c
> > +++ b/lib/sbi/sbi_pmu.c
> > @@ -852,3 +852,10 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot)
> >
> >         return 0;
> >  }
> > +
> > +void sbi_pmu_override_counter_data(unsigned int *count,
> > +                                  unsigned int *bits)
> > +{
> > +       if (pmu_dev && pmu_dev->hw_counter_data)
> > +               pmu_dev->hw_counter_data(count, bits);
> > +}
> > --
> > 2.35.1
> >
> >
> > --
> > opensbi mailing list
> > opensbi at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/opensbi
> 
> We may need similar functionality in the future as well where the
> platform may override the hart feature details.
> Should we pass the hfeatures in the extension_init callback so that a
> specific platform override can access it ?

you tell me :-) .

I.e. I didn't want to expose the previously unexposed hfeatures struct
(right now it's local to sbi_hart) but if it's ok to expose it, directly
setting the hfeatures values of course makes a lot of sense also for
future uses.


Heiko




  reply	other threads:[~2022-09-29 11:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 10:16 [PATCH v4 0/5] Add support for T-HEAD C9xx PMU extensions Heiko Stuebner
2022-09-26 10:16 ` [PATCH v4 1/5] lib: sbi: do platform-specific extension population earlier Heiko Stuebner
2022-09-26 23:15   ` Guo Ren
2022-09-26 10:16 ` [PATCH v4 2/5] lib: sbi_pmu: move pmu irq information into pmu itself Heiko Stuebner
2022-09-26 23:20   ` Guo Ren
2022-09-29  8:12   ` Atish Patra
2022-09-26 10:16 ` [PATCH v4 3/5] lib: sbi_pmu: add override for counter data Heiko Stuebner
2022-09-26 23:18   ` Guo Ren
2022-09-29  8:28   ` Atish Patra
2022-09-29 11:54     ` Heiko Stübner [this message]
2022-09-26 10:16 ` [PATCH v4 4/5] platform: generic: add extensions_init handler and platform-override Heiko Stuebner
2022-09-26 23:13   ` Guo Ren
2022-09-26 10:16 ` [PATCH v4 5/5] platform: generic: allwinner: add support for c9xx pmu Heiko Stuebner
2022-09-26 23:30   ` Guo Ren
2022-09-27 11:41     ` Heiko Stübner
2022-09-28  5:45       ` Guo Ren

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=2197780.iZASKD2KPV@diego \
    --to=heiko@sntech.de \
    --cc=opensbi@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox