diff mbox series

[16/18] libpdbg: Add sbefifo based implementation of ocmb getscom/putscom

Message ID 20200924044236.130586-17-amitay@ozlabs.org
State Superseded
Headers show
Series Add p10 support to libpdbg | expand

Commit Message

Amitay Isaacs Sept. 24, 2020, 4:42 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 Makefile.am    |  1 +
 libpdbg/ocmb.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 libpdbg/ocmb.c

Comments

Joel Stanley Sept. 28, 2020, 6:09 a.m. UTC | #1
On Thu, 24 Sep 2020 at 04:44, Amitay Isaacs <amitay@ozlabs.org> wrote:
>
> Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>

> ---
>  Makefile.am    |  1 +
>  libpdbg/ocmb.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 86 insertions(+)
>  create mode 100644 libpdbg/ocmb.c
>
> diff --git a/Makefile.am b/Makefile.am
> index d902863..a970ab9 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -178,6 +178,7 @@ libpdbg_la_SOURCES = \
>         libpdbg/kernel.c \
>         libpdbg/libpdbg.c \
>         libpdbg/libpdbg.h \
> +       libpdbg/ocmb.c \
>         libpdbg/operations.h \
>         libpdbg/p8chip.c \
>         libpdbg/p9chip.c \
> diff --git a/libpdbg/ocmb.c b/libpdbg/ocmb.c
> new file mode 100644
> index 0000000..ef929f9
> --- /dev/null
> +++ b/libpdbg/ocmb.c
> @@ -0,0 +1,85 @@
> +/* Copyright 2020 IBM Corp.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + * implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +#include <stdio.h>
> +
> +#include <libsbefifo/libsbefifo.h>
> +
> +#include "hwunit.h"
> +
> +static struct sbefifo *ocmb_to_sbefifo(struct ocmb *ocmb)
> +{
> +       struct pdbg_target *pib = pdbg_target_require_parent("pib", &ocmb->target);
> +       struct pdbg_target *target;
> +       struct sbefifo *sbefifo = NULL;
> +
> +       pdbg_for_each_class_target("sbefifo", target) {
> +               if (pdbg_target_index(target) == pdbg_target_index(pib)) {
> +                       sbefifo = target_to_sbefifo(target);
> +                       break;
> +               }
> +       }
> +
> +       assert(sbefifo);

So there will always be a sbefifo, unless the device tree is broken?
Is there any point printing a message?

Reviewed-by: Joel Stanley <joel@jms.id.au>

> +
> +       return sbefifo;
> +}
> +
> +static int sbefifo_ocmb_getscom(struct ocmb *ocmb, uint64_t addr, uint64_t *value)
> +{
> +       struct sbefifo *sbefifo = ocmb_to_sbefifo(ocmb);
> +       struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo);
> +       uint8_t instance_id;
> +
> +       instance_id = pdbg_target_index(&ocmb->target) & 0xff;
> +
> +       return sbefifo_hw_register_get(sctx,
> +                                      SBEFIFO_TARGET_TYPE_OCMB,
> +                                      instance_id,
> +                                      addr,
> +                                      value);
> +}
> +
> +static int sbefifo_ocmb_putscom(struct ocmb *ocmb, uint64_t addr, uint64_t value)
> +{
> +       struct sbefifo *sbefifo = ocmb_to_sbefifo(ocmb);
> +       struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo);
> +       uint8_t instance_id;
> +
> +       instance_id = pdbg_target_index(&ocmb->target) & 0xff;
> +
> +       return sbefifo_hw_register_put(sctx,
> +                                      SBEFIFO_TARGET_TYPE_OCMB,
> +                                      instance_id,
> +                                      addr,
> +                                      value);
> +}
> +
> +static struct ocmb sbefifo_ocmb = {
> +       .target = {
> +               .name = "SBE FIFO Chip-op based OCMB",
> +               .compatible = "ibm,power-ocmb",
> +               .class = "ocmb",
> +       },
> +       .getscom = sbefifo_ocmb_getscom,
> +       .putscom = sbefifo_ocmb_putscom,
> +};
> +DECLARE_HW_UNIT(sbefifo_ocmb);
> +
> +__attribute__((constructor))
> +static void register_ocmb(void)
> +{
> +       pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &sbefifo_ocmb_hw_unit);
> +}
> --
> 2.26.2
>
> --
> Pdbg mailing list
> Pdbg@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg
Amitay Isaacs Sept. 28, 2020, 7:09 a.m. UTC | #2
On Mon, 2020-09-28 at 06:09 +0000, Joel Stanley wrote:
> On Thu, 24 Sep 2020 at 04:44, Amitay Isaacs <amitay@ozlabs.org>
> wrote:
> > Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
> > ---
> >  Makefile.am    |  1 +
> >  libpdbg/ocmb.c | 85
> > ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 86 insertions(+)
> >  create mode 100644 libpdbg/ocmb.c
> > 
> > diff --git a/Makefile.am b/Makefile.am
> > index d902863..a970ab9 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -178,6 +178,7 @@ libpdbg_la_SOURCES = \
> >         libpdbg/kernel.c \
> >         libpdbg/libpdbg.c \
> >         libpdbg/libpdbg.h \
> > +       libpdbg/ocmb.c \
> >         libpdbg/operations.h \
> >         libpdbg/p8chip.c \
> >         libpdbg/p9chip.c \
> > diff --git a/libpdbg/ocmb.c b/libpdbg/ocmb.c
> > new file mode 100644
> > index 0000000..ef929f9
> > --- /dev/null
> > +++ b/libpdbg/ocmb.c
> > @@ -0,0 +1,85 @@
> > +/* Copyright 2020 IBM Corp.
> > + *
> > + * Licensed under the Apache License, Version 2.0 (the "License");
> > + * you may not use this file except in compliance with the
> > License.
> > + * You may obtain a copy of the License at
> > + *
> > + *     http://www.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > software
> > + * distributed under the License is distributed on an "AS IS"
> > BASIS,
> > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> > + * implied.
> > + * See the License for the specific language governing permissions
> > and
> > + * limitations under the License.
> > + */
> > +#include <stdio.h>
> > +
> > +#include <libsbefifo/libsbefifo.h>
> > +
> > +#include "hwunit.h"
> > +
> > +static struct sbefifo *ocmb_to_sbefifo(struct ocmb *ocmb)
> > +{
> > +       struct pdbg_target *pib = pdbg_target_require_parent("pib",
> > &ocmb->target);
> > +       struct pdbg_target *target;
> > +       struct sbefifo *sbefifo = NULL;
> > +
> > +       pdbg_for_each_class_target("sbefifo", target) {
> > +               if (pdbg_target_index(target) ==
> > pdbg_target_index(pib)) {
> > +                       sbefifo = target_to_sbefifo(target);
> > +                       break;
> > +               }
> > +       }
> > +
> > +       assert(sbefifo);
> 
> So there will always be a sbefifo, unless the device tree is broken?
> Is there any point printing a message?

There must always be sbefifo in the backend device tree.  This is not
user controlled (users can only override system device tree), so it's
programming error and that's why the assert.

Amitay.
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index d902863..a970ab9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -178,6 +178,7 @@  libpdbg_la_SOURCES = \
 	libpdbg/kernel.c \
 	libpdbg/libpdbg.c \
 	libpdbg/libpdbg.h \
+	libpdbg/ocmb.c \
 	libpdbg/operations.h \
 	libpdbg/p8chip.c \
 	libpdbg/p9chip.c \
diff --git a/libpdbg/ocmb.c b/libpdbg/ocmb.c
new file mode 100644
index 0000000..ef929f9
--- /dev/null
+++ b/libpdbg/ocmb.c
@@ -0,0 +1,85 @@ 
+/* Copyright 2020 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+
+#include <libsbefifo/libsbefifo.h>
+
+#include "hwunit.h"
+
+static struct sbefifo *ocmb_to_sbefifo(struct ocmb *ocmb)
+{
+	struct pdbg_target *pib = pdbg_target_require_parent("pib", &ocmb->target);
+	struct pdbg_target *target;
+	struct sbefifo *sbefifo = NULL;
+
+	pdbg_for_each_class_target("sbefifo", target) {
+		if (pdbg_target_index(target) == pdbg_target_index(pib)) {
+			sbefifo = target_to_sbefifo(target);
+			break;
+		}
+	}
+
+	assert(sbefifo);
+
+	return sbefifo;
+}
+
+static int sbefifo_ocmb_getscom(struct ocmb *ocmb, uint64_t addr, uint64_t *value)
+{
+	struct sbefifo *sbefifo = ocmb_to_sbefifo(ocmb);
+	struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo);
+	uint8_t instance_id;
+
+	instance_id = pdbg_target_index(&ocmb->target) & 0xff;
+
+	return sbefifo_hw_register_get(sctx,
+				       SBEFIFO_TARGET_TYPE_OCMB,
+				       instance_id,
+				       addr,
+				       value);
+}
+
+static int sbefifo_ocmb_putscom(struct ocmb *ocmb, uint64_t addr, uint64_t value)
+{
+	struct sbefifo *sbefifo = ocmb_to_sbefifo(ocmb);
+	struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo);
+	uint8_t instance_id;
+
+	instance_id = pdbg_target_index(&ocmb->target) & 0xff;
+
+	return sbefifo_hw_register_put(sctx,
+				       SBEFIFO_TARGET_TYPE_OCMB,
+				       instance_id,
+				       addr,
+				       value);
+}
+
+static struct ocmb sbefifo_ocmb = {
+	.target = {
+		.name = "SBE FIFO Chip-op based OCMB",
+		.compatible = "ibm,power-ocmb",
+		.class = "ocmb",
+	},
+	.getscom = sbefifo_ocmb_getscom,
+	.putscom = sbefifo_ocmb_putscom,
+};
+DECLARE_HW_UNIT(sbefifo_ocmb);
+
+__attribute__((constructor))
+static void register_ocmb(void)
+{
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &sbefifo_ocmb_hw_unit);
+}