aboutsummaryrefslogtreecommitdiff
path: root/core/hwprobe.c
blob: 0a641ada5c0f2215c75b455ce675822baa30f81e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
/* Copyright 2021 Stewart Smith */

#define pr_fmt(fmt)  "HWPROBE: " fmt
#include <skiboot.h>
#include <string.h>

static bool hwprobe_deps_satisfied(const struct hwprobe *hwp)
{
	struct hwprobe *hwprobe;
	const char **dep;
	unsigned int i;

	dep = hwp->deps;
	if (dep == NULL)
		return true;


	prlog(PR_TRACE, "Checking deps for %s\n", hwp->name);

	while (*dep != NULL) {
		prlog(PR_TRACE, "Checking %s dep %s\n", hwp->name, *dep);
		hwprobe = &__hwprobes_start;
		for (i = 0; &hwprobe[i] < &__hwprobes_end; i++) {
			if(strcmp(hwprobe[i].name, *dep) == 0 &&
			   !hwprobe[i].probed)
				return false;
		}
		dep++;
	}

	prlog(PR_TRACE, "deps for %s are satisfied!\n", hwp->name);
	return true;

}

void probe_hardware(void)
{
	struct hwprobe *hwprobe;
	unsigned int i;
	bool work_todo = true;
	bool did_something = true;

	while (work_todo) {
		work_todo = false;
		did_something = false;
		hwprobe = &__hwprobes_start;
		prlog(PR_DEBUG, "Begin loop\n");
		for (i = 0; &hwprobe[i] < &__hwprobes_end; i++) {
			if (hwprobe[i].probed)
				continue;
			if (hwprobe_deps_satisfied(&hwprobe[i])) {
				prlog(PR_DEBUG, "Probing %s...\n", hwprobe[i].name);
				if (hwprobe[i].probe)
					hwprobe[i].probe();
				did_something = true;
				hwprobe[i].probed = true;
			} else {
				prlog(PR_DEBUG, "Dependencies for %s not yet satisfied, skipping\n",
				      hwprobe[i].name);
				work_todo = true;
			}
		}

		if (work_todo && !did_something) {
			prlog(PR_ERR, "Cannot satisfy dependencies! Bailing out\n");
			break;
		}
	}
}