From patchwork Mon Jan 27 15:49:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240290 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:36 -0700 Subject: [PATCH 01/21] dm: core: Use const where possible in device.h In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.1.Iafefa95a02355a5e67f9638d115e4a038c8f791d@changeid> Update this header file to use const devices where possible, to permit callers to also use const. Signed-off-by: Simon Glass --- drivers/core/device.c | 27 ++++++++++++++------------- include/dm/device.h | 30 ++++++++++++++++-------------- include/dm/read.h | 4 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 9f39218423..b7f59fcde3 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -591,7 +591,8 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) } #endif -int device_get_child(struct udevice *parent, int index, struct udevice **devp) +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp) { struct udevice *dev; @@ -603,7 +604,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp) return -ENODEV; } -int device_get_child_count(struct udevice *parent) +int device_get_child_count(const struct udevice *parent) { struct udevice *dev; int count = 0; @@ -614,7 +615,7 @@ int device_get_child_count(struct udevice *parent) return count; } -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { struct udevice *dev; @@ -634,7 +635,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, return -ENODEV; } -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp) { struct udevice *dev; @@ -652,7 +653,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, return device_get_device_tail(dev, ret, devp); } -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp) { struct udevice *dev; @@ -669,7 +670,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, return -ENODEV; } -int device_get_child_by_of_offset(struct udevice *parent, int node, +int device_get_child_by_of_offset(const struct udevice *parent, int node, struct udevice **devp) { struct udevice *dev; @@ -712,7 +713,7 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } -int device_find_first_child(struct udevice *parent, struct udevice **devp) +int device_find_first_child(const struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { *devp = NULL; @@ -739,7 +740,7 @@ int device_find_next_child(struct udevice **devp) return 0; } -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -757,7 +758,7 @@ int device_find_first_inactive_child(struct udevice *parent, return -ENODEV; } -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -774,7 +775,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, return -ENODEV; } -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp) { struct udevice *dev; @@ -827,7 +828,7 @@ bool device_has_children(const struct udevice *dev) return !list_empty(&dev->child_head); } -bool device_has_active_children(struct udevice *dev) +bool device_has_active_children(const struct udevice *dev) { struct udevice *child; @@ -841,7 +842,7 @@ bool device_has_active_children(struct udevice *dev) return false; } -bool device_is_last_sibling(struct udevice *dev) +bool device_is_last_sibling(const struct udevice *dev) { struct udevice *parent = dev->parent; @@ -867,7 +868,7 @@ int device_set_name(struct udevice *dev, const char *name) } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) -bool device_is_compatible(struct udevice *dev, const char *compat) +bool device_is_compatible(const struct udevice *dev, const char *compat) { return ofnode_device_is_compatible(dev_ofnode(dev), compat); } diff --git a/include/dm/device.h b/include/dm/device.h index 1138a09149..611fc2e197 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -409,7 +409,8 @@ const char *dev_get_uclass_name(const struct udevice *dev); * @return 0 if OK, -ENODEV if no such device, other error if the device fails * to probe */ -int device_get_child(struct udevice *parent, int index, struct udevice **devp); +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp); /** * device_get_child_count() - Get the available child count of a device @@ -418,7 +419,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp); * * @parent: Parent device to check */ -int device_get_child_count(struct udevice *parent); +int device_get_child_count(const struct udevice *parent); /** * device_find_child_by_seq() - Find a child device based on a sequence @@ -439,7 +440,7 @@ int device_get_child_count(struct udevice *parent); * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp); /** @@ -457,7 +458,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp); /** @@ -470,7 +471,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -485,7 +486,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_get_child_by_of_offset(struct udevice *parent, int of_offset, +int device_get_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -524,7 +525,8 @@ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); * @devp: Returns first child device, or NULL if none * @return 0 */ -int device_find_first_child(struct udevice *parent, struct udevice **devp); +int device_find_first_child(const struct udevice *parent, + struct udevice **devp); /** * device_find_next_child() - Find the next child of a device @@ -548,7 +550,7 @@ int device_find_next_child(struct udevice **devp); * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -560,7 +562,7 @@ int device_find_first_inactive_child(struct udevice *parent, * @devp: Returns first child device in that uclass, if any * @return 0 if found, else -ENODEV */ -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -572,7 +574,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); /** @@ -590,7 +592,7 @@ bool device_has_children(const struct udevice *dev); * @return true if the device has one or more children and at least one of * them is active (probed). */ -bool device_has_active_children(struct udevice *dev); +bool device_has_active_children(const struct udevice *dev); /** * device_is_last_sibling() - check if a device is the last sibling @@ -603,7 +605,7 @@ bool device_has_active_children(struct udevice *dev); * @return true if there are no more siblings after this one - i.e. is it * last in the list. */ -bool device_is_last_sibling(struct udevice *dev); +bool device_is_last_sibling(const struct udevice *dev); /** * device_set_name() - set the name of a device @@ -643,7 +645,7 @@ void device_set_name_alloced(struct udevice *dev); * device * @return true if OK, false if the compatible is not found */ -bool device_is_compatible(struct udevice *dev, const char *compat); +bool device_is_compatible(const struct udevice *dev, const char *compat); /** * of_machine_is_compatible() - check if the machine is compatible with @@ -678,7 +680,7 @@ int dev_enable_by_path(const char *path); * @dev: device to test * @return: true if it is on a PCI bus, false otherwise */ -static inline bool device_is_on_pci_bus(struct udevice *dev) +static inline bool device_is_on_pci_bus(const struct udevice *dev) { return device_get_uclass_id(dev->parent) == UCLASS_PCI; } diff --git a/include/dm/read.h b/include/dm/read.h index d37fcb504d..f1c1553f80 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -33,12 +33,12 @@ static inline const struct device_node *dev_np(struct udevice *dev) * @dev: device to check * @return reference of the the device's DT node */ -static inline ofnode dev_ofnode(struct udevice *dev) +static inline ofnode dev_ofnode(const struct udevice *dev) { return dev->node; } -static inline bool dev_of_valid(struct udevice *dev) +static inline bool dev_of_valid(const struct udevice *dev) { return ofnode_valid(dev_ofnode(dev)); } From patchwork Mon Jan 27 15:49:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240291 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:37 -0700 Subject: [PATCH 02/21] dm: pci: Update the PCI read_config() method to const dev * In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.2.I900b0334ac3e2377865fef23204521c1ac59410d@changeid> At present this method uses a non-const udevice pointer, but the call should not modify the device. Use a const pointer. Signed-off-by: Simon Glass --- drivers/misc/p2sb_emul.c | 5 +++-- drivers/misc/swap_case.c | 9 +++++---- drivers/pci/pci-aardvark.c | 2 +- drivers/pci/pci-emul-uclass.c | 2 +- drivers/pci/pci-rcar-gen2.c | 4 ++-- drivers/pci/pci-rcar-gen3.c | 2 +- drivers/pci/pci-uclass.c | 14 ++++++++------ drivers/pci/pci_mpc85xx.c | 2 +- drivers/pci/pci_mvebu.c | 2 +- drivers/pci/pci_sandbox.c | 2 +- drivers/pci/pci_sh7751.c | 2 +- drivers/pci/pci_tegra.c | 2 +- drivers/pci/pci_x86.c | 5 +++-- drivers/pci/pcie_dw_mvebu.c | 2 +- drivers/pci/pcie_dw_ti.c | 2 +- drivers/pci/pcie_ecam_generic.c | 11 ++++++----- drivers/pci/pcie_fsl.c | 2 +- drivers/pci/pcie_imx.c | 2 +- drivers/pci/pcie_intel_fpga.c | 4 ++-- drivers/pci/pcie_layerscape.c | 4 ++-- drivers/pci/pcie_layerscape_gen4.c | 2 +- drivers/pci/pcie_mediatek.c | 4 ++-- drivers/pci/pcie_phytium.c | 7 +++---- drivers/pci/pcie_xilinx.c | 4 ++-- drivers/power/acpi_pmc/pmc_emul.c | 2 +- include/pci.h | 22 ++++++++++++---------- 26 files changed, 64 insertions(+), 57 deletions(-) diff --git a/drivers/misc/p2sb_emul.c b/drivers/misc/p2sb_emul.c index c3795c59c0..a6ee9a235e 100644 --- a/drivers/misc/p2sb_emul.c +++ b/drivers/misc/p2sb_emul.c @@ -48,8 +48,9 @@ struct p2sb_emul_priv { u8 regs[16]; }; -static int sandbox_p2sb_emul_read_config(struct udevice *emul, uint offset, - ulong *valuep, enum pci_size_t size) +static int sandbox_p2sb_emul_read_config(const struct udevice *emul, + uint offset, ulong *valuep, + enum pci_size_t size) { struct p2sb_emul_platdata *plat = dev_get_platdata(emul); diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index 11189d16c8..97e2afa676 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -51,7 +51,7 @@ struct swap_case_priv { char mem_text[MEM_TEXT_SIZE]; }; -static int sandbox_swap_case_use_ea(struct udevice *dev) +static int sandbox_swap_case_use_ea(const struct udevice *dev) { return !!ofnode_get_property(dev->node, "use-ea", NULL); } @@ -82,7 +82,7 @@ static const u32 ea_regs[] = { PCI_CAP_EA_SIZE_HI, }; -static int sandbox_swap_case_read_ea(struct udevice *emul, uint offset, +static int sandbox_swap_case_read_ea(const struct udevice *emul, uint offset, ulong *valuep, enum pci_size_t size) { u32 reg; @@ -95,8 +95,9 @@ static int sandbox_swap_case_read_ea(struct udevice *emul, uint offset, return 0; } -static int sandbox_swap_case_read_config(struct udevice *emul, uint offset, - ulong *valuep, enum pci_size_t size) +static int sandbox_swap_case_read_config(const struct udevice *emul, + uint offset, ulong *valuep, + enum pci_size_t size) { struct swap_case_platdata *plat = dev_get_platdata(emul); diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index aa0b4bc845..f1527ac667 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -297,7 +297,7 @@ static int pcie_advk_check_pio_status(struct pcie_advk *pcie, * * Return: 0 on success */ -static int pcie_advk_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c index 0f63e491a7..9486e1cb96 100644 --- a/drivers/pci/pci-emul-uclass.c +++ b/drivers/pci/pci-emul-uclass.c @@ -15,7 +15,7 @@ struct sandbox_pci_emul_priv { int dev_count; }; -int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, +int sandbox_pci_get_emul(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp) { struct pci_emul_uc_priv *upriv; diff --git a/drivers/pci/pci-rcar-gen2.c b/drivers/pci/pci-rcar-gen2.c index d913d53f3c..014d870478 100644 --- a/drivers/pci/pci-rcar-gen2.c +++ b/drivers/pci/pci-rcar-gen2.c @@ -107,7 +107,7 @@ static int rcar_gen2_pci_addr_valid(pci_dev_t d, uint offset) return 0; } -static u32 get_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) +static u32 get_bus_address(const struct udevice *dev, pci_dev_t bdf, u32 offset) { struct rcar_gen2_pci_priv *priv = dev_get_priv(dev); @@ -126,7 +126,7 @@ static u32 setup_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) return get_bus_address(dev, bdf, offset); } -static int rcar_gen2_pci_read_config(struct udevice *dev, pci_dev_t bdf, +static int rcar_gen2_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci-rcar-gen3.c b/drivers/pci/pci-rcar-gen3.c index 52ca13b70c..4ea7930613 100644 --- a/drivers/pci/pci-rcar-gen3.c +++ b/drivers/pci/pci-rcar-gen3.c @@ -204,7 +204,7 @@ static int rcar_gen3_pcie_addr_valid(pci_dev_t d, uint where) return 0; } -static int rcar_gen3_pcie_read_config(struct udevice *dev, pci_dev_t bdf, +static int rcar_gen3_pcie_read_config(const struct udevice *dev, pci_dev_t bdf, uint where, ulong *val, enum pci_size_t size) { diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 5be2dfd0bf..78d4129572 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -124,7 +124,7 @@ static void pci_dev_find_ofnode(struct udevice *bus, phys_addr_t bdf, } }; -int pci_bus_find_devfn(struct udevice *bus, pci_dev_t find_devfn, +int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **devp) { struct udevice *dev; @@ -551,8 +551,9 @@ int pci_auto_config_devices(struct udevice *bus) } int pci_generic_mmap_write_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong value, @@ -579,8 +580,9 @@ int pci_generic_mmap_write_config( } int pci_generic_mmap_read_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong *valuep, @@ -1054,7 +1056,7 @@ static int pci_uclass_child_post_bind(struct udevice *dev) return 0; } -static int pci_bridge_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_bridge_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_mpc85xx.c b/drivers/pci/pci_mpc85xx.c index e58ab60ee0..8dff68dbd0 100644 --- a/drivers/pci/pci_mpc85xx.c +++ b/drivers/pci/pci_mpc85xx.c @@ -15,7 +15,7 @@ struct mpc85xx_pci_priv { void __iomem *cfg_data; }; -static int mpc85xx_pci_dm_read_config(struct udevice *dev, pci_dev_t bdf, +static int mpc85xx_pci_dm_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci_mvebu.c b/drivers/pci/pci_mvebu.c index f9b08f38a1..7d9ad34e9d 100644 --- a/drivers/pci/pci_mvebu.c +++ b/drivers/pci/pci_mvebu.c @@ -136,7 +136,7 @@ static inline struct mvebu_pcie *hose_to_pcie(struct pci_controller *hose) return container_of(hose, struct mvebu_pcie, hose); } -static int mvebu_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int mvebu_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_sandbox.c b/drivers/pci/pci_sandbox.c index 2af2b79c05..fa4c476597 100644 --- a/drivers/pci/pci_sandbox.c +++ b/drivers/pci/pci_sandbox.c @@ -39,7 +39,7 @@ static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn, return ops->write_config(emul, offset, value, size); } -static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn, +static int sandbox_pci_read_config(const struct udevice *bus, pci_dev_t devfn, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_sh7751.c b/drivers/pci/pci_sh7751.c index 53e1668c99..b39c6283db 100644 --- a/drivers/pci/pci_sh7751.c +++ b/drivers/pci/pci_sh7751.c @@ -85,7 +85,7 @@ static u32 get_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) return BIT(31) | (PCI_DEV(bdf) << 8) | (offset & ~3); } -static int sh7751_pci_read_config(struct udevice *dev, pci_dev_t bdf, +static int sh7751_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci_tegra.c b/drivers/pci/pci_tegra.c index 56c08585e6..96d308f7bf 100644 --- a/drivers/pci/pci_tegra.c +++ b/drivers/pci/pci_tegra.c @@ -308,7 +308,7 @@ static int tegra_pcie_conf_address(struct tegra_pcie *pcie, pci_dev_t bdf, } } -static int pci_tegra_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_tegra_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_x86.c b/drivers/pci/pci_x86.c index e76a9c6e44..8d036930e7 100644 --- a/drivers/pci/pci_x86.c +++ b/drivers/pci/pci_x86.c @@ -8,8 +8,9 @@ #include #include -static int _pci_x86_read_config(struct udevice *bus, pci_dev_t bdf, uint offset, - ulong *valuep, enum pci_size_t size) +static int _pci_x86_read_config(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) { return pci_x86_read_config(bdf, offset, valuep, size); } diff --git a/drivers/pci/pcie_dw_mvebu.c b/drivers/pci/pcie_dw_mvebu.c index 693591e375..1f216e1c68 100644 --- a/drivers/pci/pcie_dw_mvebu.c +++ b/drivers/pci/pcie_dw_mvebu.c @@ -240,7 +240,7 @@ static int pcie_dw_addr_valid(pci_dev_t d, int first_busno) * * Return: 0 on success */ -static int pcie_dw_mvebu_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_dw_mvebu_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_dw_ti.c b/drivers/pci/pcie_dw_ti.c index b37fc2de7f..433640d3e7 100644 --- a/drivers/pci/pcie_dw_ti.c +++ b/drivers/pci/pcie_dw_ti.c @@ -289,7 +289,7 @@ static int pcie_dw_addr_valid(pci_dev_t d, int first_busno) * * Return: 0 on success */ -static int pcie_dw_ti_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_dw_ti_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_ecam_generic.c b/drivers/pci/pcie_ecam_generic.c index 00644edd26..c875f3a5b7 100644 --- a/drivers/pci/pcie_ecam_generic.c +++ b/drivers/pci/pcie_ecam_generic.c @@ -35,8 +35,9 @@ struct generic_ecam_pcie { * code. Otherwise the address to access will be written to the pointer pointed * to by @paddress. */ -static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, - uint offset, void **paddress) +static int pci_generic_ecam_conf_address(const struct udevice *bus, + pci_dev_t bdf, uint offset, + void **paddress) { struct generic_ecam_pcie *pcie = dev_get_priv(bus); void *addr; @@ -63,9 +64,9 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, * space of the device identified by the bus, device & function numbers in @bdf * on the PCI bus @bus. */ -static int pci_generic_ecam_read_config(struct udevice *bus, pci_dev_t bdf, - uint offset, ulong *valuep, - enum pci_size_t size) +static int pci_generic_ecam_read_config(const struct udevice *bus, + pci_dev_t bdf, uint offset, + ulong *valuep, enum pci_size_t size) { return pci_generic_mmap_read_config(bus, pci_generic_ecam_conf_address, bdf, offset, valuep, size); diff --git a/drivers/pci/pcie_fsl.c b/drivers/pci/pcie_fsl.c index ab25aeee73..f516ec0576 100644 --- a/drivers/pci/pcie_fsl.c +++ b/drivers/pci/pcie_fsl.c @@ -42,7 +42,7 @@ static int fsl_pcie_addr_valid(struct fsl_pcie *pcie, pci_dev_t bdf) return 0; } -static int fsl_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_imx.c b/drivers/pci/pcie_imx.c index 3621636cb2..8e1713a2d1 100644 --- a/drivers/pci/pcie_imx.c +++ b/drivers/pci/pcie_imx.c @@ -748,7 +748,7 @@ void pci_init_board(void) imx_pcie_init(); } #else -static int imx_pcie_dm_read_config(struct udevice *dev, pci_dev_t bdf, +static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pcie_intel_fpga.c b/drivers/pci/pcie_intel_fpga.c index a5ea4888f3..a1f6e95e69 100644 --- a/drivers/pci/pcie_intel_fpga.c +++ b/drivers/pci/pcie_intel_fpga.c @@ -226,7 +226,7 @@ static int tlp_cfg_dword_write(struct intel_fpga_pcie *pcie, pci_dev_t bdf, return tlp_read_packet(pcie, NULL); } -int intel_fpga_rp_conf_addr(struct udevice *bus, pci_dev_t bdf, +int intel_fpga_rp_conf_addr(const struct udevice *bus, pci_dev_t bdf, uint offset, void **paddress) { struct intel_fpga_pcie *pcie = dev_get_priv(bus); @@ -326,7 +326,7 @@ static int _pcie_intel_fpga_write_config(struct intel_fpga_pcie *pcie, byte_en, data); } -static int pcie_intel_fpga_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_intel_fpga_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_layerscape.c b/drivers/pci/pcie_layerscape.c index 2ab67d1fc9..8b313e9278 100644 --- a/drivers/pci/pcie_layerscape.c +++ b/drivers/pci/pcie_layerscape.c @@ -243,7 +243,7 @@ static int ls_pcie_addr_valid(struct ls_pcie *pcie, pci_dev_t bdf) return 0; } -int ls_pcie_conf_address(struct udevice *bus, pci_dev_t bdf, +int ls_pcie_conf_address(const struct udevice *bus, pci_dev_t bdf, uint offset, void **paddress) { struct ls_pcie *pcie = dev_get_priv(bus); @@ -271,7 +271,7 @@ int ls_pcie_conf_address(struct udevice *bus, pci_dev_t bdf, return 0; } -static int ls_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int ls_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_layerscape_gen4.c b/drivers/pci/pcie_layerscape_gen4.c index 1fd8761bbc..cec61fa7d6 100644 --- a/drivers/pci/pcie_layerscape_gen4.c +++ b/drivers/pci/pcie_layerscape_gen4.c @@ -227,7 +227,7 @@ void *ls_pcie_g4_conf_address(struct ls_pcie_g4 *pcie, pci_dev_t bdf, return pcie->cfg + offset; } -static int ls_pcie_g4_read_config(struct udevice *bus, pci_dev_t bdf, +static int ls_pcie_g4_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_mediatek.c b/drivers/pci/pcie_mediatek.c index a0dcb258b0..0b412aca0e 100644 --- a/drivers/pci/pcie_mediatek.c +++ b/drivers/pci/pcie_mediatek.c @@ -66,7 +66,7 @@ struct mtk_pcie { struct list_head ports; }; -static int mtk_pcie_config_address(struct udevice *udev, pci_dev_t bdf, +static int mtk_pcie_config_address(const struct udevice *udev, pci_dev_t bdf, uint offset, void **paddress) { struct mtk_pcie *pcie = dev_get_priv(udev); @@ -77,7 +77,7 @@ static int mtk_pcie_config_address(struct udevice *udev, pci_dev_t bdf, return 0; } -static int mtk_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int mtk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_phytium.c b/drivers/pci/pcie_phytium.c index 92e281e7c2..51b2171f9f 100644 --- a/drivers/pci/pcie_phytium.c +++ b/drivers/pci/pcie_phytium.c @@ -75,9 +75,8 @@ static int phytium_pci_skip_dev(pci_dev_t parent) * code. Otherwise the address to access will be written to the pointer pointed * to by @paddress. */ -static int pci_phytium_conf_address(struct udevice *bus, pci_dev_t bdf, - uint offset, - void **paddress) +static int pci_phytium_conf_address(const struct udevice *bus, pci_dev_t bdf, + uint offset, void **paddress) { struct phytium_pcie *pcie = dev_get_priv(bus); void *addr; @@ -119,7 +118,7 @@ static int pci_phytium_conf_address(struct udevice *bus, pci_dev_t bdf, * space of the device identified by the bus, device & function numbers in @bdf * on the PCI bus @bus. */ -static int pci_phytium_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_phytium_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_xilinx.c b/drivers/pci/pcie_xilinx.c index 44a5f1e1f4..05787ae144 100644 --- a/drivers/pci/pcie_xilinx.c +++ b/drivers/pci/pcie_xilinx.c @@ -54,7 +54,7 @@ static bool pcie_xilinx_link_up(struct xilinx_pcie *pcie) * * Return: 0 on success, else -ENODEV */ -static int pcie_xilinx_config_address(struct udevice *udev, pci_dev_t bdf, +static int pcie_xilinx_config_address(const struct udevice *udev, pci_dev_t bdf, uint offset, void **paddress) { struct xilinx_pcie *pcie = dev_get_priv(udev); @@ -97,7 +97,7 @@ static int pcie_xilinx_config_address(struct udevice *udev, pci_dev_t bdf, * * Return: 0 on success, else -ENODEV or -EINVAL */ -static int pcie_xilinx_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_xilinx_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/power/acpi_pmc/pmc_emul.c b/drivers/power/acpi_pmc/pmc_emul.c index 15cc7acaf3..dfff335e54 100644 --- a/drivers/power/acpi_pmc/pmc_emul.c +++ b/drivers/power/acpi_pmc/pmc_emul.c @@ -42,7 +42,7 @@ struct pmc_emul_priv { u8 regs[MEMMAP_SIZE]; }; -static int sandbox_pmc_emul_read_config(struct udevice *emul, uint offset, +static int sandbox_pmc_emul_read_config(const struct udevice *emul, uint offset, ulong *valuep, enum pci_size_t size) { struct pmc_emul_platdata *plat = dev_get_platdata(emul); diff --git a/include/pci.h b/include/pci.h index 8c761d8da3..40e3c3fc6f 100644 --- a/include/pci.h +++ b/include/pci.h @@ -899,8 +899,8 @@ struct dm_pci_ops { * @size: Access size * @return 0 if OK, -ve on error */ - int (*read_config)(struct udevice *bus, pci_dev_t bdf, uint offset, - ulong *valuep, enum pci_size_t size); + int (*read_config)(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, enum pci_size_t size); /** * write_config() - Write a PCI configuration value * @@ -974,7 +974,7 @@ int dm_pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp); * @devp: Returns the device for this address, if found * @return 0 if OK, -ENODEV if not found */ -int pci_bus_find_devfn(struct udevice *bus, pci_dev_t find_devfn, +int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **devp); /** @@ -1155,8 +1155,9 @@ int pci_read_config8(pci_dev_t pcidev, int offset, u8 *valuep); * Return: 0 on success, else -EINVAL */ int pci_generic_mmap_write_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong value, @@ -1180,8 +1181,9 @@ int pci_generic_mmap_write_config( * Return: 0 on success, else -EINVAL */ int pci_generic_mmap_read_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong *valuep, @@ -1523,8 +1525,8 @@ struct dm_pci_emul_ops { * @size: Access size * @return 0 if OK, -ve on error */ - int (*read_config)(struct udevice *dev, uint offset, ulong *valuep, - enum pci_size_t size); + int (*read_config)(const struct udevice *dev, uint offset, + ulong *valuep, enum pci_size_t size); /** * write_config() - Write a PCI configuration value * @@ -1609,7 +1611,7 @@ struct dm_pci_emul_ops { * @emulp: Returns emulated device if found * @return 0 if found, -ENODEV if not found */ -int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, +int sandbox_pci_get_emul(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp); /** From patchwork Mon Jan 27 15:49:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240292 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:38 -0700 Subject: [PATCH 03/21] dm: pci: Update a few more interfaces for const udevice * In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.3.I36b78dcb38fa3d0b3f6ca37cdcc6b8df09a2ae22@changeid> Tidy up a few places where const * should be used. Signed-off-by: Simon Glass --- drivers/pci/pci-uclass.c | 18 +++++++++--------- include/fdtdec.h | 2 +- include/pci.h | 16 ++++++++-------- lib/fdtdec.c | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 78d4129572..5f318120e1 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -43,7 +43,7 @@ struct udevice *pci_get_controller(struct udevice *dev) return dev; } -pci_dev_t dm_pci_get_bdf(struct udevice *dev) +pci_dev_t dm_pci_get_bdf(const struct udevice *dev) { struct pci_child_platdata *pplat = dev_get_parent_platdata(dev); struct udevice *bus = dev->parent; @@ -349,7 +349,7 @@ int dm_pci_write_config32(struct udevice *dev, int offset, u32 value) return dm_pci_write_config(dev, offset, value, PCI_SIZE_32); } -int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset, +int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset, unsigned long *valuep, enum pci_size_t size) { struct dm_pci_ops *ops; @@ -373,10 +373,10 @@ int pci_read_config(pci_dev_t bdf, int offset, unsigned long *valuep, return pci_bus_read_config(bus, bdf, offset, valuep, size); } -int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep, - enum pci_size_t size) +int dm_pci_read_config(const struct udevice *dev, int offset, + unsigned long *valuep, enum pci_size_t size) { - struct udevice *bus; + const struct udevice *bus; for (bus = dev; device_is_on_pci_bus(bus);) bus = bus->parent; @@ -423,7 +423,7 @@ int pci_read_config8(pci_dev_t bdf, int offset, u8 *valuep) return 0; } -int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep) +int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep) { unsigned long value; int ret; @@ -436,7 +436,7 @@ int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep) return 0; } -int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep) +int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep) { unsigned long value; int ret; @@ -449,7 +449,7 @@ int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep) return 0; } -int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep) +int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep) { unsigned long value; int ret; @@ -1203,7 +1203,7 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop, return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL); } -u32 dm_pci_read_bar32(struct udevice *dev, int barnum) +u32 dm_pci_read_bar32(const struct udevice *dev, int barnum) { u32 addr; int bar; diff --git a/include/fdtdec.h b/include/fdtdec.h index c8a143db5f..166f29c55b 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -441,7 +441,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node, * @param bar returns base address of the pci device's registers * @return 0 if ok, negative on error */ -int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, +int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr, u32 *bar); /** diff --git a/include/pci.h b/include/pci.h index 40e3c3fc6f..50ca249f2d 100644 --- a/include/pci.h +++ b/include/pci.h @@ -924,7 +924,7 @@ struct dm_pci_ops { * @dev: Device to check * @return bus/device/function value (see PCI_BDF()) */ -pci_dev_t dm_pci_get_bdf(struct udevice *dev); +pci_dev_t dm_pci_get_bdf(const struct udevice *dev); /** * pci_bind_bus_devices() - scan a PCI bus and bind devices @@ -1067,7 +1067,7 @@ int dm_pci_hose_probe_bus(struct udevice *bus); * @size: Access size * @return 0 if OK, -ve on error */ -int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset, +int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset, unsigned long *valuep, enum pci_size_t size); /** @@ -1102,12 +1102,12 @@ int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset, * Driver model PCI config access functions. Use these in preference to others * when you have a valid device */ -int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep, - enum pci_size_t size); +int dm_pci_read_config(const struct udevice *dev, int offset, + unsigned long *valuep, enum pci_size_t size); -int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep); -int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep); -int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep); +int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep); +int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep); +int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep); int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value, enum pci_size_t size); @@ -1313,7 +1313,7 @@ void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr); * @barnum: Bar number to read (numbered from 0) * @return: value of BAR */ -u32 dm_pci_read_bar32(struct udevice *dev, int barnum); +u32 dm_pci_read_bar32(const struct udevice *dev, int barnum); /** * dm_pci_bus_to_phys() - convert a PCI bus address to a physical address diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 17051d409c..7fbb4c7ddc 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -224,7 +224,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device) return -ENOENT; } -int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, +int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr, u32 *bar) { int barnum; From patchwork Mon Jan 27 15:49:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240294 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:39 -0700 Subject: [PATCH 04/21] dm: core: Use const device for the devfdt...() interface In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.4.I875a778e957587ebdead7b7a09d91ba410ad9d08@changeid> These functions do not modify the device so should use a const pointer to it. Update the code accordingly. Signed-off-by: Simon Glass --- drivers/core/fdtaddr.c | 26 +++++++++++++------------- include/dm/fdtaddr.h | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 575798fae9..33811e62f7 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR; -fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index) +fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index) { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) fdt_addr_t addr; @@ -91,8 +91,8 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index) #endif } -fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, - fdt_size_t *size) +fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, + fdt_size_t *size) { #if CONFIG_IS_ENABLED(OF_CONTROL) /* @@ -113,7 +113,7 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, #endif } -fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name) +fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) { #if CONFIG_IS_ENABLED(OF_CONTROL) int index; @@ -129,8 +129,8 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name) #endif } -fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, - fdt_size_t *size) +fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, + const char *name, fdt_size_t *size) { #if CONFIG_IS_ENABLED(OF_CONTROL) int index; @@ -146,17 +146,17 @@ fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, #endif } -fdt_addr_t devfdt_get_addr(struct udevice *dev) +fdt_addr_t devfdt_get_addr(const struct udevice *dev) { return devfdt_get_addr_index(dev, 0); } -void *devfdt_get_addr_ptr(struct udevice *dev) +void *devfdt_get_addr_ptr(const struct udevice *dev) { return (void *)(uintptr_t)devfdt_get_addr_index(dev, 0); } -void *devfdt_remap_addr_index(struct udevice *dev, int index) +void *devfdt_remap_addr_index(const struct udevice *dev, int index) { fdt_addr_t addr = devfdt_get_addr_index(dev, index); @@ -166,7 +166,7 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } -void *devfdt_remap_addr_name(struct udevice *dev, const char *name) +void *devfdt_remap_addr_name(const struct udevice *dev, const char *name) { fdt_addr_t addr = devfdt_get_addr_name(dev, name); @@ -176,12 +176,12 @@ void *devfdt_remap_addr_name(struct udevice *dev, const char *name) return map_physmem(addr, 0, MAP_NOCACHE); } -void *devfdt_remap_addr(struct udevice *dev) +void *devfdt_remap_addr(const struct udevice *dev) { return devfdt_remap_addr_index(dev, 0); } -void *devfdt_map_physmem(struct udevice *dev, unsigned long size) +void *devfdt_map_physmem(const struct udevice *dev, unsigned long size) { fdt_addr_t addr = devfdt_get_addr(dev); @@ -191,7 +191,7 @@ void *devfdt_map_physmem(struct udevice *dev, unsigned long size) return map_physmem(addr, size, MAP_NOCACHE); } -fdt_addr_t devfdt_get_addr_pci(struct udevice *dev) +fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev) { ulong addr; diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index 959d3bc2d6..a4fda581a7 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -21,7 +21,7 @@ struct udevice; * * @return addr */ -fdt_addr_t devfdt_get_addr(struct udevice *dev); +fdt_addr_t devfdt_get_addr(const struct udevice *dev); /** * devfdt_get_addr_ptr() - Return pointer to the address of the reg property @@ -31,7 +31,7 @@ fdt_addr_t devfdt_get_addr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_get_addr_ptr(struct udevice *dev); +void *devfdt_get_addr_ptr(const struct udevice *dev); /** * devfdt_remap_addr() - Return pointer to the memory-mapped I/O address @@ -41,7 +41,7 @@ void *devfdt_get_addr_ptr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr(struct udevice *dev); +void *devfdt_remap_addr(const struct udevice *dev); /** * devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped @@ -53,7 +53,7 @@ void *devfdt_remap_addr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr_index(struct udevice *dev, int index); +void *devfdt_remap_addr_index(const struct udevice *dev, int index); /** * devfdt_remap_addr_name() - Get the reg property of a device, indexed by @@ -66,7 +66,7 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr_name(struct udevice *dev, const char *name); +void *devfdt_remap_addr_name(const struct udevice *dev, const char *name); /** * devfdt_map_physmem() - Read device address from reg property of the @@ -79,7 +79,7 @@ void *devfdt_remap_addr_name(struct udevice *dev, const char *name); * @return mapped address, or NULL if the device does not have reg * property. */ -void *devfdt_map_physmem(struct udevice *dev, unsigned long size); +void *devfdt_map_physmem(const struct udevice *dev, unsigned long size); /** * devfdt_get_addr_index() - Get the indexed reg property of a device @@ -90,7 +90,7 @@ void *devfdt_map_physmem(struct udevice *dev, unsigned long size); * * @return addr */ -fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index); +fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index); /** * devfdt_get_addr_size_index() - Get the indexed reg property of a device @@ -105,8 +105,8 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index); * * @return addr */ -fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, - fdt_size_t *size); +fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, + fdt_size_t *size); /** * devfdt_get_addr_name() - Get the reg property of a device, indexed by name @@ -118,7 +118,7 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, * * @return addr */ -fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name); +fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); /** * devfdt_get_addr_size_name() - Get the reg property and its size for a device, @@ -135,8 +135,8 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name); * * @return addr */ -fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, - fdt_size_t *size); +fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, + const char *name, fdt_size_t *size); /** * devfdt_get_addr_pci() - Read an address and handle PCI address translation @@ -144,6 +144,6 @@ fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, * @dev: Device to read from * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t devfdt_get_addr_pci(struct udevice *dev); +fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev); #endif From patchwork Mon Jan 27 15:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240296 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:40 -0700 Subject: [PATCH 05/21] dm: core: Use const device for the dev_read_...() interface In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.5.I875a778e957587ebdead7b7a09d91ba410ad9d08@changeid> These functions do not modify the device so should use a const pointer to it. Update the code accordingly. Signed-off-by: Simon Glass --- drivers/core/read.c | 97 +++++++++++---------- include/dm/read.h | 205 +++++++++++++++++++++++--------------------- 2 files changed, 159 insertions(+), 143 deletions(-) diff --git a/drivers/core/read.c b/drivers/core/read.c index 9602e52d1b..1f999b1b31 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -11,27 +11,29 @@ #include #include -int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp) +int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, outp); } -int dev_read_u32_default(struct udevice *dev, const char *propname, int def) +int dev_read_u32_default(const struct udevice *dev, const char *propname, + int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp) +int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); } -int dev_read_s32_default(struct udevice *dev, const char *propname, int def) +int dev_read_s32_default(const struct udevice *dev, const char *propname, + int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp) +int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) { u32 val; int ret; @@ -44,32 +46,33 @@ int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp) return 0; } -int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp) +int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) { return ofnode_read_u64(dev_ofnode(dev), propname, outp); } -u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def) +u64 dev_read_u64_default(const struct udevice *dev, const char *propname, + u64 def) { return ofnode_read_u64_default(dev_ofnode(dev), propname, def); } -const char *dev_read_string(struct udevice *dev, const char *propname) +const char *dev_read_string(const struct udevice *dev, const char *propname) { return ofnode_read_string(dev_ofnode(dev), propname); } -bool dev_read_bool(struct udevice *dev, const char *propname) +bool dev_read_bool(const struct udevice *dev, const char *propname) { return ofnode_read_bool(dev_ofnode(dev), propname); } -ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name) +ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name) { return ofnode_find_subnode(dev_ofnode(dev), subnode_name); } -ofnode dev_read_first_subnode(struct udevice *dev) +ofnode dev_read_first_subnode(const struct udevice *dev) { return ofnode_first_subnode(dev_ofnode(dev)); } @@ -79,12 +82,12 @@ ofnode dev_read_next_subnode(ofnode node) return ofnode_next_subnode(node); } -int dev_read_size(struct udevice *dev, const char *propname) +int dev_read_size(const struct udevice *dev, const char *propname) { return ofnode_read_size(dev_ofnode(dev), propname); } -fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index) { if (ofnode_is_np(dev_ofnode(dev))) return ofnode_get_addr_index(dev_ofnode(dev), index); @@ -92,7 +95,7 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) return devfdt_get_addr_index(dev, index); } -fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, +fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size) { if (ofnode_is_np(dev_ofnode(dev))) @@ -101,7 +104,7 @@ fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, return devfdt_get_addr_size_index(dev, index, size); } -void *dev_remap_addr_index(struct udevice *dev, int index) +void *dev_remap_addr_index(const struct udevice *dev, int index) { fdt_addr_t addr = dev_read_addr_index(dev, index); @@ -111,7 +114,7 @@ void *dev_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } -fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) +fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) { int index = dev_read_stringlist_search(dev, "reg-names", name); @@ -121,7 +124,7 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) return dev_read_addr_index(dev, index); } -fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, +fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { int index = dev_read_stringlist_search(dev, "reg-names", name); @@ -132,7 +135,7 @@ fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, return dev_read_addr_size_index(dev, index, size); } -void *dev_remap_addr_name(struct udevice *dev, const char *name) +void *dev_remap_addr_name(const struct udevice *dev, const char *name) { fdt_addr_t addr = dev_read_addr_name(dev, name); @@ -142,52 +145,52 @@ void *dev_remap_addr_name(struct udevice *dev, const char *name) return map_physmem(addr, 0, MAP_NOCACHE); } -fdt_addr_t dev_read_addr(struct udevice *dev) +fdt_addr_t dev_read_addr(const struct udevice *dev) { return dev_read_addr_index(dev, 0); } -void *dev_read_addr_ptr(struct udevice *dev) +void *dev_read_addr_ptr(const struct udevice *dev) { fdt_addr_t addr = dev_read_addr(dev); return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0); } -void *dev_remap_addr(struct udevice *dev) +void *dev_remap_addr(const struct udevice *dev) { return dev_remap_addr_index(dev, 0); } -fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, +fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *property, fdt_size_t *sizep) { return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); } -const char *dev_read_name(struct udevice *dev) +const char *dev_read_name(const struct udevice *dev) { return ofnode_get_name(dev_ofnode(dev)); } -int dev_read_stringlist_search(struct udevice *dev, const char *property, +int dev_read_stringlist_search(const struct udevice *dev, const char *property, const char *string) { return ofnode_stringlist_search(dev_ofnode(dev), property, string); } -int dev_read_string_index(struct udevice *dev, const char *propname, int index, - const char **outp) +int dev_read_string_index(const struct udevice *dev, const char *propname, + int index, const char **outp) { return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); } -int dev_read_string_count(struct udevice *dev, const char *propname) +int dev_read_string_count(const struct udevice *dev, const char *propname) { return ofnode_read_string_count(dev_ofnode(dev), propname); } -int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, +int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args) { @@ -196,34 +199,34 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, out_args); } -int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name) +int dev_count_phandle_with_args(const struct udevice *dev, + const char *list_name, const char *cells_name) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, cells_name); } -int dev_read_addr_cells(struct udevice *dev) +int dev_read_addr_cells(const struct udevice *dev) { return ofnode_read_addr_cells(dev_ofnode(dev)); } -int dev_read_size_cells(struct udevice *dev) +int dev_read_size_cells(const struct udevice *dev) { return ofnode_read_size_cells(dev_ofnode(dev)); } -int dev_read_simple_addr_cells(struct udevice *dev) +int dev_read_simple_addr_cells(const struct udevice *dev) { return ofnode_read_simple_addr_cells(dev_ofnode(dev)); } -int dev_read_simple_size_cells(struct udevice *dev) +int dev_read_simple_size_cells(const struct udevice *dev) { return ofnode_read_simple_size_cells(dev_ofnode(dev)); } -int dev_read_phandle(struct udevice *dev) +int dev_read_phandle(const struct udevice *dev) { ofnode node = dev_ofnode(dev); @@ -233,12 +236,13 @@ int dev_read_phandle(struct udevice *dev) return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); } -const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp) +const void *dev_read_prop(const struct udevice *dev, const char *propname, + int *lenp) { return ofnode_get_property(dev_ofnode(dev), propname, lenp); } -int dev_read_alias_seq(struct udevice *dev, int *devnump) +int dev_read_alias_seq(const struct udevice *dev, int *devnump) { ofnode node = dev_ofnode(dev); const char *uc_name = dev->uclass->uc_drv->name; @@ -256,19 +260,19 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump) return ret; } -int dev_read_u32_array(struct udevice *dev, const char *propname, +int dev_read_u32_array(const struct udevice *dev, const char *propname, u32 *out_values, size_t sz) { return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } -const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, - size_t sz) +const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, + const char *propname, size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } -int dev_read_enabled(struct udevice *dev) +int dev_read_enabled(const struct udevice *dev) { ofnode node = dev_ofnode(dev); @@ -279,23 +283,24 @@ int dev_read_enabled(struct udevice *dev) ofnode_to_offset(node)); } -int dev_read_resource(struct udevice *dev, uint index, struct resource *res) +int dev_read_resource(const struct udevice *dev, uint index, + struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } -int dev_read_resource_byname(struct udevice *dev, const char *name, +int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res) { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } -u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } -u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr) +u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } @@ -308,7 +313,7 @@ int dev_read_alias_highest_id(const char *stem) return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); } -fdt_addr_t dev_read_addr_pci(struct udevice *dev) +fdt_addr_t dev_read_addr_pci(const struct udevice *dev) { ulong addr; diff --git a/include/dm/read.h b/include/dm/read.h index f1c1553f80..92a7328fc8 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -16,12 +16,12 @@ struct resource; #if CONFIG_IS_ENABLED(OF_LIVE) -static inline const struct device_node *dev_np(struct udevice *dev) +static inline const struct device_node *dev_np(const struct udevice *dev) { return ofnode_to_np(dev->node); } #else -static inline const struct device_node *dev_np(struct udevice *dev) +static inline const struct device_node *dev_np(const struct udevice *dev) { return NULL; } @@ -53,7 +53,7 @@ static inline bool dev_of_valid(const struct udevice *dev) * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); +int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp); /** * dev_read_u32_default() - read a 32-bit integer from a device's DT property @@ -63,7 +63,8 @@ int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -int dev_read_u32_default(struct udevice *dev, const char *propname, int def); +int dev_read_u32_default(const struct udevice *dev, const char *propname, + int def); /** * dev_read_s32() - read a signed 32-bit integer from a device's DT property @@ -73,7 +74,7 @@ int dev_read_u32_default(struct udevice *dev, const char *propname, int def); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); +int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp); /** * dev_read_s32_default() - read a signed 32-bit int from a device's DT property @@ -83,7 +84,8 @@ int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -int dev_read_s32_default(struct udevice *dev, const char *propname, int def); +int dev_read_s32_default(const struct udevice *dev, const char *propname, + int def); /** * dev_read_u32u() - read a 32-bit integer from a device's DT property @@ -95,7 +97,7 @@ int dev_read_s32_default(struct udevice *dev, const char *propname, int def); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); +int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp); /** * dev_read_u64() - read a 64-bit integer from a device's DT property @@ -105,7 +107,7 @@ int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp); +int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp); /** * dev_read_u64_default() - read a 64-bit integer from a device's DT property @@ -115,7 +117,8 @@ int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def); +u64 dev_read_u64_default(const struct udevice *dev, const char *propname, + u64 def); /** * dev_read_string() - Read a string from a device's DT property @@ -124,7 +127,7 @@ u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def); * @propname: name of the property to read * @return string from property value, or NULL if there is no such property */ -const char *dev_read_string(struct udevice *dev, const char *propname); +const char *dev_read_string(const struct udevice *dev, const char *propname); /** * dev_read_bool() - read a boolean value from a device's DT property @@ -133,7 +136,7 @@ const char *dev_read_string(struct udevice *dev, const char *propname); * @propname: name of property to read * @return true if property is present (meaning true), false if not present */ -bool dev_read_bool(struct udevice *dev, const char *propname); +bool dev_read_bool(const struct udevice *dev, const char *propname); /** * dev_read_subnode() - find a named subnode of a device @@ -143,7 +146,7 @@ bool dev_read_bool(struct udevice *dev, const char *propname); * @return reference to subnode (which can be invalid if there is no such * subnode) */ -ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); +ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name); /** * dev_read_size() - read the size of a property @@ -152,7 +155,7 @@ ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); * @propname: property to check * @return size of property if present, or -EINVAL if not */ -int dev_read_size(struct udevice *dev, const char *propname); +int dev_read_size(const struct udevice *dev, const char *propname); /** * dev_read_addr_index() - Get the indexed reg property of a device @@ -163,7 +166,7 @@ int dev_read_size(struct udevice *dev, const char *propname); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); +fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index); /** * dev_read_addr_size_index() - Get the indexed reg property of a device @@ -175,7 +178,7 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, +fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size); /** @@ -188,7 +191,7 @@ fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, * * @return pointer or NULL if not found */ -void *dev_remap_addr_index(struct udevice *dev, int index); +void *dev_remap_addr_index(const struct udevice *dev, int index); /** * dev_read_addr_name() - Get the reg property of a device, indexed by name @@ -200,7 +203,7 @@ void *dev_remap_addr_index(struct udevice *dev, int index); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); +fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name); /** * dev_read_addr_size_name() - Get the reg property of a device, indexed by name @@ -213,7 +216,7 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, +fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size); /** @@ -227,7 +230,7 @@ fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, * * @return pointer or NULL if not found */ -void *dev_remap_addr_name(struct udevice *dev, const char* name); +void *dev_remap_addr_name(const struct udevice *dev, const char *name); /** * dev_read_addr() - Get the reg property of a device @@ -236,7 +239,7 @@ void *dev_remap_addr_name(struct udevice *dev, const char* name); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr(struct udevice *dev); +fdt_addr_t dev_read_addr(const struct udevice *dev); /** * dev_read_addr_ptr() - Get the reg property of a device @@ -246,7 +249,7 @@ fdt_addr_t dev_read_addr(struct udevice *dev); * * @return pointer or NULL if not found */ -void *dev_read_addr_ptr(struct udevice *dev); +void *dev_read_addr_ptr(const struct udevice *dev); /** * dev_read_addr_pci() - Read an address and handle PCI address translation @@ -266,7 +269,7 @@ void *dev_read_addr_ptr(struct udevice *dev); * @dev: Device to read from * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_pci(struct udevice *dev); +fdt_addr_t dev_read_addr_pci(const struct udevice *dev); /** * dev_remap_addr() - Get the reg property of a device as a @@ -276,7 +279,7 @@ fdt_addr_t dev_read_addr_pci(struct udevice *dev); * * @return pointer or NULL if not found */ -void *dev_remap_addr(struct udevice *dev); +void *dev_remap_addr(const struct udevice *dev); /** * dev_read_addr_size() - get address and size from a device property @@ -289,8 +292,8 @@ void *dev_remap_addr(struct udevice *dev); * @sizep: place to put size value (on success) * @return address value, or FDT_ADDR_T_NONE on error */ -fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, - fdt_size_t *sizep); +fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname, + fdt_size_t *sizep); /** * dev_read_name() - get the name of a device's node @@ -298,7 +301,7 @@ fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, * @dev: Device to read from * @return name of node */ -const char *dev_read_name(struct udevice *dev); +const char *dev_read_name(const struct udevice *dev); /** * dev_read_stringlist_search() - find string in a string list and return index @@ -318,8 +321,8 @@ const char *dev_read_name(struct udevice *dev); * -ENODATA if the property is not found * -EINVAL on some other error */ -int dev_read_stringlist_search(struct udevice *dev, const char *property, - const char *string); +int dev_read_stringlist_search(const struct udevice *dev, const char *property, + const char *string); /** * dev_read_string_index() - obtain an indexed string from a string list @@ -332,8 +335,8 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, * @return: * length of string, if found or -ve error value if not found */ -int dev_read_string_index(struct udevice *dev, const char *propname, int index, - const char **outp); +int dev_read_string_index(const struct udevice *dev, const char *propname, + int index, const char **outp); /** * dev_read_string_count() - find the number of strings in a string list @@ -343,7 +346,7 @@ int dev_read_string_index(struct udevice *dev, const char *propname, int index, * @return: * number of strings in the list, or -ve error value if not found */ -int dev_read_string_count(struct udevice *dev, const char *propname); +int dev_read_string_count(const struct udevice *dev, const char *propname); /** * dev_read_phandle_with_args() - Find a node pointed by phandle in a list * @@ -382,10 +385,9 @@ int dev_read_string_count(struct udevice *dev, const char *propname); * @cells_name could not be found, the arguments were truncated or there * were too many arguments. */ -int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name, int cell_count, - int index, - struct ofnode_phandle_args *out_args); +int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, + const char *cells_name, int cell_count, + int index, struct ofnode_phandle_args *out_args); /** * dev_count_phandle_with_args() - Return phandle number in a list @@ -402,8 +404,8 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, * errno value. */ -int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name); +int dev_count_phandle_with_args(const struct udevice *dev, + const char *list_name, const char *cells_name); /** * dev_read_addr_cells() - Get the number of address cells for a device's node @@ -414,7 +416,7 @@ int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, * @dev: device to check * @return number of address cells this node uses */ -int dev_read_addr_cells(struct udevice *dev); +int dev_read_addr_cells(const struct udevice *dev); /** * dev_read_size_cells() - Get the number of size cells for a device's node @@ -425,7 +427,7 @@ int dev_read_addr_cells(struct udevice *dev); * @dev: device to check * @return number of size cells this node uses */ -int dev_read_size_cells(struct udevice *dev); +int dev_read_size_cells(const struct udevice *dev); /** * dev_read_addr_cells() - Get the address cells property in a node @@ -435,7 +437,7 @@ int dev_read_size_cells(struct udevice *dev); * @dev: device to check * @return number of address cells this node uses */ -int dev_read_simple_addr_cells(struct udevice *dev); +int dev_read_simple_addr_cells(const struct udevice *dev); /** * dev_read_size_cells() - Get the size cells property in a node @@ -445,7 +447,7 @@ int dev_read_simple_addr_cells(struct udevice *dev); * @dev: device to check * @return number of size cells this node uses */ -int dev_read_simple_size_cells(struct udevice *dev); +int dev_read_simple_size_cells(const struct udevice *dev); /** * dev_read_phandle() - Get the phandle from a device @@ -453,7 +455,7 @@ int dev_read_simple_size_cells(struct udevice *dev); * @dev: device to check * @return phandle (1 or greater), or 0 if no phandle or other error */ -int dev_read_phandle(struct udevice *dev); +int dev_read_phandle(const struct udevice *dev); /** * dev_read_prop()- - read a property from a device's node @@ -463,7 +465,8 @@ int dev_read_phandle(struct udevice *dev); * @lenp: place to put length on success * @return pointer to property, or NULL if not found */ -const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); +const void *dev_read_prop(const struct udevice *dev, const char *propname, + int *lenp); /** * dev_read_alias_seq() - Get the alias sequence number of a node @@ -476,7 +479,7 @@ const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); * @devnump: set to the sequence number if one is found * @return 0 if a sequence was found, -ve if not */ -int dev_read_alias_seq(struct udevice *dev, int *devnump); +int dev_read_alias_seq(const struct udevice *dev, int *devnump); /** * dev_read_u32_array() - Find and read an array of 32 bit integers @@ -494,7 +497,7 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump); * property does not have a value, and -EOVERFLOW if the property data isn't * large enough. */ -int dev_read_u32_array(struct udevice *dev, const char *propname, +int dev_read_u32_array(const struct udevice *dev, const char *propname, u32 *out_values, size_t sz); /** @@ -504,7 +507,7 @@ int dev_read_u32_array(struct udevice *dev, const char *propname, * @return reference to the first subnode (which can be invalid if the device's * node has no subnodes) */ -ofnode dev_read_first_subnode(struct udevice *dev); +ofnode dev_read_first_subnode(const struct udevice *dev); /** * ofnode_next_subnode() - find the next sibling of a subnode @@ -529,8 +532,8 @@ ofnode dev_read_next_subnode(ofnode node); * @return pointer to byte array if found, or NULL if the property is not * found or there is not enough data */ -const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, - size_t sz); +const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, + const char *propname, size_t sz); /** * dev_read_enabled() - check whether a node is enabled @@ -543,7 +546,7 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, * @dev: device to examine * @return integer value 0 (not enabled) or 1 (enabled) */ -int dev_read_enabled(struct udevice *dev); +int dev_read_enabled(const struct udevice *dev); /** * dev_read_resource() - obtain an indexed resource from a device. @@ -553,7 +556,8 @@ int dev_read_enabled(struct udevice *dev); * @res returns the resource * @return 0 if ok, negative on error */ -int dev_read_resource(struct udevice *dev, uint index, struct resource *res); +int dev_read_resource(const struct udevice *dev, uint index, + struct resource *res); /** * dev_read_resource_byname() - obtain a named resource from a device. @@ -563,7 +567,7 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res); * @res: returns the resource * @return 0 if ok, negative on error */ -int dev_read_resource_byname(struct udevice *dev, const char *name, +int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res); /** @@ -577,7 +581,7 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, * @in_addr: pointer to the address to translate * @return the translated address; OF_BAD_ADDR on error */ -u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); +u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr); /** * dev_translate_dma_address() - Translate a device-tree DMA address @@ -590,7 +594,8 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); * @in_addr: pointer to the DMA address to translate * @return the translated DMA address; OF_BAD_ADDR on error */ -u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr); +u64 dev_translate_dma_address(const struct udevice *dev, + const fdt32_t *in_addr); /** * dev_read_alias_highest_id - Get highest alias id for the given stem @@ -604,31 +609,31 @@ int dev_read_alias_highest_id(const char *stem); #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ -static inline int dev_read_u32(struct udevice *dev, +static inline int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, outp); } -static inline int dev_read_u32_default(struct udevice *dev, +static inline int dev_read_u32_default(const struct udevice *dev, const char *propname, int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -static inline int dev_read_s32(struct udevice *dev, +static inline int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) { return ofnode_read_s32(dev_ofnode(dev), propname, outp); } -static inline int dev_read_s32_default(struct udevice *dev, +static inline int dev_read_s32_default(const struct udevice *dev, const char *propname, int def) { return ofnode_read_s32_default(dev_ofnode(dev), propname, def); } -static inline int dev_read_u32u(struct udevice *dev, +static inline int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) { u32 val; @@ -642,128 +647,131 @@ static inline int dev_read_u32u(struct udevice *dev, return 0; } -static inline int dev_read_u64(struct udevice *dev, +static inline int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) { return ofnode_read_u64(dev_ofnode(dev), propname, outp); } -static inline u64 dev_read_u64_default(struct udevice *dev, +static inline u64 dev_read_u64_default(const struct udevice *dev, const char *propname, u64 def) { return ofnode_read_u64_default(dev_ofnode(dev), propname, def); } -static inline const char *dev_read_string(struct udevice *dev, +static inline const char *dev_read_string(const struct udevice *dev, const char *propname) { return ofnode_read_string(dev_ofnode(dev), propname); } -static inline bool dev_read_bool(struct udevice *dev, const char *propname) +static inline bool dev_read_bool(const struct udevice *dev, + const char *propname) { return ofnode_read_bool(dev_ofnode(dev), propname); } -static inline ofnode dev_read_subnode(struct udevice *dev, +static inline ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name) { return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); } -static inline int dev_read_size(struct udevice *dev, const char *propname) +static inline int dev_read_size(const struct udevice *dev, const char *propname) { return ofnode_read_size(dev_ofnode(dev), propname); } -static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev, + int index) { return devfdt_get_addr_index(dev, index); } -static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size) { return devfdt_get_addr_size_index(dev, index, size); } -static inline fdt_addr_t dev_read_addr_name(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) { return devfdt_get_addr_name(dev, name); } -static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { return devfdt_get_addr_size_name(dev, name, size); } -static inline fdt_addr_t dev_read_addr(struct udevice *dev) +static inline fdt_addr_t dev_read_addr(const struct udevice *dev) { return devfdt_get_addr(dev); } -static inline void *dev_read_addr_ptr(struct udevice *dev) +static inline void *dev_read_addr_ptr(const struct udevice *dev) { return devfdt_get_addr_ptr(dev); } -static inline fdt_addr_t dev_read_addr_pci(struct udevice *dev) +static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev) { return devfdt_get_addr_pci(dev); } -static inline void *dev_remap_addr(struct udevice *dev) +static inline void *dev_remap_addr(const struct udevice *dev) { return devfdt_remap_addr(dev); } -static inline void *dev_remap_addr_index(struct udevice *dev, int index) +static inline void *dev_remap_addr_index(const struct udevice *dev, int index) { return devfdt_remap_addr_index(dev, index); } -static inline void *dev_remap_addr_name(struct udevice *dev, const char *name) +static inline void *dev_remap_addr_name(const struct udevice *dev, + const char *name) { return devfdt_remap_addr_name(dev, name); } -static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname, fdt_size_t *sizep) { return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); } -static inline const char *dev_read_name(struct udevice *dev) +static inline const char *dev_read_name(const struct udevice *dev) { return ofnode_get_name(dev_ofnode(dev)); } -static inline int dev_read_stringlist_search(struct udevice *dev, +static inline int dev_read_stringlist_search(const struct udevice *dev, const char *propname, const char *string) { return ofnode_stringlist_search(dev_ofnode(dev), propname, string); } -static inline int dev_read_string_index(struct udevice *dev, +static inline int dev_read_string_index(const struct udevice *dev, const char *propname, int index, const char **outp) { return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); } -static inline int dev_read_string_count(struct udevice *dev, +static inline int dev_read_string_count(const struct udevice *dev, const char *propname) { return ofnode_read_string_count(dev_ofnode(dev), propname); } -static inline int dev_read_phandle_with_args(struct udevice *dev, +static inline int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args) { @@ -772,59 +780,60 @@ static inline int dev_read_phandle_with_args(struct udevice *dev, out_args); } -static inline int dev_count_phandle_with_args(struct udevice *dev, +static inline int dev_count_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, cells_name); } -static inline int dev_read_addr_cells(struct udevice *dev) +static inline int dev_read_addr_cells(const struct udevice *dev) { /* NOTE: this call should walk up the parent stack */ return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_size_cells(struct udevice *dev) +static inline int dev_read_size_cells(const struct udevice *dev) { /* NOTE: this call should walk up the parent stack */ return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_simple_addr_cells(struct udevice *dev) +static inline int dev_read_simple_addr_cells(const struct udevice *dev) { return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_simple_size_cells(struct udevice *dev) +static inline int dev_read_simple_size_cells(const struct udevice *dev) { return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_phandle(struct udevice *dev) +static inline int dev_read_phandle(const struct udevice *dev) { return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); } -static inline const void *dev_read_prop(struct udevice *dev, +static inline const void *dev_read_prop(const struct udevice *dev, const char *propname, int *lenp) { return ofnode_get_property(dev_ofnode(dev), propname, lenp); } -static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) +static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump) { return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, dev_of_offset(dev), devnump); } -static inline int dev_read_u32_array(struct udevice *dev, const char *propname, - u32 *out_values, size_t sz) +static inline int dev_read_u32_array(const struct udevice *dev, + const char *propname, u32 *out_values, + size_t sz) { return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } -static inline ofnode dev_read_first_subnode(struct udevice *dev) +static inline ofnode dev_read_first_subnode(const struct udevice *dev) { return ofnode_first_subnode(dev_ofnode(dev)); } @@ -834,36 +843,38 @@ static inline ofnode dev_read_next_subnode(ofnode node) return ofnode_next_subnode(node); } -static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, +static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, const char *propname, size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } -static inline int dev_read_enabled(struct udevice *dev) +static inline int dev_read_enabled(const struct udevice *dev) { return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_resource(struct udevice *dev, uint index, +static inline int dev_read_resource(const struct udevice *dev, uint index, struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } -static inline int dev_read_resource_byname(struct udevice *dev, +static inline int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res) { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } -static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +static inline u64 dev_translate_address(const struct udevice *dev, + const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } -static inline u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr) +static inline u64 dev_translate_dma_address(const struct udevice *dev, + const fdt32_t *in_addr) { return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } From patchwork Mon Jan 27 15:49:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240293 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:41 -0700 Subject: [PATCH 06/21] test: Add underscore prefix to macro parameters In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.6.If6d0a8b5d09cac7de5b5ded8f9d5c5b6271f7893@changeid> If a test happens to use the same variable as the macro parameter the macro does not work as intended. Add an underscore to guard against this. Signed-off-by: Simon Glass --- include/test/ut.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/test/ut.h b/include/test/ut.h index f616c202f3..c9fc9cc839 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -56,39 +56,39 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two int expressions are equal */ #define ut_asserteq(expr1, expr2) { \ - unsigned int val1 = (expr1), val2 = (expr2); \ + unsigned int _val1 = (expr1), _val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \ - "Expected %#x (%d), got %#x (%d)", val1, val1, \ - val2, val2); \ + "Expected %#x (%d), got %#x (%d)", \ + _val1, _val1, _val2, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two string expressions are equal */ #define ut_asserteq_str(expr1, expr2) { \ - const char *val1 = (expr1), *val2 = (expr2); \ + const char *_val1 = (expr1), *_val2 = (expr2); \ \ - if (strcmp(val1, val2)) { \ + if (strcmp(_val1, _val2)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected \"%s\", got \"%s\"", val1, val2); \ + "Expected \"%s\", got \"%s\"", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two memory areas are equal */ #define ut_asserteq_mem(expr1, expr2, len) { \ - const u8 *val1 = (u8 *)(expr1), *val2 = (u8 *)(expr2); \ + const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \ const uint __len = len; \ \ - if (memcmp(val1, val2, __len)) { \ + if (memcmp(_val1, _val2, __len)) { \ char __buf1[64 + 1] = "\0"; \ char __buf2[64 + 1] = "\0"; \ - bin2hex(__buf1, val1, min(__len, (uint)32)); \ - bin2hex(__buf2, val2, min(__len, (uint)32)); \ + bin2hex(__buf1, _val1, min(__len, (uint)32)); \ + bin2hex(__buf2, _val2, min(__len, (uint)32)); \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ "Expected \"%s\", got \"%s\"", \ @@ -99,33 +99,33 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two pointers are equal */ #define ut_asserteq_ptr(expr1, expr2) { \ - const void *val1 = (expr1), *val2 = (expr2); \ + const void *_val1 = (expr1), *_val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected %p, got %p", val1, val2); \ + "Expected %p, got %p", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is NULL */ #define ut_assertnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val != NULL) { \ + if (_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " != NULL", \ - "Expected NULL, got %p", val); \ + "Expected NULL, got %p", _val); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is not NULL */ #define ut_assertnonnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val == NULL) { \ + if (!_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected non-null, got NULL"); \ @@ -135,13 +135,13 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that a pointer is not an error pointer */ #define ut_assertok_ptr(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (IS_ERR(val)) { \ + if (IS_ERR(_val)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected pointer, got error %ld", \ - PTR_ERR(val)); \ + PTR_ERR(_val)); \ return CMD_RET_FAILURE; \ } \ } From patchwork Mon Jan 27 15:49:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240295 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:42 -0700 Subject: [PATCH 07/21] dm: core: Update comment for ofnode_get_chosen_node() In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.7.If25281d45a0cd34637ee21792c9926a836078fcc@changeid> The current comment is a big vague and misleading. Rewrite it to state precisely what the function does. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 4282169706..62ba0c13ea 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -520,11 +520,14 @@ ofnode ofnode_path(const char *path); const char *ofnode_get_chosen_prop(const char *propname); /** - * ofnode_get_chosen_node() - get the chosen node + * ofnode_get_chosen_node() - get a referenced node from the chosen node * - * @return the chosen node if present, else ofnode_null() + * This looks up a named property in the chosen node and uses that as a path to + * look up a code. + * + * @return the referenced node if present, else ofnode_null() */ -ofnode ofnode_get_chosen_node(const char *name); +ofnode ofnode_get_chosen_node(const char *propname); struct display_timing; /** From patchwork Mon Jan 27 15:49:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240297 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:43 -0700 Subject: [PATCH 08/21] dm: core: Rename ofnode_get_chosen_prop() In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.8.I9f5ac53543976f8413d5879b751232b16efce5c3@changeid> This function is actually intended to read a string rather than a property. All of its current callers use it that way. Also there is no way to return the length of the property from this function. Rename it to better indicate its purpose, using ofnode_read as the prefix since this matches most other functions. Also add some tests which are missing for these functions. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 2 ++ .../puma_rk3399/puma-rk3399.c | 2 +- board/xilinx/common/board.c | 2 +- drivers/core/ofnode.c | 4 ++-- include/dm/ofnode.h | 9 ++++---- test/dm/ofnode.c | 21 +++++++++++++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e529c54d8d..a04afd4076 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -813,6 +813,8 @@ chosen { #address-cells = <1>; #size-cells = <1>; + setting = "sunrise ohoka"; + other-node = "/some-bus/c-test at 5"; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>; diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index 9887d20207..7ff4766947 100644 --- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -49,7 +49,7 @@ static void setup_iodomain(void) static int setup_boottargets(void) { const char *boot_device = - ofnode_get_chosen_prop("u-boot,spl-boot-device"); + ofnode_read_chosen_string("u-boot,spl-boot-device"); char *env_default, *env; if (!boot_device) { diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index ae5fe2729f..f87e2e9105 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -22,7 +22,7 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) return -ENODEV; debug("%s: Path to EEPROM %s\n", __func__, - ofnode_get_chosen_prop("xlnx,eeprom")); + ofnode_read_chosen_string("xlnx,eeprom")); ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); if (ret) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8f0eab2ca6..011b43bc02 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -419,7 +419,7 @@ ofnode ofnode_path(const char *path) return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path)); } -const char *ofnode_get_chosen_prop(const char *name) +const char *ofnode_read_chosen_string(const char *name) { ofnode chosen_node; @@ -432,7 +432,7 @@ ofnode ofnode_get_chosen_node(const char *name) { const char *prop; - prop = ofnode_get_chosen_prop(name); + prop = ofnode_read_chosen_string(name); if (!prop) return ofnode_null(); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 62ba0c13ea..9e76ae8407 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -510,14 +510,15 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, ofnode ofnode_path(const char *path); /** - * ofnode_get_chosen_prop() - get the value of a chosen property + * ofnode_read_chosen_string() - get the string value of a chosen property * - * This looks for a property within the /chosen node and returns its value + * This looks for a property within the /chosen node and returns its value, + * checking that it is a valid nul-terminated string * * @propname: Property name to look for - * @return property value if found, else NULL + * @return string value if found, else NULL */ -const char *ofnode_get_chosen_prop(const char *propname); +const char *ofnode_read_chosen_string(const char *propname); /** * ofnode_get_chosen_node() - get a referenced node from the chosen node diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 745de50c7b..633a3a9e9a 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -58,3 +58,24 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) +{ + const char *str; + ofnode node; + + str = ofnode_read_chosen_string("setting"); + ut_assertnonnull(str); + ut_asserteq_str("sunrise ohoka", str); + ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting")); + + node = ofnode_get_chosen_node("other-node"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("c-test at 5", ofnode_get_name(node)); + + node = ofnode_get_chosen_node("setting"); + ut_assert(!ofnode_valid(node)); + + return 0; +} +DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240298 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:44 -0700 Subject: [PATCH 09/21] dm: core: Add ofnode_read_prop() In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.9.Ib8a81e6304c5ed5ecb2149f2826a1c00cc4f5270@changeid> Add a new function to read a property that supports reading the length as well. Reimplement ofnode_read_string() using it and fix its comment. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 31 ++++++++++++++++++++++++------- include/dm/ofnode.h | 13 ++++++++++++- test/dm/ofnode.c | 26 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 011b43bc02..eebc5a7dce 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -101,30 +101,47 @@ bool ofnode_read_bool(ofnode node, const char *propname) return prop ? true : false; } -const char *ofnode_read_string(ofnode node, const char *propname) +const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep) { - const char *str = NULL; - int len = -1; + const char *val = NULL; + int len; assert(ofnode_valid(node)); debug("%s: %s: ", __func__, propname); if (ofnode_is_np(node)) { struct property *prop = of_find_property( - ofnode_to_np(node), propname, NULL); + ofnode_to_np(node), propname, &len); if (prop) { - str = prop->value; + val = prop->value; len = prop->length; } } else { - str = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), + val = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname, &len); } - if (!str) { + if (!val) { debug("\n"); + if (sizep) + *sizep = -FDT_ERR_NOTFOUND; return NULL; } + if (sizep) + *sizep = len; + + return val; +} + +const char *ofnode_read_string(ofnode node, const char *propname) +{ + const char *str; + int len; + + str = ofnode_read_prop(node, propname, &len); + if (!str) + return NULL; + if (strnlen(str, len) >= len) { debug("\n"); return NULL; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 9e76ae8407..8007483680 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -256,10 +256,21 @@ int ofnode_read_u64(ofnode node, const char *propname, u64 *outp); */ u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def); +/** + * ofnode_read_prop() - Read a property from a node + * + * @node: valid node reference to read property from + * @propname: name of the property to read + * @sizep: if non-NULL, returns the size of the property, or an error code + if not found + * @return property value, or NULL if there is no such property + */ +const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep); + /** * ofnode_read_string() - Read a string from a property * - * @ref: valid node reference to read property from + * @node: valid node reference to read property from * @propname: name of the property to read * @return string from property value, or NULL if there is no such property */ diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 633a3a9e9a..f1e4ed75db 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -59,6 +59,32 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +static int dm_test_ofnode_read(struct unit_test_state *uts) +{ + const u32 *val; + ofnode node; + int size; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + + val = ofnode_read_prop(node, "int-value", &size); + ut_assertnonnull(val); + ut_asserteq(4, size); + ut_asserteq(1234, fdt32_to_cpu(val[0])); + + val = ofnode_read_prop(node, "missing", &size); + ut_assertnull(val); + ut_asserteq(-FDT_ERR_NOTFOUND, size); + + /* Check it works without a size parameter */ + val = ofnode_read_prop(node, "missing", NULL); + ut_assertnull(val); + + return 0; +} +DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; From patchwork Mon Jan 27 15:49:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240301 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:45 -0700 Subject: [PATCH 10/21] dm: core: Reimplement ofnode_read_size() In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.10.I1dc4de977a1773af3abaccb48ffa7fa4882221e7@changeid> Now that we have ofnode_read_prop() we can rewrite this function using that one, reducing the amount of duplicated code. Update ofnode_read_size() and move it up next to the other similar functions. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index eebc5a7dce..4fc29a7c43 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -151,6 +151,16 @@ const char *ofnode_read_string(ofnode node, const char *propname) return str; } +int ofnode_read_size(ofnode node, const char *propname) +{ + int len; + + if (!ofnode_read_prop(node, propname, &len)) + return -EINVAL; + + return len; +} + ofnode ofnode_find_subnode(ofnode node, const char *subnode_name) { ofnode subnode; @@ -253,25 +263,6 @@ ofnode ofnode_get_by_phandle(uint phandle) return node; } -int ofnode_read_size(ofnode node, const char *propname) -{ - int len; - - if (ofnode_is_np(node)) { - struct property *prop = of_find_property( - ofnode_to_np(node), propname, NULL); - - if (prop) - return prop->length; - } else { - if (fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname, - &len)) - return len; - } - - return -EINVAL; -} - fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size) { int na, ns; From patchwork Mon Jan 27 15:49:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240300 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:46 -0700 Subject: [PATCH 11/21] dm: core: Add ofnode_get_chosen_prop() In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.11.I632d75f01fd709293b43d85b077a4ed2e4dc4e58@changeid> Add a function to read a property from the chosen node, providing access to its length. Update ofnode_get_chosen_string() to make use of it. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 1 + drivers/core/ofnode.c | 11 ++++++++--- include/dm/ofnode.h | 12 ++++++++++++ test/dm/ofnode.c | 8 ++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index a04afd4076..347ea79077 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -815,6 +815,7 @@ #size-cells = <1>; setting = "sunrise ohoka"; other-node = "/some-bus/c-test at 5"; + int-values = <0x1937 72993>; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 4fc29a7c43..f55ef15cee 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -427,20 +427,25 @@ ofnode ofnode_path(const char *path) return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path)); } -const char *ofnode_read_chosen_string(const char *name) +const void *ofnode_read_chosen_prop(const char *propname, int *sizep) { ofnode chosen_node; chosen_node = ofnode_path("/chosen"); - return ofnode_read_string(chosen_node, name); + return ofnode_read_prop(chosen_node, propname, sizep); +} + +const char *ofnode_read_chosen_string(const char *propname) +{ + return ofnode_read_chosen_prop(propname, NULL); } ofnode ofnode_get_chosen_node(const char *name) { const char *prop; - prop = ofnode_read_chosen_string(name); + prop = ofnode_read_chosen_prop(name, NULL); if (!prop) return ofnode_null(); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 8007483680..b5a50e8849 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -520,6 +520,18 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, */ ofnode ofnode_path(const char *path); +/** + * ofnode_read_chosen_prop() - get the value of a chosen property + * + * This looks for a property within the /chosen node and returns its value + * + * @propname: Property name to look for + * @sizep: Returns size of property, or FDT_ERR_... error code if function + * returns NULL + * @return property value if found, else NULL + */ +const void *ofnode_read_chosen_prop(const char *propname, int *sizep); + /** * ofnode_read_chosen_string() - get the string value of a chosen property * diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index f1e4ed75db..1c49eaf38b 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -88,7 +88,9 @@ DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; + const u32 *val; ofnode node; + int size; str = ofnode_read_chosen_string("setting"); ut_assertnonnull(str); @@ -102,6 +104,12 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) node = ofnode_get_chosen_node("setting"); ut_assert(!ofnode_valid(node)); + val = ofnode_read_chosen_prop("int-values", &size); + ut_assertnonnull(val); + ut_asserteq(8, size); + ut_asserteq(0x1937, fdt32_to_cpu(val[0])); + ut_asserteq(72993, fdt32_to_cpu(val[1])); + return 0; } DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240299 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:47 -0700 Subject: [PATCH 12/21] dm: core: Add a way to read platdata for all child devices In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.12.I68491432ec9983eb6b1af18bb8400ccddbb7709d@changeid> When generating ACPI tables we need to make sure that all devices have read their platform data, so that they can generate the tables correctly. Rather than adding this code in ACPI, create a core function to handle it. Signed-off-by: Simon Glass --- drivers/core/device.c | 36 ++++++++++++++++++++++++++++++++++++ include/dm/device.h | 42 ++++++++++++++++++++++++++++++++++++++++++ include/dm/read.h | 3 ++- test/dm/test-fdt.c | 19 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index b7f59fcde3..c948d8dbbc 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -792,6 +792,42 @@ int device_find_child_by_name(const struct udevice *parent, const char *name, return -ENODEV; } +int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + int ret; + + device_find_first_child(parent, &dev); + if (!dev) + return -ENODEV; + + ret = device_ofdata_to_platdata(dev); + if (ret) + return ret; + + *devp = dev; + + return 0; +} + +int device_next_child_ofdata_err(struct udevice **devp) +{ + struct udevice *dev = *devp; + int ret; + + device_find_next_child(&dev); + if (!dev) + return -ENODEV; + + ret = device_ofdata_to_platdata(dev); + if (ret) + return ret; + + *devp = dev; + + return 0; +} + struct udevice *dev_get_parent(const struct udevice *child) { return child->parent; diff --git a/include/dm/device.h b/include/dm/device.h index 611fc2e197..2618952336 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -577,6 +577,31 @@ int device_find_first_child_by_uclass(const struct udevice *parent, int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); +/** + * device_first_child_ofdata_err() - Find the first child and reads its platdata + * + * The ofdata_to_platdata() method is called on the child before it is returned, + * but the child is not probed. + * + * @parent: Parent to check + * @devp: Returns child that was found, if any + * @return 0 on success, -ENODEV if no children, other -ve on error + */ +int device_first_child_ofdata_err(struct udevice *parent, + struct udevice **devp); + +/* + * device_next_child_ofdata_err() - Find the next child and read its platdata + * + * The ofdata_to_platdata() method is called on the child before it is returned, + * but the child is not probed. + * + * @devp: On entry, points to the previous child; on exit returns the child that + * was found, if any + * @return 0 on success, -ENODEV if no children, other -ve on error + */ +int device_next_child_ofdata_err(struct udevice **devp); + /** * device_has_children() - check if a device has any children * @@ -706,6 +731,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) #define device_foreach_child(pos, parent) \ list_for_each_entry(pos, &parent->child_head, sibling_node) +/** + * device_foreach_child_ofdata_to_platdata() - iterate through children + * + * This stops when it gets an error, with @pos set to the device that failed to + * read ofdata. + + * This creates a for() loop which works through the available children of + * a device in order from start to end. Device ofdata is read by calling + * device_ofdata_to_platdata() on each one. The devices are not probed. + * + * @pos: struct udevice * for the current device + * @parent: parent device to scan + */ +#define device_foreach_child_ofdata_to_platdata(pos, parent) \ + for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \ + _ret = device_next_child_ofdata_err(&dev)) + /** * dm_scan_fdt_dev() - Bind child device in a the device tree * diff --git a/include/dm/read.h b/include/dm/read.h index 92a7328fc8..da8c7f25e7 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -844,7 +844,8 @@ static inline ofnode dev_read_next_subnode(ofnode node) } static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, - const char *propname, size_t sz) + const char *propname, + size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index d59c449ce0..8fe4425b21 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -872,3 +872,22 @@ static int dm_test_read_int(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_ofdata_err(), etc. */ +static int dm_test_child_ofdata(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_ofdata_to_platdata(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240302 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:48 -0700 Subject: [PATCH 13/21] dm: core: Add a way to iterate through children, probing each In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.13.I307389a2de896b0eee9728fa4cb109f1b5379693@changeid> It is sometimes useful to process all children, making sure they are probed first. Add functions to help with this and a macro to make it more convenient. Signed-off-by: Simon Glass --- drivers/core/device.c | 22 ++++++++++++++++++++++ include/dm/device.h | 39 +++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 19 +++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index c948d8dbbc..89ea820d48 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -792,6 +792,28 @@ int device_find_child_by_name(const struct udevice *parent, const char *name, return -ENODEV; } +int device_first_child_err(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + + device_find_first_child(parent, &dev); + if (!dev) + return -ENODEV; + + return device_get_device_tail(dev, 0, devp); +} + +int device_next_child_err(struct udevice **devp) +{ + struct udevice *dev = *devp; + + device_find_next_child(&dev); + if (!dev) + return -ENODEV; + + return device_get_device_tail(dev, 0, devp); +} + int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp) { struct udevice *dev; diff --git a/include/dm/device.h b/include/dm/device.h index 2618952336..517ae7fc90 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -602,6 +602,28 @@ int device_first_child_ofdata_err(struct udevice *parent, */ int device_next_child_ofdata_err(struct udevice **devp); +/** + * device_first_child_err() - Get the first child of a device + * + * The device returned is probed if necessary, and ready for use + * + * @parent: Parent device to search + * @devp: Returns device found, if any + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_first_child_err(struct udevice *parent, struct udevice **devp); + +/** + * device_next_child_err() - Get the next child of a parent device + * + * The device returned is probed if necessary, and ready for use + * + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next sibling if no error occurred + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_next_child_err(struct udevice **devp); + /** * device_has_children() - check if a device has any children * @@ -748,6 +770,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \ _ret = device_next_child_ofdata_err(&dev)) +/** + * device_foreach_child_probe() - iterate through children, probing them + * + * This creates a for() loop which works through the available children of + * a device in order from start to end. Devices are probed if necessary, + * and ready for use. + * + * This stops when it gets an error, with @pos set to the device that failed to + * probe + * + * @pos: struct udevice * for the current device + * @parent: parent device to scan + */ +#define device_foreach_child_probe(pos, parent) \ + for (int _ret = device_first_child_err(parent, &dev); !_ret; \ + _ret = device_next_child_err(&dev)) + /** * dm_scan_fdt_dev() - Bind child device in a the device tree * diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 8fe4425b21..cd65e42a88 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -891,3 +891,22 @@ static int dm_test_child_ofdata(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_err(), etc. */ +static int dm_test_first_child_probe(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_probe(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(dev->flags & DM_FLAG_ACTIVATED); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240303 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:49 -0700 Subject: [PATCH 14/21] dm: core: Drop uclass_find_next_free_req_seq() conditions In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.14.Ib428956dc56e56ec5f488b4b4e16f4fa82bdb160@changeid> These conditions are not needed and just reduce build coverage. Drop them. Signed-off-by: Simon Glass --- drivers/core/uclass.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c520ef113a..cd6ee47146 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -271,9 +271,6 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, return -ENODEV; } -#if !CONFIG_IS_ENABLED(OF_CONTROL) || \ - CONFIG_IS_ENABLED(OF_PLATDATA) || \ - CONFIG_IS_ENABLED(OF_PRIOR_STAGE) int uclass_find_next_free_req_seq(enum uclass_id id) { struct uclass *uc; @@ -295,7 +292,6 @@ int uclass_find_next_free_req_seq(enum uclass_id id) return max + 1; } -#endif int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) From patchwork Mon Jan 27 15:49:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240304 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:50 -0700 Subject: [PATCH 15/21] bloblist: Add a new function to add or check size In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.15.I54b288f82c19b6c8a3d350ab3a49f971cd19dce9@changeid> A common check is to see if a blob is present, create it if not and make sure that the size is large enough. Add a function to handle this. Signed-off-by: Simon Glass --- common/bloblist.c | 15 +++++++++++++++ include/bloblist.h | 13 +++++++++++++ test/bloblist.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/common/bloblist.c b/common/bloblist.c index ccf5e4b6f6..0c87115e81 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -145,6 +145,21 @@ void *bloblist_ensure(uint tag, int size) return (void *)rec + rec->hdr_size; } +int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp) +{ + struct bloblist_rec *rec; + int ret; + + ret = bloblist_ensurerec(tag, &rec, *sizep); + if (ret == -ESPIPE) + *sizep = rec->size; + else if (ret) + return ret; + *blobp = (void *)rec + rec->hdr_size; + + return 0; +} + static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr) { struct bloblist_rec *rec; diff --git a/include/bloblist.h b/include/bloblist.h index 85144010ab..8c9ce98a3b 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -151,6 +151,19 @@ int bloblist_ensure_size(uint tag, int size, void **blobp); */ void *bloblist_ensure(uint tag, int size); +/** + * bloblist_ensure_size_ret() - Find or add a blob + * + * Find an existing blob, or add a new one if not found + * + * @tag: Tag to add (enum bloblist_tag_t) + * @sizep: Size of the blob to create; returns size of actual blob + * @blobp: Returns a pointer to blob on success + * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack + * of space + */ +int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp); + /** * bloblist_new() - Create a new, empty bloblist of a given size * diff --git a/test/bloblist.c b/test/bloblist.c index d0f7296e0d..c78b58ea29 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -24,6 +24,7 @@ enum { TEST_SIZE = 10, TEST_SIZE2 = 20, + TEST_SIZE_LARGE = 0xe0, TEST_ADDR = CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE = 0x100, @@ -97,6 +98,39 @@ static int bloblist_test_blob(struct unit_test_state *uts) } BLOBLIST_TEST(bloblist_test_blob, 0); +/* Check bloblist_ensure_size_ret() */ +static int bloblist_test_blob_ensure(struct unit_test_state *uts) +{ + void *data, *data2; + int size; + + /* At the start there should be no records */ + clear_bloblist(); + ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0)); + + /* Test with an empty bloblist */ + size = TEST_SIZE; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check that we get the same thing again */ + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); + ut_asserteq(TEST_SIZE, size); + ut_asserteq_ptr(data, data2); + + /* Check that the size remains the same */ + size = TEST_SIZE2; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check running out of space */ + size = TEST_SIZE_LARGE; + ut_asserteq(-ENOSPC, bloblist_ensure_size_ret(TEST_TAG2, &size, &data)); + + return 0; +} +BLOBLIST_TEST(bloblist_test_blob_ensure, 0); + static int bloblist_test_bad_blob(struct unit_test_state *uts) { struct bloblist_hdr *hdr; From patchwork Mon Jan 27 15:49:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240305 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:51 -0700 Subject: [PATCH 16/21] bloblist: Tidy up a few comments and code-style nits In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.16.If57a0ad7fb8aeef04ec034b19c95cd24b4fb9644@changeid> Add a messing error code to bloblist_new() and tidy up the line length in bloblist_addrec(). Signed-off-by: Simon Glass --- common/bloblist.c | 5 ++--- include/bloblist.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index 0c87115e81..e2b7cc62e0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -59,11 +59,10 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) struct bloblist_rec *rec; int new_alloced; - new_alloced = hdr->alloced + sizeof(*rec) + - ALIGN(size, BLOBLIST_ALIGN); + new_alloced = hdr->alloced + sizeof(*rec) + ALIGN(size, BLOBLIST_ALIGN); if (new_alloced >= hdr->size) { log(LOGC_BLOBLIST, LOGL_ERR, - "Failed to allocate %x bytes size=%x, need size>=%x\n", + "Failed to allocate %x bytes size=%x, need size=%x\n", size, hdr->size, new_alloced); return log_msg_ret("bloblist add", -ENOSPC); } diff --git a/include/bloblist.h b/include/bloblist.h index 8c9ce98a3b..609ac421d6 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -183,7 +183,8 @@ int bloblist_new(ulong addr, uint size, uint flags); * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that * there problem is no bloblist at the given address), -EPROTONOSUPPORT * if the version does not match, -EIO if the checksum does not match, - * -EFBIG if the expected size does not match the detected size + * -EFBIG if the expected size does not match the detected size, -ENOSPC + * if the size is not large enough to hold the headers */ int bloblist_check(ulong addr, uint size); From patchwork Mon Jan 27 15:49:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240306 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:52 -0700 Subject: [PATCH 17/21] bloblist: Zero records when adding In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.17.I6864f6c3746a7a08437504d012456c9f14f3ee08@changeid> It is convenient for bloblist to zero out the contents of a records when it is added. This saves the callers having to do it. Update the API accordingly. Signed-off-by: Simon Glass --- common/bloblist.c | 3 +++ doc/README.bloblist | 4 ++-- test/bloblist.c | 27 +++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index e2b7cc62e0..20a20ae0c0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -73,6 +73,9 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) rec->hdr_size = sizeof(*rec); rec->size = size; rec->spare = 0; + + /* Zero the record data */ + memset(rec + 1, '\0', rec->size); *recp = rec; return 0; diff --git a/doc/README.bloblist b/doc/README.bloblist index b0e787b97d..274c460557 100644 --- a/doc/README.bloblist +++ b/doc/README.bloblist @@ -55,8 +55,8 @@ a single bloblist. API --- -Bloblist provides a fairly simple API which allows blobs to be created and -found. All access is via the blob's tag. +Bloblist provides a fairly simple API which allows blobs to be created and +found. All access is via the blob's tag. Blob records are zeroed when added. Finishing the bloblist diff --git a/test/bloblist.c b/test/bloblist.c index c78b58ea29..bdcca0291c 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -34,13 +34,31 @@ static struct bloblist_hdr *clear_bloblist(void) { struct bloblist_hdr *hdr; - /* Clear out any existing bloblist so we have a clean slate */ + /* + * Clear out any existing bloblist so we have a clean slate. Zero the + * header so that existing records are removed, but set everything else + * to 0xff for testing purposes. + */ hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); - memset(hdr, '\0', TEST_BLOBLIST_SIZE); + memset(hdr, '\xff', TEST_BLOBLIST_SIZE); + memset(hdr, '\0', sizeof(*hdr)); return hdr; } +static int check_zero(void *data, int size) +{ + u8 *ptr; + int i; + + for (ptr = data, i = 0; i < size; i++, ptr++) { + if (*ptr) + return -EINVAL; + } + + return 0; +} + static int bloblist_test_init(struct unit_test_state *uts) { struct bloblist_hdr *hdr; @@ -84,10 +102,14 @@ static int bloblist_test_blob(struct unit_test_state *uts) data = bloblist_find(TEST_TAG, TEST_SIZE); ut_asserteq_ptr(rec + 1, data); + /* Check the data is zeroed */ + ut_assertok(check_zero(data, TEST_SIZE)); + /* Check the 'ensure' method */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check for a non-existent record */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); @@ -112,6 +134,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts) size = TEST_SIZE; ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); ut_asserteq(TEST_SIZE, size); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check that we get the same thing again */ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); From patchwork Mon Jan 27 15:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240307 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:53 -0700 Subject: [PATCH 18/21] sandbox: pmic: Correct i2c pmic emulator platdata method In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.18.I296e8199523e08dced6bb64d6984b84753ec64c6@changeid> This currently reads the uclass's private data in the ofdata_to_platdata method which is not allowed, since the uclass has not read it from the device tree. This happens in the probe method. Fix it by adding a probe() method and moving the code there. Signed-off-by: Simon Glass --- drivers/power/pmic/i2c_pmic_emul.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/power/pmic/i2c_pmic_emul.c b/drivers/power/pmic/i2c_pmic_emul.c index 80efc0265d..b58c8302cf 100644 --- a/drivers/power/pmic/i2c_pmic_emul.c +++ b/drivers/power/pmic/i2c_pmic_emul.c @@ -105,12 +105,21 @@ static int sandbox_i2c_pmic_ofdata_to_platdata(struct udevice *emul) { struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul); struct udevice *pmic_dev = i2c_emul_get_device(emul); - struct uc_pmic_priv *priv = dev_get_uclass_priv(pmic_dev); - const u8 *reg_defaults; debug("%s:%d Setting PMIC default registers\n", __func__, __LINE__); plat->reg_count = pmic_reg_count(pmic_dev); - plat->trans_len = priv->trans_len; + + return 0; +} + +static int sandbox_i2c_pmic_probe(struct udevice *emul) +{ + struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul); + struct udevice *pmic_dev = i2c_emul_get_device(emul); + struct uc_pmic_priv *upriv = dev_get_uclass_priv(pmic_dev); + const u8 *reg_defaults; + + plat->trans_len = upriv->trans_len; plat->buf_size = plat->reg_count * plat->trans_len; plat->reg = calloc(1, plat->buf_size); @@ -149,6 +158,7 @@ U_BOOT_DRIVER(sandbox_i2c_pmic_emul) = { .id = UCLASS_I2C_EMUL, .of_match = sandbox_i2c_pmic_ids, .ofdata_to_platdata = sandbox_i2c_pmic_ofdata_to_platdata, + .probe = sandbox_i2c_pmic_probe, .platdata_auto_alloc_size = sizeof(struct sandbox_i2c_pmic_plat_data), .ops = &sandbox_i2c_pmic_emul_ops, }; From patchwork Mon Jan 27 15:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240309 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:54 -0700 Subject: [PATCH 19/21] console: Add a function to read a line of the output / eof In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.19.I8114ed3d67267c833b7d9f456e6da6e9c4653c9b@changeid> When recording the console output for testing it is useful to be able to read the output a line at a time to check that the output is correct. Also we need to check that we get to the end of the output. Add a console function to return the next line and another to see how must data is left. Signed-off-by: Simon Glass --- common/console.c | 11 +++++++++++ include/console.h | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/common/console.c b/common/console.c index 168ba60d0d..7681da19a2 100644 --- a/common/console.c +++ b/common/console.c @@ -621,6 +621,17 @@ void console_record_reset_enable(void) console_record_reset(); gd->flags |= GD_FLG_RECORD; } + +int console_record_readline(char *str, int maxlen) +{ + return membuff_readline(&gd->console_out, str, maxlen, ' '); +} + +int console_record_avail(void) +{ + return membuff_avail(&gd->console_out); +} + #endif /* test if ctrl-c was pressed */ diff --git a/include/console.h b/include/console.h index e935c601f1..74afe22b7e 100644 --- a/include/console.h +++ b/include/console.h @@ -41,6 +41,25 @@ void console_record_reset(void); */ void console_record_reset_enable(void); +/** + * console_record_readline() - Read a line from the console output + * + * This reads the next available line from the console output previously + * recorded. + * + * @str: Place to put string + * @maxlen: Maximum length of @str including nul terminator + * @return length of string returned + */ +int console_record_readline(char *str, int maxlen); + +/** + * console_record_avail() - Get the number of available bytes in console output + * + * @return available bytes (0 if empty) + */ +int console_record_avail(void); + /** * console_announce_r() - print a U-Boot console on non-serial consoles * From patchwork Mon Jan 27 15:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240308 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:55 -0700 Subject: [PATCH 20/21] test: Enable console recording in tests In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.20.I0d843e524c54d3c7a29919c95929b1909b9eaa61@changeid> At present we reset the console buffer before each test but do not actually set the recording flag. Without this, the output is not recorded. Update the code to set the flag before the test and clear it afterwards. Signed-off-by: Simon Glass --- test/dm/test-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 72648162a9..d7dc8d1f91 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -97,11 +97,11 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, * Silence the console and rely on console recording to get * our output. */ - console_record_reset(); + console_record_reset_enable(); if (!state->show_test_output) gd->flags |= GD_FLG_SILENT; test->func(uts); - gd->flags &= ~GD_FLG_SILENT; + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); state_set_skip_delays(false); ut_assertok(dm_test_destroy(uts)); From patchwork Mon Jan 27 15:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240310 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 27 Jan 2020 08:49:56 -0700 Subject: [PATCH 21/21] test: Add a way to check each line of console output In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> Message-ID: <20200127084920.21.I6e63c1c6aae518ed5a245427b8046b1bac3dbf66@changeid> When writing tests to check the output from commands it is useful to be able to check the output line by line using an assertion. Add helper macros to support this and to check that there is no unexpected trailing data. Also some commands produce a dump using print_buffer(). Add a way to check that the correct number of bytes are dumped (ignoring the actual contents). Signed-off-by: Simon Glass --- include/test/test.h | 4 +++ include/test/ut.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ test/ut.c | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/include/test/test.h b/include/test/test.h index e5bef4759a..2a75211008 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -15,12 +15,16 @@ * @start: Store the starting mallinfo when doing leak test * @priv: A pointer to some other info some suites want to track * @of_root: Record of the livetree root node (used for setting up tests) + * @expect_str: Temporary string used to hold expected string value + * @actual_str: Temporary string used to hold actual string value */ struct unit_test_state { int fail_count; struct mallinfo start; void *priv; struct device_node *of_root; + char expect_str[256]; + char actual_str[256]; }; /** diff --git a/include/test/ut.h b/include/test/ut.h index c9fc9cc839..04df8ba3af 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -38,6 +38,43 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, const char *func, const char *cond, const char *fmt, ...) __attribute__ ((format (__printf__, 6, 7))); +/** + * ut_check_console_line() - Check the next console line against expectations + * + * This creates a string and then checks it against the next line of console + * output obtained with console_record_readline(). + * + * After the function returns, uts->expect_str holds the expected string and + * uts->actual_str holds the actual string read from the console. + * + * @uts: Test state + * @fmt: printf() format string for the error, followed by args + * @return 0 if OK, other value on error + */ +int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) + __attribute__ ((format (__printf__, 2, 3))); + +/** + * ut_check_console_end() - Check there is no more console output + * + * After the function returns, uts->actual_str holds the actual string read + * from the console + * + * @uts: Test state + * @return 0 if OK (console has no output), other value on error + */ +int ut_check_console_end(struct unit_test_state *uts); + +/** + * ut_check_console_dump() - Check that next lines have a print_buffer() dump + * + * This only supports a byte dump. + * + * @total_bytes: Size of the expected dump in bytes` + * @return 0 if OK (looks like a dump and the length matches), other value on + * error + */ +int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); /* Assert that a condition is non-zero */ #define ut_assert(cond) \ @@ -149,6 +186,34 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that an operation succeeds (returns 0) */ #define ut_assertok(cond) ut_asserteq(0, cond) +/* Assert that the next console output line matches */ +#define ut_assert_nextline(fmt, args...) \ + if (ut_check_console_line(uts, fmt, ##args)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected '%s',\n got '%s'", \ + uts->expect_str, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + +/* Assert that there is no more console output */ +#define ut_assert_console_end() \ + if (ut_check_console_end(uts)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "Expected no more output, got '%s'",\ + uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + +/* Assert that the next lines are print_buffer() dump at an address */ +#define ut_assert_nextlines_are_dump(total_bytes) \ + if (ut_check_console_dump(uts, total_bytes)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", \ + "Expected dump of length %x bytes, got '%s'", \ + total_bytes, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + /** * ut_check_free() - Return the number of bytes free in the malloc() pool * diff --git a/test/ut.c b/test/ut.c index 265da4a0d8..c64f0b554d 100644 --- a/test/ut.c +++ b/test/ut.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -46,3 +47,48 @@ long ut_check_delta(ulong last) return ut_check_free() - last; } +int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + va_end(args); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return strcmp(uts->expect_str, uts->actual_str); +} + +int ut_check_console_end(struct unit_test_state *uts) +{ + if (!console_record_avail()) + return 0; + + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return 1; +} + +int ut_check_console_dump(struct unit_test_state *uts, int total_bytes) +{ + char *str = uts->actual_str; + int upto; + + /* Handle empty dump */ + if (!total_bytes) + return 0; + + for (upto = 0; upto < total_bytes;) { + int len; + int bytes; + + len = console_record_readline(str, sizeof(uts->actual_str)); + if (str[8] != ':' || str[9] != ' ') + return 1; + + bytes = len - 8 - 2 - 3 * 16 - 4; + upto += bytes; + } + + return upto == total_bytes ? 0 : 1; +}