Pārlūkot izejas kodu

New device probing mechanism

tags/v0.9.3
Michael Brown 19 gadus atpakaļ
vecāks
revīzija
17c1ca90e7
2 mainītis faili ar 83 papildinājumiem un 107 dzēšanām
  1. 44
    0
      src/core/dev.c
  2. 39
    107
      src/include/dev.h

+ 44
- 0
src/core/dev.c Parādīt failu

@@ -0,0 +1,44 @@
1
+#include "etherboot.h"
2
+#include "stddef.h"
3
+#include "dev.h"
4
+
5
+/* Defined by linker */
6
+extern struct boot_driver boot_drivers[];
7
+extern struct boot_driver boot_drivers_end[];
8
+
9
+/* Current attempted boot driver */
10
+static struct boot_driver *boot_driver = boot_drivers;
11
+
12
+/* Current boot device */
13
+struct dev dev;
14
+
15
+/* Print all drivers */
16
+void print_drivers ( void ) {
17
+	struct boot_driver *driver;
18
+
19
+	for ( driver = boot_drivers ; driver < boot_drivers_end ; driver++ ) {
20
+		printf ( "%s ", driver->name );
21
+	}
22
+}
23
+
24
+/* Get the next available boot device */
25
+int probe ( struct dev *dev ) {
26
+	
27
+	for ( ; boot_driver < boot_drivers_end ; boot_driver++ ) {
28
+		dev->name = "unknown";
29
+		if ( boot_driver->probe ( dev ) )
30
+			return 1;
31
+	}
32
+	
33
+	/* No more boot devices found */
34
+	boot_driver = boot_drivers;
35
+	return 0;
36
+}
37
+
38
+/* Disable a device */
39
+void disable ( struct dev *dev ) {
40
+	if ( dev->dev_op ) {
41
+		dev->dev_op->disable ( dev );
42
+		dev->dev_op = NULL;
43
+	}
44
+}

+ 39
- 107
src/include/dev.h Parādīt failu

@@ -1,126 +1,58 @@
1 1
 #ifndef DEV_H
2 2
 #define DEV_H
3 3
 
4
-#include "isa.h"
5
-#include "pci.h"
4
+#include "stdint.h"
5
+#include "nic.h"
6 6
 
7 7
 /* Need to check the packing of this struct if Etherboot is ported */
8
-struct dev_id
9
-{
10
-	unsigned short	vendor_id;
11
-	unsigned short	device_id;
12
-	unsigned char	bus_type;
8
+struct dev_id {
9
+	uint16_t	vendor_id;
10
+	uint16_t	device_id;
11
+	uint8_t		bus_type;
13 12
 #define	PCI_BUS_TYPE	1
14 13
 #define	ISA_BUS_TYPE	2
15
-};
14
+} __attribute__ ((packed));
16 15
 
17 16
 /* Dont use sizeof, that will include the padding */
18 17
 #define	DEV_ID_SIZE	8
19 18
 
20
-
21
-struct pci_probe_state 
22
-{
23
-#ifdef CONFIG_PCI
24
-	struct pci_device dev;
25
-	int advance;
26
-#else
27
-	int dummy;
28
-#endif
29
-};
30
-struct isa_probe_state
31
-{
32
-#ifdef CONFIG_ISA
33
-	const struct isa_driver *driver;
34
-	int advance;
35
-#else
36
-	int dummy;
37
-#endif
19
+struct dev {
20
+	const char *name;
21
+	struct dev_id	devid;	/* device ID string (sent to DHCP server) */
22
+	struct dev_operations *dev_op;
23
+	/* All possible device types */
24
+	union {
25
+		struct nic	nic;
26
+	};
38 27
 };
39 28
 
40
-union probe_state
41
-{
42
-	struct pci_probe_state pci;
43
-	struct isa_probe_state isa;
29
+struct dev_operations {
30
+	void ( *disable ) ( struct dev * );
31
+	int ( *load_configuration ) ( struct dev * );
32
+	int ( *load ) ( struct dev * );
44 33
 };
45 34
 
46
-struct dev
47
-{
48
-	void		(*disable)P((struct dev *));
49
-	struct dev_id	devid;	/* device ID string (sent to DHCP server) */
50
-	int		index;  /* Index of next device on this controller to probe */
51
-	int		type;		/* Type of device I am probing for */
52
-	int		how_probe;	/* First, next or awake */
53
-	int 		to_probe;	/* Flavor of device I am probing */
54
-	int		failsafe;	/* Failsafe probe requested */
55
-	int		type_index;	/* Index of this device (within type) */
56
-#define	PROBE_NONE 0
57
-#define PROBE_PCI  1
58
-#define PROBE_ISA  2
59
-	union probe_state state;
35
+struct boot_driver {
36
+	char *name;
37
+	int (*probe) ( struct dev * );
60 38
 };
61 39
 
62
-
63
-#define NIC_DRIVER    0
64
-#define DISK_DRIVER   1
65
-#define FLOPPY_DRIVER 2
66
-
67
-#define BRIDGE_DRIVER 1000
68
-
69
-#define PROBE_FIRST  (-1)
70
-#define PROBE_NEXT   0
71
-#define PROBE_AWAKE  1		/* After calling disable bring up the same device */
72
-
73
-/* The probe result codes are selected
74
- * to allow them to be fed back into the probe
75
- * routine and get a successful probe.
76
- */
77
-#define PROBE_FAILED PROBE_FIRST
78
-#define PROBE_WORKED  PROBE_NEXT
79
-
80
-extern int probe(struct dev *dev);
81
-extern void disable(struct dev *dev);
82
-
83
-/* Boot option values
84
- * option & BOOT_TYPE_MASK should equal a driver for probing
85
- */
86
-
87
-#define BOOT_NIC      0x0	/* Boot from a nic */
88
-#define BOOT_DISK     0x1	/* Boot from disk */
89
-#define BOOT_FLOPPY   0x2	/* Boot from a floppy */
90
-
91
-#define BOOT_NOTHING  0x3	/* Last valid boot choice */
92
-
93
-/* Do magic failsafe boot processing */
94
-#define BOOT_FAILSAFE 0x8
95
-
96
-#define BOOT_BITS       4
97
-#define BOOT_MASK      ((1 << (BOOT_BITS)) - 1)
98
-#define BOOT_TYPE_MASK ((1 << (BOOT_BITS - 1)) - 1)
99
-
100
-#define MAX_BOOT_ENTRIES 3
101
-
102
-#define	BOOT_ALL_VALUE	(1<<BOOT_FIRST|1<<BOOT_SECOND|1<<BOOT_THIRD)
103
-
104
-/* These could be customised for different languages perhaps */
105
-#if	BOOT_ALL_VALUE&(1<<BOOT_DISK)
106
-#define	BOOT_DISK_PROMPT	"(D)isk "
107
-#else
108
-#define	BOOT_DISK_PROMPT
109
-#endif
110
-
111
-#if	BOOT_ALL_VALUE&(1<<BOOT_FLOPPY)
112
-#define	BOOT_FLOPPY_PROMPT	"(F)loppy "
113
-#else
114
-#define	BOOT_FLOPPY_PROMPT
115
-#endif
116
-
117
-#define	ASK_PROMPT	\
118
-	"Boot from (N)etwork " BOOT_DISK_PROMPT BOOT_FLOPPY_PROMPT "or (Q)uit? "
119
-
120
-#define	ANS_NETWORK	'N'
121
-#define ANS_DISK	'D'
122
-#define ANS_FLOPPY	'F'
123
-#define	ANS_QUIT	'Q'
124
-#define ANS_DEFAULT	'\n'
40
+#define BOOT_DRIVER( driver_name, probe_func )				      \
41
+	static struct boot_driver boot_driver				      \
42
+	    __attribute__ ((used,__section__(".boot_drivers"))) = {	      \
43
+		.name = driver_name,					      \
44
+		.probe = probe_func,					      \
45
+	};
46
+
47
+/* Functions in dev.c */
48
+extern void print_drivers ( void );
49
+extern int probe ( struct dev *dev );
50
+extern void disable ( struct dev *dev );
51
+static inline int load_configuration ( struct dev *dev ) {
52
+	return dev->dev_op->load_configuration ( dev );
53
+}
54
+static inline int load ( struct dev *dev ) {
55
+	return dev->dev_op->load ( dev );
56
+}
125 57
 
126 58
 #endif /* DEV_H */

Notiek ielāde…
Atcelt
Saglabāt