summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/device.c4
-rw-r--r--drivers/core/dump.c116
-rw-r--r--drivers/core/of_access.c16
-rw-r--r--drivers/core/of_addr.c1
-rw-r--r--drivers/core/ofnode.c93
-rw-r--r--drivers/core/root.c82
6 files changed, 196 insertions, 116 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 6e26b64fb81..bf7f261cbce 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -33,6 +33,7 @@
#include <linux/err.h>
#include <linux/list.h>
#include <power-domain.h>
+#include <linux/printk.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -598,9 +599,10 @@ int device_probe(struct udevice *dev)
ret = device_notify(dev, EVT_DM_POST_PROBE);
if (ret)
- return ret;
+ goto fail_event;
return 0;
+fail_event:
fail_uclass:
if (device_remove(dev, DM_REMOVE_NORMAL)) {
dm_warn("%s: Device '%s' failed to remove on error path\n",
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 3e77832a3a0..4023b390f54 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -85,29 +85,65 @@ static void show_devices(struct udevice *dev, int depth, int last_flag,
}
}
-void dm_dump_tree(bool sort)
+static void dm_dump_tree_single(struct udevice *dev, bool sort)
{
- struct udevice *root;
+ int dev_count, uclasses;
+ struct udevice **devs = NULL;
- root = dm_root();
- if (root) {
- int dev_count, uclasses;
- struct udevice **devs = NULL;
-
- dm_get_stats(&dev_count, &uclasses);
-
- printf(" Class Index Probed Driver Name\n");
- printf("-----------------------------------------------------------\n");
- if (sort) {
- devs = calloc(dev_count, sizeof(struct udevice *));
- if (!devs) {
- printf("(out of memory)\n");
- return;
+ dm_get_stats(&dev_count, &uclasses);
+
+ if (sort) {
+ devs = calloc(dev_count, sizeof(struct udevice *));
+ if (!devs) {
+ printf("(out of memory)\n");
+ return;
+ }
+ }
+ show_devices(dev, -1, 0, devs);
+ free(devs);
+}
+
+static void dm_dump_tree_recursive(struct udevice *dev, char *dev_name,
+ bool extended, bool sort)
+{
+ struct udevice *child;
+ size_t len;
+
+ len = strlen(dev_name);
+
+ device_foreach_child(child, dev) {
+ if (extended) {
+ if (!strncmp(child->name, dev_name, len)) {
+ dm_dump_tree_single(child, sort);
+ continue;
+ }
+ } else {
+ if (!strcmp(child->name, dev_name)) {
+ dm_dump_tree_single(child, sort);
+ continue;
}
}
- show_devices(root, -1, 0, devs);
- free(devs);
+ dm_dump_tree_recursive(child, dev_name, extended, sort);
+ }
+}
+
+void dm_dump_tree(char *dev_name, bool extended, bool sort)
+{
+ struct udevice *root;
+
+ printf(" Class Index Probed Driver Name\n");
+ printf("-----------------------------------------------------------\n");
+
+ root = dm_root();
+ if (!root)
+ return;
+
+ if (!dev_name || !strcmp(dev_name, "root")) {
+ dm_dump_tree_single(root, sort);
+ return;
}
+
+ dm_dump_tree_recursive(root, dev_name, extended, sort);
}
/**
@@ -127,26 +163,50 @@ static void dm_display_line(struct udevice *dev, int index)
puts("\n");
}
-void dm_dump_uclass(void)
+static void dm_dump_uclass_single(enum uclass_id id)
{
struct uclass *uc;
+ struct udevice *dev;
+ int i = 0, ret;
+
+ ret = uclass_get(id, &uc);
+ if (ret)
+ return;
+
+ printf("uclass %d: %s\n", id, uc->uc_drv->name);
+ uclass_foreach_dev(dev, uc) {
+ dm_display_line(dev, i);
+ i++;
+ }
+ puts("\n");
+}
+
+void dm_dump_uclass(char *uclass, bool extended)
+{
+ struct uclass *uc;
+ enum uclass_id id;
+ bool matching;
int ret;
- int id;
- for (id = 0; id < UCLASS_COUNT; id++) {
- struct udevice *dev;
- int i = 0;
+ matching = !!(uclass && strcmp(uclass, "root"));
+ for (id = 0; id < UCLASS_COUNT; id++) {
ret = uclass_get(id, &uc);
if (ret)
continue;
- printf("uclass %d: %s\n", id, uc->uc_drv->name);
- uclass_foreach_dev(dev, uc) {
- dm_display_line(dev, i);
- i++;
+ if (matching) {
+ if (extended) {
+ if (!strncmp(uc->uc_drv->name, uclass,
+ strlen(uclass)))
+ dm_dump_uclass_single(id);
+ } else {
+ if (!strcmp(uc->uc_drv->name, uclass))
+ dm_dump_uclass_single(id);
+ }
+ } else {
+ dm_dump_uclass_single(id);
}
- puts("\n");
}
}
diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index 57f10445b12..1bb4d8eab70 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -570,26 +570,34 @@ int of_read_u32_index(const struct device_node *np, const char *propname,
return 0;
}
-int of_read_u64(const struct device_node *np, const char *propname, u64 *outp)
+int of_read_u64_index(const struct device_node *np, const char *propname,
+ int index, u64 *outp)
{
const __be64 *val;
debug("%s: %s: ", __func__, propname);
if (!np)
return -EINVAL;
- val = of_find_property_value_of_size(np, propname, sizeof(*outp));
+
+ val = of_find_property_value_of_size(np, propname,
+ sizeof(*outp) * (index + 1));
if (IS_ERR(val)) {
debug("(not found)\n");
return PTR_ERR(val);
}
- *outp = be64_to_cpup(val);
+ *outp = be64_to_cpup(val + index);
debug("%#llx (%lld)\n", (unsigned long long)*outp,
- (unsigned long long)*outp);
+ (unsigned long long)*outp);
return 0;
}
+int of_read_u64(const struct device_node *np, const char *propname, u64 *outp)
+{
+ return of_read_u64_index(np, propname, 0, outp);
+}
+
int of_property_match_string(const struct device_node *np, const char *propname,
const char *string)
{
diff --git a/drivers/core/of_addr.c b/drivers/core/of_addr.c
index 431dd4e565d..b3b3d7ccdd5 100644
--- a/drivers/core/of_addr.c
+++ b/drivers/core/of_addr.c
@@ -14,6 +14,7 @@
#include <dm/of_addr.h>
#include <linux/err.h>
#include <linux/ioport.h>
+#include <linux/printk.h>
/* Max address size we deal with */
#define OF_MAX_ADDR_CELLS 4
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 8df16e56af5..2cafa7bca5b 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -103,7 +103,7 @@ void *ofnode_lookup_fdt(ofnode node)
if (gd->flags & GD_FLG_RELOC) {
uint i = OFTREE_TREE_ID(node.of_offset);
- if (i > oftree_count) {
+ if (i >= oftree_count) {
log_debug("Invalid tree ID %x\n", i);
return NULL;
}
@@ -344,6 +344,36 @@ int ofnode_read_u32_index(ofnode node, const char *propname, int index,
return 0;
}
+int ofnode_read_u64_index(ofnode node, const char *propname, int index,
+ u64 *outp)
+{
+ const fdt64_t *cell;
+ int len;
+
+ assert(ofnode_valid(node));
+
+ if (ofnode_is_np(node))
+ return of_read_u64_index(ofnode_to_np(node), propname, index,
+ outp);
+
+ cell = fdt_getprop(ofnode_to_fdt(node), ofnode_to_offset(node),
+ propname, &len);
+ if (!cell) {
+ debug("(not found)\n");
+ return -EINVAL;
+ }
+
+ if (len < (sizeof(u64) * (index + 1))) {
+ debug("(not large enough)\n");
+ return -EOVERFLOW;
+ }
+
+ *outp = fdt64_to_cpu(cell[index]);
+ debug("%#llx (%lld)\n", *outp, *outp);
+
+ return 0;
+}
+
u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
u32 def)
{
@@ -1353,7 +1383,7 @@ bool ofnode_pre_reloc(ofnode node)
*/
if (ofnode_read_bool(node, "bootph-pre-ram") ||
ofnode_read_bool(node, "bootph-pre-sram"))
- return true;
+ return gd->flags & GD_FLG_RELOC;
if (IS_ENABLED(CONFIG_OF_TAG_MIGRATE)) {
/* detect and handle old tags */
@@ -1563,6 +1593,65 @@ const char *ofnode_conf_read_str(const char *prop_name)
return ofnode_read_string(node, prop_name);
}
+int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset)
+{
+ int ret;
+ ofnode uboot;
+
+ *bootscr_address = 0;
+ *bootscr_offset = 0;
+
+ uboot = ofnode_path("/options/u-boot");
+ if (!ofnode_valid(uboot)) {
+ debug("%s: Missing /u-boot node\n", __func__);
+ return -EINVAL;
+ }
+
+ ret = ofnode_read_u64(uboot, "bootscr-address", bootscr_address);
+ if (ret) {
+ ret = ofnode_read_u64(uboot, "bootscr-ram-offset",
+ bootscr_offset);
+ if (ret)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,
+ u64 *bootscr_flash_size)
+{
+ int ret;
+ ofnode uboot;
+
+ *bootscr_flash_offset = 0;
+ *bootscr_flash_size = 0;
+
+ uboot = ofnode_path("/options/u-boot");
+ if (!ofnode_valid(uboot)) {
+ debug("%s: Missing /u-boot node\n", __func__);
+ return -EINVAL;
+ }
+
+ ret = ofnode_read_u64(uboot, "bootscr-flash-offset",
+ bootscr_flash_offset);
+ if (ret)
+ return -EINVAL;
+
+ ret = ofnode_read_u64(uboot, "bootscr-flash-size",
+ bootscr_flash_size);
+ if (ret)
+ return -EINVAL;
+
+ if (!bootscr_flash_size) {
+ debug("bootscr-flash-size is zero. Ignoring properties!\n");
+ *bootscr_flash_offset = 0;
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
ofnode ofnode_get_phy_node(ofnode node)
{
/* DT node properties that reference a PHY node */
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 79d871ab291..126b3140666 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -29,6 +29,7 @@
#include <dm/uclass-internal.h>
#include <dm/util.h>
#include <linux/list.h>
+#include <linux/printk.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -55,81 +56,6 @@ void dm_fixup_for_gd_move(struct global_data *new_gd)
}
}
-void fix_drivers(void)
-{
- struct driver *drv =
- ll_entry_start(struct driver, driver);
- const int n_ents = ll_entry_count(struct driver, driver);
- struct driver *entry;
-
- for (entry = drv; entry != drv + n_ents; entry++) {
- if (entry->of_match)
- entry->of_match = (const struct udevice_id *)
- ((ulong)entry->of_match + gd->reloc_off);
- if (entry->bind)
- entry->bind += gd->reloc_off;
- if (entry->probe)
- entry->probe += gd->reloc_off;
- if (entry->remove)
- entry->remove += gd->reloc_off;
- if (entry->unbind)
- entry->unbind += gd->reloc_off;
- if (entry->of_to_plat)
- entry->of_to_plat += gd->reloc_off;
- if (entry->child_post_bind)
- entry->child_post_bind += gd->reloc_off;
- if (entry->child_pre_probe)
- entry->child_pre_probe += gd->reloc_off;
- if (entry->child_post_remove)
- entry->child_post_remove += gd->reloc_off;
- /* OPS are fixed in every uclass post_probe function */
- if (entry->ops)
- entry->ops += gd->reloc_off;
- }
-}
-
-void fix_uclass(void)
-{
- struct uclass_driver *uclass =
- ll_entry_start(struct uclass_driver, uclass_driver);
- const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver);
- struct uclass_driver *entry;
-
- for (entry = uclass; entry != uclass + n_ents; entry++) {
- if (entry->post_bind)
- entry->post_bind += gd->reloc_off;
- if (entry->pre_unbind)
- entry->pre_unbind += gd->reloc_off;
- if (entry->pre_probe)
- entry->pre_probe += gd->reloc_off;
- if (entry->post_probe)
- entry->post_probe += gd->reloc_off;
- if (entry->pre_remove)
- entry->pre_remove += gd->reloc_off;
- if (entry->child_post_bind)
- entry->child_post_bind += gd->reloc_off;
- if (entry->child_pre_probe)
- entry->child_pre_probe += gd->reloc_off;
- if (entry->init)
- entry->init += gd->reloc_off;
- if (entry->destroy)
- entry->destroy += gd->reloc_off;
- }
-}
-
-void fix_devices(void)
-{
- struct driver_info *dev =
- ll_entry_start(struct driver_info, driver_info);
- const int n_ents = ll_entry_count(struct driver_info, driver_info);
- struct driver_info *entry;
-
- for (entry = dev; entry != dev + n_ents; entry++) {
- if (entry->plat)
- entry->plat += gd->reloc_off;
- }
-}
-
static int dm_setup_inst(void)
{
DM_ROOT_NON_CONST = DM_DEVICE_GET(root);
@@ -181,12 +107,6 @@ int dm_init(bool of_live)
INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST);
}
- if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
- fix_drivers();
- fix_uclass();
- fix_devices();
- }
-
if (CONFIG_IS_ENABLED(OF_PLATDATA_INST)) {
ret = dm_setup_inst();
if (ret) {