Commit e2833f2d authored by Jens Korinth's avatar Jens Korinth
Browse files

platform_addr_map: init directly from info struct

* call graph was too convoluted, address map would call platform_info
* instead passing info struct directly
parent 4566b028
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
typedef struct platform_addr_map platform_addr_map_t; typedef struct platform_addr_map platform_addr_map_t;
platform_res_t platform_addr_map_init(platform_ctx_t *ctx, platform_res_t platform_addr_map_init(platform_ctx_t *ctx,
platform_info_t const *info,
platform_addr_map_t **am); platform_addr_map_t **am);
void platform_addr_map_deinit(platform_ctx_t *ctx, platform_addr_map_t *am); void platform_addr_map_deinit(platform_ctx_t *ctx, platform_addr_map_t *am);
......
...@@ -35,10 +35,11 @@ ...@@ -35,10 +35,11 @@
#endif #endif
struct platform_addr_map { struct platform_addr_map {
platform_info_t info; platform_info_t const *info;
}; };
platform_res_t platform_addr_map_init(platform_ctx_t *ctx, platform_res_t platform_addr_map_init(platform_ctx_t *ctx,
platform_info_t const *info,
platform_addr_map_t **am) platform_addr_map_t **am)
{ {
*am = (platform_addr_map_t *)malloc(sizeof(**am)); *am = (platform_addr_map_t *)malloc(sizeof(**am));
...@@ -46,13 +47,7 @@ platform_res_t platform_addr_map_init(platform_ctx_t *ctx, ...@@ -46,13 +47,7 @@ platform_res_t platform_addr_map_init(platform_ctx_t *ctx,
ERR("could not allocate memory for platform_addr_map_t"); ERR("could not allocate memory for platform_addr_map_t");
return PERR_OUT_OF_MEMORY; return PERR_OUT_OF_MEMORY;
} }
(*am)->info = info;
platform_res_t r = platform_info(ctx, &(*am)->info);
if (r != PLATFORM_SUCCESS) {
ERR("could not initialize address map: %s (%d)",
platform_strerror(r), r);
return r;
}
LOG(LPLL_ADDR, "address map successfully initialized"); LOG(LPLL_ADDR, "address map successfully initialized");
return PLATFORM_SUCCESS; return PLATFORM_SUCCESS;
...@@ -76,7 +71,7 @@ platform_res_t platform_addr_map_get_slot_base(platform_addr_map_t const* am, ...@@ -76,7 +71,7 @@ platform_res_t platform_addr_map_get_slot_base(platform_addr_map_t const* am,
return PLATFORM_ADDRESS_MAP_INVALID_BASE; return PLATFORM_ADDRESS_MAP_INVALID_BASE;
} }
#endif #endif
*addr = am->info.base.arch[slot_id]; *addr = am->info->base.arch[slot_id];
return PLATFORM_SUCCESS; return PLATFORM_SUCCESS;
} }
...@@ -103,12 +98,12 @@ platform_res_t platform_addr_map_get_component_base( ...@@ -103,12 +98,12 @@ platform_res_t platform_addr_map_get_component_base(
comp_id, PLATFORM_NUM_SLOTS); comp_id, PLATFORM_NUM_SLOTS);
return PERR_ADDR_INVALID_COMP_ID; return PERR_ADDR_INVALID_COMP_ID;
} }
if (am->info.base.platform[comp_id] == 0) { if (am->info->base.platform[comp_id] == 0) {
ERR("no base defined for component #%lu", (unsigned long)comp_id); ERR("no base defined for component #%lu", (unsigned long)comp_id);
return PERR_COMPONENT_NOT_FOUND; return PERR_COMPONENT_NOT_FOUND;
} }
#endif #endif
*addr = am->info.base.platform[comp_id]; *addr = am->info->base.platform[comp_id];
return PLATFORM_SUCCESS; return PLATFORM_SUCCESS;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <platform_logging.h> #include <platform_logging.h>
struct platform_ctx { struct platform_ctx {
platform_info_t info;
platform_addr_map_t *addrmap; platform_addr_map_t *addrmap;
}; };
...@@ -43,8 +44,17 @@ platform_res_t platform_context_init(platform_ctx_t **ctx) ...@@ -43,8 +44,17 @@ platform_res_t platform_context_init(platform_ctx_t **ctx)
return PERR_OUT_OF_MEMORY; return PERR_OUT_OF_MEMORY;
} }
platform_res_t r = platform_addr_map_init(*ctx, &(*ctx)->addrmap); platform_res_t r = platform_info(*ctx, &(*ctx)->info);
if (r != PLATFORM_SUCCESS) { if (r != PLATFORM_SUCCESS) {
free(*ctx);
ERR("could not get device info: %s (%d)",
platform_strerror(r), r);
return r;
}
r = platform_addr_map_init(*ctx, &(*ctx)->info, &(*ctx)->addrmap);
if (r != PLATFORM_SUCCESS) {
free(*ctx);
ERR("could not initialize platform address map: %s (%d)", ERR("could not initialize platform address map: %s (%d)",
platform_strerror(r), r); platform_strerror(r), r);
return r; return r;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment