Add infrastructure to probe per bus

Add some infrastructure around per-bus probing functions.  Each function
is provided a private parameter, e.g. the expected length of an ID. This
will allow us to implement probing functions that are only called as of-
ten as necessary. The results will be stored in the `registered_master`
structure, to be compared to database entries later.

The probe_buses() wrapper can be used for chip entries, and allows us to
transition the existing probing functions one by one. Once all functions
have been ported, probe_flash() can be adapted as well and the wrapper
will become obsolete.

Change-Id: I6e82b6d61df50234096ac39acab58a4014203933
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/74899
diff --git a/include/chipdrivers/probing.h b/include/chipdrivers/probing.h
index 7563f74..fefca3c 100644
--- a/include/chipdrivers/probing.h
+++ b/include/chipdrivers/probing.h
@@ -17,6 +17,7 @@
 #ifndef __PROBING_H__
 #define __PROBING_H__ 1
 
+#include <stddef.h>
 #include <stdint.h>
 
 enum id_type {
@@ -47,9 +48,43 @@
  * Identification code.
  */
 struct id_info {
-	uint32_t manufacture;
-	uint32_t model;
+	union {
+		uint32_t manufacture;
+		uint32_t id1;
+	};
+	union {
+		uint32_t model;
+		uint32_t id2;
+	};
 	enum id_type type;
 };
 
+struct id_info_ext {
+	struct id_info id;
+	void *ext;
+};
+
+struct found_id {
+	struct found_id *next;
+	struct id_info_ext info;
+};
+
+struct flashprog_chip;
+struct master_common;
+
+struct bus_probe {
+	enum id_type type;
+	struct found_id *(*run)(const struct bus_probe *, const struct master_common *);
+	void *arg;
+};
+
+struct bus_probing {
+	unsigned int probe_count;
+	const struct bus_probe *probes;
+	bool (*match)(const struct flashprog_chip *, const struct id_info_ext *);
+};
+
+struct flashprog_flashctx;
+int probe_buses(struct flashprog_flashctx *);
+
 #endif /* !__PROBING_H__ */