diff options
| author | Alistair Popple <alistair@popple.id.au> | 2018-10-25 16:16:16 +1100 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-11-09 11:27:16 +1100 |
| commit | 541331dc5e346e45217caf3fcdf3f00479ef05a9 (patch) | |
| tree | a532cda0846ca28bafafa1580f0e9e7f7c0f0699 | |
| parent | 936dbdcedb27375c792006481f92b48685a08039 (diff) | |
| download | pdbg-541331dc5e346e45217caf3fcdf3f00479ef05a9.tar.gz pdbg-541331dc5e346e45217caf3fcdf3f00479ef05a9.zip | |
libpdbg: Remove old dt_prop functions
The dt_prop functions were copied over from Skiboot. Rework and rename
these to make use of the existing libpdbg property functions. These
should not have been used by external projects so maintaining
backwards compatibility is not a concern.
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Reviewed-by: Amitay Isaacs <amitay@ozlabs.org>
| -rw-r--r-- | libpdbg/bmcfsi.c | 37 | ||||
| -rw-r--r-- | libpdbg/cfam.c | 2 | ||||
| -rw-r--r-- | libpdbg/device.c | 39 | ||||
| -rw-r--r-- | libpdbg/device.h | 7 | ||||
| -rw-r--r-- | libpdbg/i2c.c | 5 | ||||
| -rw-r--r-- | libpdbg/libpdbg.c | 19 | ||||
| -rw-r--r-- | libpdbg/libpdbg.h | 1 | ||||
| -rw-r--r-- | libpdbg/p9chip.c | 4 |
8 files changed, 54 insertions, 60 deletions
diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index b57e029..a233106 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -42,7 +42,7 @@ * address offset */ struct gpio_pin { uint32_t offset; - int bit; + uint32_t bit; }; enum gpio { @@ -71,7 +71,7 @@ enum fsi_result { FSI_ERR_C = 0x3, }; -static int clock_delay = 0; +static uint32_t clock_delay = 0; #define FSI_DATA0_REG 0x1000 #define FSI_DATA1_REG 0x1001 @@ -459,17 +459,28 @@ int bmcfsi_probe(struct pdbg_target *target) } if (!gpio_reg) { - gpio_pins[GPIO_FSI_CLK].offset = dt_prop_get_u32_index(target, "fsi_clk", 0); - gpio_pins[GPIO_FSI_CLK].bit = dt_prop_get_u32_index(target, "fsi_clk", 1); - gpio_pins[GPIO_FSI_DAT].offset = dt_prop_get_u32_index(target, "fsi_dat", 0); - gpio_pins[GPIO_FSI_DAT].bit = dt_prop_get_u32_index(target, "fsi_dat", 1); - gpio_pins[GPIO_FSI_DAT_EN].offset = dt_prop_get_u32_index(target, "fsi_dat_en", 0); - gpio_pins[GPIO_FSI_DAT_EN].bit = dt_prop_get_u32_index(target, "fsi_dat_en", 1); - gpio_pins[GPIO_FSI_ENABLE].offset = dt_prop_get_u32_index(target, "fsi_enable", 0); - gpio_pins[GPIO_FSI_ENABLE].bit = dt_prop_get_u32_index(target, "fsi_enable", 1); - gpio_pins[GPIO_CRONUS_SEL].offset = dt_prop_get_u32_index(target, "cronus_sel", 0); - gpio_pins[GPIO_CRONUS_SEL].bit = dt_prop_get_u32_index(target, "cronus_sel", 1); - clock_delay = dt_prop_get_u32(target, "clock_delay"); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 0, + &gpio_pins[GPIO_FSI_CLK].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 1, + &gpio_pins[GPIO_FSI_CLK].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 0, + &gpio_pins[GPIO_FSI_DAT].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 1, + &gpio_pins[GPIO_FSI_DAT].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 0, + &gpio_pins[GPIO_FSI_DAT_EN].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 1, + &gpio_pins[GPIO_FSI_DAT_EN].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 0, + &gpio_pins[GPIO_FSI_ENABLE].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 1, + &gpio_pins[GPIO_FSI_ENABLE].bit))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 0, + &gpio_pins[GPIO_CRONUS_SEL].offset))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 1, + &gpio_pins[GPIO_CRONUS_SEL].bit))); + assert(!(pdbg_target_u32_property(target, "clock_delay", + &clock_delay))); /* We only have to do this init once per backend */ gpio_reg = mmap(NULL, getpagesize(), diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c index 67ab22e..c9bdf3b 100644 --- a/libpdbg/cfam.c +++ b/libpdbg/cfam.c @@ -317,7 +317,7 @@ static int cfam_hmfsi_probe(struct pdbg_target *target) int rc; /* Enable the port in the upstream control register */ - port = dt_prop_get_u32(target, "port"); + assert(!(pdbg_target_u32_property(target, "port", &port))); fsi_read(fsi_parent, 0x3404, &value); value |= 1 << (31 - port); if ((rc = fsi_write(fsi_parent, 0x3404, value))) { diff --git a/libpdbg/device.c b/libpdbg/device.c index 5cd8302..a26be30 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -501,14 +501,8 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, return NULL; } -u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, 4); - - return dt_property_get_cell(p, 0); -} - -static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) +static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, + const char *prop, uint32_t def) { const struct dt_property *p = dt_find_property(node, prop); @@ -518,35 +512,6 @@ static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, return dt_property_get_cell(p, 0); } -u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, index); -} - -const void *dt_prop_get(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return p->prop; -} - -const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, - void *def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - return p ? p->prop : def; -} - -u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, cell); -} - static enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { diff --git a/libpdbg/device.h b/libpdbg/device.h index 29224a2..ac265e9 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -37,11 +37,4 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* Simplified accessors */ -u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); -u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); -const void *dt_prop_get(const struct pdbg_target *node, const char *prop); -const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, - void *def); - #endif /* __DEVICE_H */ diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c index 9cb6271..f1c6ea9 100644 --- a/libpdbg/i2c.c +++ b/libpdbg/i2c.c @@ -130,7 +130,10 @@ int i2c_target_probe(struct pdbg_target *target) const char *bus; int addr; - bus = dt_prop_get_def(&pib->target, "bus", "/dev/i2c4"); + bus = pdbg_target_property(&pib->target, "bus", NULL); + if (!bus) + bus = "/dev/i2c4"; + addr = pdbg_target_address(&pib->target, NULL); assert(addr); diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index ff1838b..2393fb1 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -150,6 +150,25 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3 return 0; } +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val) +{ + size_t len; + uint32_t *p; + + p = pdbg_get_target_property(target, name, &len); + if (!p) + return -1; + + assert(len >= (index+1)*sizeof(uint32_t)); + + /* FDT pointers should be aligned, but best to check */ + assert(!((uintptr_t) p & 0x3)); + + /* Always aligned, so this works. */ + *val = be32toh(p[index]); + return 0; +} + uint32_t pdbg_target_chip_id(struct pdbg_target *target) { uint32_t id; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index cd356fc..8adbc49 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,6 +73,7 @@ void pdbg_target_set_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size); int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val); uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size); /* Old deprecated for names for the above. Do not use for new projects diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 2411103..9d43725 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -118,8 +118,10 @@ static struct thread_state p9_get_thread_status(struct thread *thread) static int p9_thread_probe(struct pdbg_target *target) { struct thread *thread = target_to_thread(target); + uint32_t tid; - thread->id = dt_prop_get_u32(target, "tid"); + assert(!pdbg_target_u32_property(target, "tid", &tid)); + thread->id = tid; thread->status = p9_get_thread_status(thread); return 0; |

