[Pdbg] [PATCH 04/13] libpdbg: Cache device trees globally
Alistair Popple
alistair at popple.id.au
Thu Jan 16 12:26:53 AEDT 2020
Reviewed-by: Alistair Popple <alistair at popple.id.au>
On Wednesday, 15 January 2020 4:18:52 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
> libpdbg/device.c | 17 +++++++++++------
> libpdbg/dtb.c | 13 +++++++++----
> libpdbg/target.h | 2 +-
> 3 files changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index ac2351d..6599171 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -754,11 +754,16 @@ skip:
>
> bool pdbg_targets_init(void *fdt)
> {
> - struct pdbg_dtb dtb;
> + struct pdbg_dtb *dtb;
>
> - pdbg_default_dtb(&dtb, fdt);
> + dtb = pdbg_default_dtb(fdt);
>
> - if (!dtb.system) {
> + if (!dtb) {
> + pdbg_log(PDBG_ERROR, "Could not determine system\n");
> + return false;
> + }
> +
> + if (!dtb->system) {
> pdbg_log(PDBG_ERROR, "Could not find a system device tree\n");
> return false;
> }
> @@ -768,10 +773,10 @@ bool pdbg_targets_init(void *fdt)
> if (!pdbg_dt_root)
> return false;
>
> - if (dtb.backend)
> - dt_expand(pdbg_dt_root, dtb.backend);
> + if (dtb->backend)
> + dt_expand(pdbg_dt_root, dtb->backend);
>
> - dt_expand(pdbg_dt_root, dtb.system);
> + dt_expand(pdbg_dt_root, dtb->system);
>
> pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);
> return true;
> diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
> index 18b5a6f..ab5ef4c 100644
> --- a/libpdbg/dtb.c
> +++ b/libpdbg/dtb.c
> @@ -58,6 +58,7 @@
>
> static enum pdbg_backend pdbg_backend = PDBG_DEFAULT_BACKEND;
> static const char *pdbg_backend_option;
> +static struct pdbg_dtb pdbg_dtb;
>
> /* Determines the most appropriate backend for the host system we are
> * running on. */
> @@ -276,8 +277,9 @@ const char *pdbg_get_backend_option(void)
>
> /* Determines what platform we are running on and returns a pointer to
> * the fdt that is most likely to work on the system. */
> -void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt)
> +struct pdbg_dtb *pdbg_default_dtb(void *system_fdt)
> {
> + struct pdbg_dtb *dtb = &pdbg_dtb;
> char *fdt;
>
> *dtb = (struct pdbg_dtb) {
> @@ -294,7 +296,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void
> *system_fdt) dtb->system = mmap_dtb(fdt, false);
>
> if (dtb->backend && dtb->system)
> - return;
> + goto done;
>
> if (!pdbg_backend)
> pdbg_backend = default_backend();
> @@ -322,7 +324,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void
> *system_fdt) if (!pdbg_backend_option) {
> pdbg_log(PDBG_ERROR, "No system type specified\n");
> pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9r/p9w/p9z'\n");
> - return;
> + return NULL;
> }
>
> if (!strcmp(pdbg_backend_option, "p8")) {
> @@ -355,7 +357,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void
> *system_fdt) if (!pdbg_backend_option) {
> pdbg_log(PDBG_ERROR, "No system type specified\n");
> pdbg_log(PDBG_ERROR, "Use p8@<server> or p9@<server>\n");
> - return;
> + return NULL;
> }
>
> if (!strncmp(pdbg_backend_option, "p8", 2)) {
> @@ -382,4 +384,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void
> *system_fdt) dtb->system = &_binary_fake_dtb_o_start;
> break;
> }
> +
> +done:
> + return dtb;
> }
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index f068e8d..25fdbad 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -71,7 +71,7 @@ bool pdbg_target_is_class(struct pdbg_target *target,
> const char *class); extern struct list_head empty_list;
> extern struct list_head target_classes;
>
> -void pdbg_default_dtb(struct pdbg_dtb *pdtb, void *system_fdt);
> +struct pdbg_dtb *pdbg_default_dtb(void *system_fdt);
> const char *pdbg_get_backend_option(void);
>
> struct chipop *pib_to_chipop(struct pdbg_target *target);
More information about the Pdbg
mailing list